Fork me on GitHub

source: git/modules/TreeWriter.cc@ 2a1d95e

Last change on this file since 2a1d95e was 3c59f98, checked in by christinaw97 <christina.wang@…>, 3 years ago

add example/ExampleCscCluster.py and remove decayPosition from GenParticle class

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