Fork me on GitHub

source: svn/trunk/Resolutions.cpp@ 36

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

OK for jet resolution

File size: 12.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"
[19]31#include "Utilities/Fastjet/include/fastjet/PseudoJet.hh"
32#include "Utilities/Fastjet/include/fastjet/ClusterSequence.hh"
33
34// get info on how fastjet was configured
35#include "Utilities/Fastjet/include/fastjet/config.h"
36
37// make sure we have what is needed
38#ifdef ENABLE_PLUGIN_SISCONE
39# include "Utilities/Fastjet/plugins/SISCone/SISConePlugin.hh"
40#endif
41#ifdef ENABLE_PLUGIN_CDFCONES
42# include "Utilities/Fastjet/plugins/CDFCones/CDFMidPointPlugin.hh"
43# include "Utilities/Fastjet/plugins/CDFCones/CDFJetCluPlugin.hh"
44#endif
45
46#include<vector>
47#include<iostream>
48
[9]49#include "interface/TreeClasses.h"
50using namespace std;
51
52//------------------------------------------------------------------------------
53
[26]54
55
56void PairingJet(TLorentzVector &JETSm, TLorentzVector JET, vector<fastjet::PseudoJet> sorted_jetsS)
[9]57{
58 JETSm.SetPxPyPzE(0,0,0,0);
59 float deltaRtest=5000;
[19]60 for (unsigned int i = 0; i < sorted_jetsS.size(); i++) {
61 TLorentzVector Att;
62 Att.SetPxPyPzE(sorted_jetsS[i].px(),sorted_jetsS[i].py(),sorted_jetsS[i].pz(),sorted_jetsS[i].E());
63 if(DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
64 {
65 deltaRtest = DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta());
66 if(deltaRtest < 0.25)
67 {
68 JETSm = Att;
69 }
70 }
71 }
[9]72}
73
74
75int main(int argc, char *argv[])
76{
77 int appargc = 2;
[26]78 char *appName = "Smearing";
[9]79 char *appargv[] = {appName, "-b"};
80 TApplication app(appName, &appargc, appargv);
81
82 if(argc != 4 && argc != 3) {
83 cout << " Usage: " << argv[0] << " input_file" << " output_file" << " data_card " << endl;
84 cout << " input_list - list of files in Ntpl, StdHep of LHEF format," << endl;
85 cout << " output_file - output file." << endl;
86 cout << " data_card - Datacard containing resolution variables for the detector simulation (optional) "<<endl;
87 exit(1);
88 }
89
90 srand (time (NULL)); /* Initialisation du générateur */
91
92 //read the input TROOT file
93 string inputFileList(argv[1]), outputfilename(argv[2]);
94 if(outputfilename.find(".root") > outputfilename.length() ) {
95 cout << "output_file should be a .root file!\n";
96 return -1;
97 }
98 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
99 outputFile->Close();
[26]100
[9]101 string line;
102 ifstream infile(inputFileList.c_str());
103 infile >> line; // the first line determines the type of input files
[26]104
[9]105 DataConverter *converter=0;
[26]106
[9]107 if(strstr(line.c_str(),".hep"))
108 {
109 cout<<"*************************************************************************"<<endl;
110 cout<<"************ StdHEP file format detected **************"<<endl;
111 cout<<"************ Starting convertion to TRoot format **************"<<endl;
112 cout<<"*************************************************************************"<<endl;
113 converter = new STDHEPConverter(inputFileList,outputfilename);//case ntpl file in input list
114 }
115 else if(strstr(line.c_str(),".lhe"))
116 {
117 cout<<"*************************************************************************"<<endl;
118 cout<<"************ LHEF file format detected **************"<<endl;
119 cout<<"************ Starting convertion to TRoot format **************"<<endl;
120 cout<<"*************************************************************************"<<endl;
121 converter = new LHEFConverter(inputFileList,outputfilename);//case ntpl file in input list
122 }
123 else if(strstr(line.c_str(),".root"))
124 {
125 cout<<"*************************************************************************"<<endl;
126 cout<<"************ h2root file format detected **************"<<endl;
127 cout<<"************ Starting convertion to TRoot format **************"<<endl;
128 cout<<"*************************************************************************"<<endl;
129 converter = new HEPEVTConverter(inputFileList,outputfilename);//case ntpl file in input list
130 }
131 else { cout << "*** " << line.c_str() << "\n*** file format not identified\n*** Exiting\n"; return -1;};
[26]132
[9]133 TChain chain("GEN");
134 chain.Add(outputfilename.c_str());
135 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
136 const TClonesArray *branchGen = treeReader->UseBranch("Particle");
137 TIter itGen((TCollection*)branchGen);
138
139 //write the output root file
140 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
141 ExRootTreeBranch *branchjet = treeWriter->NewBranch("JetPTResol", RESOLJET::Class());
142 ExRootTreeBranch *branchelec = treeWriter->NewBranch("ElecEResol", RESOLELEC::Class());
143 ExRootTreeBranch *branchmuon = treeWriter->NewBranch("MuonPTResol", RESOLMUON::Class());
144 ExRootTreeBranch *branchtaujet = treeWriter->NewBranch("TauJetPTResol", TAUHAD::Class());
145 ExRootTreeBranch *branchetmis = treeWriter->NewBranch("ETmisResol",ETMIS::Class());
[26]146
[9]147 TRootGenParticle *particle;
148 TRootETmis *etmisc;
[26]149
[9]150 RESOLELEC *elementElec;
151 RESOLMUON *elementMuon;
152 RESOLJET *elementJet;
153 TAUHAD *elementTaujet;
154 ETMIS *elementEtmis;
[26]155
156
[9]157 //read the datacard input file
158 string DetDatacard("");
159 if(argc==4) DetDatacard =argv[3];
160 RESOLution *DET = new RESOLution();
161 DET->ReadDataCard(DetDatacard);
162
163 TLorentzVector genMomentum(0,0,0,0);
164 LorentzVector jetMomentum;
[19]165 vector<TLorentzVector> TrackCentral;
[26]166
[19]167 vector<fastjet::PseudoJet> input_particles;//for FastJet algorithm
168 vector<fastjet::PseudoJet> inclusive_jets;
169 vector<fastjet::PseudoJet> sorted_jets;
[26]170
[19]171 vector<fastjet::PseudoJet> input_particlesS;//for FastJet algorithm
172 vector<fastjet::PseudoJet> inclusive_jetsS;
173 vector<fastjet::PseudoJet> sorted_jetsS;
[23]174 vector<PhysicsTower> towers;
[26]175
[19]176 fastjet::JetDefinition jet_def;
177 fastjet::JetDefinition jet_defS;
178 fastjet::JetDefinition::Plugin * plugins;
179 fastjet::JetDefinition::Plugin * pluginsS;
[26]180
[19]181 // set up a CDF midpoint jet definition
[26]182#ifdef ENABLE_PLUGIN_CDFCONES
[23]183 plugins = new fastjet::CDFJetCluPlugin(0,DET->CONERADIUS,DET->C_ADJACENCYCUT,DET->C_MAXITERATIONS,DET->C_IRATCH,DET->C_OVERLAPTHRESHOLD);
[19]184 jet_def = fastjet::JetDefinition(plugins);
[26]185#else
[19]186 plugins = NULL;
[26]187#endif
188
[19]189 // set up a CDF midpoint jet definition
[26]190#ifdef ENABLE_PLUGIN_CDFCONES
191 pluginsS = new fastjet::CDFJetCluPlugin(1,DET->CONERADIUS,DET->C_ADJACENCYCUT,DET->C_MAXITERATIONS,DET->C_IRATCH,DET->C_OVERLAPTHRESHOLD);
[19]192 jet_defS = fastjet::JetDefinition(pluginsS);
[26]193#else
[19]194 pluginsS = NULL;
[26]195#endif
196
197
[9]198 // Loop over all events
199 Long64_t entry, allEntries = treeReader->GetEntries();
200 cout << "** Chain contains " << allEntries << " events" << endl;
201 for(entry = 0; entry < allEntries; ++entry)
202 {
[23]203 TLorentzVector PTmisS(0,0,0,0);
[9]204 TLorentzVector PTmis(0,0,0,0);
205 treeReader->ReadEntry(entry);
206 treeWriter->Clear();
207
208 if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl;
209
210 TSimpleArray<TRootGenParticle> bGen;
211 itGen.Reset();
212 TrackCentral.clear();
213 TSimpleArray<TRootGenParticle> NFCentralQ;
[19]214 input_particles.clear();
215 inclusive_jets.clear();
216 sorted_jets.clear();
217 input_particlesS.clear();
218 inclusive_jetsS.clear();
219 sorted_jetsS.clear();
[23]220 towers.clear();
[26]221
[9]222 // Loop over all particles in event
223 while( (particle = (TRootGenParticle*) itGen.Next()) )
224 {
225 genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
[26]226
[9]227 int pid = abs(particle->PID);
228 float eta = fabs(particle->Eta);
[26]229
[19]230 if(particle->Status == 1)
[26]231 {
232 input_particles.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
233 }
234
[9]235 // keeps only final particles, visible by the central detector, including the fiducial volume
236 // the ordering of conditions have been optimised for speed : put first the STATUS condition
237 if( (particle->Status == 1) &&
238 (
[26]239 (pid == pMU && eta < DET->MAX_MU) ||
240 (pid != pMU && (pid != pNU1) && (pid != pNU2) && (pid != pNU3) && eta < DET->MAX_CALO_FWD) )
241 )
242 {
243 PTmis = PTmis + genMomentum;//ptmis
244 switch(pid) {
[9]245
[26]246 case pE: // all electrons with eta < DET->MAX_CALO_FWD
247 DET->SmearElectron(genMomentum);
248 break; // case pE
249 case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD
250 DET->SmearElectron(genMomentum);
251 break; // case pGAMMA
252 case pMU: // all muons with eta < DET->MAX_MU
253 DET->SmearMu(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 if(pid != pMU)
265 {
266// PTmisS = PTmisS + genMomentum;
267 towers.push_back(PhysicsTower(LorentzVector(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E())));
268 if(genMomentum.Et()>0.5)input_particlesS.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
269 }
270
271 // all final charged particles
272 if(
273 ((rand()%100) < DET->TRACKING_EFF) &&
274 (genMomentum.E()!=0) &&
275 (fabs(particle->Eta) < DET->MAX_TRACKER) &&
276 (genMomentum.Pt() > DET->PT_TRACKS_MIN ) && // pt too small to be taken into account
277 (pid != pGAMMA) &&
278 (pid != pPI0) &&
279 (pid != pK0L) &&
280 (pid != pN) &&
281 (pid != pSIGMA0) &&
282 (pid != pDELTA0) &&
283 (pid != pK0S) // not charged particles : invisible by tracker
[9]284 )
[26]285 TrackCentral.push_back(genMomentum);
[9]286 } // switch
287 } // while
[26]288
289 TLorentzVector TowerTLV(0.,0.,0.,0.);
290 for(unsigned int i=0; i < towers.size(); i++)
291 {
292 TowerTLV.SetPxPyPzE(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E);
293 if(TowerTLV.Et()>0.5)PTmisS = PTmisS + TowerTLV;
294 }
[9]295
[26]296
297 elementEtmis= (ETMIS*) branchetmis->NewEntry();
298 elementEtmis->Et = (PTmis).Et();
299 elementEtmis->EtSmeare = (PTmisS).Et()-(PTmis).Et();
300
[9]301 //*****************************
[26]302
303 double ptmin=1;
304 if(input_particles.size()!=0)
[19]305 {
306 fastjet::ClusterSequence clust_seq(input_particles, jet_def);
307 inclusive_jets = clust_seq.inclusive_jets(ptmin);
308 sorted_jets = sorted_by_pt(inclusive_jets);
309 }
[26]310
311 if(input_particlesS.size()!=0)
[19]312 {
313 fastjet::ClusterSequence clust_seqS(input_particlesS, jet_defS);
314 inclusive_jetsS = clust_seqS.inclusive_jets(ptmin);
315 sorted_jetsS = sorted_by_pt(inclusive_jetsS);
316 }
[26]317
318 TLorentzVector JETSm(0,0,0,0);
319 for (unsigned int i = 0; i < sorted_jets.size(); i++) {
[19]320 TLorentzVector JET(0,0,0,0);
321 JET.SetPxPyPzE(sorted_jets[i].px(),sorted_jets[i].py(),sorted_jets[i].pz(),sorted_jets[i].E());
322 PairingJet(JETSm,JET,sorted_jetsS);
323 if(JETSm.Pt()>1)
324 {
325 elementJet= (RESOLJET*) branchjet->NewEntry();
[23]326 elementJet->NonSmearePT = JET.Et();
327 elementJet->SmearePT = JETSm.Et()/JET.Et();
[26]328
[19]329 }
[26]330
331 } // for itJet : loop on all jets
332
[9]333 treeWriter->Fill();
334 } // Loop over all events
335 treeWriter->Write();
336
337 cout << "** Exiting..." << endl;
338
339 delete treeWriter;
340 delete treeReader;
341 delete DET;
342 if(converter) delete converter;
343}
344
Note: See TracBrowser for help on using the repository browser.