CMS 3D CMS Logo

ParticleKinematicLinearizedTrackState.cc
Go to the documentation of this file.
4 
8  return theConstantTerm;
9 }
10 
12  if (!jacobiansAvailable)
14  return thePositionJacobian;
15 }
16 
18  if (!jacobiansAvailable)
20  return theMomentumJacobian;
21 }
22 
24  if (!jacobiansAvailable)
26  return theExpandedParams;
27 }
28 
30  if (!jacobiansAvailable)
33 }
34 
36  if (!jacobiansAvailable)
38  int i = 0;
40  error = i;
41  return z;
42  // return thePredState.perigeeError().weightMatrix(error);
43 }
44 
46  if (!jacobiansAvailable)
49 }
50 
51 // ImpactPointMeasurement ParticleKinematicLinearizedTrackState::impactPointMeasurement() const
52 // { throw VertexException(" ParticleKinematicLinearizedTrackState::impact point measurement is not implemented for kinematic classes!");}
53 
54 TrackCharge ParticleKinematicLinearizedTrackState::charge() const { return part->initialState().particleCharge(); }
55 
57 
60  dynamic_cast<const ParticleKinematicLinearizedTrackState*>(&other);
61  if (otherP == nullptr) {
62  throw VertexException(
63  " ParticleKinematicLinearizedTrackState:: don't know how to compare myself to non-kinematic track state");
64  }
65  return (*(otherP->particle()) == *part);
66 }
67 
69  if (!jacobiansAvailable)
71  return thePredState.isValid();
72 }
73 
74 // here we make a and b matrices of
75 // our measurement function expansion.
76 // marices will be almost the same as for
77 // classical perigee, but bigger:
78 // (6x3) and (6x4) respectivelly.
80  GlobalPoint paramPt(theLinPoint);
81  thePredState = builder(part->currentState(), paramPt);
82  // bool valid = thePredState.isValid();
83  // if (!valid) std::cout <<"Help!!!!!!!!! State is invalid\n";
84  // if (!valid) return;
85  if (std::abs(theCharge) < 1e-5) {
86  //neutral track
88  } else {
89  //charged track
91  }
92  jacobiansAvailable = true;
93 }
94 
98  return new ParticleKinematicLinearizedTrackState(newLP, pr);
99 }
100 
103  const AlgebraicVector4& vectorParameters,
104  const AlgebraicSymMatrix77& covarianceMatrix) const {
106  KinematicState lst = conversions.kinematicState(
107  vectorParameters, vertexPosition, charge(), covarianceMatrix, part->currentState().magneticField());
109  RefCountedRefittedTrackState(new KinematicRefittedTrackState(lst, vectorParameters));
110  return rst;
111 }
112 
114  if (!jacobiansAvailable)
121  return res;
122 }
123 
125  int error;
126  if (!jacobiansAvailable)
130  res.Place_at(m3, 0, 0);
135  return res;
136 }
137 
139 
140 std::vector<ReferenceCountingPointer<LinearizedTrackState<6> > > ParticleKinematicLinearizedTrackState::components()
141  const {
142  std::vector<ReferenceCountingPointer<LinearizedTrackState<6> > > res;
143  res.reserve(1);
144  res.push_back(RefCountedLinearizedTrackState(const_cast<ParticleKinematicLinearizedTrackState*>(this)));
145  return res;
146 }
147 
149  const RefCountedRefittedTrackState& theRefittedState) const {
150  AlgebraicVectorM momentum = theRefittedState->momentumVector();
151  if ((momentum(2) * predictedStateMomentumParameters()(2) < 0) && (std::fabs(momentum(2)) > M_PI / 2)) {
152  if (predictedStateMomentumParameters()(2) < 0.)
153  momentum(2) -= 2 * M_PI;
154  if (predictedStateMomentumParameters()(2) > 0.)
155  momentum(2) += 2 * M_PI;
156  }
157 
158  AlgebraicVector3 vertexPosition;
159  vertexPosition(0) = theRefittedState->position().x();
160  vertexPosition(1) = theRefittedState->position().y();
161  vertexPosition(2) = theRefittedState->position().z();
162  AlgebraicVector6 param = constantTerm() + positionJacobian() * vertexPosition + momentumJacobian() * momentum;
163 
164  if (param(2) > M_PI)
165  param(2) -= 2 * M_PI;
166  if (param(2) < -M_PI)
167  param(2) += 2 * M_PI;
168 
169  return param;
170 }
171 
173  if (parameters(2) > M_PI)
174  parameters(2) -= 2 * M_PI;
175  if (parameters(2) < -M_PI)
176  parameters(2) += 2 * M_PI;
177 }
178 
180  GlobalPoint paramPt(theLinPoint);
181 
182  double field = part->currentState().magneticField()->inInverseGeV(thePredState.theState().globalPosition()).z();
183  double signTC = -part->currentState().particleCharge();
184 
185  double thetaAtEP = thePredState.theState().globalMomentum().theta();
186  double phiAtEP = thePredState.theState().globalMomentum().phi();
187  double ptAtEP = thePredState.theState().globalMomentum().perp();
188  double transverseCurvatureAtEP = field / ptAtEP * signTC;
189 
190  // Fix calculation for case where magnetic field swaps sign between previous state and current state
191  if (field * part->currentState().magneticField()->inInverseGeV(part->currentState().globalPosition()).z() < 0.) {
192  signTC = -signTC;
193  }
194 
195  double x_v = thePredState.theState().globalPosition().x();
196  double y_v = thePredState.theState().globalPosition().y();
197  double z_v = thePredState.theState().globalPosition().z();
198  double X = x_v - paramPt.x() - sin(phiAtEP) / transverseCurvatureAtEP;
199  double Y = y_v - paramPt.y() + cos(phiAtEP) / transverseCurvatureAtEP;
200  double SS = X * X + Y * Y;
201  double S = sqrt(SS);
202 
203  // The track parameters at the expansion point
204  theExpandedParams[0] = transverseCurvatureAtEP;
205  theExpandedParams[1] = thetaAtEP;
206  theExpandedParams[3] = 1 / transverseCurvatureAtEP - signTC * S;
207 
208  theExpandedParams[5] = part->currentState().mass();
209 
210  double phiFEP;
211  if (std::abs(X) > std::abs(Y)) {
212  double signX = (X > 0.0 ? +1.0 : -1.0);
213  phiFEP = -signTC * signX * acos(signTC * Y / S);
214  } else {
215  phiFEP = asin(-signTC * X / S);
216  if ((signTC * Y) < 0.0)
217  phiFEP = M_PI - phiFEP;
218  }
219  if (phiFEP > M_PI)
220  phiFEP -= 2 * M_PI;
221  theExpandedParams[2] = phiFEP;
222  theExpandedParams[4] =
223  z_v - paramPt.z() - (phiAtEP - theExpandedParams[2]) / tan(thetaAtEP) / transverseCurvatureAtEP;
224 
225  thePositionJacobian(2, 0) = -Y / (SS);
226  thePositionJacobian(2, 1) = X / (SS);
227  thePositionJacobian(3, 0) = -signTC * X / S;
228  thePositionJacobian(3, 1) = -signTC * Y / S;
229  thePositionJacobian(4, 0) = thePositionJacobian(2, 0) / tan(thetaAtEP) / transverseCurvatureAtEP;
230  thePositionJacobian(4, 1) = thePositionJacobian(2, 1) / tan(thetaAtEP) / transverseCurvatureAtEP;
231  thePositionJacobian(4, 2) = 1;
232 
233  //debug code - to be removed later
234  // cout<<"parameters for momentum jacobian: X "<<X<<endl;
235  // cout<<"parameters for momentum jacobian: Y "<<Y<<endl;
236  // cout<<"parameters for momentum jacobian: SS "<<SS<<endl;
237  // cout<<"parameters for momentum jacobian: PhiAtEP "<<phiAtEP<<endl;
238  // cout<<"parameters for momentum jacobian: curv "<<transverseCurvatureAtEP<<endl;
239  // cout<<"sin phi Atep "<<sin(phiAtEP)<<endl;
240  // cout<<"cos phi at EP "<<cos(phiAtEP)<<endl;
241  // cout<<"upper part is "<<X*cos(phiAtEP) + Y*sin(phiAtEP) <<endl;
242  // cout<<"lower part is"<<SS*transverseCurvatureAtEP*transverseCurvatureAtEP<<endl;
243 
244  theMomentumJacobian(0, 0) = 1;
245  theMomentumJacobian(1, 1) = 1;
246 
247  theMomentumJacobian(2, 0) =
248  -(X * cos(phiAtEP) + Y * sin(phiAtEP)) / (SS * transverseCurvatureAtEP * transverseCurvatureAtEP);
249 
250  theMomentumJacobian(2, 2) = (Y * cos(phiAtEP) - X * sin(phiAtEP)) / (SS * transverseCurvatureAtEP);
251 
252  theMomentumJacobian(3, 0) =
253  (signTC * (Y * cos(phiAtEP) - X * sin(phiAtEP)) / S - 1) / (transverseCurvatureAtEP * transverseCurvatureAtEP);
254 
255  theMomentumJacobian(3, 2) = signTC * (X * cos(phiAtEP) + Y * sin(phiAtEP)) / (S * transverseCurvatureAtEP);
256 
257  theMomentumJacobian(4, 0) =
258  (phiAtEP - theExpandedParams(2)) / tan(thetaAtEP) / (transverseCurvatureAtEP * transverseCurvatureAtEP) +
259  theMomentumJacobian(2, 0) / tan(thetaAtEP) / transverseCurvatureAtEP;
260 
261  theMomentumJacobian(4, 1) =
262  (phiAtEP - theExpandedParams(2)) * (1 + 1 / (tan(thetaAtEP) * tan(thetaAtEP))) / transverseCurvatureAtEP;
263 
264  theMomentumJacobian(4, 2) = (theMomentumJacobian(2, 2) - 1) / tan(thetaAtEP) / transverseCurvatureAtEP;
265 
266  theMomentumJacobian(5, 3) = 1;
267 
268  // And finally the residuals:
269  AlgebraicVector3 expansionPoint;
270  expansionPoint[0] = thePredState.theState().globalPosition().x();
271  expansionPoint[1] = thePredState.theState().globalPosition().y();
272  expansionPoint[2] = thePredState.theState().globalPosition().z();
273  AlgebraicVector4 momentumAtExpansionPoint;
274  momentumAtExpansionPoint[0] = transverseCurvatureAtEP; // Transverse Curv
275  momentumAtExpansionPoint[1] = thetaAtEP;
276  momentumAtExpansionPoint[2] = phiAtEP;
277  momentumAtExpansionPoint[3] = theExpandedParams[5];
278 
280  theMomentumJacobian * momentumAtExpansionPoint);
281 }
282 
284  GlobalPoint paramPt(theLinPoint);
285  double thetaAtEP = thePredState.theState().globalMomentum().theta();
286  double phiAtEP = thePredState.theState().globalMomentum().phi();
287  double ptAtEP = thePredState.theState().globalMomentum().perp();
288 
289  double x_v = thePredState.theState().globalPosition().x();
290  double y_v = thePredState.theState().globalPosition().y();
291  double z_v = thePredState.theState().globalPosition().z();
292  double X = x_v - paramPt.x();
293  double Y = y_v - paramPt.y();
294 
295  // The track parameters at the expansion point
296  theExpandedParams[0] = 1 / ptAtEP;
297  theExpandedParams[1] = thetaAtEP;
298  theExpandedParams[2] = phiAtEP;
299  theExpandedParams[3] = X * sin(phiAtEP) - Y * cos(phiAtEP);
300  theExpandedParams[4] = z_v - paramPt.z() - (X * cos(phiAtEP) + Y * sin(phiAtEP)) / tan(thetaAtEP);
301  theExpandedParams[5] = part->currentState().mass();
302 
303  // The Jacobian: (all at the expansion point)
304  // [i,j]
305  // i = 0: rho = 1/pt , 1: theta, 2: phi_p, 3: epsilon, 4: z_p
306  // j = 0: x_v, 1: y_v, 2: z_v
307  thePositionJacobian(3, 0) = sin(phiAtEP);
308  thePositionJacobian(3, 1) = -cos(phiAtEP);
309  thePositionJacobian(4, 0) = -cos(phiAtEP) / tan(thetaAtEP);
310  thePositionJacobian(4, 1) = -sin(phiAtEP) / tan(thetaAtEP);
311  thePositionJacobian(4, 2) = 1;
312 
313  // [i,j]
314  // i = 0: rho = 1/pt , 1: theta, 2: phi_p, 3: epsilon, 4: z_p
315  // j = 0: rho = 1/pt , 1: theta, 2: phi_v
316  theMomentumJacobian(0, 0) = 1;
317  theMomentumJacobian(1, 1) = 1;
318  theMomentumJacobian(2, 2) = 1;
319 
320  theMomentumJacobian(3, 2) = X * cos(phiAtEP) + Y * sin(phiAtEP);
321  theMomentumJacobian(4, 1) = theMomentumJacobian(3, 2) * (1 + 1 / (tan(thetaAtEP) * tan(thetaAtEP)));
322 
323  theMomentumJacobian(4, 2) = (X * sin(phiAtEP) - Y * cos(phiAtEP)) / tan(thetaAtEP);
324  theMomentumJacobian(5, 3) = 1;
325 
326  // And finally the residuals:
327  AlgebraicVector3 expansionPoint;
328  expansionPoint[0] = thePredState.theState().globalPosition().x();
329  expansionPoint[1] = thePredState.theState().globalPosition().y();
330  expansionPoint[2] = thePredState.theState().globalPosition().z();
331  AlgebraicVector4 momentumAtExpansionPoint;
332  momentumAtExpansionPoint[0] = 1 / ptAtEP;
333  momentumAtExpansionPoint[1] = thetaAtEP;
334  momentumAtExpansionPoint[2] = phiAtEP;
335  momentumAtExpansionPoint[3] = theExpandedParams[5];
336 
338  theMomentumJacobian * momentumAtExpansionPoint);
339 }
340 
342  throw VertexException(" ParticleKinematicLinearizedTrackState:: no TransientTrack to return");
343 }
const AlgebraicMatrix63 & positionJacobian() const override
RefCountedRefittedTrackState createRefittedTrackState(const GlobalPoint &vertexPosition, const AlgebraicVectorM &vectorParameters, const AlgebraicSymMatrix77 &covarianceMatrix) const override
ReferenceCountingPointer< LinearizedTrackState< 6 > > stateWithNewLinearizationPoint(const GlobalPoint &newLP) const override
T perp() const
Definition: PV3DBase.h:69
bool operator==(LinearizedTrackState< 6 > &other) const override
const AlgebraicMatrix64 & momentumJacobian() const override
T z() const
Definition: PV3DBase.h:61
Common base class.
AlgebraicVectorN refittedParamFromEquation(const RefCountedRefittedTrackState &theRefittedState) const override
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
#define X(str)
Definition: MuonsGrabber.cc:38
const AlgebraicVector6 & parametersFromExpansion() const override
ROOT::Math::SVector< double, N - 2 > AlgebraicVectorM
const ExtendedPerigeeTrajectoryParameters & perigeeParameters() const
const AlgebraicSymMatrix66 & weightMatrix(int &error) const
ROOT::Math::SMatrix< double, 6, 4, ROOT::Math::MatRepStd< double, 6, 4 > > AlgebraicMatrix64
void checkParameters(AlgebraicVectorN &parameters) const override
GlobalPoint globalPosition() const
Definition: Electron.h:6
const ExtendedPerigeeTrajectoryError & perigeeError() const
ROOT::Math::SMatrix< double, 6, 3, ROOT::Math::MatRepStd< double, 6, 3 > > AlgebraicMatrix63
const KinematicState & theState() const
int TrackCharge
Definition: TrackCharge.h:4
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
AlgebraicVectorM predictedStateMomentumParameters() const override
const AlgebraicVector6 & constantTerm() const override
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
GlobalVector globalMomentum() const
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > AlgebraicSymMatrix44
ReferenceCountingPointer< RefittedTrackState< N > > RefCountedRefittedTrackState
ROOT::Math::SVector< double, 4 > AlgebraicVector4
ReferenceCountingPointer< LinearizedTrackState< 6 > > RefCountedLinearizedTrackState
#define M_PI
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
part
Definition: HCALResponse.h:20
const AlgebraicSymMatrix66 & covarianceMatrix() const
ROOT::Math::SMatrix< double, 7, 7, ROOT::Math::MatRepSym< double, 7 > > AlgebraicSymMatrix77
Definition: Matrices.h:9
AlgebraicSymMatrix66 predictedStateWeight(int &error) const override
ROOT::Math::SVector< double, 3 > AlgebraicVector3
ROOT::Math::SVector< double, 6 > AlgebraicVector6
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
AlgebraicSymMatrix66 predictedStateError() const override
std::vector< ReferenceCountingPointer< LinearizedTrackState< 6 > > > components() const override
AlgebraicSymMatrix44 predictedStateMomentumError() const override
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72