Fork me on GitHub

source: svn/trunk/Examples/src/Analysis_Ex.cc@ 371

Last change on this file since 371 was 371, checked in by Xavier Rouby, 15 years ago

update , w.r.t to the new ZDC/ForwardTagger classes

File size: 15.7 KB
Line 
1/***********************************************************************
2** **
3** /----------------------------------------------\ **
4** | Delphes, a framework for the fast simulation | **
5** | of a generic collider experiment | **
6** \----------------------------------------------/ **
7** **
8** **
9** This package uses: **
10** ------------------ **
11** FastJet algorithm: Phys. Lett. B641 (2006) [hep-ph/0512210] **
12** Hector: JINST 2:P09005 (2007) [physics.acc-ph:0707.1198v2] **
13** FROG: [hep-ex/0901.2718v1] **
14** **
15** ------------------------------------------------------------------ **
16** **
17** Main authors: **
18** ------------- **
19** **
20** Severine Ovyn Xavier Rouby **
21** severine.ovyn@uclouvain.be xavier.rouby@cern **
22** **
23** Center for Particle Physics and Phenomenology (CP3) **
24** Universite catholique de Louvain (UCL) **
25** Louvain-la-Neuve, Belgium **
26** **
27** Copyright (C) 2008-2009, **
28** All rights reserved. **
29** **
30***********************************************************************/
31
32
33#include "Examples/interface/Analysis_Ex.h"
34#include <iostream>
35#include <sstream>
36#include <fstream>
37#include <iomanip>
38
39using namespace std;
40
41//******************************Debut de l'analyse****************************************
42//*****************************************************************************************
43
44Analysis_Ex::Analysis_Ex(string CardWithCuts,string LogName)
45{
46 string temp_string;
47 istringstream curstring;
48
49 ifstream fichier_a_lire(CardWithCuts.c_str());
50 if(!fichier_a_lire.good()) {
51 cout << "DataCardname " << CardWithCuts << " not found, use default values" << endl;
52 return;
53 }
54
55 while (getline(fichier_a_lire,temp_string)) {
56 curstring.clear(); // needed when using several times istringstream::str(string)
57 curstring.str(temp_string);
58 string varname;
59 float value;
60
61 if(strstr(temp_string.c_str(),"#")) { }//remove comments
62 else if(strstr(temp_string.c_str(),"PT_ELEC")){curstring >> varname >> value; PT_ELEC = value;}
63 else if(strstr(temp_string.c_str(),"PT_MUON")){curstring >> varname >> value; PT_MUON = value;}
64 else if(strstr(temp_string.c_str(),"INV_MASS_LL")){curstring >> varname >> value; INV_MASS_LL = value;}
65 }
66
67 ofstream f_out(LogName.c_str(),ofstream::app);
68
69 f_out<<"*******************************************************************"<<endl;
70 f_out << left << setw(30) <<"Cut values used in the analysis: "<<""
71 << right << setw(37) <<"-------------------------------------"<<"\n";
72 f_out << left <<setw(50) << "Invariant mass of the leptons: "<<""
73 << right <<setw(17) << INV_MASS_LL <<"\n";
74 f_out<<"*******************************************************************"<<endl;
75
76}
77
78Analysis_Ex::~Analysis_Ex()
79{
80}
81
82void Analysis_Ex::Run(ExRootTreeReader *treeReaderGen, ExRootTreeReader *treeReaderRec, ExRootTreeReader *treeReaderTrig, ExRootTreeWriter *treeWriter)
83{
84 total=0;//initialisation of total number of events
85 cut_trig=0;
86 cut_1=0;//initialisation of counter for cut 1
87 cut_2=0;
88 //access the branches************************
89 //to get the generator level information
90 const TClonesArray *GEN = treeReaderGen->UseBranch("Particle");
91
92 //to get the reconstructed level information
93 const TClonesArray *JET = treeReaderRec->UseBranch("Jet");
94 const TClonesArray *TAUJET = treeReaderRec->UseBranch("TauJet");
95 const TClonesArray *PHOTO = treeReaderRec->UseBranch("Photon");
96 const TClonesArray *ELEC = treeReaderRec->UseBranch("Electron");
97 const TClonesArray *MUON = treeReaderRec->UseBranch("Muon");
98 const TClonesArray *TRACKS = treeReaderRec->UseBranch("Tracks");
99 const TClonesArray *CALO = treeReaderRec->UseBranch("CaloTower");
100
101 //to get the VFD reconstructed level information
102 const TClonesArray *ZDC = treeReaderRec->UseBranch("ZDChits");
103 const TClonesArray *RP220 = treeReaderRec->UseBranch("RP220hits");
104 const TClonesArray *FP420 = treeReaderRec->UseBranch("FP420hits");
105
106 //to get the trigger information
107 const TClonesArray *TRIGGER = treeReaderTrig->UseBranch("TrigResult");
108
109 //Define the branches that will be filled during the analysis
110 ExRootTreeBranch *INVMASS = treeWriter->NewBranch("INVMass", TRootInvm::Class());
111 TRootInvm *inv_mass;
112 //*******************************************
113
114 //run on the events
115 Long64_t entry, allEntries = treeReaderRec->GetEntries();
116 cout << "** Chain contains " << allEntries << " events" << endl;
117 total=allEntries;
118
119 //general information
120 float E,Px,Py,Pz;
121 float PT,Eta,Phi;
122
123 //lepton information
124 bool IsolFlag;
125
126 //bjet information
127 bool Btag;
128
129 //Particle level information
130 int PID, Status, M1,M2,D1,D2;
131 float Charge, T, X, Y, Z, M;
132
133 //VFD information
134 float S,q2,Tx,Ty;
135 int side;
136 bool hadronic_hit;
137
138 for(entry = 0; entry < allEntries; ++entry)
139 {
140 treeReaderGen->ReadEntry(entry);//access information of generated information
141 treeReaderRec->ReadEntry(entry);//access information of reconstructed information
142 treeReaderTrig->ReadEntry(entry);//access information of Trigger information
143
144 //*****************************************************
145 //Example how to run on the generator level information
146 //*****************************************************
147 TIter itGen((TCollection*)GEN);
148 TRootC::GenParticle *gen;
149 itGen.Reset();
150 while( (gen = (TRootC::GenParticle*) itGen.Next()) )
151 {
152 PID = gen->PID; // particle HEP ID number
153 Status = gen->Status; // particle status
154 M1 = gen->M1; // particle 1st mother
155 M2 = gen->M2; // particle 2nd mother
156 D1 = gen->D1; // particle 1st daughter
157 D2 = gen->D2; // particle 2nd daughter
158 Charge = gen->Charge; // electrical charge
159
160 T = gen->T; // particle vertex position (t component)
161 X = gen->X; // particle vertex position (x component)
162 Y = gen->Y; // particle vertex position (y component)
163 Z = gen->Z; // particle vertex position (z component)
164 M = gen->M; // particle mass
165 }
166
167
168 //***********************************************
169 //Example how to run on the reconstructed objects
170 //***********************************************
171
172 //access the Electron branch
173 TIter itElec((TCollection*)ELEC);
174 TRootElectron *elec;
175 itElec.Reset();
176 while( (elec = (TRootElectron*) itElec.Next()) )
177 {
178 E = elec->E; // particle energy in GeV
179 Px = elec->Px; // particle momentum vector (x component) in GeV
180 Py = elec->Py; // particle momentum vector (y component) in GeV
181 Pz = elec->Pz; // particle momentum vector (z component) in GeV
182
183 PT = elec->PT; // particle transverse momentum in GeV
184 Eta = elec->Eta; // particle pseudorapidity
185 Phi = elec->Phi; // particle azimuthal angle in rad
186 IsolFlag = elec->IsolFlag; // is the particule isolated?
187 }
188 //Running on the muon branch is identical:
189 TIter itMuon((TCollection*)MUON);
190 TRootMuon *muon;
191 itMuon.Reset();
192 while( (muon = (TRootMuon*) itMuon.Next()) ){}
193
194 //access the Photon branch
195 TIter itGam((TCollection*)PHOTO);
196 TRootPhoton *gam;
197 itGam.Reset();
198 while( (gam = (TRootPhoton*) itGam.Next()) )
199 {
200 E = gam->E; // particle energy in GeV
201 Px = gam->Px; // particle momentum vector (x component) in GeV
202 Py = gam->Py; // particle momentum vector (y component) in GeV
203 Pz = gam->Pz; // particle momentum vector (z component) in GeV
204
205 PT = gam->PT; // particle transverse momentum in GeV
206 Eta = gam->Eta; // particle pseudorapidity
207 Phi = gam->Phi; // particle azimuthal angle in rad
208 }
209
210 //access the jet branch
211 TIter itJet((TCollection*)JET);
212 TRootJet *jet;
213 itJet.Reset();
214 while( (jet = (TRootJet*) itJet.Next()) )
215 {
216 E = jet->E; // particle energy in GeV
217 Px = jet->Px; // particle momentum vector (x component) in GeV
218 Py = jet->Py; // particle momentum vector (y component) in GeV
219 Pz = jet->Pz; // particle momentum vector (z component) in GeV
220
221 PT = jet->PT; // particle transverse momentum in GeV
222 Eta = jet->Eta; // particle pseudorapidity
223 Phi = jet->Phi; // particle azimuthal angle in rad
224 Btag = jet->Btag; // is the jet BTagged
225 }
226 //Running on the tau-jet branch is identical:
227 TIter itTaujet((TCollection*)TAUJET);
228 TRootTauJet *taujet;
229 itTaujet.Reset();
230 while( (taujet = (TRootTauJet*) itTaujet.Next()) ){}
231
232 //access the track branch
233 TIter itTrack((TCollection*)TRACKS);
234 TRootTracks *tracks;
235 itTrack.Reset();
236 while( (tracks = (TRootTracks*) itTrack.Next()) )
237 {
238 E = tracks->E; // particle energy in GeV
239 Px = tracks->Px; // particle momentum vector (x component) in GeV
240 Py = tracks->Py; // particle momentum vector (y component) in GeV
241 Pz = tracks->Pz; // particle momentum vector (z component) in GeV
242
243 PT = tracks->PT; // particle transverse momentum in GeV
244 Eta = tracks->Eta; // particle pseudorapidity
245 Phi = tracks->Phi; // particle azimuthal angle in rad
246 }
247
248 //Running on the calo branch is identical:
249 TIter itCalo((TCollection*)CALO);
250 TRootCalo *calo;
251 itCalo.Reset();
252 while( (calo = (TRootCalo*) itCalo.Next()) ){}
253
254 //***************************************************
255 //Example how to run on the VFD reconstructed objects
256 //***************************************************
257
258 //access the ZDC branch
259 TIter itZdc((TCollection*)ZDC);
260 TRootZdcHits *zdc;
261 itZdc.Reset();
262 while( (zdc = (TRootZdcHits*) itZdc.Next()) )
263 {
264 E = zdc->E; // particle energy in GeV
265 T = zdc->T; // time of flight [s]
266 side = zdc->side; // -1 or +1
267 hadronic_hit = zdc->hadronic_hit; // true if neutron, false if photon
268 }
269
270 //access the RP220 branch
271 TIter itRp220((TCollection*)RP220);
272 TRootRomanPotHits *rp220;
273 itRp220.Reset();
274
275 while( (rp220 = (TRootRomanPotHits*) itRp220.Next()) )
276 {
277 //T = rp220->T; // time of flight to the detector [s]
278 S = rp220->S; // distance to the IP [m]
279 E = rp220->E; // reconstructed energy [GeV]
280 q2 = rp220->q2; // reconstructed squared momentum transfer [GeV^2]
281
282 X = rp220->X; // horizontal distance to the beam [um]
283 Y = rp220->Y; // vertical distance to the beam [um]
284
285 Tx = rp220->Tx; // angle of the momentum in the horizontal (x,z) plane [urad]
286 Ty = rp220->Ty; // angle of the momentum in the verical (y,z) plane [urad]
287
288 side = rp220->side; // -1 or 1
289 }
290 //running on FP420 branch is identical
291 TIter itFp420((TCollection*)FP420);
292 TRootRomanPotHits *fp420;
293 itFp420.Reset();
294 while( (fp420 = (TRootRomanPotHits*) itFp420.Next()) ){}
295
296 //*********************************************
297 //Example how to run on the trigger information
298 //*********************************************
299
300 TRootTrigger *trig;
301 int NumTrigBit = TRIGGER->GetEntries();
302 //get the global response of the trigger
303
304 bool GlobalResponse=false;
305 if(NumTrigBit!=0)GlobalResponse=true;
306 cout<<"GlobalResponse "<<GlobalResponse<<endl;
307 for(int i=0; i < NumTrigBit-1; i++){
308 trig = (TRootTrigger*)TRIGGER->At(i);
309 cout<<"The event has been accepted by the trigger number: "<<trig->Accepted<<endl;
310 }
311
312 //********************************
313 //Example of a very small analysis
314 //********************************
315
316 TLorentzVector Lept[2];
317
318 if(NumTrigBit==0)continue; //event not accepted by the trigger
319 cut_trig++;//event accepted
320
321 TSimpleArray<TRootElectron> el=SubArrayEl(ELEC,PT_ELEC);//the central isolated electrons, pt > PT_ELEC GeV
322 TSimpleArray<TRootMuon> mu=SubArrayMu(MUON,PT_MUON);//the central isolated electrons, pt > PT_MUON GeV
323
324 Int_t numElec=el.GetEntries();
325
326 if(el.GetEntries()+mu.GetEntries()!=2)continue;//Exactly 2 isolated leptons are needed
327 cut_1++;//event accepted
328 for(Int_t i=0;i < numElec; i++)Lept[i].SetPxPyPzE(el[i]->Px,el[i]->Py,el[i]->Pz,el[i]->E);
329 for(Int_t k = numElec; k < (numElec+mu.GetEntries()); k++)Lept[k].SetPxPyPzE(mu[k-numElec]->Px,mu[k-numElec]->Py,mu[k-numElec]->Pz,mu[k-numElec]->E);
330 cout<<"normalement il y a quelque chose... "<<endl;
331 //Example how to white a branch in the output file
332 inv_mass=(TRootInvm*) INVMASS->NewEntry();
333 inv_mass->M=(Lept[0]+Lept[1]).M();
334
335 if((Lept[0]+Lept[1]).M() > INV_MASS_LL )continue;// the invariant mass should be < INV_MASS_LL
336 cut_2++;//event accepted
337
338 treeWriter->Fill();
339 }
340 treeWriter->Write();
341
342}
343
344void Analysis_Ex::WriteOutput(string LogName)
345{
346 ofstream f_out(LogName.c_str(),ofstream::app);
347
348 f_out<<"*******************************************************************"<<endl;
349 f_out << left << setw(20) << "Numer of Events "<<""
350 << right << setw(15) << total <<"\n";
351 f_out << left << setw(17) << " Accepted by the trigger "<<""
352 << right << setw(20) << cut_trig <<"\n";
353 f_out << left << setw(17) <<" 2 leptons "<< ""
354 << right << setw(20) << cut_1 << ""
355 << right << setw(15) << cut_1/total << "\n";
356 f_out << left << setw(17) <<" Invariant mass "<< ""
357 << right << setw(20) << cut_2 << ""
358 << right << setw(15) << cut_2/total << "\n";
359 f_out<<"*******************************************************************"<<endl;
360 f_out<<" "<<endl;
361
362}
363
364TSimpleArray<TRootElectron> Analysis_Ex::SubArrayEl(const TClonesArray *ELEC,float pt)
365{
366 TIter itElec((TCollection*)ELEC);
367 TRootElectron *elec;
368 itElec.Reset();
369 TSimpleArray<TRootElectron> array;
370 while( (elec = (TRootElectron*) itElec.Next()) )
371 {
372 if(elec->PT<pt)continue;
373 array.Add(elec);
374 }
375 return array;
376}
377
378TSimpleArray<TRootMuon> Analysis_Ex::SubArrayMu(const TClonesArray *MUON,float pt)
379{
380 TIter itMuon((TCollection*)MUON);
381 TRootMuon *muon;
382 itMuon.Reset();
383 TSimpleArray<TRootMuon> array;
384 while( (muon = (TRootMuon*) itMuon.Next()) )
385 {
386 if(muon->PT<pt)continue;
387 array.Add(muon);
388 }
389 return array;
390}
391
Note: See TracBrowser for help on using the repository browser.