TrackingPlane.cxx
Go to the documentation of this file.
1 #include "TrackingPlane.h"
2 
3 namespace recob {
4  namespace tracking {
5 
6  // formulas for 5->6 and 6->5 transformations
7  //
8  // par6d[0] = planePos.X() + par5d[0]*cosalpha;
9  // par6d[1] = planePos.Y() + par5d[0]*sinalpha*sinbeta + par5d[1]*cosbeta;
10  // par6d[2] = planePos.Z() - par5d[0]*sinalpha*cosbeta + par5d[1]*sinbeta;
11  // par6d[3] = (par5d[2]*cosalpha + 1.*sinalpha)/(par5d[4]*std::sqrt(1. + par5d[2]*par5d[2] + par5d[3]*par5d[3]));
12  // par6d[4] = (par5d[2]*sinalpha*sinbeta + par5d[3]*cosbeta - cosalpha*sinbeta)/(par5d[4]*std::sqrt(1. + par5d[2]*par5d[2] + par5d[3]*par5d[3]));
13  // par6d[5] = (-par5d[2]*sinalpha*cosbeta + par5d[3]*sinbeta + cosalpha*cosbeta)/(par5d[4]*std::sqrt(1. + par5d[2]*par5d[2] + par5d[3]*par5d[3]));
14  //
15  // par5d[0] = (par6d[0]-planePos.X())*cosalpha + (par6d[1]-planePos.Y())*sinalpha*sinbeta - (par6d[2]-planePos.Z())*sinalpha*cosbeta;
16  // par5d[1] = (par6d[1]-planePos.Y())*cosbeta + (par6d[2]-planePos.Z())*sinbeta;
17  // par5d[2] = (par6d[3]*cosalpha + par6d[4]*sinalpha*sinbeta - par6d[5]*sinalpha*cosbeta)/(par6d[3]*sinalpha - par6d[4]*cosalpha*sinbeta + par6d[5]*cosalpha*cosbeta);
18  // par5d[3] = (par6d[4]*cosbeta + par6d[5]*sinbeta)/(par6d[3]*sinalpha - par6d[4]*cosalpha*sinbeta + par6d[5]*cosalpha*cosbeta);
19  // par5d[4] = 1./sqrt(par6d[3]*par6d[3]+par6d[4]*par6d[4]+par6d[5]*par6d[5]);
20 
21  SVector6 Plane::Local5DToGlobal6DParameters(const SVector5& par5d, const Point_t& planePos,const Vector_t& /* planeDir */, const TrigCache& trigCache, bool trackAlongPlaneDir) const {
22  const double& sinalpha = trigCache.fSinA;
23  const double& cosalpha = trigCache.fCosA;
24  const double& sinbeta = trigCache.fSinB;
25  const double& cosbeta = trigCache.fCosB;
26  const double denom = (trackAlongPlaneDir ? par5d[4]*std::sqrt(1. + par5d[2]*par5d[2] + par5d[3]*par5d[3]) : -par5d[4]*std::sqrt(1. + par5d[2]*par5d[2] + par5d[3]*par5d[3]) );
27  SVector6 par6d;
28  par6d[0] = planePos.X() + par5d[0]*cosalpha;
29  par6d[1] = planePos.Y() + par5d[0]*sinalpha*sinbeta + par5d[1]*cosbeta;
30  par6d[2] = planePos.Z() - par5d[0]*sinalpha*cosbeta + par5d[1]*sinbeta;
31  par6d[3] = (par5d[2]*cosalpha + 1.*sinalpha)/denom;
32  par6d[4] = (par5d[2]*sinalpha*sinbeta + par5d[3]*cosbeta - cosalpha*sinbeta)/denom;
33  par6d[5] = (-par5d[2]*sinalpha*cosbeta + par5d[3]*sinbeta + cosalpha*cosbeta)/denom;
34  return par6d;
35  }
36 
37  SVector5 Plane::Global6DToLocal5DParameters(const SVector6& par6d, const Point_t& planePos,const Vector_t& /* planeDir */, const TrigCache& trigCache) const {
38  const double& sinalpha = trigCache.fSinA;
39  const double& cosalpha = trigCache.fCosA;
40  const double& sinbeta = trigCache.fSinB;
41  const double& cosbeta = trigCache.fCosB;
42  const double pu = par6d[3]*cosalpha + par6d[4]*sinalpha*sinbeta - par6d[5]*sinalpha*cosbeta;
43  const double pv = par6d[4]*cosbeta + par6d[5]*sinbeta;
44  const double pw = par6d[3]*sinalpha - par6d[4]*cosalpha*sinbeta + par6d[5]*cosalpha*cosbeta;
45  const double pval = sqrt(par6d[3]*par6d[3]+par6d[4]*par6d[4]+par6d[5]*par6d[5]);
46  SVector5 par5d;
47  par5d[0] = (par6d[0]-planePos.X())*cosalpha + (par6d[1]-planePos.Y())*sinalpha*sinbeta - (par6d[2]-planePos.Z())*sinalpha*cosbeta;
48  par5d[1] = (par6d[1]-planePos.Y())*cosbeta + (par6d[2]-planePos.Z())*sinbeta;
49  par5d[2] = pu/pw;
50  par5d[3] = pv/pw;
51  par5d[4] = (pval>0 ? 1./pval : 1.);
52  return par5d;
53  }
54 
55  SMatrix65 Plane::Local5DToGlobal6DJacobian(bool hasMomentum, const Vector_t& trackMomOrDir, const Vector_t& planeDir, const TrigCache& trigCache) const {
56  bool trackAlongPlaneDir = trackMomOrDir.Dot(planeDir)>0;
57  const double& sinalpha = trigCache.fSinA;
58  const double& cosalpha = trigCache.fCosA;
59  const double& sinbeta = trigCache.fSinB;
60  const double& cosbeta = trigCache.fCosB;
61  const double pu = trackMomOrDir.X()*cosalpha + trackMomOrDir.Y()*sinalpha*sinbeta - trackMomOrDir.Z()*sinalpha*cosbeta;
62  const double pv = trackMomOrDir.Y()*cosbeta + trackMomOrDir.Z()*sinbeta;
63  const double pw = trackMomOrDir.X()*sinalpha - trackMomOrDir.Y()*cosalpha*sinbeta + trackMomOrDir.Z()*cosalpha*cosbeta;
64  //local parameters 2,3,4
65  const double l2 = pu/pw;
66  const double l3 = pv/pw;
67  const double p2 = trackMomOrDir.X()*trackMomOrDir.X() + trackMomOrDir.Y()*trackMomOrDir.Y() + trackMomOrDir.Z()*trackMomOrDir.Z();
68  const double l4 = (hasMomentum ? 1./sqrt(p2) : 1.);
69  const double den23 = ( trackAlongPlaneDir ? l4*(l2*l2+l3*l3+1.)*sqrt(l2*l2+l3*l3+1.) : -l4*(l2*l2+l3*l3+1.)*sqrt(l2*l2+l3*l3+1.) );
70  const double den4 = l4*l4*sqrt(l2*l2+l3*l3+1.);
71  SMatrix65 j;
72  //
73  j(0,0) = cosalpha;
74  j(0,1) = 0.;
75  j(0,2) = 0.;
76  j(0,3) = 0.;
77  j(0,4) = 0.;
78  //
79  j(1,0) = sinalpha*sinbeta;
80  j(1,1) = cosbeta;
81  j(1,2) = 0.;
82  j(1,3) = 0.;
83  j(1,4) = 0.;
84  //
85  j(2,0) = -sinalpha*cosbeta;
86  j(2,1) = sinbeta;
87  j(2,2) = 0.;
88  j(2,3) = 0.;
89  j(2,4) = 0.;
90  //
91  j(3,0) = 0.;
92  j(3,1) = 0.;
93  j(3,2) = (cosalpha*(l3*l3+1.) - sinalpha*l2)/den23;
94  j(3,3) = -l3*(l2*cosalpha + sinalpha)/den23;
95  j(3,4) = (hasMomentum ? -(l2*cosalpha + sinalpha)/den4 : 0.);
96  //
97  j(4,0) = 0.;
98  j(4,1) = 0.;
99  j(4,2) = (cosalpha*sinbeta*l2 - cosbeta*l2*l3 + sinalpha*sinbeta*(l3*l3+1.))/den23;
100  j(4,3) = (sinbeta*l3*(cosalpha-sinalpha*l2) + cosbeta*(l2*l2+1.))/den23;
101  j(4,4) = (hasMomentum ? (cosalpha*sinbeta - cosbeta*l3 - sinalpha*sinbeta*l2)/den4 : 0.);
102  //
103  j(5,0) = 0.;
104  j(5,1) = 0.;
105  j(5,2) = -(cosalpha*cosbeta*l2 + cosbeta*sinalpha*l3*l3 + cosbeta*sinalpha + sinbeta*l2*l3)/den23;
106  j(5,3) = (-cosalpha*cosbeta*l3 + cosbeta*sinalpha*l2*l3 + sinbeta*l2*l2 + sinbeta)/den23;
107  j(5,4) = (hasMomentum ? (-cosalpha*cosbeta + cosbeta*sinalpha*l2 - sinbeta*l3)/den4 : 0.);
108  //
109  return j;
110  }
111 
112  SMatrix56 Plane::Global6DToLocal5DJacobian(bool hasMomentum, const Vector_t& trackMomOrDir, const Vector_t& /* planeDir */, const TrigCache& trigCache) const {
113  const double& sinalpha = trigCache.fSinA;
114  const double& cosalpha = trigCache.fCosA;
115  const double& sinbeta = trigCache.fSinB;
116  const double& cosbeta = trigCache.fCosB;
117  const double den23 = (cosalpha*(cosbeta*trackMomOrDir.Z() - sinbeta*trackMomOrDir.Y()) + sinalpha*trackMomOrDir.X())*(cosalpha*(cosbeta*trackMomOrDir.Z() - sinbeta*trackMomOrDir.Y()) + sinalpha*trackMomOrDir.X());
118  const double den4 = sqrt(trackMomOrDir.X()*trackMomOrDir.X()+trackMomOrDir.Y()*trackMomOrDir.Y()+trackMomOrDir.Z()*trackMomOrDir.Z())*(trackMomOrDir.X()*trackMomOrDir.X()+trackMomOrDir.Y()*trackMomOrDir.Y()+trackMomOrDir.Z()*trackMomOrDir.Z());
119  SMatrix56 j;
120  //
121  j(0,0) = cosalpha;
122  j(0,1) = sinalpha*sinbeta ;
123  j(0,2) = -sinalpha*cosbeta;
124  j(0,3) = 0.;
125  j(0,4) = 0.;
126  j(0,5) = 0.;
127  //
128  j(1,0) = 0.;
129  j(1,1) = cosbeta;
130  j(1,2) = sinbeta;
131  j(1,3) = 0.;
132  j(1,4) = 0.;
133  j(1,5) = 0.;
134  //
135  j(2,0) = 0.;
136  j(2,1) = 0.;
137  j(2,2) = 0.;
138  j(2,3) = ((cosalpha*cosalpha + sinalpha*sinalpha)*(cosbeta*trackMomOrDir.Z() - sinbeta*trackMomOrDir.Y()))/den23;
139  j(2,4) = (sinbeta*trackMomOrDir.X()*(cosalpha*cosalpha + sinalpha*sinalpha))/den23;
140  j(2,5) = -(cosbeta*trackMomOrDir.X()*(cosalpha*cosalpha + sinalpha*sinalpha))/den23;
141  //
142  j(3,0) = 0.;
143  j(3,1) = 0.;
144  j(3,2) = 0.;
145  j(3,3) = -(sinalpha*(cosbeta*trackMomOrDir.Y() + sinbeta*trackMomOrDir.Z()))/den23;
146  j(3,4) = (cosalpha*trackMomOrDir.Z()*(cosbeta*cosbeta + sinbeta*sinbeta) + cosbeta*sinalpha*trackMomOrDir.X())/den23;
147  j(3,5) = (-cosalpha*cosbeta*cosbeta*trackMomOrDir.Y() - cosalpha*sinbeta*sinbeta*trackMomOrDir.Y() + sinalpha*sinbeta*trackMomOrDir.X())/den23;
148  //
149  j(4,0) = 0.;
150  j(4,1) = 0.;
151  j(4,2) = 0.;
152  j(4,3) = (hasMomentum ? -trackMomOrDir.X()/den4 : 0.);
153  j(4,4) = (hasMomentum ? -trackMomOrDir.Y()/den4 : 0.);
154  j(4,5) = (hasMomentum ? -trackMomOrDir.Z()/den4 : 0.);
155  //
156  return j;
157  }
158 
159  Rotation_t Plane::Global3DToLocal3DRotation(const Vector_t& /* planeDir */, const TrigCache& trigCache) const {
160  const double& sinalpha = trigCache.fSinA;
161  const double& cosalpha = trigCache.fCosA;
162  const double& sinbeta = trigCache.fSinB;
163  const double& cosbeta = trigCache.fCosB;
164  return {
165  cosalpha /* xx */, sinalpha * sinbeta /* xy */, -sinalpha * cosbeta /* xz */,
166  0.0 /* yx */, cosbeta /* yy */, sinbeta /* yz */,
167  sinalpha /* zx */, -cosalpha * sinbeta /* zy */, cosalpha * cosbeta /* zz */
168  };
169  }
170 
171  Rotation_t Plane::Local3DToGlobal3DRotation(const Vector_t& /* planeDir */, const TrigCache& trigCache) const {
172  const double& sinalpha = trigCache.fSinA;
173  const double& cosalpha = trigCache.fCosA;
174  const double& sinbeta = trigCache.fSinB;
175  const double& cosbeta = trigCache.fCosB;
176  return {
177  cosalpha /* xx */, 0. /* xy */, sinalpha /* xz */,
178  sinalpha * sinbeta /* yx */, cosbeta /* yy */, -cosalpha * sinbeta /* yz */,
179  -sinalpha * cosbeta /* zx */, sinbeta /* zy */, cosalpha * cosbeta /* zz */
180  };
181  }
182 
183  }
184 }
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
Reconstruction base classes.
Rotation_t Global3DToLocal3DRotation() const
Calculate rotation matrices from global (x,y,z) to local (u,v,w) coordinates.
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
ROOT::Math::SMatrix< Double32_t, 5, 6 > SMatrix56
Definition: TrackingTypes.h:88
ROOT::Math::SVector< Double32_t, 5 > SVector5
Definition: TrackingTypes.h:92
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
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
ROOT::Math::Rotation3D Rotation_t
Type for representation of space rotations.
Definition: TrackingTypes.h:38
pval
Definition: tracks.py:168
ROOT::Math::SVector< Double32_t, 6 > SVector6
Definition: TrackingTypes.h:91
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.
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