Fork me on GitHub

source: git/modules/TimeOfFlight.cc@ d612dec

Last change on this file since d612dec was 1ad8eca, checked in by michele <michele.selvaggi@…>, 3 years ago

fixed momentum cut and generalised to neutrals

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
4 *
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.
9 *
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.
14 *
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
19 /** \class TimeOfFlight
20 *
21 * Calculates Time-Of-Flight
22 *
23 * \author Michele Selvaggi - CERN
24 *
25 */
26
27#include "modules/TimeOfFlight.h"
28
29#include "classes/DelphesClasses.h"
30#include "classes/DelphesFactory.h"
31#include "classes/DelphesFormula.h"
32
33#include "ExRootAnalysis/ExRootClassifier.h"
34#include "ExRootAnalysis/ExRootFilter.h"
35#include "ExRootAnalysis/ExRootResult.h"
36
37#include "TDatabasePDG.h"
38#include "TFormula.h"
39#include "TLorentzVector.h"
40#include "TMath.h"
41#include "TObjArray.h"
42#include "TRandom3.h"
43#include "TString.h"
44
45#include <algorithm>
46#include <iostream>
47#include <sstream>
48#include <stdexcept>
49
50using namespace std;
51//------------------------------------------------------------------------------
52
53TimeOfFlight::TimeOfFlight() :
54 fItInputArray(0), fItVertexInputArray(0)
55{
56}
57
58//------------------------------------------------------------------------------
59
60TimeOfFlight::~TimeOfFlight()
61{
62}
63
64//------------------------------------------------------------------------------
65
66void TimeOfFlight::Init()
67{
68
69 // method to compute vertex time
70 fVertexTimeMode = GetInt("VertexTimeMode", 0);
71
72 // import track input array
73 fInputArray = ImportArray(GetString("InputArray", "MuonMomentumSmearing/muons"));
74 fItInputArray = fInputArray->MakeIterator();
75
76 // import vertex input array
77 fVertexInputArray = ImportArray(GetString("VertexInputArray", "TruthVertexFinder/vertices"));
78 fItVertexInputArray = fVertexInputArray->MakeIterator();
79
80 // create output array
81 fOutputArray = ExportArray(GetString("OutputArray", "tracks"));
82}
83
84//------------------------------------------------------------------------------
85
86void TimeOfFlight::Finish()
87{
88 if(fItInputArray) delete fItInputArray;
89 if(fItVertexInputArray) delete fItVertexInputArray;
90}
91
92//------------------------------------------------------------------------------
93
94void TimeOfFlight::Process()
95{
96 Candidate *candidate, *particle, *vertex, *constituent, *mother;
97 Double_t ti, t_truth, tf;
98 Double_t l, tof, beta, p, mass;
99
100 const Double_t c_light = 2.99792458E8;
101
102 // first compute momenta of vertices based on reconstructed tracks
103 ComputeVertexMomenta();
104
105 fItInputArray->Reset();
106 while((candidate = static_cast<Candidate *>(fItInputArray->Next())))
107 {
108
109 particle = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
110
111 const TLorentzVector &candidateInitialPosition = particle->Position;
112 const TLorentzVector &candidateInitialPositionSmeared = candidate->InitialPosition;
113 const TLorentzVector &candidateFinalPosition = candidate->Position;
114 const TLorentzVector &candidateMomentum = particle->Momentum;
115
116 // time at vertex from MC truth
117 t_truth = candidateInitialPosition.T() * 1.0E-3 / c_light;
118
119 // various options on how to calculate the vertex time
120 ti=0;
121 switch (fVertexTimeMode)
122 {
123 case 0:
124 {
125 // assume ti from MC truth
126 // most aggressive, we are cheating and assume we can perfectly reconstruct time of primary and secondary vertices
127 ti = t_truth;
128 break;
129 }
130 case 1:
131 {
132 // always assume t=0, most conservative assumption
133 // reasonable assumption for particles originating from PV, if beamSpot has small time spread compared to timing resolution
134 // probably bad assumption for particles from highly displaced vertices (i.e Ks)
135 ti=0;
136 break;
137 }
138 case 2:
139 {
140 // same as 2 but attempt at estimate beta from vertex mass and momentum
141 beta = 1.;
142 fItVertexInputArray->Reset();
143 while((vertex = static_cast<Candidate *>(fItVertexInputArray->Next())))
144 {
145 TIter itGenParts(vertex->GetCandidates());
146 itGenParts.Reset();
147
148 while((constituent = static_cast<Candidate *>(itGenParts.Next())))
149 {
150 if (particle == constituent)
151 {
152 beta = vertex->Momentum.Beta();
153 break;
154 }
155 }
156 } // end vertex loop
157
158 // track displacement to be possibily replaced by vertex fitted position
159 ti = candidateInitialPositionSmeared.Vect().Mag() * 1.0E-3 /(beta*c_light);
160 }
161 break;
162 }
163
164 p = candidateMomentum.P();
165
166 // this quantity has already been smeared by another module
167 tf = candidateFinalPosition.T() * 1.0E-3 / c_light;
168
169 // calculate time-of-flight
170 tof = tf - ti;
171 // path length of the full helix
172 l = candidate->L * 1.0E-3;
173
174 // particle velocity
175 beta = l/(c_light*tof);
176
177 // calculate particle mass (i.e particle ID)
178 mass = 0.;
179 if (beta<1) mass = p* TMath::Sqrt(1/(beta*beta) - 1);
180
181 mother = candidate;
182 candidate = static_cast<Candidate*>(candidate->Clone());
183
184 // update time at vertex based on option
185 candidate->InitialPosition.SetT(ti * 1.0E3 * c_light);
186
187 // update particle mass based on TOF-based PID (commented for now, assume this calculation is done offline)
188 //candidate->Momentum.SetVectM(candidateMomentum.Vect(), mass);
189
190 candidate->AddCandidate(mother);
191 fOutputArray->Add(candidate);
192 }
193}
194
195//------------------------------------------------------------------------------
196
197void TimeOfFlight::ComputeVertexMomenta()
198{
199 Candidate *track, *constituent, *particle, *vertex;
200
201 fItVertexInputArray->Reset();
202 while((vertex = static_cast<Candidate *>(fItVertexInputArray->Next())))
203 {
204
205 TIter itGenParts(vertex->GetCandidates());
206 itGenParts.Reset();
207
208 while((constituent = static_cast<Candidate *>(itGenParts.Next())))
209 {
210 fItInputArray->Reset();
211 while((track = static_cast<Candidate *>(fItInputArray->Next())))
212 {
213 // get gen part that generated track
214 particle = static_cast<Candidate *>(track->GetCandidates()->At(0));
215 if (particle == constituent)
216 {
217 vertex->Momentum += track->Momentum;
218 }
219
220 } // end track loop
221 } // end vertex consitutent loop
222 } // end vertex loop
223}
Note: See TracBrowser for help on using the repository browser.