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