forked from delphes/delphes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Example3.C
242 lines (183 loc) · 7.41 KB
/
Example3.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
/*
This macro shows how to access the particle-level reference for reconstructed objects.
It is also shown how to loop over the jet constituents.
root -l examples/Example3.C'("delphes_output.root")'
*/
#ifdef __CLING__
R__LOAD_LIBRARY(libDelphes)
#include "classes/DelphesClasses.h"
#include "external/ExRootAnalysis/ExRootTreeReader.h"
#include "external/ExRootAnalysis/ExRootResult.h"
#else
class ExRootTreeReader;
class ExRootResult;
#endif
//------------------------------------------------------------------------------
struct TestPlots
{
TH1 *fElectronDeltaPT;
TH1 *fElectronDeltaEta;
TH1 *fPhotonDeltaPT;
TH1 *fPhotonDeltaEta;
TH1 *fPhotonDeltaE;
TH1 *fMuonDeltaPT;
TH1 *fMuonDeltaEta;
TH1 *fJetDeltaPT;
};
//------------------------------------------------------------------------------
void BookHistograms(ExRootResult *result, TestPlots *plots)
{
TLegend *legend;
TPaveText *comment;
plots->fElectronDeltaPT = result->AddHist1D(
"electron_delta_pt", "(p_{T}^{particle} - p_{T}^{electron})/p_{T}^{particle}",
"(p_{T}^{particle} - p_{T}^{electron})/p_{T}^{particle}", "number of electrons",
100, -0.1, 0.1);
plots->fElectronDeltaEta = result->AddHist1D(
"electron_delta_eta", "(#eta^{particle} - #eta^{electron})/#eta^{particle}",
"(#eta^{particle} - #eta^{electron})/#eta^{particle}", "number of electrons",
100, -0.1, 0.1);
plots->fPhotonDeltaPT = result->AddHist1D(
"photon_delta_pt", "(p_{T}^{particle} - p_{T}^{photon})/p_{T}^{particle}",
"(p_{T}^{particle} - p_{T}^{photon})/p_{T}^{particle}", "number of photons",
100, -0.1, 0.1);
plots->fPhotonDeltaEta = result->AddHist1D(
"photon_delta_eta", "(#eta^{particle} - #eta^{photon})/#eta^{particle}",
"(#eta^{particle} - #eta^{photon})/#eta^{particle}", "number of photons",
100, -0.1, 0.1);
plots->fPhotonDeltaE = result->AddHist1D(
"photon_delta_energy", "(E^{particle} - E^{photon})/E^{particle}",
"(E^{particle} - E^{photon})/E^{particle}", "number of photons",
100, -0.1, 0.1);
plots->fMuonDeltaPT = result->AddHist1D(
"muon_delta_pt", "(p_{T}^{particle} - p_{T}^{muon})/p_{T}^{particle}",
"(p_{T}^{particle} - p_{T}^{muon})/p_{T}^{particle}", "number of muons",
100, -0.1, 0.1);
plots->fMuonDeltaEta = result->AddHist1D(
"muon_delta_eta", "(#eta^{particle} - #eta^{muon})/#eta^{particle}",
"(#eta^{particle} - #eta^{muon})/#eta^{particle}", "number of muons",
100, -0.1, 0.1);
plots->fJetDeltaPT = result->AddHist1D(
"jet_delta_pt", "(p_{T}^{jet} - p_{T}^{constituents})/p_{T}^{jet}",
"(p_{T}^{jet} - p_{T}^{constituents})/p_{T}^{jet}", "number of jets",
100, -1.0e-1, 1.0e-1);
}
//------------------------------------------------------------------------------
void AnalyseEvents(ExRootTreeReader *treeReader, TestPlots *plots)
{
TClonesArray *branchParticle = treeReader->UseBranch("Particle");
TClonesArray *branchElectron = treeReader->UseBranch("Electron");
TClonesArray *branchPhoton = treeReader->UseBranch("Photon");
TClonesArray *branchMuon = treeReader->UseBranch("Muon");
TClonesArray *branchEFlowTrack = treeReader->UseBranch("EFlowTrack");
TClonesArray *branchEFlowPhoton = treeReader->UseBranch("EFlowPhoton");
TClonesArray *branchEFlowNeutralHadron = treeReader->UseBranch("EFlowNeutralHadron");
TClonesArray *branchJet = treeReader->UseBranch("Jet");
Long64_t allEntries = treeReader->GetEntries();
cout << "** Chain contains " << allEntries << " events" << endl;
GenParticle *particle;
Electron *electron;
Photon *photon;
Muon *muon;
Track *track;
Tower *tower;
Jet *jet;
TObject *object;
TLorentzVector momentum;
Float_t Eem, Ehad;
Bool_t skip;
Long64_t entry;
Int_t i, j, pdgCode;
// Loop over all events
for(entry = 0; entry < allEntries; ++entry)
{
// Load selected branches with data from specified event
treeReader->ReadEntry(entry);
// Loop over all electrons in event
for(i = 0; i < branchElectron->GetEntriesFast(); ++i)
{
electron = (Electron*) branchElectron->At(i);
particle = (GenParticle*) electron->Particle.GetObject();
plots->fElectronDeltaPT->Fill((particle->PT - electron->PT)/particle->PT);
plots->fElectronDeltaEta->Fill((particle->Eta - electron->Eta)/particle->Eta);
}
// Loop over all photons in event
for(i = 0; i < branchPhoton->GetEntriesFast(); ++i)
{
photon = (Photon*) branchPhoton->At(i);
// skip photons with references to multiple particles
if(photon->Particles.GetEntriesFast() != 1) continue;
particle = (GenParticle*) photon->Particles.At(0);
plots->fPhotonDeltaPT->Fill((particle->PT - photon->PT)/particle->PT);
plots->fPhotonDeltaEta->Fill((particle->Eta - photon->Eta)/particle->Eta);
plots->fPhotonDeltaE->Fill((particle->E - photon->E)/particle->E);
}
// Loop over all muons in event
for(i = 0; i < branchMuon->GetEntriesFast(); ++i)
{
muon = (Muon*) branchMuon->At(i);
particle = (GenParticle*) muon->Particle.GetObject();
plots->fMuonDeltaPT->Fill((particle->PT - muon->PT)/particle->PT);
plots->fMuonDeltaEta->Fill((particle->Eta - muon->Eta)/particle->Eta);
}
// cout << "-- New event -- " << endl;
// Loop over all jets in event
for(i = 0; i < branchJet->GetEntriesFast(); ++i)
{
jet = (Jet*) branchJet->At(i);
momentum.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);
// cout<<"Looping over jet constituents. Jet pt: "<<jet->PT<<", eta: "<<jet->Eta<<", phi: "<<jet->Phi<<endl;
// Loop over all jet's constituents
for(j = 0; j < jet->Constituents.GetEntriesFast(); ++j)
{
object = jet->Constituents.At(j);
// Check if the constituent is accessible
if(object == 0) continue;
if(object->IsA() == GenParticle::Class())
{
particle = (GenParticle*) object;
// cout << " GenPart pt: " << particle->PT << ", eta: " << particle->Eta << ", phi: " << particle->Phi << endl;
momentum += particle->P4();
}
else if(object->IsA() == Track::Class())
{
track = (Track*) object;
// cout << " Track pt: " << track->PT << ", eta: " << track->Eta << ", phi: " << track->Phi << endl;
momentum += track->P4();
}
else if(object->IsA() == Tower::Class())
{
tower = (Tower*) object;
// cout << " Tower pt: " << tower->ET << ", eta: " << tower->Eta << ", phi: " << tower->Phi << endl;
momentum += tower->P4();
}
}
plots->fJetDeltaPT->Fill((jet->PT - momentum.Pt())/jet->PT);
}
}
}
//------------------------------------------------------------------------------
void PrintHistograms(ExRootResult *result, TestPlots *plots)
{
result->Print("png");
}
//------------------------------------------------------------------------------
void Example3(const char *inputFile)
{
gSystem->Load("libDelphes");
TChain *chain = new TChain("Delphes");
chain->Add(inputFile);
ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
ExRootResult *result = new ExRootResult();
TestPlots *plots = new TestPlots;
BookHistograms(result, plots);
AnalyseEvents(treeReader, plots);
PrintHistograms(result, plots);
result->Write("results.root");
cout << "** Exiting..." << endl;
delete plots;
delete result;
delete treeReader;
delete chain;
}
//------------------------------------------------------------------------------