Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 456

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

put the inputfiles in the Logfile

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