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 | #include "TFile.h"
|
---|
17 |
|
---|
18 | #include "ExRootTreeReader.h"
|
---|
19 | #include "ExRootTreeWriter.h"
|
---|
20 | #include "ExRootTreeBranch.h"
|
---|
21 | #include "TreeClasses.h"
|
---|
22 |
|
---|
23 | #include "DataConverter.h"
|
---|
24 | #include "HEPEVTConverter.h"
|
---|
25 | #include "LHEFConverter.h"
|
---|
26 | #include "STDHEPConverter.h"
|
---|
27 |
|
---|
28 | #include "SmearUtil.h"
|
---|
29 | #include "JetsUtil.h"
|
---|
30 | #include "BFieldProp.h"
|
---|
31 |
|
---|
32 | //#include "PseudoJet.hh"
|
---|
33 | //#include "ClusterSequence.hh"
|
---|
34 |
|
---|
35 | #include<vector>
|
---|
36 | #include<iostream>
|
---|
37 |
|
---|
38 | using namespace std;
|
---|
39 |
|
---|
40 | //------------------------------------------------------------------------------
|
---|
41 |
|
---|
42 | // //********************************** PYTHIA INFORMATION*********************************
|
---|
43 |
|
---|
44 | TSimpleArray<TRootGenParticle> TauHadr(const TClonesArray *GEN)
|
---|
45 | {
|
---|
46 | TIter it((TCollection*)GEN);
|
---|
47 | it.Reset();
|
---|
48 | TRootGenParticle *gen1;
|
---|
49 | TSimpleArray<TRootGenParticle> array,array2;
|
---|
50 |
|
---|
51 | while((gen1 = (TRootGenParticle*) it.Next()))
|
---|
52 | {
|
---|
53 | array.Add(gen1);
|
---|
54 | }
|
---|
55 | it.Reset();
|
---|
56 | bool tauhad;
|
---|
57 | while((gen1 = (TRootGenParticle*) it.Next()))
|
---|
58 | {
|
---|
59 | tauhad=false;
|
---|
60 | if(abs(gen1->PID)==15)
|
---|
61 | {
|
---|
62 | int d1=gen1->D1;
|
---|
63 | int d2=gen1->D2;
|
---|
64 | if((d1 < array.GetEntries()) && (d1 > 0) && (d2 < array.GetEntries()) && (d2 > 0))
|
---|
65 | {
|
---|
66 | tauhad=true;
|
---|
67 | for(int d=d1; d < d2+1; d++)
|
---|
68 | {
|
---|
69 | if(abs(array[d]->PID)== pE || abs(array[d]->PID)== pMU)tauhad=false;
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 | if(tauhad)array2.Add(gen1);
|
---|
74 | }
|
---|
75 | return array2;
|
---|
76 | }
|
---|
77 |
|
---|
78 | double EnergySmallCone(const vector<TLorentzVector> &towers, const float eta, const float phi,float energy_scone,float JET_seed) {
|
---|
79 | double Energie=0;
|
---|
80 | for(unsigned int i=0; i < towers.size(); i++) {
|
---|
81 | if(towers[i].Pt() < JET_seed) continue;
|
---|
82 | if((DeltaR(phi,eta,towers[i].Phi(),towers[i].Eta()) < energy_scone)) {
|
---|
83 | Energie += towers[i].E();
|
---|
84 | }
|
---|
85 | }
|
---|
86 | return Energie;
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | void PairingJet(TLorentzVector &JETSm, const TLorentzVector &JET, const TClonesArray *branchJet)
|
---|
91 | {
|
---|
92 | JETSm.SetPxPyPzE(0,0,0,0);
|
---|
93 | float deltaRtest=5000;
|
---|
94 | TIter itJet((TCollection*)branchJet);
|
---|
95 | TRootJet *jet;
|
---|
96 | itJet.Reset();
|
---|
97 | while( (jet = (TRootJet*) itJet.Next()) )
|
---|
98 | {
|
---|
99 | TLorentzVector Att;
|
---|
100 | Att.SetPtEtaPhiE(jet->PT,jet->Eta,jet->Phi,jet->E);
|
---|
101 | if(DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
|
---|
102 | {
|
---|
103 | deltaRtest = DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta());
|
---|
104 | if(deltaRtest < 0.25)
|
---|
105 | {
|
---|
106 | JETSm = Att;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | void PairingElec(TLorentzVector &ELECSm, const TLorentzVector &ELEC, const TClonesArray *branchElec)
|
---|
113 | {
|
---|
114 | ELECSm.SetPxPyPzE(0,0,0,0);
|
---|
115 | float deltaRtest=5000;
|
---|
116 | TIter itElec((TCollection*)branchElec);
|
---|
117 | TRootElectron *elec;
|
---|
118 | itElec.Reset();
|
---|
119 | while( (elec = (TRootElectron*) itElec.Next()) )
|
---|
120 | {
|
---|
121 | TLorentzVector Att;
|
---|
122 | Att.SetPtEtaPhiE(elec->PT,elec->Eta,elec->Phi,elec->E);
|
---|
123 | if(DeltaR(ELEC.Phi(),ELEC.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
|
---|
124 | {
|
---|
125 | deltaRtest = DeltaR(ELEC.Phi(),ELEC.Eta(),Att.Phi(),Att.Eta());
|
---|
126 | if(deltaRtest < 0.025)
|
---|
127 | {
|
---|
128 | ELECSm = Att;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | void PairingMuon(TLorentzVector &MUONSm, const TLorentzVector &MUON, const TClonesArray *branchMuon)
|
---|
135 | {
|
---|
136 | MUONSm.SetPxPyPzE(0,0,0,0);
|
---|
137 | float deltaRtest=5000;
|
---|
138 | TIter itMuon((TCollection*)branchMuon);
|
---|
139 | TRootMuon *muon;
|
---|
140 | itMuon.Reset();
|
---|
141 | while( (muon = (TRootMuon*) itMuon.Next()) )
|
---|
142 | {
|
---|
143 | TLorentzVector Att;
|
---|
144 | Att.SetPxPyPzE(muon->Px,muon->Py,muon->Pz,muon->E);
|
---|
145 | if(DeltaR(MUON.Phi(),MUON.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
|
---|
146 | {
|
---|
147 | deltaRtest = DeltaR(MUON.Phi(),MUON.Eta(),Att.Phi(),Att.Eta());
|
---|
148 | if(deltaRtest < 0.025)
|
---|
149 | {
|
---|
150 | MUONSm = Att;
|
---|
151 | }
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | unsigned int NumTracks(const TClonesArray *branchTracks, const float pt_track, const float eta, const float phi,float track_scone) {
|
---|
157 | unsigned int numtrack=0;
|
---|
158 | TIter itTrack((TCollection*)branchTracks);
|
---|
159 | TRootTracks *track;
|
---|
160 | itTrack.Reset();
|
---|
161 | while( (track = (TRootTracks*) itTrack.Next()) )
|
---|
162 | {
|
---|
163 | if((track->PT < pt_track )||
|
---|
164 | (DeltaR(phi,eta,track->Phi,track->Eta) > track_scone)
|
---|
165 | )continue;
|
---|
166 | numtrack++;
|
---|
167 | }
|
---|
168 | return numtrack;
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 |
|
---|
173 | int main(int argc, char *argv[])
|
---|
174 | {
|
---|
175 | int appargc = 2;
|
---|
176 | char *appName = "Resolution";
|
---|
177 | char *appargv[] = {appName, "-b"};
|
---|
178 | TApplication app(appName, &appargc, appargv);
|
---|
179 |
|
---|
180 | if(argc != 3) {
|
---|
181 | cout << " Usage: " << argv[0] << " input_file" << " output_file" << endl;
|
---|
182 | cout << " input_list - list of files in root format," << endl;
|
---|
183 | cout << " output_file - output file." << endl;
|
---|
184 | exit(1);
|
---|
185 | }
|
---|
186 |
|
---|
187 | srand (time (NULL)); /* Initialisation du générateur */
|
---|
188 |
|
---|
189 | //read the input TROOT file
|
---|
190 | string inputfilename(argv[1]), outputfilename(argv[2]);
|
---|
191 |
|
---|
192 | if(outputfilename.find(".root") > outputfilename.length() ) {
|
---|
193 | cout << "output_file should be a .root file!\n";
|
---|
194 | return -1;
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 |
|
---|
199 | TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
|
---|
200 | outputFile->Close();
|
---|
201 |
|
---|
202 | TChain chainGEN("GEN");
|
---|
203 | chainGEN.Add(inputfilename.c_str());
|
---|
204 | ExRootTreeReader *treeReaderGEN = new ExRootTreeReader(&chainGEN);
|
---|
205 | TChain chain("Analysis");
|
---|
206 | chain.Add(inputfilename.c_str());
|
---|
207 | ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
|
---|
208 | const TClonesArray *branchJet = treeReader->UseBranch("Jet");
|
---|
209 | const TClonesArray *branchElec = treeReader->UseBranch("Electron");
|
---|
210 | const TClonesArray *branchMuon = treeReader->UseBranch("Muon");
|
---|
211 | const TClonesArray *branchTracks = treeReader->UseBranch("Tracks");
|
---|
212 | const TClonesArray *branchTowers = treeReader->UseBranch("CaloTower");
|
---|
213 | const TClonesArray *branchGen = treeReaderGEN->UseBranch("Particle");
|
---|
214 | TIter itGen((TCollection*)branchGen);
|
---|
215 |
|
---|
216 | //write the output root file
|
---|
217 | ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
|
---|
218 | ExRootTreeBranch *branchjet = treeWriter->NewBranch("JetPTResol", RESOLJET::Class());
|
---|
219 | ExRootTreeBranch *branchelec = treeWriter->NewBranch("ElecEResol", RESOLELEC::Class());
|
---|
220 | ExRootTreeBranch *branchmuon = treeWriter->NewBranch("MuonPTResol", RESOLMUON::Class());
|
---|
221 | ExRootTreeBranch *branchtaujet = treeWriter->NewBranch("TauJetPTResol", TAUHAD::Class());
|
---|
222 | ExRootTreeBranch *branchetmis = treeWriter->NewBranch("ETmisResol",ETMIS::Class());
|
---|
223 |
|
---|
224 | TRootGenParticle *particle;
|
---|
225 |
|
---|
226 | RESOLELEC * elementElec;
|
---|
227 | RESOLMUON *elementMuon;
|
---|
228 | RESOLJET *elementJet;
|
---|
229 | TAUHAD *elementTaujet;
|
---|
230 | ETMIS *elementEtmis;
|
---|
231 |
|
---|
232 | int numTau=0;
|
---|
233 | int numTauRec=0;
|
---|
234 |
|
---|
235 | RESOLution *DET = new RESOLution();
|
---|
236 | DET->ReadDataCard("data/Datacard_CMS.dat");
|
---|
237 |
|
---|
238 |
|
---|
239 | //Jet information
|
---|
240 | JetsUtil *JETRUN = new JetsUtil("data/Datacard_CMS.dat");
|
---|
241 |
|
---|
242 | TLorentzVector genMomentum(0,0,0,0);//TLorentzVector containing generator level information
|
---|
243 | TLorentzVector recoMomentum(0,0,0,0);//TLorentzVector containing generator level information
|
---|
244 | LorentzVector jetMomentum;
|
---|
245 |
|
---|
246 | vector<fastjet::PseudoJet> input_particlesGEN;//for FastJet algorithm
|
---|
247 | vector<fastjet::PseudoJet> sorted_jetsGEN;
|
---|
248 |
|
---|
249 | vector<TLorentzVector> towers;
|
---|
250 |
|
---|
251 | // Loop over all events
|
---|
252 | Long64_t entry, allEntries = treeReader->GetEntries();
|
---|
253 | cout << "** Chain contains " << allEntries << " events" << endl;
|
---|
254 | for(entry = 0; entry < allEntries; ++entry)
|
---|
255 | {
|
---|
256 | TLorentzVector PTmisReco(0,0,0,0);
|
---|
257 | TLorentzVector PTmisGEN(0,0,0,0);
|
---|
258 | treeReader->ReadEntry(entry);
|
---|
259 | treeReaderGEN->ReadEntry(entry);
|
---|
260 | treeWriter->Clear();
|
---|
261 | if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl;
|
---|
262 |
|
---|
263 | TSimpleArray<TRootGenParticle> bGen;
|
---|
264 | itGen.Reset();
|
---|
265 | TSimpleArray<TRootGenParticle> NFCentralQ;
|
---|
266 |
|
---|
267 | input_particlesGEN.clear();
|
---|
268 | towers.clear();
|
---|
269 |
|
---|
270 | // Loop over all particles in event
|
---|
271 | while( (particle = (TRootGenParticle*) itGen.Next()) )
|
---|
272 | {
|
---|
273 | genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
|
---|
274 |
|
---|
275 | int pid = abs(particle->PID);
|
---|
276 | float eta = fabs(particle->Eta);
|
---|
277 |
|
---|
278 | //input generator level particle for jet algorithm
|
---|
279 | if(particle->Status == 1 && eta < DET->CEN_max_calo_fwd)
|
---|
280 | {
|
---|
281 | input_particlesGEN.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
|
---|
282 | }
|
---|
283 |
|
---|
284 | //Calculate ETMIS from generated particles
|
---|
285 | if((pid == pNU1) || (pid == pNU2) || (pid == pNU3))PTmisGEN = PTmisGEN + genMomentum;
|
---|
286 |
|
---|
287 | if( (particle->Status == 1) &&
|
---|
288 | ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
|
---|
289 | (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
|
---|
290 | )
|
---|
291 | {
|
---|
292 | eta=fabs(genMomentum.Eta());
|
---|
293 |
|
---|
294 | switch(pid) {
|
---|
295 |
|
---|
296 | case pE: // all electrons with eta < DET->MAX_CALO_FWD
|
---|
297 | PairingElec(recoMomentum,genMomentum,branchElec);
|
---|
298 | if(recoMomentum.E()!=0){
|
---|
299 | elementElec=(RESOLELEC*) branchelec->NewEntry();
|
---|
300 | elementElec->E = genMomentum.E();
|
---|
301 | elementElec->SmearedE = recoMomentum.E();}
|
---|
302 | break; // case pE
|
---|
303 | case pMU: // all muons with eta < DET->MAX_MU
|
---|
304 | PairingMuon(recoMomentum,genMomentum,branchMuon);
|
---|
305 | if(recoMomentum.E() !=0){
|
---|
306 | elementMuon = (RESOLMUON*) branchmuon->NewEntry();
|
---|
307 | elementMuon->OverPT = (1/genMomentum.Pt());
|
---|
308 | elementMuon->OverSmearedPT = (1/recoMomentum.Pt());}
|
---|
309 | break; // case pMU
|
---|
310 | default:
|
---|
311 | break;
|
---|
312 | } // switch (pid)
|
---|
313 | }
|
---|
314 |
|
---|
315 | } // while
|
---|
316 |
|
---|
317 | //compute missing transverse energy from calo towers
|
---|
318 | TIter itCalo((TCollection*)branchTowers);
|
---|
319 | TRootCalo *calo;
|
---|
320 | itCalo.Reset();
|
---|
321 | TLorentzVector Att(0.,0.,0.,0.);
|
---|
322 | float ScalarEt=0;
|
---|
323 | while( (calo = (TRootCalo*) itCalo.Next()) )
|
---|
324 | {
|
---|
325 | if(calo->E !=0){
|
---|
326 | Att.SetPtEtaPhiE(calo->getET(),calo->Eta,calo->Phi,calo->E);
|
---|
327 | towers.push_back(Att);
|
---|
328 | if(fabs(Att.Eta()) < DET->CEN_max_calo_fwd)
|
---|
329 | {
|
---|
330 | ScalarEt = ScalarEt + calo->getET();
|
---|
331 | PTmisReco = PTmisReco + Att;
|
---|
332 | }
|
---|
333 | }
|
---|
334 | }
|
---|
335 | elementEtmis= (ETMIS*) branchetmis->NewEntry();
|
---|
336 | elementEtmis->Et = (PTmisGEN).Pt();
|
---|
337 | elementEtmis->Ex = (-PTmisGEN).Px();
|
---|
338 | elementEtmis->SEt = ScalarEt;
|
---|
339 |
|
---|
340 | elementEtmis->EtSmeare = (PTmisReco).Pt()-(PTmisGEN).Pt();
|
---|
341 | elementEtmis->ExSmeare = (-PTmisReco).Px()-(PTmisGEN).Px();
|
---|
342 |
|
---|
343 | //*****************************
|
---|
344 |
|
---|
345 | sorted_jetsGEN=JETRUN->RunJets(input_particlesGEN);
|
---|
346 |
|
---|
347 | TSimpleArray<TRootGenParticle> TausHadr = TauHadr(branchGen);
|
---|
348 |
|
---|
349 | TLorentzVector JETreco(0,0,0,0);
|
---|
350 | for (unsigned int i = 0; i < sorted_jetsGEN.size(); i++) {
|
---|
351 | TLorentzVector JETgen(0,0,0,0);
|
---|
352 | JETgen.SetPxPyPzE(sorted_jetsGEN[i].px(),sorted_jetsGEN[i].py(),sorted_jetsGEN[i].pz(),sorted_jetsGEN[i].E());
|
---|
353 | PairingJet(JETreco,JETgen,branchJet);
|
---|
354 | if(JETreco.Pt()>1)
|
---|
355 | {
|
---|
356 | elementJet= (RESOLJET*) branchjet->NewEntry();
|
---|
357 | elementJet->PT = JETgen.Et();
|
---|
358 | elementJet->SmearedPT = JETreco.Et()/JETgen.Et();
|
---|
359 | }
|
---|
360 | }
|
---|
361 | numTau = numTau+TausHadr.GetEntries();
|
---|
362 |
|
---|
363 | TIter itJet((TCollection*)branchJet);
|
---|
364 | TRootJet *jet;
|
---|
365 | itJet.Reset();
|
---|
366 | while( (jet = (TRootJet*) itJet.Next()) )
|
---|
367 | {
|
---|
368 | TLorentzVector JETT(0,0,0,0);
|
---|
369 | JETT.SetPxPyPzE(jet->Px,jet->Py,jet->Pz,jet->E);
|
---|
370 | if(fabs(JETT.Eta()) < (DET->CEN_max_tracker - DET->TAU_track_scone))
|
---|
371 | {
|
---|
372 | for(Int_t i=0; i<TausHadr.GetEntries();i++)
|
---|
373 | {
|
---|
374 | if(DeltaR(TausHadr[i]->Phi,TausHadr[i]->Eta,JETT.Phi(),JETT.Eta())<0.1)
|
---|
375 | {
|
---|
376 | elementTaujet= (TAUHAD*) branchtaujet->NewEntry();
|
---|
377 | elementTaujet->EnergieCen = (EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E());
|
---|
378 | elementTaujet->NumTrack = NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone);
|
---|
379 | if( (EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E()) > 0.95
|
---|
380 | && (NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone))==1)numTauRec++;
|
---|
381 | }
|
---|
382 | }
|
---|
383 | }
|
---|
384 |
|
---|
385 |
|
---|
386 | } // for itJet : loop on all jets
|
---|
387 | //cout<<"i"<<endl;
|
---|
388 |
|
---|
389 | treeWriter->Fill();
|
---|
390 | } // Loop over all events
|
---|
391 | treeWriter->Write();
|
---|
392 | float frac = numTauRec/numTau;
|
---|
393 | cout<<numTauRec<<endl;
|
---|
394 | cout<<numTau<<endl;
|
---|
395 |
|
---|
396 | cout << "** Exiting..." << endl;
|
---|
397 | cout<<frac<<endl;
|
---|
398 |
|
---|
399 |
|
---|
400 | delete treeWriter;
|
---|
401 | delete treeReader;
|
---|
402 | delete DET;
|
---|
403 | }
|
---|
404 |
|
---|