Fork me on GitHub

source: git/examples/Example3.C@ 38bf1ae

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 38bf1ae was fbb617b, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

improve formatting and remove trailing spaces

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