forked from miquork/jetphys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk_HistosFill.C
executable file
·249 lines (227 loc) · 8.24 KB
/
mk_HistosFill.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
// Purpose: Fill jet physics analysis histograms
// Author: mikko.voutilainen@cern.ch
// Co-author: hannu.siikonen@cern.ch
// Created: March 20, 2010
#include "CondFormats/JetMETObjects/src/Utilities.cc"
#include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
#include "CondFormats/JetMETObjects/interface/SimpleJetCorrector.h"
#include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h"
// For JEC uncertainty
#include "CondFormats/JetMETObjects/interface/SimpleJetCorrectionUncertainty.h"
#include "CondFormats/JetMETObjects/interface/JetCorrectionUncertainty.h"
#include "settings.h"
#include "tools.h"
#include "HistosRun.h"
#include "HistosBasic.h"
#include "HistosEta.h"
#include "HistosMC.h"
#include "HistosAll.h"
#include "HistosFill.h"
R__LOAD_LIBRARY(CondFormats/JetMETObjects/src/JetCorrectorParameters.cc+)
R__LOAD_LIBRARY(CondFormats/JetMETObjects/src/SimpleJetCorrector.cc+)
R__LOAD_LIBRARY(CondFormats/JetMETObjects/src/FactorizedJetCorrector.cc+)
R__LOAD_LIBRARY(CondFormats/JetMETObjects/src/SimpleJetCorrectionUncertainty.cc+)
R__LOAD_LIBRARY(CondFormats/JetMETObjects/src/JetCorrectionUncertainty.cc+)
#if JETRESO == 1
R__LOAD_LIBRARY(CondFormats/JetMETObjects/src/JetResolutionObject.cc+)
R__LOAD_LIBRARY(JetMETCorrections/Modules/src/JetResolution.cc+)
#endif
#ifdef USEASSERT
R__LOAD_LIBRARY(tools.C+g)
R__LOAD_LIBRARY(HistosRun.C+g)
R__LOAD_LIBRARY(HistosBasic.C+g)
R__LOAD_LIBRARY(HistosEta.C+g)
R__LOAD_LIBRARY(HistosMC.C+g)
R__LOAD_LIBRARY(Histos2D.C+g)
R__LOAD_LIBRARY(HistosAll.C+g)
R__LOAD_LIBRARY(HistosFill.C+g)
#else
R__LOAD_LIBRARY(tools.C+)
R__LOAD_LIBRARY(HistosRun.C+)
R__LOAD_LIBRARY(HistosBasic.C+)
R__LOAD_LIBRARY(HistosEta.C+)
R__LOAD_LIBRARY(HistosMC.C+)
R__LOAD_LIBRARY(Histos2D.C+)
R__LOAD_LIBRARY(HistosAll.C+)
R__LOAD_LIBRARY(HistosFill.C+)
#endif // USEASSERT or not?
void mk_HistosFill() {
bool fail = false;
// Performing generic checks always, as a safety measure
if (jp::triggers.size()!=jp::notrigs) {
cout << "jp::trigger size mismatch" << endl;
fail = true;
}
if (jp::trigthr.size()!=jp::notrigs) {
cout << "jp::trigthr size mismatch" << endl;
fail = true;
}
if (jp::trigranges.size()!=jp::notrigs) {
cout << "jp::trigranges size mismatch" << endl;
fail = true;
}
if (jp::triglumi.size()!=jp::notrigs) {
cout << "jp::triglumi size mismatch" << endl;
fail = true;
}
if (jp::triglumi.size()!=jp::notrigs) {
cout << "jp::triglumi size mismatch" << endl;
fail = true;
}
if (jp::IOVnames.size()!=jp::IOVranges.size()) {
cout << "IOV count mismatch in jp::IOVnames and jp::IOVranges" << endl;
fail = true;
}
if (jp::triglumiera.size()!=jp::dtfiles.size()) {
cout << "Mismatch between data files and lumi era" << endl;
fail = true;
}
for (auto &lumis : jp::triglumiera) {
if (lumis.size()!=jp::notrigs) {
cout << "jp::triglumiera size mismatch with triggers!" << endl;
fail = true;
}
}
if (jp::eras.size()<jp::dtfiles.size()) {
cout << "Amount of eras not sufficient! (jp::eras)" << endl;
fail = true;
}
if (jp::eras.size()<jp::dtfiles.size()) {
cout << "Amount of eras not sufficient! (jp::eras)" << endl;
fail = true;
}
// Check that pthat file dimensions are ok
if (jp::pthatfiles.size()<jp::npthatbins) {
cout << "The pthat info dimensions don't match! jp::pthatfiles vs jp::npthatbins" << endl;
fail = true;
} else if (jp::pthatsigmas.size()!=jp::npthatbins) {
cout << "The pthat info dimensions don't match! jp::pthatsigmas vs jp::npthatbins" << endl;
fail = true;
} else if (jp::pthatranges.size()!=jp::npthatbins+1) {
cout << "The pthat info dimensions don't match! jp::pthatranges vs jp::npthatbins" << endl;
fail = true;
}
// Check that ht file dimensions are ok
if (jp::htfiles.size()<jp::nhtbins) {
cout << "The ht info dimensions don't match! jp::htfiles vs jp::nhtbins" << endl;
fail = true;
} else if (jp::htsigmas.size()!=jp::nhtbins) {
cout << "The ht info dimensions don't match! jp::htsigmas vs jp::nhtbins" << endl;
fail = true;
} else if (jp::htranges.size()!=jp::nhtbins+1) {
cout << "The ht info dimensions don't match! jp::htranges vs jp::nhtbins" << endl;
fail = true;
}
if (fail) return;
// Find out era index
int eraIdx = -1;
int eraNo = 0;
for (auto &eraMatch : jp::eras) {
if (jp::run==eraMatch) {
eraIdx = eraNo;
break;
}
++eraNo;
}
if (eraIdx<0) {
cout << "Era " << jp::run << " not found! Aborting!" << endl;
return;
}
string algo = "ak4";
if (jp::strings_equal(jp::algo,"AK8")) algo = "ak8";
// connect trees
TChain *c = new TChain(Form("%s/ProcessedTree",algo.c_str()));
const char* p = jp::filepath;
vector<const char*> files;
if (jp::isdt) {
cout << "Running over DT" << endl;
cout << "Load trees..." << endl;
if (eraIdx>=jp::dtfiles.size()) {
cout << "Era index for " << jp::run << " does not match to a data file! Please retry!" << endl;
return;
}
const char* ps = jp::dtpath;
for (auto &fname : jp::dtfiles[eraIdx])
files.push_back(Form("%s%s%s",p,ps,fname.c_str()));
} else if (jp::ispy) {
if (jp::pthatbins) {
cout << "Running over pthat binned files in pythia8" << endl;
cout << "Load trees..." << endl;
const char *ps = jp::pthatpath;
for (auto &fname : jp::pthatfiles) {
const char *name1 = Form("%s%s%s.root",p,ps,fname);
const char *name2 = Form("%s%s%s_ext.root",p,ps,fname);
std::ifstream stream1(name1);
std::ifstream stream2(name2);
if (stream1.good()) files.push_back(name1);
if (stream2.good()) files.push_back(name2);
}
} else if (jp::htbins) {
cout << "Running over ht binned files in pythia8" << endl;
cout << "Load trees..." << endl;
const char *ps = jp::htpath;
for (auto &fname : jp::htfiles) {
const char *name1 = Form("%s%s%s.root",p,ps,fname);
const char *name2 = Form("%s%s%s_ext.root",p,ps,fname);
std::ifstream stream1(name1);
std::ifstream stream2(name2);
if (stream1.good()) files.push_back(name1);
if (stream2.good()) files.push_back(name2);
}
} else {
cout << "Running over pythia flat sample" << endl;
for (auto &fname : jp::mcfiles.at(jp::p8file))
files.push_back(Form("%s%s",p,fname));
}
} else if (jp::ishw) {
if (jp::pthatbins) cout << "No pthat binned files exist for Herwig!" << endl;
else if (jp::htbins) cout << "No ht binned files exist for Herwig!" << endl;
cout << "Running over Herwig flat sample" << endl;
for (auto &fname : jp::mcfiles.at(jp::hwfile)) files.push_back(Form("%s%s",p,fname));
} else if (jp::isnu) {
if (jp::pthatbins) cout << "No pthat binned files exist for Neutrino Gun!" << endl;
else if (jp::htbins) cout << "No ht binned files exist for Neutrino Gun!" << endl;
cout << "Running over HSingle Neutrino sample" << endl;
for (auto &fname : jp::mcfiles.at(jp::nufile)) files.push_back(Form("%s%s",p,fname));
} else {
cout << "Enter a proper type!!" << endl;
}
if (files.size()==0) {
if (jp::isdt) {
cout << "Enter a proper value for run!" << endl;
cout << "Entered: " << jp::run << endl << "Options:";
for (auto &fname : jp::eras) cout << " " << fname;
cout << endl;
} else if (jp::ispy or jp::ishw or jp::isnu) {
if (jp::pthatbins) {
cout << "Problems with pthat file logic!" << endl;
} else if (jp::htbins) {
cout << "Problems with ht file logic!" << endl;
} else {
cout << "Enter a proper value for MC tag!" << endl;
cout << "Entered: " << jp::p8file << endl << "Options:";
for (auto &fname : jp::mcfiles) cout << " " << fname.first;
cout << endl;
}
}
} else {
cout << "Loading the files:" << endl;
for (auto &fname : files) {
cout << fname << endl;
c->AddFile(fname);
}
}
int centries = c->GetEntries();
cout << "Got " << centries << " entries" << endl;
if (centries > 0) {
try {
HistosFill filler(c,eraIdx);
filler.Loop();
} catch (const exception& e) {
cout << e.what() << endl;
}
} else {
cout << "Please specify files to be looped over!" << endl << "Exiting ..." << endl;
}
gROOT->ProcessLine(".q");
}