Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 326

Last change on this file since 326 was 321, checked in by Xavier Rouby, 16 years ago

Isolation updated. ptiso implemented. etrat prepared but not finished

File size: 36.3 KB
RevLine 
[260]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) **
[310]25** Louvain-la-Neuve, Belgium **
[260]26** **
27** Copyright (C) 2008-2009, **
28** All rights reserved. **
29** **
30***********************************************************************/
[2]31
32/// \file Delphes.cpp
[264]33/// \brief Executable for Delphes
[2]34
35#include "TChain.h"
36#include "TApplication.h"
[191]37#include "TStopwatch.h"
[228]38#include "TFile.h"
[2]39
[228]40#include "ExRootTreeReader.h"
41#include "ExRootTreeWriter.h"
42#include "ExRootTreeBranch.h"
[264]43#include "ExRootProgressBar.h"
[2]44
[228]45#include "DataConverter.h"
46#include "HEPEVTConverter.h"
47#include "LHEFConverter.h"
48#include "STDHEPConverter.h"
[307]49#include "LHCOConverter.h"
[2]50
[228]51#include "SmearUtil.h"
[264]52#include "CaloUtil.h"
[228]53#include "BFieldProp.h"
54#include "TriggerUtil.h"
55#include "VeryForward.h"
56#include "JetsUtil.h"
57#include "FrogUtil.h"
[2]58
[55]59#include <vector>
60#include <iostream>
[11]61
[2]62using namespace std;
63
64//------------------------------------------------------------------------------
65void todo(string filename) {
66 ifstream infile(filename.c_str());
67 cout << "** TODO list ..." << endl;
68 while(infile.good()) {
[94]69 string temp;
70 getline(infile,temp);
71 cout << "*" << temp << endl;
[2]72 }
73 cout << "** done...\n";
74}
75
76//------------------------------------------------------------------------------
77
78int main(int argc, char *argv[])
79{
[307]80
[2]81 int appargc = 2;
[228]82 char *appName= new char[20];
83 char *appOpt= new char[20];
84 sprintf(appName,"Delphes");
85 sprintf(appOpt,"-b");
86 char *appargv[] = {appName,appOpt};
[2]87 TApplication app(appName, &appargc, appargv);
[228]88 delete [] appName;
89 delete [] appOpt;
[307]90
[249]91 if(argc != 3 && argc != 4 && argc != 5) {
[94]92 cout << " Usage: " << argv[0] << " input_file output_file [detector_card] [trigger_card] " << endl;
93 cout << " input_list - list of files in Ntpl, StdHep of LHEF format," << endl;
94 cout << " output_file - output file." << endl;
95 cout << " detector_card - Datacard containing resolution variables for the detector simulation (optional) "<<endl;
96 cout << " trigger_card - Datacard containing the trigger algorithms (optional) "<<endl;
97 exit(1);
[2]98 }
[228]99
[307]100
101
102
103 cout << endl << endl;
104
105 cout <<"*********************************************************************"<< endl;
106 cout <<"*********************************************************************"<< endl;
107 cout <<"** **"<< endl;
108 cout <<"** Welcome to **"<< endl;
109 cout <<"** **"<< endl;
110 cout <<"** **"<< endl;
111 cout <<"** .ddddddd- lL hH **"<< endl;
112 cout <<"** -Dd` `dD: Ll hH` **"<< endl;
113 cout <<"** dDd dDd eeee. lL .pp+pp Hh+hhh` -eeee- `sssss **"<< endl;
114 cout <<"** -Dd `DD ee. ee Ll .Pp. PP Hh. HH. ee. ee sSs **"<< endl;
115 cout <<"** dD` dDd eEeee: lL. pP. pP hH hH` eEeee:` -sSSSs. **"<< endl;
116 cout <<"** .Dd :dd eE. LlL PpppPP Hh Hh eE sSS **"<< endl;
117 cout <<"** dddddd:. eee+: lL. pp. hh. hh eee+ sssssS **"<< endl;
118 cout <<"** Pp **"<< endl;
119 cout <<"** **"<< endl;
120 cout <<"** Delphes, a framework for the fast simulation **"<< endl;
121 cout <<"** of a generic collider experiment **"<< endl;
122 cout <<"** **"<< endl;
123 cout <<"** --- Version 1.4beta of Delphes --- **"<< endl;
124 cout <<"** Last date of change: 9 February 2009 **"<< endl;
125 cout <<"** **"<< endl;
126 cout <<"** **"<< endl;
127 cout <<"** This package uses: **"<< endl;
128 cout <<"** ------------------ **"<< endl;
129 cout <<"** FastJet algorithm: Phys. Lett. B641 (2006) [hep-ph/0512210] **"<< endl;
130 cout <<"** Hector: JINST 2:P09005 (2007) [physics.acc-ph:0707.1198v2] **"<< endl;
131 cout <<"** FROG: [hep-ex/0901.2718v1] **"<< endl;
132 cout <<"** **"<< endl;
133 cout <<"**-----------------------------------------------------------------**"<< endl;
134 cout <<"** **"<< endl;
135 cout <<"** Main authors: **"<< endl;
136 cout <<"** ------------- **"<< endl;
137 cout <<"** **"<< endl;
138 cout <<"** Séverine Ovyn Xavier Rouby **"<< endl;
139 cout <<"** severine.ovyn@uclouvain.be xavier.rouby@cern **"<< endl;
140 cout <<"** Center for Particle Physics and Phenomenology (CP3) **"<< endl;
141 cout <<"** Universite Catholique de Louvain (UCL) **"<< endl;
142 cout <<"** Louvain-la-Neuve, Belgium **"<< endl;
143 cout <<"** **"<< endl;
144 cout <<"**-----------------------------------------------------------------**"<< endl;
145 cout <<"** **"<< endl;
146 cout <<"** Former Delphes versions and documentation can be found on : **"<< endl;
147 cout <<"** http://www.fynu.ucl.ac.be/delphes.html **"<< endl;
148 cout <<"** **"<< endl;
149 cout <<"** **"<< endl;
150 cout <<"** Disclaimer: this program is a beta version of Delphes and **"<< endl;
151 cout <<"** therefore comes without guarantees. Beware of errors and please **"<< endl;
152 cout <<"** give us your feedbacks about potential bugs **"<< endl;
153 cout <<"** **"<< endl;
154 cout <<"*********************************************************************"<< endl;
155 cout <<"*********************************************************************"<< endl;
156
157 // 1. ********** initialisation ***********
158
[2]159 srand (time (NULL)); /* Initialisation du générateur */
[313]160 TStopwatch globalwatch, loopwatch, triggerwatch, frogwatch, lhcowatch;
[191]161 globalwatch.Start();
[2]162
[307]163
[249]164 //read the output TROOT file
[2]165 string inputFileList(argv[1]), outputfilename(argv[2]);
[249]166 if(outputfilename.find(".root") > outputfilename.length()) {
167 cout <<"** ERROR: 'output_file' should be a .root file. Exiting... **"<< endl;
[94]168 exit(1);
[2]169 }
[44]170 //create output log-file name
[45]171 string forLog = outputfilename;
172 string LogName = forLog.erase(forLog.find(".root"));
[44]173 LogName = LogName+"_run.log";
[94]174
[2]175 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
176 outputFile->Close();
[94]177
[2]178 string line;
179 ifstream infile(inputFileList.c_str());
180 infile >> line; // the first line determines the type of input files
[94]181
[44]182 //read the datacard input file
[304]183 string DetDatacard("data/DetectorCard.dat"); //for detector smearing parameters
184 string TrigDatacard("data/TriggerCard.dat"); //for trigger selection
[307]185
[249]186 string lineCard1,lineCard2;
187 bool detecCard=false,trigCard=false;
188 if(argv[3])
189 {
190 ifstream infile1(argv[3]);
191 infile1 >> lineCard1; // the first line determines the type of input files
192 if(strstr(lineCard1.c_str(),"DETECTOR") && detecCard==true)
[307]193 cerr <<"** ERROR: A DETECTOR card has already been loaded **"<< endl;
[249]194 else if(strstr(lineCard1.c_str(),"DETECTOR") && detecCard==false){DetDatacard =argv[3]; detecCard=true;}
195 else if(strstr(lineCard1.c_str(),"TRIGGER") && trigCard==true)
[307]196 cerr <<"** ERROR: A TRIGGER card has already been loaded **"<< endl;
[249]197 else if(strstr(lineCard1.c_str(),"TRIGGER") && trigCard==false){TrigDatacard =argv[3]; trigCard=true;}
198 }
199 if(argv[4])
200 {
201 ifstream infile2(argv[4]);
202 infile2 >> lineCard2; // the first line determines the type of input files
203 if(strstr(lineCard2.c_str(),"DETECTOR") && detecCard==true)
[307]204 cerr <<"** ERROR: A DETECTOR card has already been loaded **"<< endl;
[249]205 else if(strstr(lineCard2.c_str(),"DETECTOR") && detecCard==false){DetDatacard =argv[4]; detecCard=true;}
206 else if(strstr(lineCard2.c_str(),"TRIGGER") && trigCard==true)
[307]207 cerr <<"** ERROR: A TRIGGER card has already been loaded **"<< endl;
[249]208 else if(strstr(lineCard2.c_str(),"TRIGGER") && trigCard==false){TrigDatacard =argv[4]; trigCard=true;}
209 }
[94]210
[55]211 //Smearing information
[44]212 RESOLution *DET = new RESOLution();
[212]213 cout <<"** **"<< endl;
214 cout <<"** ####### Start reading DETECTOR parameters ####### **"<< endl;
215 cout << left << setw(40) <<"** Opening configuration card: "<<""
[258]216 << left << setw(27) << DetDatacard <<""
217 << right << setw(2) <<"**"<<""<<endl;
[44]218 DET->ReadDataCard(DetDatacard);
219 DET->Logfile(LogName);
[304]220 cout << left << setw(40) <<"** Parameters summarised in: "<<""
[258]221 << left << setw(27) << LogName <<""
222 << right << setw(2) <<"**"<<""<<endl;
[212]223 cout <<"** **"<< endl;
[307]224
[55]225 //Trigger information
[249]226 cout <<"** ########### Start reading TRIGGER card ########## **"<< endl;
227 if(trigCard==false)
[307]228 {
229 cout <<"** WARNING: Datacard not found, use default card **" << endl;
230 TrigDatacard="data/TriggerCard.dat";
231 }
[72]232 TriggerTable *TRIGT = new TriggerTable();
[80]233 TRIGT->TriggerCardReader(TrigDatacard.c_str());
[72]234 TRIGT->PrintTriggerTable(LogName);
[212]235 if(DET->FLAG_trigger == 1)
236 {
237 cout << left << setw(40) <<"** Opening configuration card: "<<""
[258]238 << left << setw(27) << TrigDatacard <<""
239 << right << setw(2) <<"**"<<""<<endl;
[212]240 cout <<"** **"<< endl;
241 }
[94]242
[55]243 //Propagation of tracks in the B field
[228]244 TrackPropagation *TRACP = new TrackPropagation(DET);
[94]245
[55]246 //Jet information
[228]247 JetsUtil *JETRUN = new JetsUtil(DET);
[94]248
[55]249 //VFD information
[228]250 VeryForward * VFD = new VeryForward(DET);
[307]251
[178]252 // data converters
[228]253 DataConverter *converter=NULL;
[212]254 cout <<"** **"<<endl;
255 cout <<"** ####### Start convertion to TRoot format ######## **"<< endl;
[307]256
[2]257 if(strstr(line.c_str(),".hep"))
258 {
[212]259 cout <<"** StdHEP file format detected **"<<endl;
260 cout <<"** This can take several minutes **"<< endl;
[2]261 converter = new STDHEPConverter(inputFileList,outputfilename);//case ntpl file in input list
262 }
263 else if(strstr(line.c_str(),".lhe"))
264 {
[212]265 cout <<"** LHEF file format detected **"<<endl;
266 cout <<"** This can take several minutes **"<< endl;
[2]267 converter = new LHEFConverter(inputFileList,outputfilename);//case ntpl file in input list
268 }
269 else if(strstr(line.c_str(),".root"))
270 {
[212]271 cout <<"** h2root file format detected **"<<endl;
272 cout <<"** This can take several minutes **"<< endl;
[2]273 converter = new HEPEVTConverter(inputFileList,outputfilename);//case ntpl file in input list
274 }
[212]275 else {
[307]276 cerr << left << setw(4) <<"** "<<""
277 << left << setw(63) << line.c_str() <<""
278 << right << setw(2) <<"**"<<endl;
279 cerr <<"** ERROR: File format not identified -- Exiting... **"<< endl;
280 cout <<"** **"<< endl;
281 cout <<"*********************************************************************"<< endl;
282 return -1;};
[212]283 cout <<"** Exiting conversion... **"<< endl;
[307]284
[2]285 TChain chain("GEN");
286 chain.Add(outputfilename.c_str());
287 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
288 const TClonesArray *branchGen = treeReader->UseBranch("Particle");
[307]289
[2]290 TIter itGen((TCollection*)branchGen);
291
[178]292 //Output file : contents of the analysis object data
[2]293 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
[267]294 ExRootTreeBranch *branchTauJet = treeWriter->NewBranch("TauJet", TRootTauJet::Class());
[2]295 ExRootTreeBranch *branchJet = treeWriter->NewBranch("Jet", TRootJet::Class());
296 ExRootTreeBranch *branchElectron = treeWriter->NewBranch("Electron", TRootElectron::Class());
297 ExRootTreeBranch *branchMuon = treeWriter->NewBranch("Muon", TRootMuon::Class());
298 ExRootTreeBranch *branchPhoton = treeWriter->NewBranch("Photon", TRootPhoton::Class());
[268]299 ExRootTreeBranch *branchTrack = treeWriter->NewBranch("Tracks", TRootTracks::Class());
[2]300 ExRootTreeBranch *branchETmis = treeWriter->NewBranch("ETmis", TRootETmis::Class());
301 ExRootTreeBranch *branchCalo = treeWriter->NewBranch("CaloTower", TRootCalo::Class());
302 ExRootTreeBranch *branchZDC = treeWriter->NewBranch("ZDChits", TRootZdcHits::Class());
303 ExRootTreeBranch *branchRP220 = treeWriter->NewBranch("RP220hits", TRootRomanPotHits::Class());
304 ExRootTreeBranch *branchFP420 = treeWriter->NewBranch("FP420hits", TRootRomanPotHits::Class());
[30]305
[2]306 TRootETmis *elementEtmis;
307 TRootElectron *elementElec;
308 TRootMuon *elementMu;
309 TRootPhoton *elementPhoton;
[268]310 TRootTracks * elementTrack;
[2]311 TRootCalo *elementCalo;
312
[184]313 TLorentzVector genMomentum(0,0,0,0); // four-momentum at the vertex
314 TLorentzVector genMomentumBfield(0,0,0,0); // four-momentum at the exit of the tracks
315 TLorentzVector momentumCaloSegmentation(0,0,0,0); // four-momentum in the calo, after applying the calo segmentation
[2]316 LorentzVector jetMomentum;
[94]317
[55]318 vector<fastjet::PseudoJet> input_particles;//for FastJet algorithm
319 vector<fastjet::PseudoJet> sorted_jets;
[290]320 vector<TRootTracks> TrackCentral;
[2]321 vector<PhysicsTower> towers;
[264]322 vector<D_Particle> electron;
323 vector<D_Particle> muon;
324 vector<D_Particle> gamma;
[307]325
326 vector<int> NTrackJet;
[98]327
[319]328 TSimpleArray<GenParticle> NFCentralQ;
[307]329
330 D_CaloList list_of_calorimeters;
331 D_CaloElement CentralCalo("centralcalo",
332 -DET->CEN_max_calo_cen, DET->CEN_max_calo_cen,
333 DET->ELG_Ccen, DET->ELG_Ncen, DET->ELG_Scen,
334 DET->HAD_Chcal, DET->HAD_Nhcal, DET->HAD_Shcal);
335 D_CaloElement ForwardCalo("forwardcalo",
336 DET->CEN_max_calo_cen, DET->CEN_max_calo_fwd,
337 DET->ELG_Cfwd, DET->ELG_Nfwd, DET->ELG_Sfwd,
338 DET->HAD_Chf, DET->HAD_Nhf, DET->HAD_Shf );
339 D_CaloElement BackwardCalo("backwardcalo",
340 -DET->CEN_max_calo_fwd, -DET->CEN_max_calo_cen,
341 DET->ELG_Cfwd, DET->ELG_Nfwd, DET->ELG_Sfwd,
342 DET->HAD_Chf, DET->HAD_Nhf, DET->HAD_Shf );
343 //D_CaloElement CastorCalo("castor",5.5,6.6,1,0,0,1,0,0);
344 list_of_calorimeters.addElement(CentralCalo);
345 list_of_calorimeters.addElement(ForwardCalo);
346 list_of_calorimeters.addElement(BackwardCalo);
347 //list_of_calorimeters.addElement(CastorCalo);
348 list_of_calorimeters.sortElements();
349
350
351 // 2. ********** Loop over all events ***********
[2]352 Long64_t entry, allEntries = treeReader->GetEntries();
[212]353 cout <<"** **"<<endl;
354 cout <<"** ####### Start fast detector simulation ######## **"<< endl;
355 cout << left << setw(52) <<"** Total number of events to run: "<<""
356 << left << setw(15) << allEntries <<""
357 << right << setw(2) <<"**"<<endl;
[307]358
[251]359 ExRootProgressBar *Progress = new ExRootProgressBar(allEntries);
[307]360
[191]361 loopwatch.Start();
[307]362
[178]363 // loop on all events
364 for(entry = 0; entry < allEntries; ++entry)
[2]365 {
[251]366 Progress->Update(entry);
[2]367 TLorentzVector PTmis(0,0,0,0);
368 treeReader->ReadEntry(entry);
369 treeWriter->Clear();
370
[30]371 electron.clear();
372 muon.clear();
[74]373 gamma.clear();
[30]374 NFCentralQ.Clear();
375
[2]376 TrackCentral.clear();
377 towers.clear();
[11]378 input_particles.clear();
[307]379 NTrackJet.clear();
[310]380
381
382 D_CaloTowerList list_of_active_towers;
383 D_CaloTowerList list_of_towers_with_photon; // to speed up the code: will only look in interesting towers for gamma candidates
384
385
386 // 2.1a Loop over all particles in event, to fill the towers
387 itGen.Reset();
388 GenParticle *particleG;
389 while( (particleG = (GenParticle*) itGen.Next()) )
390 {
[307]391 TRootGenParticle *particle = new TRootGenParticle(particleG);
392 int pid = abs(particle->PID);
393 particle->Charge=ChargeVal(particle->PID);
394 particle->setFractions(); // init
395
396
[264]397 // 2.1a.1********************* preparation for the b-tagging
398 //// This subarray is needed for the B-jet algorithm
399 // optimization for speed : put first PID condition, then ETA condition, then either pt or status
400 if( (pid <= pB || pid == pGLUON) &&// is it a light quark or a gluon, i.e. is it one of these : u,d,c,s,b,g ?
401 fabs(particle->Eta) < DET->CEN_max_tracker &&
402 particle->Status != 1 &&
[310]403 particle->PT > DET->PT_QUARKS_MIN )
404 {
[319]405 NFCentralQ.Add(particleG);
[310]406 }
[307]407
[264]408 // 2.1a.2********************* visible particles only
[310]409 if( (particle->Status == 1) && (pid != pNU1) && (pid != pNU2) && (pid != pNU3) )
410 {
411 // 2.1a.2.1 Central solenoidal magnetic field
412 TRACP->bfield(particle); // fills in particle->EtaCalo et particle->PhiCalo
413 // 2.1a.2.2 Filling the calorimetric towers -- includes also forward detectors ?
414 // first checks if the charged particles reach the calo!
415 if( DET->FLAG_bfield ||
416 particle->Charge==0 ||
417 (!DET->FLAG_bfield && particle->Charge!=0 && particle->PT > DET->TRACK_ptmin))
418 if(
419 (particle->EtaCalo > list_of_calorimeters.getEtamin() ) &&
420 (particle->EtaCalo < list_of_calorimeters.getEtamax() )
421 )
[307]422 {
[310]423 float iEta=UNDEFINED, iPhi=UNDEFINED;
424 DET->BinEtaPhi(particle->PhiCalo,particle->EtaCalo,iPhi,iEta); // fills in iPhi and iEta
425 if (iEta != UNDEFINED && iPhi != UNDEFINED)
426 {
427 D_CaloTower tower(iEta,iPhi); // new tower
428 tower.Set_Eem_Ehad_E_ET(particle->E*particle->getFem() , particle->E*particle->getFhad() );
429 list_of_active_towers.addTower(tower);
430 // this list may contain several times the same calotower, as several particles
431 // may leave some energy in the same calotower
432 // After the loop on particles, identical cells in the list should be merged
433 } // iEta and iPhi must be defined
434 }
[307]435
[310]436 // 2.1a.2.3 charged particles in tracker: energy flow
437 // if bfield not simulated, pt should be high enough to be taken into account
438 // it is supposed here that DET->MAX_calo > DET->CEN_max_tracker > DET->CEN_max_mu > 0
439 if( particle->Charge !=0 &&
440 fabs(particle->EtaCalo)< DET->CEN_max_tracker && // stays in the tracker -> track available
441 ( DET->FLAG_bfield ||
442 (!DET->FLAG_bfield && particle->PT > DET->TRACK_ptmin)
443 )
444 )
445 {
446 // 2.1a.2.3.1 Filling the particle properties + smearing
447 // Hypothesis: the final eta/phi are the ones from the generator, thanks to the track reconstruction
448 // This is the EnergyFlow hypothesis
449 particle->SetEtaPhi(particle->Eta,particle->Phi);
450 float sET=UNDEFINED; // smeared ET, computed from the smeared E -> needed for the tracks
451
452 // 2.1a.2.3.2 Muons
453 if (pid == pMU && fabs(particle->EtaCalo)< DET->CEN_max_mu)
454 {
455 TLorentzVector p;
456 float sPT = gRandom->Gaus(particle->PT, DET->MU_SmearPt*particle->PT );
457 if (sPT > 0 && sPT > DET->PTCUT_muon)
458 {
459 p.SetPtEtaPhiE(sPT,particle->Eta,particle->Phi,sPT*cosh(particle->Eta));
460 muon.push_back(D_Particle(p,pMU,particle->EtaCalo,particle->PhiCalo));
461 }
462 sET = (sPT >0)? sPT : 0;
463 }
464 // 2.1a.2.3.3 Electrons
465 else if (pid == pE)
466 {
467 // Finds in which calorimeter the particle has gone, to know its resolution
468
469 D_CaloElement currentCalo = list_of_calorimeters.getElement(particle->EtaCalo);
470 if(currentCalo.getName() == dummyCalo.getName())
471 {
472 cout << "** Warning: the calo coverage behind the tracker is not complete! **" << endl;
473 }
474
475 // final smeared EM energy // electromagnetic fraction F_em =1 for electrons;
476 float sE = currentCalo.getElectromagneticResolution().Smear(particle->E);
477 if (sE>0)
478 {
479 sET = sE/cosh(particle->Eta);
480 // NB: ET is found via the calorimetry and not via the track curvature
481
482 TLorentzVector p;
483 p.SetPtEtaPhiE(sET,particle->Eta,particle->Phi,sE);
484 if (sET > DET->PTCUT_elec)
485 electron.push_back(D_Particle(p,particle->PID,particle->EtaCalo,particle->PhiCalo));
486 }
487 else { sET=0;} // if negative smeared energy -- needed for the tracks
488 }
489 // 2.1a.2.3.4 Other charged particles : smear them for the tracks!
490 else
491 { //other particles
492 D_CaloElement currentCalo = list_of_calorimeters.getElement(particle->EtaCalo);
493 float sEem = currentCalo.getElectromagneticResolution().Smear(particle->E * particle->getFem());
494 float sEhad = currentCalo.getHadronicResolution().Smear(particle->E * particle->getFhad());
495 float sE = ( (sEem>0)? sEem : 0 ) + ( (sEhad>0)? sEhad : 0 );
496 sET = sE/cosh(particle->EtaCalo);
497 }
[307]498
[310]499 // 2.1a.2.3.5 Tracks
500 if( (rand()%100) < DET->TRACK_eff && sET!=0)
501 {
502 elementTrack = (TRootTracks*) branchTrack->NewEntry();
503 elementTrack->Set(particle->Eta, particle->Phi, particle->EtaCalo, particle->PhiCalo, sET, particle->Charge);
504 TrackCentral.push_back(*elementTrack); // tracks at vertex!
505 // TODO!!! apply a smearing on the position of the origin of the track
506 // TODO!!! elementTracks->SetPositionOut(Xout,Yout,Zout);
507 }
508 } // 2.1a.2.3 : if tracker/energy-flow
509 // 2.1a.2.4 Photons
510 // stays in the tracker -> track available -> gamma ID
511 else if( (pid == pGAMMA) && fabs(particle->EtaCalo)< DET->CEN_max_tracker )
512 {
513 float iEta=UNDEFINED, iPhi=UNDEFINED;
514 DET->BinEtaPhi(particle->PhiCalo,particle->EtaCalo,iPhi,iEta); // fills in iPhi and iEta
515 D_CaloTower tower(iEta,iPhi);
516 // stores the list of towers where to apply the photon ID algorithm. Just a trick for a faster search
517 list_of_towers_with_photon.addTower(tower);
[307]518 }
[310]519 // 2.1a.2.5 : very forward detectors
520 else
521 {
522 if (DET->FLAG_RP==1)
523 {
524 // for the moment, only protons are transported
525 // BUT !!! could be a beam of other particles! (heavy ions?)
526 // BUT ALSO !!! if very forward muons, or others!
527 VFD->RomanPots(treeWriter,branchRP220,branchFP420,particle);
528 }
529 // 2.1a.2.6: Zero degree calorimeter
530 if(DET->FLAG_vfd==1)
531 {
532 VFD->ZDC(treeWriter,branchZDC,particle);
533 }
534 }
[307]535
[310]536 } // 2.1a.2 : if visible particle
[307]537 delete particle;
[310]538 }// loop on all particles 2.1a
539
540
541 // 2.1b loop on all (activated) towers
542 // at this stage, list_of_active_towers may contain several times the same tower
543 // first step is to merge identical towers, by matching their (iEta,iPhi)
544
545 list_of_active_towers.sortElements();
546 list_of_active_towers.mergeDuplicates();
547
548 // Calotower smearing
549 list_of_active_towers.smearTowers(list_of_calorimeters);
550
551 for(unsigned int i=0; i<list_of_active_towers.size(); i++)
552 {
[307]553 float iEta = list_of_active_towers[i].getEta();
554 float iPhi = list_of_active_towers[i].getPhi();
555 float e = list_of_active_towers[i].getE();
[310]556 if(iEta != UNDEFINED && iPhi != UNDEFINED && e!=0)
557 {
558 elementCalo = (TRootCalo*) branchCalo->NewEntry();
559 elementCalo->set(list_of_active_towers[i]);
560 // not beautiful : should be improved!
561 TLorentzVector p;
562 p.SetPtEtaPhiE(list_of_active_towers[i].getET(), iEta, iPhi, e );
563 PhysicsTower Tower(LorentzVector(p.Px(),p.Py(),p.Pz(),p.E()));
564 towers.push_back(Tower);
565 }
[307]566 } // loop on towers
[310]567
568 // 2.1c photon ID
569 // list_of_towers_with_photon is the list of towers with photon candidates
570 // already smeared !
571 // sorts the vector and smears duplicates
572 list_of_towers_with_photon.mergeDuplicates();
[321]573 for(unsigned int i=0; i<list_of_towers_with_photon.size(); i++) {
[264]574 float eta = list_of_towers_with_photon[i].getEta();
575 float phi = list_of_towers_with_photon[i].getPhi();
576 D_CaloTower cal(list_of_active_towers.getElement(eta,phi));
[310]577 if(cal.getEta() != UNDEFINED && cal.getPhi() != UNDEFINED && cal.getE() > 0)
578 {
579 TLorentzVector p;
580 p.SetPtEtaPhiE(cal.getET(), eta,phi,cal.getE() );
581 if (cal.getET() > DET->PTCUT_gamma) { gamma.push_back(D_Particle(p,pGAMMA,p.Eta(),p.Phi())); }
582 }
[307]583 } // for -- list of photons
584
[178]585 // 2.2 ********** Output preparation & complex objects ***********
586 // 2.2.1 ********************* sorting collections by decreasing pt
[74]587 DET->SortedVector(electron);
[321]588 float iPhiEl=0,iEtaEl=0,ptisoEl=0;
[310]589 for(unsigned int i=0; i < electron.size(); i++)
590 {
591 elementElec = (TRootElectron*) branchElectron->NewEntry();
592 elementElec->Set(electron[i].Px(),electron[i].Py(),electron[i].Pz(),electron[i].E());
593 elementElec->EtaCalo = electron[i].EtaCalo();
594 elementElec->PhiCalo = electron[i].PhiCalo();
595 elementElec->Charge = sign(electron[i].PID());
[321]596 elementElec->IsolFlag = DET->Isolation(electron[i],TrackCentral,DET->ISOL_PT,DET->ISOL_Cone,ptisoEl);
597 elementElec->IsolPt = ptisoEl;
[312]598 DET->BinEtaPhi(elementElec->PhiCalo,elementElec->EtaCalo,iPhiEl,iEtaEl);
599 D_CaloTower calElec(list_of_active_towers.getElement(iEtaEl,iPhiEl));
[310]600 elementElec->EHoverEE = calElec.getEhad()/calElec.getEem();
[312]601 }
[310]602
[74]603 DET->SortedVector(muon);
[321]604 float iPhiMu=0,iEtaMu=0,ptisoMu=0;
[310]605 for(unsigned int i=0; i < muon.size(); i++)
606 {
607 elementMu = (TRootMuon*) branchMuon->NewEntry();
608 elementMu->Charge = sign(muon[i].PID());
609 elementMu->Set(muon[i].Px(),muon[i].Py(),muon[i].Pz(),muon[i].E());
610 elementMu->EtaCalo = muon[i].EtaCalo();
611 elementMu->PhiCalo = muon[i].PhiCalo();
[321]612 elementMu->IsolFlag = DET->Isolation(muon[i],TrackCentral,DET->ISOL_PT,DET->ISOL_Cone,ptisoMu);
613 elementMu->IsolPt = ptisoMu;
614 DET->BinEtaPhi(elementMu->PhiCalo,elementMu->EtaCalo,iPhiMu,iEtaMu);
[312]615 D_CaloTower calMuon(list_of_active_towers.getElement(iEtaMu,iPhiMu));
[321]616 if( calMuon.getEem() !=0 ) elementMu->EHoverEE = calMuon.getEhad()/calMuon.getEem();
617 else elementMu->EHoverEE = UNDEFINED;
618 elementMu->EtRatio = DET->CaloIsolation(muon[i], list_of_active_towers);
[310]619 }
620
[74]621 DET->SortedVector(gamma);
[310]622 for(unsigned int i=0; i < gamma.size(); i++)
623 {
624 elementPhoton = (TRootPhoton*) branchPhoton->NewEntry();
625 elementPhoton->Set(gamma[i].Px(),gamma[i].Py(),gamma[i].Pz(),gamma[i].E());
626 D_CaloTower calGamma(list_of_active_towers.getElement(gamma[i].EtaCalo(),gamma[i].PhiCalo()));
627 elementPhoton->EHoverEE = calGamma.getEhad()/calGamma.getEem();
628 }
[30]629
[178]630 // 2.2.2 ************* computes the Missing Transverse Momentum
[71]631 TLorentzVector Att(0.,0.,0.,0.);
632 for(unsigned int i=0; i < towers.size(); i++)
633 {
[107]634 Att.SetPxPyPzE(towers[i].fourVector.px, towers[i].fourVector.py, towers[i].fourVector.pz, towers[i].fourVector.E);
635 if(fabs(Att.Eta()) < DET->CEN_max_calo_fwd)
[307]636 {
637 PTmis = PTmis + Att;
638 // create a fastjet::PseudoJet with these components and put it onto
639 // back of the input_particles vector
640 input_particles.push_back(fastjet::PseudoJet(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E));
641 }
[71]642 }
643 elementEtmis = (TRootETmis*) branchETmis->NewEntry();
644 elementEtmis->ET = (PTmis).Pt();
645 elementEtmis->Phi = (-PTmis).Phi();
646 elementEtmis->Px = (-PTmis).Px();
647 elementEtmis->Py = (-PTmis).Py();
[74]648
[264]649 // 2.2.3 ************* jets, B-tag, tau jets
[310]650 vector<int> NTrackJet; //for number of tracks
651 vector<float> EHADEEM; //for energyHad over energyEm
652 sorted_jets=JETRUN->RunJets(input_particles, TrackCentral,NTrackJet,EHADEEM,list_of_active_towers);
653 JETRUN->RunJetBtagging(treeWriter, branchJet,sorted_jets,NFCentralQ,NTrackJet,EHADEEM);
654 JETRUN->RunTauJets(treeWriter,branchTauJet,sorted_jets,towers, TrackCentral,NTrackJet,EHADEEM);
[74]655
[72]656 treeWriter->Fill();
[178]657 } // 2. Loop over all events ('for' loop)
[307]658
[212]659 cout <<"** Exiting detector simulation... **"<< endl;
[307]660
661
[2]662 treeWriter->Write();
[77]663 delete treeWriter;
[191]664 loopwatch.Stop();
[307]665
666
667
[212]668 // 3. ********** Trigger & Frog ***********
[178]669 // 3.1 ************ running the trigger in case the FLAG trigger is put to 1 in the datacard
[191]670 triggerwatch.Start();
[94]671 if(DET->FLAG_trigger == 1)
[72]672 {
[307]673 cout <<"** **"<<endl;
674 cout <<"** ########### Start Trigger selection ########### **"<< endl;
675
[178]676 // input
[72]677 TChain chainT("Analysis");
678 chainT.Add(outputfilename.c_str());
679 ExRootTreeReader *treeReaderT = new ExRootTreeReader(&chainT);
[74]680
[178]681 // output
[72]682 TClonesArray *branchElecTrig = treeReaderT->UseBranch("Electron");
683 TClonesArray *branchMuonTrig = treeReaderT->UseBranch("Muon");
684 TClonesArray *branchJetTrig = treeReaderT->UseBranch("Jet");
685 TClonesArray *branchTauJetTrig = treeReaderT->UseBranch("TauJet");
686 TClonesArray *branchPhotonTrig = treeReaderT->UseBranch("Photon");
687 TClonesArray *branchETmisTrig = treeReaderT->UseBranch("ETmis");
[74]688
[72]689 ExRootTreeWriter *treeWriterT = new ExRootTreeWriter(outputfilename, "Trigger");
690 ExRootTreeBranch *branchTrigger = treeWriterT->NewBranch("TrigResult", TRootTrigger::Class());
[307]691
692
[72]693 Long64_t entryT, allEntriesT = treeReaderT->GetEntries();
[178]694 // loop on all entries
695 for(entryT = 0; entryT < allEntriesT; ++entryT) {
[307]696 treeWriterT->Clear();
697 treeReaderT->ReadEntry(entryT);
698 TRIGT->GetGlobalResult(branchElecTrig, branchMuonTrig,branchJetTrig, branchTauJetTrig,branchPhotonTrig, branchETmisTrig,branchTrigger);
699 treeWriterT->Fill();
[178]700 } // loop on all entries
[212]701 cout <<"** Exiting trigger simulation... **"<< endl;
[94]702
[72]703 treeWriterT->Write();
704 delete treeWriterT;
[228]705 delete treeReaderT;
[178]706 } // trigger
[307]707 triggerwatch.Stop();
708
709
[178]710 // 3.2 ************** FROG display
[191]711 frogwatch.Start();
[228]712 if(DET->FLAG_frog == 1) {
[307]713 cout <<"** **"<<endl;
714 cout <<"** ################## Start FROG ################# **"<< endl;
715
716 FrogDisplay *FROG = new FrogDisplay(DET);
717 FROG->BuildEvents(outputfilename);
718 FROG->BuildGeom();
719 delete FROG;
[313]720 cout <<"** Exiting FROG preparation... **"<< endl;
[228]721 }
722 frogwatch.Stop();
[94]723
[307]724 // 3.3 *************** LHCO output
[313]725 lhcowatch.Start();
[307]726 if(DET->FLAG_lhco == 1){
727 cout <<"** **"<<endl;
728 cout <<"** ############ Start LHCO convertion ############ **"<< endl;
729
730 //LHCOConverter *LHCO = new LHCOConverter(outputfilename,LogNameLHCO);
731 LHCOConverter *LHCO = new LHCOConverter(outputfilename,"");
732 LHCO->CopyRunLogFile();
733 LHCO->ConvertExRootAnalysisToLHCO();
734 delete LHCO;
[313]735 cout <<"** Exiting LHCO converstion... **"<< endl;
[307]736 }
[313]737 lhcowatch.Stop();
[307]738
739
740
741 // 4. ********** End & Exit ***********
742
[191]743 globalwatch.Stop();
[212]744 cout <<"** **"<< endl;
745 cout <<"** ################## Time report ################# **"<< endl;
746 cout << left << setw(32) <<"** Time report for "<<""
[307]747 << left << setw(15) << allEntries <<""
748 << right << setw(22) <<"events **"<<endl;
[212]749 cout <<"** **"<< endl;
750 cout << left << setw(10) <<"**"<<""
751 << left << setw(15) <<"Time (s):"<<""
752 << right << setw(15) <<"CPU"<<""
753 << right << setw(15) <<"Real"<<""
754 << right << setw(14) <<"**"<<endl;
755 cout << left << setw(10) <<"**"<<""
756 << left << setw(15) <<" + Global:"<<""
757 << right << setw(15) <<globalwatch.CpuTime()<<""
758 << right << setw(15) <<globalwatch.RealTime()<<""
759 << right << setw(14) <<"**"<<endl;
760 cout << left << setw(10) <<"**"<<""
761 << left << setw(15) <<" + Events:"<<""
762 << right << setw(15) <<loopwatch.CpuTime()<<""
763 << right << setw(15) <<loopwatch.RealTime()<<""
764 << right << setw(14) <<"**"<<endl;
[191]765 if(DET->FLAG_trigger == 1)
[212]766 {
[307]767 cout << left << setw(10) <<"**"<<""
768 << left << setw(15) <<" + Trigger:"<<""
769 << right << setw(15) <<triggerwatch.CpuTime()<<""
770 << right << setw(15) <<triggerwatch.RealTime()<<""
771 << right << setw(14) <<"**"<<endl;
[212]772 }
[191]773 if(DET->FLAG_frog == 1)
[212]774 {
[307]775 cout << left << setw(10) <<"**"<<""
776 << left << setw(15) <<" + Frog:"<<""
777 << right << setw(15) <<frogwatch.CpuTime()<<""
778 << right << setw(15) <<frogwatch.RealTime()<<""
779 << right << setw(14) <<"**"<<endl;
[212]780 }
[313]781 if(DET->FLAG_lhco == 1)
782 {
783 cout << left << setw(10) <<"**"<<""
784 << left << setw(15) <<" + LHCO:"<<""
785 << right << setw(15) <<lhcowatch.CpuTime()<<""
786 << right << setw(15) <<lhcowatch.RealTime()<<""
787 << right << setw(14) <<"**"<<endl;
788 }
789
[2]790
[307]791 cout <<"** **"<< endl;
792 cout <<"** Exiting Delphes ... **"<< endl;
793 cout <<"** **"<< endl;
794 cout <<"*********************************************************************"<< endl;
795 cout <<"*********************************************************************"<< endl;
796
797
[2]798 delete treeReader;
799 delete DET;
[264]800 delete TRIGT;
[74]801 delete TRACP;
802 delete JETRUN;
803 delete VFD;
[228]804 delete converter;
[94]805
[307]806 // todo("TODO");
[2]807}
Note: See TracBrowser for help on using the repository browser.