1 | /*
|
---|
2 | ---- Delphes ----
|
---|
3 | A Fast Simulator for general purpose LHC detector
|
---|
4 | S. Ovyn ~~~~ severine.ovyn@uclouvain.be
|
---|
5 |
|
---|
6 | Center for Particle Physics and Phenomenology (CP3)
|
---|
7 | Universite Catholique de Louvain (UCL)
|
---|
8 | Louvain-la-Neuve, Belgium
|
---|
9 | */
|
---|
10 |
|
---|
11 | /// \file Delphes.cpp
|
---|
12 | /// \brief executable for the Delphes
|
---|
13 |
|
---|
14 | #include "TChain.h"
|
---|
15 | #include "TApplication.h"
|
---|
16 |
|
---|
17 | #include "Utilities/ExRootAnalysis/interface/ExRootTreeReader.h"
|
---|
18 | #include "Utilities/ExRootAnalysis/interface/ExRootTreeWriter.h"
|
---|
19 | #include "Utilities/ExRootAnalysis/interface/ExRootTreeBranch.h"
|
---|
20 |
|
---|
21 | #include "interface/DataConverter.h"
|
---|
22 | #include "interface/HEPEVTConverter.h"
|
---|
23 | #include "interface/LHEFConverter.h"
|
---|
24 | #include "interface/STDHEPConverter.h"
|
---|
25 |
|
---|
26 | #include "interface/SmearUtil.h"
|
---|
27 | #include "interface/BFieldProp.h"
|
---|
28 | #include "interface/TriggerUtil.h"
|
---|
29 | #include "interface/VeryForward.h"
|
---|
30 | #include "interface/JetUtils.h"
|
---|
31 |
|
---|
32 | #include <vector>
|
---|
33 | #include <iostream>
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 |
|
---|
37 | //------------------------------------------------------------------------------
|
---|
38 | void todo(string filename) {
|
---|
39 | ifstream infile(filename.c_str());
|
---|
40 | cout << "** TODO list ..." << endl;
|
---|
41 | while(infile.good()) {
|
---|
42 | string temp;
|
---|
43 | getline(infile,temp);
|
---|
44 | cout << "*" << temp << endl;
|
---|
45 | }
|
---|
46 | cout << "** done...\n";
|
---|
47 | }
|
---|
48 |
|
---|
49 | //------------------------------------------------------------------------------
|
---|
50 |
|
---|
51 | int main(int argc, char *argv[])
|
---|
52 | {
|
---|
53 | int appargc = 2;
|
---|
54 | char *appName = "Delphes";
|
---|
55 | char *appargv[] = {appName, "-b"};
|
---|
56 | TApplication app(appName, &appargc, appargv);
|
---|
57 |
|
---|
58 | if(argc != 4 && argc != 3) {
|
---|
59 | cout << " Usage: " << argv[0] << " input_file" << " output_file" << " data_card " << endl;
|
---|
60 | cout << " input_list - list of files in Ntpl, StdHep of LHEF format," << endl;
|
---|
61 | cout << " output_file - output file." << endl;
|
---|
62 | cout << " data_card - Datacard containing resolution variables for the detector simulation (optional) "<<endl;
|
---|
63 | exit(1);
|
---|
64 | }
|
---|
65 |
|
---|
66 | srand (time (NULL)); /* Initialisation du générateur */
|
---|
67 |
|
---|
68 | //read the input TROOT file
|
---|
69 | string inputFileList(argv[1]), outputfilename(argv[2]);
|
---|
70 | if(outputfilename.find(".root") > outputfilename.length() ) {
|
---|
71 | cout << "output_file should be a .root file!\n";
|
---|
72 | exit(1);
|
---|
73 | }
|
---|
74 | //create output log-file name
|
---|
75 | string forLog = outputfilename;
|
---|
76 | string LogName = forLog.erase(forLog.find(".root"));
|
---|
77 | LogName = LogName+"_run.log";
|
---|
78 |
|
---|
79 | TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
|
---|
80 | outputFile->Close();
|
---|
81 |
|
---|
82 | string line;
|
---|
83 | ifstream infile(inputFileList.c_str());
|
---|
84 | infile >> line; // the first line determines the type of input files
|
---|
85 |
|
---|
86 | //read the datacard input file
|
---|
87 | string DetDatacard("");
|
---|
88 | if(argc==4) DetDatacard =argv[3];
|
---|
89 |
|
---|
90 | //Smearing information
|
---|
91 | RESOLution *DET = new RESOLution();
|
---|
92 | DET->ReadDataCard(DetDatacard);
|
---|
93 | DET->Logfile(LogName);
|
---|
94 |
|
---|
95 | //Trigger information
|
---|
96 | Trigger *TRIG = new Trigger();
|
---|
97 | TRIG->TriggerReader("data/trigger.dat");
|
---|
98 |
|
---|
99 | //Propagation of tracks in the B field
|
---|
100 | TrackPropagation *TRACP = new TrackPropagation();
|
---|
101 |
|
---|
102 | //Jet information
|
---|
103 | JetsUtil *JETRUN = new JetsUtil();
|
---|
104 |
|
---|
105 | //VFD information
|
---|
106 | VeryForward * VFD = new VeryForward();
|
---|
107 |
|
---|
108 | //todo(LogName.c_str());
|
---|
109 |
|
---|
110 | DataConverter *converter=0;
|
---|
111 |
|
---|
112 | if(strstr(line.c_str(),".hep"))
|
---|
113 | {
|
---|
114 | cout<<"#**********************************************************************"<<endl;
|
---|
115 | cout<<"#********** StdHEP file format detected *************"<<endl;
|
---|
116 | cout<<"#*********** Starting convertion to TRoot format **************"<<endl;
|
---|
117 | cout<<"#**********************************************************************"<<endl;
|
---|
118 | converter = new STDHEPConverter(inputFileList,outputfilename);//case ntpl file in input list
|
---|
119 | }
|
---|
120 | else if(strstr(line.c_str(),".lhe"))
|
---|
121 | {
|
---|
122 | cout<<"#**********************************************************************"<<endl;
|
---|
123 | cout<<"#*********** LHEF file format detected ************"<<endl;
|
---|
124 | cout<<"#*********** Starting convertion to TRoot format ************"<<endl;
|
---|
125 | cout<<"#**********************************************************************"<<endl;
|
---|
126 | converter = new LHEFConverter(inputFileList,outputfilename);//case ntpl file in input list
|
---|
127 | }
|
---|
128 | else if(strstr(line.c_str(),".root"))
|
---|
129 | {
|
---|
130 | cout<<"#**********************************************************************"<<endl;
|
---|
131 | cout<<"#********** h2root file format detected *************"<<endl;
|
---|
132 | cout<<"#********** Starting convertion to TRoot format *************"<<endl;
|
---|
133 | cout<<"#**********************************************************************"<<endl;
|
---|
134 | converter = new HEPEVTConverter(inputFileList,outputfilename);//case ntpl file in input list
|
---|
135 | }
|
---|
136 | else { cout << "*** " << line.c_str() << "\n*** file format not identified\n*** Exiting\n"; return -1;};
|
---|
137 |
|
---|
138 | TChain chain("GEN");
|
---|
139 | chain.Add(outputfilename.c_str());
|
---|
140 | ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
|
---|
141 | const TClonesArray *branchGen = treeReader->UseBranch("Particle");
|
---|
142 | TIter itGen((TCollection*)branchGen);
|
---|
143 |
|
---|
144 | //write the output root file
|
---|
145 | ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
|
---|
146 | ExRootTreeBranch *branchJet = treeWriter->NewBranch("Jet", TRootJet::Class());
|
---|
147 | ExRootTreeBranch *branchTauJet = treeWriter->NewBranch("TauJet", TRootTauJet::Class());
|
---|
148 | ExRootTreeBranch *branchElectron = treeWriter->NewBranch("Electron", TRootElectron::Class());
|
---|
149 | ExRootTreeBranch *branchMuon = treeWriter->NewBranch("Muon", TRootMuon::Class());
|
---|
150 | ExRootTreeBranch *branchPhoton = treeWriter->NewBranch("Photon", TRootPhoton::Class());
|
---|
151 | ExRootTreeBranch *branchTracks = treeWriter->NewBranch("Tracks", TRootTracks::Class());
|
---|
152 | ExRootTreeBranch *branchETmis = treeWriter->NewBranch("ETmis", TRootETmis::Class());
|
---|
153 | ExRootTreeBranch *branchCalo = treeWriter->NewBranch("CaloTower", TRootCalo::Class());
|
---|
154 | ExRootTreeBranch *branchZDC = treeWriter->NewBranch("ZDChits", TRootZdcHits::Class());
|
---|
155 | ExRootTreeBranch *branchRP220 = treeWriter->NewBranch("RP220hits", TRootRomanPotHits::Class());
|
---|
156 | ExRootTreeBranch *branchFP420 = treeWriter->NewBranch("FP420hits", TRootRomanPotHits::Class());
|
---|
157 |
|
---|
158 |
|
---|
159 | TRootGenParticle *particle;
|
---|
160 | TRootETmis *elementEtmis;
|
---|
161 | TRootElectron *elementElec;
|
---|
162 | TRootMuon *elementMu;
|
---|
163 | TRootPhoton *elementPhoton;
|
---|
164 | TRootTracks *elementTracks;
|
---|
165 | TRootCalo *elementCalo;
|
---|
166 |
|
---|
167 | TLorentzVector genMomentum(0,0,0,0);
|
---|
168 | TLorentzVector genMomentumCalo(0,0,0,0);
|
---|
169 | LorentzVector jetMomentum;
|
---|
170 |
|
---|
171 | vector<fastjet::PseudoJet> input_particles;//for FastJet algorithm
|
---|
172 | vector<fastjet::PseudoJet> sorted_jets;
|
---|
173 |
|
---|
174 | vector<TLorentzVector> TrackCentral;
|
---|
175 | vector<PhysicsTower> towers;
|
---|
176 |
|
---|
177 | vector<TLorentzVector> electron;
|
---|
178 | vector<int> elecPID;
|
---|
179 | vector<TLorentzVector> muon;
|
---|
180 | vector<int> muonPID;
|
---|
181 | TSimpleArray<TRootGenParticle> NFCentralQ;
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 | // Loop over all events
|
---|
186 | Long64_t entry, allEntries = treeReader->GetEntries();
|
---|
187 | cout << "** Chain contains " << allEntries << " events" << endl;
|
---|
188 | for(entry = 0; entry < allEntries; ++entry)
|
---|
189 | {
|
---|
190 | TLorentzVector PTmis(0,0,0,0);
|
---|
191 | treeReader->ReadEntry(entry);
|
---|
192 | treeWriter->Clear();
|
---|
193 | if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl;
|
---|
194 |
|
---|
195 | electron.clear();
|
---|
196 | muon.clear();
|
---|
197 | elecPID.clear();
|
---|
198 | muonPID.clear();
|
---|
199 | NFCentralQ.Clear();
|
---|
200 |
|
---|
201 | itGen.Reset();
|
---|
202 | TrackCentral.clear();
|
---|
203 | towers.clear();
|
---|
204 | input_particles.clear();
|
---|
205 |
|
---|
206 | // Loop over all particles in event
|
---|
207 | while( (particle = (TRootGenParticle*) itGen.Next()) )
|
---|
208 | {
|
---|
209 | int pid = abs(particle->PID);
|
---|
210 | //// This subarray is needed for the B-jet algorithm
|
---|
211 | // optimization for speed : put first PID condition, then ETA condition, then either pt or status
|
---|
212 | 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 ?
|
---|
213 | fabs(particle->Eta) < DET->MAX_TRACKER &&
|
---|
214 | particle->Status != 1 &&
|
---|
215 | particle->PT > DET->PT_QUARKS_MIN ) {
|
---|
216 | NFCentralQ.Add(particle);
|
---|
217 | }
|
---|
218 |
|
---|
219 | // keeps only final particles, visible by the central detector, including the fiducial volume
|
---|
220 | // the ordering of conditions have been optimised for speed : put first the STATUS condition
|
---|
221 | //
|
---|
222 | //
|
---|
223 | if( (particle->Status == 1) &&
|
---|
224 | ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
|
---|
225 | (fabs(particle->Eta) < DET->MAX_CALO_FWD)
|
---|
226 | )
|
---|
227 | {
|
---|
228 | genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
|
---|
229 | TRACP->Propagation(particle,genMomentum);
|
---|
230 | float eta=fabs(genMomentum.Eta());
|
---|
231 | switch(pid) {
|
---|
232 |
|
---|
233 | case pE: // all electrons with eta < DET->MAX_CALO_FWD
|
---|
234 | DET->SmearElectron(genMomentum);
|
---|
235 | electron.push_back(genMomentum);
|
---|
236 | elecPID.push_back(particle->PID);
|
---|
237 | break; // case pE
|
---|
238 | case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD
|
---|
239 | DET->SmearElectron(genMomentum);
|
---|
240 | if(genMomentum.E()!=0 && eta < DET->MAX_TRACKER) {
|
---|
241 | elementPhoton = (TRootPhoton*) branchPhoton->NewEntry();
|
---|
242 | elementPhoton->Set(genMomentum);
|
---|
243 | }
|
---|
244 | break; // case pGAMMA
|
---|
245 | case pMU: // all muons with eta < DET->MAX_MU
|
---|
246 | DET->SmearMu(genMomentum);
|
---|
247 | muonPID.push_back(particle->PID);
|
---|
248 | muon.push_back(genMomentum);
|
---|
249 | break; // case pMU
|
---|
250 | case pLAMBDA: // all lambdas with eta < DET->MAX_CALO_FWD
|
---|
251 | case pK0S: // all K0s with eta < DET->MAX_CALO_FWD
|
---|
252 | DET->SmearHadron(genMomentum, 0.7);
|
---|
253 | break; // case hadron
|
---|
254 | default: // all other final particles with eta < DET->MAX_CALO_FWD
|
---|
255 | DET->SmearHadron(genMomentum, 1.0);
|
---|
256 | break;
|
---|
257 | } // switch (pid)
|
---|
258 |
|
---|
259 | // all final particles but muons and neutrinos
|
---|
260 | // for calorimetric towers and mission PT
|
---|
261 |
|
---|
262 | if(genMomentum.E() !=0) {
|
---|
263 | if(pid !=pMU) {
|
---|
264 | PhysicsTower CaloTower = PhysicsTower(LorentzVector(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
|
---|
265 | towers.push_back(CaloTower);
|
---|
266 | // create a fastjet::PseudoJet with these components and put it onto
|
---|
267 | // back of the input_particles vector
|
---|
268 | input_particles.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
|
---|
269 |
|
---|
270 | genMomentumCalo.SetPxPyPzE(CaloTower.fourVector.px,CaloTower.fourVector.py,CaloTower.fourVector.pz,CaloTower.fourVector.E);
|
---|
271 | elementCalo = (TRootCalo*) branchCalo->NewEntry();
|
---|
272 | elementCalo->Set(genMomentumCalo);
|
---|
273 | }
|
---|
274 | }
|
---|
275 |
|
---|
276 | // all final charged particles
|
---|
277 | if(
|
---|
278 | ((rand()%100) < DET->TRACKING_EFF) &&
|
---|
279 | (genMomentum.E()!=0) &&
|
---|
280 | (fabs(genMomentum.Eta()) < DET->MAX_TRACKER) &&
|
---|
281 | (genMomentum.Pt() > DET->PT_TRACKS_MIN ) && // pt too small to be taken into account
|
---|
282 | (pid != pGAMMA) &&
|
---|
283 | (pid != pPI0) &&
|
---|
284 | (pid != pK0L) &&
|
---|
285 | (pid != pN) &&
|
---|
286 | (pid != pSIGMA0) &&
|
---|
287 | (pid != pDELTA0) &&
|
---|
288 | (pid != pK0S) // not charged particles : invisible by tracker
|
---|
289 | )
|
---|
290 | {
|
---|
291 | elementTracks = (TRootTracks*) branchTracks->NewEntry();
|
---|
292 | elementTracks->Set(genMomentum);
|
---|
293 | TrackCentral.push_back(genMomentum);
|
---|
294 | }
|
---|
295 |
|
---|
296 | } // switch
|
---|
297 |
|
---|
298 | VFD->ZDC(treeWriter,branchZDC,particle);
|
---|
299 | VFD->RomanPots(treeWriter,branchRP220,branchFP420,particle);
|
---|
300 |
|
---|
301 | } // while
|
---|
302 |
|
---|
303 | for(unsigned int i=0; i < electron.size(); i++) {
|
---|
304 | if(electron[i].E()!=0 && fabs(electron[i].Eta()) < DET->MAX_TRACKER && electron[i].Pt() > DET->ELEC_pt)
|
---|
305 | {
|
---|
306 | elementElec = (TRootElectron*) branchElectron->NewEntry();
|
---|
307 | elementElec->Set(electron[i]);
|
---|
308 | elementElec->Charge = sign(elecPID[i]);
|
---|
309 | elementElec->IsolFlag = DET->Isolation(electron[i].Phi(),electron[i].Eta(),TrackCentral,2.0);
|
---|
310 | }
|
---|
311 | }
|
---|
312 | for(unsigned int i=0; i < muon.size(); i++) {
|
---|
313 | if(muon[i].E()!=0 && fabs(muon[i].Eta()) < DET->MAX_MU && muon[i].Pt() > DET->MUON_pt)
|
---|
314 | {
|
---|
315 | elementMu = (TRootMuon*) branchMuon->NewEntry();
|
---|
316 | elementMu->Charge = sign(muonPID[i]);
|
---|
317 | elementMu->Set(muon[i]);
|
---|
318 | elementMu->IsolFlag = DET->Isolation(muon[i].Phi(),muon[i].Eta(),TrackCentral,2.0);
|
---|
319 | }
|
---|
320 | }
|
---|
321 |
|
---|
322 | // computes the Missing Transverse Momentum
|
---|
323 | TLorentzVector Att(0.,0.,0.,0.);
|
---|
324 | for(unsigned int i=0; i < towers.size(); i++)
|
---|
325 | {
|
---|
326 | Att.SetPxPyPzE(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E);
|
---|
327 | PTmis = PTmis + Att;
|
---|
328 | }
|
---|
329 | elementEtmis = (TRootETmis*) branchETmis->NewEntry();
|
---|
330 | elementEtmis->ET = (PTmis).Pt();
|
---|
331 | elementEtmis->Phi = (-PTmis).Phi();
|
---|
332 | elementEtmis->Px = (-PTmis).Px();
|
---|
333 | elementEtmis->Py = (-PTmis).Py();
|
---|
334 |
|
---|
335 | //*****************************
|
---|
336 | treeWriter->Fill();
|
---|
337 |
|
---|
338 | sorted_jets=JETRUN->RunJets(input_particles);
|
---|
339 | JETRUN->RunJetBtagging(treeWriter, branchJet,sorted_jets,NFCentralQ);
|
---|
340 | JETRUN->RunTauJets(treeWriter,branchTauJet,sorted_jets,towers, TrackCentral);
|
---|
341 |
|
---|
342 | // Add here the trigger
|
---|
343 | // Should test all the trigger table on the event, based on reconstructed objects
|
---|
344 |
|
---|
345 | } // Loop over all events
|
---|
346 |
|
---|
347 | treeWriter->Write();
|
---|
348 |
|
---|
349 | cout << "** Exiting..." << endl;
|
---|
350 |
|
---|
351 | delete treeWriter;
|
---|
352 | delete treeReader;
|
---|
353 | delete DET;
|
---|
354 | if(converter) delete converter;
|
---|
355 |
|
---|
356 | todo("TODO");
|
---|
357 | }
|
---|
358 |
|
---|