Fork me on GitHub

source: git/modules/TreeWriter.cc@ a47edcc

Last change on this file since a47edcc was a95da74, checked in by michele <michele.selvaggi@…>, 4 years ago

added v0 of Ionisation cluster counting

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