Fork me on GitHub

source: git/modules/TreeWriter.cc@ fd4b326

Last change on this file since fd4b326 was fd4b326, checked in by michele <michele.selvaggi@…>, 4 years ago

tracks have now montecarlo mass

  • Property mode set to 100644
File size: 28.7 KB
Line 
1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/** \class TreeWriter
20 *
21 * Fills ROOT tree branches.
22 *
23 * \author P. Demin - UCL, Louvain-la-Neuve
24 *
25 */
26
27#include "modules/TreeWriter.h"
28
29#include "classes/DelphesClasses.h"
30#include "classes/DelphesFactory.h"
31#include "classes/DelphesFormula.h"
32
33#include "ExRootAnalysis/ExRootClassifier.h"
34#include "ExRootAnalysis/ExRootFilter.h"
35#include "ExRootAnalysis/ExRootResult.h"
36#include "ExRootAnalysis/ExRootTreeBranch.h"
37
38#include "TDatabasePDG.h"
39#include "TFormula.h"
40#include "TLorentzVector.h"
41#include "TMath.h"
42#include "TObjArray.h"
43#include "TROOT.h"
44#include "TRandom3.h"
45#include "TString.h"
46
47#include <algorithm>
48#include <iostream>
49#include <sstream>
50#include <stdexcept>
51
52using namespace std;
53
54//------------------------------------------------------------------------------
55
56TreeWriter::TreeWriter()
57{
58}
59
60//------------------------------------------------------------------------------
61
62TreeWriter::~TreeWriter()
63{
64}
65
66//------------------------------------------------------------------------------
67
68void TreeWriter::Init()
69{
70 fClassMap[GenParticle::Class()] = &TreeWriter::ProcessParticles;
71 fClassMap[Vertex::Class()] = &TreeWriter::ProcessVertices;
72 fClassMap[Track::Class()] = &TreeWriter::ProcessTracks;
73 fClassMap[Tower::Class()] = &TreeWriter::ProcessTowers;
74 fClassMap[ParticleFlowCandidate::Class()] = &TreeWriter::ProcessParticleFlowCandidates;
75 fClassMap[Photon::Class()] = &TreeWriter::ProcessPhotons;
76 fClassMap[Electron::Class()] = &TreeWriter::ProcessElectrons;
77 fClassMap[Muon::Class()] = &TreeWriter::ProcessMuons;
78 fClassMap[Jet::Class()] = &TreeWriter::ProcessJets;
79 fClassMap[MissingET::Class()] = &TreeWriter::ProcessMissingET;
80 fClassMap[ScalarHT::Class()] = &TreeWriter::ProcessScalarHT;
81 fClassMap[Rho::Class()] = &TreeWriter::ProcessRho;
82 fClassMap[Weight::Class()] = &TreeWriter::ProcessWeight;
83 fClassMap[HectorHit::Class()] = &TreeWriter::ProcessHectorHit;
84
85 TBranchMap::iterator itBranchMap;
86 map<TClass *, TProcessMethod>::iterator itClassMap;
87
88 // read branch configuration and
89 // import array with output from filter/classifier/jetfinder modules
90
91 ExRootConfParam param = GetParam("Branch");
92 Long_t i, size;
93 TString branchName, branchClassName, branchInputArray;
94 TClass *branchClass;
95 TObjArray *array;
96 ExRootTreeBranch *branch;
97
98 size = param.GetSize();
99 for(i = 0; i < size / 3; ++i)
100 {
101 branchInputArray = param[i * 3].GetString();
102 branchName = param[i * 3 + 1].GetString();
103 branchClassName = param[i * 3 + 2].GetString();
104
105 branchClass = gROOT->GetClass(branchClassName);
106
107 if(!branchClass)
108 {
109 cout << "** ERROR: cannot find class '" << branchClassName << "'" << endl;
110 continue;
111 }
112
113 itClassMap = fClassMap.find(branchClass);
114 if(itClassMap == fClassMap.end())
115 {
116 cout << "** ERROR: cannot create branch for class '" << branchClassName << "'" << endl;
117 continue;
118 }
119
120 array = ImportArray(branchInputArray);
121 branch = NewBranch(branchName, branchClass);
122
123 fBranchMap.insert(make_pair(branch, make_pair(itClassMap->second, array)));
124 }
125
126 param = GetParam("Info");
127 TString infoName;
128 Double_t infoValue;
129
130 size = param.GetSize();
131 for(i = 0; i < size / 2; ++i)
132 {
133 infoName = param[i * 2].GetString();
134 infoValue = param[i * 2 + 1].GetDouble();
135
136 AddInfo(infoName, infoValue);
137 }
138}
139
140//------------------------------------------------------------------------------
141
142void TreeWriter::Finish()
143{
144}
145
146//------------------------------------------------------------------------------
147
148void TreeWriter::FillParticles(Candidate *candidate, TRefArray *array)
149{
150 TIter it1(candidate->GetCandidates());
151 it1.Reset();
152 array->Clear();
153
154 while((candidate = static_cast<Candidate *>(it1.Next())))
155 {
156 TIter it2(candidate->GetCandidates());
157
158 // particle
159 if(candidate->GetCandidates()->GetEntriesFast() == 0)
160 {
161 array->Add(candidate);
162 continue;
163 }
164
165 // track
166 candidate = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
167 if(candidate->GetCandidates()->GetEntriesFast() == 0)
168 {
169 array->Add(candidate);
170 continue;
171 }
172
173 // tower
174 it2.Reset();
175 while((candidate = static_cast<Candidate *>(it2.Next())))
176 {
177 array->Add(candidate->GetCandidates()->At(0));
178 }
179 }
180}
181
182//------------------------------------------------------------------------------
183
184void TreeWriter::ProcessParticles(ExRootTreeBranch *branch, TObjArray *array)
185{
186 TIter iterator(array);
187 Candidate *candidate = 0;
188 GenParticle *entry = 0;
189 Double_t pt, signPz, cosTheta, eta, rapidity;
190
191 const Double_t c_light = 2.99792458E8;
192
193 // loop over all particles
194 iterator.Reset();
195 while((candidate = static_cast<Candidate *>(iterator.Next())))
196 {
197 const TLorentzVector &momentum = candidate->Momentum;
198 const TLorentzVector &position = candidate->Position;
199
200 entry = static_cast<GenParticle *>(branch->NewEntry());
201
202 entry->SetBit(kIsReferenced);
203 entry->SetUniqueID(candidate->GetUniqueID());
204
205 pt = momentum.Pt();
206 cosTheta = TMath::Abs(momentum.CosTheta());
207 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
208 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
209 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
210
211 entry->PID = candidate->PID;
212
213 entry->Status = candidate->Status;
214 entry->IsPU = candidate->IsPU;
215
216 entry->M1 = candidate->M1;
217 entry->M2 = candidate->M2;
218
219 entry->D1 = candidate->D1;
220 entry->D2 = candidate->D2;
221
222 entry->Charge = candidate->Charge;
223 entry->Mass = candidate->Mass;
224
225 entry->E = momentum.E();
226 entry->Px = momentum.Px();
227 entry->Py = momentum.Py();
228 entry->Pz = momentum.Pz();
229
230 entry->Eta = eta;
231 entry->Phi = momentum.Phi();
232 entry->PT = pt;
233
234 entry->Rapidity = rapidity;
235
236 entry->X = position.X();
237 entry->Y = position.Y();
238 entry->Z = position.Z();
239 entry->T = position.T() * 1.0E-3 / c_light;
240 }
241}
242
243//------------------------------------------------------------------------------
244
245void TreeWriter::ProcessVertices(ExRootTreeBranch *branch, TObjArray *array)
246{
247 TIter iterator(array);
248 Candidate *candidate = 0, *constituent = 0;
249 Vertex *entry = 0;
250
251 const Double_t c_light = 2.99792458E8;
252
253 Double_t x, y, z, t, xError, yError, zError, tError, sigma, sumPT2, btvSumPT2, genDeltaZ, genSumPT2;
254 UInt_t index, ndf;
255
256 CompBase *compare = Candidate::fgCompare;
257 Candidate::fgCompare = CompSumPT2<Candidate>::Instance();
258 array->Sort();
259 Candidate::fgCompare = compare;
260
261 // loop over all vertices
262 iterator.Reset();
263 while((candidate = static_cast<Candidate *>(iterator.Next())))
264 {
265
266 index = candidate->ClusterIndex;
267 ndf = candidate->ClusterNDF;
268 sigma = candidate->ClusterSigma;
269 sumPT2 = candidate->SumPT2;
270 btvSumPT2 = candidate->BTVSumPT2;
271 genDeltaZ = candidate->GenDeltaZ;
272 genSumPT2 = candidate->GenSumPT2;
273
274 x = candidate->Position.X();
275 y = candidate->Position.Y();
276 z = candidate->Position.Z();
277 t = candidate->Position.T() * 1.0E-3 / c_light;
278
279 xError = candidate->PositionError.X();
280 yError = candidate->PositionError.Y();
281 zError = candidate->PositionError.Z();
282 tError = candidate->PositionError.T() * 1.0E-3 / c_light;
283
284 entry = static_cast<Vertex *>(branch->NewEntry());
285
286 entry->Index = index;
287 entry->NDF = ndf;
288 entry->Sigma = sigma;
289 entry->SumPT2 = sumPT2;
290 entry->BTVSumPT2 = btvSumPT2;
291 entry->GenDeltaZ = genDeltaZ;
292 entry->GenSumPT2 = genSumPT2;
293
294 entry->X = x;
295 entry->Y = y;
296 entry->Z = z;
297 entry->T = t;
298
299 entry->ErrorX = xError;
300 entry->ErrorY = yError;
301 entry->ErrorZ = zError;
302 entry->ErrorT = tError;
303
304 TIter itConstituents(candidate->GetCandidates());
305 itConstituents.Reset();
306 entry->Constituents.Clear();
307 while((constituent = static_cast<Candidate *>(itConstituents.Next())))
308 {
309 entry->Constituents.Add(constituent);
310 }
311 }
312}
313
314//------------------------------------------------------------------------------
315
316void TreeWriter::ProcessTracks(ExRootTreeBranch *branch, TObjArray *array)
317{
318 TIter iterator(array);
319 Candidate *candidate = 0;
320 Candidate *particle = 0;
321 Track *entry = 0;
322 Double_t pt, signz, cosTheta, eta, rapidity, p, ctgTheta, phi, m;
323 const Double_t c_light = 2.99792458E8;
324
325 // loop over all tracks
326 iterator.Reset();
327 while((candidate = static_cast<Candidate *>(iterator.Next())))
328 {
329 const TLorentzVector &position = candidate->Position;
330
331 cosTheta = TMath::Abs(position.CosTheta());
332 signz = (position.Pz() >= 0.0) ? 1.0 : -1.0;
333 eta = (cosTheta == 1.0 ? signz * 999.9 : position.Eta());
334 rapidity = (cosTheta == 1.0 ? signz * 999.9 : position.Rapidity());
335
336 entry = static_cast<Track *>(branch->NewEntry());
337
338 entry->SetBit(kIsReferenced);
339 entry->SetUniqueID(candidate->GetUniqueID());
340
341 entry->PID = candidate->PID;
342
343 entry->Charge = candidate->Charge;
344
345 entry->EtaOuter = eta;
346 entry->PhiOuter = position.Phi();
347
348 entry->XOuter = position.X();
349 entry->YOuter = position.Y();
350 entry->ZOuter = position.Z();
351 entry->TOuter = position.T() * 1.0E-3 / c_light;
352
353 entry->L = candidate->L;
354
355 entry->D0 = candidate->D0;
356 entry->DZ = candidate->DZ;
357
358 entry->ErrorP = candidate->ErrorP;
359 entry->ErrorPT = candidate->ErrorPT;
360
361 // diagonal covariance matrix terms
362 entry->ErrorD0 = candidate->ErrorD0;
363 entry->ErrorC = candidate->ErrorC;
364 entry->ErrorPhi = candidate->ErrorPhi;
365 entry->ErrorDZ = candidate->ErrorDZ;
366 entry->ErrorCtgTheta = candidate->ErrorCtgTheta;
367
368 // add some offdiagonal covariance matrix elements
369 entry->ErrorD0Phi = candidate->TrackCovariance(0,1);
370 entry->ErrorD0C = candidate->TrackCovariance(0,2);
371 entry->ErrorD0DZ = candidate->TrackCovariance(0,3);
372 entry->ErrorD0CtgTheta = candidate->TrackCovariance(0,4);
373 entry->ErrorPhiC = candidate->TrackCovariance(1,2);
374 entry->ErrorPhiDZ = candidate->TrackCovariance(1,3);
375 entry->ErrorPhiCtgTheta = candidate->TrackCovariance(1,4);
376 entry->ErrorCDZ = candidate->TrackCovariance(2,3);
377 entry->ErrorCCtgTheta = candidate->TrackCovariance(2,4);
378 entry->ErrorDZCtgTheta = candidate->TrackCovariance(3,4);
379
380 entry->Xd = candidate->Xd;
381 entry->Yd = candidate->Yd;
382 entry->Zd = candidate->Zd;
383
384 const TLorentzVector &momentum = candidate->Momentum;
385
386 pt = momentum.Pt();
387 p = momentum.P();
388 phi = momentum.Phi();
389 m = momentum.M();
390 ctgTheta = (TMath::Tan(momentum.Theta()) != 0) ? 1 / TMath::Tan(momentum.Theta()) : 1e10;
391
392 cosTheta = TMath::Abs(momentum.CosTheta());
393 signz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
394 eta = (cosTheta == 1.0 ? signz * 999.9 : momentum.Eta());
395 rapidity = (cosTheta == 1.0 ? signz * 999.9 : momentum.Rapidity());
396
397 entry->P = p;
398 entry->PT = pt;
399 entry->Eta = eta;
400 entry->Phi = phi;
401 entry->CtgTheta = ctgTheta;
402 entry->C = candidate->C;
403 entry->Mass = m;
404
405 particle = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
406 const TLorentzVector &initialPosition = particle->Position;
407
408 entry->X = initialPosition.X();
409 entry->Y = initialPosition.Y();
410 entry->Z = initialPosition.Z();
411 entry->T = initialPosition.T() * 1.0E-3 / c_light;
412
413 entry->Particle = particle;
414
415 entry->VertexIndex = candidate->ClusterIndex;
416 }
417}
418
419//------------------------------------------------------------------------------
420
421void TreeWriter::ProcessTowers(ExRootTreeBranch *branch, TObjArray *array)
422{
423 TIter iterator(array);
424 Candidate *candidate = 0;
425 Tower *entry = 0;
426 Double_t pt, signPz, cosTheta, eta, rapidity;
427 const Double_t c_light = 2.99792458E8;
428
429 // loop over all towers
430 iterator.Reset();
431 while((candidate = static_cast<Candidate *>(iterator.Next())))
432 {
433 const TLorentzVector &momentum = candidate->Momentum;
434 const TLorentzVector &position = candidate->Position;
435
436 pt = momentum.Pt();
437 cosTheta = TMath::Abs(momentum.CosTheta());
438 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
439 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
440 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
441
442 entry = static_cast<Tower *>(branch->NewEntry());
443
444 entry->SetBit(kIsReferenced);
445 entry->SetUniqueID(candidate->GetUniqueID());
446
447 entry->Eta = eta;
448 entry->Phi = momentum.Phi();
449 entry->ET = pt;
450 entry->E = momentum.E();
451 entry->Eem = candidate->Eem;
452 entry->Ehad = candidate->Ehad;
453 entry->Edges[0] = candidate->Edges[0];
454 entry->Edges[1] = candidate->Edges[1];
455 entry->Edges[2] = candidate->Edges[2];
456 entry->Edges[3] = candidate->Edges[3];
457
458 entry->T = position.T() * 1.0E-3 / c_light;
459 entry->NTimeHits = candidate->NTimeHits;
460
461 FillParticles(candidate, &entry->Particles);
462 }
463}
464
465//------------------------------------------------------------------------------
466
467void TreeWriter::ProcessParticleFlowCandidates(ExRootTreeBranch *branch, TObjArray *array)
468{
469
470 TIter iterator(array);
471 Candidate *candidate = 0;
472 Candidate *particle = 0;
473 ParticleFlowCandidate *entry = 0;
474 Double_t e, pt, signz, cosTheta, eta, rapidity, p, ctgTheta, phi, m;
475 const Double_t c_light = 2.99792458E8;
476
477 // loop over all tracks
478 iterator.Reset();
479 while((candidate = static_cast<Candidate *>(iterator.Next())))
480 {
481 const TLorentzVector &position = candidate->Position;
482
483 cosTheta = TMath::Abs(position.CosTheta());
484 signz = (position.Pz() >= 0.0) ? 1.0 : -1.0;
485 eta = (cosTheta == 1.0 ? signz * 999.9 : position.Eta());
486 rapidity = (cosTheta == 1.0 ? signz * 999.9 : position.Rapidity());
487
488 entry = static_cast<ParticleFlowCandidate *>(branch->NewEntry());
489
490 entry->SetBit(kIsReferenced);
491 entry->SetUniqueID(candidate->GetUniqueID());
492
493 entry->PID = candidate->PID;
494
495 entry->Charge = candidate->Charge;
496
497 entry->EtaOuter = eta;
498 entry->PhiOuter = position.Phi();
499
500 entry->XOuter = position.X();
501 entry->YOuter = position.Y();
502 entry->ZOuter = position.Z();
503 entry->TOuter = position.T() * 1.0E-3 / c_light;
504
505 entry->L = candidate->L;
506
507 entry->D0 = candidate->D0;
508 entry->DZ = candidate->DZ;
509
510 entry->ErrorP = candidate->ErrorP;
511 entry->ErrorPT = candidate->ErrorPT;
512 entry->ErrorCtgTheta = candidate->ErrorCtgTheta;
513
514
515 // diagonal covariance matrix terms
516
517 entry->ErrorD0 = candidate->ErrorD0;
518 entry->ErrorC = candidate->ErrorC;
519 entry->ErrorPhi = candidate->ErrorPhi;
520 entry->ErrorDZ = candidate->ErrorDZ;
521 entry->ErrorCtgTheta = candidate->ErrorCtgTheta;
522
523 // add some offdiagonal covariance matrix elements
524 entry->ErrorD0Phi = candidate->TrackCovariance(0,1);
525 entry->ErrorD0C = candidate->TrackCovariance(0,2);
526 entry->ErrorD0DZ = candidate->TrackCovariance(0,3);
527 entry->ErrorD0CtgTheta = candidate->TrackCovariance(0,4);
528 entry->ErrorPhiC = candidate->TrackCovariance(1,2);
529 entry->ErrorPhiDZ = candidate->TrackCovariance(1,3);
530 entry->ErrorPhiCtgTheta = candidate->TrackCovariance(1,4);
531 entry->ErrorCDZ = candidate->TrackCovariance(2,3);
532 entry->ErrorCCtgTheta = candidate->TrackCovariance(2,4);
533 entry->ErrorDZCtgTheta = candidate->TrackCovariance(3,4);
534
535 entry->Xd = candidate->Xd;
536 entry->Yd = candidate->Yd;
537 entry->Zd = candidate->Zd;
538
539 const TLorentzVector &momentum = candidate->Momentum;
540
541 e = momentum.E();
542 pt = momentum.Pt();
543 p = momentum.P();
544 phi = momentum.Phi();
545 m = momentum.M();
546 ctgTheta = (TMath::Tan(momentum.Theta()) != 0) ? 1 / TMath::Tan(momentum.Theta()) : 1e10;
547
548 entry->E = e;
549 entry->P = p;
550 entry->PT = pt;
551 entry->Eta = eta;
552 entry->Phi = phi;
553 entry->CtgTheta = ctgTheta;
554 entry->C = candidate->C;
555 entry->Mass = m;
556
557 particle = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
558 const TLorentzVector &initialPosition = particle->Position;
559
560 entry->X = initialPosition.X();
561 entry->Y = initialPosition.Y();
562 entry->Z = initialPosition.Z();
563 entry->T = initialPosition.T() * 1.0E-3 / c_light;
564
565 entry->VertexIndex = candidate->ClusterIndex;
566
567 entry->Eem = candidate->Eem;
568 entry->Ehad = candidate->Ehad;
569 entry->Edges[0] = candidate->Edges[0];
570 entry->Edges[1] = candidate->Edges[1];
571 entry->Edges[2] = candidate->Edges[2];
572 entry->Edges[3] = candidate->Edges[3];
573
574 entry->T = position.T() * 1.0E-3 / c_light;
575 entry->NTimeHits = candidate->NTimeHits;
576
577 FillParticles(candidate, &entry->Particles);
578
579 }
580}
581
582//------------------------------------------------------------------------------
583
584void TreeWriter::ProcessPhotons(ExRootTreeBranch *branch, TObjArray *array)
585{
586 TIter iterator(array);
587 Candidate *candidate = 0;
588 Photon *entry = 0;
589 Double_t pt, signPz, cosTheta, eta, rapidity;
590 const Double_t c_light = 2.99792458E8;
591
592 array->Sort();
593
594 // loop over all photons
595 iterator.Reset();
596 while((candidate = static_cast<Candidate *>(iterator.Next())))
597 {
598 TIter it1(candidate->GetCandidates());
599 const TLorentzVector &momentum = candidate->Momentum;
600 const TLorentzVector &position = candidate->Position;
601
602 pt = momentum.Pt();
603 cosTheta = TMath::Abs(momentum.CosTheta());
604 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
605 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
606 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
607
608 entry = static_cast<Photon *>(branch->NewEntry());
609
610 entry->Eta = eta;
611 entry->Phi = momentum.Phi();
612 entry->PT = pt;
613 entry->E = momentum.E();
614 entry->T = position.T() * 1.0E-3 / c_light;
615
616 // Isolation variables
617
618 entry->IsolationVar = candidate->IsolationVar;
619 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
620 entry->SumPtCharged = candidate->SumPtCharged;
621 entry->SumPtNeutral = candidate->SumPtNeutral;
622 entry->SumPtChargedPU = candidate->SumPtChargedPU;
623 entry->SumPt = candidate->SumPt;
624
625 entry->EhadOverEem = candidate->Eem > 0.0 ? candidate->Ehad / candidate->Eem : 999.9;
626
627 // 1: prompt -- 2: non prompt -- 3: fake
628 entry->Status = candidate->Status;
629
630 FillParticles(candidate, &entry->Particles);
631 }
632}
633
634//------------------------------------------------------------------------------
635
636void TreeWriter::ProcessElectrons(ExRootTreeBranch *branch, TObjArray *array)
637{
638 TIter iterator(array);
639 Candidate *candidate = 0;
640 Electron *entry = 0;
641 Double_t pt, signPz, cosTheta, eta, rapidity;
642 const Double_t c_light = 2.99792458E8;
643
644 array->Sort();
645
646 // loop over all electrons
647 iterator.Reset();
648 while((candidate = static_cast<Candidate *>(iterator.Next())))
649 {
650 const TLorentzVector &momentum = candidate->Momentum;
651 const TLorentzVector &position = candidate->Position;
652
653 pt = momentum.Pt();
654 cosTheta = TMath::Abs(momentum.CosTheta());
655 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
656 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
657 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
658
659 entry = static_cast<Electron *>(branch->NewEntry());
660
661 entry->Eta = eta;
662 entry->Phi = momentum.Phi();
663 entry->PT = pt;
664
665 entry->T = position.T() * 1.0E-3 / c_light;
666
667 // displacement
668 entry->D0 = candidate->D0;
669 entry->ErrorD0 = candidate->ErrorD0;
670 entry->DZ = candidate->DZ;
671 entry->ErrorDZ = candidate->ErrorDZ;
672
673 // Isolation variables
674 entry->IsolationVar = candidate->IsolationVar;
675 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
676 entry->SumPtCharged = candidate->SumPtCharged;
677 entry->SumPtNeutral = candidate->SumPtNeutral;
678 entry->SumPtChargedPU = candidate->SumPtChargedPU;
679 entry->SumPt = candidate->SumPt;
680
681 entry->Charge = candidate->Charge;
682
683 entry->EhadOverEem = 0.0;
684
685 entry->Particle = candidate->GetCandidates()->At(0);
686 }
687}
688
689//------------------------------------------------------------------------------
690
691void TreeWriter::ProcessMuons(ExRootTreeBranch *branch, TObjArray *array)
692{
693 TIter iterator(array);
694 Candidate *candidate = 0;
695 Muon *entry = 0;
696 Double_t pt, signPz, cosTheta, eta, rapidity;
697
698 const Double_t c_light = 2.99792458E8;
699
700 array->Sort();
701
702 // loop over all muons
703 iterator.Reset();
704 while((candidate = static_cast<Candidate *>(iterator.Next())))
705 {
706 const TLorentzVector &momentum = candidate->Momentum;
707 const TLorentzVector &position = candidate->Position;
708
709 pt = momentum.Pt();
710 cosTheta = TMath::Abs(momentum.CosTheta());
711 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
712 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
713 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
714
715 entry = static_cast<Muon *>(branch->NewEntry());
716
717 entry->SetBit(kIsReferenced);
718 entry->SetUniqueID(candidate->GetUniqueID());
719
720 entry->Eta = eta;
721 entry->Phi = momentum.Phi();
722 entry->PT = pt;
723
724 entry->T = position.T() * 1.0E-3 / c_light;
725
726 // displacement
727 entry->D0 = candidate->D0;
728 entry->ErrorD0 = candidate->ErrorD0;
729 entry->DZ = candidate->DZ;
730 entry->ErrorDZ = candidate->ErrorDZ;
731
732 // Isolation variables
733
734 entry->IsolationVar = candidate->IsolationVar;
735 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
736 entry->SumPtCharged = candidate->SumPtCharged;
737 entry->SumPtNeutral = candidate->SumPtNeutral;
738 entry->SumPtChargedPU = candidate->SumPtChargedPU;
739 entry->SumPt = candidate->SumPt;
740
741 entry->Charge = candidate->Charge;
742
743 entry->Particle = candidate->GetCandidates()->At(0);
744 }
745}
746
747//------------------------------------------------------------------------------
748
749void TreeWriter::ProcessJets(ExRootTreeBranch *branch, TObjArray *array)
750{
751 TIter iterator(array);
752 Candidate *candidate = 0, *constituent = 0;
753 Jet *entry = 0;
754 Double_t pt, signPz, cosTheta, eta, rapidity;
755 Double_t ecalEnergy, hcalEnergy;
756 const Double_t c_light = 2.99792458E8;
757 Int_t i;
758
759 array->Sort();
760
761 // loop over all jets
762 iterator.Reset();
763 while((candidate = static_cast<Candidate *>(iterator.Next())))
764 {
765 TIter itConstituents(candidate->GetCandidates());
766
767 const TLorentzVector &momentum = candidate->Momentum;
768 const TLorentzVector &position = candidate->Position;
769
770 pt = momentum.Pt();
771 cosTheta = TMath::Abs(momentum.CosTheta());
772 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
773 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
774 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
775
776 entry = static_cast<Jet *>(branch->NewEntry());
777
778 entry->Eta = eta;
779 entry->Phi = momentum.Phi();
780 entry->PT = pt;
781
782 entry->T = position.T() * 1.0E-3 / c_light;
783
784 entry->Mass = momentum.M();
785
786 entry->Area = candidate->Area;
787
788 entry->DeltaEta = candidate->DeltaEta;
789 entry->DeltaPhi = candidate->DeltaPhi;
790
791 entry->Flavor = candidate->Flavor;
792 entry->FlavorAlgo = candidate->FlavorAlgo;
793 entry->FlavorPhys = candidate->FlavorPhys;
794
795 entry->BTag = candidate->BTag;
796
797 entry->BTagAlgo = candidate->BTagAlgo;
798 entry->BTagPhys = candidate->BTagPhys;
799
800 entry->TauTag = candidate->TauTag;
801 entry->TauWeight = candidate->TauWeight;
802
803 entry->Charge = candidate->Charge;
804
805 itConstituents.Reset();
806 entry->Constituents.Clear();
807 ecalEnergy = 0.0;
808 hcalEnergy = 0.0;
809 while((constituent = static_cast<Candidate *>(itConstituents.Next())))
810 {
811 entry->Constituents.Add(constituent);
812 ecalEnergy += constituent->Eem;
813 hcalEnergy += constituent->Ehad;
814 }
815
816 entry->EhadOverEem = ecalEnergy > 0.0 ? hcalEnergy / ecalEnergy : 999.9;
817
818 //--- Pile-Up Jet ID variables ----
819
820 entry->NCharged = candidate->NCharged;
821 entry->NNeutrals = candidate->NNeutrals;
822
823 entry->NeutralEnergyFraction = candidate->NeutralEnergyFraction;
824 entry->ChargedEnergyFraction = candidate->ChargedEnergyFraction;
825 entry->Beta = candidate->Beta;
826 entry->BetaStar = candidate->BetaStar;
827 entry->MeanSqDeltaR = candidate->MeanSqDeltaR;
828 entry->PTD = candidate->PTD;
829
830 //--- Sub-structure variables ----
831
832 entry->NSubJetsTrimmed = candidate->NSubJetsTrimmed;
833 entry->NSubJetsPruned = candidate->NSubJetsPruned;
834 entry->NSubJetsSoftDropped = candidate->NSubJetsSoftDropped;
835
836 entry->SoftDroppedJet = candidate->SoftDroppedJet;
837 entry->SoftDroppedSubJet1 = candidate->SoftDroppedSubJet1;
838 entry->SoftDroppedSubJet2 = candidate->SoftDroppedSubJet2;
839
840 for(i = 0; i < 5; i++)
841 {
842 entry->FracPt[i] = candidate->FracPt[i];
843 entry->Tau[i] = candidate->Tau[i];
844 entry->TrimmedP4[i] = candidate->TrimmedP4[i];
845 entry->PrunedP4[i] = candidate->PrunedP4[i];
846 entry->SoftDroppedP4[i] = candidate->SoftDroppedP4[i];
847 }
848
849 //--- exclusive clustering variables ---
850 entry->ExclYmerge23 = candidate->ExclYmerge23;
851 entry->ExclYmerge34 = candidate->ExclYmerge34;
852 entry->ExclYmerge45 = candidate->ExclYmerge45;
853 entry->ExclYmerge56 = candidate->ExclYmerge56;
854
855 FillParticles(candidate, &entry->Particles);
856 }
857}
858
859//------------------------------------------------------------------------------
860
861void TreeWriter::ProcessMissingET(ExRootTreeBranch *branch, TObjArray *array)
862{
863 Candidate *candidate = 0;
864 MissingET *entry = 0;
865
866 // get the first entry
867 if((candidate = static_cast<Candidate *>(array->At(0))))
868 {
869 const TLorentzVector &momentum = candidate->Momentum;
870
871 entry = static_cast<MissingET *>(branch->NewEntry());
872
873 entry->Eta = (-momentum).Eta();
874 entry->Phi = (-momentum).Phi();
875 entry->MET = momentum.Pt();
876 }
877}
878
879//------------------------------------------------------------------------------
880
881void TreeWriter::ProcessScalarHT(ExRootTreeBranch *branch, TObjArray *array)
882{
883 Candidate *candidate = 0;
884 ScalarHT *entry = 0;
885
886 // get the first entry
887 if((candidate = static_cast<Candidate *>(array->At(0))))
888 {
889 const TLorentzVector &momentum = candidate->Momentum;
890
891 entry = static_cast<ScalarHT *>(branch->NewEntry());
892
893 entry->HT = momentum.Pt();
894 }
895}
896
897//------------------------------------------------------------------------------
898
899void TreeWriter::ProcessRho(ExRootTreeBranch *branch, TObjArray *array)
900{
901 TIter iterator(array);
902 Candidate *candidate = 0;
903 Rho *entry = 0;
904
905 // loop over all rho
906 iterator.Reset();
907 while((candidate = static_cast<Candidate *>(iterator.Next())))
908 {
909 const TLorentzVector &momentum = candidate->Momentum;
910
911 entry = static_cast<Rho *>(branch->NewEntry());
912
913 entry->Rho = momentum.E();
914 entry->Edges[0] = candidate->Edges[0];
915 entry->Edges[1] = candidate->Edges[1];
916 }
917}
918
919//------------------------------------------------------------------------------
920
921void TreeWriter::ProcessWeight(ExRootTreeBranch *branch, TObjArray *array)
922{
923 Candidate *candidate = 0;
924 Weight *entry = 0;
925
926 // get the first entry
927 if((candidate = static_cast<Candidate *>(array->At(0))))
928 {
929 const TLorentzVector &momentum = candidate->Momentum;
930
931 entry = static_cast<Weight *>(branch->NewEntry());
932
933 entry->Weight = momentum.E();
934 }
935}
936
937//------------------------------------------------------------------------------
938
939void TreeWriter::ProcessHectorHit(ExRootTreeBranch *branch, TObjArray *array)
940{
941 TIter iterator(array);
942 Candidate *candidate = 0;
943 HectorHit *entry = 0;
944
945 // loop over all roman pot hits
946 iterator.Reset();
947 while((candidate = static_cast<Candidate *>(iterator.Next())))
948 {
949 const TLorentzVector &position = candidate->Position;
950 const TLorentzVector &momentum = candidate->Momentum;
951
952 entry = static_cast<HectorHit *>(branch->NewEntry());
953
954 entry->E = momentum.E();
955
956 entry->Tx = momentum.Px();
957 entry->Ty = momentum.Py();
958
959 entry->T = position.T();
960
961 entry->X = position.X();
962 entry->Y = position.Y();
963 entry->S = position.Z();
964
965 entry->Particle = candidate->GetCandidates()->At(0);
966 }
967}
968
969//------------------------------------------------------------------------------
970
971void TreeWriter::Process()
972{
973 TBranchMap::iterator itBranchMap;
974 ExRootTreeBranch *branch;
975 TProcessMethod method;
976 TObjArray *array;
977
978 for(itBranchMap = fBranchMap.begin(); itBranchMap != fBranchMap.end(); ++itBranchMap)
979 {
980 branch = itBranchMap->first;
981 method = itBranchMap->second.first;
982 array = itBranchMap->second.second;
983
984 (this->*method)(branch, array);
985 }
986}
987
988//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.