Fork me on GitHub

source: git/modules/TimeOfFlight.cc@ d248604

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

added TOF module (processing time TBC)

  • 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 fItTrackInputArray(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 fTrackInputArray = ImportArray(GetString("TrackInputArray", "MuonMomentumSmearing/muons"));
74 fItTrackInputArray = fTrackInputArray->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(fItTrackInputArray) delete fItTrackInputArray;
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 fItTrackInputArray->Reset();
106 while((candidate = static_cast<Candidate *>(fItTrackInputArray->Next())))
107 {
108
109 particle = static_cast<Candidate *>(candidate->GetCandidates()->At(0));
110
111 const TLorentzVector &candidateInitialPosition = particle->Position;
112 const TLorentzVector &candidateFinalPosition = candidate->Position;
113 const TLorentzVector &candidateMomentum = particle->Momentum;
114
115 // time at vertex from MC truth
116 t_truth = candidateInitialPosition.T() * 1.0E-3 / c_light;
117
118 if (candidate->Position.Vect().Mag() < 5.) continue;
119
120 // various options on how to calculate the vertex time
121 ti=0;
122 switch (fVertexTimeMode)
123 {
124 case 0:
125 {
126 // assume ti from MC truth
127 // most aggressive, we are cheating and assume we can perfectly reconstruct time of primary and secondary vertices
128 ti = t_truth;
129 break;
130 }
131 case 1:
132 {
133 // always assume t=0, most conservative assumption
134 // reasonable assumption for particles originating from PV, if beamSpot has small time spread compared to timing resolution
135 // probably bad assumption for particles from highly displaced vertices (i.e Ks)
136 ti=0;
137 break;
138 }
139 case 2:
140 {
141 // same as 2 but attempt at estimate beta from vertex mass and momentum
142 beta = 1.;
143 fItVertexInputArray->Reset();
144 while((vertex = static_cast<Candidate *>(fItVertexInputArray->Next())))
145 {
146 TIter itGenParts(vertex->GetCandidates());
147 itGenParts.Reset();
148
149 while((constituent = static_cast<Candidate *>(itGenParts.Next())))
150 {
151 if (particle == constituent)
152 {
153 beta = vertex->Momentum.Beta();
154 break;
155 }
156 }
157 } // end vertex loop
158
159 // track displacement to be possibily replaced by vertex fitted position
160 ti = candidate->Position.Vect().Mag() * 1.0E-3 /(beta*c_light);
161 }
162 break;
163 }
164
165
166 ti = ti - t_truth;
167
168 p = candidateMomentum.P();
169
170 // this quantity has already been smeared by another module
171 tf = candidateFinalPosition.T() * 1.0E-3 / c_light;
172
173 // calculate time-of-flight
174 tof = tf - ti;
175 // path length of the full helix
176 l = candidate->L * 1.0E-3;
177
178 // particle velocity
179 beta = l/(c_light*tof);
180
181 // calculate particle mass (i.e particle ID)
182 mass = 0.;
183 if (beta<1) mass = p* TMath::Sqrt(1/(beta*beta) - 1);
184
185 mother = candidate;
186 candidate = static_cast<Candidate*>(candidate->Clone());
187
188 // update time at vertex based on option
189 candidate->InitialPosition.SetT(ti * 1.0E3 * c_light);
190
191 // update particle mass based on TOF-based PID
192 candidate->Momentum.SetVectM(candidateMomentum.Vect(), mass);
193
194 candidate->AddCandidate(mother);
195 fOutputArray->Add(candidate);
196 }
197}
198
199//------------------------------------------------------------------------------
200
201void TimeOfFlight::ComputeVertexMomenta()
202{
203 Candidate *track, *constituent, *particle, *vertex;
204
205 fItVertexInputArray->Reset();
206 while((vertex = static_cast<Candidate *>(fItVertexInputArray->Next())))
207 {
208
209 TIter itGenParts(vertex->GetCandidates());
210 itGenParts.Reset();
211
212 while((constituent = static_cast<Candidate *>(itGenParts.Next())))
213 {
214 fItTrackInputArray->Reset();
215 while((track = static_cast<Candidate *>(fItTrackInputArray->Next())))
216 {
217 // get gen part that generated track
218 particle = static_cast<Candidate *>(track->GetCandidates()->At(0));
219 if (particle == constituent)
220 {
221 vertex->Momentum += track->Momentum;
222 }
223
224 } // end track loop
225 } // end vertex consitutent loop
226 } // end vertex loop
227}
Note: See TracBrowser for help on using the repository browser.