Fork me on GitHub

source: git/modules/TreeWriter.cc@ 2a1d95e

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

add example/ExampleCscCluster.py and remove decayPosition from GenParticle class

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