Fork me on GitHub

source: git/modules/TreeWriter.cc@ d612dec

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

Merge branch 'master' of github.com:Christinaw97/delphes into HEAD

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