1 | /*
|
---|
2 | This macro shows how to access the particle-level reference for reconstructed objects.
|
---|
3 | It is also shown how to loop over the jet constituents.
|
---|
4 |
|
---|
5 | root -l examples/Example3.C'("delphes_output.root")'
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifdef __CLING__
|
---|
9 | R__LOAD_LIBRARY(libDelphes)
|
---|
10 | #include "classes/DelphesClasses.h"
|
---|
11 | #include "external/ExRootAnalysis/ExRootTreeReader.h"
|
---|
12 | #include "external/ExRootAnalysis/ExRootResult.h"
|
---|
13 | #else
|
---|
14 | class ExRootTreeReader;
|
---|
15 | class ExRootResult;
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | //------------------------------------------------------------------------------
|
---|
19 |
|
---|
20 | struct TestPlots
|
---|
21 | {
|
---|
22 | TH1 *fElectronDeltaPT;
|
---|
23 | TH1 *fElectronDeltaEta;
|
---|
24 |
|
---|
25 | TH1 *fPhotonDeltaPT;
|
---|
26 | TH1 *fPhotonDeltaEta;
|
---|
27 | TH1 *fPhotonDeltaE;
|
---|
28 |
|
---|
29 | TH1 *fMuonDeltaPT;
|
---|
30 | TH1 *fMuonDeltaEta;
|
---|
31 |
|
---|
32 | TH1 *fJetDeltaPT;
|
---|
33 | };
|
---|
34 |
|
---|
35 | //------------------------------------------------------------------------------
|
---|
36 |
|
---|
37 | void BookHistograms(ExRootResult *result, TestPlots *plots)
|
---|
38 | {
|
---|
39 | TLegend *legend;
|
---|
40 | TPaveText *comment;
|
---|
41 |
|
---|
42 | plots->fElectronDeltaPT = result->AddHist1D(
|
---|
43 | "electron_delta_pt", "(p_{T}^{particle} - p_{T}^{electron})/p_{T}^{particle}",
|
---|
44 | "(p_{T}^{particle} - p_{T}^{electron})/p_{T}^{particle}", "number of electrons",
|
---|
45 | 100, -0.1, 0.1);
|
---|
46 |
|
---|
47 | plots->fElectronDeltaEta = result->AddHist1D(
|
---|
48 | "electron_delta_eta", "(#eta^{particle} - #eta^{electron})/#eta^{particle}",
|
---|
49 | "(#eta^{particle} - #eta^{electron})/#eta^{particle}", "number of electrons",
|
---|
50 | 100, -0.1, 0.1);
|
---|
51 |
|
---|
52 | plots->fPhotonDeltaPT = result->AddHist1D(
|
---|
53 | "photon_delta_pt", "(p_{T}^{particle} - p_{T}^{photon})/p_{T}^{particle}",
|
---|
54 | "(p_{T}^{particle} - p_{T}^{photon})/p_{T}^{particle}", "number of photons",
|
---|
55 | 100, -0.1, 0.1);
|
---|
56 |
|
---|
57 | plots->fPhotonDeltaEta = result->AddHist1D(
|
---|
58 | "photon_delta_eta", "(#eta^{particle} - #eta^{photon})/#eta^{particle}",
|
---|
59 | "(#eta^{particle} - #eta^{photon})/#eta^{particle}", "number of photons",
|
---|
60 | 100, -0.1, 0.1);
|
---|
61 |
|
---|
62 | plots->fPhotonDeltaE = result->AddHist1D(
|
---|
63 | "photon_delta_energy", "(E^{particle} - E^{photon})/E^{particle}",
|
---|
64 | "(E^{particle} - E^{photon})/E^{particle}", "number of photons",
|
---|
65 | 100, -0.1, 0.1);
|
---|
66 |
|
---|
67 | plots->fMuonDeltaPT = result->AddHist1D(
|
---|
68 | "muon_delta_pt", "(p_{T}^{particle} - p_{T}^{muon})/p_{T}^{particle}",
|
---|
69 | "(p_{T}^{particle} - p_{T}^{muon})/p_{T}^{particle}", "number of muons",
|
---|
70 | 100, -0.1, 0.1);
|
---|
71 |
|
---|
72 | plots->fMuonDeltaEta = result->AddHist1D(
|
---|
73 | "muon_delta_eta", "(#eta^{particle} - #eta^{muon})/#eta^{particle}",
|
---|
74 | "(#eta^{particle} - #eta^{muon})/#eta^{particle}", "number of muons",
|
---|
75 | 100, -0.1, 0.1);
|
---|
76 |
|
---|
77 | plots->fJetDeltaPT = result->AddHist1D(
|
---|
78 | "jet_delta_pt", "(p_{T}^{jet} - p_{T}^{constituents})/p_{T}^{jet}",
|
---|
79 | "(p_{T}^{jet} - p_{T}^{constituents})/p_{T}^{jet}", "number of jets",
|
---|
80 | 100, -1.0e-1, 1.0e-1);
|
---|
81 |
|
---|
82 | }
|
---|
83 |
|
---|
84 | //------------------------------------------------------------------------------
|
---|
85 |
|
---|
86 | void AnalyseEvents(ExRootTreeReader *treeReader, TestPlots *plots)
|
---|
87 | {
|
---|
88 | TClonesArray *branchParticle = treeReader->UseBranch("Particle");
|
---|
89 | TClonesArray *branchElectron = treeReader->UseBranch("Electron");
|
---|
90 | TClonesArray *branchPhoton = treeReader->UseBranch("Photon");
|
---|
91 | TClonesArray *branchMuon = treeReader->UseBranch("Muon");
|
---|
92 | TClonesArray *branchEFlowTrack = treeReader->UseBranch("EFlowTrack");
|
---|
93 | TClonesArray *branchEFlowPhoton = treeReader->UseBranch("EFlowPhoton");
|
---|
94 | TClonesArray *branchEFlowNeutralHadron = treeReader->UseBranch("EFlowNeutralHadron");
|
---|
95 | TClonesArray *branchJet = treeReader->UseBranch("Jet");
|
---|
96 |
|
---|
97 | Long64_t allEntries = treeReader->GetEntries();
|
---|
98 |
|
---|
99 | cout << "** Chain contains " << allEntries << " events" << endl;
|
---|
100 |
|
---|
101 | GenParticle *particle;
|
---|
102 | Electron *electron;
|
---|
103 | Photon *photon;
|
---|
104 | Muon *muon;
|
---|
105 |
|
---|
106 | Track *track;
|
---|
107 | Tower *tower;
|
---|
108 |
|
---|
109 | Jet *jet;
|
---|
110 | TObject *object;
|
---|
111 |
|
---|
112 | TLorentzVector momentum;
|
---|
113 |
|
---|
114 | Float_t Eem, Ehad;
|
---|
115 | Bool_t skip;
|
---|
116 |
|
---|
117 | Long64_t entry;
|
---|
118 |
|
---|
119 | Int_t i, j, pdgCode;
|
---|
120 |
|
---|
121 | // Loop over all events
|
---|
122 | for(entry = 0; entry < allEntries; ++entry)
|
---|
123 | {
|
---|
124 | // Load selected branches with data from specified event
|
---|
125 | treeReader->ReadEntry(entry);
|
---|
126 |
|
---|
127 | // Loop over all electrons in event
|
---|
128 | for(i = 0; i < branchElectron->GetEntriesFast(); ++i)
|
---|
129 | {
|
---|
130 | electron = (Electron*) branchElectron->At(i);
|
---|
131 | particle = (GenParticle*) electron->Particle.GetObject();
|
---|
132 |
|
---|
133 | plots->fElectronDeltaPT->Fill((particle->PT - electron->PT)/particle->PT);
|
---|
134 | plots->fElectronDeltaEta->Fill((particle->Eta - electron->Eta)/particle->Eta);
|
---|
135 | }
|
---|
136 |
|
---|
137 | // Loop over all photons in event
|
---|
138 | for(i = 0; i < branchPhoton->GetEntriesFast(); ++i)
|
---|
139 | {
|
---|
140 | photon = (Photon*) branchPhoton->At(i);
|
---|
141 |
|
---|
142 | // skip photons with references to multiple particles
|
---|
143 | if(photon->Particles.GetEntriesFast() != 1) continue;
|
---|
144 |
|
---|
145 | particle = (GenParticle*) photon->Particles.At(0);
|
---|
146 | if(object->IsA() == GenParticle::Class())
|
---|
147 | {
|
---|
148 | plots->fPhotonDeltaPT->Fill((particle->PT - photon->PT)/particle->PT);
|
---|
149 | plots->fPhotonDeltaEta->Fill((particle->Eta - photon->Eta)/particle->Eta);
|
---|
150 | plots->fPhotonDeltaE->Fill((particle->E - photon->E)/particle->E);
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | // Loop over all muons in event
|
---|
155 | for(i = 0; i < branchMuon->GetEntriesFast(); ++i)
|
---|
156 | {
|
---|
157 | muon = (Muon*) branchMuon->At(i);
|
---|
158 | particle = (GenParticle*) muon->Particle.GetObject();
|
---|
159 |
|
---|
160 | plots->fMuonDeltaPT->Fill((particle->PT - muon->PT)/particle->PT);
|
---|
161 | plots->fMuonDeltaEta->Fill((particle->Eta - muon->Eta)/particle->Eta);
|
---|
162 | }
|
---|
163 |
|
---|
164 | // cout << "-- New event -- " << endl;
|
---|
165 |
|
---|
166 | // Loop over all jets in event
|
---|
167 | for(i = 0; i < branchJet->GetEntriesFast(); ++i)
|
---|
168 | {
|
---|
169 | jet = (Jet*) branchJet->At(i);
|
---|
170 |
|
---|
171 | momentum.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);
|
---|
172 |
|
---|
173 | // cout<<"Looping over jet constituents. Jet pt: "<<jet->PT<<", eta: "<<jet->Eta<<", phi: "<<jet->Phi<<endl;
|
---|
174 |
|
---|
175 | // Loop over all jet's constituents
|
---|
176 | for(j = 0; j < jet->Constituents.GetEntriesFast(); ++j)
|
---|
177 | {
|
---|
178 | object = jet->Constituents.At(j);
|
---|
179 |
|
---|
180 | // Check if the constituent is accessible
|
---|
181 | if(object == 0) continue;
|
---|
182 |
|
---|
183 | if(object->IsA() == GenParticle::Class())
|
---|
184 | {
|
---|
185 | particle = (GenParticle*) object;
|
---|
186 | // cout << " GenPart pt: " << particle->PT << ", eta: " << particle->Eta << ", phi: " << particle->Phi << endl;
|
---|
187 | momentum += particle->P4();
|
---|
188 | }
|
---|
189 | else if(object->IsA() == Track::Class())
|
---|
190 | {
|
---|
191 | track = (Track*) object;
|
---|
192 | // cout << " Track pt: " << track->PT << ", eta: " << track->Eta << ", phi: " << track->Phi << endl;
|
---|
193 | momentum += track->P4();
|
---|
194 | }
|
---|
195 | else if(object->IsA() == Tower::Class())
|
---|
196 | {
|
---|
197 | tower = (Tower*) object;
|
---|
198 | // cout << " Tower pt: " << tower->ET << ", eta: " << tower->Eta << ", phi: " << tower->Phi << endl;
|
---|
199 | momentum += tower->P4();
|
---|
200 | }
|
---|
201 | }
|
---|
202 | plots->fJetDeltaPT->Fill((jet->PT - momentum.Pt())/jet->PT);
|
---|
203 | }
|
---|
204 | }
|
---|
205 | }
|
---|
206 |
|
---|
207 | //------------------------------------------------------------------------------
|
---|
208 |
|
---|
209 | void PrintHistograms(ExRootResult *result, TestPlots *plots)
|
---|
210 | {
|
---|
211 | result->Print("png");
|
---|
212 | }
|
---|
213 |
|
---|
214 | //------------------------------------------------------------------------------
|
---|
215 |
|
---|
216 | void Example3(const char *inputFile)
|
---|
217 | {
|
---|
218 | gSystem->Load("libDelphes");
|
---|
219 |
|
---|
220 | TChain *chain = new TChain("Delphes");
|
---|
221 | chain->Add(inputFile);
|
---|
222 |
|
---|
223 | ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
|
---|
224 | ExRootResult *result = new ExRootResult();
|
---|
225 |
|
---|
226 | TestPlots *plots = new TestPlots;
|
---|
227 |
|
---|
228 | BookHistograms(result, plots);
|
---|
229 |
|
---|
230 | AnalyseEvents(treeReader, plots);
|
---|
231 |
|
---|
232 | PrintHistograms(result, plots);
|
---|
233 |
|
---|
234 | result->Write("results.root");
|
---|
235 |
|
---|
236 | cout << "** Exiting..." << endl;
|
---|
237 |
|
---|
238 | delete plots;
|
---|
239 | delete result;
|
---|
240 | delete treeReader;
|
---|
241 | delete chain;
|
---|
242 | }
|
---|
243 |
|
---|
244 | //------------------------------------------------------------------------------
|
---|