All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
TOFUtils.h
Go to the documentation of this file.
1 #ifndef TOFUtils_h
2 #define TOFUtils_h 1
3 
4 #include <vector>
5 #include "EVENT/ReconstructedParticle.h"
6 #include "IMPL/TrackStateImpl.h"
7 #include "MarlinTrk/IMarlinTrkSystem.h"
8 #include "MarlinTrk/IMarlinTrack.h"
9 #include "DDRec/Vector3D.h"
10 
11 /**
12 \addtogroup TimeOfFlight TimeOfFlight
13 @{
14 
15  * Utility functions that are used by the TOFEstimators processor.
16  *
17  * \author F. Gaede, DESY, 2018
18  * \author B. Dudar, DESY, 2021
19 */
20 namespace TOFUtils{
21 
22  /** Comparator function by radius for tracker hits.
23  Returns `true` if \f$ \rho_{a} < \rho_{b} \f$.
24  With \f$ \rho \f$ being a radius of the tracker hit projected on the \f$ xy \f$ plane: \f$ \rho = \sqrt{x^2 + y^2} \f$.
25 
26  Primarily used to sort vector of tracker hits by \f$ \rho \f$ for the Kalman Filter fit.
27  */
28  bool sortByRho(EVENT::TrackerHit* a, EVENT::TrackerHit* b);
29 
30 
31  /** Get track state at tracker hit.
32  Returns track state at tracker hit from the Kalman Filter fit.
33 
34  Tracker hit has to be used in the fit by the Kalman Filter.
35  */
36  IMPL::TrackStateImpl getTrackStateAtHit(MarlinTrk::IMarlinTrack* marlinTrk, EVENT::TrackerHit* hit);
37 
38 
39  /** Get track momentum at the track state.
40  Returns momentum Vector3D from the given track state.
41  */
42  dd4hep::rec::Vector3D getHelixMomAtTrackState(const EVENT::TrackState& ts, double bField);
43 
44 
45  /** Get track length.
46  Returns the track length between two track states estimated by the helix length formula:
47 
48  \f$ \ell = \sqrt{\left( \frac{\varphi_{i+1} - \varphi_{i}}{\Omega}\right)^{2} + \left( z_{i+1} - z_{i} \right)^{2} } \f$
49 
50  Note: The formula above works only for the arcs with \f$ \Delta \varphi < \pi \f$.
51  */
52  double getHelixArcLength(const EVENT::TrackState& ts1, const EVENT::TrackState& ts2);
53 
54 
55 
56  /** Get track length.
57  Returns the track length between two track states estimated by the helix length formula:
58 
59  \f$ \ell = \frac{\left |z_{i+1} - z_{i}\right |}{\tan{\lambda}} \sqrt{1 + \tan{\lambda}^{2} } \f$
60 
61  Note: The formula above works for any \f$ \Delta \varphi \f$.
62 
63  However it is less precise than getHelixArcLength() due to the less precise \f$ \tan{\lambda} \f$.
64  Also helix formula implies constant momentum assumption which may show higher discrepancy for long tracks with low momentum.
65  */
66  double getHelixLengthAlongZ(const EVENT::TrackState& ts1, const EVENT::TrackState& ts2);
67 
68 
69  /** Get number of helix revolutions.
70  Returns number of helix revolutions between two track states.
71 
72  The calculation is done with:
73  \f$ N_{\mathrm{turns}} = \frac{\left |z_{i+1} - z_{i}\right |}{\tan{\lambda}} \bigg / (2 \pi \frac{1}{|\Omega|}) \f$
74  */
75  double getHelixNRevolutions(const EVENT::TrackState& ts1, const EVENT::TrackState& ts2);
76 
77  /** Returns TPC outer radius from the DD4hep detector geometry.
78  */
79  double getTPCOuterR();
80 
81  /** Returns SET hit.
82  Checks the \f$ \rho = \sqrt{x^{2}+y^{2}} \f$ of the tracker hit.
83  If \f$ \rho > R_{\mathrm{TPC, outer}} \f$ then it is the SET hit.
84  */
85  EVENT::TrackerHit* getSETHit(EVENT::Track* track, double tpcOuterR);
86 
87  /** Get a subset of the cluster calorimeter hits.
88  Returns the subset of the cluster calorimeter hits which we call "Frank"
89  by historical reasons as these hits were used to calculate time-of-flight as
90  a default method for the IDR production.
91 
92  "Frank" hits are the closest ECal hits to the linearly extrapolated
93  track line inside the ECal in each of the first maxEcalLayer ECal layers.
94  */
95  std::vector<EVENT::CalorimeterHit*> selectFrankEcalHits( EVENT::Cluster* cluster, EVENT::Track* track, int maxEcalLayer, double bField );
96 
97 
98  /** Get all subtracks of the Track.
99  Returns a vector of the subTracks of the main track that is passed as an argument.
100 
101  The main purpose of this function is to capture all hits of the track.
102  This requires iteration over the subTracks as the main Track stores hits only
103  of the first half turn due to the our fit procedure.
104 
105  The first subTrack in the returned vector is always main Track itself, which
106  containes VXD, SIT and TPC tracker hits for the first half turn.
107 
108  Then additional subTracks are added which contain hits for additional track revolutions if such exist.
109 
110  If nTPCHits \f$ \pm 1\f$ = nHits of SubTrack0 then assume subTrack0 stores TPC hits.
111  This would mean that VXD and SIT subTrack is not stored!
112  So we need skip *only first* subtrack: initial subTrack0 with TPC hits which we have anyhow added with the main Track
113  Else if nTPCHits \f$ \pm 1\f$ = nHits of SubTrack1 assume subTrack1 stores TPC hits
114  This would mean that subTrack0 stores VXD and SIT hits.
115  So we need to *skip both* subtracks VXD+SIT and 1st TPC half-turn subTracks which we have anyhow added with the main Track
116 
117  Note: We consider deviations for \f$\pm 1\f$ hit may happen because of the
118  SET and only God knows what other reasons...
119 
120  Note: This function is not guarantied to properly work 100% of times,
121  but I didn't find a better way to collect subTracks.
122  */
123  std::vector<EVENT::Track*> getSubTracks(EVENT::Track* track);
124 
125  /** Get list of track states.
126  Returns a vector of track states at the IP, track state for every tracker hit
127  inside all provided subTracks as tracks argument and the track state at the ECal surface if extrapolateToEcal argument is set to true.
128  */
129  std::vector<IMPL::TrackStateImpl> getTrackStatesPerHit(std::vector<EVENT::Track*> tracks, MarlinTrk::IMarlinTrkSystem* trkSystem, bool extrapolateToEcal, double bField);
130 
131  /** Get the time-of-flight using the closest ECal hit.
132  Returns time measured by the closest ECal hit to the extrapolated track position at the ECal surface.
133 
134  \f$ \mathrm{TOF} = t_{\mathrm{closest}} - \frac{\left| \vec{r}_{\mathrm{track}} - \vec{r}_{\mathrm{closest}} \right|}{c} \f$
135 
136  If no ECal hits are found returns `0.0`.
137  */
138  double getTofClosest( EVENT::Cluster* cluster, EVENT::Track* track, double timeResolution);
139 
140  /** Get the time-of-flight using average of the Frank ECal hits.
141  Returns the time-of-flight as an average of the Frank hits time corrected for the distance to
142  the extrapolated track position at the ECal surface assuming speed of flight is the speed of light.
143 
144  \f$ \mathrm{TOF} = \frac{1}{\mathrm{MaxEcalLayer}}\sum_{i}^{\mathrm{MaxEcalLayer}} \left( t_{i} - \frac{\left|\vec{r}_{\mathrm{track}} - \vec{r}_{i} \right|}{c} \right) \f$
145 
146  If no ECal hits are found within selectedHits, then returns `0.0`.
147  */
148  double getTofFrankAvg( std::vector<EVENT::CalorimeterHit*> selectedHits, EVENT::Track* track, double timeResolution);
149 
150  /** Get the time-of-flight using fit of the Frank ECal hits.
151  Returns the time-of-flight as an extrapolated time at the extrapolated track
152  position at the ECal surface by using a linear fit of the Frank hits time as a
153  function of the distance to the extrapolated track position at the ECal surface.
154 
155  \f$ \mathrm{TOF}=f(|\vec{r}_{\mathrm{track}} - \vec{r}_{\mathrm{hit}} |=0) \f$
156 
157  If no ECal hits are found within selectedHits, then returns `0.0`.
158  If *only one* ECal hit is found, which is not enough to perform the linear fit, then returns the same as getTofClosest() and getTofFrankAvg().
159  */
160  double getTofFrankFit( std::vector<EVENT::CalorimeterHit*> selectedHits, EVENT::Track* track, double timeResolution);
161 
162 
163 }
164 /** @} */
165 
166 #endif
double getHelixLengthAlongZ(const EVENT::TrackState &ts1, const EVENT::TrackState &ts2)
Get track length.
Definition: TOFUtils.cc:82
double getTofFrankAvg(std::vector< EVENT::CalorimeterHit * > selectedHits, EVENT::Track *track, double timeResolution)
Get the time-of-flight using average of the Frank ECal hits.
Definition: TOFUtils.cc:292
double getTofClosest(EVENT::Cluster *cluster, EVENT::Track *track, double timeResolution)
Get the time-of-flight using the closest ECal hit.
Definition: TOFUtils.cc:268
double getHelixNRevolutions(const EVENT::TrackState &ts1, const EVENT::TrackState &ts2)
Get number of helix revolutions.
Definition: TOFUtils.cc:90
CLHEP::Hep3Vector Vector3D
EVENT::TrackerHit * getSETHit(EVENT::Track *track, double tpcOuterR)
Returns SET hit.
Definition: TOFUtils.cc:112
double getTPCOuterR()
Returns TPC outer radius from the DD4hep detector geometry.
Definition: TOFUtils.cc:104
std::vector< IMPL::TrackStateImpl > getTrackStatesPerHit(std::vector< EVENT::Track * > tracks, MarlinTrk::IMarlinTrkSystem *trkSystem, bool extrapolateToEcal, double bField)
Get list of track states.
Definition: TOFUtils.cc:175
double getTofFrankFit(std::vector< EVENT::CalorimeterHit * > selectedHits, EVENT::Track *track, double timeResolution)
Get the time-of-flight using fit of the Frank ECal hits.
Definition: TOFUtils.cc:309
std::vector< EVENT::CalorimeterHit * > selectFrankEcalHits(EVENT::Cluster *cluster, EVENT::Track *track, int maxEcalLayer, double bField)
Get a subset of the cluster calorimeter hits.
Definition: TOFUtils.cc:122
double getHelixArcLength(const EVENT::TrackState &ts1, const EVENT::TrackState &ts2)
Get track length.
Definition: TOFUtils.cc:71
std::vector< EVENT::Track * > getSubTracks(EVENT::Track *track)
Get all subtracks of the Track.
Definition: TOFUtils.cc:149
bool sortByRho(EVENT::TrackerHit *a, EVENT::TrackerHit *b)
Comparator function by radius for tracker hits.
Definition: TOFUtils.cc:42
IMPL::TrackStateImpl getTrackStateAtHit(MarlinTrk::IMarlinTrack *marlinTrk, EVENT::TrackerHit *hit)
Get track state at tracker hit.
Definition: TOFUtils.cc:49
dd4hep::rec::Vector3D getHelixMomAtTrackState(const EVENT::TrackState &ts, double bField)
Get track momentum at the track state.
Definition: TOFUtils.cc:58