-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProdTemplate.C
166 lines (147 loc) · 4.25 KB
/
ProdTemplate.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <iostream>
#include <unordered_set>
#include <boost/algorithm/string/replace.hpp>
#include <TString.h>
#include <TH1F.h>
#include <TFile.h>
namespace
{
const std::unordered_set<std::string> blackList{};
} // namespace
bool ProdTemplate(const TString& inputdistrib,
const std::vector<TString>& sampleList,
const std::vector<TString>& systList,
const TString& intputfilename,
const bool theta,
const bool pseudodata)
{
TFile* inputfile{new TFile{intputfilename.Data()}};
TH1F* histBdt_DataEG;
TH1F* histBdt_DataMu;
std::vector<TH1F*> distrib_MC;
std::vector<TH1F*> distrib_MC_sys;
//deal with nominal templates
for(const auto& sample: sampleList)
{
TH1F* tmp{dynamic_cast<TH1F*>
(inputfile->Get((inputdistrib + "__" + sample).Data())->Clone())};
if(!tmp)
{
cout << "non existing histogram " <<
inputdistrib+"__"+sample << endl;
return false;
}
else if (tmp->GetEntries() > 0
&& blackList.find(tmp->GetName()) == blackList.end())
{
cout << inputdistrib + "__"+ sample << endl;
distrib_MC.emplace_back(tmp);
}
}
//deal with systematic templates
for(const auto& sample: sampleList)
{
if(sample == "DataMu" || sample == "DataEG")
{
continue;
}
for(const auto& syst: systList)
{
TH1F* tmp{dynamic_cast<TH1F*>
(inputfile->
Get((inputdistrib + "__" + sample + syst).Data())->Clone())};
if (tmp->GetEntries() > 0
&& blackList.find(tmp->GetName()) == blackList.end())
{
cout << inputdistrib + "__" + sample + syst << endl;
distrib_MC_sys.emplace_back(tmp);
}
}
}
TString analysisProg;
if (theta)
{
analysisProg = "theta";
}
else
{
analysisProg = "combine";
}
TString outputfilename{"TemplateRootFiles/" + inputdistrib + "_" +
analysisProg + ".root"};
TFile* outputfile{new TFile{outputfilename.Data(), "recreate"}};
outputfile->cd();
if (pseudodata)
{
histBdt_DataMu = dynamic_cast<TH1F*>
(inputfile->Get((inputdistrib+"__DATA").Data())->Clone());
}
else
{
histBdt_DataEG= dynamic_cast<TH1F*>
(inputfile->Get((inputdistrib+"__DataEG").Data())->Clone());
histBdt_DataMu = dynamic_cast<TH1F*>
(inputfile->Get((inputdistrib+"__DataMu").Data())->Clone());
histBdt_DataMu->Add(histBdt_DataEG);
}
if (theta)
{
histBdt_DataMu->Write((inputdistrib+"__DATA").Data() );
}
else
{
histBdt_DataMu->Write((inputdistrib+"__data_obs").Data() );
}
for(auto& distrib: distrib_MC)
{
distrib->Write();
}
for(auto& distrib: distrib_MC_sys)
{
std::string name{distrib->GetName()};
if (!theta)
{
boost::replace_last(name, "__minus", "Down");
boost::replace_last(name, "__plus", "Up");
}
distrib->SetName(name.c_str());
distrib->Write();
}
return true;
}
void ProdTemplate(const bool theta=false, const bool pseudodata=true)
{
const std::vector<TString> sampleList{
"DYToLL_M50",
"TbartChan",
"TbartW",
"TT",
"TtW",
"TTW",
"tZq",
"TTZ",
"ZZ"};
const std::vector<TString> systList{
"__pileup__plus",
"__pileup__minus",
"__trig__plus",
"__trig__minus",
"__bTag__plus",
"__bTag__minus",
"__met__plus",
"__met__minus",
"__pdf__plus",
"__pdf__minus",
"__jes__plus",
"__jes__minus",
"__jer__plus",
"__jer__minus",
"__ME_PS__plus",
"__ME_PS__minus"};
// ProdTemplate("MVA_all", sampleList, systList,
// "outputroot/output_merged.root", theta, pseudodata);
ProdTemplate("MVA_ee", sampleList, systList,
"outputroot/output_merged_ee.root", theta, pseudodata);
ProdTemplate("MVA_mumu", sampleList, systList,
"outputroot/output_merged_mumu.root", theta, pseudodata);
}