TrackingPlane.h
Go to the documentation of this file.
1 #ifndef TRACKINGPLANE_H
2 #define TRACKINGPLANE_H
3 
5 
6 namespace recob {
7  namespace tracking {
8 
9  /// \file lardataobj/RecoBase/TrackingPlane.h
10  /// \class recob::tracking::Plane
11  ///
12  /// \brief Class defining a plane for tracking.
13  /// It provides various functionalities to convert track parameters and covariance matrices from global to local coordinates.
14  ///
15  /// \author G. Cerati (FNAL, MicroBooNE)
16  /// \date 2017
17  /// \version 1.0
18  ///
19  /// The plane is constructed from a point in global coordinates, and a direction unit vector orthogonal to the plane.
20  /// For instance, they may refer to the position and direction of a trajectory at a given point,
21  /// or to the center of a wire and the direction orthogonal to both the wire and drift directions.
22  ///
23  /// The plane and parameters are defined along the lines of trkf::SurfXYZPlane, but with a different notation for the angles
24  /// which are now called alpha and beta to avoid confusion with theta and phi in global spherical coordinates:
25  /// (alpha, beta) correspond to (alpha := Rotation angle about y'-axis (projected Lorentz angle) = atan2(nx, hypot(ny, nz)),
26  /// beta := Rotation angle about x-axis (wire angle) = atan2(-ny, nz))
27  /// The 3D local positions are defined in terms of the unit vectors u,v,w where w is along the normal direction to the plane,
28  /// u is perpendicular to w and coplanar to the global x axis and with position sign along the positive sign of x,
29  /// v forms a right handed orthonormal basis with u and w.
30  /// The 5D track parameters are u,v,du/dw,dv/dw,1/p:
31  /// u,v are the local positions, du, dv, and dw are the local directions, and 1/p is the inverse of the track momentum.
32  /// The global 6D coordinates are formed by the track position and momentum (or direction) at a given point.
33  ///
34  /// The discussion above refers to a detector with drift direction along the x axis;
35  /// this class will have to be extended for a detector with a different drift direction.
36 
37  class Plane {
38 
39  ///
40  /// Struct caching trigonometric function results.
41  struct TrigCache {
42  public:
43  TrigCache(const Vector_t& planeDir)
44  {
45  const double diryz = std::hypot(planeDir.Y(), planeDir.Z());
46  fCosA = diryz;
47  fSinA = planeDir.X();
48  fCosB = (diryz != 0.0) ? planeDir.Z()/diryz : 1.0;
49  fSinB = (diryz != 0.0) ? -planeDir.Y()/diryz : 0.0;
50  }
51  double fCosA;
52  double fSinA;
53  double fCosB;
54  double fSinB;
55  };
56 
57  public:
58 
59  ///
60  /// Constructor from reference position on the plane and direction orthogonal to the plane
61  Plane(const Point_t& planePos, const Vector_t& planeDir)
62  : fPlanePos(planePos), fPlaneDir(planeDir.Unit()), fTrigCache(planeDir.Unit()) { }
63 
64  ///
65  /// Reference position on the plane
66  Point_t const& position() const { return fPlanePos; }
67 
68  ///
69  /// Reference direction orthogonal to the plane
70  Vector_t const& direction() const { return fPlaneDir; }
71 
72  //@{
73  /// Function to convert parameters from global to local coordinates. Local coordinates are on the plane with origin at planePos and orthogonal to planeDir. It is responsibility of the user to make sure the global position lies on the plane
75  SVector5 Global6DToLocal5DParameters(const SVector6& par6d, const Point_t& planePos, const Vector_t& planeDir, const TrigCache& trigCache) const;
76  //@}
77 
78  //@{
79  /// Function to convert parameters from local to global coordinates. Local coordinates are on the plane with origin at planePos and orthogonal to planeDir. trackAlongPlaneDir is as given by trackDir.Dot(planeDir)>0
80  inline SVector6 Local5DToGlobal6DParameters(const SVector5& par5d, bool trackAlongPlaneDir = true) const { return Local5DToGlobal6DParameters(par5d, fPlanePos, fPlaneDir, fTrigCache, trackAlongPlaneDir); }
81  SVector6 Local5DToGlobal6DParameters(const SVector5& par5d, const Point_t& planePos, const Vector_t& planeDir, const TrigCache& trigCache, bool trackAlongPlaneDir = true) const;
82  //@}
83 
84  //@{
85  /// Compute the jacobian to translate track covariance from local to global coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic).
86  inline SMatrix65 Local5DToGlobal6DJacobian(bool hasMomentum, const Vector_t& trackMomOrDir) const { return Local5DToGlobal6DJacobian(hasMomentum, trackMomOrDir,fPlaneDir,fTrigCache); }
87  SMatrix65 Local5DToGlobal6DJacobian(bool hasMomentum, const Vector_t& trackMomOrDir, const Vector_t& planeDir, const TrigCache& trigCache) const;
88  //@}
89 
90  //@{
91  /// Compute the jacobian to translate track covariance from global to local coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic). Warning: some information may be lost in degenerate cases, e.g. the unceratinty along z position when converting to a x-y plane (fixed z)
92  inline SMatrix56 Global6DToLocal5DJacobian(bool hasMomentum, const Vector_t& trackMomOrDir) const { return Global6DToLocal5DJacobian(hasMomentum, trackMomOrDir,fPlaneDir,fTrigCache); }
93  SMatrix56 Global6DToLocal5DJacobian(bool hasMomentum, const Vector_t& trackMomOrDir, const Vector_t& planeDir, const TrigCache& trigCache) const;
94  //@}
95 
96  /// Translate track covariance from local to global coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic).
97  inline SMatrixSym66 Local5DToGlobal6DCovariance(SMatrixSym55 cov5d, bool hasMomentum, const Vector_t& trackMomOrDir) const {
98  return Local5DToGlobal6DCovariance(cov5d, hasMomentum,trackMomOrDir,fPlaneDir);
99  }
100 
101  /// Translate track covariance from global to local coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic). Warning: some information may be lost in degenerate cases, e.g. the unceratinty along z position when converting to a x-y plane (fixed z)
102  inline SMatrixSym55 Global6DToLocal5DCovariance(SMatrixSym66 cov6d, bool hasMomentum, const Vector_t& trackMomOrDir) const {
103  return Global6DToLocal5DCovariance(cov6d,hasMomentum,trackMomOrDir,fPlaneDir);
104  }
105 
106  //@{
107  /// Calculate rotation matrices from global (x,y,z) to local (u,v,w) coordinates
109  Rotation_t Global3DToLocal3DRotation(const Vector_t& planeDir, const TrigCache& trigCache) const;
110  //@}
111 
112  //@{
113  /// Calculate rotation matrices from local (u,v,w) to global (x,y,z) coordinates
115  Rotation_t Local3DToGlobal3DRotation(const Vector_t& planeDir, const TrigCache& trigCache) const;
116  //@}
117 
118  //@{
119  /// Return cached values of trigonometric function for angles defining the plane
120  double cosAlpha() const { return fTrigCache.fCosA; }
121  double sinAlpha() const { return fTrigCache.fSinA; }
122  double cosBeta() const { return fTrigCache.fCosB; }
123  double sinBeta() const { return fTrigCache.fSinB; }
124  //@}
125 
126  /// \copydoc Plane::Global6DToLocal5DParameters
127  static SVector5 Global6DToLocal5DParameters(const SVector6& par6d, const Point_t& planePos, const Vector_t& planeDir) {
128  Plane p(planePos, planeDir); return p.Global6DToLocal5DParameters(par6d);
129  }
130  /// \copydoc Plane::Local5DToGlobal6DParameters
131  static SVector6 Local5DToGlobal6DParameters(const SVector5& par5d, const Point_t& planePos, const Vector_t& planeDir, bool trackAlongPlaneDir = true) {
132  Plane p(planePos, planeDir); return p.Local5DToGlobal6DParameters(par5d, trackAlongPlaneDir);
133  }
134  /// \copydoc Plane::Local5DToGlobal6DJacobian
135  static SMatrix65 Local5DToGlobal6DJacobian(bool hasMomentum, const Vector_t& trackMomOrDir, const Vector_t& planeDir) {
136  Plane p(Point_t(), planeDir); return p.Local5DToGlobal6DJacobian(hasMomentum, trackMomOrDir);
137  }
138  /// \copydoc Plane::Local5DToGlobal6DJacobian
139  static SMatrix65 Local5DToGlobal6DJacobian(bool hasMomentum, const SVector6& par6d, const Vector_t& planeDir) {
140  Plane p(Point_t(), planeDir); return p.Local5DToGlobal6DJacobian(hasMomentum, Vector_t(par6d[3],par6d[4],par6d[5]));
141  }
142  /// \copydoc Plane::Global6DToLocal5DJacobian
143  static SMatrix56 Global6DToLocal5DJacobian(bool hasMomentum, const Vector_t& trackMomOrDir, const Vector_t& planeDir) {
144  Plane p(Point_t(), planeDir); return p.Global6DToLocal5DJacobian(hasMomentum, trackMomOrDir);
145  }
146  /// \copydoc Plane::Global6DToLocal5DJacobian
147  static SMatrix56 Global6DToLocal5DJacobian(bool hasMomentum, const SVector6& par6d, const Vector_t& planeDir) {
148  Plane p(Point_t(), planeDir); return p.Global6DToLocal5DJacobian(hasMomentum, Vector_t(par6d[3],par6d[4],par6d[5]));
149  }
150  /// \copydoc Plane::Local5DToGlobal6DCovariance
151  static SMatrixSym66 Local5DToGlobal6DCovariance(SMatrixSym55 cov5d, bool hasMomentum, const Vector_t& trackMomOrDir, const Vector_t& planeDir) {
152  return ROOT::Math::Similarity(Local5DToGlobal6DJacobian(hasMomentum,trackMomOrDir,planeDir),cov5d);
153  }
154  /// \copydoc Plane::Global6DToLocal5DCovariance
155  static SMatrixSym55 Global6DToLocal5DCovariance(SMatrixSym66 cov6d, bool hasMomentum, const Vector_t& trackMomOrDir, const Vector_t& planeDir) {
156  return ROOT::Math::Similarity(Global6DToLocal5DJacobian(hasMomentum,trackMomOrDir,planeDir),cov6d);
157  }
158  /// \copydoc Plane::Global3DToLocal3DRotation
160  Plane p(Point_t(), planeDir); return p.Global3DToLocal3DRotation();
161  }
162  /// \copydoc Plane::Local3DToGlobal3DRotation
164  Plane p(Point_t(), planeDir); return p.Local3DToGlobal3DRotation();
165  }
166 
167  private:
168  Point_t fPlanePos; ///< Position of a point on the plane
169  Vector_t fPlaneDir; ///< Direction vector othogonal to the plane
170  TrigCache fTrigCache; ///< Cached trigonometric function values
171  };
172 
173  }
174 }
175 
176 #endif
double cosAlpha() const
Return cached values of trigonometric function for angles defining the plane.
Vector_t const & direction() const
Reference direction orthogonal to the plane.
Definition: TrackingPlane.h:70
SMatrix65 Local5DToGlobal6DJacobian(bool hasMomentum, const Vector_t &trackMomOrDir) const
Compute the jacobian to translate track covariance from local to global coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic).
Definition: TrackingPlane.h:86
Struct caching trigonometric function results.
Definition: TrackingPlane.h:41
static SMatrix65 Local5DToGlobal6DJacobian(bool hasMomentum, const SVector6 &par6d, const Vector_t &planeDir)
Compute the jacobian to translate track covariance from local to global coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic).
Reconstruction base classes.
static SVector6 Local5DToGlobal6DParameters(const SVector5 &par5d, const Point_t &planePos, const Vector_t &planeDir, bool trackAlongPlaneDir=true)
Function to convert parameters from local to global coordinates. Local coordinates are on the plane w...
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
Definition: TrackingTypes.h:85
Point_t fPlanePos
Position of a point on the plane.
Rotation_t Global3DToLocal3DRotation() const
Calculate rotation matrices from global (x,y,z) to local (u,v,w) coordinates.
static SMatrixSym55 Global6DToLocal5DCovariance(SMatrixSym66 cov6d, bool hasMomentum, const Vector_t &trackMomOrDir, const Vector_t &planeDir)
Translate track covariance from global to local coordinates. The track momentum (or direction) is nee...
SVector5 Global6DToLocal5DParameters(const SVector6 &par6d) const
Function to convert parameters from global to local coordinates. Local coordinates are on the plane w...
Definition: TrackingPlane.h:74
Plane(const Point_t &planePos, const Vector_t &planeDir)
Constructor from reference position on the plane and direction orthogonal to the plane.
Definition: TrackingPlane.h:61
double cosBeta() const
ROOT::Math::SMatrix< Double32_t, 5, 6 > SMatrix56
Definition: TrackingTypes.h:88
TrigCache fTrigCache
Cached trigonometric function values.
static SVector5 Global6DToLocal5DParameters(const SVector6 &par6d, const Point_t &planePos, const Vector_t &planeDir)
Function to convert parameters from global to local coordinates. Local coordinates are on the plane w...
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
Definition: hypot.h:60
ROOT::Math::SVector< Double32_t, 5 > SVector5
Definition: TrackingTypes.h:92
static SMatrix56 Global6DToLocal5DJacobian(bool hasMomentum, const SVector6 &par6d, const Vector_t &planeDir)
Compute the jacobian to translate track covariance from global to local coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic). Warning: some information may be lost in degenerate cases, e.g. the unceratinty along z position when converting to a x-y plane (fixed z)
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
Vector_t fPlaneDir
Direction vector othogonal to the plane.
static Rotation_t Local3DToGlobal3DRotation(const Vector_t &planeDir)
Calculate rotation matrices from local (u,v,w) to global (x,y,z) coordinates.
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...
Definition: TrackingPlane.h:97
p
Definition: test.py:223
static SMatrixSym66 Local5DToGlobal6DCovariance(SMatrixSym55 cov5d, bool hasMomentum, const Vector_t &trackMomOrDir, const Vector_t &planeDir)
Translate track covariance from local to global coordinates. The track momentum (or direction) is nee...
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
ROOT::Math::Rotation3D Rotation_t
Type for representation of space rotations.
Definition: TrackingTypes.h:38
TrigCache(const Vector_t &planeDir)
Definition: TrackingPlane.h:43
ROOT::Math::SMatrix< Double32_t, 6, 6, ROOT::Math::MatRepSym< Double32_t, 6 > > SMatrixSym66
Definition: TrackingTypes.h:86
static Rotation_t Global3DToLocal3DRotation(const Vector_t &planeDir)
Calculate rotation matrices from global (x,y,z) to local (u,v,w) coordinates.
double sinAlpha() const
SMatrixSym55 Global6DToLocal5DCovariance(SMatrixSym66 cov6d, bool hasMomentum, const Vector_t &trackMomOrDir) const
Translate track covariance from global to local coordinates. The track momentum (or direction) is nee...
ROOT::Math::SVector< Double32_t, 6 > SVector6
Definition: TrackingTypes.h:91
double sinBeta() const
static SMatrix56 Global6DToLocal5DJacobian(bool hasMomentum, const Vector_t &trackMomOrDir, const Vector_t &planeDir)
Compute the jacobian to translate track covariance from global to local coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic). Warning: some information may be lost in degenerate cases, e.g. the unceratinty along z position when converting to a x-y plane (fixed z)
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
Rotation_t Local3DToGlobal3DRotation() const
Calculate rotation matrices from local (u,v,w) to global (x,y,z) coordinates.
static SMatrix65 Local5DToGlobal6DJacobian(bool hasMomentum, const Vector_t &trackMomOrDir, const Vector_t &planeDir)
Compute the jacobian to translate track covariance from local to global coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic).
SMatrix56 Global6DToLocal5DJacobian(bool hasMomentum, const Vector_t &trackMomOrDir) const
Compute the jacobian to translate track covariance from global to local coordinates. The track momentum (or direction) is needed to compute the jacobian. Local coordinates are on the plane orthogonal to planeDir (it may be the same direction as the momentum, but the function is generic). Warning: some information may be lost in degenerate cases, e.g. the unceratinty along z position when converting to a x-y plane (fixed z)
Definition: TrackingPlane.h:92
ROOT::Math::SMatrix< Double32_t, 6, 5 > SMatrix65
Definition: TrackingTypes.h:87