Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 66

Last change on this file since 66 was 66, checked in by severine ovyn, 16 years ago

Remove frog stuff

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