Fork me on GitHub

source: git/modules/TreeWriter.cc@ 0852ba95

Last change on this file since 0852ba95 was 2671df6, checked in by Michele Selvaggi <michele.selvaggi@…>, 4 years ago

included CovarianceMatrix in Track and ParticleFlowCandidate branches

  • Property mode set to 100644
File size: 28.5 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->DZ = candidate->DZ;
[2a3eb22]351
[341014c]352 entry->ErrorP = candidate->ErrorP;
353 entry->ErrorPT = candidate->ErrorPT;
[2671df6]354
355 // diagonal covariance matrix terms
356 entry->ErrorD0 = candidate->ErrorD0;
357 entry->ErrorC = candidate->ErrorC;
[341014c]358 entry->ErrorPhi = candidate->ErrorPhi;
[2671df6]359 entry->ErrorDZ = candidate->ErrorDZ;
360 entry->ErrorCtgTheta = candidate->ErrorCtgTheta;
361
362 // add some offdiagonal covariance matrix elements
363 entry->ErrorD0Phi = candidate->TrackCovariance(0,1);
364 entry->ErrorD0C = candidate->TrackCovariance(0,2);
365 entry->ErrorD0DZ = candidate->TrackCovariance(0,3);
366 entry->ErrorD0CtgTheta = candidate->TrackCovariance(0,4);
367 entry->ErrorPhiC = candidate->TrackCovariance(1,2);
368 entry->ErrorPhiDZ = candidate->TrackCovariance(1,3);
369 entry->ErrorPhiCtgTheta = candidate->TrackCovariance(1,4);
370 entry->ErrorCDZ = candidate->TrackCovariance(2,3);
371 entry->ErrorCCtgTheta = candidate->TrackCovariance(2,4);
372 entry->ErrorDZCtgTheta = candidate->TrackCovariance(3,4);
[5496767]373
[e4c3fef]374 entry->Xd = candidate->Xd;
375 entry->Yd = candidate->Yd;
376 entry->Zd = candidate->Zd;
[9040259]377
[d7d2da3]378 const TLorentzVector &momentum = candidate->Momentum;
379
380 pt = momentum.Pt();
[2a3eb22]381 p = momentum.P();
382 phi = momentum.Phi();
[341014c]383 ctgTheta = (TMath::Tan(momentum.Theta()) != 0) ? 1 / TMath::Tan(momentum.Theta()) : 1e10;
[2a3eb22]384
[d7d2da3]385 cosTheta = TMath::Abs(momentum.CosTheta());
386 signz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]387 eta = (cosTheta == 1.0 ? signz * 999.9 : momentum.Eta());
388 rapidity = (cosTheta == 1.0 ? signz * 999.9 : momentum.Rapidity());
[d7d2da3]389
[c1ea422]390 entry->P = p;
[341014c]391 entry->PT = pt;
[d7d2da3]392 entry->Eta = eta;
[2a3eb22]393 entry->Phi = phi;
394 entry->CtgTheta = ctgTheta;
[5496767]395
[341014c]396 particle = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
[d7d2da3]397 const TLorentzVector &initialPosition = particle->Position;
398
399 entry->X = initialPosition.X();
400 entry->Y = initialPosition.Y();
401 entry->Z = initialPosition.Z();
[341014c]402 entry->T = initialPosition.T() * 1.0E-3 / c_light;
[d7d2da3]403
404 entry->Particle = particle;
[2600216]405
406 entry->VertexIndex = candidate->ClusterIndex;
[d7d2da3]407 }
408}
409
410//------------------------------------------------------------------------------
411
412void TreeWriter::ProcessTowers(ExRootTreeBranch *branch, TObjArray *array)
413{
414 TIter iterator(array);
415 Candidate *candidate = 0;
416 Tower *entry = 0;
417 Double_t pt, signPz, cosTheta, eta, rapidity;
[22dc7fd]418 const Double_t c_light = 2.99792458E8;
[8f7db23]419
[d07e957]420 // loop over all towers
[d7d2da3]421 iterator.Reset();
[341014c]422 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]423 {
424 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]425 const TLorentzVector &position = candidate->Position;
[8f7db23]426
[d7d2da3]427 pt = momentum.Pt();
428 cosTheta = TMath::Abs(momentum.CosTheta());
429 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]430 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
431 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]432
[341014c]433 entry = static_cast<Tower *>(branch->NewEntry());
[d7d2da3]434
435 entry->SetBit(kIsReferenced);
436 entry->SetUniqueID(candidate->GetUniqueID());
437
438 entry->Eta = eta;
439 entry->Phi = momentum.Phi();
440 entry->ET = pt;
441 entry->E = momentum.E();
442 entry->Eem = candidate->Eem;
443 entry->Ehad = candidate->Ehad;
444 entry->Edges[0] = candidate->Edges[0];
445 entry->Edges[1] = candidate->Edges[1];
446 entry->Edges[2] = candidate->Edges[2];
447 entry->Edges[3] = candidate->Edges[3];
[8f7db23]448
[341014c]449 entry->T = position.T() * 1.0E-3 / c_light;
[839deb7]450 entry->NTimeHits = candidate->NTimeHits;
[8f7db23]451
[d7d2da3]452 FillParticles(candidate, &entry->Particles);
453 }
454}
455
456//------------------------------------------------------------------------------
457
[4d7014e]458void TreeWriter::ProcessParticleFlowCandidates(ExRootTreeBranch *branch, TObjArray *array)
459{
460
461 TIter iterator(array);
462 Candidate *candidate = 0;
463 Candidate *particle = 0;
464 ParticleFlowCandidate *entry = 0;
465 Double_t e, pt, signz, cosTheta, eta, rapidity, p, ctgTheta, phi;
466 const Double_t c_light = 2.99792458E8;
467
468 // loop over all tracks
469 iterator.Reset();
470 while((candidate = static_cast<Candidate *>(iterator.Next())))
471 {
472 const TLorentzVector &position = candidate->Position;
473
474 cosTheta = TMath::Abs(position.CosTheta());
475 signz = (position.Pz() >= 0.0) ? 1.0 : -1.0;
476 eta = (cosTheta == 1.0 ? signz * 999.9 : position.Eta());
477 rapidity = (cosTheta == 1.0 ? signz * 999.9 : position.Rapidity());
478
479 entry = static_cast<ParticleFlowCandidate *>(branch->NewEntry());
480
481 entry->SetBit(kIsReferenced);
482 entry->SetUniqueID(candidate->GetUniqueID());
483
484 entry->PID = candidate->PID;
485
486 entry->Charge = candidate->Charge;
487
488 entry->EtaOuter = eta;
489 entry->PhiOuter = position.Phi();
490
491 entry->XOuter = position.X();
492 entry->YOuter = position.Y();
493 entry->ZOuter = position.Z();
494 entry->TOuter = position.T() * 1.0E-3 / c_light;
495
496 entry->L = candidate->L;
497
498 entry->D0 = candidate->D0;
499 entry->DZ = candidate->DZ;
500
501 entry->ErrorP = candidate->ErrorP;
502 entry->ErrorPT = candidate->ErrorPT;
503 entry->ErrorCtgTheta = candidate->ErrorCtgTheta;
[2671df6]504
505
506 // diagonal covariance matrix terms
507
508 entry->ErrorD0 = candidate->ErrorD0;
509 entry->ErrorC = candidate->ErrorC;
[4d7014e]510 entry->ErrorPhi = candidate->ErrorPhi;
[2671df6]511 entry->ErrorDZ = candidate->ErrorDZ;
512 entry->ErrorCtgTheta = candidate->ErrorCtgTheta;
513
514 // add some offdiagonal covariance matrix elements
515 entry->ErrorD0Phi = candidate->TrackCovariance(0,1);
516 entry->ErrorD0C = candidate->TrackCovariance(0,2);
517 entry->ErrorD0DZ = candidate->TrackCovariance(0,3);
518 entry->ErrorD0CtgTheta = candidate->TrackCovariance(0,4);
519 entry->ErrorPhiC = candidate->TrackCovariance(1,2);
520 entry->ErrorPhiDZ = candidate->TrackCovariance(1,3);
521 entry->ErrorPhiCtgTheta = candidate->TrackCovariance(1,4);
522 entry->ErrorCDZ = candidate->TrackCovariance(2,3);
523 entry->ErrorCCtgTheta = candidate->TrackCovariance(2,4);
524 entry->ErrorDZCtgTheta = candidate->TrackCovariance(3,4);
525
526 cout<<entry->ErrorPhiC<<endl;
[4d7014e]527
528 entry->Xd = candidate->Xd;
529 entry->Yd = candidate->Yd;
530 entry->Zd = candidate->Zd;
531
532 const TLorentzVector &momentum = candidate->Momentum;
533
534 e = momentum.E();
535 pt = momentum.Pt();
536 p = momentum.P();
537 phi = momentum.Phi();
538 ctgTheta = (TMath::Tan(momentum.Theta()) != 0) ? 1 / TMath::Tan(momentum.Theta()) : 1e10;
539
540 entry->E = e;
541 entry->P = p;
542 entry->PT = pt;
543 entry->Eta = eta;
544 entry->Phi = phi;
545 entry->CtgTheta = ctgTheta;
546
547 particle = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
548 const TLorentzVector &initialPosition = particle->Position;
549
550 entry->X = initialPosition.X();
551 entry->Y = initialPosition.Y();
552 entry->Z = initialPosition.Z();
553 entry->T = initialPosition.T() * 1.0E-3 / c_light;
554
555 entry->VertexIndex = candidate->ClusterIndex;
556
557 entry->Eem = candidate->Eem;
558 entry->Ehad = candidate->Ehad;
559 entry->Edges[0] = candidate->Edges[0];
560 entry->Edges[1] = candidate->Edges[1];
561 entry->Edges[2] = candidate->Edges[2];
562 entry->Edges[3] = candidate->Edges[3];
563
564 entry->T = position.T() * 1.0E-3 / c_light;
565 entry->NTimeHits = candidate->NTimeHits;
566
567 FillParticles(candidate, &entry->Particles);
568
569 }
570}
571
572//------------------------------------------------------------------------------
573
[d7d2da3]574void TreeWriter::ProcessPhotons(ExRootTreeBranch *branch, TObjArray *array)
575{
576 TIter iterator(array);
577 Candidate *candidate = 0;
578 Photon *entry = 0;
579 Double_t pt, signPz, cosTheta, eta, rapidity;
[22dc7fd]580 const Double_t c_light = 2.99792458E8;
[8f7db23]581
[d7d2da3]582 array->Sort();
583
584 // loop over all photons
585 iterator.Reset();
[341014c]586 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]587 {
588 TIter it1(candidate->GetCandidates());
589 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]590 const TLorentzVector &position = candidate->Position;
[8f7db23]591
[d7d2da3]592 pt = momentum.Pt();
593 cosTheta = TMath::Abs(momentum.CosTheta());
594 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]595 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
596 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]597
[341014c]598 entry = static_cast<Photon *>(branch->NewEntry());
[d7d2da3]599
600 entry->Eta = eta;
601 entry->Phi = momentum.Phi();
602 entry->PT = pt;
603 entry->E = momentum.E();
[341014c]604 entry->T = position.T() * 1.0E-3 / c_light;
[8f7db23]605
[d5cae2b]606 // Isolation variables
[9040259]607
[d5cae2b]608 entry->IsolationVar = candidate->IsolationVar;
[341014c]609 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
610 entry->SumPtCharged = candidate->SumPtCharged;
611 entry->SumPtNeutral = candidate->SumPtNeutral;
612 entry->SumPtChargedPU = candidate->SumPtChargedPU;
613 entry->SumPt = candidate->SumPt;
[d5cae2b]614
[341014c]615 entry->EhadOverEem = candidate->Eem > 0.0 ? candidate->Ehad / candidate->Eem : 999.9;
[d7d2da3]616
[0e0f211]617 // 1: prompt -- 2: non prompt -- 3: fake
618 entry->Status = candidate->Status;
619
[d7d2da3]620 FillParticles(candidate, &entry->Particles);
621 }
622}
623
624//------------------------------------------------------------------------------
625
626void TreeWriter::ProcessElectrons(ExRootTreeBranch *branch, TObjArray *array)
627{
628 TIter iterator(array);
629 Candidate *candidate = 0;
630 Electron *entry = 0;
631 Double_t pt, signPz, cosTheta, eta, rapidity;
[22dc7fd]632 const Double_t c_light = 2.99792458E8;
[8f7db23]633
[d7d2da3]634 array->Sort();
635
636 // loop over all electrons
637 iterator.Reset();
[341014c]638 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]639 {
640 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]641 const TLorentzVector &position = candidate->Position;
[8f7db23]642
[d7d2da3]643 pt = momentum.Pt();
644 cosTheta = TMath::Abs(momentum.CosTheta());
645 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]646 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
647 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]648
[341014c]649 entry = static_cast<Electron *>(branch->NewEntry());
[d7d2da3]650
651 entry->Eta = eta;
652 entry->Phi = momentum.Phi();
653 entry->PT = pt;
[8f7db23]654
[341014c]655 entry->T = position.T() * 1.0E-3 / c_light;
[8f7db23]656
[0518688]657 // displacement
[341014c]658 entry->D0 = candidate->D0;
659 entry->ErrorD0 = candidate->ErrorD0;
660 entry->DZ = candidate->DZ;
661 entry->ErrorDZ = candidate->ErrorDZ;
[9040259]662
[0518688]663 // Isolation variables
[d5cae2b]664 entry->IsolationVar = candidate->IsolationVar;
[341014c]665 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
666 entry->SumPtCharged = candidate->SumPtCharged;
667 entry->SumPtNeutral = candidate->SumPtNeutral;
668 entry->SumPtChargedPU = candidate->SumPtChargedPU;
669 entry->SumPt = candidate->SumPt;
[d5cae2b]670
[d7d2da3]671 entry->Charge = candidate->Charge;
672
673 entry->EhadOverEem = 0.0;
674
675 entry->Particle = candidate->GetCandidates()->At(0);
676 }
677}
678
679//------------------------------------------------------------------------------
680
681void TreeWriter::ProcessMuons(ExRootTreeBranch *branch, TObjArray *array)
682{
683 TIter iterator(array);
684 Candidate *candidate = 0;
685 Muon *entry = 0;
686 Double_t pt, signPz, cosTheta, eta, rapidity;
[8f7db23]687
[22dc7fd]688 const Double_t c_light = 2.99792458E8;
[8f7db23]689
[d7d2da3]690 array->Sort();
691
692 // loop over all muons
693 iterator.Reset();
[341014c]694 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]695 {
696 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]697 const TLorentzVector &position = candidate->Position;
[8f7db23]698
[d7d2da3]699 pt = momentum.Pt();
700 cosTheta = TMath::Abs(momentum.CosTheta());
701 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]702 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
703 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]704
[341014c]705 entry = static_cast<Muon *>(branch->NewEntry());
[d7d2da3]706
707 entry->SetBit(kIsReferenced);
708 entry->SetUniqueID(candidate->GetUniqueID());
709
710 entry->Eta = eta;
711 entry->Phi = momentum.Phi();
712 entry->PT = pt;
713
[341014c]714 entry->T = position.T() * 1.0E-3 / c_light;
[0518688]715
716 // displacement
[341014c]717 entry->D0 = candidate->D0;
718 entry->ErrorD0 = candidate->ErrorD0;
719 entry->DZ = candidate->DZ;
720 entry->ErrorDZ = candidate->ErrorDZ;
[0518688]721
[d5cae2b]722 // Isolation variables
[9040259]723
[d5cae2b]724 entry->IsolationVar = candidate->IsolationVar;
[341014c]725 entry->IsolationVarRhoCorr = candidate->IsolationVarRhoCorr;
726 entry->SumPtCharged = candidate->SumPtCharged;
727 entry->SumPtNeutral = candidate->SumPtNeutral;
728 entry->SumPtChargedPU = candidate->SumPtChargedPU;
729 entry->SumPt = candidate->SumPt;
[8f7db23]730
[d7d2da3]731 entry->Charge = candidate->Charge;
732
733 entry->Particle = candidate->GetCandidates()->At(0);
734 }
735}
736
737//------------------------------------------------------------------------------
738
739void TreeWriter::ProcessJets(ExRootTreeBranch *branch, TObjArray *array)
740{
741 TIter iterator(array);
742 Candidate *candidate = 0, *constituent = 0;
743 Jet *entry = 0;
744 Double_t pt, signPz, cosTheta, eta, rapidity;
745 Double_t ecalEnergy, hcalEnergy;
[22dc7fd]746 const Double_t c_light = 2.99792458E8;
[de6d698]747 Int_t i;
[8f7db23]748
[d7d2da3]749 array->Sort();
750
751 // loop over all jets
752 iterator.Reset();
[341014c]753 while((candidate = static_cast<Candidate *>(iterator.Next())))
[d7d2da3]754 {
755 TIter itConstituents(candidate->GetCandidates());
[8f7db23]756
[d7d2da3]757 const TLorentzVector &momentum = candidate->Momentum;
[22dc7fd]758 const TLorentzVector &position = candidate->Position;
[8f7db23]759
[d7d2da3]760 pt = momentum.Pt();
761 cosTheta = TMath::Abs(momentum.CosTheta());
762 signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
[341014c]763 eta = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Eta());
764 rapidity = (cosTheta == 1.0 ? signPz * 999.9 : momentum.Rapidity());
[d7d2da3]765
[341014c]766 entry = static_cast<Jet *>(branch->NewEntry());
[d7d2da3]767
768 entry->Eta = eta;
769 entry->Phi = momentum.Phi();
770 entry->PT = pt;
771
[341014c]772 entry->T = position.T() * 1.0E-3 / c_light;
[8f7db23]773
[d7d2da3]774 entry->Mass = momentum.M();
775
[ba1f1ee]776 entry->Area = candidate->Area;
777
[d7d2da3]778 entry->DeltaEta = candidate->DeltaEta;
779 entry->DeltaPhi = candidate->DeltaPhi;
780
[fe0273c]781 entry->Flavor = candidate->Flavor;
782 entry->FlavorAlgo = candidate->FlavorAlgo;
783 entry->FlavorPhys = candidate->FlavorPhys;
784
[d7d2da3]785 entry->BTag = candidate->BTag;
[9040259]786
787 entry->BTagAlgo = candidate->BTagAlgo;
[fe0273c]788 entry->BTagPhys = candidate->BTagPhys;
[9040259]789
[d7d2da3]790 entry->TauTag = candidate->TauTag;
[7429c6a]791 entry->TauWeight = candidate->TauWeight;
[d7d2da3]792
793 entry->Charge = candidate->Charge;
794
795 itConstituents.Reset();
796 entry->Constituents.Clear();
797 ecalEnergy = 0.0;
798 hcalEnergy = 0.0;
[341014c]799 while((constituent = static_cast<Candidate *>(itConstituents.Next())))
[d7d2da3]800 {
801 entry->Constituents.Add(constituent);
802 ecalEnergy += constituent->Eem;
803 hcalEnergy += constituent->Ehad;
804 }
805
[341014c]806 entry->EhadOverEem = ecalEnergy > 0.0 ? hcalEnergy / ecalEnergy : 999.9;
[8f7db23]807
[24d005f]808 //--- Pile-Up Jet ID variables ----
809
810 entry->NCharged = candidate->NCharged;
811 entry->NNeutrals = candidate->NNeutrals;
[c614dd7]812
813 entry->NeutralEnergyFraction = candidate->NeutralEnergyFraction;
814 entry->ChargedEnergyFraction = candidate->ChargedEnergyFraction;
[24d005f]815 entry->Beta = candidate->Beta;
816 entry->BetaStar = candidate->BetaStar;
817 entry->MeanSqDeltaR = candidate->MeanSqDeltaR;
818 entry->PTD = candidate->PTD;
[9040259]819
[de6d698]820 //--- Sub-structure variables ----
[9040259]821
822 entry->NSubJetsTrimmed = candidate->NSubJetsTrimmed;
823 entry->NSubJetsPruned = candidate->NSubJetsPruned;
[de6d698]824 entry->NSubJetsSoftDropped = candidate->NSubJetsSoftDropped;
[9040259]825
[341014c]826 entry->SoftDroppedJet = candidate->SoftDroppedJet;
827 entry->SoftDroppedSubJet1 = candidate->SoftDroppedSubJet1;
[ba75867]828 entry->SoftDroppedSubJet2 = candidate->SoftDroppedSubJet2;
829
[de6d698]830 for(i = 0; i < 5; i++)
831 {
[341014c]832 entry->FracPt[i] = candidate->FracPt[i];
833 entry->Tau[i] = candidate->Tau[i];
834 entry->TrimmedP4[i] = candidate->TrimmedP4[i];
835 entry->PrunedP4[i] = candidate->PrunedP4[i];
836 entry->SoftDroppedP4[i] = candidate->SoftDroppedP4[i];
[de6d698]837 }
[9040259]838
[e9c0d73]839 //--- exclusive clustering variables ---
840 entry->ExclYmerge23 = candidate->ExclYmerge23;
841 entry->ExclYmerge34 = candidate->ExclYmerge34;
842 entry->ExclYmerge45 = candidate->ExclYmerge45;
[341014c]843 entry->ExclYmerge56 = candidate->ExclYmerge56;
[e9c0d73]844
[d7d2da3]845 FillParticles(candidate, &entry->Particles);
846 }
847}
848
849//------------------------------------------------------------------------------
850
851void TreeWriter::ProcessMissingET(ExRootTreeBranch *branch, TObjArray *array)
852{
853 Candidate *candidate = 0;
854 MissingET *entry = 0;
855
856 // get the first entry
[341014c]857 if((candidate = static_cast<Candidate *>(array->At(0))))
[d7d2da3]858 {
859 const TLorentzVector &momentum = candidate->Momentum;
860
[341014c]861 entry = static_cast<MissingET *>(branch->NewEntry());
[d7d2da3]862
[3b465ca]863 entry->Eta = (-momentum).Eta();
[d7d2da3]864 entry->Phi = (-momentum).Phi();
865 entry->MET = momentum.Pt();
866 }
867}
868
869//------------------------------------------------------------------------------
870
871void TreeWriter::ProcessScalarHT(ExRootTreeBranch *branch, TObjArray *array)
872{
873 Candidate *candidate = 0;
874 ScalarHT *entry = 0;
875
876 // get the first entry
[341014c]877 if((candidate = static_cast<Candidate *>(array->At(0))))
[d7d2da3]878 {
879 const TLorentzVector &momentum = candidate->Momentum;
880
[341014c]881 entry = static_cast<ScalarHT *>(branch->NewEntry());
[d7d2da3]882
883 entry->HT = momentum.Pt();
884 }
885}
886
887//------------------------------------------------------------------------------
888
[71648c2]889void TreeWriter::ProcessRho(ExRootTreeBranch *branch, TObjArray *array)
890{
[3b465ca]891 TIter iterator(array);
[71648c2]892 Candidate *candidate = 0;
893 Rho *entry = 0;
894
[3b465ca]895 // loop over all rho
896 iterator.Reset();
[341014c]897 while((candidate = static_cast<Candidate *>(iterator.Next())))
[71648c2]898 {
899 const TLorentzVector &momentum = candidate->Momentum;
900
[341014c]901 entry = static_cast<Rho *>(branch->NewEntry());
[71648c2]902
[8608ef8]903 entry->Rho = momentum.E();
[3b465ca]904 entry->Edges[0] = candidate->Edges[0];
905 entry->Edges[1] = candidate->Edges[1];
[71648c2]906 }
907}
908
909//------------------------------------------------------------------------------
910
[2e229c9]911void TreeWriter::ProcessWeight(ExRootTreeBranch *branch, TObjArray *array)
912{
913 Candidate *candidate = 0;
914 Weight *entry = 0;
915
916 // get the first entry
[341014c]917 if((candidate = static_cast<Candidate *>(array->At(0))))
[2e229c9]918 {
919 const TLorentzVector &momentum = candidate->Momentum;
920
[341014c]921 entry = static_cast<Weight *>(branch->NewEntry());
[2e229c9]922
923 entry->Weight = momentum.E();
924 }
925}
926
927//------------------------------------------------------------------------------
928
[8f7db23]929void TreeWriter::ProcessHectorHit(ExRootTreeBranch *branch, TObjArray *array)
930{
931 TIter iterator(array);
932 Candidate *candidate = 0;
933 HectorHit *entry = 0;
934
935 // loop over all roman pot hits
936 iterator.Reset();
[341014c]937 while((candidate = static_cast<Candidate *>(iterator.Next())))
[8f7db23]938 {
939 const TLorentzVector &position = candidate->Position;
940 const TLorentzVector &momentum = candidate->Momentum;
941
[341014c]942 entry = static_cast<HectorHit *>(branch->NewEntry());
[8f7db23]943
944 entry->E = momentum.E();
945
946 entry->Tx = momentum.Px();
947 entry->Ty = momentum.Py();
948
949 entry->T = position.T();
950
951 entry->X = position.X();
952 entry->Y = position.Y();
953 entry->S = position.Z();
[64a4950]954
955 entry->Particle = candidate->GetCandidates()->At(0);
[8f7db23]956 }
957}
958
959//------------------------------------------------------------------------------
960
[d7d2da3]961void TreeWriter::Process()
962{
963 TBranchMap::iterator itBranchMap;
964 ExRootTreeBranch *branch;
965 TProcessMethod method;
966 TObjArray *array;
967
968 for(itBranchMap = fBranchMap.begin(); itBranchMap != fBranchMap.end(); ++itBranchMap)
969 {
970 branch = itBranchMap->first;
971 method = itBranchMap->second.first;
972 array = itBranchMap->second.second;
973
974 (this->*method)(branch, array);
975 }
976}
977
978//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.