Skip to content

Commit

Permalink
Continuing modifications related to the new config format.
Browse files Browse the repository at this point in the history
- Analysis/include/AnalysisCategories.h:
  - reading channel parameter as analysis::Channel object;
  - fixed bugs in DataCategoryCollection.
- AnalysisBase/include/AnalysisTypes.h: definition of enum Channel moved
  here from FlatTree.h.
- PrintTools/config/sources.txt: modified to be compatible with a new
  format.
  • Loading branch information
kandrosov committed Oct 13, 2014
1 parent 0be5409 commit 560e9b0
Show file tree
Hide file tree
Showing 12 changed files with 610 additions and 439 deletions.
31 changes: 17 additions & 14 deletions Analysis/include/AnalysisCategories.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
#include <TFile.h>
#include <Rtypes.h>

#include "AnalysisBase/include/exception.h"
#include "AnalysisBase/include/AnalysisTypes.h"

namespace analysis {

typedef std::map<std::string, double> DataSourceScaleFactorMap;

enum class DataCategoryType { Signal, Background, Data, DYJets, ZL, ZJ, ZTT, ZTT_MC, Embedded, Limits, Sum, QCD, WJets,
EWK};
EWK };
static const std::map<DataCategoryType, std::string> dataCategoryTypeNameMap = {
{ DataCategoryType::Signal, "SIGNAL" }, { DataCategoryType::Background, "BACKGROUND" },
{ DataCategoryType::Data, "DATA" }, { DataCategoryType::DYJets, "DY_JETS" }, { DataCategoryType::ZL, "ZL" },
Expand Down Expand Up @@ -78,11 +78,11 @@ struct DataCategory {
unsigned draw_sf;

std::set<DataCategoryType> types;
std::set<std::string> channels;
std::set<Channel> channels;
DataSourceScaleFactorMap sources_sf;

DataCategory()
: color(kBlack), limits_sf(std::nan("")), draw(false), draw_sf(1) {}
: color(kBlack), limits_sf(1.0), draw(false), draw_sf(1) {}

bool IsSignal() const { return types.count(DataCategoryType::Signal); }
bool IsBackground() const { return types.count(DataCategoryType::Background); }
Expand All @@ -108,16 +108,15 @@ typedef std::map<std::string, DataSource> DataSourceMap;

class DataCategoryCollection {
public:
DataCategoryCollection(const std::string& sources_cfg_name, const std::string& signal_list,
const std::string& channel_name)
DataCategoryCollection(const std::string& sources_cfg_name, const std::string& signal_list, Channel channel_id)
{
DataCategory category;
std::ifstream cfg(sources_cfg_name);
size_t line_number = 0;
while(ReadNextCategory(cfg, line_number, category)) {
if(categories.count(category.name))
throw exception("Category with name '") << category.name << "' is already defined.";
if(category.channels.size() && !category.channels.count(channel_name)) continue;
if(category.channels.size() && !category.channels.count(channel_id)) continue;
categories[category.name] = category;
all_categories.insert(&categories[category.name]);
for(DataCategoryType type : category.types)
Expand Down Expand Up @@ -160,15 +159,15 @@ class DataCategoryCollection {
}

private:
static bool ReadNextCategory(std::istream& cfg, size_t line_number, DataCategory& category)
static bool ReadNextCategory(std::istream& cfg, size_t& line_number, DataCategory& category)
{
category = DataCategory();
bool category_started = false;
while (cfg.good()) {
std::string cfgLine;
std::getline(cfg,cfgLine);
++line_number;
if (cfgLine.at(0) == '#' || (!cfgLine.size() && !category_started)) continue;
if ((cfgLine.size() && cfgLine.at(0) == '#') || (!cfgLine.size() && !category_started)) continue;
if(!cfgLine.size())
return true;
if(!category_started && cfgLine.at(0) == '[') {
Expand All @@ -187,10 +186,14 @@ class DataCategoryCollection {

static void ReadParameterLine(const std::string& cfgLine, size_t line_number, DataCategory& category)
{
static const char separator = ',';
static const char separator = ':';

const size_t pos = cfgLine.find(separator);
const std::string param_name = cfgLine.substr(0, pos - 1);
if(pos == std::string::npos)
throw exception("bad source config syntax for a parameter in line ") << line_number;
const std::string param_name = cfgLine.substr(0, pos);
if(pos + 2 >= cfgLine.size())
throw exception("empty parameter value in source config in line ") << line_number;
const std::string param_value = cfgLine.substr(pos + 2);
std::istringstream ss(param_value);
if(param_name == "type") {
Expand All @@ -213,9 +216,9 @@ class DataCategoryCollection {
} else if(param_name == "draw_sf") {
ss >> category.draw_sf;
} else if(param_name == "channel") {
std::string channel_name;
ss >> channel_name;
category.channels.insert(channel_name);
Channel channel_id;
ss >> channel_id;
category.channels.insert(channel_id);
} else if(param_name == "datacard") {
ss >> category.datacard;
} else
Expand Down
1 change: 1 addition & 0 deletions Analysis/include/BaseAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "AnalysisBase/include/RunReport.h"
#include "AnalysisBase/include/Tools.h"
#include "AnalysisBase/include/AnalysisTools.h"
#include "AnalysisBase/include/AnalysisTypes.h"

#include "Htautau_Summer13.h"
#include "Htautau_TriggerEfficiency.h"
Expand Down
20 changes: 13 additions & 7 deletions Analysis/include/BaseFlatTreeAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "AnalysisBase/include/AnalyzerData.h"
#include "AnalysisBase/include/FlatEventInfo.h"
#include "AnalysisBase/include/AnalysisMath.h"
#include "AnalysisBase/include/AnalysisTypes.h"
#include "AnalysisBase/include/exception.h"
#include "AnalysisBase/include/Particles.h"
#include "PrintTools/include/RootPrintToPdf.h"
Expand Down Expand Up @@ -112,10 +113,10 @@ class BaseFlatTreeAnalyzer {
typedef std::map<EventCategory, AnaDataForDataCategory> FullAnaData;

BaseFlatTreeAnalyzer(const std::string& source_cfg, const std::string& hist_cfg, const std::string& _inputPath,
const std::string& _outputFileName, const std::string& channel_name,
const std::string& _outputFileName, Channel channel_id,
const std::string& signal_list, bool _WjetsData = false)
: inputPath(_inputPath), outputFileName(_outputFileName),
dataCategoryCollection(source_cfg, signal_list, channel_name), WjetsData(_WjetsData)
dataCategoryCollection(source_cfg, signal_list, channel_id), WjetsData(_WjetsData)
{
TH1::SetDefaultSumw2();

Expand Down Expand Up @@ -216,12 +217,14 @@ class BaseFlatTreeAnalyzer {
}
}

virtual const std::string& ChannelName() = 0;
virtual Channel ChannelId() = 0;

virtual EventType_QCD DetermineEventTypeForQCD(const ntuple::Flat& event) = 0;
virtual EventType_Wjets DetermineEventTypeForWjets(const ntuple::Flat& event) = 0;
virtual bool PassMvaCut(const FlatEventInfo& eventInfo, EventCategory eventCategory) = 0;

const std::string& ChannelName() const { return detail::ChannelNameMap.at(ChannelId()); }

virtual EventCategoryVector DetermineEventCategories(const ntuple::Flat& event)
{
EventCategoryVector categories;
Expand Down Expand Up @@ -419,10 +422,11 @@ class BaseFlatTreeAnalyzer {
for(const DataCategory* dataCategory : dataCategoryCollection.GetCategories(DataCategoryType::Limits)) {
if(!dataCategory->datacard.size())
throw exception("Empty datacard name for data category '") << dataCategory->name << "'.";
FlatAnalyzerData& anaData = anaDataForCategory[dataCategory->name].QCD[EventType_QCD::OS_Isolated];
FlatAnalyzerData& anaData = anaDataForCategory[dataCategory->name].Signal();
TH1D* hist_orig = anaData.GetPtr<TH1D>(hist_name);
if(!hist_orig)
throw exception("Datacard histogram '") << hist_name << "' not found.";
throw exception("Datacard histogram '") << hist_name << "' not found for data category '"
<< dataCategory->name << "'.";
std::shared_ptr<TH1D> hist(static_cast<TH1D*>(hist_orig->Clone()));
hist->Scale(dataCategory->limits_sf);
hist->Write(dataCategory->datacard.c_str());
Expand All @@ -432,13 +436,15 @@ class BaseFlatTreeAnalyzer {

TH1D* hist_up_orig = anaData.GetPtr<TH1D>(hist_name_up);
if(!hist_up_orig)
throw exception("Datacard histogram '") << hist_name_up << "' not found.";
throw exception("Datacard histogram '") << hist_name_up << "' not found for data category '"
<< dataCategory->name << "'.";
std::shared_ptr<TH1D> hist_up(static_cast<TH1D*>(hist_up_orig->Clone()));
hist_up->Scale(dataCategory->limits_sf);
hist_up->Write(nameUp.c_str());
TH1D* hist_down_orig = anaData.GetPtr<TH1D>(hist_name_down);
if(!hist_down_orig)
throw exception("Datacard histogram '") << hist_name_down << "' not found.";
throw exception("Datacard histogram '") << hist_name_down << "' not found for data category '"
<< dataCategory->name << "'.";
std::shared_ptr<TH1D> hist_down(static_cast<TH1D*>(hist_down_orig->Clone()));
hist_down->Scale(dataCategory->limits_sf);
hist_down->Write(nameDown.c_str());
Expand Down
8 changes: 2 additions & 6 deletions Analysis/source/FlatTreeAnalyzer_mutau.C
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@ class FlatTreeAnalyzer_mutau : public analysis::BaseFlatTreeAnalyzer {
public:
FlatTreeAnalyzer_mutau(const std::string& source_cfg, const std::string& hist_cfg, const std::string& _inputPath,
const std::string& outputFileName, const std::string& signal_list, bool _WjetsData = false)
: BaseFlatTreeAnalyzer(source_cfg, hist_cfg, _inputPath, outputFileName, ChannelName(), signal_list, _WjetsData)
: BaseFlatTreeAnalyzer(source_cfg, hist_cfg, _inputPath, outputFileName, ChannelId(), signal_list, _WjetsData)
{
}

protected:
virtual const std::string& ChannelName() override
{
static const std::string channelName = "muTau";
return channelName;
}
virtual analysis::Channel ChannelId() override { return analysis::Channel::MuTau; }

virtual analysis::EventType_QCD DetermineEventTypeForQCD(const ntuple::Flat& event) override
{
Expand Down
2 changes: 1 addition & 1 deletion Analysis/source/HHbbetau_FlatTreeProducer.C
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ protected:
BaseFlatTreeProducer::FillFlatTree(higgs, svfitResults, kinfitResults, jets, jetsPt20, bjets_all, retagged_bjets,
vertices, electron, tau, pfMET, eTau_MC);

flatTree->channel() = static_cast<int>(ntuple::Channel::ETau);
flatTree->channel() = static_cast<int>(analysis::Channel::ETau);
flatTree->pfRelIso_1() = ntuple_electron.pfRelIso;
flatTree->mva_1() = ntuple_electron.mvaPOGNonTrig;
flatTree->passid_1() = true;
Expand Down
2 changes: 1 addition & 1 deletion Analysis/source/HHbbmutau_FlatTreeProducer.C
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ protected:
retagged_bjets, vertices, muon, tau, pfMET, muTau_MC);


flatTree->channel() = static_cast<int>(ntuple::Channel::MuTau);
flatTree->channel() = static_cast<int>(analysis::Channel::MuTau);
flatTree->pfRelIso_1() = ntuple_muon.pfRelIso;
flatTree->mva_1() = 0;
flatTree->passid_1() = true;
Expand Down
2 changes: 1 addition & 1 deletion Analysis/source/HHbbtautau_FlatTreeProducer.C
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ protected:
BaseFlatTreeProducer::FillFlatTree(higgs, svfitResults, kinfitResults, jets, jetsPt20,
bjets_all, retagged_bjets, vertices, leadTau, subLeadTau, pfMET, tauTau_MC);

flatTree->channel() = static_cast<int>(ntuple::Channel::TauTau);
flatTree->channel() = static_cast<int>(analysis::Channel::TauTau);
flatTree->pfRelIso_1() = default_value;
flatTree->mva_1() = default_int_value;
flatTree->passid_1() = false;
Expand Down
64 changes: 64 additions & 0 deletions AnalysisBase/include/AnalysisTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*!
* \file AnalysisMath.h
* \brief Common simple types for analysis purposes.
* \author Konstantin Androsov (Siena University, INFN Pisa)
* \author Maria Teresa Grippo (Siena University, INFN Pisa)
* \date 2014-10-09 created
*
* Copyright 2014 Konstantin Androsov <[email protected]>,
* Maria Teresa Grippo <[email protected]>
*
* This file is part of X->HH->bbTauTau.
*
* X->HH->bbTauTau is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* X->HH->bbTauTau is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with X->HH->bbTauTau. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <iostream>
#include <map>

#include "exception.h"

namespace analysis {

enum class Channel { ETau = 0, MuTau = 1, TauTau = 2 };

namespace detail {
std::map<Channel, std::string> ChannelNameMap = {
{ Channel::ETau, "eTau" }, { Channel::MuTau, "muTau" }, { Channel::TauTau, "tauTau" }
};
} // namespace detail

std::ostream& operator<< (std::ostream& s, const Channel& c)
{
s << detail::ChannelNameMap.at(c);
return s;
}

std::istream& operator>> (std::istream& s, Channel& c)
{
std::string name;
s >> name;
for(const auto& map_entry : detail::ChannelNameMap) {
if(map_entry.second == name) {
c = map_entry.first;
return s;
}
}
throw exception("Unknown channel name '") << name << "'.";
}


} // namespace analysis
3 changes: 1 addition & 2 deletions AnalysisBase/include/FlatTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
SIMPLE_VAR(Int_t, run) /* Run */ \
SIMPLE_VAR(Int_t, lumi) /* Lumi */ \
SIMPLE_VAR(Int_t, evt) /* Event */ \
SIMPLE_VAR(Int_t, channel) /* Analysis channel as defined in ntuple::Channel */ \
SIMPLE_VAR(Int_t, channel) /* Analysis channel as defined in analysis::Channel */ \
SIMPLE_VAR(Int_t, eventType) /* event type category */ \
\
\
Expand Down Expand Up @@ -240,6 +240,5 @@ TREE_CLASS_INITIALIZE(ntuple, FlatTree, FLAT_DATA)
namespace ntuple {
inline float DefaultFloatFillValueForFlatTree() { return std::numeric_limits<float>::lowest(); }
inline int DefaultIntegerFillValueForFlatTree() { return std::numeric_limits<int>::lowest(); }
enum class Channel { ETau = 0, MuTau = 1, TauTau = 2 };
enum class EventType { Unknown = 0, ZL = 1, ZJ = 2, ZTT = 3, OtherZ = 4 };
}
1 change: 1 addition & 0 deletions HHbbTauTau.files
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,4 @@ RunTools/config/known_issues.supp
AnalysisBase/include/FlatEventInfo.h
Analysis/include/LightBaseFlatTreeAnalyzer.h
Analysis/source/LightFlatTreeAnalyzer_mutau.C
AnalysisBase/include/AnalysisTypes.h
1 change: 1 addition & 0 deletions MVASelections/include/MvaReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "AnalysisBase/include/AnalyzerData.h"
#include "AnalysisBase/include/FlatTree.h"
#include "AnalysisBase/include/AnalysisMath.h"
#include "AnalysisBase/include/AnalysisTypes.h"
#include "AnalysisBase/include/exception.h"
#include "AnalysisBase/include/Particles.h"

Expand Down
Loading

0 comments on commit 560e9b0

Please sign in to comment.