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