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