CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ReferenceTrajectory.cc
Go to the documentation of this file.
1 // Author : Gero Flucke (based on code by Edmund Widl replacing ORCA's TkReferenceTrack)
2 // date : 2006/09/17
3 // last update: $Date: 2010/09/10 13:24:44 $
4 // by : $Author: mussgill $
5 
6 #include <memory>
7 
9 
13 
15 
20 
22 
26 
29 
32 
40 
42 
44 #include "BeamSpotGeomDet.h"
45 
46 //__________________________________________________________________________________
47 
50  &recHits, bool hitsAreReverse,
51  const MagneticField *magField,
52  MaterialEffects materialEffects,
53  PropagationDirection propDir,
54  double mass,
55  bool useBeamSpot, const reco::BeamSpot &beamSpot)
57  (materialEffects >= brokenLinesCoarse) ? 1 : refTsos.localParameters().mixedFormatVector().kSize,
58  (useBeamSpot == true) ? recHits.size()+1 : recHits.size(),
59  (materialEffects >= brokenLinesCoarse) ?
60  2*((useBeamSpot == true) ? recHits.size()+1 : recHits.size()) :
61  ( (materialEffects == breakPoints) ? 2*((useBeamSpot == true) ? recHits.size()+1 : recHits.size())-2 : 0) ,
62  (materialEffects >= brokenLinesCoarse) ?
63  2*((useBeamSpot == true) ? recHits.size()+1 : recHits.size())-4 :
64  ( (materialEffects == breakPoints) ? 2*((useBeamSpot == true) ? recHits.size()+1 : recHits.size())-2 : 0) )
65 {
66  // no check against magField == 0
67  theParameters = asHepVector<5>( refTsos.localParameters().mixedFormatVector() );
68 
69  if (hitsAreReverse) {
71  fwdRecHits.reserve(recHits.size());
72  for (TransientTrackingRecHit::ConstRecHitContainer::const_reverse_iterator it=recHits.rbegin();
73  it != recHits.rend(); ++it) {
74  fwdRecHits.push_back(*it);
75  }
76  theValidityFlag = this->construct(refTsos, fwdRecHits, mass, materialEffects,
77  propDir, magField,
78  useBeamSpot, beamSpot);
79  } else {
80  theValidityFlag = this->construct(refTsos, recHits, mass, materialEffects,
81  propDir, magField,
82  useBeamSpot, beamSpot);
83  }
84 }
85 
86 
87 //__________________________________________________________________________________
88 
89 ReferenceTrajectory::ReferenceTrajectory( unsigned int nPar, unsigned int nHits,
90  MaterialEffects materialEffects)
92  (materialEffects >= brokenLinesCoarse) ? 1 : nPar,
93  nHits,
94  (materialEffects >= brokenLinesCoarse) ? 2*nHits : ( (materialEffects == breakPoints) ? 2*nHits-2 : 0 ),
95  (materialEffects >= brokenLinesCoarse) ? 2*nHits-4 : ( (materialEffects == breakPoints) ? 2*nHits-2 : 0 ) )
96 {}
97 
98 
99 //__________________________________________________________________________________
100 
103  double mass, MaterialEffects materialEffects,
104  const PropagationDirection propDir,
105  const MagneticField *magField,
106  bool useBeamSpot,
107  const reco::BeamSpot &beamSpot)
108 {
109  TrajectoryStateOnSurface theRefTsos = refTsos;
110 
111  const SurfaceSide surfaceSide = this->surfaceSide(propDir);
112  // auto_ptr to avoid memory leaks in case of not reaching delete at end of method:
113  std::auto_ptr<MaterialEffectsUpdator> aMaterialEffectsUpdator
114  (this->createUpdator(materialEffects, mass));
115  if (!aMaterialEffectsUpdator.get()) return false; // empty auto_ptr
116 
117  AlgebraicMatrix fullJacobian(theParameters.num_row(), theParameters.num_row());
118  std::vector<AlgebraicMatrix> allJacobians;
119  allJacobians.reserve(theNumberOfHits);
120 
122  TrajectoryStateOnSurface previousTsos;
123  AlgebraicSymMatrix previousChangeInCurvature(theParameters.num_row(), 1);
124  std::vector<AlgebraicSymMatrix> allCurvatureChanges;
125  allCurvatureChanges.reserve(theNumberOfHits);
126 
127  const LocalTrajectoryError zeroErrors(0., 0., 0., 0., 0.);
128 
129  std::vector<AlgebraicMatrix> allProjections;
130  allProjections.reserve(theNumberOfHits);
131  std::vector<AlgebraicSymMatrix> allDeltaParameterCovs;
132  allDeltaParameterCovs.reserve(theNumberOfHits);
133 
134  // CHK
135  std::vector<AlgebraicMatrix> allLocalToCurv;
136  allLocalToCurv.reserve(theNumberOfHits);
137  std::vector<double> allSteps;
138  allSteps.reserve(theNumberOfHits);
139  std::vector<AlgebraicMatrix> allCurvlinJacobians;
140  allCurvlinJacobians.reserve(theNumberOfHits);
141 
142  AlgebraicMatrix firstCurvlinJacobian(5, 5, 1);
143 
144  unsigned int iRow = 0;
145 
146  // local storage vector of all rechits (including rechit for beam spot in case it is used)
148 
149  if (useBeamSpot && propDir==alongMomentum) {
150 
151  GlobalPoint bs(beamSpot.x0(), beamSpot.y0(), beamSpot.z0());
152 
153  TrajectoryStateClosestToBeamLine tsctbl(TSCBLBuilderNoMaterial()(*(refTsos.freeState()), beamSpot));
154  FreeTrajectoryState pcaFts = tsctbl.trackStateAtPCA();
155  GlobalVector bd(beamSpot.dxdz(), beamSpot.dydz(), 1.0);
156 
157  //propagation FIXME: Should use same propagator everywhere...
159  std::pair< TrajectoryStateOnSurface, double > tsosWithPath =
160  propagator.propagateWithPath(pcaFts, refTsos.surface());
161 
162  if (!tsosWithPath.first.isValid()) return false;
163 
164  GlobalVector momDir(pcaFts.momentum());
165  GlobalVector perpDir(bd.cross(momDir));
166  BoundPlane::RotationType rotation(perpDir, bd);
167 
168  BeamSpotGeomDet * bsGeom = new BeamSpotGeomDet(BoundPlane::build(bs, rotation, OpenBounds()));
169 
170  // There is also a constructor taking the magentic field. Use this one instead?
171  theRefTsos = TrajectoryStateOnSurface(pcaFts, bsGeom->surface());
172 
174  new BeamSpotTransientTrackingRecHit(beamSpot,
175  bsGeom,
176  theRefTsos.freeState()->momentum().phi());
177  allRecHits.push_back(bsRecHit);
178 
179  }
180 
181  // copy all rechits to the local storage vector
182  TransientTrackingRecHit::ConstRecHitContainer::const_iterator itRecHit;
183  for ( itRecHit = recHits.begin(); itRecHit != recHits.end(); ++itRecHit ) {
184  const TransientTrackingRecHit::ConstRecHitPointer &hitPtr = *itRecHit;
185  allRecHits.push_back(hitPtr);
186  }
187 
188  for ( itRecHit = allRecHits.begin(); itRecHit != allRecHits.end(); ++itRecHit ) {
189 
190  const TransientTrackingRecHit::ConstRecHitPointer &hitPtr = *itRecHit;
191  theRecHits.push_back(hitPtr);
192 
193  if (0 == iRow) {
194 
195  // compute the derivatives of the reference-track's parameters w.r.t. the initial ones
196  // derivative of the initial reference-track parameters w.r.t. themselves is of course the identity
197  fullJacobian = AlgebraicMatrix(theParameters.num_row(), theParameters.num_row(), 1);
198  allJacobians.push_back(fullJacobian);
199  theTsosVec.push_back(theRefTsos);
200  const JacobianLocalToCurvilinear startTrafo(hitPtr->det()->surface(), theRefTsos.localParameters(), *magField);
201  const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
202  if (materialEffects <= breakPoints) {
203  theInnerTrajectoryToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
205  }
206  allLocalToCurv.push_back(localToCurvilinear);
207  allSteps.push_back(0.);
208  allCurvlinJacobians.push_back(firstCurvlinJacobian);
209 
210  } else {
211 
212  AlgebraicMatrix nextJacobian;
213  AlgebraicMatrix nextCurvlinJacobian;
214  double nextStep = 0.;
215  TrajectoryStateOnSurface nextTsos;
216 
217  if (!this->propagate(previousHitPtr->det()->surface(), previousTsos,
218  hitPtr->det()->surface(), nextTsos,
219  nextJacobian, nextCurvlinJacobian, nextStep, propDir, magField)) {
220  return false; // stop if problem...// no delete aMaterialEffectsUpdator needed
221  }
222 
223  allJacobians.push_back(nextJacobian);
224  fullJacobian = nextJacobian * previousChangeInCurvature * fullJacobian;
225  theTsosVec.push_back(nextTsos);
226 
227  const JacobianLocalToCurvilinear startTrafo(hitPtr->det()->surface(), nextTsos.localParameters(), *magField);
228  const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
229  allLocalToCurv.push_back(localToCurvilinear);
230  if (nextStep == 0.) {
231  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::construct"
232  << "step 0. from id " << previousHitPtr->geographicalId()
233  << " to " << hitPtr->det()->geographicalId() << ".";
234  // brokenLinesFine will not work, brokenLinesCoarse combines close by layers
235  if (materialEffects == brokenLinesFine) {
236  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::construct" << "Skip track.";
237  return false;
238  }
239  }
240  allSteps.push_back(nextStep);
241  allCurvlinJacobians.push_back(nextCurvlinJacobian);
242 
243  }
244 
245  // take material effects into account. since trajectory-state is constructed with errors equal zero,
246  // the updated state contains only the uncertainties due to interactions in the current layer.
247  const TrajectoryStateOnSurface tmpTsos(theTsosVec.back().localParameters(), zeroErrors,
248  theTsosVec.back().surface(), magField, surfaceSide);
249  const TrajectoryStateOnSurface updatedTsos = aMaterialEffectsUpdator->updateState(tmpTsos, propDir);
250 
251  if ( !updatedTsos.isValid() ) return false;// no delete aMaterialEffectsUpdator needed
252 
253  if ( theTsosVec.back().localParameters().charge() )
254  {
255  previousChangeInCurvature[0][0] = updatedTsos.localParameters().signedInverseMomentum()
256  / theTsosVec.back().localParameters().signedInverseMomentum();
257  }
258 
259  // get multiple-scattering covariance-matrix
260  allDeltaParameterCovs.push_back( asHepMatrix<5>(updatedTsos.localError().matrix()) );
261  allCurvatureChanges.push_back(previousChangeInCurvature);
262 
263  // projection-matrix tsos-parameters -> measurement-coordinates
264  if ( useRecHit( hitPtr ) ) { allProjections.push_back( hitPtr->projectionMatrix() ); }
265  else { allProjections.push_back( AlgebraicMatrix( 2, 5, 0) ); } // get size from ???
266 
267  // set start-parameters for next propagation. trajectory-state without error
268  // - no error propagation needed here.
269  previousHitPtr = hitPtr;
270  previousTsos = TrajectoryStateOnSurface(updatedTsos.globalParameters(),
271  updatedTsos.surface(), surfaceSide);
272 
273  if (materialEffects < brokenLinesCoarse) {
274  this->fillDerivatives(allProjections.back(), fullJacobian, iRow);
275  }
276 
277  AlgebraicVector mixedLocalParams = asHepVector<5>(theTsosVec.back().localParameters().mixedFormatVector());
278  this->fillTrajectoryPositions(allProjections.back(), mixedLocalParams, iRow);
279  if ( useRecHit( hitPtr ) ) this->fillMeasurementAndError(hitPtr, iRow, updatedTsos);
280 
281  iRow += nMeasPerHit;
282  } // end of loop on hits
283 
284  bool msOK = true;
285  switch (materialEffects) {
286  case none:
287  break;
288  case multipleScattering:
289  case energyLoss:
290  case combined:
291  msOK = this->addMaterialEffectsCov(allJacobians, allProjections, allCurvatureChanges,
292  allDeltaParameterCovs);
293  break;
294  case breakPoints:
295  msOK = this->addMaterialEffectsBp(allJacobians, allProjections, allCurvatureChanges,
296  allDeltaParameterCovs, allLocalToCurv);
297  break;
298  case brokenLinesCoarse:
299  msOK = this->addMaterialEffectsBrl(allProjections, allDeltaParameterCovs, allLocalToCurv,
300  allSteps, refTsos.globalParameters());
301  break;
302  case brokenLinesFine:
303  msOK = this->addMaterialEffectsBrl(allCurvlinJacobians, allProjections, allCurvatureChanges,
304  allDeltaParameterCovs, allLocalToCurv, refTsos.globalParameters());
305  }
306  if (!msOK) return false;
307 
308  if (refTsos.hasError()) {
309  AlgebraicSymMatrix parameterCov = asHepMatrix<5>(refTsos.localError().matrix());
310  AlgebraicMatrix parDeriv;
311  if (theNumberOfMsPars>0) {
312  parDeriv = theDerivatives.sub( 1, nMeasPerHit*allJacobians.size(), 1, theParameters.num_row() );
313  } else {
314  parDeriv = theDerivatives;
315  }
316  theTrajectoryPositionCov = parameterCov.similarity(parDeriv);
317  } else {
319  }
320 
321  return true;
322 }
323 
324 //__________________________________________________________________________________
325 
327 ReferenceTrajectory::createUpdator(MaterialEffects materialEffects, double mass) const
328 {
329  switch (materialEffects) {
330  // MultipleScatteringUpdator doesn't change the trajectory-state
331  // during update and can therefore be used if material effects should be ignored:
332  case none:
333  case multipleScattering:
334  return new MultipleScatteringUpdator(mass);
335  case energyLoss:
336  return new EnergyLossUpdator(mass);
337  case combined:
338  return new CombinedMaterialEffectsUpdator(mass);
339  case breakPoints:
340  return new CombinedMaterialEffectsUpdator(mass);
341  case brokenLinesCoarse:
342  case brokenLinesFine:
343  return new CombinedMaterialEffectsUpdator(mass);
344 }
345 
346  return 0;
347 }
348 
349 //__________________________________________________________________________________
350 
351 bool ReferenceTrajectory::propagate(const BoundPlane &previousSurface, const TrajectoryStateOnSurface &previousTsos,
352  const BoundPlane &newSurface, TrajectoryStateOnSurface &newTsos, AlgebraicMatrix &newJacobian,
353  AlgebraicMatrix &newCurvlinJacobian, double &nextStep,
354  const PropagationDirection propDir, const MagneticField *magField) const
355 {
356  // propagate to next layer
360  //AnalyticalPropagator aPropagator(magField, propDir);
361  // Hard coded RungeKutta instead Analytical (avoid bias in TEC), but
362  // work around TrackPropagation/RungeKutta/interface/RKTestPropagator.h and
363  // http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9
364  RKTestPropagator bPropagator(magField, propDir); //double tolerance = 5.e-5)
365  Propagator &aPropagator = bPropagator;
366  const std::pair<TrajectoryStateOnSurface, double> tsosWithPath =
367  aPropagator.propagateWithPath(previousTsos, newSurface);
368 
369  // stop if propagation wasn't successful
370  if (!tsosWithPath.first.isValid()) return false;
371 
372  nextStep = tsosWithPath.second;
373  // calculate derivative of reference-track parameters on the actual layer w.r.t. the ones
374  // on the previous layer (both in global coordinates)
375  const AnalyticalCurvilinearJacobian aJacobian(previousTsos.globalParameters(),
376  tsosWithPath.first.globalPosition(),
377  tsosWithPath.first.globalMomentum(),
378  tsosWithPath.second);
379  const AlgebraicMatrix curvilinearJacobian = asHepMatrix<5,5>(aJacobian.jacobian());
380 
381  // jacobian of the track parameters on the previous layer for local->global transformation
382  const JacobianLocalToCurvilinear startTrafo(previousSurface, previousTsos.localParameters(), *magField);
383  const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
384 
385  // jacobian of the track parameters on the actual layer for global->local transformation
386  const JacobianCurvilinearToLocal endTrafo(newSurface, tsosWithPath.first.localParameters(), *magField);
387  const AlgebraicMatrix curvilinearToLocal = asHepMatrix<5>(endTrafo.jacobian());
388 
389  // compute derivative of reference-track parameters on the actual layer w.r.t. the ones on
390  // the previous layer (both in their local representation)
391  newCurvlinJacobian = curvilinearJacobian;
392  newJacobian = curvilinearToLocal * curvilinearJacobian * localToCurvilinear;
393  newTsos = tsosWithPath.first;
394 
395  return true;
396 }
397 
398 //__________________________________________________________________________________
399 
401  unsigned int iRow,
402  const TrajectoryStateOnSurface &updatedTsos)
403 {
404  // get the measurements and their errors, use information updated with tsos if improving
405  // (GF: Also for measurements or only for errors or do the former not change?)
406  // GF 10/2008: I doubt that it makes sense to update the hit with the tsos here:
407  // That is an analytical extrapolation and not the best guess of the real
408  // track state on the module, but the latter should be better to get the best
409  // hit uncertainty estimate!
410  TransientTrackingRecHit::ConstRecHitPointer newHitPtr(hitPtr->canImproveWithTrack() ?
411  hitPtr->clone(updatedTsos) : hitPtr);
412 
413  const LocalPoint localMeasurement = newHitPtr->localPosition();
414  const LocalError localMeasurementCov = newHitPtr->localPositionError();
415 
416  theMeasurements[iRow] = localMeasurement.x();
417  theMeasurements[iRow+1] = localMeasurement.y();
418  theMeasurementsCov[iRow][iRow] = localMeasurementCov.xx();
419  theMeasurementsCov[iRow][iRow+1] = localMeasurementCov.xy();
420  theMeasurementsCov[iRow+1][iRow+1] = localMeasurementCov.yy();
421  // GF: Should be a loop once the hit dimension is not hardcoded as nMeasPerHit (to be checked):
422  // for (int i = 0; i < hitPtr->dimension(); ++i) {
423  // theMeasurements[iRow+i] = hitPtr->parameters()[i]; // fixme: parameters() is by value!
424  // for (int j = i; j < hitPtr->dimension(); ++j) {
425  // theMeasurementsCov[iRow+i][iRow+j] = hitPtr->parametersError()[i][j];
426  // }
427  // }
428 }
429 
430 //__________________________________________________________________________________
431 
433  const AlgebraicMatrix &fullJacobian,
434  unsigned int iRow)
435 {
436  // derivatives of the local coordinates of the reference track w.r.t. to the inital track-parameters
437  const AlgebraicMatrix projectedJacobian(projection * fullJacobian);
438  for (int i = 0; i < parameters().num_row(); ++i) {
439  theDerivatives[iRow ][i] = projectedJacobian[0][i];
440  theDerivatives[iRow+1][i] = projectedJacobian[1][i];
441  // GF: Should be a loop once the hit dimension is not hardcoded as nMeasPerHit (to be checked):
442  // for (int j = 0; j < projection.num_col(); ++j) {
443  // theDerivatives[iRow+j][i] = projectedJacobian[j][i];
444  // }
445  }
446 }
447 
448 //__________________________________________________________________________________
449 
451  const AlgebraicVector &mixedLocalParams,
452  unsigned int iRow)
453 {
454  // get the local coordinates of the reference trajectory
455  const AlgebraicVector localPosition(projection * mixedLocalParams);
456  theTrajectoryPositions[iRow] = localPosition[0];
457  theTrajectoryPositions[iRow+1] = localPosition[1];
458  // GF: Should be a loop once the hit dimension is not hardcoded as nMeasPerHit (to be checked):
459  // for (int j = 0; j < projection.num_col(); ++j) {
460  // theTrajectoryPositions[iRow+j] = localPosition[j];
461  // }
462 }
463 
464 //__________________________________________________________________________________
465 
466 bool ReferenceTrajectory::addMaterialEffectsCov(const std::vector<AlgebraicMatrix> &allJacobians,
467  const std::vector<AlgebraicMatrix> &allProjections,
468  const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
469  const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs)
470 {
471  // the uncertainty due to multiple scattering is 'transferred' to the error matrix of the hits
472 
473  // GF: Needs update once hit dimension is not hardcoded as nMeasPerHit!
474 
475  AlgebraicSymMatrix materialEffectsCov(nMeasPerHit * allJacobians.size(), 0);
476 
477  // additional covariance-matrix of the measurements due to material-effects (single measurement)
478  AlgebraicSymMatrix deltaMaterialEffectsCov;
479 
480  // additional covariance-matrix of the parameters due to material-effects
481  AlgebraicSymMatrix paramMaterialEffectsCov(allDeltaParameterCovs[0]); //initialization
482  // error-propagation to state after energy loss
483  //GFback paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allCurvatureChanges[0]);
484 
485  AlgebraicMatrix tempParameterCov;
486  AlgebraicMatrix tempMeasurementCov;
487 
488  for (unsigned int k = 1; k < allJacobians.size(); ++k) {
489  // error-propagation to next layer
490  paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allJacobians[k]);
491 
492  // get dependences for the measurements
493  deltaMaterialEffectsCov = paramMaterialEffectsCov.similarity(allProjections[k]);
494  materialEffectsCov[nMeasPerHit*k ][nMeasPerHit*k ] = deltaMaterialEffectsCov[0][0];
495  materialEffectsCov[nMeasPerHit*k ][nMeasPerHit*k+1] = deltaMaterialEffectsCov[0][1];
496  materialEffectsCov[nMeasPerHit*k+1][nMeasPerHit*k ] = deltaMaterialEffectsCov[1][0];
497  materialEffectsCov[nMeasPerHit*k+1][nMeasPerHit*k+1] = deltaMaterialEffectsCov[1][1];
498 
499  // GFback add uncertainties for the following layers due to scattering at this layer
500  paramMaterialEffectsCov += allDeltaParameterCovs[k];
501  // end GFback
502  tempParameterCov = paramMaterialEffectsCov;
503 
504  // compute "inter-layer-dependencies"
505  for (unsigned int l = k+1; l < allJacobians.size(); ++l) {
506  tempParameterCov = allJacobians[l] * allCurvatureChanges[l] * tempParameterCov;
507  tempMeasurementCov = allProjections[l] * tempParameterCov * allProjections[k].T();
508 
509  materialEffectsCov[nMeasPerHit*l][nMeasPerHit*k] = tempMeasurementCov[0][0];
510  materialEffectsCov[nMeasPerHit*k][nMeasPerHit*l] = tempMeasurementCov[0][0];
511 
512  materialEffectsCov[nMeasPerHit*l][nMeasPerHit*k+1] = tempMeasurementCov[0][1];
513  materialEffectsCov[nMeasPerHit*k+1][nMeasPerHit*l] = tempMeasurementCov[0][1];
514 
515  materialEffectsCov[nMeasPerHit*l+1][nMeasPerHit*k] = tempMeasurementCov[1][0];
516  materialEffectsCov[nMeasPerHit*k][nMeasPerHit*l+1] = tempMeasurementCov[1][0];
517 
518  materialEffectsCov[nMeasPerHit*l+1][nMeasPerHit*k+1] = tempMeasurementCov[1][1];
519  materialEffectsCov[nMeasPerHit*k+1][nMeasPerHit*l+1] = tempMeasurementCov[1][1];
520  }
521  // add uncertainties for the following layers due to scattering at this layer
522  // GFback paramMaterialEffectsCov += allDeltaParameterCovs[k];
523  // error-propagation to state after energy loss
524  paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allCurvatureChanges[k]);
525 
526  }
527  theMeasurementsCov += materialEffectsCov;
528 
529  return true; // cannot fail
530 }
531 
532 //__________________________________________________________________________________
533 
534 bool ReferenceTrajectory::addMaterialEffectsBp(const std::vector<AlgebraicMatrix> &allJacobians,
535  const std::vector<AlgebraicMatrix> &allProjections,
536  const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
537  const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
538  const std::vector<AlgebraicMatrix> &allLocalToCurv)
539 {
540 //CHK: add material effects using break points
541  int offsetPar = theNumberOfPars;
542  int offsetMeas = nMeasPerHit * allJacobians.size();
543  int ierr = 0;
544 
545  AlgebraicMatrix tempJacobian;
546  AlgebraicMatrix MSprojection(2,5);
547  MSprojection[0][1] = 1;
548  MSprojection[1][2] = 1;
549  AlgebraicSymMatrix tempMSCov;
550  AlgebraicSymMatrix tempMSCovProj;
551  AlgebraicMatrix tempMSJacProj;
552 
553  for (unsigned int k = 1; k < allJacobians.size(); ++k) {
554 // CHK
555  int kbp = k-1;
556  tempJacobian = allJacobians[k] * allCurvatureChanges[k];
557  tempMSCov = allDeltaParameterCovs[k-1].similarity(allLocalToCurv[k-1]);
558  tempMSCovProj = tempMSCov.similarity(MSprojection);
559  theMeasurementsCov[offsetMeas+nMeasPerHit*kbp ][offsetMeas+nMeasPerHit*kbp ] = tempMSCovProj[0][0];
560  theMeasurementsCov[offsetMeas+nMeasPerHit*kbp+1][offsetMeas+nMeasPerHit*kbp+1]= tempMSCovProj[1][1];
561  theDerivatives[offsetMeas+nMeasPerHit*kbp ][offsetPar+2*kbp ] = 1.0;
562  theDerivatives[offsetMeas+nMeasPerHit*kbp+1][offsetPar+2*kbp+1] = 1.0 ;
563 
564  tempMSJacProj = (allProjections[k] * ( tempJacobian * allLocalToCurv[k-1].inverse(ierr) )) * MSprojection.T();
565  if (ierr) {
566  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBp"
567  << "Inversion 1 for break points failed: " << ierr;
568  return false;
569  }
570  theDerivatives[nMeasPerHit*k ][offsetPar+2*kbp ] = tempMSJacProj[0][0];
571  theDerivatives[nMeasPerHit*k ][offsetPar+2*kbp+1] = tempMSJacProj[0][1];
572  theDerivatives[nMeasPerHit*k+1][offsetPar+2*kbp ] = tempMSJacProj[1][0];
573  theDerivatives[nMeasPerHit*k+1][offsetPar+2*kbp+1] = tempMSJacProj[1][1];
574 
575  for (unsigned int l = k+1; l < allJacobians.size(); ++l) {
576 // CHK
577  int kbp = k-1;
578  tempJacobian = allJacobians[l] * allCurvatureChanges[l] * tempJacobian;
579  tempMSJacProj = (allProjections[l] * ( tempJacobian * allLocalToCurv[k-1].inverse(ierr) )) * MSprojection.T();
580  if (ierr) {
581  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBp"
582  << "Inversion 2 for break points failed: " << ierr;
583  return false;
584  }
585  theDerivatives[nMeasPerHit*l ][offsetPar+2*kbp ] = tempMSJacProj[0][0];
586  theDerivatives[nMeasPerHit*l ][offsetPar+2*kbp+1] = tempMSJacProj[0][1];
587  theDerivatives[nMeasPerHit*l+1][offsetPar+2*kbp ] = tempMSJacProj[1][0];
588  theDerivatives[nMeasPerHit*l+1][offsetPar+2*kbp+1] = tempMSJacProj[1][1];
589 
590  }
591 
592  }
593 
594  return true;
595 }
596 
597 //__________________________________________________________________________________
598 
599 bool ReferenceTrajectory::addMaterialEffectsBrl(const std::vector<AlgebraicMatrix> &allCurvlinJacobians,
600  const std::vector<AlgebraicMatrix> &allProjections,
601  const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
602  const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
603  const std::vector<AlgebraicMatrix> &allLocalToCurv,
604  const GlobalTrajectoryParameters &gtp)
605 {
606 //CHK: add material effects using broken lines
607 //fine: use exact Jacobians, all detectors
608 //broken lines: pair of offsets (u1,u2) = (xt,yt) (in curvilinear frame (q/p,lambda,phi,xt,yt)) at each layer
609 // scattering angles (alpha1,alpha2) = (cosLambda*dPhi, dLambda) (cosLambda cancels in Chi2)
610 // DU' = (dU'/dU)*DU + (dU'/dAlpha)*DAlpha + (dU'/dQbyp)*DQbyp (propagation of U)
611 // = J*DU + S*DAlpha + d*DQbyp
612 // => DAlpha = S^-1 (DU' - J*DU - d*DQbyp)
613 
614  int offsetPar = theNumberOfPars;
615  int offsetMeas = nMeasPerHit*allCurvlinJacobians.size();
616  int ierr = 0;
617 
618  GlobalVector p = gtp.momentum();
619  double cosLambda = sqrt((p.x()*p.x()+p.y()*p.y())/(p.x()*p.x()+p.y()*p.y()+p.z()*p.z()));
620 
621 // transformations Curvilinear <-> BrokenLines
622  AlgebraicMatrix QbypToCurv(5,1); // dCurv/dQbyp
623  QbypToCurv[0][0] = 1.; // dQbyp/dQbyp
624  AlgebraicMatrix AngleToCurv(5,2); // dCurv/dAlpha
625  AngleToCurv[1][1] = 1.; // dlambda/dalpha2
626  AngleToCurv[2][0] = 1./cosLambda; // dphi/dalpha1
627  AlgebraicMatrix CurvToAngle(2,5); // dAlpha/dCurv
628  CurvToAngle[1][1] = 1.; // dalpha2/dlambda
629  CurvToAngle[0][2] = cosLambda; // dalpha1/dphi
630  AlgebraicMatrix OffsetToCurv(5,2); // dCurv/dU
631  OffsetToCurv[3][0] = 1.; // dxt/du1
632  OffsetToCurv[4][1] = 1.; // dyt/du2
633  AlgebraicMatrix CurvToOffset(2,5); // dU/dCurv
634  CurvToOffset[0][3] = 1.; // du1/dxt
635  CurvToOffset[1][4] = 1.; // du2/dyt
636 
637 // transformations trajectory to components (Qbyp, U1, U2)
638  AlgebraicMatrix TrajToQbyp(1,5);
639  TrajToQbyp[0][0] = 1.;
640  AlgebraicMatrix TrajToOff1(2,5);
641  TrajToOff1[0][1] = 1.;
642  TrajToOff1[1][2] = 1.;
643  AlgebraicMatrix TrajToOff2(2,5);
644  TrajToOff2[0][3] = 1.;
645  TrajToOff2[1][4] = 1.;
646 
647  AlgebraicMatrix JacOffsetToAngleC, JacQbypToAngleC;
648  AlgebraicMatrix JacCurvToOffsetL, JacOffsetToOffsetL, JacAngleToOffsetL, JacQbypToOffsetL, JacOffsetToAngleL;
649  AlgebraicMatrix JacCurvToOffsetN, JacOffsetToOffsetN, JacAngleToOffsetN, JacQbypToOffsetN, JacOffsetToAngleN;
650 
651 // transformation from trajectory to curvilinear parameters
652 
653  JacCurvToOffsetN = CurvToOffset * allCurvlinJacobians[1]; // (dU'/dCurv') * (dCurv'/dCurv) @ 2nd point
654  JacOffsetToOffsetN = JacCurvToOffsetN * OffsetToCurv; // J: (dU'/dU) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dU)
655  JacAngleToOffsetN = JacCurvToOffsetN * AngleToCurv; // S: (dU'/dAlpha) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dAlpha)
656  JacQbypToOffsetN = JacCurvToOffsetN * QbypToCurv; // d: (dU'/dQbyp) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dQbyp)
657  JacOffsetToAngleN = JacAngleToOffsetN.inverse(ierr); // W
658  if (ierr) {
659  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
660  << "Inversion 1 for fine broken lines failed: " << ierr;
661  return false;
662  }
663  JacOffsetToAngleC = -(JacOffsetToAngleN * JacOffsetToOffsetN); // (dAlpha/dU)
664  JacQbypToAngleC = -(JacOffsetToAngleN * JacQbypToOffsetN); // (dAlpha/dQbyp)
665  // (dAlpha/dTraj) = (dAlpha/dQbyp) * (dQbyp/dTraj) + (dAlpha/dU1) * (dU1/dTraj) + (dAlpha/dU2) * (dU2/dTraj)
666  AlgebraicMatrix JacTrajToAngle = JacQbypToAngleC * TrajToQbyp + JacOffsetToAngleC * TrajToOff1 + JacOffsetToAngleN * TrajToOff2;
667  // (dCurv/dTraj) = (dCurv/dQbyp) * (dQbyp/dTraj) + (dCurv/dAlpha) * (dAlpha/dTraj) + (dCurv/dU) * (dU/dTraj)
668  theInnerTrajectoryToCurvilinear = QbypToCurv * TrajToQbyp + AngleToCurv * JacTrajToAngle + OffsetToCurv * TrajToOff1;
669  theInnerLocalToTrajectory = theInnerTrajectoryToCurvilinear.inverse(ierr) * allLocalToCurv[0];
670  if (ierr) {
671  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
672  << "Inversion 2 for fine broken lines failed: " << ierr;
673  return false;
674  }
675 
676  AlgebraicMatrix tempJacobian(allCurvatureChanges[0]);
677  AlgebraicSymMatrix tempMSCov;
678  AlgebraicSymMatrix tempMSCovProj;
679  AlgebraicMatrix tempJacL, tempJacN;
680  AlgebraicMatrix JacOffsetToMeas;
681 
682 // measurements from hits
683  for (unsigned int k = 0; k < allCurvlinJacobians.size(); ++k) {
684 // (dMeas/dU) = (dMeas/dLoc) * (dLoc/dCurv) * (dCurv/dU)
685  JacOffsetToMeas = (allProjections[k] * allLocalToCurv[k].inverse(ierr) ) * OffsetToCurv;
686  if (ierr) {
687  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
688  << "Inversion 3 for fine broken lines failed: " << ierr;
689  return false;
690  }
691  theDerivatives[nMeasPerHit*k ][offsetPar+2*k ] = JacOffsetToMeas[0][0];
692  theDerivatives[nMeasPerHit*k ][offsetPar+2*k+1] = JacOffsetToMeas[0][1];
693  theDerivatives[nMeasPerHit*k+1][offsetPar+2*k ] = JacOffsetToMeas[1][0];
694  theDerivatives[nMeasPerHit*k+1][offsetPar+2*k+1] = JacOffsetToMeas[1][1];
695  }
696 
697 // measurement of MS kink
698  for (unsigned int k = 1; k < allCurvlinJacobians.size()-1; ++k) {
699 // CHK
700  int iMsMeas = k-1;
701  int l = k-1; // last hit
702  int n = k+1; // next hit
703 
704 // amount of multiple scattering in layer k (angular error perp to direction)
705  tempMSCov = allDeltaParameterCovs[k].similarity(allLocalToCurv[k]);
706  tempMSCovProj = tempMSCov.similarity(CurvToAngle);
707  theMeasurementsCov[offsetMeas+nMeasPerHit*iMsMeas ][offsetMeas+nMeasPerHit*iMsMeas ] = tempMSCovProj[1][1];
708  theMeasurementsCov[offsetMeas+nMeasPerHit*iMsMeas+1][offsetMeas+nMeasPerHit*iMsMeas+1] = tempMSCovProj[0][0];
709 
710 // transformation matices for offsets ( l <- k -> n )
711  tempJacL = allCurvlinJacobians[k] * tempJacobian;
712  JacCurvToOffsetL = CurvToOffset * tempJacL.inverse(ierr); // (dU'/dCurv') * (dCurv'/dCurv) @ last point
713 
714  if (ierr) {
715  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
716  << "Inversion 4 for fine broken lines failed: " << ierr;
717  return false;
718  }
719  JacOffsetToOffsetL = JacCurvToOffsetL * OffsetToCurv; // J-: (dU'/dU) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dU)
720  JacAngleToOffsetL = JacCurvToOffsetL * AngleToCurv; // S-: (dU'/dAlpha) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dAlpha)
721  JacQbypToOffsetL = JacCurvToOffsetL * QbypToCurv; // d-: (dU'/dQbyp) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dQbyp)
722  JacOffsetToAngleL =-JacAngleToOffsetL.inverse(ierr); // W-
723  if (ierr) {
724  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
725  << "Inversion 5 for fine broken lines failed: " << ierr;
726  return false;
727  }
728  tempJacobian = tempJacobian * allCurvatureChanges[k];
729  tempJacN = allCurvlinJacobians[n] * tempJacobian;
730  JacCurvToOffsetN = CurvToOffset * tempJacN; // (dU'/dCurv') * (dCurv'/dCurv) @ next point
731  JacOffsetToOffsetN = JacCurvToOffsetN * OffsetToCurv; // J+: (dU'/dU) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dU)
732  JacAngleToOffsetN = JacCurvToOffsetN * AngleToCurv; // S+: (dU'/dAlpha) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dAlpha)
733  JacQbypToOffsetN = JacCurvToOffsetN * QbypToCurv; // d+: (dU'/dQbyp) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dQbyp)
734  JacOffsetToAngleN = JacAngleToOffsetN.inverse(ierr); // W+
735  if (ierr) {
736  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
737  << "Inversion 6 for fine broken lines failed: " << ierr;
738  return false;
739  }
740  JacOffsetToAngleC = -(JacOffsetToAngleL * JacOffsetToOffsetL + JacOffsetToAngleN * JacOffsetToOffsetN);
741  JacQbypToAngleC = -(JacOffsetToAngleL * JacQbypToOffsetL + JacOffsetToAngleN * JacQbypToOffsetN);
742 
743  // bending
744  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][ 0] = JacQbypToAngleC[0][0];
745  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][ 0] = JacQbypToAngleC[1][0];
746  // last layer
747  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*l ] = JacOffsetToAngleL[0][0];
748  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*l+1] = JacOffsetToAngleL[0][1];
749  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*l ] = JacOffsetToAngleL[1][0];
750  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*l+1] = JacOffsetToAngleL[1][1];
751  // current layer
752  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*k ] = JacOffsetToAngleC[0][0];
753  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*k+1] = JacOffsetToAngleC[0][1];
754  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*k ] = JacOffsetToAngleC[1][0];
755  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*k+1] = JacOffsetToAngleC[1][1];
756 
757  // next layer
758  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*n ] = JacOffsetToAngleN[0][0];
759  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*n+1] = JacOffsetToAngleN[0][1];
760  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*n ] = JacOffsetToAngleN[1][0];
761  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*n+1] = JacOffsetToAngleN[1][1];
762 
763  }
764 
765  return true;
766 }
767 
768 bool ReferenceTrajectory::addMaterialEffectsBrl(const std::vector<AlgebraicMatrix> &allProjections,
769  const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
770  const std::vector<AlgebraicMatrix> &allLocalToCurv,
771  const std::vector<double> &allSteps,
772  const GlobalTrajectoryParameters &gtp,
773  const double minStep)
774 {
775 //CHK: add material effects using broken lines
776 //BrokenLinesCoarse: combine close by detectors,
777 // use approximate Jacobians from Steps (limit Qbyp -> 0),
778 // bending only in RPhi (B=(0,0,Bz)), no energy loss correction
779 
780  int offsetPar = theNumberOfPars;
781  int offsetMeas = nMeasPerHit*allSteps.size();
782  int ierr = 0;
783 
784  GlobalVector p = gtp.momentum();
785  double cosLambda = sqrt((p.x()*p.x()+p.y()*p.y())/(p.x()*p.x()+p.y()*p.y()+p.z()*p.z()));
786  double bFac = -gtp.magneticFieldInInverseGeV(gtp.position()).mag();
787 
788  // transformation from trajectory to curvilinear parameters at refTsos
789  double delta (1.0/allSteps[1]);
793  theInnerTrajectoryToCurvilinear[2][0] = -0.5*bFac/delta;
794  theInnerTrajectoryToCurvilinear[2][1] = -delta/cosLambda;
795  theInnerTrajectoryToCurvilinear[2][3] = delta/cosLambda;
798  theInnerLocalToTrajectory = theInnerTrajectoryToCurvilinear.inverse(ierr) * allLocalToCurv[0];
799  if (ierr) {
800  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
801  << "Inversion 1 for coarse broken lines failed: " << ierr;
802  return false;
803  }
804 
805  AlgebraicMatrix CurvToAngle(2,5); // dAlpha/dCurv
806  CurvToAngle[1][1] = 1.; // dalpha2/dlambda
807  CurvToAngle[0][2] = cosLambda; // dalpha1/dphi
808  AlgebraicMatrix OffsetToCurv(5,2); // dCurv/dU
809  OffsetToCurv[3][0] = 1.; // dxt/du1
810  OffsetToCurv[4][1] = 1.; // dyt/du2
811 
812  AlgebraicSymMatrix tempMSCov;
813  AlgebraicSymMatrix tempMSCovProj;
814  AlgebraicMatrix JacOffsetToMeas;
815 
816  // combine closeby detectors into single plane
817  std::vector<unsigned int> first(allSteps.size());
818  std::vector<unsigned int> last (allSteps.size());
819  std::vector<unsigned int> plane(allSteps.size());
820  std::vector<double> sPlane(allSteps.size());
821  unsigned int nPlane = 0;
822  double sTot = 0;
823 
824  for (unsigned int k = 1; k < allSteps.size(); ++k) {
825  sTot += allSteps[k];
826  if (fabs(allSteps[k])>minStep) { nPlane += 1; first[nPlane] = k; }
827  last[nPlane] = k;
828  plane[k] = nPlane;
829  sPlane[nPlane] += sTot;
830  }
831  if (nPlane < 2) return false; // pathological cases: need at least 2 planes
832 
833  theNumberOfMsPars = 2*(nPlane+1);
834  theNumberOfMsMeas = 2*(nPlane-1);// unsigned underflow for nPlane == 0...
835  for (unsigned int k = 0; k <= nPlane; ++k) { sPlane[k] /= (double) (last[k]-first[k]+1); }
836 
837  // measurements from hits
838  sTot = 0;
839  for (unsigned int k = 0; k < allSteps.size(); ++k) {
840  sTot += allSteps[k];
841 // (dMeas/dU) = (dMeas/dLoc) * (dLoc/dCurv) * (dCurv/dU)
842  JacOffsetToMeas = (allProjections[k] * allLocalToCurv[k].inverse(ierr) ) * OffsetToCurv;
843  if (ierr) {
844  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
845  << "Inversion 2 for coarse broken lines failed: " << ierr;
846  return false;
847  }
848 
849  unsigned int iPlane = plane[k];
850  if (last[iPlane] == first[iPlane])
851  { // single plane
852  theDerivatives[nMeasPerHit*k ][offsetPar+2*iPlane ] = JacOffsetToMeas[0][0];
853  theDerivatives[nMeasPerHit*k ][offsetPar+2*iPlane+1] = JacOffsetToMeas[0][1];
854  theDerivatives[nMeasPerHit*k+1][offsetPar+2*iPlane ] = JacOffsetToMeas[1][0];
855  theDerivatives[nMeasPerHit*k+1][offsetPar+2*iPlane+1] = JacOffsetToMeas[1][1];
856  } else
857  { // combined plane: (linear) interpolation
858  unsigned int jPlane; // neighbor plane for interpolation
859  if (fabs(sTot) < fabs(sPlane[iPlane])) { jPlane = (iPlane>0) ? iPlane - 1 : 1; }
860  else { jPlane = (iPlane<nPlane) ? iPlane + 1 : nPlane -1 ;}
861  // interpolation weights
862  double sDiff = sPlane[iPlane] - sPlane[jPlane];
863  double iFrac = (sTot - sPlane[jPlane]) / sDiff;
864  double jFrac = 1.0 - iFrac;
865  theDerivatives[nMeasPerHit*k ][offsetPar+2*iPlane ] = JacOffsetToMeas[0][0]*iFrac;
866  theDerivatives[nMeasPerHit*k ][offsetPar+2*iPlane+1] = JacOffsetToMeas[0][1]*iFrac;
867  theDerivatives[nMeasPerHit*k+1][offsetPar+2*iPlane ] = JacOffsetToMeas[1][0]*iFrac;
868  theDerivatives[nMeasPerHit*k+1][offsetPar+2*iPlane+1] = JacOffsetToMeas[1][1]*iFrac;
869  theDerivatives[nMeasPerHit*k ][offsetPar+2*jPlane ] = JacOffsetToMeas[0][0]*jFrac;
870  theDerivatives[nMeasPerHit*k ][offsetPar+2*jPlane+1] = JacOffsetToMeas[0][1]*jFrac;
871  theDerivatives[nMeasPerHit*k+1][offsetPar+2*jPlane ] = JacOffsetToMeas[1][0]*jFrac;
872  theDerivatives[nMeasPerHit*k+1][offsetPar+2*jPlane+1] = JacOffsetToMeas[1][1]*jFrac;
873  // 2nd order neglected
874  // theDerivatives[nMeasPerHit*k ][ 0] = -0.5*bFac*sDiff*iFrac*sDiff*jFrac*cosLambda;
875  }
876  }
877 
878 // measurement of MS kink
879  for (unsigned int i = 1; i < nPlane; ++i) {
880 // CHK
881  int iMsMeas = i-1;
882  int l = i-1; // last hit
883  int n = i+1; // next hit
884 
885 // amount of multiple scattering in plane k
886  for (unsigned int k = first[i]; k <= last[i]; ++k) {
887  tempMSCov = allDeltaParameterCovs[k].similarity(allLocalToCurv[k]);
888  tempMSCovProj = tempMSCov.similarity(CurvToAngle);
889  theMeasurementsCov[offsetMeas+nMeasPerHit*iMsMeas ][offsetMeas+nMeasPerHit*iMsMeas ] += tempMSCovProj[0][0];
890  theMeasurementsCov[offsetMeas+nMeasPerHit*iMsMeas+1][offsetMeas+nMeasPerHit*iMsMeas+1] += tempMSCovProj[1][1];
891  }
892 // broken line measurements for layer k, correlations between both planes neglected
893  double stepK = sPlane[i] - sPlane[l];
894  double stepN = sPlane[n] - sPlane[i];
895  double deltaK (1.0/stepK);
896  double deltaN (1.0/stepN);
897  // bending (only in RPhi)
898  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][ 0] = -0.5*bFac*(stepK+stepN)*cosLambda;
899  // last layer
900  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*l ] = deltaK;
901  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*l+1] = deltaK;
902  // current layer
903  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*i ] = -(deltaK + deltaN);
904  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*i+1] = -(deltaK + deltaN);
905  // next layer
906  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*n ] = deltaN;
907  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*n+1] = deltaN;
908  }
909 
910  return true;
911 }
dbl * delta
Definition: mlp_gen.cc:36
AlgebraicMatrix theInnerTrajectoryToCurvilinear
double z0() const
z coordinate
Definition: BeamSpot.h:69
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:19
virtual bool addMaterialEffectsBrl(const std::vector< AlgebraicMatrix > &allJacobians, const std::vector< AlgebraicMatrix > &allProjections, const std::vector< AlgebraicSymMatrix > &allCurvChanges, const std::vector< AlgebraicSymMatrix > &allDeltaParaCovs, const std::vector< AlgebraicMatrix > &allLocalToCurv, const GlobalTrajectoryParameters &gtp)
const LocalTrajectoryParameters & localParameters() const
virtual bool construct(const TrajectoryStateOnSurface &referenceTsos, const TransientTrackingRecHit::ConstRecHitContainer &recHits, double mass, MaterialEffects materialEffects, const PropagationDirection propDir, const MagneticField *magField, bool useBeamSpot, const reco::BeamSpot &beamSpot)
AlgebraicMatrix theInnerLocalToTrajectory
virtual void fillMeasurementAndError(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr, unsigned int iRow, const TrajectoryStateOnSurface &updatedTsos)
static const unsigned int nMeasPerHit
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
T y() const
Definition: PV3DBase.h:57
PropagationDirection
static BoundPlanePointer build(const PositionType &pos, const RotationType &rot, const Bounds *bounds, MediumProperties *mp=0)
Definition: BoundPlane.h:26
virtual bool addMaterialEffectsBp(const std::vector< AlgebraicMatrix > &allJacobians, const std::vector< AlgebraicMatrix > &allProjections, const std::vector< AlgebraicSymMatrix > &allCurvChanges, const std::vector< AlgebraicSymMatrix > &allDeltaParaCovs, const std::vector< AlgebraicMatrix > &allLocalToCurv)
GlobalVector magneticFieldInInverseGeV(const GlobalPoint &x) const
virtual bool propagate(const BoundPlane &previousSurface, const TrajectoryStateOnSurface &previousTsos, const BoundPlane &newSurface, TrajectoryStateOnSurface &newTsos, AlgebraicMatrix &newJacobian, AlgebraicMatrix &newCurvlinJacobian, double &nextStep, const PropagationDirection propDir, const MagneticField *magField) const
AlgebraicSymMatrix theTrajectoryPositionCov
double dydz() const
dydz slope
Definition: BeamSpot.h:85
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:74
float xy() const
Definition: LocalError.h:20
const SurfaceSide surfaceSide(const PropagationDirection dir) const
CLHEP::HepMatrix AlgebraicMatrix
FreeTrajectoryState * freeState(bool withErrors=true) const
float yy() const
Definition: LocalError.h:21
T sqrt(T t)
Definition: SSEVec.h:28
ReferenceTrajectory(const TrajectoryStateOnSurface &referenceTsos, const TransientTrackingRecHit::ConstRecHitContainer &recHits, bool hitsAreReverse, const MagneticField *magField, MaterialEffects materialEffects, PropagationDirection propDir, double mass, bool useBeamSpot, const reco::BeamSpot &beamSpot)
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:119
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &fts, const Plane &plane) const
propagation to plane with path length
T z() const
Definition: PV3DBase.h:58
MaterialEffectsUpdator * createUpdator(MaterialEffects materialEffects, double mass) const
const AlgebraicSymMatrix55 & matrix() const
virtual void fillDerivatives(const AlgebraicMatrix &projection, const AlgebraicMatrix &fullJacobian, unsigned int iRow)
const LocalTrajectoryError & localError() const
bool first
Definition: L1TdeRCT.cc:79
GlobalVector momentum() const
double dxdz() const
dxdz slope
Definition: BeamSpot.h:83
TransientTrackingRecHit::ConstRecHitContainer theRecHits
int k[5][pyjets_maxn]
AlgebraicSymMatrix theMeasurementsCov
std::vector< ConstRecHitPointer > ConstRecHitContainer
const AlgebraicVector & parameters() const
CLHEP::HepVector AlgebraicVector
const GlobalTrajectoryParameters & globalParameters() const
AlgebraicVector5 mixedFormatVector() const
Unlimited (trivial) bounds.
Definition: OpenBounds.h:10
const Surface & surface() const
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::vector< TrajectoryStateOnSurface > theTsosVec
double y0() const
y coordinate
Definition: BeamSpot.h:67
virtual bool addMaterialEffectsCov(const std::vector< AlgebraicMatrix > &allJacobians, const std::vector< AlgebraicMatrix > &allProjections, const std::vector< AlgebraicSymMatrix > &allCurvChanges, const std::vector< AlgebraicSymMatrix > &allDeltaParaCovs)
virtual void fillTrajectoryPositions(const AlgebraicMatrix &projection, const AlgebraicVector &mixedLocalParams, unsigned int iRow)
bool useRecHit(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr) const
T x() const
Definition: PV3DBase.h:56
double signedInverseMomentum() const
Signed inverse momentum q/p (zero for neutrals).
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
tuple size
Write out results.
double x0() const
x coordinate
Definition: BeamSpot.h:65