TrackState.h
Go to the documentation of this file.
1 #ifndef TRACKSTATE_H
2 #define TRACKSTATE_H
3 
9 
10 namespace trkf {
11 
20 
21  namespace {
22  const double elmass = 0.000510998; // Electron
23  const double mumass = 0.105658367; // Muon
24  const double pimass = 0.13957; // Charged pion
25  const double kmass = 0.493677; // Charged kaon
26  const double pmass = 0.938272; // Proton
27  }
28 
29  /// \file lardata/RecoObjects/TrackState.h
30  /// \class HitState
31  ///
32  /// \brief Class for a measurement on a recob::tracking::Plane (plane defined by a wire and the drift direction).
33  ///
34  /// \author G. Cerati (FNAL, MicroBooNE)
35  /// \date 2017
36  /// \version 1.0
37  ///
38  /// This class collects the measurement information from a Hit on wire.
39  /// The information are the measured (1D) position, its error, and the measurement plane (defined by the wire and the drift direction)
40  ///
41 
42  class HitState {
43  public:
44  HitState(double hitMeas, double hitMeasErr2, geo::WireID& wireId, const geo::WireGeo& wgeom)
45  : fHitMeas(hitMeas),fHitMeasErr2(hitMeasErr2), fWireId(wireId),fPlane(recob::tracking::makePlane(wgeom)) {}
46  HitState(double hitMeas, double hitMeasErr2, geo::WireID&& wireId, const geo::WireGeo& wgeom)
47  : fHitMeas(hitMeas),fHitMeasErr2(hitMeasErr2), fWireId(std::move(wireId)),fPlane(recob::tracking::makePlane(wgeom)) {}
48  double hitMeas() const { return fHitMeas; }
49  double hitMeasErr2() const { return fHitMeasErr2; }
50  const Plane& plane() const { return fPlane; }
51  const geo::WireID& wireId() const { return fWireId; }
52  std::ostream& dump(std::ostream& out = std::cout) const {
53  out << "HitState with meas=" << hitMeas() << " err2=" << hitMeasErr2()
54  << " plane=" << wireId().Plane << " wire=" << wireId().Wire
55  << " on plane with pos=" << plane().position() << " and dir=" << plane().direction() << "\n";
56  return out;
57  }
58  private:
59  double fHitMeas;
60  double fHitMeasErr2;
63  };
64 
65  /// \file lardata/RecoObjects/TrackState.h
66  /// \class TrackState
67  ///
68  /// \brief Class for track parameters (and errors) defined on a recob::tracking::Plane.
69  ///
70  /// \author G. Cerati (FNAL, MicroBooNE)
71  /// \date 2017
72  /// \version 1.0
73  ///
74  /// This class collects the track parameters (and errors) defined on a recob::tracking::Plane.
75  /// It stores the 5d parameters and covariance, plus the global position and momentum.
76  /// Given a HitState on the same plane, it provides easy access to functionalities like chi2 and residual.
77  ///
78 
79  class TrackState {
80  public:
81  TrackState(const SVector5& trackStatePar, const SMatrixSym55& trackStateCov, const Plane& plane, bool trackAlongPlaneDir, int pid)
82  :fTrackStatePar(trackStatePar), fTrackStateCov(trackStateCov), fPlane(plane), fPid(pid)
83  {
84  SVector6 par6d = fPlane.Local5DToGlobal6DParameters(fTrackStatePar,trackAlongPlaneDir);
85  fPos = Point_t(par6d[0],par6d[1],par6d[2]);
86  fMom = Point_t(par6d[3],par6d[4],par6d[5]);
87  }
88  //
89  /// track parameters defined on the plane
90  const SVector5& parameters() const { return fTrackStatePar; }
91  /// track parameter covariance matrix on the plane
92  const SMatrixSym55& covariance() const { return fTrackStateCov; }
93  /// plane where the parameters are defined
94  const Plane& plane() const { return fPlane; }
95  /// position of the track
96  const Point_t& position() const { return fPos; }
97  /// momentum of the track
98  const Vector_t& momentum() const { return fMom; }
99  /// particle id hypthesis of the track
100  int pID() const { return fPid; }
101  /// mass hypthesis of the track
102  double mass() const {
103  if (abs(fPid)==11) { return elmass; }
104  if (abs(fPid)==13) { return mumass; }
105  if (abs(fPid)==211) { return pimass; }
106  if (abs(fPid)==321) { return kmass; }
107  if (abs(fPid)==2212) { return pmass; }
108  return util::kBogusD;
109  }
110  /// track parameters in global cartesian coordinates
111  SVector6 parameters6D() const { return SVector6(fPos.X(),fPos.Y(),fPos.Z(),fMom.X(),fMom.Y(),fMom.Z()); }
112  /// track parameter covariance matrix in global cartesian coordinates
113  SMatrixSym66 covariance6D() const { return fPlane.Local5DToGlobal6DCovariance(fTrackStateCov, true, fMom); }
114  //
115  /// is the track momentum along the plane direction?
116  bool isTrackAlongPlaneDir() const { return fMom.Dot(fPlane.direction())>0; }
117  //
118  /// Printout information
119  std::ostream& dump(std::ostream& out = std::cout) const {
120  out << "TrackState with pID=" << pID() << " mass=" << mass()
121  << "\npars=" << parameters() << " position=" << position() << " momentum=" << momentum()
122  << "\ncov=\n" << covariance()
123  << "\non plane with pos=" << plane().position() << " and dir=" << plane().direction() << " along=" << isTrackAlongPlaneDir() << "\n";
124  return out;
125  }
126  //
127  /// Residual of the TrackState with respect to a HitState. The two states must be on the same plane; it is responsibility of the user to enforce this.
128  inline double residual (const HitState& hitstate) const { return hitstate.hitMeas()-fTrackStatePar(0); }
129 
130  /// Combined squared error of the TrackState with respect to a HitState. The two states must be on the same plane; it is responsibility of the user to enforce this.
131  inline double combinedError2(const HitState& hitstate) const { return hitstate.hitMeasErr2()+fTrackStateCov(0,0); }
132 
133  /// Combined error of the TrackState with respect to a HitState. The two states must be on the same plane; it is responsibility of the user to enforce this.
134  inline double combinedError (const HitState& hitstate) const { return sqrt(combinedError2(hitstate)); }
135 
136  /// Chi2 of the TrackState with respect to a HitState. The two states must be on the same plane; it is responsibility of the user to enforce this.
137  inline double chi2 (const HitState& hitstate) const { return residual(hitstate)*residual(hitstate)/combinedError2(hitstate); }
138 
139  /// Set the covariance matrix of the TrackState.
140  void setCovariance(const SMatrixSym55& trackStateCov) { fTrackStateCov = trackStateCov; }
141 
142  /// Set the parameters of the TrackState; also update the global position and momentum accordingly.
143  void setParameters(const SVector5& trackStatePar) {
144  fTrackStatePar = trackStatePar;
145  SVector6 par6d = fPlane.Local5DToGlobal6DParameters(trackStatePar,isTrackAlongPlaneDir());
146  fPos = Point_t(par6d[0],par6d[1],par6d[2]);
147  fMom = Vector_t(par6d[3],par6d[4],par6d[5]);
148  }
149  //
150  private:
151  SVector5 fTrackStatePar; ///< track parameters defined on the plane
152  SMatrixSym55 fTrackStateCov; ///< track parameter covariance matrix on the plane
153  Plane fPlane; ///< plane where the parameters are defined
154  int fPid; ///< particle id hypthesis of the track
155  Point_t fPos; ///< position of the track (cached)
156  Vector_t fMom; ///< momentum of the track (cached)
157  };
158 
159 }
160 
161 #endif
int fPid
particle id hypthesis of the track
Definition: TrackState.h:154
Plane fPlane
plane where the parameters are defined
Definition: TrackState.h:153
Class for track parameters (and errors) defined on a recob::tracking::Plane.
Definition: TrackState.h:79
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:65
Vector_t const & direction() const
Reference direction orthogonal to the plane.
Definition: TrackingPlane.h:70
double fHitMeas
Definition: TrackState.h:59
const geo::WireID & wireId() const
Definition: TrackState.h:51
ROOT::Math::SMatrix< Double32_t, 5, 5 > SMatrix55
Definition: TrackingTypes.h:89
Reconstruction base classes.
void setCovariance(const SMatrixSym55 &trackStateCov)
Set the covariance matrix of the TrackState.
Definition: TrackState.h:140
recob::tracking::Point_t Point_t
Definition: TrackState.h:18
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
Definition: TrackingTypes.h:85
recob::tracking::Vector_t Vector_t
Definition: TrackState.h:19
const Vector_t & momentum() const
momentum of the track
Definition: TrackState.h:98
const SVector5 & parameters() const
track parameters defined on the plane
Definition: TrackState.h:90
recob::tracking::SMatrixSym55 SMatrixSym55
Definition: TrackState.h:15
double hitMeas() const
Definition: TrackState.h:48
STL namespace.
SMatrixSym66 covariance6D() const
track parameter covariance matrix in global cartesian coordinates
Definition: TrackState.h:113
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
recob::tracking::SMatrix55 SMatrix55
Definition: TrackState.h:14
double mass() const
mass hypthesis of the track
Definition: TrackState.h:102
ROOT::Math::SVector< Double32_t, 5 > SVector5
Definition: TrackingTypes.h:92
const Point_t & position() const
position of the track
Definition: TrackState.h:96
double hitMeasErr2() const
Definition: TrackState.h:49
T abs(T value)
const Plane & plane() const
Definition: TrackState.h:50
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
double fHitMeasErr2
Definition: TrackState.h:60
bool isTrackAlongPlaneDir() const
is the track momentum along the plane direction?
Definition: TrackState.h:116
recob::tracking::SVector5 SVector5
Definition: TrackState.h:12
int pID() const
particle id hypthesis of the track
Definition: TrackState.h:100
Vector_t fMom
momentum of the track (cached)
Definition: TrackState.h:156
Point_t const & position() const
Reference position on the plane.
Definition: TrackingPlane.h:66
def move(depos, offset)
Definition: depos.py:107
SMatrixSym66 Local5DToGlobal6DCovariance(SMatrixSym55 cov5d, bool hasMomentum, const Vector_t &trackMomOrDir) const
Translate track covariance from local to global coordinates. The track momentum (or direction) is nee...
Definition: TrackingPlane.h:97
void setParameters(const SVector5 &trackStatePar)
Set the parameters of the TrackState; also update the global position and momentum accordingly...
Definition: TrackState.h:143
Plane makePlane(recob::tracking::Point_t const &pos, recob::tracking::Vector_t const &dir)
helper function to construct a recob::tracking::Plane from a Point_t and a Vector_t; the point is on ...
SMatrixSym55 fTrackStateCov
track parameter covariance matrix on the plane
Definition: TrackState.h:152
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Definition of data types for geometry description.
SVector6 Local5DToGlobal6DParameters(const SVector5 &par5d, bool trackAlongPlaneDir=true) const
Function to convert parameters from local to global coordinates. Local coordinates are on the plane w...
Definition: TrackingPlane.h:80
Class defining a plane for tracking. It provides various functionalities to convert track parameters ...
Definition: TrackingPlane.h:37
double chi2(const HitState &hitstate) const
Chi2 of the TrackState with respect to a HitState. The two states must be on the same plane; it is re...
Definition: TrackState.h:137
double combinedError(const HitState &hitstate) const
Combined error of the TrackState with respect to a HitState. The two states must be on the same plane...
Definition: TrackState.h:134
ROOT::Math::SMatrix< Double32_t, 6, 6, ROOT::Math::MatRepSym< Double32_t, 6 > > SMatrixSym66
Definition: TrackingTypes.h:86
SVector6 parameters6D() const
track parameters in global cartesian coordinates
Definition: TrackState.h:111
const geo::WireID fWireId
Definition: TrackState.h:61
std::ostream & dump(std::ostream &out=std::cout) const
Definition: TrackState.h:52
const SMatrixSym55 & covariance() const
track parameter covariance matrix on the plane
Definition: TrackState.h:92
recob::tracking::SMatrixSym66 SMatrixSym66
Definition: TrackState.h:16
std::ostream & dump(std::ostream &out=std::cout) const
Printout information.
Definition: TrackState.h:119
double residual(const HitState &hitstate) const
Residual of the TrackState with respect to a HitState. The two states must be on the same plane; it i...
Definition: TrackState.h:128
recob::tracking::SVector6 SVector6
Definition: TrackState.h:13
constexpr double kBogusD
obviously bogus double value
ROOT::Math::SVector< Double32_t, 6 > SVector6
Definition: TrackingTypes.h:91
Class for a measurement on a recob::tracking::Plane (plane defined by a wire and the drift direction)...
Definition: TrackState.h:42
HitState(double hitMeas, double hitMeasErr2, geo::WireID &wireId, const geo::WireGeo &wgeom)
Definition: TrackState.h:44
Point_t fPos
position of the track (cached)
Definition: TrackState.h:155
def momentum(x1, x2, x3, scale=1.)
Collection of Physical constants used in LArSoft.
const Plane & plane() const
plane where the parameters are defined
Definition: TrackState.h:94
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
TrackState(const SVector5 &trackStatePar, const SMatrixSym55 &trackStateCov, const Plane &plane, bool trackAlongPlaneDir, int pid)
Definition: TrackState.h:81
SVector5 fTrackStatePar
track parameters defined on the plane
Definition: TrackState.h:151
HitState(double hitMeas, double hitMeasErr2, geo::WireID &&wireId, const geo::WireGeo &wgeom)
Definition: TrackState.h:46
double combinedError2(const HitState &hitstate) const
Combined squared error of the TrackState with respect to a HitState. The two states must be on the sa...
Definition: TrackState.h:131