TrackStatePropagator.h
Go to the documentation of this file.
1 #ifndef TRACKSTATEPROPAGATOR_H
2 #define TRACKSTATEPROPAGATOR_H
3 
4 #include "fhiclcpp/types/Atom.h"
5 #include "fhiclcpp/types/Table.h"
9 
10 #include <utility>
11 
12 namespace detinfo {
13  class DetectorPropertiesData;
14  class LArProperties;
15 }
16 
17 namespace trkf {
18 
19  /// \class TrackStatePropagator
20  ///
21  /// \brief Class for propagation of a trkf::TrackState to a recob::tracking::Plane
22  ///
23  /// \author G. Cerati (FNAL, MicroBooNE)
24  /// \date 2017
25  /// \version 1.0
26  ///
27  /// This class holds the functionalities needed to propagate a trkf::TrackState to a recob::tracking::Plane.
28  /// While the core physics is mainly duplicated from trkf::Propagator and its derived classes (kudos to H. Greenlee),
29  /// the code and the interface are optimized for usage with classes based on SMatrix (e.g. TrackState) and
30  /// for the needs of TrackKalmanFitter.
31  ///
32  /// While the propagated position can be directly computed, accounting for the material effects
33  /// in the covariance matrix requires an iterative procedure in case of long propagations distances.
34  ///
35  /// For configuration options see TrackStatePropagator#Config
36  ///
37 
39  public:
44 
45  struct Config {
46  using Name = fhicl::Name;
48  fhicl::Atom<double> minStep{Name("minStep"),
49  Comment("Minimum propagation step length guaranteed."),
50  1.0};
51  fhicl::Atom<double> maxElossFrac{
52  Name("maxElossFrac"),
53  Comment("Maximum propagation step length based on fraction of energy loss."),
54  0.1};
56  Name("maxNit"),
57  Comment("Maximum number of iterations when applying material effects."),
58  10};
59  fhicl::Atom<double> tcut{Name("tcut"), Comment("Maximum delta ray energy for dE/dx."), 10.};
60  fhicl::Atom<double> wrongDirDistTolerance{
61  Name("wrongDirDistTolerance"),
62  Comment("Allowed propagation distance in the wrong direction."),
63  0.01};
64  fhicl::Atom<bool> propPinvErr{
65  Name("propPinvErr"),
66  Comment("Propagate error on 1/p or not (in order to avoid infs, it should be set to false "
67  "when 1/p not updated)."),
68  false};
69  };
71 
72  /// Propagation direction enum.
73  enum PropDirection { FORWARD = 0, BACKWARD = 1, UNKNOWN = 2 };
74 
75  /// Constructor from parameter values.
76  TrackStatePropagator(double minStep,
77  double maxElossFrac,
78  int maxNit,
79  double tcut,
80  double wrongDirDistTolerance,
81  bool propPinvErr);
82 
83  /// Constructor from Parameters (fhicl::Table<Config>).
85  : TrackStatePropagator(p().minStep(),
86  p().maxElossFrac(),
87  p().maxNit(),
88  p().tcut(),
89  p().wrongDirDistTolerance(),
90  p().propPinvErr())
91  {}
92 
93  /// Main function for propagation of a TrackState to a Plane
94  TrackState propagateToPlane(bool& success,
95  const detinfo::DetectorPropertiesData& detProp,
96  const TrackState& origin,
97  const Plane& target,
98  bool dodedx,
99  bool domcs,
100  PropDirection dir = FORWARD) const;
101 
102  /// Rotation of a TrackState to a Plane (zero distance propagation)
103  TrackState
104  rotateToPlane(bool& success, const TrackState& origin, const Plane& target) const
105  {
106  double dw2dw1 = 0.;
107  return rotateToPlane(success, origin, target, dw2dw1);
108  }
109 
110  /// Quick accesss to the propagated position given a distance
111  Point_t
112  propagatedPosByDistance(const Point_t& origpos, const Vector_t& origdir, double distance) const
113  {
114  return origpos + distance * origdir;
115  }
116 
117  //@{
118  /// Distance of a TrackState (Point and Vector) to a Plane, along the TrackState direction
119  double distanceToPlane(bool& success,
120  const Point_t& origpos,
121  const Vector_t& origdir,
122  const Plane& target) const;
123  double
124  distanceToPlane(bool& success, const TrackState& origin, const Plane& target) const
125  {
126  return distanceToPlane(success, origin.position(), origin.momentum().Unit(), target);
127  }
128  //@}
129 
130  //@{
131  /// Distance of a TrackState (Point) to a Plane along the direction orthogonal to the Plane
132  double perpDistanceToPlane(bool& success, const Point_t& origpos, const Plane& target) const;
133  double
134  perpDistanceToPlane(bool& success, const TrackState& origin, const Plane& target) const
135  {
136  return perpDistanceToPlane(success, origin.position(), target);
137  }
138  //@}
139 
140  //@{
141  /// Return both direction types in one go
142  std::pair<double, double> distancePairToPlane(bool& success,
143  const Point_t& origpos,
144  const Vector_t& origdir,
145  const Plane& target) const;
146  std::pair<double, double>
147  distancePairToPlane(bool& success, const TrackState& origin, const Plane& target) const
148  {
149  return distancePairToPlane(success, origin.position(), origin.momentum().Unit(), target);
150  }
151  //@}
152 
153  /// Apply energy loss.
154  void apply_dedx(double& pinv,
155  detinfo::DetectorPropertiesData const& detProp,
156  double dedx,
157  double e1,
158  double mass,
159  double s,
160  double& deriv) const;
161 
162  /// Apply multiple coulomb scattering.
163  bool apply_mcs(detinfo::DetectorPropertiesData const& detProp,
164  double dudw,
165  double dvdw,
166  double pinv,
167  double mass,
168  double s,
169  double range,
170  double p,
171  double e2,
172  bool flipSign,
173  SMatrixSym55& noise_matrix) const;
174 
175  /// get Tcut parameter used in DetectorPropertiesService Eloss method
176  double
177  getTcut() const
178  {
179  return fTcut;
180  }
181 
182  private:
183  /// Rotation of a TrackState to a Plane (zero distance propagation), keeping track of dw2dw1 (needed by mcs)
184  TrackState rotateToPlane(bool& success,
185  const TrackState& origin,
186  const Plane& target,
187  double& dw2dw1) const;
188 
189  double fMinStep; ///< Minimum propagation step length guaranteed.
190  double fMaxElossFrac; ///< Maximum propagation step length based on fraction of energy loss.
191  int fMaxNit; ///< Maximum number of iterations.
192  double fTcut; ///< Maximum delta ray energy for dE/dx.
193  double fWrongDirDistTolerance; ///< Allowed propagation distance in the wrong direction.
194  bool
195  fPropPinvErr; ///< Propagate error on 1/p or not (in order to avoid infs, it should be set to false when 1/p not updated)
197  };
198 }
199 
200 #endif
Class for track parameters (and errors) defined on a recob::tracking::Plane.
Definition: TrackState.h:79
double perpDistanceToPlane(bool &success, const TrackState &origin, const Plane &target) const
int fMaxNit
Maximum number of iterations.
const Vector_t & momentum() const
momentum of the track
Definition: TrackState.h:98
recob::tracking::SMatrixSym55 SMatrixSym55
Definition: TrackState.h:15
TrackStatePropagator(Parameters const &p)
Constructor from Parameters (fhicl::Table<Config>).
ChannelGroupService::Name Name
Class for propagation of a trkf::TrackState to a recob::tracking::Plane.
string dir
recob::tracking::Point_t Point_t
double fMinStep
Minimum propagation step length guaranteed.
const Point_t & position() const
position of the track
Definition: TrackState.h:96
double fTcut
Maximum delta ray energy for dE/dx.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space. See recob::tracking::Coord_t for more details on the ...
Definition: TrackingTypes.h:29
PropDirection
Propagation direction enum.
recob::tracking::SVector6 SVector6
TrackState rotateToPlane(bool &success, const TrackState &origin, const Plane &target) const
Rotation of a TrackState to a Plane (zero distance propagation)
Point_t propagatedPosByDistance(const Point_t &origpos, const Vector_t &origdir, double distance) const
Quick accesss to the propagated position given a distance.
p
Definition: test.py:223
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
std::pair< double, double > distancePairToPlane(bool &success, const TrackState &origin, const Plane &target) const
General LArSoft Utilities.
const detinfo::LArProperties * larprop
Class defining a plane for tracking. It provides various functionalities to convert track parameters ...
Definition: TrackingPlane.h:37
bool fPropPinvErr
Propagate error on 1/p or not (in order to avoid infs, it should be set to false when 1/p not updated...
#define Comment
double fWrongDirDistTolerance
Allowed propagation distance in the wrong direction.
double distanceToPlane(bool &success, const TrackState &origin, const Plane &target) const
ROOT::Math::SVector< Double32_t, 6 > SVector6
Definition: TrackingTypes.h:91
double fMaxElossFrac
Maximum propagation step length based on fraction of energy loss.
recob::tracking::Plane Plane
Definition: TrackState.h:17
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space. See recob::tracking::Coord_t for more detai...
Definition: TrackingTypes.h:26
recob::tracking::Vector_t Vector_t
static QCString * s
Definition: config.cpp:1042
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
double getTcut() const
get Tcut parameter used in DetectorPropertiesService Eloss method