Belle II Software development
BaseTrackTimeEstimatorModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <tracking/modules/fitter/timeEstimator/BaseTrackTimeEstimatorModule.h>
9
10#include <tracking/trackFitting/fitter/base/TrackFitter.h>
11
12#include <framework/geometry/B2Vector3.h>
13
14using namespace Belle2;
15
16namespace {
18 double calculateVelocity(const ROOT::Math::XYZVector& momentum, const Const::ChargedStable& particleHypothesis)
19 {
20 // Particle velocity in cm / ns using the typical relation between E and p.
21 const double m = particleHypothesis.getMass();
22 const double p = momentum.R();
23 const double E = hypot(m, p);
24 const double beta = p / E;
25 const double v = beta * Const::speedOfLight;
26
27 return v;
28 }
29}
30
32 Module()
33{
34 setDescription("Module estimating the track time of RecoTracks - before or after the fit. "
35 "Loops over all RecoTracks and set their time seed correctly. In case of using the fitted information,"
36 "it also sets the track seeds of the position and momentum into the first measurement (where the time seed"
37 "is calculated). It also deletes all fitted information. Do not forget to refit "
38 "the tracks afterwards.");
40
41 addParam("recoTracksStoreArrayName", m_param_recoTracksStoreArrayName, "StoreArray name of the input and output reco tracks.",
43
44 addParam("useFittedInformation", m_param_useFittedInformation, "Whether to use the information in the measurements (after fit)"
45 " or the tracking seeds for doing the extrapolation. Of course, the track fit has to be performed to use the fitted information.",
47
48 addParam("pdgCodeToUseForEstimation", m_param_pdgCodeToUseForEstimation,
49 "Which PDG code to use for creating the time estimate. How this information is used"
50 "depends on the implementation details of the child modules. Please only use the positive pdg code.",
52
53 addParam("timeOffset", m_param_timeOffset, "If you want to subtract or add a certain time, you can use this variable.",
55
56 addParam("readoutPosition", m_param_readoutPosition,
57 "In cases where the readout of the trigger is not located at the trigger directly and the signal has to"
58 "propagate a non-vanashing distance, you can set the readout position here. Please note that you have to"
59 "enable this feature by using the useReadoutPosition flag. You can control the propagation speed with the"
60 "flag readoutPositionPropagationSpeed.", m_param_readoutPosition);
61 addParam("useReadoutPosition", m_param_useReadoutPosition, "Enable the usage of the readout position."
62 "When this feature is enabled, the length from the incident of the particle in the trigger to the position"
63 "set by the readoutPosition flag is calculated and using the readoutPositionPropagationSpeed, a time is"
64 "calculated which is used in the time estimation as an offset."
65 "In the moment, this feature is only possible when using the fitted information.", m_param_useReadoutPosition);
66 addParam("readoutPositionPropagationSpeed", m_param_readoutPositionPropagationSpeed,
67 "Speed of the propagation from the hit on the trigger to the readoutPosition. Only is used when the"
68 "flag useReadoutPosition is enabled.", m_param_readoutPositionPropagationSpeed);
69}
70
72{
73 // Read and write out RecoTracks
75
77 B2FATAL("The combination of using the seed information and the readout position is not implemented in the moment.");
78 }
79}
80
82{
84
85 // Estimate the track time for each reco track depending on the settings of the module.
86 for (auto& recoTrack : m_recoTracks) {
87 double timeSeed;
89 try {
90 timeSeed = estimateTimeSeedUsingFittedInformation(recoTrack, particleHypothesis);
91 } catch (genfit::Exception& e) {
92 B2WARNING("Time extraction from fitted state failed because of " << e.what());
93 timeSeed = -9999;
94 }
95 } else {
96 timeSeed = estimateTimeSeedUsingSeedInformation(recoTrack, particleHypothesis);
97 }
98
99 if (!(timeSeed > -1000)) {
100 // Guard against NaN or just something silly.
101 B2WARNING("Fixing calculated seed Time " << timeSeed << " to zero.");
102 timeSeed = 0;
103 } else {
104 // Add the constant time offset only in non-silly cases.
105 timeSeed += m_param_timeOffset;
106 }
107
108 B2DEBUG(28, "Setting seed to " << timeSeed);
109 recoTrack.setTimeSeed(timeSeed);
110 }
111}
112
114 const Const::ChargedStable& particleHypothesis) const
115{
116 const int currentPdgCode = TrackFitter::createCorrectPDGCodeForChargedStable(particleHypothesis, recoTrack);
117 const genfit::AbsTrackRep* trackRepresentation = recoTrack.getTrackRepresentationForPDG(std::abs(currentPdgCode));
118
119 if (not trackRepresentation or not recoTrack.wasFitSuccessful(trackRepresentation)) {
120 B2WARNING("Could not estimate a correct time, as the last fit failed.");
121 return 0;
122 } else {
123 // If the flight length is clear, just use the s = v * t relation.
124 genfit::MeasuredStateOnPlane measuredState = recoTrack.getMeasuredStateOnPlaneFromFirstHit(trackRepresentation);
125
126 // Fix the position and momentum seed to the same place as where we calculation the time seed: the first measured state on plane
127 recoTrack.setPositionAndMomentum(ROOT::Math::XYZVector(measuredState.getPos()), ROOT::Math::XYZVector(measuredState.getMom()));
128
129 const double flightLength = estimateFlightLengthUsingFittedInformation(measuredState);
130
131 // Be aware that we use the measured state on plane after the extrapolation to compile the momentum.
132 const ROOT::Math::XYZVector& momentum = ROOT::Math::XYZVector(measuredState.getMom());
133 const double v = calculateVelocity(momentum, particleHypothesis);
134
135 const double flightTime = flightLength / v;
136
137 // When the readout position should be used, calculate the propagation time of the signal from the hit to the
138 // readout position.
140 const ROOT::Math::XYZVector& position = ROOT::Math::XYZVector(measuredState.getPos());
141 B2ASSERT("Readout Position must have 3 components.", m_param_readoutPosition.size() == 3);
142 const ROOT::Math::XYZVector readoutPosition(m_param_readoutPosition[0], m_param_readoutPosition[1], m_param_readoutPosition[2]);
143 const double propagationLength = (position - readoutPosition).R();
144 const double propagationTime = propagationLength / m_param_readoutPositionPropagationSpeed;
145
146 return flightTime - propagationTime;
147 } else {
148 return flightTime;
149 }
150 }
151}
152
154 const Const::ChargedStable& particleHypothesis) const
155{
156 // If the flight length is clear, just use the s = v * t relation.
157 const double s = estimateFlightLengthUsingSeedInformation(recoTrack);
158
159 const ROOT::Math::XYZVector& momentum = recoTrack.getMomentumSeed();
160 const double v = calculateVelocity(momentum, particleHypothesis);
161
162 return s / v;
163}
R E
internal precision of FFTW codelets
double R
typedef autogenerated by FFTW
virtual double estimateFlightLengthUsingFittedInformation(genfit::MeasuredStateOnPlane &measuredStateOnPlane) const =0
Overload this function to implement a specific extrapolation mechanism for fitted tracks....
double estimateTimeSeedUsingFittedInformation(RecoTrack &recoTrack, const Const::ChargedStable &particleHypothesis) const
Private helper function which calls the estimateFlightLengthUsingFittedInformation with the correct m...
void initialize() override
Initialize the needed StoreArrays and ensure they are created properly.
double m_param_timeOffset
If you want to subtract or add a certain time, you can use this variable.
void event() override
Loop over all RecoTracks and set their time seed correctly.
virtual double estimateFlightLengthUsingSeedInformation(const RecoTrack &recoTrack) const =0
Overload this function to implement a specific extrapolation mechanism for track seeds.
BaseTrackTimeEstimatorModule()
Initialize the module parameters.
bool m_param_useFittedInformation
Whether to use the information in the measurements (after fit) or the tracking seeds for doing the ex...
std::vector< double > m_param_readoutPosition
In cases where the readout of the trigger is not located at the trigger directly and the signal has t...
std::string m_param_recoTracksStoreArrayName
StoreArray name of the input and output reco tracks.
double estimateTimeSeedUsingSeedInformation(const RecoTrack &recoTrack, const Const::ChargedStable &particleHypothesis) const
Private helper function which calls the estimateFlightLengthUsingSeedInformation and computes the fli...
StoreArray< RecoTrack > m_recoTracks
RecoTracks StoreArray.
unsigned int m_param_pdgCodeToUseForEstimation
Which PDG code to use for creating the time estimate.
bool m_param_useReadoutPosition
Enable the usage of the readout position.
double m_param_readoutPositionPropagationSpeed
Speed of the propagation from the hit on the trigger to the readoutPosition.
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
double getMass() const
Particle mass.
Definition: UnitConst.cc:356
static const double speedOfLight
[cm/ns]
Definition: Const.h:695
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
Definition: RecoTrack.cc:336
void setPositionAndMomentum(const ROOT::Math::XYZVector &positionSeed, const ROOT::Math::XYZVector &momentumSeed)
Set the position and momentum seed of the reco track. ATTENTION: This is not the fitted position or m...
Definition: RecoTrack.h:590
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromFirstHit(const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane for the first hit in a fit useful for extrapolation of measureme...
Definition: RecoTrack.cc:605
ROOT::Math::XYZVector getMomentumSeed() const
Return the momentum seed stored in the reco track. ATTENTION: This is not the fitted momentum.
Definition: RecoTrack.h:487
genfit::AbsTrackRep * getTrackRepresentationForPDG(int pdgCode) const
Return an already created track representation of the given reco track for the PDG.
Definition: RecoTrack.cc:475
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
static int createCorrectPDGCodeForChargedStable(const Const::ChargedStable &particleType, const RecoTrack &recoTrack)
Helper function to multiply the PDG code of a charged stable with the charge of the reco track (if ne...
Definition: TrackFitter.cc:24
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
Abstract base class for different kinds of events.