Fork me on GitHub

source: git/modules/TreeWriter.cc@ 5c716fa

Last change on this file since 5c716fa was c614dd7, checked in by Michele Selvaggi <michele.selvaggi@…>, 5 years ago

added neutral and charged energy fraction to jets

  • Property mode set to 100644
File size: 26.9 KB
RevLine 
[b443089]1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
[1fa50c2]4 *
[b443089]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.
[1fa50c2]9 *
[b443089]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.
[1fa50c2]14 *
[b443089]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
[d7d2da3]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"
[341014c]34#include "ExRootAnalysis/ExRootFilter.h"
35#include "ExRootAnalysis/ExRootResult.h"
[d7d2da3]36#include "ExRootAnalysis/ExRootTreeBranch.h"
37
38#include "TDatabasePDG.h"
[341014c]39#include "TFormula.h"
[d7d2da3]40#include "TLorentzVector.h"
[341014c]41#include "TMath.h"
42#include "TObjArray.h"
43#include "TROOT.h"
44#include "TRandom3.h"
45#include "TString.h"
[d7d2da3]46
47#include <algorithm>
48#include <iostream>
49#include <sstream>
[341014c]50#include <stdexcept>
[d7d2da3]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;
[2de4dcd]71 fClassMap[Vertex::Class()] = &TreeWriter::ProcessVertices;
[d7d2da3]72 fClassMap[Track::Class()] = &TreeWriter::ProcessTracks;
73 fClassMap[Tower::Class()] = &TreeWriter::ProcessTowers;
[4d7014e]74 fClassMap[ParticleFlowCandidate::Class()] = &TreeWriter::ProcessParticleFlowCandidates;
[d7d2da3]75 fClassMap[Photon::Class()] = &TreeWriter::ProcessPhotons;
76 fClassMap[Electron::Class()] = &TreeWriter::ProcessElectrons;
77 fClassMap[Muon::Class()] = &TreeWriter::ProcessMuons;
78 fClassMap[Jet::Class()] = &TreeWriter::ProcessJets;
79 fClassMap[MissingET::Class()] = &TreeWriter::ProcessMissingET;
80 fClassMap[ScalarHT::Class()] = &TreeWriter::ProcessScalarHT;
[71648c2]81 fClassMap[Rho::Class()] = &TreeWriter::ProcessRho;
[2e229c9]82 fClassMap[Weight::Class()] = &TreeWriter::ProcessWeight;
[8f7db23]83 fClassMap[HectorHit::Class()] = &TreeWriter::ProcessHectorHit;
[d7d2da3]84
85 TBranchMap::iterator itBranchMap;
[341014c]86 map<TClass *, TProcessMethod>::iterator itClassMap;
[d7d2da3]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();
[341014c]99 for(i = 0; i < size / 3; ++i)
[d7d2da3]100 {
[341014c]101 branchInputArray = param[i * 3].GetString();
102 branchName = param[i * 3 + 1].GetString();
103 branchClassName = param[i * 3 + 2].GetString();
[d7d2da3]104
105 branchClass = gROOT->GetClass(branchClassName);
106
107 if(!branchClass)
108 {
109 cout << "** ERROR: cannot find class '" << branchClassName << "'" << endl;
110 continue;
111 }
[8f7db23]112
[d7d2da3]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();
[4d7014e]140
[341014c]141 while((candidate = static_cast<Candidate *>(it1.Next())))
[d7d2da3]142 {
143 TIter it2(candidate->GetCandidates());
144
145 // particle
146 if(candidate->GetCandidates()->GetEntriesFast() == 0)
147 {
148 array->Add(candidate);
149 continue;
150 }
151
152 // track
[341014c]153 candidate = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
[d7d2da3]154 if(candidate->GetCandidates()->GetEntriesFast() == 0)
155 {
156 array->Add(candidate);
157 continue;
158 }
159
160 // tower
161 it2.Reset();
[341014c]162 while((candidate = static_cast<Candidate *>(it2.Next())))
[d7d2da3]163 {
164 array->Add(candidate->GetCandidates()->At(0));
165 }
166 }
167}
168
169//------------------------------------------------------------------------------
170
171void TreeWriter::ProcessParticles(ExRootTreeBranch *branch, TObjArray *array)
172{
173 TIter iterator(array);
174 Candidate *candidate = 0;
175 GenParticle *entry = 0;
176 Double_t pt, signPz, cosTheta, eta, rapidity;
[8f7db23]177
[22dc7fd]178 const Double_t c_light = 2.99792458E8;
[8f7db23]179
[d7d2da3]180 // loop over all particles
181 iterator.Reset();
[341014c]182 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]183 {
184 const TLorentzVector &momentum = candidate->Momentum;
185 const TLorentzVector &position = candidate->Position;
186
[341014c]187 entry = static_cast<GenParticle *>(branch->NewEntry());
[d7d2da3]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;
[341014c]195 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
196 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]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
[341014c]217 entry->D0 = candidate->D0;
218 entry->DZ = candidate->DZ;
219 entry->P = candidate->P;
220 entry->PT = candidate->PT;
221 entry->CtgTheta = candidate->CtgTheta;
222 entry->Phi = candidate->Phi;
[acd0621]223
[d7d2da3]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();
[341014c]233 entry->T = position.T() * 1.0E-3 / c_light;
[d7d2da3]234 }
235}
236
237//------------------------------------------------------------------------------
238
[d07e957]239void TreeWriter::ProcessVertices(ExRootTreeBranch *branch, TObjArray *array)
240{
241 TIter iterator(array);
[5496767]242 Candidate *candidate = 0, *constituent = 0;
[d07e957]243 Vertex *entry = 0;
[8f7db23]244
[22dc7fd]245 const Double_t c_light = 2.99792458E8;
[5496767]246
[332025f]247 Double_t x, y, z, t, xError, yError, zError, tError, sigma, sumPT2, btvSumPT2, genDeltaZ, genSumPT2;
[2600216]248 UInt_t index, ndf;
[5496767]249
[3e2bb2b]250 CompBase *compare = Candidate::fgCompare;
251 Candidate::fgCompare = CompSumPT2<Candidate>::Instance();
[3c46e17]252 array->Sort();
[3e2bb2b]253 Candidate::fgCompare = compare;
[5496767]254
[d07e957]255 // loop over all vertices
256 iterator.Reset();
[341014c]257 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d07e957]258 {
[5496767]259
[2600216]260 index = candidate->ClusterIndex;
261 ndf = candidate->ClusterNDF;
262 sigma = candidate->ClusterSigma;
263 sumPT2 = candidate->SumPT2;
264 btvSumPT2 = candidate->BTVSumPT2;
265 genDeltaZ = candidate->GenDeltaZ;
266 genSumPT2 = candidate->GenSumPT2;
[5496767]267
[7bcca65]268 x = candidate->Position.X();
269 y = candidate->Position.Y();
270 z = candidate->Position.Z();
[341014c]271 t = candidate->Position.T() * 1.0E-3 / c_light;
[5496767]272
[341014c]273 xError = candidate->PositionError.X();
274 yError = candidate->PositionError.Y();
275 zError = candidate->PositionError.Z();
276 tError = candidate->PositionError.T() * 1.0E-3 / c_light;
[d07e957]277
[341014c]278 entry = static_cast<Vertex *>(branch->NewEntry());
[d07e957]279
[2600216]280 entry->Index = index;
281 entry->NDF = ndf;
282 entry->Sigma = sigma;
283 entry->SumPT2 = sumPT2;
284 entry->BTVSumPT2 = btvSumPT2;
285 entry->GenDeltaZ = genDeltaZ;
286 entry->GenSumPT2 = genSumPT2;
[5496767]287
[2600216]288 entry->X = x;
289 entry->Y = y;
290 entry->Z = z;
291 entry->T = t;
[5496767]292
[2600216]293 entry->ErrorX = xError;
294 entry->ErrorY = yError;
295 entry->ErrorZ = zError;
[332025f]296 entry->ErrorT = tError;
[5496767]297
[3e2bb2b]298 TIter itConstituents(candidate->GetCandidates());
299 itConstituents.Reset();
300 entry->Constituents.Clear();
[341014c]301 while((constituent = static_cast<Candidate *>(itConstituents.Next())))
[5496767]302 {
303 entry->Constituents.Add(constituent);
304 }
[d07e957]305 }
306}
307
308//------------------------------------------------------------------------------
309
[d7d2da3]310void TreeWriter::ProcessTracks(ExRootTreeBranch *branch, TObjArray *array)
311{
312 TIter iterator(array);
313 Candidate *candidate = 0;
314 Candidate *particle = 0;
315 Track *entry = 0;
[2a3eb22]316 Double_t pt, signz, cosTheta, eta, rapidity, p, ctgTheta, phi;
[22dc7fd]317 const Double_t c_light = 2.99792458E8;
[8f7db23]318
[d07e957]319 // loop over all tracks
[d7d2da3]320 iterator.Reset();
[341014c]321 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]322 {
323 const TLorentzVector &position = candidate->Position;
324
325 cosTheta = TMath::Abs(position.CosTheta());
326 signz = (position.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]327 eta = (cosTheta == 1.0 ? signz * 999.9 : position.Eta());
328 rapidity = (cosTheta == 1.0 ? signz * 999.9 : position.Rapidity());
[d7d2da3]329
[341014c]330 entry = static_cast<Track *>(branch->NewEntry());
[d7d2da3]331
332 entry->SetBit(kIsReferenced);
333 entry->SetUniqueID(candidate->GetUniqueID());
334
335 entry->PID = candidate->PID;
336
337 entry->Charge = candidate->Charge;
338
339 entry->EtaOuter = eta;
340 entry->PhiOuter = position.Phi();
341
342 entry->XOuter = position.X();
343 entry->YOuter = position.Y();
344 entry->ZOuter = position.Z();
[341014c]345 entry->TOuter = position.T() * 1.0E-3 / c_light;
[5496767]346
[acd0621]347 entry->L = candidate->L;
[5496767]348
[341014c]349 entry->D0 = candidate->D0;
350 entry->ErrorD0 = candidate->ErrorD0;
351 entry->DZ = candidate->DZ;
352 entry->ErrorDZ = candidate->ErrorDZ;
[2a3eb22]353
[341014c]354 entry->ErrorP = candidate->ErrorP;
355 entry->ErrorPT = candidate->ErrorPT;
[acd0621]356 entry->ErrorCtgTheta = candidate->ErrorCtgTheta;
[341014c]357 entry->ErrorPhi = candidate->ErrorPhi;
[5496767]358
[e4c3fef]359 entry->Xd = candidate->Xd;
360 entry->Yd = candidate->Yd;
361 entry->Zd = candidate->Zd;
[9040259]362
[d7d2da3]363 const TLorentzVector &momentum = candidate->Momentum;
364
365 pt = momentum.Pt();
[2a3eb22]366 p = momentum.P();
367 phi = momentum.Phi();
[341014c]368 ctgTheta = (TMath::Tan(momentum.Theta()) != 0) ? 1 / TMath::Tan(momentum.Theta()) : 1e10;
[2a3eb22]369
[d7d2da3]370 cosTheta = TMath::Abs(momentum.CosTheta());
371 signz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]372 eta = (cosTheta == 1.0 ? signz * 999.9 : momentum.Eta());
373 rapidity = (cosTheta == 1.0 ? signz * 999.9 : momentum.Rapidity());
[d7d2da3]374
[c1ea422]375 entry->P = p;
[341014c]376 entry->PT = pt;
[d7d2da3]377 entry->Eta = eta;
[2a3eb22]378 entry->Phi = phi;
379 entry->CtgTheta = ctgTheta;
[5496767]380
[341014c]381 particle = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
[d7d2da3]382 const TLorentzVector &initialPosition = particle->Position;
383
384 entry->X = initialPosition.X();
385 entry->Y = initialPosition.Y();
386 entry->Z = initialPosition.Z();
[341014c]387 entry->T = initialPosition.T() * 1.0E-3 / c_light;
[d7d2da3]388
389 entry->Particle = particle;
[2600216]390
391 entry->VertexIndex = candidate->ClusterIndex;
[d7d2da3]392 }
393}
394
395//------------------------------------------------------------------------------
396
397void TreeWriter::ProcessTowers(ExRootTreeBranch *branch, TObjArray *array)
398{
399 TIter iterator(array);
400 Candidate *candidate = 0;
401 Tower *entry = 0;
402 Double_t pt, signPz, cosTheta, eta, rapidity;
[22dc7fd]403 const Double_t c_light = 2.99792458E8;
[8f7db23]404
[d07e957]405 // loop over all towers
[d7d2da3]406 iterator.Reset();
[341014c]407 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]408 {
409 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]410 const TLorentzVector &position = candidate->Position;
[8f7db23]411
[d7d2da3]412 pt = momentum.Pt();
413 cosTheta = TMath::Abs(momentum.CosTheta());
414 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]415 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
416 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]417
[341014c]418 entry = static_cast<Tower *>(branch->NewEntry());
[d7d2da3]419
420 entry->SetBit(kIsReferenced);
421 entry->SetUniqueID(candidate->GetUniqueID());
422
423 entry->Eta = eta;
424 entry->Phi = momentum.Phi();
425 entry->ET = pt;
426 entry->E = momentum.E();
427 entry->Eem = candidate->Eem;
428 entry->Ehad = candidate->Ehad;
429 entry->Edges[0] = candidate->Edges[0];
430 entry->Edges[1] = candidate->Edges[1];
431 entry->Edges[2] = candidate->Edges[2];
432 entry->Edges[3] = candidate->Edges[3];
[8f7db23]433
[341014c]434 entry->T = position.T() * 1.0E-3 / c_light;
[839deb7]435 entry->NTimeHits = candidate->NTimeHits;
[8f7db23]436
[d7d2da3]437 FillParticles(candidate, &entry->Particles);
438 }
439}
440
441//------------------------------------------------------------------------------
442
[4d7014e]443void TreeWriter::ProcessParticleFlowCandidates(ExRootTreeBranch *branch, TObjArray *array)
444{
445
446 TIter iterator(array);
447 Candidate *candidate = 0;
448 Candidate *particle = 0;
449 ParticleFlowCandidate *entry = 0;
450 Double_t e, pt, signz, cosTheta, eta, rapidity, p, ctgTheta, phi;
451 const Double_t c_light = 2.99792458E8;
452
453 // loop over all tracks
454 iterator.Reset();
455 while((candidate = static_cast<Candidate *>(iterator.Next())))
456 {
457 const TLorentzVector &position = candidate->Position;
458
459 cosTheta = TMath::Abs(position.CosTheta());
460 signz = (position.Pz() >= 0.0) ? 1.0 : -1.0;
461 eta = (cosTheta == 1.0 ? signz * 999.9 : position.Eta());
462 rapidity = (cosTheta == 1.0 ? signz * 999.9 : position.Rapidity());
463
464 entry = static_cast<ParticleFlowCandidate *>(branch->NewEntry());
465
466 entry->SetBit(kIsReferenced);
467 entry->SetUniqueID(candidate->GetUniqueID());
468
469 entry->PID = candidate->PID;
470
471 entry->Charge = candidate->Charge;
472
473 entry->EtaOuter = eta;
474 entry->PhiOuter = position.Phi();
475
476 entry->XOuter = position.X();
477 entry->YOuter = position.Y();
478 entry->ZOuter = position.Z();
479 entry->TOuter = position.T() * 1.0E-3 / c_light;
480
481 entry->L = candidate->L;
482
483 entry->D0 = candidate->D0;
484 entry->ErrorD0 = candidate->ErrorD0;
485 entry->DZ = candidate->DZ;
486 entry->ErrorDZ = candidate->ErrorDZ;
487
488 entry->ErrorP = candidate->ErrorP;
489 entry->ErrorPT = candidate->ErrorPT;
490 entry->ErrorCtgTheta = candidate->ErrorCtgTheta;
491 entry->ErrorPhi = candidate->ErrorPhi;
492
493 entry->Xd = candidate->Xd;
494 entry->Yd = candidate->Yd;
495 entry->Zd = candidate->Zd;
496
497 const TLorentzVector &momentum = candidate->Momentum;
498
499 e = momentum.E();
500 pt = momentum.Pt();
501 p = momentum.P();
502 phi = momentum.Phi();
503 ctgTheta = (TMath::Tan(momentum.Theta()) != 0) ? 1 / TMath::Tan(momentum.Theta()) : 1e10;
504
505 entry->E = e;
506 entry->P = p;
507 entry->PT = pt;
508 entry->Eta = eta;
509 entry->Phi = phi;
510 entry->CtgTheta = ctgTheta;
511
512 particle = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
513 const TLorentzVector &initialPosition = particle->Position;
514
515 entry->X = initialPosition.X();
516 entry->Y = initialPosition.Y();
517 entry->Z = initialPosition.Z();
518 entry->T = initialPosition.T() * 1.0E-3 / c_light;
519
520 entry->VertexIndex = candidate->ClusterIndex;
521
522 entry->Eem = candidate->Eem;
523 entry->Ehad = candidate->Ehad;
524 entry->Edges[0] = candidate->Edges[0];
525 entry->Edges[1] = candidate->Edges[1];
526 entry->Edges[2] = candidate->Edges[2];
527 entry->Edges[3] = candidate->Edges[3];
528
529 entry->T = position.T() * 1.0E-3 / c_light;
530 entry->NTimeHits = candidate->NTimeHits;
531
532 FillParticles(candidate, &entry->Particles);
533
534 }
535}
536
537//------------------------------------------------------------------------------
538
[d7d2da3]539void TreeWriter::ProcessPhotons(ExRootTreeBranch *branch, TObjArray *array)
540{
541 TIter iterator(array);
542 Candidate *candidate = 0;
543 Photon *entry = 0;
544 Double_t pt, signPz, cosTheta, eta, rapidity;
[22dc7fd]545 const Double_t c_light = 2.99792458E8;
[8f7db23]546
[d7d2da3]547 array->Sort();
548
549 // loop over all photons
550 iterator.Reset();
[341014c]551 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]552 {
553 TIter it1(candidate->GetCandidates());
554 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]555 const TLorentzVector &position = candidate->Position;
[8f7db23]556
[d7d2da3]557 pt = momentum.Pt();
558 cosTheta = TMath::Abs(momentum.CosTheta());
559 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]560 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
561 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]562
[341014c]563 entry = static_cast<Photon *>(branch->NewEntry());
[d7d2da3]564
565 entry->Eta = eta;
566 entry->Phi = momentum.Phi();
567 entry->PT = pt;
568 entry->E = momentum.E();
[341014c]569 entry->T = position.T() * 1.0E-3 / c_light;
[8f7db23]570
[d5cae2b]571 // Isolation variables
[9040259]572
[d5cae2b]573 entry->IsolationVar = candidate->IsolationVar;
[341014c]574 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
575 entry->SumPtCharged = candidate->SumPtCharged;
576 entry->SumPtNeutral = candidate->SumPtNeutral;
577 entry->SumPtChargedPU = candidate->SumPtChargedPU;
578 entry->SumPt = candidate->SumPt;
[d5cae2b]579
[341014c]580 entry->EhadOverEem = candidate->Eem > 0.0 ? candidate->Ehad / candidate->Eem : 999.9;
[d7d2da3]581
[0e0f211]582 // 1: prompt -- 2: non prompt -- 3: fake
583 entry->Status = candidate->Status;
584
[d7d2da3]585 FillParticles(candidate, &entry->Particles);
586 }
587}
588
589//------------------------------------------------------------------------------
590
591void TreeWriter::ProcessElectrons(ExRootTreeBranch *branch, TObjArray *array)
592{
593 TIter iterator(array);
594 Candidate *candidate = 0;
595 Electron *entry = 0;
596 Double_t pt, signPz, cosTheta, eta, rapidity;
[22dc7fd]597 const Double_t c_light = 2.99792458E8;
[8f7db23]598
[d7d2da3]599 array->Sort();
600
601 // loop over all electrons
602 iterator.Reset();
[341014c]603 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]604 {
605 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]606 const TLorentzVector &position = candidate->Position;
[8f7db23]607
[d7d2da3]608 pt = momentum.Pt();
609 cosTheta = TMath::Abs(momentum.CosTheta());
610 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]611 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
612 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]613
[341014c]614 entry = static_cast<Electron *>(branch->NewEntry());
[d7d2da3]615
616 entry->Eta = eta;
617 entry->Phi = momentum.Phi();
618 entry->PT = pt;
[8f7db23]619
[341014c]620 entry->T = position.T() * 1.0E-3 / c_light;
[8f7db23]621
[0518688]622 // displacement
[341014c]623 entry->D0 = candidate->D0;
624 entry->ErrorD0 = candidate->ErrorD0;
625 entry->DZ = candidate->DZ;
626 entry->ErrorDZ = candidate->ErrorDZ;
[9040259]627
[0518688]628 // Isolation variables
[d5cae2b]629 entry->IsolationVar = candidate->IsolationVar;
[341014c]630 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
631 entry->SumPtCharged = candidate->SumPtCharged;
632 entry->SumPtNeutral = candidate->SumPtNeutral;
633 entry->SumPtChargedPU = candidate->SumPtChargedPU;
634 entry->SumPt = candidate->SumPt;
[d5cae2b]635
[d7d2da3]636 entry->Charge = candidate->Charge;
637
638 entry->EhadOverEem = 0.0;
639
640 entry->Particle = candidate->GetCandidates()->At(0);
641 }
642}
643
644//------------------------------------------------------------------------------
645
646void TreeWriter::ProcessMuons(ExRootTreeBranch *branch, TObjArray *array)
647{
648 TIter iterator(array);
649 Candidate *candidate = 0;
650 Muon *entry = 0;
651 Double_t pt, signPz, cosTheta, eta, rapidity;
[8f7db23]652
[22dc7fd]653 const Double_t c_light = 2.99792458E8;
[8f7db23]654
[d7d2da3]655 array->Sort();
656
657 // loop over all muons
658 iterator.Reset();
[341014c]659 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]660 {
661 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]662 const TLorentzVector &position = candidate->Position;
[8f7db23]663
[d7d2da3]664 pt = momentum.Pt();
665 cosTheta = TMath::Abs(momentum.CosTheta());
666 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]667 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
668 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]669
[341014c]670 entry = static_cast<Muon *>(branch->NewEntry());
[d7d2da3]671
672 entry->SetBit(kIsReferenced);
673 entry->SetUniqueID(candidate->GetUniqueID());
674
675 entry->Eta = eta;
676 entry->Phi = momentum.Phi();
677 entry->PT = pt;
678
[341014c]679 entry->T = position.T() * 1.0E-3 / c_light;
[0518688]680
681 // displacement
[341014c]682 entry->D0 = candidate->D0;
683 entry->ErrorD0 = candidate->ErrorD0;
684 entry->DZ = candidate->DZ;
685 entry->ErrorDZ = candidate->ErrorDZ;
[0518688]686
[d5cae2b]687 // Isolation variables
[9040259]688
[d5cae2b]689 entry->IsolationVar = candidate->IsolationVar;
[341014c]690 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
691 entry->SumPtCharged = candidate->SumPtCharged;
692 entry->SumPtNeutral = candidate->SumPtNeutral;
693 entry->SumPtChargedPU = candidate->SumPtChargedPU;
694 entry->SumPt = candidate->SumPt;
[8f7db23]695
[d7d2da3]696 entry->Charge = candidate->Charge;
697
698 entry->Particle = candidate->GetCandidates()->At(0);
699 }
700}
701
702//------------------------------------------------------------------------------
703
704void TreeWriter::ProcessJets(ExRootTreeBranch *branch, TObjArray *array)
705{
706 TIter iterator(array);
707 Candidate *candidate = 0, *constituent = 0;
708 Jet *entry = 0;
709 Double_t pt, signPz, cosTheta, eta, rapidity;
710 Double_t ecalEnergy, hcalEnergy;
[22dc7fd]711 const Double_t c_light = 2.99792458E8;
[de6d698]712 Int_t i;
[8f7db23]713
[d7d2da3]714 array->Sort();
715
716 // loop over all jets
717 iterator.Reset();
[341014c]718 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]719 {
720 TIter itConstituents(candidate->GetCandidates());
[8f7db23]721
[d7d2da3]722 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]723 const TLorentzVector &position = candidate->Position;
[8f7db23]724
[d7d2da3]725 pt = momentum.Pt();
726 cosTheta = TMath::Abs(momentum.CosTheta());
727 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]728 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
729 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]730
[341014c]731 entry = static_cast<Jet *>(branch->NewEntry());
[d7d2da3]732
733 entry->Eta = eta;
734 entry->Phi = momentum.Phi();
735 entry->PT = pt;
736
[341014c]737 entry->T = position.T() * 1.0E-3 / c_light;
[8f7db23]738
[d7d2da3]739 entry->Mass = momentum.M();
740
[ba1f1ee]741 entry->Area = candidate->Area;
742
[d7d2da3]743 entry->DeltaEta = candidate->DeltaEta;
744 entry->DeltaPhi = candidate->DeltaPhi;
745
[fe0273c]746 entry->Flavor = candidate->Flavor;
747 entry->FlavorAlgo = candidate->FlavorAlgo;
748 entry->FlavorPhys = candidate->FlavorPhys;
749
[d7d2da3]750 entry->BTag = candidate->BTag;
[9040259]751
752 entry->BTagAlgo = candidate->BTagAlgo;
[fe0273c]753 entry->BTagPhys = candidate->BTagPhys;
[9040259]754
[d7d2da3]755 entry->TauTag = candidate->TauTag;
[7429c6a]756 entry->TauWeight = candidate->TauWeight;
[d7d2da3]757
758 entry->Charge = candidate->Charge;
759
760 itConstituents.Reset();
761 entry->Constituents.Clear();
762 ecalEnergy = 0.0;
763 hcalEnergy = 0.0;
[341014c]764 while((constituent = static_cast<Candidate *>(itConstituents.Next())))
[d7d2da3]765 {
766 entry->Constituents.Add(constituent);
767 ecalEnergy += constituent->Eem;
768 hcalEnergy += constituent->Ehad;
769 }
770
[341014c]771 entry->EhadOverEem = ecalEnergy > 0.0 ? hcalEnergy / ecalEnergy : 999.9;
[8f7db23]772
[24d005f]773 //--- Pile-Up Jet ID variables ----
774
775 entry->NCharged = candidate->NCharged;
776 entry->NNeutrals = candidate->NNeutrals;
[c614dd7]777
778 entry->NeutralEnergyFraction = candidate->NeutralEnergyFraction;
779 entry->ChargedEnergyFraction = candidate->ChargedEnergyFraction;
[24d005f]780 entry->Beta = candidate->Beta;
781 entry->BetaStar = candidate->BetaStar;
782 entry->MeanSqDeltaR = candidate->MeanSqDeltaR;
783 entry->PTD = candidate->PTD;
[9040259]784
[de6d698]785 //--- Sub-structure variables ----
[9040259]786
787 entry->NSubJetsTrimmed = candidate->NSubJetsTrimmed;
788 entry->NSubJetsPruned = candidate->NSubJetsPruned;
[de6d698]789 entry->NSubJetsSoftDropped = candidate->NSubJetsSoftDropped;
[9040259]790
[341014c]791 entry->SoftDroppedJet = candidate->SoftDroppedJet;
792 entry->SoftDroppedSubJet1 = candidate->SoftDroppedSubJet1;
[ba75867]793 entry->SoftDroppedSubJet2 = candidate->SoftDroppedSubJet2;
794
[de6d698]795 for(i = 0; i < 5; i++)
796 {
[341014c]797 entry->FracPt[i] = candidate->FracPt[i];
798 entry->Tau[i] = candidate->Tau[i];
799 entry->TrimmedP4[i] = candidate->TrimmedP4[i];
800 entry->PrunedP4[i] = candidate->PrunedP4[i];
801 entry->SoftDroppedP4[i] = candidate->SoftDroppedP4[i];
[de6d698]802 }
[9040259]803
[e9c0d73]804 //--- exclusive clustering variables ---
805 entry->ExclYmerge23 = candidate->ExclYmerge23;
806 entry->ExclYmerge34 = candidate->ExclYmerge34;
807 entry->ExclYmerge45 = candidate->ExclYmerge45;
[341014c]808 entry->ExclYmerge56 = candidate->ExclYmerge56;
[e9c0d73]809
[d7d2da3]810 FillParticles(candidate, &entry->Particles);
811 }
812}
813
814//------------------------------------------------------------------------------
815
816void TreeWriter::ProcessMissingET(ExRootTreeBranch *branch, TObjArray *array)
817{
818 Candidate *candidate = 0;
819 MissingET *entry = 0;
820
821 // get the first entry
[341014c]822 if((candidate = static_cast<Candidate *>(array->At(0))))
[d7d2da3]823 {
824 const TLorentzVector &momentum = candidate->Momentum;
825
[341014c]826 entry = static_cast<MissingET *>(branch->NewEntry());
[d7d2da3]827
[3b465ca]828 entry->Eta = (-momentum).Eta();
[d7d2da3]829 entry->Phi = (-momentum).Phi();
830 entry->MET = momentum.Pt();
831 }
832}
833
834//------------------------------------------------------------------------------
835
836void TreeWriter::ProcessScalarHT(ExRootTreeBranch *branch, TObjArray *array)
837{
838 Candidate *candidate = 0;
839 ScalarHT *entry = 0;
840
841 // get the first entry
[341014c]842 if((candidate = static_cast<Candidate *>(array->At(0))))
[d7d2da3]843 {
844 const TLorentzVector &momentum = candidate->Momentum;
845
[341014c]846 entry = static_cast<ScalarHT *>(branch->NewEntry());
[d7d2da3]847
848 entry->HT = momentum.Pt();
849 }
850}
851
852//------------------------------------------------------------------------------
853
[71648c2]854void TreeWriter::ProcessRho(ExRootTreeBranch *branch, TObjArray *array)
855{
[3b465ca]856 TIter iterator(array);
[71648c2]857 Candidate *candidate = 0;
858 Rho *entry = 0;
859
[3b465ca]860 // loop over all rho
861 iterator.Reset();
[341014c]862 while((candidate = static_cast<Candidate *>(iterator.Next())))
[71648c2]863 {
864 const TLorentzVector &momentum = candidate->Momentum;
865
[341014c]866 entry = static_cast<Rho *>(branch->NewEntry());
[71648c2]867
[8608ef8]868 entry->Rho = momentum.E();
[3b465ca]869 entry->Edges[0] = candidate->Edges[0];
870 entry->Edges[1] = candidate->Edges[1];
[71648c2]871 }
872}
873
874//------------------------------------------------------------------------------
875
[2e229c9]876void TreeWriter::ProcessWeight(ExRootTreeBranch *branch, TObjArray *array)
877{
878 Candidate *candidate = 0;
879 Weight *entry = 0;
880
881 // get the first entry
[341014c]882 if((candidate = static_cast<Candidate *>(array->At(0))))
[2e229c9]883 {
884 const TLorentzVector &momentum = candidate->Momentum;
885
[341014c]886 entry = static_cast<Weight *>(branch->NewEntry());
[2e229c9]887
888 entry->Weight = momentum.E();
889 }
890}
891
892//------------------------------------------------------------------------------
893
[8f7db23]894void TreeWriter::ProcessHectorHit(ExRootTreeBranch *branch, TObjArray *array)
895{
896 TIter iterator(array);
897 Candidate *candidate = 0;
898 HectorHit *entry = 0;
899
900 // loop over all roman pot hits
901 iterator.Reset();
[341014c]902 while((candidate = static_cast<Candidate *>(iterator.Next())))
[8f7db23]903 {
904 const TLorentzVector &position = candidate->Position;
905 const TLorentzVector &momentum = candidate->Momentum;
906
[341014c]907 entry = static_cast<HectorHit *>(branch->NewEntry());
[8f7db23]908
909 entry->E = momentum.E();
910
911 entry->Tx = momentum.Px();
912 entry->Ty = momentum.Py();
913
914 entry->T = position.T();
915
916 entry->X = position.X();
917 entry->Y = position.Y();
918 entry->S = position.Z();
[64a4950]919
920 entry->Particle = candidate->GetCandidates()->At(0);
[8f7db23]921 }
922}
923
924//------------------------------------------------------------------------------
925
[d7d2da3]926void TreeWriter::Process()
927{
928 TBranchMap::iterator itBranchMap;
929 ExRootTreeBranch *branch;
930 TProcessMethod method;
931 TObjArray *array;
932
933 for(itBranchMap = fBranchMap.begin(); itBranchMap != fBranchMap.end(); ++itBranchMap)
934 {
935 branch = itBranchMap->first;
936 method = itBranchMap->second.first;
937 array = itBranchMap->second.second;
938
939 (this->*method)(branch, array);
940 }
941}
942
943//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.