-
Notifications
You must be signed in to change notification settings - Fork 2
/
analyzeJES.C
207 lines (173 loc) · 7.39 KB
/
analyzeJES.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
#include "UserCode/diall/interface/genParticleProducer.h"
#include "UserCode/diall/interface/hiEventProducer.h"
#include "UserCode/diall/interface/lwMuonProducer.h"
#include "UserCode/diall/interface/pfParticleProducer.h"
#include "UserCode/diall/interface/LWJetProducer.h"
#include "UserCode/diall/interface/lwJetContainer.h"
#include "UserCode/diall/interface/lwJetFromForestProducer.h"
#include "UserCode/diall/interface/anaBaseTask.h"
#include "UserCode/diall/interface/anaJetEnergyScale.h"
#include "UserCode/diall/interface/anaJetMatching.h"
#include "UserCode/diall/interface/anaJetQA.h"
#include "UserCode/diall/interface/anaRhoProducer.h"
#include "UserCode/diall/interface/anaMET.h"
#include "UserCode/diall/interface/anaMuonIsolation.h"
#include "UserCode/diall/interface/anaMuonMatcher.h"
#include "UserCode/diall/interface/anaPuppiProducer.h"
#include "UserCode/diall/interface/anaPuppiParticles.h"
#include "UserCode/diall/interface/anaZToMuMu.h"
#include <TList.h>
#include <TChain.h>
#include <TFile.h>
#include <iostream>
using namespace std;
void analyzeJES(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1, Int_t firstEvent = 0) {
/*
ptminType: minimum raw pt for particles used by puppi
0 : 0 GeV
1 : 1 GeV
2 : 2 GeV
jetSignalType: jets used to select jetty region in events
0 : detector-level jets (akPu4PF)
1 : particle-level jets (gen jets)
*/
TString jetName = "aktPuppiR040";
TString jetTreeName = "akPuppi4PFJetAnalyzer";
jetName = "aktCsR040";
jetTreeName = "akCs4PFJetAnalyzer";
//jetName = "aktPuR030";
//jetTreeName = "akPu3PFJetAnalyzer";
std::cout << "analyzing JES for: " << jetName << " tree: " << jetTreeName << std::endl;
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 = std::min((size_t)lastF,lastFile);
}
std::cout << "firstFile: " << firstFile << " lastFile: " << lastFile << std::endl;
Int_t lastEvent = nentries;
if(firstEvent>0) {
lastEvent = firstEvent + nentries;
}
std::cout << "firstEvent: " << firstEvent << 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 *jetTree = new TChain(Form("%s/t",jetTreeName.Data()));
for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
chain->AddFriend(jetTree);
Printf("jetTree done");
TList *fEventObjects = new TList();
//---------------------------------------------------------------
// producers
//
hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
p_evt->SetInput(chain);
p_evt->SetHIEventContName("hiEventContainer");
p_evt->SetEventObjects(fEventObjects);
lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
p_PUJet->SetInput(chain);
p_PUJet->SetJetContName(jetName);
p_PUJet->SetGenJetContName("akt4Gen");
p_PUJet->SetEventObjects(fEventObjects);
p_PUJet->SetRadius(0.4);
//---------------------------------------------------------------
//analysis modules
//
//handler to which all modules will be added
anaBaseTask *handler = new anaBaseTask("handler","handler");
anaJetEnergyScale *anajesForest = new anaJetEnergyScale("anaJESForest","anaJESForest");
anajesForest->ConnectEventObject(fEventObjects);
anajesForest->SetHiEvtName("hiEventContainer");
anajesForest->SetGenJetsName("akt4Gen");
anajesForest->SetRecJetsName(jetName);
anajesForest->SetNCentBins(4);
anajesForest->SetUseForestMatching(true);
//anajesForest->SetMaxDistance(0.2);
handler->Add(anajesForest);
anaJetEnergyScale *anajesForestQuarks = new anaJetEnergyScale("anaJESForestQuarks","anaJESForestQuarks");
anajesForestQuarks->ConnectEventObject(fEventObjects);
anajesForestQuarks->SetHiEvtName("hiEventContainer");
anajesForestQuarks->SetGenJetsName("akt4Gen");
anajesForestQuarks->SetRecJetsName(jetName);
anajesForestQuarks->SetNCentBins(4);
anajesForestQuarks->SetUseForestMatching(true);
//anajesForestQuarks->SetMaxDistance(0.2);
anajesForestQuarks->SetRefPartonFlavor(0,2);
handler->Add(anajesForestQuarks);
anaJetEnergyScale *anajesForestGluons = new anaJetEnergyScale("anaJESForestGluons","anaJESForestGluons");
anajesForestGluons->ConnectEventObject(fEventObjects);
anajesForestGluons->SetHiEvtName("hiEventContainer");
anajesForestGluons->SetGenJetsName("akt4Gen");
anajesForestGluons->SetRecJetsName(jetName);
anajesForestGluons->SetNCentBins(4);
anajesForestGluons->SetUseForestMatching(true);
//anajesForestGluons->SetMaxDistance(0.2);
anajesForestGluons->SetRefPartonFlavor(21,21);
handler->Add(anajesForestGluons);
anaJetEnergyScale *anajesForestRaw = new anaJetEnergyScale("anaJESForestRaw","anaJESForestRaw");
anajesForestRaw->ConnectEventObject(fEventObjects);
anajesForestRaw->SetHiEvtName("hiEventContainer");
anajesForestRaw->SetGenJetsName("");
anajesForestRaw->SetRecJetsName(jetName);
anajesForestRaw->SetNCentBins(4);
anajesForestRaw->SetUseForestMatching(true);
anajesForestRaw->SetUseRawPt(true);
//handler->Add(anajesForestRaw);
//particle-detector-level jet matching
anaJetMatching *match = new anaJetMatching("jetMatching","jetMatching");
match->ConnectEventObject(fEventObjects);
match->SetHiEvtName("hiEventContainer");
//match->SetJetsNameBase(jetName);
//match->SetJetsNameTag("akt4Gen");
match->SetJetsNameTag(jetName);
match->SetJetsNameBase("akt4Gen");
match->SetMatchingType(0);
//handler->Add(match);
anaJetEnergyScale *anajes = new anaJetEnergyScale("anaJES","anaJES");
anajes->ConnectEventObject(fEventObjects);
anajes->SetHiEvtName("hiEventContainer");
anajes->SetGenJetsName("akt4Gen");
anajes->SetRecJetsName(jetName);
anajes->SetNCentBins(4);
//handler->Add(anajes);
anaJetEnergyScale *anajesRaw = new anaJetEnergyScale("anaJESRaw","anaJESRaw");
anajesRaw->ConnectEventObject(fEventObjects);
anajesRaw->SetHiEvtName("hiEventContainer");
anajesRaw->SetGenJetsName("akt4Gen");
anajesRaw->SetRecJetsName(jetName);
anajesRaw->SetNCentBins(4);
anajesRaw->SetUseForestMatching(false);
anajesRaw->SetUseRawPt(true);
//handler->Add(anajesRaw);
//---------------------------------------------------------------
//Event loop
//---------------------------------------------------------------
Long64_t entries_tot = chain->GetEntries(); //93064
if(nentries<0) lastEvent = chain->GetEntries();
Printf("nentries: %lld tot: %lld",nentries,entries_tot);
for (Long64_t jentry=firstEvent; jentry<lastEvent; ++jentry) {
if(jentry%10000==0) cout << "entry: "<< jentry << endl;
//Run producers
//Printf("produce hiEvent");
p_evt->Run(jentry); //hi event properties
//Printf("produce PU jets");
p_PUJet->Run(jentry); //forest jets
//Execute all analysis tasks
handler->ExecuteTask();
}
fEventObjects->Print();
TFile *out = new TFile(outname,"RECREATE");
TList *tasks = handler->GetListOfTasks();
TIter next(tasks);
anaBaseTask *obj;
while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
out->Write();
out->Close();
}