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 |
|
---|
21 | #include "H_BeamParticle.h"
|
---|
22 | #include "H_BeamLine.h"
|
---|
23 | #include "H_RomanPot.h"
|
---|
24 |
|
---|
25 | #include "interface/DataConverter.h"
|
---|
26 | #include "interface/HEPEVTConverter.h"
|
---|
27 | #include "interface/LHEFConverter.h"
|
---|
28 | #include "interface/STDHEPConverter.h"
|
---|
29 |
|
---|
30 | #include "interface/SmearUtil.h"
|
---|
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 |
|
---|
49 | #include "interface/TreeClasses.h"
|
---|
50 | using namespace std;
|
---|
51 |
|
---|
52 | //------------------------------------------------------------------------------
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 | void PairingJet(TLorentzVector &JETSm, TLorentzVector JET, vector<fastjet::PseudoJet> sorted_jetsS)
|
---|
57 | {
|
---|
58 | JETSm.SetPxPyPzE(0,0,0,0);
|
---|
59 | float deltaRtest=5000;
|
---|
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 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | int main(int argc, char *argv[])
|
---|
76 | {
|
---|
77 | int appargc = 2;
|
---|
78 | char *appName = "Smearing";
|
---|
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();
|
---|
100 |
|
---|
101 | string line;
|
---|
102 | ifstream infile(inputFileList.c_str());
|
---|
103 | infile >> line; // the first line determines the type of input files
|
---|
104 |
|
---|
105 | DataConverter *converter=0;
|
---|
106 |
|
---|
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;};
|
---|
132 |
|
---|
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());
|
---|
146 |
|
---|
147 | TRootGenParticle *particle;
|
---|
148 | TRootETmis *etmisc;
|
---|
149 |
|
---|
150 | RESOLELEC *elementElec;
|
---|
151 | RESOLMUON *elementMuon;
|
---|
152 | RESOLJET *elementJet;
|
---|
153 | TAUHAD *elementTaujet;
|
---|
154 | ETMIS *elementEtmis;
|
---|
155 |
|
---|
156 |
|
---|
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;
|
---|
165 | vector<TLorentzVector> TrackCentral;
|
---|
166 |
|
---|
167 | vector<fastjet::PseudoJet> input_particles;//for FastJet algorithm
|
---|
168 | vector<fastjet::PseudoJet> inclusive_jets;
|
---|
169 | vector<fastjet::PseudoJet> sorted_jets;
|
---|
170 |
|
---|
171 | vector<fastjet::PseudoJet> input_particlesS;//for FastJet algorithm
|
---|
172 | vector<fastjet::PseudoJet> inclusive_jetsS;
|
---|
173 | vector<fastjet::PseudoJet> sorted_jetsS;
|
---|
174 | vector<PhysicsTower> towers;
|
---|
175 |
|
---|
176 | fastjet::JetDefinition jet_def;
|
---|
177 | fastjet::JetDefinition jet_defS;
|
---|
178 | fastjet::JetDefinition::Plugin * plugins;
|
---|
179 | fastjet::JetDefinition::Plugin * pluginsS;
|
---|
180 |
|
---|
181 | // set up a CDF midpoint jet definition
|
---|
182 | #ifdef ENABLE_PLUGIN_CDFCONES
|
---|
183 | plugins = new fastjet::CDFJetCluPlugin(0,DET->CONERADIUS,DET->C_ADJACENCYCUT,DET->C_MAXITERATIONS,DET->C_IRATCH,DET->C_OVERLAPTHRESHOLD);
|
---|
184 | jet_def = fastjet::JetDefinition(plugins);
|
---|
185 | #else
|
---|
186 | plugins = NULL;
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | // set up a CDF midpoint jet definition
|
---|
190 | #ifdef ENABLE_PLUGIN_CDFCONES
|
---|
191 | pluginsS = new fastjet::CDFJetCluPlugin(2,DET->CONERADIUS,DET->C_ADJACENCYCUT,DET->C_MAXITERATIONS,DET->C_IRATCH,DET->C_OVERLAPTHRESHOLD);
|
---|
192 | jet_defS = fastjet::JetDefinition(pluginsS);
|
---|
193 | #else
|
---|
194 | pluginsS = NULL;
|
---|
195 | #endif
|
---|
196 |
|
---|
197 |
|
---|
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 | {
|
---|
203 | TLorentzVector PTmisS(0,0,0,0);
|
---|
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;
|
---|
214 | input_particles.clear();
|
---|
215 | inclusive_jets.clear();
|
---|
216 | sorted_jets.clear();
|
---|
217 | input_particlesS.clear();
|
---|
218 | inclusive_jetsS.clear();
|
---|
219 | sorted_jetsS.clear();
|
---|
220 | towers.clear();
|
---|
221 |
|
---|
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);
|
---|
226 |
|
---|
227 | int pid = abs(particle->PID);
|
---|
228 | float eta = fabs(particle->Eta);
|
---|
229 |
|
---|
230 | if(particle->Status == 1)
|
---|
231 | {
|
---|
232 | input_particles.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
|
---|
233 | }
|
---|
234 |
|
---|
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 | (
|
---|
239 | (pid == pMU && eta < DET->MAX_MU) ||
|
---|
240 | (pid != pMU && (pid != pNU1) && (pid != pNU2) && (pid != pNU3) && eta < DET->MAX_CALO_FWD)
|
---|
241 | )
|
---|
242 | ) {
|
---|
243 | if(pid != pMU)PTmis = PTmis + genMomentum;//ptmis
|
---|
244 | switch(pid) {
|
---|
245 |
|
---|
246 | case pE: // all electrons with eta < DET->MAX_CALO_FWD
|
---|
247 | DET->SmearElectron(genMomentum);
|
---|
248 | break; // case pE
|
---|
249 |
|
---|
250 | case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD
|
---|
251 | DET->SmearElectron(genMomentum);
|
---|
252 | break; // case pGAMMA
|
---|
253 |
|
---|
254 | case pMU: // all muons with eta < DET->MAX_MU
|
---|
255 | DET->SmearMu(genMomentum);
|
---|
256 | break; // case pMU
|
---|
257 |
|
---|
258 | case pLAMBDA: // all lambdas with eta < DET->MAX_CALO_FWD
|
---|
259 | case pK0S: // all K0s with eta < DET->MAX_CALO_FWD
|
---|
260 | DET->SmearHadron(genMomentum, 0.7);
|
---|
261 | break; // case hadron
|
---|
262 |
|
---|
263 | default: // all other final particles with eta < DET->MAX_CALO_FWD
|
---|
264 | DET->SmearHadron(genMomentum, 1.0);
|
---|
265 | break;
|
---|
266 | } // switch (pid)
|
---|
267 |
|
---|
268 | // all final particles but muons and neutrinos
|
---|
269 | // for calorimetric towers and mission PT
|
---|
270 | //if(genMomentum.E()!=0) PTmis = PTmis + genMomentum;//ptmis
|
---|
271 |
|
---|
272 | if(pid != pMU)
|
---|
273 | {
|
---|
274 | PTmisS = PTmisS + genMomentum;
|
---|
275 | towers.push_back(PhysicsTower(LorentzVector(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E())));
|
---|
276 | input_particlesS.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
|
---|
277 | }
|
---|
278 |
|
---|
279 | // all final charged particles
|
---|
280 | if(
|
---|
281 | ((rand()%100) < DET->TRACKING_EFF) &&
|
---|
282 | (genMomentum.E()!=0) &&
|
---|
283 | (fabs(particle->Eta) < DET->MAX_TRACKER) &&
|
---|
284 | (genMomentum.Pt() > DET->PT_TRACKS_MIN ) && // pt too small to be taken into account
|
---|
285 | (pid != pGAMMA) &&
|
---|
286 | (pid != pPI0) &&
|
---|
287 | (pid != pK0L) &&
|
---|
288 | (pid != pN) &&
|
---|
289 | (pid != pSIGMA0) &&
|
---|
290 | (pid != pDELTA0) &&
|
---|
291 | (pid != pK0S) // not charged particles : invisible by tracker
|
---|
292 | )
|
---|
293 | TrackCentral.push_back(genMomentum);
|
---|
294 | } // switch
|
---|
295 | } // while
|
---|
296 |
|
---|
297 | TLorentzVector toWerS(0,0,0,0);
|
---|
298 | //calcul de ETmis au depart des tours calorimetriques..
|
---|
299 | /* for(unsigned int i=0; i < towers.size(); i++) {
|
---|
300 | if(towers[i].fourVector.pt() < 0.5) continue;
|
---|
301 | toWerS.SetPxPyPzE(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E);
|
---|
302 | PTmisS = PTmisS + toWerS;
|
---|
303 | }
|
---|
304 | */
|
---|
305 | //PTmis = (0,0,0,0)-PTmis;
|
---|
306 | //PTmisS = (0,0,0,0)-PTmisS;
|
---|
307 |
|
---|
308 | //float ET=PTmis.Et()<<endl;
|
---|
309 | //float ETS=PTmisS.Et()<<endl;
|
---|
310 |
|
---|
311 | cout<<"Ptmis "<<PTmis.Et()<<" PTmis smeare "<<PTmisS.Et()<<endl;
|
---|
312 | cout<<"Ptmis "<<(-PTmis).Pt()<<" PTmis smeare "<<(-PTmisS).Pt()<<endl;
|
---|
313 |
|
---|
314 | elementEtmis= (ETMIS*) branchetmis->NewEntry();
|
---|
315 | elementEtmis->Et = (PTmis).Et();
|
---|
316 | elementEtmis->EtSmeare = (PTmisS).Et();
|
---|
317 |
|
---|
318 |
|
---|
319 |
|
---|
320 | //*****************************
|
---|
321 |
|
---|
322 | double ptmin=1;
|
---|
323 | if(input_particles.size()!=0)
|
---|
324 | {
|
---|
325 | fastjet::ClusterSequence clust_seq(input_particles, jet_def);
|
---|
326 | inclusive_jets = clust_seq.inclusive_jets(ptmin);
|
---|
327 | sorted_jets = sorted_by_pt(inclusive_jets);
|
---|
328 | }
|
---|
329 |
|
---|
330 | if(input_particlesS.size()!=0)
|
---|
331 | {
|
---|
332 | fastjet::ClusterSequence clust_seqS(input_particlesS, jet_defS);
|
---|
333 | inclusive_jetsS = clust_seqS.inclusive_jets(ptmin);
|
---|
334 | sorted_jetsS = sorted_by_pt(inclusive_jetsS);
|
---|
335 | }
|
---|
336 |
|
---|
337 | TLorentzVector JETSm(0,0,0,0);
|
---|
338 | for (unsigned int i = 0; i < sorted_jets.size(); i++) {
|
---|
339 | TLorentzVector JET(0,0,0,0);
|
---|
340 | JET.SetPxPyPzE(sorted_jets[i].px(),sorted_jets[i].py(),sorted_jets[i].pz(),sorted_jets[i].E());
|
---|
341 | PairingJet(JETSm,JET,sorted_jetsS);
|
---|
342 | if(JETSm.Pt()>1)
|
---|
343 | {
|
---|
344 | float NonSmeareEt=(JET.E()*sin(JET.Theta()));
|
---|
345 | float SmeareEt=(JETSm.E()*sin(JETSm.Theta()));
|
---|
346 |
|
---|
347 | elementJet= (RESOLJET*) branchjet->NewEntry();
|
---|
348 | elementJet->NonSmearePT = JET.Et();
|
---|
349 | elementJet->SmearePT = JETSm.Et()/JET.Et();
|
---|
350 |
|
---|
351 | }
|
---|
352 |
|
---|
353 | } // for itJet : loop on all jets
|
---|
354 |
|
---|
355 | treeWriter->Fill();
|
---|
356 | } // Loop over all events
|
---|
357 | treeWriter->Write();
|
---|
358 |
|
---|
359 | cout << "** Exiting..." << endl;
|
---|
360 |
|
---|
361 | delete treeWriter;
|
---|
362 | delete treeReader;
|
---|
363 | delete DET;
|
---|
364 | if(converter) delete converter;
|
---|
365 | }
|
---|
366 |
|
---|