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: 2012/12/25 16:42:04 $
4 // by : $Author: innocent $
5 
6 #include <memory>
7 
9 
12 
14 
19 
22 
26 
29 
32 
40 
42 
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  if (!tsctbl.isValid()) {
155  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::construct"
156  << "TrajectoryStateClostestToBeamLine invalid. Skip track.";
157  return false;
158  }
159 
160  FreeTrajectoryState pcaFts = tsctbl.trackStateAtPCA();
161  GlobalVector bd(beamSpot.dxdz(), beamSpot.dydz(), 1.0);
162 
163  //propagation FIXME: Should use same propagator everywhere...
165  std::pair< TrajectoryStateOnSurface, double > tsosWithPath =
166  propagator.propagateWithPath(pcaFts, refTsos.surface());
167 
168  if (!tsosWithPath.first.isValid()) return false;
169 
170  GlobalVector momDir(pcaFts.momentum());
171  GlobalVector perpDir(bd.cross(momDir));
172  Plane::RotationType rotation(perpDir, bd);
173 
174  BeamSpotGeomDet * bsGeom = new BeamSpotGeomDet(Plane::build(bs, rotation));
175 
176  // There is also a constructor taking the magentic field. Use this one instead?
177  theRefTsos = TrajectoryStateOnSurface(pcaFts, bsGeom->surface());
178 
180  new BeamSpotTransientTrackingRecHit(beamSpot,
181  bsGeom,
182  theRefTsos.freeState()->momentum().phi());
183  allRecHits.push_back(bsRecHit);
184 
185  }
186 
187  // copy all rechits to the local storage vector
188  TransientTrackingRecHit::ConstRecHitContainer::const_iterator itRecHit;
189  for ( itRecHit = recHits.begin(); itRecHit != recHits.end(); ++itRecHit ) {
190  const TransientTrackingRecHit::ConstRecHitPointer &hitPtr = *itRecHit;
191  allRecHits.push_back(hitPtr);
192  }
193 
194  for ( itRecHit = allRecHits.begin(); itRecHit != allRecHits.end(); ++itRecHit ) {
195 
196  const TransientTrackingRecHit::ConstRecHitPointer &hitPtr = *itRecHit;
197  theRecHits.push_back(hitPtr);
198 
199  if (0 == iRow) {
200 
201  // compute the derivatives of the reference-track's parameters w.r.t. the initial ones
202  // derivative of the initial reference-track parameters w.r.t. themselves is of course the identity
203  fullJacobian = AlgebraicMatrix(theParameters.num_row(), theParameters.num_row(), 1);
204  allJacobians.push_back(fullJacobian);
205  theTsosVec.push_back(theRefTsos);
206  const JacobianLocalToCurvilinear startTrafo(hitPtr->det()->surface(), theRefTsos.localParameters(), *magField);
207  const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
208  if (materialEffects <= breakPoints) {
209  theInnerTrajectoryToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
211  }
212  allLocalToCurv.push_back(localToCurvilinear);
213  allSteps.push_back(0.);
214  allCurvlinJacobians.push_back(firstCurvlinJacobian);
215 
216  } else {
217 
218  AlgebraicMatrix nextJacobian;
219  AlgebraicMatrix nextCurvlinJacobian;
220  double nextStep = 0.;
221  TrajectoryStateOnSurface nextTsos;
222 
223  if (!this->propagate(previousHitPtr->det()->surface(), previousTsos,
224  hitPtr->det()->surface(), nextTsos,
225  nextJacobian, nextCurvlinJacobian, nextStep, propDir, magField)) {
226  return false; // stop if problem...// no delete aMaterialEffectsUpdator needed
227  }
228 
229  allJacobians.push_back(nextJacobian);
230  fullJacobian = nextJacobian * previousChangeInCurvature * fullJacobian;
231  theTsosVec.push_back(nextTsos);
232 
233  const JacobianLocalToCurvilinear startTrafo(hitPtr->det()->surface(), nextTsos.localParameters(), *magField);
234  const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
235  allLocalToCurv.push_back(localToCurvilinear);
236  if (nextStep == 0.) {
237  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::construct"
238  << "step 0. from id " << previousHitPtr->geographicalId()
239  << " to " << hitPtr->det()->geographicalId() << ".";
240  // brokenLinesFine will not work, brokenLinesCoarse combines close by layers
241  if (materialEffects == brokenLinesFine) {
242  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::construct" << "Skip track.";
243  return false;
244  }
245  }
246  allSteps.push_back(nextStep);
247  allCurvlinJacobians.push_back(nextCurvlinJacobian);
248 
249  }
250 
251  // take material effects into account. since trajectory-state is constructed with errors equal zero,
252  // the updated state contains only the uncertainties due to interactions in the current layer.
253  const TrajectoryStateOnSurface tmpTsos(theTsosVec.back().localParameters(), zeroErrors,
254  theTsosVec.back().surface(), magField, surfaceSide);
255  const TrajectoryStateOnSurface updatedTsos = aMaterialEffectsUpdator->updateState(tmpTsos, propDir);
256 
257  if ( !updatedTsos.isValid() ) return false;// no delete aMaterialEffectsUpdator needed
258 
259  if ( theTsosVec.back().localParameters().charge() )
260  {
261  previousChangeInCurvature[0][0] = updatedTsos.localParameters().signedInverseMomentum()
262  / theTsosVec.back().localParameters().signedInverseMomentum();
263  }
264 
265  // get multiple-scattering covariance-matrix
266  allDeltaParameterCovs.push_back( asHepMatrix<5>(updatedTsos.localError().matrix()) );
267  allCurvatureChanges.push_back(previousChangeInCurvature);
268 
269  // projection-matrix tsos-parameters -> measurement-coordinates
270  allProjections.push_back(this->getHitProjectionMatrix(hitPtr));
271  // set start-parameters for next propagation. trajectory-state without error
272  // - no error propagation needed here.
273  previousHitPtr = hitPtr;
274  previousTsos = TrajectoryStateOnSurface(updatedTsos.globalParameters(),
275  updatedTsos.surface(), surfaceSide);
276 
277  if (materialEffects < brokenLinesCoarse) {
278  this->fillDerivatives(allProjections.back(), fullJacobian, iRow);
279  }
280 
281  AlgebraicVector mixedLocalParams = asHepVector<5>(theTsosVec.back().localParameters().mixedFormatVector());
282  this->fillTrajectoryPositions(allProjections.back(), mixedLocalParams, iRow);
283  if ( useRecHit( hitPtr ) ) this->fillMeasurementAndError(hitPtr, iRow, updatedTsos);
284 
285  iRow += nMeasPerHit;
286  } // end of loop on hits
287 
288  bool msOK = true;
289  switch (materialEffects) {
290  case none:
291  break;
292  case multipleScattering:
293  case energyLoss:
294  case combined:
295  msOK = this->addMaterialEffectsCov(allJacobians, allProjections, allCurvatureChanges,
296  allDeltaParameterCovs);
297  break;
298  case breakPoints:
299  msOK = this->addMaterialEffectsBp(allJacobians, allProjections, allCurvatureChanges,
300  allDeltaParameterCovs, allLocalToCurv);
301  break;
302  case brokenLinesCoarse:
303  msOK = this->addMaterialEffectsBrl(allProjections, allDeltaParameterCovs, allLocalToCurv,
304  allSteps, refTsos.globalParameters());
305  break;
306  case brokenLinesFine:
307  msOK = this->addMaterialEffectsBrl(allCurvlinJacobians, allProjections, allCurvatureChanges,
308  allDeltaParameterCovs, allLocalToCurv, refTsos.globalParameters());
309  }
310  if (!msOK) return false;
311 
312  if (refTsos.hasError()) {
313  AlgebraicSymMatrix parameterCov = asHepMatrix<5>(refTsos.localError().matrix());
314  AlgebraicMatrix parDeriv;
315  if (theNumberOfVirtualPars>0) {
316  parDeriv = theDerivatives.sub( 1, nMeasPerHit*allJacobians.size(), 1, theParameters.num_row() );
317  } else {
318  parDeriv = theDerivatives;
319  }
320  theTrajectoryPositionCov = parameterCov.similarity(parDeriv);
321  } else {
323  }
324 
325  return true;
326 }
327 
328 //__________________________________________________________________________________
329 
331 ReferenceTrajectory::createUpdator(MaterialEffects materialEffects, double mass) const
332 {
333  switch (materialEffects) {
334  // MultipleScatteringUpdator doesn't change the trajectory-state
335  // during update and can therefore be used if material effects should be ignored:
336  case none:
337  case multipleScattering:
338  return new MultipleScatteringUpdator(mass);
339  case energyLoss:
340  return new EnergyLossUpdator(mass);
341  case combined:
342  return new CombinedMaterialEffectsUpdator(mass);
343  case breakPoints:
344  return new CombinedMaterialEffectsUpdator(mass);
345  case brokenLinesCoarse:
346  case brokenLinesFine:
347  return new CombinedMaterialEffectsUpdator(mass);
348 }
349 
350  return 0;
351 }
352 
353 //__________________________________________________________________________________
354 
355 bool ReferenceTrajectory::propagate(const Plane &previousSurface, const TrajectoryStateOnSurface &previousTsos,
356  const Plane &newSurface, TrajectoryStateOnSurface &newTsos, AlgebraicMatrix &newJacobian,
357  AlgebraicMatrix &newCurvlinJacobian, double &nextStep,
358  const PropagationDirection propDir, const MagneticField *magField) const
359 {
360  // propagate to next layer
364  //AnalyticalPropagator aPropagator(magField, propDir);
365  // Hard coded RungeKutta instead Analytical (avoid bias in TEC), but
366  // work around TrackPropagation/RungeKutta/interface/RKTestPropagator.h and
367  // http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9
368  defaultRKPropagator::Product rkprod(magField, propDir); //double tolerance = 5.e-5)
369  Propagator &aPropagator = rkprod.propagator;
370  const std::pair<TrajectoryStateOnSurface, double> tsosWithPath =
371  aPropagator.propagateWithPath(previousTsos, newSurface);
372 
373  // stop if propagation wasn't successful
374  if (!tsosWithPath.first.isValid()) return false;
375 
376  nextStep = tsosWithPath.second;
377  // calculate derivative of reference-track parameters on the actual layer w.r.t. the ones
378  // on the previous layer (both in global coordinates)
379  const AnalyticalCurvilinearJacobian aJacobian(previousTsos.globalParameters(),
380  tsosWithPath.first.globalPosition(),
381  tsosWithPath.first.globalMomentum(),
382  tsosWithPath.second);
383  const AlgebraicMatrix curvilinearJacobian = asHepMatrix<5,5>(aJacobian.jacobian());
384 
385  // jacobian of the track parameters on the previous layer for local->global transformation
386  const JacobianLocalToCurvilinear startTrafo(previousSurface, previousTsos.localParameters(), *magField);
387  const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
388 
389  // jacobian of the track parameters on the actual layer for global->local transformation
390  const JacobianCurvilinearToLocal endTrafo(newSurface, tsosWithPath.first.localParameters(), *magField);
391  const AlgebraicMatrix curvilinearToLocal = asHepMatrix<5>(endTrafo.jacobian());
392 
393  // compute derivative of reference-track parameters on the actual layer w.r.t. the ones on
394  // the previous layer (both in their local representation)
395  newCurvlinJacobian = curvilinearJacobian;
396  newJacobian = curvilinearToLocal * curvilinearJacobian * localToCurvilinear;
397  newTsos = tsosWithPath.first;
398 
399  return true;
400 }
401 
402 //__________________________________________________________________________________
403 
405  unsigned int iRow,
406  const TrajectoryStateOnSurface &updatedTsos)
407 {
408  // get the measurements and their errors, use information updated with tsos if improving
409  // (GF: Also for measurements or only for errors or do the former not change?)
410  // GF 10/2008: I doubt that it makes sense to update the hit with the tsos here:
411  // That is an analytical extrapolation and not the best guess of the real
412  // track state on the module, but the latter should be better to get the best
413  // hit uncertainty estimate!
414  TransientTrackingRecHit::ConstRecHitPointer newHitPtr(hitPtr->canImproveWithTrack() ?
415  hitPtr->clone(updatedTsos) : hitPtr);
416 
417  const LocalPoint localMeasurement = newHitPtr->localPosition();
418  const LocalError localMeasurementCov = newHitPtr->localPositionError();
419 
420  theMeasurements[iRow] = localMeasurement.x();
421  theMeasurements[iRow+1] = localMeasurement.y();
422  theMeasurementsCov[iRow][iRow] = localMeasurementCov.xx();
423  theMeasurementsCov[iRow][iRow+1] = localMeasurementCov.xy();
424  theMeasurementsCov[iRow+1][iRow+1] = localMeasurementCov.yy();
425  // GF: Should be a loop once the hit dimension is not hardcoded as nMeasPerHit (to be checked):
426  // for (int i = 0; i < hitPtr->dimension(); ++i) {
427  // theMeasurements[iRow+i] = hitPtr->parameters()[i]; // fixme: parameters() is by value!
428  // for (int j = i; j < hitPtr->dimension(); ++j) {
429  // theMeasurementsCov[iRow+i][iRow+j] = hitPtr->parametersError()[i][j];
430  // }
431  // }
432 }
433 
434 //__________________________________________________________________________________
435 
437  const AlgebraicMatrix &fullJacobian,
438  unsigned int iRow)
439 {
440  // derivatives of the local coordinates of the reference track w.r.t. to the inital track-parameters
441  const AlgebraicMatrix projectedJacobian(projection * fullJacobian);
442  for (int i = 0; i < parameters().num_row(); ++i) {
443  theDerivatives[iRow ][i] = projectedJacobian[0][i];
444  theDerivatives[iRow+1][i] = projectedJacobian[1][i];
445  // GF: Should be a loop once the hit dimension is not hardcoded as nMeasPerHit (to be checked):
446  // for (int j = 0; j < projection.num_col(); ++j) {
447  // theDerivatives[iRow+j][i] = projectedJacobian[j][i];
448  // }
449  }
450 }
451 
452 //__________________________________________________________________________________
453 
455  const AlgebraicVector &mixedLocalParams,
456  unsigned int iRow)
457 {
458  // get the local coordinates of the reference trajectory
459  const AlgebraicVector localPosition(projection * mixedLocalParams);
460  theTrajectoryPositions[iRow] = localPosition[0];
461  theTrajectoryPositions[iRow+1] = localPosition[1];
462  // GF: Should be a loop once the hit dimension is not hardcoded as nMeasPerHit (to be checked):
463  // for (int j = 0; j < projection.num_col(); ++j) {
464  // theTrajectoryPositions[iRow+j] = localPosition[j];
465  // }
466 }
467 
468 //__________________________________________________________________________________
469 
470 bool ReferenceTrajectory::addMaterialEffectsCov(const std::vector<AlgebraicMatrix> &allJacobians,
471  const std::vector<AlgebraicMatrix> &allProjections,
472  const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
473  const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs)
474 {
475  // the uncertainty due to multiple scattering is 'transferred' to the error matrix of the hits
476 
477  // GF: Needs update once hit dimension is not hardcoded as nMeasPerHit!
478 
479  AlgebraicSymMatrix materialEffectsCov(nMeasPerHit * allJacobians.size(), 0);
480 
481  // additional covariance-matrix of the measurements due to material-effects (single measurement)
482  AlgebraicSymMatrix deltaMaterialEffectsCov;
483 
484  // additional covariance-matrix of the parameters due to material-effects
485  AlgebraicSymMatrix paramMaterialEffectsCov(allDeltaParameterCovs[0]); //initialization
486  // error-propagation to state after energy loss
487  //GFback paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allCurvatureChanges[0]);
488 
489  AlgebraicMatrix tempParameterCov;
490  AlgebraicMatrix tempMeasurementCov;
491 
492  for (unsigned int k = 1; k < allJacobians.size(); ++k) {
493  // error-propagation to next layer
494  paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allJacobians[k]);
495 
496  // get dependences for the measurements
497  deltaMaterialEffectsCov = paramMaterialEffectsCov.similarity(allProjections[k]);
498  materialEffectsCov[nMeasPerHit*k ][nMeasPerHit*k ] = deltaMaterialEffectsCov[0][0];
499  materialEffectsCov[nMeasPerHit*k ][nMeasPerHit*k+1] = deltaMaterialEffectsCov[0][1];
500  materialEffectsCov[nMeasPerHit*k+1][nMeasPerHit*k ] = deltaMaterialEffectsCov[1][0];
501  materialEffectsCov[nMeasPerHit*k+1][nMeasPerHit*k+1] = deltaMaterialEffectsCov[1][1];
502 
503  // GFback add uncertainties for the following layers due to scattering at this layer
504  paramMaterialEffectsCov += allDeltaParameterCovs[k];
505  // end GFback
506  tempParameterCov = paramMaterialEffectsCov;
507 
508  // compute "inter-layer-dependencies"
509  for (unsigned int l = k+1; l < allJacobians.size(); ++l) {
510  tempParameterCov = allJacobians[l] * allCurvatureChanges[l] * tempParameterCov;
511  tempMeasurementCov = allProjections[l] * tempParameterCov * allProjections[k].T();
512 
513  materialEffectsCov[nMeasPerHit*l][nMeasPerHit*k] = tempMeasurementCov[0][0];
514  materialEffectsCov[nMeasPerHit*k][nMeasPerHit*l] = tempMeasurementCov[0][0];
515 
516  materialEffectsCov[nMeasPerHit*l][nMeasPerHit*k+1] = tempMeasurementCov[0][1];
517  materialEffectsCov[nMeasPerHit*k+1][nMeasPerHit*l] = tempMeasurementCov[0][1];
518 
519  materialEffectsCov[nMeasPerHit*l+1][nMeasPerHit*k] = tempMeasurementCov[1][0];
520  materialEffectsCov[nMeasPerHit*k][nMeasPerHit*l+1] = tempMeasurementCov[1][0];
521 
522  materialEffectsCov[nMeasPerHit*l+1][nMeasPerHit*k+1] = tempMeasurementCov[1][1];
523  materialEffectsCov[nMeasPerHit*k+1][nMeasPerHit*l+1] = tempMeasurementCov[1][1];
524  }
525  // add uncertainties for the following layers due to scattering at this layer
526  // GFback paramMaterialEffectsCov += allDeltaParameterCovs[k];
527  // error-propagation to state after energy loss
528  paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allCurvatureChanges[k]);
529 
530  }
531  theMeasurementsCov += materialEffectsCov;
532 
533  return true; // cannot fail
534 }
535 
536 //__________________________________________________________________________________
537 
538 bool ReferenceTrajectory::addMaterialEffectsBp(const std::vector<AlgebraicMatrix> &allJacobians,
539  const std::vector<AlgebraicMatrix> &allProjections,
540  const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
541  const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
542  const std::vector<AlgebraicMatrix> &allLocalToCurv)
543 {
544 //CHK: add material effects using break points
545  int offsetPar = theNumberOfPars;
546  int offsetMeas = nMeasPerHit * allJacobians.size();
547  int ierr = 0;
548 
549  AlgebraicMatrix tempJacobian;
550  AlgebraicMatrix MSprojection(2,5);
551  MSprojection[0][1] = 1;
552  MSprojection[1][2] = 1;
553  AlgebraicSymMatrix tempMSCov;
554  AlgebraicSymMatrix tempMSCovProj;
555  AlgebraicMatrix tempMSJacProj;
556 
557  for (unsigned int k = 1; k < allJacobians.size(); ++k) {
558 // CHK
559  int kbp = k-1;
560  tempJacobian = allJacobians[k] * allCurvatureChanges[k];
561  tempMSCov = allDeltaParameterCovs[k-1].similarity(allLocalToCurv[k-1]);
562  tempMSCovProj = tempMSCov.similarity(MSprojection);
563  theMeasurementsCov[offsetMeas+nMeasPerHit*kbp ][offsetMeas+nMeasPerHit*kbp ] = tempMSCovProj[0][0];
564  theMeasurementsCov[offsetMeas+nMeasPerHit*kbp+1][offsetMeas+nMeasPerHit*kbp+1]= tempMSCovProj[1][1];
565  theDerivatives[offsetMeas+nMeasPerHit*kbp ][offsetPar+2*kbp ] = 1.0;
566  theDerivatives[offsetMeas+nMeasPerHit*kbp+1][offsetPar+2*kbp+1] = 1.0 ;
567 
568  tempMSJacProj = (allProjections[k] * ( tempJacobian * allLocalToCurv[k-1].inverse(ierr) )) * MSprojection.T();
569  if (ierr) {
570  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBp"
571  << "Inversion 1 for break points failed: " << ierr;
572  return false;
573  }
574  theDerivatives[nMeasPerHit*k ][offsetPar+2*kbp ] = tempMSJacProj[0][0];
575  theDerivatives[nMeasPerHit*k ][offsetPar+2*kbp+1] = tempMSJacProj[0][1];
576  theDerivatives[nMeasPerHit*k+1][offsetPar+2*kbp ] = tempMSJacProj[1][0];
577  theDerivatives[nMeasPerHit*k+1][offsetPar+2*kbp+1] = tempMSJacProj[1][1];
578 
579  for (unsigned int l = k+1; l < allJacobians.size(); ++l) {
580 // CHK
581  int kbp = k-1;
582  tempJacobian = allJacobians[l] * allCurvatureChanges[l] * tempJacobian;
583  tempMSJacProj = (allProjections[l] * ( tempJacobian * allLocalToCurv[k-1].inverse(ierr) )) * MSprojection.T();
584  if (ierr) {
585  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBp"
586  << "Inversion 2 for break points failed: " << ierr;
587  return false;
588  }
589  theDerivatives[nMeasPerHit*l ][offsetPar+2*kbp ] = tempMSJacProj[0][0];
590  theDerivatives[nMeasPerHit*l ][offsetPar+2*kbp+1] = tempMSJacProj[0][1];
591  theDerivatives[nMeasPerHit*l+1][offsetPar+2*kbp ] = tempMSJacProj[1][0];
592  theDerivatives[nMeasPerHit*l+1][offsetPar+2*kbp+1] = tempMSJacProj[1][1];
593 
594  }
595 
596  }
597 
598  return true;
599 }
600 
601 //__________________________________________________________________________________
602 
603 bool ReferenceTrajectory::addMaterialEffectsBrl(const std::vector<AlgebraicMatrix> &allCurvlinJacobians,
604  const std::vector<AlgebraicMatrix> &allProjections,
605  const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
606  const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
607  const std::vector<AlgebraicMatrix> &allLocalToCurv,
608  const GlobalTrajectoryParameters &gtp)
609 {
610 //CHK: add material effects using broken lines
611 //fine: use exact Jacobians, all detectors
612 //broken lines: pair of offsets (u1,u2) = (xt,yt) (in curvilinear frame (q/p,lambda,phi,xt,yt)) at each layer
613 // scattering angles (alpha1,alpha2) = (cosLambda*dPhi, dLambda) (cosLambda cancels in Chi2)
614 // DU' = (dU'/dU)*DU + (dU'/dAlpha)*DAlpha + (dU'/dQbyp)*DQbyp (propagation of U)
615 // = J*DU + S*DAlpha + d*DQbyp
616 // => DAlpha = S^-1 (DU' - J*DU - d*DQbyp)
617 
618  int offsetPar = theNumberOfPars;
619  int offsetMeas = nMeasPerHit*allCurvlinJacobians.size();
620  int ierr = 0;
621 
622  GlobalVector p = gtp.momentum();
623  double cosLambda = sqrt((p.x()*p.x()+p.y()*p.y())/(p.x()*p.x()+p.y()*p.y()+p.z()*p.z()));
624 
625 // transformations Curvilinear <-> BrokenLines
626  AlgebraicMatrix QbypToCurv(5,1); // dCurv/dQbyp
627  QbypToCurv[0][0] = 1.; // dQbyp/dQbyp
628  AlgebraicMatrix AngleToCurv(5,2); // dCurv/dAlpha
629  AngleToCurv[1][1] = 1.; // dlambda/dalpha2
630  AngleToCurv[2][0] = 1./cosLambda; // dphi/dalpha1
631  AlgebraicMatrix CurvToAngle(2,5); // dAlpha/dCurv
632  CurvToAngle[1][1] = 1.; // dalpha2/dlambda
633  CurvToAngle[0][2] = cosLambda; // dalpha1/dphi
634  AlgebraicMatrix OffsetToCurv(5,2); // dCurv/dU
635  OffsetToCurv[3][0] = 1.; // dxt/du1
636  OffsetToCurv[4][1] = 1.; // dyt/du2
637  AlgebraicMatrix CurvToOffset(2,5); // dU/dCurv
638  CurvToOffset[0][3] = 1.; // du1/dxt
639  CurvToOffset[1][4] = 1.; // du2/dyt
640 
641 // transformations trajectory to components (Qbyp, U1, U2)
642  AlgebraicMatrix TrajToQbyp(1,5);
643  TrajToQbyp[0][0] = 1.;
644  AlgebraicMatrix TrajToOff1(2,5);
645  TrajToOff1[0][1] = 1.;
646  TrajToOff1[1][2] = 1.;
647  AlgebraicMatrix TrajToOff2(2,5);
648  TrajToOff2[0][3] = 1.;
649  TrajToOff2[1][4] = 1.;
650 
651  AlgebraicMatrix JacOffsetToAngleC, JacQbypToAngleC;
652  AlgebraicMatrix JacCurvToOffsetL, JacOffsetToOffsetL, JacAngleToOffsetL, JacQbypToOffsetL, JacOffsetToAngleL;
653  AlgebraicMatrix JacCurvToOffsetN, JacOffsetToOffsetN, JacAngleToOffsetN, JacQbypToOffsetN, JacOffsetToAngleN;
654 
655 // transformation from trajectory to curvilinear parameters
656 
657  JacCurvToOffsetN = CurvToOffset * allCurvlinJacobians[1]; // (dU'/dCurv') * (dCurv'/dCurv) @ 2nd point
658  JacOffsetToOffsetN = JacCurvToOffsetN * OffsetToCurv; // J: (dU'/dU) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dU)
659  JacAngleToOffsetN = JacCurvToOffsetN * AngleToCurv; // S: (dU'/dAlpha) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dAlpha)
660  JacQbypToOffsetN = JacCurvToOffsetN * QbypToCurv; // d: (dU'/dQbyp) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dQbyp)
661  JacOffsetToAngleN = JacAngleToOffsetN.inverse(ierr); // W
662  if (ierr) {
663  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
664  << "Inversion 1 for fine broken lines failed: " << ierr;
665  return false;
666  }
667  JacOffsetToAngleC = -(JacOffsetToAngleN * JacOffsetToOffsetN); // (dAlpha/dU)
668  JacQbypToAngleC = -(JacOffsetToAngleN * JacQbypToOffsetN); // (dAlpha/dQbyp)
669  // (dAlpha/dTraj) = (dAlpha/dQbyp) * (dQbyp/dTraj) + (dAlpha/dU1) * (dU1/dTraj) + (dAlpha/dU2) * (dU2/dTraj)
670  AlgebraicMatrix JacTrajToAngle = JacQbypToAngleC * TrajToQbyp + JacOffsetToAngleC * TrajToOff1 + JacOffsetToAngleN * TrajToOff2;
671  // (dCurv/dTraj) = (dCurv/dQbyp) * (dQbyp/dTraj) + (dCurv/dAlpha) * (dAlpha/dTraj) + (dCurv/dU) * (dU/dTraj)
672  theInnerTrajectoryToCurvilinear = QbypToCurv * TrajToQbyp + AngleToCurv * JacTrajToAngle + OffsetToCurv * TrajToOff1;
673  theInnerLocalToTrajectory = theInnerTrajectoryToCurvilinear.inverse(ierr) * allLocalToCurv[0];
674  if (ierr) {
675  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
676  << "Inversion 2 for fine broken lines failed: " << ierr;
677  return false;
678  }
679 
680  AlgebraicMatrix tempJacobian(allCurvatureChanges[0]);
681  AlgebraicSymMatrix tempMSCov;
682  AlgebraicSymMatrix tempMSCovProj;
683  AlgebraicMatrix tempJacL, tempJacN;
684  AlgebraicMatrix JacOffsetToMeas;
685 
686 // measurements from hits
687  for (unsigned int k = 0; k < allCurvlinJacobians.size(); ++k) {
688 // (dMeas/dU) = (dMeas/dLoc) * (dLoc/dCurv) * (dCurv/dU)
689  JacOffsetToMeas = (allProjections[k] * allLocalToCurv[k].inverse(ierr) ) * OffsetToCurv;
690  if (ierr) {
691  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
692  << "Inversion 3 for fine broken lines failed: " << ierr;
693  return false;
694  }
695  theDerivatives[nMeasPerHit*k ][offsetPar+2*k ] = JacOffsetToMeas[0][0];
696  theDerivatives[nMeasPerHit*k ][offsetPar+2*k+1] = JacOffsetToMeas[0][1];
697  theDerivatives[nMeasPerHit*k+1][offsetPar+2*k ] = JacOffsetToMeas[1][0];
698  theDerivatives[nMeasPerHit*k+1][offsetPar+2*k+1] = JacOffsetToMeas[1][1];
699  }
700 
701 // measurement of MS kink
702  for (unsigned int k = 1; k < allCurvlinJacobians.size()-1; ++k) {
703 // CHK
704  int iMsMeas = k-1;
705  int l = k-1; // last hit
706  int n = k+1; // next hit
707 
708 // amount of multiple scattering in layer k (angular error perp to direction)
709  tempMSCov = allDeltaParameterCovs[k].similarity(allLocalToCurv[k]);
710  tempMSCovProj = tempMSCov.similarity(CurvToAngle);
711  theMeasurementsCov[offsetMeas+nMeasPerHit*iMsMeas ][offsetMeas+nMeasPerHit*iMsMeas ] = tempMSCovProj[1][1];
712  theMeasurementsCov[offsetMeas+nMeasPerHit*iMsMeas+1][offsetMeas+nMeasPerHit*iMsMeas+1] = tempMSCovProj[0][0];
713 
714 // transformation matices for offsets ( l <- k -> n )
715  tempJacL = allCurvlinJacobians[k] * tempJacobian;
716  JacCurvToOffsetL = CurvToOffset * tempJacL.inverse(ierr); // (dU'/dCurv') * (dCurv'/dCurv) @ last point
717 
718  if (ierr) {
719  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
720  << "Inversion 4 for fine broken lines failed: " << ierr;
721  return false;
722  }
723  JacOffsetToOffsetL = JacCurvToOffsetL * OffsetToCurv; // J-: (dU'/dU) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dU)
724  JacAngleToOffsetL = JacCurvToOffsetL * AngleToCurv; // S-: (dU'/dAlpha) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dAlpha)
725  JacQbypToOffsetL = JacCurvToOffsetL * QbypToCurv; // d-: (dU'/dQbyp) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dQbyp)
726  JacOffsetToAngleL =-JacAngleToOffsetL.inverse(ierr); // W-
727  if (ierr) {
728  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
729  << "Inversion 5 for fine broken lines failed: " << ierr;
730  return false;
731  }
732  tempJacobian = tempJacobian * allCurvatureChanges[k];
733  tempJacN = allCurvlinJacobians[n] * tempJacobian;
734  JacCurvToOffsetN = CurvToOffset * tempJacN; // (dU'/dCurv') * (dCurv'/dCurv) @ next point
735  JacOffsetToOffsetN = JacCurvToOffsetN * OffsetToCurv; // J+: (dU'/dU) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dU)
736  JacAngleToOffsetN = JacCurvToOffsetN * AngleToCurv; // S+: (dU'/dAlpha) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dAlpha)
737  JacQbypToOffsetN = JacCurvToOffsetN * QbypToCurv; // d+: (dU'/dQbyp) = (dU'/dCurv') * (dCurv'/dCurv) * (dCurv/dQbyp)
738  JacOffsetToAngleN = JacAngleToOffsetN.inverse(ierr); // W+
739  if (ierr) {
740  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
741  << "Inversion 6 for fine broken lines failed: " << ierr;
742  return false;
743  }
744  JacOffsetToAngleC = -(JacOffsetToAngleL * JacOffsetToOffsetL + JacOffsetToAngleN * JacOffsetToOffsetN);
745  JacQbypToAngleC = -(JacOffsetToAngleL * JacQbypToOffsetL + JacOffsetToAngleN * JacQbypToOffsetN);
746 
747  // bending
748  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][ 0] = JacQbypToAngleC[0][0];
749  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][ 0] = JacQbypToAngleC[1][0];
750  // last layer
751  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*l ] = JacOffsetToAngleL[0][0];
752  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*l+1] = JacOffsetToAngleL[0][1];
753  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*l ] = JacOffsetToAngleL[1][0];
754  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*l+1] = JacOffsetToAngleL[1][1];
755  // current layer
756  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*k ] = JacOffsetToAngleC[0][0];
757  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*k+1] = JacOffsetToAngleC[0][1];
758  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*k ] = JacOffsetToAngleC[1][0];
759  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*k+1] = JacOffsetToAngleC[1][1];
760 
761  // next layer
762  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*n ] = JacOffsetToAngleN[0][0];
763  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*n+1] = JacOffsetToAngleN[0][1];
764  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*n ] = JacOffsetToAngleN[1][0];
765  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*n+1] = JacOffsetToAngleN[1][1];
766 
767  }
768 
769  return true;
770 }
771 
772 //__________________________________________________________________________________
773 
774 bool ReferenceTrajectory::addMaterialEffectsBrl(const std::vector<AlgebraicMatrix> &allProjections,
775  const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
776  const std::vector<AlgebraicMatrix> &allLocalToCurv,
777  const std::vector<double> &allSteps,
778  const GlobalTrajectoryParameters &gtp,
779  const double minStep)
780 {
781 //CHK: add material effects using broken lines
782 //BrokenLinesCoarse: combine close by detectors,
783 // use approximate Jacobians from Steps (limit Qbyp -> 0),
784 // bending only in RPhi (B=(0,0,Bz)), no energy loss correction
785 
786  int offsetPar = theNumberOfPars;
787  int offsetMeas = nMeasPerHit*allSteps.size();
788  int ierr = 0;
789 
790  GlobalVector p = gtp.momentum();
791  double cosLambda = sqrt((p.x()*p.x()+p.y()*p.y())/(p.x()*p.x()+p.y()*p.y()+p.z()*p.z()));
792  double bFac = -gtp.magneticFieldInInverseGeV(gtp.position()).mag();
793 
794  // transformation from trajectory to curvilinear parameters at refTsos
795  double delta (1.0/allSteps[1]);
799  theInnerTrajectoryToCurvilinear[2][0] = -0.5*bFac/delta;
800  theInnerTrajectoryToCurvilinear[2][1] = -delta/cosLambda;
801  theInnerTrajectoryToCurvilinear[2][3] = delta/cosLambda;
804  theInnerLocalToTrajectory = theInnerTrajectoryToCurvilinear.inverse(ierr) * allLocalToCurv[0];
805  if (ierr) {
806  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
807  << "Inversion 1 for coarse broken lines failed: " << ierr;
808  return false;
809  }
810 
811  AlgebraicMatrix CurvToAngle(2,5); // dAlpha/dCurv
812  CurvToAngle[1][1] = 1.; // dalpha2/dlambda
813  CurvToAngle[0][2] = cosLambda; // dalpha1/dphi
814  AlgebraicMatrix OffsetToCurv(5,2); // dCurv/dU
815  OffsetToCurv[3][0] = 1.; // dxt/du1
816  OffsetToCurv[4][1] = 1.; // dyt/du2
817 
818  AlgebraicSymMatrix tempMSCov;
819  AlgebraicSymMatrix tempMSCovProj;
820  AlgebraicMatrix JacOffsetToMeas;
821 
822  // combine closeby detectors into single plane
823  std::vector<unsigned int> first(allSteps.size());
824  std::vector<unsigned int> last (allSteps.size());
825  std::vector<unsigned int> plane(allSteps.size());
826  std::vector<double> sPlane(allSteps.size());
827  unsigned int nPlane = 0;
828  double sTot = 0;
829 
830  for (unsigned int k = 1; k < allSteps.size(); ++k) {
831  sTot += allSteps[k];
832  if (fabs(allSteps[k])>minStep) { nPlane += 1; first[nPlane] = k; }
833  last[nPlane] = k;
834  plane[k] = nPlane;
835  sPlane[nPlane] += sTot;
836  }
837  if (nPlane < 2) return false; // pathological cases: need at least 2 planes
838 
839  theNumberOfVirtualPars = 2*(nPlane+1);
840  theNumberOfVirtualMeas = 2*(nPlane-1);// unsigned underflow for nPlane == 0...
841  for (unsigned int k = 0; k <= nPlane; ++k) { sPlane[k] /= (double) (last[k]-first[k]+1); }
842 
843  // measurements from hits
844  sTot = 0;
845  for (unsigned int k = 0; k < allSteps.size(); ++k) {
846  sTot += allSteps[k];
847 // (dMeas/dU) = (dMeas/dLoc) * (dLoc/dCurv) * (dCurv/dU)
848  JacOffsetToMeas = (allProjections[k] * allLocalToCurv[k].inverse(ierr) ) * OffsetToCurv;
849  if (ierr) {
850  edm::LogError("Alignment") << "@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
851  << "Inversion 2 for coarse broken lines failed: " << ierr;
852  return false;
853  }
854 
855  unsigned int iPlane = plane[k];
856  if (last[iPlane] == first[iPlane])
857  { // single plane
858  theDerivatives[nMeasPerHit*k ][offsetPar+2*iPlane ] = JacOffsetToMeas[0][0];
859  theDerivatives[nMeasPerHit*k ][offsetPar+2*iPlane+1] = JacOffsetToMeas[0][1];
860  theDerivatives[nMeasPerHit*k+1][offsetPar+2*iPlane ] = JacOffsetToMeas[1][0];
861  theDerivatives[nMeasPerHit*k+1][offsetPar+2*iPlane+1] = JacOffsetToMeas[1][1];
862  } else
863  { // combined plane: (linear) interpolation
864  unsigned int jPlane; // neighbor plane for interpolation
865  if (fabs(sTot) < fabs(sPlane[iPlane])) { jPlane = (iPlane>0) ? iPlane - 1 : 1; }
866  else { jPlane = (iPlane<nPlane) ? iPlane + 1 : nPlane -1 ;}
867  // interpolation weights
868  double sDiff = sPlane[iPlane] - sPlane[jPlane];
869  double iFrac = (sTot - sPlane[jPlane]) / sDiff;
870  double jFrac = 1.0 - iFrac;
871  theDerivatives[nMeasPerHit*k ][offsetPar+2*iPlane ] = JacOffsetToMeas[0][0]*iFrac;
872  theDerivatives[nMeasPerHit*k ][offsetPar+2*iPlane+1] = JacOffsetToMeas[0][1]*iFrac;
873  theDerivatives[nMeasPerHit*k+1][offsetPar+2*iPlane ] = JacOffsetToMeas[1][0]*iFrac;
874  theDerivatives[nMeasPerHit*k+1][offsetPar+2*iPlane+1] = JacOffsetToMeas[1][1]*iFrac;
875  theDerivatives[nMeasPerHit*k ][offsetPar+2*jPlane ] = JacOffsetToMeas[0][0]*jFrac;
876  theDerivatives[nMeasPerHit*k ][offsetPar+2*jPlane+1] = JacOffsetToMeas[0][1]*jFrac;
877  theDerivatives[nMeasPerHit*k+1][offsetPar+2*jPlane ] = JacOffsetToMeas[1][0]*jFrac;
878  theDerivatives[nMeasPerHit*k+1][offsetPar+2*jPlane+1] = JacOffsetToMeas[1][1]*jFrac;
879  // 2nd order neglected
880  // theDerivatives[nMeasPerHit*k ][ 0] = -0.5*bFac*sDiff*iFrac*sDiff*jFrac*cosLambda;
881  }
882  }
883 
884 // measurement of MS kink
885  for (unsigned int i = 1; i < nPlane; ++i) {
886 // CHK
887  int iMsMeas = i-1;
888  int l = i-1; // last hit
889  int n = i+1; // next hit
890 
891 // amount of multiple scattering in plane k
892  for (unsigned int k = first[i]; k <= last[i]; ++k) {
893  tempMSCov = allDeltaParameterCovs[k].similarity(allLocalToCurv[k]);
894  tempMSCovProj = tempMSCov.similarity(CurvToAngle);
895  theMeasurementsCov[offsetMeas+nMeasPerHit*iMsMeas ][offsetMeas+nMeasPerHit*iMsMeas ] += tempMSCovProj[0][0];
896  theMeasurementsCov[offsetMeas+nMeasPerHit*iMsMeas+1][offsetMeas+nMeasPerHit*iMsMeas+1] += tempMSCovProj[1][1];
897  }
898 // broken line measurements for layer k, correlations between both planes neglected
899  double stepK = sPlane[i] - sPlane[l];
900  double stepN = sPlane[n] - sPlane[i];
901  double deltaK (1.0/stepK);
902  double deltaN (1.0/stepN);
903  // bending (only in RPhi)
904  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][ 0] = -0.5*bFac*(stepK+stepN)*cosLambda;
905  // last layer
906  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*l ] = deltaK;
907  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*l+1] = deltaK;
908  // current layer
909  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*i ] = -(deltaK + deltaN);
910  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*i+1] = -(deltaK + deltaN);
911  // next layer
912  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas ][offsetPar+2*n ] = deltaN;
913  theDerivatives[offsetMeas+nMeasPerHit*iMsMeas+1][offsetPar+2*n+1] = deltaN;
914  }
915 
916  return true;
917 }
918 
919 //__________________________________________________________________________________
920 
924 {
925  if (this->useRecHit(hitPtr)) {
926  // check which templated non-member function to call:
927  switch (hitPtr->dimension()) {
928  case 1:
929  return getHitProjectionMatrixT<1>(hitPtr);
930  case 2:
931  return getHitProjectionMatrixT<2>(hitPtr);
932  case 3:
933  return getHitProjectionMatrixT<3>(hitPtr);
934  case 4:
935  return getHitProjectionMatrixT<4>(hitPtr);
936  case 5:
937  return getHitProjectionMatrixT<5>(hitPtr);
938  default:
939  throw cms::Exception("ReferenceTrajectory::getHitProjectionMatrix")
940  << "Unexpected hit dimension: " << hitPtr->dimension() << "\n";
941  }
942  }
943  // invalid or (to please compiler) unknown dimension
944  return AlgebraicMatrix(2, 5, 0); // get size from ???
945 }
946 
947 //__________________________________________________________________________________
948 
949 template<unsigned int N>
953 {
954  // define variables that will be used to setup the KfComponentsHolder
955  // (their allocated memory is needed by 'hitPtr->getKfComponents(..)'
956  // ProjectMatrix<double,5,N> pf; // not needed
958  typename AlgebraicROOTObject<N>::Vector r, rMeas;
959  typename AlgebraicROOTObject<N,N>::SymMatrix V, VMeas;
960  // input for the holder - but dummy is OK here to just get the projection matrix:
961  const AlgebraicVector5 dummyPars;
962  const AlgebraicSymMatrix55 dummyErr;
963 
964  // setup the holder with the correct dimensions and get the values
965  KfComponentsHolder holder;
966  holder.setup<N>(&r, &V, &H, /*&pf,*/ &rMeas, &VMeas, dummyPars, dummyErr);
967  hitPtr->getKfComponents(holder);
968 
969  return asHepMatrix<N,5>(holder.projection<N>());
970 }
971 
dbl * delta
Definition: mlp_gen.cc:36
AlgebraicMatrix theInnerTrajectoryToCurvilinear
double z0() const
z coordinate
Definition: BeamSpot.h:68
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:24
AlgebraicMatrix getHitProjectionMatrix(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
ROOT::Math::SMatrix< double, D1, D1, ROOT::Math::MatRepSym< double, D1 > > SymMatrix
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:69
T y() const
Definition: PV3DBase.h:63
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
PropagationDirection
SurfaceSide surfaceSide(const PropagationDirection dir) const
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
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
Definition: Plane.h:17
virtual bool propagate(const Plane &previousSurface, const TrajectoryStateOnSurface &previousTsos, const Plane &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:84
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:77
ROOT::Math::SMatrix< double, D1, D2, ROOT::Math::MatRepStd< double, D1, D2 > > Matrix
float xy() const
Definition: LocalError.h:25
const SurfaceType & surface() const
CLHEP::HepMatrix AlgebraicMatrix
float yy() const
Definition: LocalError.h:26
T sqrt(T t)
Definition: SSEVec.h:48
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)
static PlanePointer build(Args &&...args)
Definition: Plane.h:36
FreeTrajectoryState const * freeState(bool withErrors=true) 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:64
MaterialEffectsUpdator * createUpdator(MaterialEffects materialEffects, double mass) const
void setup(typename AlgebraicROOTObject< D >::Vector *params, typename AlgebraicROOTObject< D, D >::SymMatrix *errors, typename AlgebraicROOTObject< D, 5 >::Matrix *projection, ProjectMatrix< double, 5, D > *projFunc, typename AlgebraicROOTObject< D >::Vector *measuredParams, typename AlgebraicROOTObject< D, D >::SymMatrix *measuredErrors, const AlgebraicVector5 &tsosLocalParameters, const AlgebraicSymMatrix55 &tsosLocalErrors)
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:82
TransientTrackingRecHit::ConstRecHitContainer theRecHits
int k[5][pyjets_maxn]
AlgebraicSymMatrix theMeasurementsCov
AlgebraicMatrix getHitProjectionMatrixT(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
const AlgebraicVector & parameters() const
CLHEP::HepVector AlgebraicVector
ROOT::Math::SVector< double, D1 > Vector
#define N
Definition: blowfish.cc:9
ROOT::Math::SVector< double, 5 > AlgebraicVector5
const GlobalTrajectoryParameters & globalParameters() const
AlgebraicVector5 mixedFormatVector() const
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::vector< TrajectoryStateOnSurface > theTsosVec
double y0() const
y coordinate
Definition: BeamSpot.h:66
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
AlgebraicROOTObject< D, 5 >::Matrix & projection()
T x() const
Definition: PV3DBase.h:62
double signedInverseMomentum() const
Signed inverse momentum q/p (zero for neutrals).
tuple size
Write out results.
double x0() const
x coordinate
Definition: BeamSpot.h:64