Fork me on GitHub

source: svn/trunk/Resolutions.cpp@ 206

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

one warning removed

File size: 15.2 KB
RevLine 
[9]1/*
2 ---- FastSim ----
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 Smearing.cpp
12/// \brief executable for the FastSim
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
[19]21#include "H_BeamParticle.h"
22#include "H_BeamLine.h"
23#include "H_RomanPot.h"
[9]24
25#include "interface/DataConverter.h"
26#include "interface/HEPEVTConverter.h"
27#include "interface/LHEFConverter.h"
28#include "interface/STDHEPConverter.h"
[19]29
[9]30#include "interface/SmearUtil.h"
[88]31#include "interface/JetUtils.h"
32#include "interface/BFieldProp.h"
33
[19]34#include "Utilities/Fastjet/include/fastjet/PseudoJet.hh"
35#include "Utilities/Fastjet/include/fastjet/ClusterSequence.hh"
36
37#include<vector>
38#include<iostream>
39
[9]40#include "interface/TreeClasses.h"
41using namespace std;
42
43//------------------------------------------------------------------------------
44
[39]45// //********************************** PYTHIA INFORMATION*********************************
[26]46
[39]47TSimpleArray<TRootGenParticle> TauHadr(const TClonesArray *GEN)
48 {
49 TIter it((TCollection*)GEN);
50 it.Reset();
51 TRootGenParticle *gen1;
52 TSimpleArray<TRootGenParticle> array,array2;
[26]53
[39]54 while((gen1 = (TRootGenParticle*) it.Next()))
55 {
56 array.Add(gen1);
57 }
58 it.Reset();
59 bool tauhad;
60 while((gen1 = (TRootGenParticle*) it.Next()))
61 {
62 tauhad=false;
63 if(abs(gen1->PID)==15)
64 {
65 int d1=gen1->D1;
66 int d2=gen1->D2;
67
68 if((d1 < array.GetEntries()) && (d1 > 0) && (d2 < array.GetEntries()) && (d2 > 0))
69 {
70 tauhad=true;
71 for(int d=d1; d < d2+1; d++)
72 {
73 if(abs(array[d]->PID)== pE || abs(array[d]->PID)== pMU)tauhad=false;
74 }
75 }
76 }
77 if(tauhad)array2.Add(gen1);
78 }
79 return array2;
80 }
81
82
83
84void PairingJet(TLorentzVector &JETSm, const TLorentzVector &JET, vector<fastjet::PseudoJet> sorted_jetsS)
[9]85{
86 JETSm.SetPxPyPzE(0,0,0,0);
87 float deltaRtest=5000;
[19]88 for (unsigned int i = 0; i < sorted_jetsS.size(); i++) {
89 TLorentzVector Att;
90 Att.SetPxPyPzE(sorted_jetsS[i].px(),sorted_jetsS[i].py(),sorted_jetsS[i].pz(),sorted_jetsS[i].E());
91 if(DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
92 {
93 deltaRtest = DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta());
94 if(deltaRtest < 0.25)
95 {
96 JETSm = Att;
97 }
98 }
99 }
[9]100}
101
102int main(int argc, char *argv[])
103{
104 int appargc = 2;
[26]105 char *appName = "Smearing";
[9]106 char *appargv[] = {appName, "-b"};
107 TApplication app(appName, &appargc, appargv);
108
109 if(argc != 4 && argc != 3) {
110 cout << " Usage: " << argv[0] << " input_file" << " output_file" << " data_card " << endl;
111 cout << " input_list - list of files in Ntpl, StdHep of LHEF format," << endl;
112 cout << " output_file - output file." << endl;
113 cout << " data_card - Datacard containing resolution variables for the detector simulation (optional) "<<endl;
114 exit(1);
115 }
116
117 srand (time (NULL)); /* Initialisation du générateur */
118
119 //read the input TROOT file
120 string inputFileList(argv[1]), outputfilename(argv[2]);
121 if(outputfilename.find(".root") > outputfilename.length() ) {
122 cout << "output_file should be a .root file!\n";
123 return -1;
124 }
[88]125
[9]126 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
127 outputFile->Close();
[26]128
[9]129 string line;
130 ifstream infile(inputFileList.c_str());
131 infile >> line; // the first line determines the type of input files
[26]132
[9]133 DataConverter *converter=0;
[26]134
[9]135 if(strstr(line.c_str(),".hep"))
136 {
137 cout<<"*************************************************************************"<<endl;
138 cout<<"************ StdHEP file format detected **************"<<endl;
139 cout<<"************ Starting convertion to TRoot format **************"<<endl;
140 cout<<"*************************************************************************"<<endl;
141 converter = new STDHEPConverter(inputFileList,outputfilename);//case ntpl file in input list
142 }
143 else if(strstr(line.c_str(),".lhe"))
144 {
145 cout<<"*************************************************************************"<<endl;
146 cout<<"************ LHEF file format detected **************"<<endl;
147 cout<<"************ Starting convertion to TRoot format **************"<<endl;
148 cout<<"*************************************************************************"<<endl;
149 converter = new LHEFConverter(inputFileList,outputfilename);//case ntpl file in input list
150 }
151 else if(strstr(line.c_str(),".root"))
152 {
153 cout<<"*************************************************************************"<<endl;
154 cout<<"************ h2root file format detected **************"<<endl;
155 cout<<"************ Starting convertion to TRoot format **************"<<endl;
156 cout<<"*************************************************************************"<<endl;
157 converter = new HEPEVTConverter(inputFileList,outputfilename);//case ntpl file in input list
158 }
159 else { cout << "*** " << line.c_str() << "\n*** file format not identified\n*** Exiting\n"; return -1;};
[26]160
[9]161 TChain chain("GEN");
162 chain.Add(outputfilename.c_str());
163 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
164 const TClonesArray *branchGen = treeReader->UseBranch("Particle");
165 TIter itGen((TCollection*)branchGen);
166
167 //write the output root file
168 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
169 ExRootTreeBranch *branchjet = treeWriter->NewBranch("JetPTResol", RESOLJET::Class());
170 ExRootTreeBranch *branchelec = treeWriter->NewBranch("ElecEResol", RESOLELEC::Class());
171 ExRootTreeBranch *branchmuon = treeWriter->NewBranch("MuonPTResol", RESOLMUON::Class());
172 ExRootTreeBranch *branchtaujet = treeWriter->NewBranch("TauJetPTResol", TAUHAD::Class());
173 ExRootTreeBranch *branchetmis = treeWriter->NewBranch("ETmisResol",ETMIS::Class());
[26]174
[9]175 TRootGenParticle *particle;
[26]176
[39]177 RESOLELEC * elementElec;
[9]178 RESOLMUON *elementMuon;
179 RESOLJET *elementJet;
180 TAUHAD *elementTaujet;
181 ETMIS *elementEtmis;
[26]182
[152]183int numTau=0;
184int numTauRec=0;
[26]185
[9]186 //read the datacard input file
[89]187 string DetDatacard("data/DataCardDet.dat");
[9]188 if(argc==4) DetDatacard =argv[3];
189 RESOLution *DET = new RESOLution();
190 DET->ReadDataCard(DetDatacard);
[88]191
192 //Jet information
[100]193 JetsUtil *JETRUN = new JetsUtil(DetDatacard);
[88]194
195 //Propagation of tracks in the B field
[202]196 //TrackPropagation *TRACP = new TrackPropagation(DetDatacard);
[88]197
198 TLorentzVector genMomentum(0,0,0,0);//TLorentzVector containing generator level information
[152]199 TLorentzVector recoMomentumCalo(0,0,0,0);
[88]200 TLorentzVector recoMomentum(0,0,0,0);//TLorentzVector containing Reco level information
[9]201 LorentzVector jetMomentum;
[19]202 vector<TLorentzVector> TrackCentral;
[26]203
[88]204 vector<fastjet::PseudoJet> input_particlesGEN;//for FastJet algorithm
205 vector<fastjet::PseudoJet> sorted_jetsGEN;
[26]206
[88]207 vector<fastjet::PseudoJet> input_particlesReco;//for FastJet algorithm
208 vector<fastjet::PseudoJet> sorted_jetsReco;
[39]209
[23]210 vector<PhysicsTower> towers;
[152]211
212 float iPhi=0,iEta=0;
213
[9]214 // Loop over all events
215 Long64_t entry, allEntries = treeReader->GetEntries();
216 cout << "** Chain contains " << allEntries << " events" << endl;
217 for(entry = 0; entry < allEntries; ++entry)
218 {
[88]219 TLorentzVector PTmisReco(0,0,0,0);
220 TLorentzVector PTmisGEN(0,0,0,0);
[9]221 treeReader->ReadEntry(entry);
222 treeWriter->Clear();
223 if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl;
224
225 TSimpleArray<TRootGenParticle> bGen;
226 itGen.Reset();
227 TrackCentral.clear();
228 TSimpleArray<TRootGenParticle> NFCentralQ;
[89]229
[88]230 input_particlesReco.clear();
231 input_particlesGEN.clear();
[23]232 towers.clear();
[26]233
[9]234 // Loop over all particles in event
235 while( (particle = (TRootGenParticle*) itGen.Next()) )
236 {
237 genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
[26]238
[9]239 int pid = abs(particle->PID);
240 float eta = fabs(particle->Eta);
[89]241
[88]242 //input generator level particle for jet algorithm
[94]243 if(particle->Status == 1 && eta < DET->CEN_max_calo_fwd)
[26]244 {
[88]245 input_particlesGEN.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
[26]246 }
[89]247
[88]248 //Calculate ETMIS from generated particles
249 if((pid == pNU1) || (pid == pNU2) || (pid == pNU3))PTmisGEN = PTmisGEN + genMomentum;
[89]250
[88]251 if( (particle->Status == 1) &&
252 ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
[94]253 (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
[88]254 )
255 {
256 recoMomentum = genMomentum;
257 //use of the magnetic field propagation
[152]258 //TRACP->Propagation(particle,recoMomentum);
[89]259 // cout<<"eta "<<eta<<endl;
260 eta=fabs(recoMomentum.Eta());
261 // cout<<"eta apres"<<eta<<endl;
262
[26]263 switch(pid) {
[89]264
[26]265 case pE: // all electrons with eta < DET->MAX_CALO_FWD
[88]266 DET->SmearElectron(recoMomentum);
[94]267 if(recoMomentum.E() !=0 && eta < DET->CEN_max_tracker){
[89]268 elementElec=(RESOLELEC*) branchelec->NewEntry();
269 elementElec->E = genMomentum.E();
270 elementElec->SmearedE = recoMomentum.E();}
[26]271 break; // case pE
272 case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD
[88]273 DET->SmearElectron(recoMomentum);
[26]274 break; // case pGAMMA
275 case pMU: // all muons with eta < DET->MAX_MU
[88]276 DET->SmearMu(recoMomentum);
[89]277 if(recoMomentum.E() !=0){
[39]278 elementMuon = (RESOLMUON*) branchmuon->NewEntry();
[88]279 elementMuon->OverPT = (1/genMomentum.Pt());
[89]280 elementMuon->OverSmearedPT = (1/recoMomentum.Pt());}
[26]281 break; // case pMU
282 case pLAMBDA: // all lambdas with eta < DET->MAX_CALO_FWD
283 case pK0S: // all K0s with eta < DET->MAX_CALO_FWD
[88]284 DET->SmearHadron(recoMomentum, 0.7);
[26]285 break; // case hadron
286 default: // all other final particles with eta < DET->MAX_CALO_FWD
[88]287 DET->SmearHadron(recoMomentum, 1.0);
[26]288 break;
289 } // switch (pid)
[89]290
291 //information to reconstruct jets from reconstructed towers
[152]292 int charge=Charge(pid);
293 if(recoMomentum.E() !=0 && pid != pMU) {
[182]294 // in case the Bfield is not simulated, checks that charged particles have enough pt to reach the calos
295 if ( !DET->FLAG_bfield && charge!=0 && genMomentum.Pt() <= DET->TRACK_ptmin ) { /* particules do not reach calos */ }
296 else { // particles reach calos
[152]297 DET->BinEtaPhi(recoMomentum.Phi(), recoMomentum.Eta(), iPhi, iEta);
298 if(iEta != -100 && iPhi != -100)
299 {
300 recoMomentumCalo.SetPtEtaPhiE(recoMomentum.Pt(),iEta,iPhi,recoMomentum.E());
301
302 PhysicsTower Tower(LorentzVector(recoMomentumCalo.Px(),recoMomentumCalo.Py(),recoMomentumCalo.Pz(), recoMomentumCalo.E()));
303 towers.push_back(Tower);
304 }
305 }
306 }
[182]307
[26]308 // all final charged particles
[89]309 if(
[152]310 (recoMomentum.E()!=0) &&
311 (fabs(recoMomentum.Eta()) < DET->CEN_max_tracker) &&
[182]312 (DET->FLAG_bfield || ( !DET->FLAG_bfield && genMomentum.Pt() > DET->TRACK_ptmin )) &&
313 // if bfield not simulated, pt should be high enough to be taken into account
[94]314 ((rand()%100) < DET->TRACK_eff) &&
[89]315 (charge!=0)
316 )
[152]317 {TrackCentral.push_back(recoMomentum);}
[89]318
[9]319 } // switch
320 } // while
[89]321
322 //compute missing transverse energy from calo towers
323 TLorentzVector Att(0.,0.,0.,0.);
324 float ScalarEt=0;
[152]325 for(unsigned int i=0; i < towers.size(); i++)
326 {
327 Att.SetPxPyPzE(towers[i].fourVector.px, towers[i].fourVector.py, towers[i].fourVector.pz, towers[i].fourVector.E);
328 if(fabs(Att.Eta()) < DET->CEN_max_calo_fwd)
329 {
330 ScalarEt = ScalarEt + Att.Et();
331 PTmisReco = PTmisReco + Att;
332 // create a fastjet::PseudoJet with these components and put it onto
333 // back of the input_particles vector
334 input_particlesReco.push_back(fastjet::PseudoJet(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E));
335 }
336 }
[89]337
338 elementEtmis= (ETMIS*) branchetmis->NewEntry();
339 elementEtmis->Et = (PTmisGEN).Pt();
340 elementEtmis->Ex = (-PTmisGEN).Px();
341 elementEtmis->SEt = ScalarEt;
[88]342
[89]343 elementEtmis->EtSmeare = (PTmisReco).Pt()-(PTmisGEN).Pt();
344 elementEtmis->ExSmeare = (-PTmisReco).Px()-(PTmisGEN).Px();
[9]345
346 //*****************************
[26]347
[88]348 sorted_jetsGEN=JETRUN->RunJets(input_particlesGEN);
349 sorted_jetsReco=JETRUN->RunJets(input_particlesReco);
350
[39]351 TSimpleArray<TRootGenParticle> TausHadr = TauHadr(branchGen);
352
[88]353 TLorentzVector JETreco(0,0,0,0);
354 for (unsigned int i = 0; i < sorted_jetsGEN.size(); i++) {
355 TLorentzVector JETgen(0,0,0,0);
356 JETgen.SetPxPyPzE(sorted_jetsGEN[i].px(),sorted_jetsGEN[i].py(),sorted_jetsGEN[i].pz(),sorted_jetsGEN[i].E());
357 PairingJet(JETreco,JETgen,sorted_jetsReco);
358 if(JETreco.Pt()>1)
[19]359 {
360 elementJet= (RESOLJET*) branchjet->NewEntry();
[88]361 elementJet->PT = JETgen.Et();
362 elementJet->SmearedPT = JETreco.Et()/JETgen.Et();
[19]363 }
[39]364 }
[152]365 numTau = numTau+TausHadr.GetEntries();
[88]366 for (unsigned int i = 0; i < sorted_jetsReco.size(); i++) {
[39]367 TLorentzVector JETT(0,0,0,0);
[88]368 JETT.SetPxPyPzE(sorted_jetsReco[i].px(),sorted_jetsReco[i].py(),sorted_jetsReco[i].pz(),sorted_jetsReco[i].E());
[94]369 if(fabs(JETT.Eta()) < (DET->CEN_max_tracker - DET->TAU_track_scone))
[39]370 {
371 for(Int_t i=0; i<TausHadr.GetEntries();i++)
372 {
373 if(DeltaR(TausHadr[i]->Phi,TausHadr[i]->Eta,JETT.Phi(),JETT.Eta())<0.1)
374 {
375 elementTaujet= (TAUHAD*) branchtaujet->NewEntry();
376 elementTaujet->EnergieCen = (DET->EnergySmallCone(towers,JETT.Eta(),JETT.Phi())/JETT.E());
[94]377 elementTaujet->NumTrack = DET->NumTracks(TrackCentral,DET->TAU_track_pt,JETT.Eta(),JETT.Phi());
[152]378 if( (DET->EnergySmallCone(towers,JETT.Eta(),JETT.Phi())/JETT.E()) > 0.95
379 && (DET->NumTracks(TrackCentral,DET->TAU_track_pt,JETT.Eta(),JETT.Phi()))==1)numTauRec++;
380
[39]381 }
382 }
383 }
384
[26]385
386 } // for itJet : loop on all jets
387
[9]388 treeWriter->Fill();
389 } // Loop over all events
390 treeWriter->Write();
[152]391float frac = numTauRec/numTau;
392cout<<numTauRec<<endl;
393cout<<numTau<<endl;
394
[9]395 cout << "** Exiting..." << endl;
[152]396 cout<<frac<<endl;
397
[9]398
399 delete treeWriter;
400 delete treeReader;
401 delete DET;
402 if(converter) delete converter;
403}
404
Note: See TracBrowser for help on using the repository browser.