CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PerigeeConversions.cc
Go to the documentation of this file.
4 #include <cmath>
5 
7  (const FTS& originalFTS, const GlobalPoint& referencePoint, double & pt) const
8 
9 {
10  GlobalVector impactDistance = originalFTS.position() - referencePoint;
11 
12  pt = originalFTS.momentum().perp();
13  if (pt==0.) throw cms::Exception("PerigeeConversions", "Track with pt=0");
14 
15  double theta = originalFTS.momentum().theta();
16  double phi = originalFTS.momentum().phi();
17  double field = originalFTS.parameters().magneticField().inInverseGeV(originalFTS.position()).z();
18 // if (field==0.) throw cms::Exception("PerigeeConversions", "Field is 0") << " at " << originalFTS.position() << "\n" ;
19 
20  double positiveMomentumPhi = ( (phi>0) ? phi : (2*M_PI+phi) );
21  double positionPhi = impactDistance.phi();
22  double positivePositionPhi =
23  ( (positionPhi>0) ? positionPhi : (2*M_PI+positionPhi) );
24  double phiDiff = positiveMomentumPhi - positivePositionPhi;
25  if (phiDiff<0.0) phiDiff+= (2*M_PI);
26  double signEpsilon = ( (phiDiff > M_PI) ? -1.0 : 1.0);
27 
28  double epsilon = signEpsilon *
29  sqrt ( impactDistance.x()*impactDistance.x() +
30  impactDistance.y()*impactDistance.y() );
31 
32  // The track parameters:
33  AlgebraicVector5 theTrackParameters;
34 
35  double signTC = - originalFTS.charge();
36  bool isCharged = (signTC!=0) && (fabs(field)>1.e-10);
37  if (isCharged) {
38  theTrackParameters[0] = field / pt*signTC;
39  } else {
40  theTrackParameters[0] = 1 / pt;
41  }
42  theTrackParameters[1] = theta;
43  theTrackParameters[2] = phi;
44  theTrackParameters[3] = epsilon;
45  theTrackParameters[4] = impactDistance.z();
46  return PerigeeTrajectoryParameters(theTrackParameters, isCharged);
47 }
48 
49 // PerigeeTrajectoryParameters PerigeeConversions::helixToPerigeeParameters
50 // (const reco::helix::Parameters & helixPar, const GlobalPoint& referencePoint) const
51 // {
52 // AlgebraicVector theTrackParameters = AlgebraicVector(5);
53 // double field = TrackingTools::FakeField::Field::inTesla(helixPar.vertex()).z() * 2.99792458e-3;
54 // theTrackParameters[0] = - field*helixPar.omega();
55 // theTrackParameters[1] = atan(1/helixPar.tanDip());
56 // theTrackParameters[2] = helixPar.phi0() - M_PI/2;
57 // theTrackParameters[3] = helixPar.d0();
58 // theTrackParameters[4] = helixPar.dz();
59 // return PerigeeTrajectoryParameters(theTrackParameters, helixPar.pt(), true);
60 // }
61 
63  (const FTS& originalFTS) const
64 {
65  AlgebraicSymMatrix55 errorMatrix = originalFTS.curvilinearError().matrix();
66  AlgebraicMatrix55 curv2perigee = jacobianCurvilinear2Perigee(originalFTS);
67  return PerigeeTrajectoryError(ROOT::Math::Similarity(curv2perigee,errorMatrix));
68 }
69 
70 // PerigeeTrajectoryError PerigeeConversions::helixToPerigeeError
71 // (const reco::helix::Parameters & helixPar,
72 // const reco::helix::Covariance & helixCov) const
73 // {
74 // //FIXME: verify that the order of the parameters are correct
75 // AlgebraicSymMatrix55 helixCovMatrix;
76 // helixCovMatrix(0,0) = helixCov(reco::helix::i_d0,reco::helix::i_d0);
77 // helixCovMatrix(1,1) = helixCov(reco::helix::i_phi0,reco::helix::i_phi0);
78 // helixCovMatrix(2,2) = helixCov(reco::helix::i_omega,reco::helix::i_omega);
79 // helixCovMatrix(3,3) = helixCov(reco::helix::i_dz,reco::helix::i_dz);
80 // helixCovMatrix(4,4) = helixCov(reco::helix::i_tanDip,reco::helix::i_tanDip);
81 //
82 // helixCovMatrix(0,1) = helixCov(reco::helix::i_d0,reco::helix::i_phi0);
83 // helixCovMatrix(0,2) = helixCov(reco::helix::i_d0,reco::helix::i_omega);
84 // helixCovMatrix(0,3) = helixCov(reco::helix::i_d0,reco::helix::i_dz);
85 // helixCovMatrix(0,4) = helixCov(reco::helix::i_d0,reco::helix::i_tanDip);
86 //
87 // helixCovMatrix(1,2) = helixCov(reco::helix::i_phi0,reco::helix::i_omega);
88 // helixCovMatrix(1,3) = helixCov(reco::helix::i_phi0,reco::helix::i_dz);
89 // helixCovMatrix(1,4) = helixCov(reco::helix::i_phi0,reco::helix::i_tanDip);
90 //
91 // helixCovMatrix(2,3) = helixCov(reco::helix::i_omega,reco::helix::i_dz);
92 // helixCovMatrix(2,4) = helixCov(reco::helix::i_omega,reco::helix::i_tanDip);
93 //
94 // helixCovMatrix(3,4) = helixCov(reco::helix::i_dz,reco::helix::i_tanDip);
95 //
96 // AlgebraicMatrix helix2perigee = jacobianHelix2Perigee(helixPar, helixCov);
97 // return PerigeeTrajectoryError(helixCovMatrix.similarity(helix2perigee));
98 // }
99 
100 
102  (const PerigeeTrajectoryError& perigeeError, const GlobalTrajectoryParameters& gtp) const
103 {
104  AlgebraicMatrix55 perigee2curv = jacobianPerigee2Curvilinear(gtp);
105  return CurvilinearTrajectoryError(ROOT::Math::Similarity(perigee2curv, perigeeError.covarianceMatrix()));
106 }
107 
109  (const PerigeeTrajectoryParameters& parameters, const GlobalPoint& referencePoint) const
110 {
111  AlgebraicVector5 theVector = parameters.vector();
112  return GlobalPoint(theVector[3]*sin(theVector[2])+referencePoint.x(),
113  -theVector[3]*cos(theVector[2])+referencePoint.y(),
114  theVector[4]+referencePoint.z());
115 }
116 
117 
119  (const PerigeeTrajectoryParameters& parameters, double pt, const GlobalPoint& referencePoint) const
120 {
121  return GlobalVector(cos(parameters.phi()) * pt,
122  sin(parameters.phi()) * pt,
123  pt / tan(parameters.theta()));
124 }
125 
127  (const AlgebraicVector& momentum, const TrackCharge& charge,
128  const GlobalPoint& referencePoint, const MagneticField* field) const {
129  return momentumFromPerigee(asSVector<3>(momentum), charge, referencePoint, field);
130  }
131 
133  (const AlgebraicVector3& momentum, const TrackCharge& charge,
134  const GlobalPoint& referencePoint, const MagneticField* field) const
135 {
136  double pt;
137  if (momentum[0]==0.) throw cms::Exception("PerigeeConversions", "Track with rho=0");
138 
139  double bz = fabs(field->inInverseGeV(referencePoint).z());
140  if ( charge!=0 && bz>1.e-10 ) {
141  pt = std::abs(bz/momentum[0]);
142  if (pt<1.e-10) throw cms::Exception("PerigeeConversions", "pt is 0");
143  } else {
144  pt = 1 / momentum[0];
145  }
146 
147  return GlobalVector(cos(momentum[2]) * pt,
148  sin(momentum[2]) * pt,
149  pt/tan(momentum[1]));
150 }
151 
153  (const PerigeeTrajectoryParameters& parameters) const
154 {
155  return parameters.charge();
156 }
157 
159  (const AlgebraicVector& momentum, const GlobalPoint& referencePoint,
160  const TrackCharge& charge, const AlgebraicMatrix& theCovarianceMatrix,
161  const MagneticField* field) const {
162  AlgebraicSymMatrix sym; sym.assign(theCovarianceMatrix); // below, this was used for Matrix => SymMatrix
163  return trajectoryStateClosestToPoint(asSVector<3>(momentum), referencePoint,
164  charge, asSMatrix<6>(sym), field);
165 
166  }
167 
168 
170  (const AlgebraicVector3& momentum, const GlobalPoint& referencePoint,
171  const TrackCharge& charge, const AlgebraicSymMatrix66& theCovarianceMatrix,
172  const MagneticField* field) const
173 {
174  AlgebraicMatrix66 param2cart = jacobianParameters2Cartesian
175  (momentum, referencePoint, charge, field);
176  CartesianTrajectoryError cartesianTrajErr(ROOT::Math::Similarity(param2cart, theCovarianceMatrix));
177 
178  FTS theFTS(GlobalTrajectoryParameters(referencePoint,
179  momentumFromPerigee(momentum, charge, referencePoint, field), charge,
180  field), cartesianTrajErr);
181 
182  return TrajectoryStateClosestToPoint(theFTS, referencePoint);
183 }
184 
187  const AlgebraicVector& momentum, const GlobalPoint& position,
188  const TrackCharge& charge, const MagneticField* field) const {
189  return asHepMatrix(jacobianParameters2Cartesian(asSVector<3>(momentum), position, charge, field));
190 }
191 
194  const AlgebraicVector3& momentum, const GlobalPoint& position,
195  const TrackCharge& charge, const MagneticField* field) const
196 {
197  if (momentum[0]==0.) throw cms::Exception("PerigeeConversions", "Track with rho=0");
198  double factor = 1.;
199  double bField = field->inInverseGeV(position).z();
200  if (charge!=0 && fabs(bField)>1.e-10) {
201 // if (bField==0.) throw cms::Exception("PerigeeConversions", "Field is 0");
202  factor = -bField*charge;
203  }
204  AlgebraicMatrix66 frameTransJ;
205  frameTransJ(0,0) = 1;
206  frameTransJ(1,1) = 1;
207  frameTransJ(2,2) = 1;
208  frameTransJ(3,3) = - factor * cos(momentum[2]) / (momentum[0]*momentum[0]);
209  frameTransJ(4,3) = - factor * sin(momentum[2]) / (momentum[0]*momentum[0]);
210  frameTransJ(5,3) = - factor / tan(momentum[1]) / (momentum[0]*momentum[0]);
211 
212  frameTransJ(3,5) = - factor * sin(momentum[2]) / (momentum[0]);
213  frameTransJ(4,5) = factor * cos(momentum[2]) / (momentum[0]);
214  frameTransJ(5,4) = - factor / (momentum[0]*sin(momentum[1])*sin(momentum[1]));
215 
216  return frameTransJ;
217 }
218 
222 }
223 
224 
227 
228  GlobalVector p = fts.momentum();
229 
230  GlobalVector Z = GlobalVector(0.,0.,1.);
231  GlobalVector T = p.unit();
232  GlobalVector U = Z.cross(T).unit();;
233  GlobalVector V = T.cross(U);
234 
235  GlobalVector I = GlobalVector(-p.x(), -p.y(), 0.); //opposite to track dir.
236  I = I.unit();
237  GlobalVector J(-I.y(), I.x(),0.); //counterclockwise rotation
238  GlobalVector K(Z);
239  GlobalPoint x = fts.position();
241  GlobalVector H = B.unit();
242  GlobalVector HxT = H.cross(T);
243  GlobalVector N = HxT.unit();
244  double alpha = HxT.mag();
245  double qbp = fts.signedInverseMomentum();
246  double Q = -B.mag() * qbp;
247  double alphaQ = alpha * Q;
248 
249  double lambda = 0.5 * M_PI - p.theta();
250  double coslambda = cos(lambda), tanlambda = tan(lambda);
251 
252  double TI = T.dot(I);
253  double NU = N.dot(U);
254  double NV = N.dot(V);
255  double UI = U.dot(I);
256  double VI = V.dot(I);
257  double UJ = U.dot(J);
258  double VJ = V.dot(J);
259  double UK = U.dot(K);
260  double VK = V.dot(K);
261 
262  AlgebraicMatrix55 jac;
263 
264  if( fabs(fts.transverseCurvature())<1.e-10 ) {
265  jac(0,0) = 1/coslambda;
266  jac(0,1) = tanlambda/coslambda/fts.parameters().momentum().mag();
267  }else{
268  double Bz = B.z();
269  jac(0,0) = -Bz/coslambda;
270  jac(0,1) = -Bz * tanlambda/coslambda*qbp;
271  jac(1,3) = alphaQ * NV * UI/TI;
272  jac(1,4) = alphaQ * NV * VI/TI;
273  jac(0,3) = -jac(0,1) * jac(1,3);
274  jac(0,4) = -jac(0,1) * jac(1,4);
275  jac(2,3) = -alphaQ/coslambda * NU * UI/TI;
276  jac(2,4) = -alphaQ/coslambda * NU * VI/TI;
277  }
278  jac(1,1) = -1.;
279  jac(2,2) = 1.;
280  jac(3,3) = VK/TI;
281  jac(3,4) = -UK/TI;
282  jac(4,3) = -VJ/TI;
283  jac(4,4) = UJ/TI;
284 
285  return jac;
286 
287 }
288 
289 
293 }
294 
297 
298  GlobalVector p = gtp.momentum();
299 
300  GlobalVector Z = GlobalVector(0.,0.,1.);
301  GlobalVector T = p.unit();
302  GlobalVector U = Z.cross(T).unit();;
303  GlobalVector V = T.cross(U);
304 
305  GlobalVector I = GlobalVector(-p.x(), -p.y(), 0.); //opposite to track dir.
306  I = I.unit();
307  GlobalVector J(-I.y(), I.x(),0.); //counterclockwise rotation
308  GlobalVector K(Z);
309  GlobalPoint x = gtp.position();
311  GlobalVector H = B.unit();
312  GlobalVector HxT = H.cross(T);
313  GlobalVector N = HxT.unit();
314  double alpha = HxT.mag();
315  double qbp = gtp.signedInverseMomentum();
316  double Q = -B.mag() * qbp;
317  double alphaQ = alpha * Q;
318 
319  double lambda = 0.5 * M_PI - p.theta();
320  double coslambda = cos(lambda), sinlambda = sin(lambda);
321  double mqbpt = -1./coslambda * qbp;
322 
323  double TJ = T.dot(J);
324  double TK = T.dot(K);
325  double NU = N.dot(U);
326  double NV = N.dot(V);
327  double UJ = U.dot(J);
328  double VJ = V.dot(J);
329  double UK = U.dot(K);
330  double VK = V.dot(K);
331 
332  AlgebraicMatrix55 jac;
333 
334  if( fabs(gtp.transverseCurvature())<1.e-10 ) {
335  jac(0,0) = coslambda;
336  jac(0,1) = sinlambda/coslambda/gtp.momentum().mag();
337  }else{
338  jac(0,0) = -coslambda/B.z();
339  jac(0,1) = -sinlambda * mqbpt;
340  jac(1,3) = -alphaQ * NV * TJ;
341  jac(1,4) = -alphaQ * NV * TK;
342  jac(2,3) = -alphaQ/coslambda * NU * TJ;
343  jac(2,4) = -alphaQ/coslambda * NU * TK;
344  }
345  jac(1,1) = -1.;
346  jac(2,2) = 1.;
347  jac(3,3) = UJ;
348  jac(3,4) = UK;
349  jac(4,3) = VJ;
350  jac(4,4) = VK;
351 
352  return jac;
353 }
354 
355 // AlgebraicMatrix
356 // PerigeeConversions::jacobianHelix2Perigee(const reco::helix::Parameters & helixPar,
357 // const reco::helix::Covariance & helixCov) const
358 // {
359 // AlgebraicMatrix55 jac;
360 //
361 // jac(3,0) = 1.;
362 // jac(2,1) = 1.;
363 // // jac(0,2) = - 1. / magField.inTesla(helixPar.vertex()).z() * 2.99792458e-3;
364 // jac(0,2) = - 1. / (TrackingTools::FakeField::Field::inTesla(helixPar.vertex()).z() * 2.99792458e-3);
365 // jac(4,3) = 1.;
366 // jac(1,4) = -(1. + helixPar.tanDip()*helixPar.tanDip());
367 // std::std::cout << jac;
368 // return jac;
369 // }
const double Z[kNumberCalorimeter]
const AlgebraicVector5 & vector() const
float alpha
Definition: AMPTWrapper.h:95
CLHEP::HepMatrix asHepMatrix(const ROOT::Math::SMatrix< double, N1, N2, typename ROOT::Math::MatRepStd< double, N1, N2 > > &rm)
Definition: Migration.h:49
T perp() const
Definition: PV3DBase.h:66
const GlobalTrajectoryParameters & parameters() const
TrackCharge chargeFromPerigee(const PerigeeTrajectoryParameters &perigee) const
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepStd< double, 6, 6 > > AlgebraicMatrix66
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
PerigeeTrajectoryParameters ftsToPerigeeParameters(const FTS &originalFTS, const GlobalPoint &referencePoint, double &pt) const
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:57
#define abs(x)
Definition: mlp_lapack.h:159
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
Geom::Theta< T > theta() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
TrackCharge charge() const
CurvilinearTrajectoryError curvilinearError(const PerigeeTrajectoryError &perigeeError, const GlobalTrajectoryParameters &gtp) const
double charge(const std::vector< uint8_t > &Ampls)
const CurvilinearTrajectoryError & curvilinearError() const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
TrajectoryStateClosestToPoint trajectoryStateClosestToPoint(const AlgebraicVector &momentum, const GlobalPoint &referencePoint, const TrackCharge &charge, const AlgebraicMatrix &theCovarianceMatrix, const MagneticField *field) const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:69
int TrackCharge
Definition: TrackCharge.h:4
virtual GlobalVector inInverseGeV(const GlobalPoint &gp) const
Field value ad specified global point, in 1/Gev.
T mag() const
Definition: PV3DBase.h:61
AlgebraicMatrix66 jacobianParameters2Cartesian(const AlgebraicVector3 &momentum, const GlobalPoint &position, const TrackCharge &charge, const MagneticField *field) const
Definition: DDAxes.h:10
CLHEP::HepMatrix AlgebraicMatrix
T sqrt(T t)
Definition: SSEVec.h:28
GlobalVector momentumFromPerigee(const AlgebraicVector &momentum, const TrackCharge &charge, const GlobalPoint &referencePoint, const MagneticField *field) const
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:119
T z() const
Definition: PV3DBase.h:58
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
GlobalPoint positionFromPerigee(const PerigeeTrajectoryParameters &parameters, const GlobalPoint &referencePoint) const
ROOT::Math::SVector< double, 3 > AlgebraicVector3
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
const std::complex< double > I
Definition: I.h:8
AlgebraicMatrix55 jacobianPerigee2Curvilinear(const GlobalTrajectoryParameters &gtp) const
AlgebraicMatrix55 jacobianCurvilinear2Perigee(const FreeTrajectoryState &fts) const
GlobalVector momentum() const
const AlgebraicSymMatrix55 & covarianceMatrix() const
Vector3DBase unit() const
Definition: Vector3DBase.h:57
GlobalPoint position() const
CLHEP::HepVector AlgebraicVector
#define M_PI
Definition: BFit3D.cc:3
ROOT::Math::SVector< double, 5 > AlgebraicVector5
AlgebraicMatrix jacobianPerigee2Curvilinear_old(const GlobalTrajectoryParameters &gtp) const
double transverseCurvature() const
AlgebraicMatrix jacobianParameters2Cartesian_old(const AlgebraicVector &momentum, const GlobalPoint &position, const TrackCharge &charge, const MagneticField *field) const
const AlgebraicSymMatrix55 & matrix() const
CLHEP::HepSymMatrix AlgebraicSymMatrix
PerigeeTrajectoryError ftsToPerigeeError(const FTS &originalFTS) const
const MagneticField & magneticField() const
const double epsilon
T x() const
Definition: PV3DBase.h:56
double signedInverseMomentum() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
AlgebraicMatrix jacobianCurvilinear2Perigee_old(const FreeTrajectoryState &fts) const
Global3DVector GlobalVector
Definition: GlobalVector.h:10
Definition: DDAxes.h:10