Fork me on GitHub

source: git/modules/TreeWriter.cc@ a5af1df

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

added CscCluster modules and classes

  • Property mode set to 100644
File size: 26.4 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[Photon::Class()] = &TreeWriter::ProcessPhotons;
75 fClassMap[Electron::Class()] = &TreeWriter::ProcessElectrons;
76 fClassMap[Muon::Class()] = &TreeWriter::ProcessMuons;
77 fClassMap[CscCluster::Class()] = &TreeWriter::ProcessCscCluster;
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
127//------------------------------------------------------------------------------
128
129void TreeWriter::Finish()
130{
131}
132
133//------------------------------------------------------------------------------
134
135void TreeWriter::FillParticles(Candidate *candidate, TRefArray *array)
136{
137 TIter it1(candidate->GetCandidates());
138 it1.Reset();
139 array->Clear();
140 while((candidate = static_cast<Candidate *>(it1.Next())))
141 {
142 TIter it2(candidate->GetCandidates());
143
144 // particle
145 if(candidate->GetCandidates()->GetEntriesFast() == 0)
146 {
147 array->Add(candidate);
148 continue;
149 }
150
151 // track
152 candidate = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
153 if(candidate->GetCandidates()->GetEntriesFast() == 0)
154 {
155 array->Add(candidate);
156 continue;
157 }
158
159 // tower
160 it2.Reset();
161 while((candidate = static_cast<Candidate *>(it2.Next())))
162 {
163 array->Add(candidate->GetCandidates()->At(0));
164 }
165 }
166}
167
168//------------------------------------------------------------------------------
169
170void TreeWriter::ProcessParticles(ExRootTreeBranch *branch, TObjArray *array)
171{
172 TIter iterator(array);
173 Candidate *candidate = 0;
174 GenParticle *entry = 0;
175 Double_t pt, signPz, cosTheta, eta, rapidity;
176
177 const Double_t c_light = 2.99792458E8;
178
179 // loop over all particles
180 iterator.Reset();
181 while((candidate = static_cast<Candidate *>(iterator.Next())))
182 {
183 const TLorentzVector &momentum = candidate->Momentum;
184 const TLorentzVector &position = candidate->Position;
185 const TLorentzVector &DecayPosition = candidate->DecayPosition;
186
187 entry = static_cast<GenParticle *>(branch->NewEntry());
188
189 entry->SetBit(kIsReferenced);
190 entry->SetUniqueID(candidate->GetUniqueID());
191
192 pt = momentum.Pt();
193 cosTheta = TMath::Abs(momentum.CosTheta());
194 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
195 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
196 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
197
198 entry->PID = candidate->PID;
199
200 entry->Status = candidate->Status;
201 entry->IsPU = candidate->IsPU;
202
203 entry->M1 = candidate->M1;
204 entry->M2 = candidate->M2;
205
206 entry->D1 = candidate->D1;
207 entry->D2 = candidate->D2;
208
209 entry->Charge = candidate->Charge;
210 entry->Mass = candidate->Mass;
211
212 entry->E = momentum.E();
213 entry->Px = momentum.Px();
214 entry->Py = momentum.Py();
215 entry->Pz = momentum.Pz();
216
217 entry->D0 = candidate->D0;
218 entry->DZ = candidate->DZ;
219 entry->P = momentum.P();
220 entry->PT = candidate->PT;
221 entry->CtgTheta = candidate->CtgTheta;
222 entry->Phi = candidate->Phi;
223
224 entry->Eta = eta;
225 entry->Phi = momentum.Phi();
226 entry->PT = pt;
227
228 entry->Rapidity = rapidity;
229
230 entry->X = position.X();
231 entry->Y = position.Y();
232 entry->Z = position.Z();
233 entry->T = position.T() * 1.0E-3 / c_light;
234
235 entry->decayX = DecayPosition.X();
236 entry->decayY = DecayPosition.Y();
237 entry->decayZ = DecayPosition.Z();
238 entry->decayT = DecayPosition.T()* 1.0E-3 / c_light;
239 float beta = entry->P/momentum.E();
240 float gamma = 1./sqrt(1-beta*beta);
241 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
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;
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->ErrorD0 = candidate->ErrorD0;
359 entry->DZ = candidate->DZ;
360 entry->ErrorDZ = candidate->ErrorDZ;
361
362 entry->ErrorP = candidate->ErrorP;
363 entry->ErrorPT = candidate->ErrorPT;
364 entry->ErrorCtgTheta = candidate->ErrorCtgTheta;
365 entry->ErrorPhi = candidate->ErrorPhi;
366
367 entry->Xd = candidate->Xd;
368 entry->Yd = candidate->Yd;
369 entry->Zd = candidate->Zd;
370
371 const TLorentzVector &momentum = candidate->Momentum;
372
373 pt = momentum.Pt();
374 p = momentum.P();
375 phi = momentum.Phi();
376 ctgTheta = (TMath::Tan(momentum.Theta()) != 0) ? 1 / TMath::Tan(momentum.Theta()) : 1e10;
377
378 cosTheta = TMath::Abs(momentum.CosTheta());
379 signz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
380 eta = (cosTheta == 1.0 ? signz * 999.9 : momentum.Eta());
381 rapidity = (cosTheta == 1.0 ? signz * 999.9 : momentum.Rapidity());
382
383 entry->P = p;
384 entry->PT = pt;
385 entry->Eta = eta;
386 entry->Phi = phi;
387 entry->CtgTheta = ctgTheta;
388
389 particle = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
390 const TLorentzVector &initialPosition = particle->Position;
391
392 entry->X = initialPosition.X();
393 entry->Y = initialPosition.Y();
394 entry->Z = initialPosition.Z();
395 entry->T = initialPosition.T() * 1.0E-3 / c_light;
396
397 entry->Particle = particle;
398
399 entry->VertexIndex = candidate->ClusterIndex;
400 }
401}
402
403//------------------------------------------------------------------------------
404
405void TreeWriter::ProcessTowers(ExRootTreeBranch *branch, TObjArray *array)
406{
407 TIter iterator(array);
408 Candidate *candidate = 0;
409 Tower *entry = 0;
410 Double_t pt, signPz, cosTheta, eta, rapidity;
411 const Double_t c_light = 2.99792458E8;
412
413 // loop over all towers
414 iterator.Reset();
415 while((candidate = static_cast<Candidate *>(iterator.Next())))
416 {
417 const TLorentzVector &momentum = candidate->Momentum;
418 const TLorentzVector &position = candidate->Position;
419
420 pt = momentum.Pt();
421 cosTheta = TMath::Abs(momentum.CosTheta());
422 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
423 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
424 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
425
426 entry = static_cast<Tower *>(branch->NewEntry());
427
428 entry->SetBit(kIsReferenced);
429 entry->SetUniqueID(candidate->GetUniqueID());
430
431 entry->Eta = eta;
432 entry->Phi = momentum.Phi();
433 entry->ET = pt;
434 entry->E = momentum.E();
435 entry->Eem = candidate->Eem;
436 entry->Ehad = candidate->Ehad;
437 entry->Edges[0] = candidate->Edges[0];
438 entry->Edges[1] = candidate->Edges[1];
439 entry->Edges[2] = candidate->Edges[2];
440 entry->Edges[3] = candidate->Edges[3];
441
442 entry->T = position.T() * 1.0E-3 / c_light;
443 entry->NTimeHits = candidate->NTimeHits;
444
445 FillParticles(candidate, &entry->Particles);
446 }
447}
448
449//------------------------------------------------------------------------------
450
451void TreeWriter::ProcessPhotons(ExRootTreeBranch *branch, TObjArray *array)
452{
453 TIter iterator(array);
454 Candidate *candidate = 0;
455 Photon *entry = 0;
456 Double_t pt, signPz, cosTheta, eta, rapidity;
457 const Double_t c_light = 2.99792458E8;
458
459 array->Sort();
460
461 // loop over all photons
462 iterator.Reset();
463 while((candidate = static_cast<Candidate *>(iterator.Next())))
464 {
465 TIter it1(candidate->GetCandidates());
466 const TLorentzVector &momentum = candidate->Momentum;
467 const TLorentzVector &position = candidate->Position;
468
469 pt = momentum.Pt();
470 cosTheta = TMath::Abs(momentum.CosTheta());
471 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
472 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
473 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
474
475 entry = static_cast<Photon *>(branch->NewEntry());
476
477 entry->Eta = eta;
478 entry->Phi = momentum.Phi();
479 entry->PT = pt;
480 entry->E = momentum.E();
481 entry->T = position.T() * 1.0E-3 / c_light;
482
483 // Isolation variables
484
485 entry->IsolationVar = candidate->IsolationVar;
486 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
487 entry->SumPtCharged = candidate->SumPtCharged;
488 entry->SumPtNeutral = candidate->SumPtNeutral;
489 entry->SumPtChargedPU = candidate->SumPtChargedPU;
490 entry->SumPt = candidate->SumPt;
491
492 entry->EhadOverEem = candidate->Eem > 0.0 ? candidate->Ehad / candidate->Eem : 999.9;
493
494 // 1: prompt -- 2: non prompt -- 3: fake
495 entry->Status = candidate->Status;
496
497 FillParticles(candidate, &entry->Particles);
498 }
499}
500
501//------------------------------------------------------------------------------
502
503void TreeWriter::ProcessElectrons(ExRootTreeBranch *branch, TObjArray *array)
504{
505 TIter iterator(array);
506 Candidate *candidate = 0;
507 Electron *entry = 0;
508 Double_t pt, signPz, cosTheta, eta, rapidity;
509 const Double_t c_light = 2.99792458E8;
510
511 array->Sort();
512
513 // loop over all electrons
514 iterator.Reset();
515 while((candidate = static_cast<Candidate *>(iterator.Next())))
516 {
517 const TLorentzVector &momentum = candidate->Momentum;
518 const TLorentzVector &position = candidate->Position;
519
520 pt = momentum.Pt();
521 cosTheta = TMath::Abs(momentum.CosTheta());
522 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
523 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
524 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
525
526 entry = static_cast<Electron *>(branch->NewEntry());
527
528 entry->Eta = eta;
529 entry->Phi = momentum.Phi();
530 entry->PT = pt;
531
532 entry->T = position.T() * 1.0E-3 / c_light;
533
534 // displacement
535 entry->D0 = candidate->D0;
536 entry->ErrorD0 = candidate->ErrorD0;
537 entry->DZ = candidate->DZ;
538 entry->ErrorDZ = candidate->ErrorDZ;
539
540 // Isolation variables
541 entry->IsolationVar = candidate->IsolationVar;
542 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
543 entry->SumPtCharged = candidate->SumPtCharged;
544 entry->SumPtNeutral = candidate->SumPtNeutral;
545 entry->SumPtChargedPU = candidate->SumPtChargedPU;
546 entry->SumPt = candidate->SumPt;
547
548 entry->Charge = candidate->Charge;
549
550 entry->EhadOverEem = 0.0;
551
552 entry->Particle = candidate->GetCandidates()->At(0);
553 }
554}
555
556//------------------------------------------------------------------------------
557
558void TreeWriter::ProcessMuons(ExRootTreeBranch *branch, TObjArray *array)
559{
560 TIter iterator(array);
561 Candidate *candidate = 0;
562 Muon *entry = 0;
563 Double_t pt, signPz, cosTheta, eta, rapidity;
564
565 const Double_t c_light = 2.99792458E8;
566
567 array->Sort();
568
569 // loop over all muons
570 iterator.Reset();
571 while((candidate = static_cast<Candidate *>(iterator.Next())))
572 {
573 const TLorentzVector &momentum = candidate->Momentum;
574 const TLorentzVector &position = candidate->Position;
575
576 pt = momentum.Pt();
577 cosTheta = TMath::Abs(momentum.CosTheta());
578 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
579 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
580 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
581
582 entry = static_cast<Muon *>(branch->NewEntry());
583
584 entry->SetBit(kIsReferenced);
585 entry->SetUniqueID(candidate->GetUniqueID());
586
587 entry->Eta = eta;
588 entry->Phi = momentum.Phi();
589 entry->PT = pt;
590
591 entry->T = position.T() * 1.0E-3 / c_light;
592
593 // displacement
594 entry->D0 = candidate->D0;
595 entry->ErrorD0 = candidate->ErrorD0;
596 entry->DZ = candidate->DZ;
597 entry->ErrorDZ = candidate->ErrorDZ;
598
599 // Isolation variables
600
601 entry->IsolationVar = candidate->IsolationVar;
602 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
603 entry->SumPtCharged = candidate->SumPtCharged;
604 entry->SumPtNeutral = candidate->SumPtNeutral;
605 entry->SumPtChargedPU = candidate->SumPtChargedPU;
606 entry->SumPt = candidate->SumPt;
607
608 entry->Charge = candidate->Charge;
609
610 entry->Particle = candidate->GetCandidates()->At(0);
611 }
612}
613
614//------------------------------------------------------------------------------
615
616void TreeWriter::ProcessJets(ExRootTreeBranch *branch, TObjArray *array)
617{
618 TIter iterator(array);
619 Candidate *candidate = 0, *constituent = 0;
620 Jet *entry = 0;
621 Double_t pt, signPz, cosTheta, eta, rapidity;
622 Double_t ecalEnergy, hcalEnergy;
623 const Double_t c_light = 2.99792458E8;
624 Int_t i;
625
626 array->Sort();
627
628 // loop over all jets
629 iterator.Reset();
630 while((candidate = static_cast<Candidate *>(iterator.Next())))
631 {
632 TIter itConstituents(candidate->GetCandidates());
633
634 const TLorentzVector &momentum = candidate->Momentum;
635 const TLorentzVector &position = candidate->Position;
636
637 pt = momentum.Pt();
638 cosTheta = TMath::Abs(momentum.CosTheta());
639 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
640 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
641 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
642
643 entry = static_cast<Jet *>(branch->NewEntry());
644
645 entry->Eta = eta;
646 entry->Phi = momentum.Phi();
647 entry->PT = pt;
648
649 entry->T = position.T() * 1.0E-3 / c_light;
650
651 entry->Mass = momentum.M();
652
653 entry->Area = candidate->Area;
654
655 entry->DeltaEta = candidate->DeltaEta;
656 entry->DeltaPhi = candidate->DeltaPhi;
657
658 entry->Flavor = candidate->Flavor;
659 entry->FlavorAlgo = candidate->FlavorAlgo;
660 entry->FlavorPhys = candidate->FlavorPhys;
661
662 entry->BTag = candidate->BTag;
663
664 entry->BTagAlgo = candidate->BTagAlgo;
665 entry->BTagPhys = candidate->BTagPhys;
666
667 entry->TauTag = candidate->TauTag;
668 entry->TauWeight = candidate->TauWeight;
669
670 entry->Charge = candidate->Charge;
671
672 itConstituents.Reset();
673 entry->Constituents.Clear();
674 ecalEnergy = 0.0;
675 hcalEnergy = 0.0;
676 while((constituent = static_cast<Candidate *>(itConstituents.Next())))
677 {
678 entry->Constituents.Add(constituent);
679 ecalEnergy += constituent->Eem;
680 hcalEnergy += constituent->Ehad;
681 }
682
683 entry->EhadOverEem = ecalEnergy > 0.0 ? hcalEnergy / ecalEnergy : 999.9;
684
685 //--- Pile-Up Jet ID variables ----
686
687 entry->NCharged = candidate->NCharged;
688 entry->NNeutrals = candidate->NNeutrals;
689 entry->Beta = candidate->Beta;
690 entry->BetaStar = candidate->BetaStar;
691 entry->MeanSqDeltaR = candidate->MeanSqDeltaR;
692 entry->PTD = candidate->PTD;
693
694 //--- Sub-structure variables ----
695
696 entry->NSubJetsTrimmed = candidate->NSubJetsTrimmed;
697 entry->NSubJetsPruned = candidate->NSubJetsPruned;
698 entry->NSubJetsSoftDropped = candidate->NSubJetsSoftDropped;
699
700 entry->SoftDroppedJet = candidate->SoftDroppedJet;
701 entry->SoftDroppedSubJet1 = candidate->SoftDroppedSubJet1;
702 entry->SoftDroppedSubJet2 = candidate->SoftDroppedSubJet2;
703
704 for(i = 0; i < 5; i++)
705 {
706 entry->FracPt[i] = candidate->FracPt[i];
707 entry->Tau[i] = candidate->Tau[i];
708 entry->TrimmedP4[i] = candidate->TrimmedP4[i];
709 entry->PrunedP4[i] = candidate->PrunedP4[i];
710 entry->SoftDroppedP4[i] = candidate->SoftDroppedP4[i];
711 }
712
713 //--- exclusive clustering variables ---
714 entry->ExclYmerge23 = candidate->ExclYmerge23;
715 entry->ExclYmerge34 = candidate->ExclYmerge34;
716 entry->ExclYmerge45 = candidate->ExclYmerge45;
717 entry->ExclYmerge56 = candidate->ExclYmerge56;
718
719 FillParticles(candidate, &entry->Particles);
720 }
721}
722
723//------------------------------------------------------------------------------
724
725void TreeWriter::ProcessMissingET(ExRootTreeBranch *branch, TObjArray *array)
726{
727 Candidate *candidate = 0;
728 MissingET *entry = 0;
729
730 // get the first entry
731 if((candidate = static_cast<Candidate *>(array->At(0))))
732 {
733 const TLorentzVector &momentum = candidate->Momentum;
734
735 entry = static_cast<MissingET *>(branch->NewEntry());
736
737 entry->Eta = (-momentum).Eta();
738 entry->Phi = (-momentum).Phi();
739 entry->MET = momentum.Pt();
740 }
741}
742//------------------------------------------------------------------------------
743
744void TreeWriter::ProcessCscCluster(ExRootTreeBranch *branch, TObjArray *array)
745{
746 TIter iterator(array);
747 Candidate *candidate = 0;
748 CscCluster *entry = 0;
749 Double_t pt, signPz, cosTheta, eta, rapidity;
750
751 const Double_t c_light = 2.99792458E8; // in unit of m/s
752
753 array->Sort();
754
755
756 // loop over all clusters
757 iterator.Reset();
758 while((candidate = static_cast<Candidate *>(iterator.Next())))
759 {
760 const TLorentzVector &momentum = candidate->Momentum;
761 const TLorentzVector &position = candidate->DecayPosition;
762
763 pt = momentum.Pt();
764 cosTheta = TMath::Abs(momentum.CosTheta());
765 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
766 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
767
768 entry = static_cast<CscCluster *>(branch->NewEntry());
769
770 entry->SetBit(kIsReferenced);
771 entry->SetUniqueID(candidate->GetUniqueID());
772
773 entry->Eta = eta;
774 entry->Phi = momentum.Phi();
775
776
777 // entry->Eta = position.Eta();
778 // entry->Phi = position.Phi();
779
780 entry->PT = momentum.Pt(); // pt of LLP
781 entry->Px = momentum.Px();// px of LLP
782 entry->Py = momentum.Py();// py of LLP
783 entry->Pz = momentum.Pz();// pz of LLP
784 entry->E = momentum.E(); // E of LLP
785 entry->pid = candidate->PID; // LLP pid
786 entry->Eem = candidate->Eem; // LLP pid
787 entry->Ehad = candidate->Ehad; // LLP pid
788 Double_t beta = momentum.P()/momentum.E();
789 Double_t gamma = 1.0/sqrt(1-beta*beta);
790 Double_t decayDistance = sqrt(pow(position.X(),2)+pow(position.Y(),2)+pow(position.Z(),2)); // mm
791 entry->beta = beta; // LLP pid
792 entry->ctau = decayDistance/(beta * gamma);; // LLP pid
793
794 // 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
795
796 entry->T = decayDistance*(1./beta-1)* 1.0E-3/c_light*1e9; // ns
797 entry->X = position.X(); // LLP decay x
798 entry->Y = position.Y(); // LLP decay y
799 entry->Z = position.Z(); // LLP decay z
800 // entry->Size = 100;
801 }
802}
803
804//------------------------------------------------------------------------------
805
806void TreeWriter::ProcessScalarHT(ExRootTreeBranch *branch, TObjArray *array)
807{
808 Candidate *candidate = 0;
809 ScalarHT *entry = 0;
810
811 // get the first entry
812 if((candidate = static_cast<Candidate *>(array->At(0))))
813 {
814 const TLorentzVector &momentum = candidate->Momentum;
815
816 entry = static_cast<ScalarHT *>(branch->NewEntry());
817
818 entry->HT = momentum.Pt();
819 }
820}
821
822//------------------------------------------------------------------------------
823
824void TreeWriter::ProcessRho(ExRootTreeBranch *branch, TObjArray *array)
825{
826 TIter iterator(array);
827 Candidate *candidate = 0;
828 Rho *entry = 0;
829
830 // loop over all rho
831 iterator.Reset();
832 while((candidate = static_cast<Candidate *>(iterator.Next())))
833 {
834 const TLorentzVector &momentum = candidate->Momentum;
835
836 entry = static_cast<Rho *>(branch->NewEntry());
837
838 entry->Rho = momentum.E();
839 entry->Edges[0] = candidate->Edges[0];
840 entry->Edges[1] = candidate->Edges[1];
841 }
842}
843
844//------------------------------------------------------------------------------
845
846void TreeWriter::ProcessWeight(ExRootTreeBranch *branch, TObjArray *array)
847{
848 Candidate *candidate = 0;
849 Weight *entry = 0;
850
851 // get the first entry
852 if((candidate = static_cast<Candidate *>(array->At(0))))
853 {
854 const TLorentzVector &momentum = candidate->Momentum;
855
856 entry = static_cast<Weight *>(branch->NewEntry());
857
858 entry->Weight = momentum.E();
859 }
860}
861
862//------------------------------------------------------------------------------
863
864void TreeWriter::ProcessHectorHit(ExRootTreeBranch *branch, TObjArray *array)
865{
866 TIter iterator(array);
867 Candidate *candidate = 0;
868 HectorHit *entry = 0;
869
870 // loop over all roman pot hits
871 iterator.Reset();
872 while((candidate = static_cast<Candidate *>(iterator.Next())))
873 {
874 const TLorentzVector &position = candidate->Position;
875 const TLorentzVector &momentum = candidate->Momentum;
876
877 entry = static_cast<HectorHit *>(branch->NewEntry());
878
879 entry->E = momentum.E();
880
881 entry->Tx = momentum.Px();
882 entry->Ty = momentum.Py();
883
884 entry->T = position.T();
885
886 entry->X = position.X();
887 entry->Y = position.Y();
888 entry->S = position.Z();
889
890 entry->Particle = candidate->GetCandidates()->At(0);
891 }
892}
893
894//------------------------------------------------------------------------------
895
896void TreeWriter::Process()
897{
898 TBranchMap::iterator itBranchMap;
899 ExRootTreeBranch *branch;
900 TProcessMethod method;
901 TObjArray *array;
902
903 for(itBranchMap = fBranchMap.begin(); itBranchMap != fBranchMap.end(); ++itBranchMap)
904 {
905 branch = itBranchMap->first;
906 method = itBranchMap->second.first;
907 array = itBranchMap->second.second;
908
909 (this->*method)(branch, array);
910 }
911}
912
913//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.