Fork me on GitHub

source: git/modules/TreeWriter.cc@ d612dec

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

Merge branch 'master' of github.com:Christinaw97/delphes into HEAD

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