LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 
41 
42  class HitState {
43  public:
44  HitState(double hitMeas,
45  double hitMeasErr2,
46  geo::WireID const& wireId,
47  const geo::WireGeo& wgeom)
48  : fHitMeas(hitMeas)
49  , fHitMeasErr2(hitMeasErr2)
50  , fWireId(wireId)
51  , fPlane(recob::tracking::makePlane(wgeom))
52  {}
53  HitState(double hitMeas, double hitMeasErr2, geo::WireID&& wireId, const geo::WireGeo& wgeom)
54  : fHitMeas(hitMeas)
55  , fHitMeasErr2(hitMeasErr2)
56  , fWireId(std::move(wireId))
57  , fPlane(recob::tracking::makePlane(wgeom))
58  {}
59  double hitMeas() const { return fHitMeas; }
60  double hitMeasErr2() const { return fHitMeasErr2; }
61  const Plane& plane() const { return fPlane; }
62  const geo::WireID& wireId() const { return fWireId; }
63  std::ostream& dump(std::ostream& out = std::cout) const
64  {
65  out << "HitState with meas=" << hitMeas() << " err2=" << hitMeasErr2()
66  << " plane=" << wireId().Plane << " wire=" << wireId().Wire
67  << " on plane with pos=" << plane().position() << " and dir=" << plane().direction()
68  << "\n";
69  return out;
70  }
71 
72  private:
73  double fHitMeas;
74  double fHitMeasErr2;
77  };
78 
92 
93  class TrackState {
94  public:
95  TrackState(const SVector5& trackStatePar,
96  const SMatrixSym55& trackStateCov,
97  const Plane& plane,
98  bool trackAlongPlaneDir,
99  int pid)
100  : fTrackStatePar(trackStatePar), fTrackStateCov(trackStateCov), fPlane(plane), fPid(pid)
101  {
102  SVector6 par6d = fPlane.Local5DToGlobal6DParameters(fTrackStatePar, trackAlongPlaneDir);
103  fPos = Point_t(par6d[0], par6d[1], par6d[2]);
104  fMom = Point_t(par6d[3], par6d[4], par6d[5]);
105  }
106  //
108  const SVector5& parameters() const { return fTrackStatePar; }
110  const SMatrixSym55& covariance() const { return fTrackStateCov; }
112  const Plane& plane() const { return fPlane; }
114  const Point_t& position() const { return fPos; }
116  const Vector_t& momentum() const { return fMom; }
118  int pID() const { return fPid; }
120  double mass() const
121  {
122  if (abs(fPid) == 11) { return elmass; }
123  if (abs(fPid) == 13) { return mumass; }
124  if (abs(fPid) == 211) { return pimass; }
125  if (abs(fPid) == 321) { return kmass; }
126  if (abs(fPid) == 2212) { return pmass; }
127  return util::kBogusD;
128  }
131  {
132  return SVector6(fPos.X(), fPos.Y(), fPos.Z(), fMom.X(), fMom.Y(), fMom.Z());
133  }
136  {
137  return fPlane.Local5DToGlobal6DCovariance(fTrackStateCov, true, fMom);
138  }
139  //
141  bool isTrackAlongPlaneDir() const { return fMom.Dot(fPlane.direction()) > 0; }
142  //
144  std::ostream& dump(std::ostream& out = std::cout) const
145  {
146  out << "TrackState with pID=" << pID() << " mass=" << mass() << "\npars=" << parameters()
147  << " position=" << position() << " momentum=" << momentum() << "\ncov=\n"
148  << covariance() << "\non plane with pos=" << plane().position()
149  << " and dir=" << plane().direction() << " along=" << isTrackAlongPlaneDir() << "\n";
150  return out;
151  }
152  //
154  inline double residual(const HitState& hitstate) const
155  {
156  return hitstate.hitMeas() - fTrackStatePar(0);
157  }
158 
160  inline double combinedError2(const HitState& hitstate) const
161  {
162  return hitstate.hitMeasErr2() + fTrackStateCov(0, 0);
163  }
164 
166  inline double combinedError(const HitState& hitstate) const
167  {
168  return sqrt(combinedError2(hitstate));
169  }
170 
172  inline double chi2(const HitState& hitstate) const
173  {
174  return residual(hitstate) * residual(hitstate) / combinedError2(hitstate);
175  }
176 
178  void setCovariance(const SMatrixSym55& trackStateCov) { fTrackStateCov = trackStateCov; }
179 
181  void setParameters(const SVector5& trackStatePar)
182  {
183  fTrackStatePar = trackStatePar;
184  SVector6 par6d = fPlane.Local5DToGlobal6DParameters(trackStatePar, isTrackAlongPlaneDir());
185  fPos = Point_t(par6d[0], par6d[1], par6d[2]);
186  fMom = Vector_t(par6d[3], par6d[4], par6d[5]);
187  }
188  //
189  private:
193  int fPid;
196  };
197 
198 }
199 
200 #endif
int fPid
particle id hypthesis of the track
Definition: TrackState.h:193
Plane fPlane
plane where the parameters are defined
Definition: TrackState.h:192
Class for track parameters (and errors) defined on a recob::tracking::Plane.
Definition: TrackState.h:93
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:114
Vector_t const & direction() const
Reference direction orthogonal to the plane.
Definition: TrackingPlane.h:70
double fHitMeas
Definition: TrackState.h:73
const geo::WireID & wireId() const
Definition: TrackState.h:62
Reconstruction base classes.
void setCovariance(const SMatrixSym55 &trackStateCov)
Set the covariance matrix of the TrackState.
Definition: TrackState.h:178
recob::tracking::Point_t Point_t
Definition: TrackState.h:18
recob::tracking::Vector_t Vector_t
Definition: TrackState.h:19
const Vector_t & momentum() const
momentum of the track
Definition: TrackState.h:116
const SVector5 & parameters() const
track parameters defined on the plane
Definition: TrackState.h:108
recob::tracking::SMatrixSym55 SMatrixSym55
Definition: TrackState.h:15
double hitMeas() const
Definition: TrackState.h:59
constexpr auto abs(T v)
Returns the absolute value of the argument.
STL namespace.
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 >> SMatrixSym55
SMatrixSym66 covariance6D() const
track parameter covariance matrix in global cartesian coordinates
Definition: TrackState.h:135
ROOT::Math::SMatrix< Double32_t, 6, 6, ROOT::Math::MatRepSym< Double32_t, 6 >> SMatrixSym66
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:563
recob::tracking::SMatrix55 SMatrix55
Definition: TrackState.h:14
double mass() const
mass hypthesis of the track
Definition: TrackState.h:120
const Point_t & position() const
position of the track
Definition: TrackState.h:114
double hitMeasErr2() const
Definition: TrackState.h:60
const Plane & plane() const
Definition: TrackState.h:61
double fHitMeasErr2
Definition: TrackState.h:74
bool isTrackAlongPlaneDir() const
is the track momentum along the plane direction?
Definition: TrackState.h:141
recob::tracking::SVector5 SVector5
Definition: TrackState.h:12
int pID() const
particle id hypthesis of the track
Definition: TrackState.h:118
Vector_t fMom
momentum of the track (cached)
Definition: TrackState.h:195
Point_t const & position() const
Reference position on the plane.
Definition: TrackingPlane.h:66
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...
void setParameters(const SVector5 &trackStatePar)
Set the parameters of the TrackState; also update the global position and momentum accordingly...
Definition: TrackState.h:181
ROOT::Math::SVector< Double32_t, 6 > SVector6
ROOT::Math::SMatrix< Double32_t, 5, 5 > SMatrix55
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:31
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:191
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:481
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:86
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:172
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:166
SVector6 parameters6D() const
track parameters in global cartesian coordinates
Definition: TrackState.h:130
const geo::WireID fWireId
Definition: TrackState.h:75
ROOT::Math::SVector< Double32_t, 5 > SVector5
std::ostream & dump(std::ostream &out=std::cout) const
Definition: TrackState.h:63
const SMatrixSym55 & covariance() const
track parameter covariance matrix on the plane
Definition: TrackState.h:110
recob::tracking::SMatrixSym66 SMatrixSym66
Definition: TrackState.h:16
std::ostream & dump(std::ostream &out=std::cout) const
Printout information.
Definition: TrackState.h:144
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:154
HitState(double hitMeas, double hitMeasErr2, geo::WireID const &wireId, const geo::WireGeo &wgeom)
Definition: TrackState.h:44
recob::tracking::SVector6 SVector6
Definition: TrackState.h:13
constexpr double kBogusD
obviously bogus double value
Class for a measurement on a recob::tracking::Plane (plane defined by a wire and the drift direction)...
Definition: TrackState.h:42
Point_t fPos
position of the track (cached)
Definition: TrackState.h:194
Collection of Physical constants used in LArSoft.
const Plane & plane() const
plane where the parameters are defined
Definition: TrackState.h:112
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:27
TrackState(const SVector5 &trackStatePar, const SMatrixSym55 &trackStateCov, const Plane &plane, bool trackAlongPlaneDir, int pid)
Definition: TrackState.h:95
SVector5 fTrackStatePar
track parameters defined on the plane
Definition: TrackState.h:190
HitState(double hitMeas, double hitMeasErr2, geo::WireID &&wireId, const geo::WireGeo &wgeom)
Definition: TrackState.h:53
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:160