-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyze.C
339 lines (279 loc) · 12.7 KB
/
analyze.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#include "UserCode/TopFromHeavyIons/interface/genParticleProducer.h"
#include "UserCode/TopFromHeavyIons/interface/hiEventProducer.h"
#include "UserCode/TopFromHeavyIons/interface/lwMuonProducer.h"
#include "UserCode/TopFromHeavyIons/interface/pfParticleProducer.h"
#include "UserCode/TopFromHeavyIons/interface/LWJetProducer.h"
#include "UserCode/TopFromHeavyIons/interface/lwJetContainer.h"
#include "UserCode/TopFromHeavyIons/interface/lwJetFromForestProducer.h"
#include "UserCode/TopFromHeavyIons/interface/anaBaseTask.h"
#include "UserCode/TopFromHeavyIons/interface/anaJetQA.h"
#include "UserCode/TopFromHeavyIons/interface/anaRhoProducer.h"
#include "UserCode/TopFromHeavyIons/interface/anaMET.h"
#include "UserCode/TopFromHeavyIons/interface/anaMuonIsolation.h"
#include "UserCode/TopFromHeavyIons/interface/anaMuonMatcher.h"
#include "UserCode/TopFromHeavyIons/interface/anaPuppiProducer.h"
#include "UserCode/TopFromHeavyIons/interface/anaZToMuMu.h"
#include <TList.h>
#include <TChain.h>
#include <TFile.h>
//#include "CollectFiles.C"
#include <iostream>
using namespace std;
Bool_t doMuonIsolation = kTRUE;//kFALSE;
Bool_t doPuppi = kTRUE;//kFALSE;
void analyze(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1) {
// std::vector<std::string> urls = CollectFiles(list);
// Printf("anaFile: %d",anaFile);
std::cout << "nfiles: " << urls.size() << std::endl;
// for (auto i = urls.begin(); i != urls.end(); ++i)
// std::cout << *i << std::endl;
size_t firstFile = 0;
size_t lastFile = urls.size();
if(firstF>-1) {
firstFile = (size_t)firstF;
lastFile = (size_t)lastF;
}
std::cout << "firstFile: " << firstFile << " lastFile: " << lastFile << std::endl;
//add files to chain
TChain *chain = NULL;
chain = new TChain("hiEvtAnalyzer/HiTree");
for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
Printf("hiTree done");
TChain *pfTree = new TChain("pfcandAnalyzer/pfTree");
for(size_t i=firstFile; i<lastFile; i++) pfTree->Add(urls[i].c_str());
chain->AddFriend(pfTree);
Printf("pfTree done");
TChain *muTree = new TChain("hltMuTree/HLTMuTree");
for(size_t i=firstFile; i<lastFile; i++) muTree->Add(urls[i].c_str());
chain->AddFriend(muTree);
Printf("muTree done");
TChain *jetTree = new TChain("akPu3PFJetAnalyzer/t");
for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
chain->AddFriend(jetTree);
Printf("jetTree done");
TChain *genTree = new TChain("HiGenParticleAna/hi");
for(size_t i=firstFile; i<lastFile; i++) genTree->Add(urls[i].c_str());
chain->AddFriend(genTree);
Printf("genTree done");
TList *fEventObjects = new TList();
//---------------------------------------------------------------
// producers
//
hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
p_evt->SetInput(chain);
p_evt->SetHIEventContName("hiEventContainer");
p_evt->SetEventObjects(fEventObjects);
pfParticleProducer *p_pf = new pfParticleProducer("pfPartProd");
p_pf->SetInput(chain);
p_pf->SetpfParticlesName("pfParticles");
p_pf->SetEventObjects(fEventObjects);
lwMuonProducer *p_mu = new lwMuonProducer("lwMuonProd");
p_mu->SetInput(chain);
p_mu->SetlwMuonsRecoName("lwMuonsReco");
p_mu->SetlwMuonsGeneName("lwMuonsGene");
p_mu->SetEventObjects(fEventObjects);
genParticleProducer *p_gen = new genParticleProducer("genParticleProd");
p_gen->SetInput(chain);
p_gen->SetGenParticlesName("genParticles");
p_gen->SetEventObjects(fEventObjects);
lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
p_PUJet->SetInput(chain);
p_PUJet->SetJetContName("aktPUR030");
p_PUJet->SetEventObjects(fEventObjects);
//anti-kt jet finder
LWJetProducer *lwjakt = new LWJetProducer("LWJetProducerAKTR030");
lwjakt->SetInput(chain);
lwjakt->SetEventObjects(fEventObjects);
lwjakt->SetJetType(LWJetProducer::kAKT);
lwjakt->SetRadius(0.3);
lwjakt->SetGhostArea(0.005);
lwjakt->SetPtMinConst(0.);
lwjakt->SetParticlesName("pfParticles");
lwjakt->SetJetContName("JetsAKTR030");
//kt jet finder
LWJetProducer *lwjkt = new LWJetProducer("LWJetProducerKTR020");
lwjkt->SetInput(chain);
lwjkt->SetEventObjects(fEventObjects);
lwjkt->SetJetType(LWJetProducer::kKT);
lwjkt->SetRadius(0.2);
lwjkt->SetGhostArea(0.005);
lwjkt->SetPtMinConst(0.);
lwjkt->SetParticlesName("pfParticles");
lwjkt->SetJetContName("JetsKTR020");
//---------------------------------------------------------------
//analysis modules
//
//handler to which all modules will be added
anaBaseTask *handler = new anaBaseTask("handler","handler");
//analysis modules which also produce
anaRhoProducer *rhoProd = new anaRhoProducer("anaRhoProducerKTR020","anaRhoProducerKTR020");
rhoProd->ConnectEventObject(fEventObjects);
rhoProd->SetJetsName("JetsKTR020");
rhoProd->SetHiEvtName("hiEventContainer");
rhoProd->SetNExcl(2);
rhoProd->SetEtaRangeAll(-5.+0.2,5.-0.2);
handler->Add(rhoProd);
anaPuppiProducer *pupProd = new anaPuppiProducer("pupProd","pupProd");
pupProd->ConnectEventObject(fEventObjects);
pupProd->SetHiEvtName("hiEventContainer");
pupProd->SetPFPartName("pfParticles");
pupProd->SetJetsName("aktPUR030");
if(doPuppi) handler->Add(pupProd); //needed for isolation and MET
//Initialization of all analysis modules
anaJetQA *jetQA = new anaJetQA("anaJetQAAKTPUR030","anaJetQAAKTPUR030");
jetQA->ConnectEventObject(fEventObjects);
jetQA->SetJetsName("aktPUR030");
handler->Add(jetQA);
anaMuonMatcher *muMatchGen = new anaMuonMatcher("muMatchGen","muMatchGen");
muMatchGen->ConnectEventObject(fEventObjects);
muMatchGen->SetMuonsName("lwMuonsReco");
muMatchGen->SetMatchName("lwMuonsGene");
muMatchGen->SetMatchType(anaMuonMatcher::kGen);
handler->Add(muMatchGen);
anaMuonMatcher *muMatchPF = new anaMuonMatcher("muMatchPF","muMatchPF");
muMatchPF->ConnectEventObject(fEventObjects);
muMatchPF->SetMuonsName("lwMuonsReco");
muMatchPF->SetMatchName("pfParticles");
muMatchPF->SetMatchType(anaMuonMatcher::kPF);
handler->Add(muMatchPF);
//Muon isolation
anaMuonIsolation *muonIsoRaw = new anaMuonIsolation("muonIsoRaw","muonIsoRaw");
muonIsoRaw->ConnectEventObject(fEventObjects);
muonIsoRaw->SetHiEvtName("hiEventContainer");
muonIsoRaw->SetMuonsName("lwMuonsReco");
muonIsoRaw->SetMuonsGenName("lwMuonsGene");
muonIsoRaw->SetPFPartName("pfParticles");
muonIsoRaw->SetIsolationType(anaMuonIsolation::kRaw);
anaMuonIsolation *muonIsoVS = new anaMuonIsolation("muonIsoVS","muonIsoVS");
muonIsoVS->ConnectEventObject(fEventObjects);
muonIsoVS->SetHiEvtName("hiEventContainer");
muonIsoVS->SetMuonsName("lwMuonsReco");
muonIsoVS->SetMuonsGenName("lwMuonsGene");
muonIsoVS->SetPFPartName("pfParticles");
muonIsoVS->SetIsolationType(anaMuonIsolation::kVS);
anaMuonIsolation *muonIsoArea = new anaMuonIsolation("muonIsoArea","muonIsoArea");
muonIsoArea->ConnectEventObject(fEventObjects);
muonIsoArea->SetHiEvtName("hiEventContainer");
muonIsoArea->SetMuonsName("lwMuonsReco");
muonIsoArea->SetMuonsGenName("lwMuonsGene");
muonIsoArea->SetPFPartName("pfParticles");
muonIsoArea->SetIsolationType(anaMuonIsolation::kArea);
muonIsoArea->SetRhoMapName("rhoMap");
anaMuonIsolation *muonIsoCS = new anaMuonIsolation("muonIsoCS","muonIsoCS");
muonIsoCS->ConnectEventObject(fEventObjects);
muonIsoCS->SetHiEvtName("hiEventContainer");
muonIsoCS->SetMuonsName("lwMuonsReco");
muonIsoCS->SetMuonsGenName("lwMuonsGene");
muonIsoCS->SetPFPartName("pfParticles");
muonIsoCS->SetIsolationType(anaMuonIsolation::kCS);
muonIsoCS->SetRhoMapName("rhoMap");
anaMuonIsolation *muonIsoPuppi = new anaMuonIsolation("muonIsoPuppi","muonIsoPuppi");
muonIsoPuppi->ConnectEventObject(fEventObjects);
muonIsoPuppi->SetHiEvtName("hiEventContainer");
muonIsoPuppi->SetMuonsName("lwMuonsReco");
muonIsoPuppi->SetMuonsGenName("lwMuonsGene");
muonIsoPuppi->SetPFPartName("pfParticles");
muonIsoPuppi->SetIsolationType(anaMuonIsolation::kPuppi);
// anaMuonIsolation *muonIsoGen = new anaMuonIsolation("muonIsoGen","muonIsoGen");
// muonIsoGen->ConnectEventObject(fEventObjects);
// muonIsoGen->SetHiEvtName("hiEventContainer");
// muonIsoGen->SetMuonsName("lwMuonsGene");
// muonIsoGen->SetMuonsGenName("");
// muonIsoGen->SetPFPartName("genParticles");
// muonIsoGen->SetIsolationType(anaMuonIsolation::kGen);
if(doMuonIsolation) {
handler->Add(muonIsoRaw);
handler->Add(muonIsoVS);
handler->Add(muonIsoArea);
handler->Add(muonIsoCS);
if(doPuppi) handler->Add(muonIsoPuppi);
}
anaMET *metPFRaw = new anaMET("metPFRaw","metPFRaw");
metPFRaw->ConnectEventObject(fEventObjects);
metPFRaw->SetHiEvtName("hiEventContainer");
metPFRaw->SetParticlesName("pfParticles");
metPFRaw->SetMetType(anaMET::kPFRaw);
handler->Add(metPFRaw);
anaMET *metVS = new anaMET("metVS","metVS");
metVS->ConnectEventObject(fEventObjects);
metVS->SetHiEvtName("hiEventContainer");
metVS->SetParticlesName("pfParticles");
metVS->SetMetType(anaMET::kVS);
handler->Add(metVS);
anaMET *metPuppi = new anaMET("metPuppi","metPuppi");
metPuppi->ConnectEventObject(fEventObjects);
metPuppi->SetHiEvtName("hiEventContainer");
metPuppi->SetParticlesName("pfParticles");
metPuppi->SetMetType(anaMET::kPuppi);
if(doPuppi) handler->Add(metPuppi);
anaMET *metGen = new anaMET("metGen","metGen");
metGen->ConnectEventObject(fEventObjects);
metGen->SetHiEvtName("hiEventContainer");
metGen->SetParticlesName("genParticles");
metGen->SetMetType(anaMET::kGen);
handler->Add(metGen);
anaZToMuMu *ZToMuMu = new anaZToMuMu("ZToMuMu","ZToMuMu");
ZToMuMu->ConnectEventObject(fEventObjects);
ZToMuMu->SetHiEvtName("hiEventContainer");
ZToMuMu->SetMuonsName("lwMuonsReco");
handler->Add(ZToMuMu);
anaZToMuMu *ZToMuMuGen = new anaZToMuMu("ZToMuMuGen","ZToMuMuGen");
ZToMuMuGen->ConnectEventObject(fEventObjects);
ZToMuMuGen->SetHiEvtName("hiEventContainer");
ZToMuMuGen->SetMuonsName("lwMuonsGene");
ZToMuMuGen->SetCheckPid(kTRUE);
handler->Add(ZToMuMuGen);
anaZToMuMu *ZToMuMuGenAll = new anaZToMuMu("ZToMuMuGenAll","ZToMuMuGenAll");
ZToMuMuGenAll->ConnectEventObject(fEventObjects);
ZToMuMuGenAll->SetHiEvtName("hiEventContainer");
ZToMuMuGenAll->SetMuonsName("genParticles");
ZToMuMuGenAll->SetCheckPid(kTRUE);
handler->Add(ZToMuMuGenAll);
//---------------------------------------------------------------
//output tree
// TTree *tree_out = new TTree("tree_out","lwTree");
//tree_out->Branch("EventObjects",&fEventObjects);
Long64_t entries_tot = chain->GetEntriesFast(); //93064
if(nentries<0) nentries = chain->GetEntries();
// Long64_t nentries = 20;//chain->GetEntriesFast();
Printf("nentries: %lld tot: %lld",nentries,entries_tot);
for (Long64_t jentry=0; jentry<nentries;jentry++) {
//Run producers
p_evt->Run(jentry); //hi event properties
p_pf->Run(jentry); //pf particles
p_mu->Run(jentry); //muons
p_gen->Run(jentry); //generated particles
p_PUJet->Run(jentry); //forest jets
// lwjakt->FindJets(); //anti-kt jets
lwjkt->FindJets(); //kt jets
//Execute all analysis tasks
handler->ExecuteTask();
//tree_out->Fill();
}
fEventObjects->Print();
TFile *out = new TFile(outname,"RECREATE");
TList *tasks = handler->GetListOfTasks();
TIter next(tasks);
anaBaseTask *obj;
while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
// rhoProd->GetOutput()->Write(rhoProd->GetName(),TObject::kSingleKey);
// // pupProd->GetOutput()->Write(pupProd->GetName(),TObject::kSingleKey);
// jetQA->GetOutput()->Write(jetQA->GetName(),TObject::kSingleKey);
// muMatchGen->GetOutput()->Write(muMatchGen->GetName(),TObject::kSingleKey);
// muMatchPF->GetOutput()->Write(muMatchPF->GetName(),TObject::kSingleKey);
// if(doMuonIsolation) {
// muonIsoRaw->GetOutput()->Write(muonIsoRaw->GetName(),TObject::kSingleKey);
// muonIsoVS->GetOutput()->Write(muonIsoVS->GetName(),TObject::kSingleKey);
// muonIsoArea->GetOutput()->Write(muonIsoArea->GetName(),TObject::kSingleKey);
// muonIsoCS->GetOutput()->Write(muonIsoCS->GetName(),TObject::kSingleKey);
// muonIsoPuppi->GetOutput()->Write(muonIsoPuppi->GetName(),TObject::kSingleKey);
// }
// metPFRaw->GetOutput()->Write(metPFRaw->GetName(),TObject::kSingleKey);
// metVS->GetOutput()->Write(metVS->GetName(),TObject::kSingleKey);
// //metPuppi->GetOutput()->Write(metPuppi->GetName(),TObject::kSingleKey);
// ZToMuMu->GetOutput()->Write(ZToMuMu->GetName(),TObject::kSingleKey);
// ZToMuMuGen->GetOutput()->Write(ZToMuMuGen->GetName(),TObject::kSingleKey);
out->Write();
out->Close();
}