Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 292

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

tracks and Taujets have charge

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