50 &recHits,
bool hitsAreReverse,
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) )
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);
78 useBeamSpot, beamSpot);
82 useBeamSpot, beamSpot);
92 (materialEffects >= brokenLinesCoarse) ? 1 : nPar,
94 (materialEffects >= brokenLinesCoarse) ? 2*nHits : ( (materialEffects == breakPoints) ? 2*nHits-2 : 0 ),
95 (materialEffects >= brokenLinesCoarse) ? 2*nHits-4 : ( (materialEffects == breakPoints) ? 2*nHits-2 : 0 ) )
113 std::auto_ptr<MaterialEffectsUpdator> aMaterialEffectsUpdator
115 if (!aMaterialEffectsUpdator.get())
return false;
118 std::vector<AlgebraicMatrix> allJacobians;
124 std::vector<AlgebraicSymMatrix> allCurvatureChanges;
129 std::vector<AlgebraicMatrix> allProjections;
131 std::vector<AlgebraicSymMatrix> allDeltaParameterCovs;
135 std::vector<AlgebraicMatrix> allLocalToCurv;
137 std::vector<double> allSteps;
139 std::vector<AlgebraicMatrix> allCurvlinJacobians;
144 unsigned int iRow = 0;
159 std::pair< TrajectoryStateOnSurface, double > tsosWithPath =
162 if (!tsosWithPath.first.isValid())
return false;
177 allRecHits.push_back(bsRecHit);
182 TransientTrackingRecHit::ConstRecHitContainer::const_iterator itRecHit;
183 for ( itRecHit = recHits.begin(); itRecHit != recHits.end(); ++itRecHit ) {
185 allRecHits.push_back(hitPtr);
188 for ( itRecHit = allRecHits.begin(); itRecHit != allRecHits.end(); ++itRecHit ) {
198 allJacobians.push_back(fullJacobian);
201 const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
206 allLocalToCurv.push_back(localToCurvilinear);
207 allSteps.push_back(0.);
208 allCurvlinJacobians.push_back(firstCurvlinJacobian);
214 double nextStep = 0.;
217 if (!this->
propagate(previousHitPtr->det()->surface(), previousTsos,
218 hitPtr->det()->surface(), nextTsos,
219 nextJacobian, nextCurvlinJacobian, nextStep, propDir, magField)) {
223 allJacobians.push_back(nextJacobian);
224 fullJacobian = nextJacobian * previousChangeInCurvature * fullJacobian;
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() <<
".";
236 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::construct" <<
"Skip track.";
240 allSteps.push_back(nextStep);
241 allCurvlinJacobians.push_back(nextCurvlinJacobian);
251 if ( !updatedTsos.isValid() )
return false;
253 if (
theTsosVec.back().localParameters().charge() )
256 /
theTsosVec.back().localParameters().signedInverseMomentum();
260 allDeltaParameterCovs.push_back( asHepMatrix<5>(updatedTsos.localError().matrix()) );
261 allCurvatureChanges.push_back(previousChangeInCurvature);
264 if (
useRecHit( hitPtr ) ) { allProjections.push_back( hitPtr->projectionMatrix() ); }
269 previousHitPtr = hitPtr;
285 switch (materialEffects) {
292 allDeltaParameterCovs);
296 allDeltaParameterCovs, allLocalToCurv);
306 if (!msOK)
return false;
329 switch (materialEffects) {
366 const std::pair<TrajectoryStateOnSurface, double> tsosWithPath =
370 if (!tsosWithPath.first.isValid())
return false;
372 nextStep = tsosWithPath.second;
376 tsosWithPath.first.globalPosition(),
377 tsosWithPath.first.globalMomentum(),
378 tsosWithPath.second);
379 const AlgebraicMatrix curvilinearJacobian = asHepMatrix<5,5>(aJacobian.jacobian());
383 const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
387 const AlgebraicMatrix curvilinearToLocal = asHepMatrix<5>(endTrafo.jacobian());
391 newCurvlinJacobian = curvilinearJacobian;
392 newJacobian = curvilinearToLocal * curvilinearJacobian * localToCurvilinear;
393 newTsos = tsosWithPath.first;
411 hitPtr->clone(updatedTsos) : hitPtr);
413 const LocalPoint localMeasurement = newHitPtr->localPosition();
414 const LocalError localMeasurementCov = newHitPtr->localPositionError();
467 const std::vector<AlgebraicMatrix> &allProjections,
468 const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
469 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs)
488 for (
unsigned int k = 1;
k < allJacobians.size(); ++
k) {
490 paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allJacobians[
k]);
493 deltaMaterialEffectsCov = paramMaterialEffectsCov.similarity(allProjections[k]);
500 paramMaterialEffectsCov += allDeltaParameterCovs[
k];
502 tempParameterCov = paramMaterialEffectsCov;
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();
524 paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allCurvatureChanges[k]);
535 const std::vector<AlgebraicMatrix> &allProjections,
536 const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
537 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
538 const std::vector<AlgebraicMatrix> &allLocalToCurv)
542 int offsetMeas =
nMeasPerHit * allJacobians.size();
547 MSprojection[0][1] = 1;
548 MSprojection[1][2] = 1;
553 for (
unsigned int k = 1;
k < allJacobians.size(); ++
k) {
556 tempJacobian = allJacobians[
k] * allCurvatureChanges[
k];
557 tempMSCov = allDeltaParameterCovs[
k-1].similarity(allLocalToCurv[
k-1]);
558 tempMSCovProj = tempMSCov.similarity(MSprojection);
564 tempMSJacProj = (allProjections[
k] * ( tempJacobian * allLocalToCurv[
k-1].inverse(ierr) )) * MSprojection.T();
566 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBp"
567 <<
"Inversion 1 for break points failed: " << ierr;
575 for (
unsigned int l =
k+1;
l < allJacobians.size(); ++
l) {
578 tempJacobian = allJacobians[
l] * allCurvatureChanges[
l] * tempJacobian;
579 tempMSJacProj = (allProjections[
l] * ( tempJacobian * allLocalToCurv[
k-1].inverse(ierr) )) * MSprojection.T();
581 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBp"
582 <<
"Inversion 2 for break points failed: " << ierr;
600 const std::vector<AlgebraicMatrix> &allProjections,
601 const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
602 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
603 const std::vector<AlgebraicMatrix> &allLocalToCurv,
615 int offsetMeas =
nMeasPerHit*allCurvlinJacobians.size();
619 double cosLambda =
sqrt((p.
x()*p.
x()+p.
y()*p.
y())/(p.
x()*p.
x()+p.
y()*p.
y()+p.
z()*p.
z()));
623 QbypToCurv[0][0] = 1.;
625 AngleToCurv[1][1] = 1.;
626 AngleToCurv[2][0] = 1./cosLambda;
628 CurvToAngle[1][1] = 1.;
629 CurvToAngle[0][2] = cosLambda;
631 OffsetToCurv[3][0] = 1.;
632 OffsetToCurv[4][1] = 1.;
634 CurvToOffset[0][3] = 1.;
635 CurvToOffset[1][4] = 1.;
639 TrajToQbyp[0][0] = 1.;
641 TrajToOff1[0][1] = 1.;
642 TrajToOff1[1][2] = 1.;
644 TrajToOff2[0][3] = 1.;
645 TrajToOff2[1][4] = 1.;
648 AlgebraicMatrix JacCurvToOffsetL, JacOffsetToOffsetL, JacAngleToOffsetL, JacQbypToOffsetL, JacOffsetToAngleL;
649 AlgebraicMatrix JacCurvToOffsetN, JacOffsetToOffsetN, JacAngleToOffsetN, JacQbypToOffsetN, JacOffsetToAngleN;
653 JacCurvToOffsetN = CurvToOffset * allCurvlinJacobians[1];
654 JacOffsetToOffsetN = JacCurvToOffsetN * OffsetToCurv;
655 JacAngleToOffsetN = JacCurvToOffsetN * AngleToCurv;
656 JacQbypToOffsetN = JacCurvToOffsetN * QbypToCurv;
657 JacOffsetToAngleN = JacAngleToOffsetN.inverse(ierr);
659 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
660 <<
"Inversion 1 for fine broken lines failed: " << ierr;
663 JacOffsetToAngleC = -(JacOffsetToAngleN * JacOffsetToOffsetN);
664 JacQbypToAngleC = -(JacOffsetToAngleN * JacQbypToOffsetN);
666 AlgebraicMatrix JacTrajToAngle = JacQbypToAngleC * TrajToQbyp + JacOffsetToAngleC * TrajToOff1 + JacOffsetToAngleN * TrajToOff2;
671 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
672 <<
"Inversion 2 for fine broken lines failed: " << ierr;
683 for (
unsigned int k = 0;
k < allCurvlinJacobians.size(); ++
k) {
685 JacOffsetToMeas = (allProjections[
k] * allLocalToCurv[
k].inverse(ierr) ) * OffsetToCurv;
687 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
688 <<
"Inversion 3 for fine broken lines failed: " << ierr;
698 for (
unsigned int k = 1;
k < allCurvlinJacobians.size()-1; ++
k) {
705 tempMSCov = allDeltaParameterCovs[
k].similarity(allLocalToCurv[
k]);
706 tempMSCovProj = tempMSCov.similarity(CurvToAngle);
711 tempJacL = allCurvlinJacobians[
k] * tempJacobian;
712 JacCurvToOffsetL = CurvToOffset * tempJacL.inverse(ierr);
715 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
716 <<
"Inversion 4 for fine broken lines failed: " << ierr;
719 JacOffsetToOffsetL = JacCurvToOffsetL * OffsetToCurv;
720 JacAngleToOffsetL = JacCurvToOffsetL * AngleToCurv;
721 JacQbypToOffsetL = JacCurvToOffsetL * QbypToCurv;
722 JacOffsetToAngleL =-JacAngleToOffsetL.inverse(ierr);
724 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
725 <<
"Inversion 5 for fine broken lines failed: " << ierr;
728 tempJacobian = tempJacobian * allCurvatureChanges[
k];
729 tempJacN = allCurvlinJacobians[
n] * tempJacobian;
730 JacCurvToOffsetN = CurvToOffset * tempJacN;
731 JacOffsetToOffsetN = JacCurvToOffsetN * OffsetToCurv;
732 JacAngleToOffsetN = JacCurvToOffsetN * AngleToCurv;
733 JacQbypToOffsetN = JacCurvToOffsetN * QbypToCurv;
734 JacOffsetToAngleN = JacAngleToOffsetN.inverse(ierr);
736 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
737 <<
"Inversion 6 for fine broken lines failed: " << ierr;
740 JacOffsetToAngleC = -(JacOffsetToAngleL * JacOffsetToOffsetL + JacOffsetToAngleN * JacOffsetToOffsetN);
741 JacQbypToAngleC = -(JacOffsetToAngleL * JacQbypToOffsetL + JacOffsetToAngleN * JacQbypToOffsetN);
769 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
770 const std::vector<AlgebraicMatrix> &allLocalToCurv,
771 const std::vector<double> &allSteps,
773 const double minStep)
785 double cosLambda =
sqrt((p.
x()*p.
x()+p.
y()*p.
y())/(p.
x()*p.
x()+p.
y()*p.
y()+p.
z()*p.
z()));
789 double delta (1.0/allSteps[1]);
800 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
801 <<
"Inversion 1 for coarse broken lines failed: " << ierr;
806 CurvToAngle[1][1] = 1.;
807 CurvToAngle[0][2] = cosLambda;
809 OffsetToCurv[3][0] = 1.;
810 OffsetToCurv[4][1] = 1.;
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;
824 for (
unsigned int k = 1;
k < allSteps.size(); ++
k) {
826 if (fabs(allSteps[
k])>minStep) { nPlane += 1;
first[nPlane] =
k; }
829 sPlane[nPlane] += sTot;
831 if (nPlane < 2)
return false;
835 for (
unsigned int k = 0;
k <= nPlane; ++
k) { sPlane[
k] /= (double) (
last[
k]-
first[
k]+1); }
839 for (
unsigned int k = 0;
k < allSteps.size(); ++
k) {
842 JacOffsetToMeas = (allProjections[
k] * allLocalToCurv[
k].inverse(ierr) ) * OffsetToCurv;
844 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
845 <<
"Inversion 2 for coarse broken lines failed: " << ierr;
849 unsigned int iPlane = plane[
k];
859 if (fabs(sTot) < fabs(sPlane[iPlane])) { jPlane = (iPlane>0) ? iPlane - 1 : 1; }
860 else { jPlane = (iPlane<nPlane) ? iPlane + 1 : nPlane -1 ;}
862 double sDiff = sPlane[iPlane] - sPlane[jPlane];
863 double iFrac = (sTot - sPlane[jPlane]) / sDiff;
864 double jFrac = 1.0 - iFrac;
879 for (
unsigned int i = 1;
i < nPlane; ++
i) {
887 tempMSCov = allDeltaParameterCovs[
k].similarity(allLocalToCurv[
k]);
888 tempMSCovProj = tempMSCov.similarity(CurvToAngle);
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);
901 theDerivatives[offsetMeas+
nMeasPerHit*iMsMeas+1][offsetPar+2*l+1] = deltaK;
903 theDerivatives[offsetMeas+
nMeasPerHit*iMsMeas ][offsetPar+2*
i ] = -(deltaK + deltaN);
904 theDerivatives[offsetMeas+
nMeasPerHit*iMsMeas+1][offsetPar+2*
i+1] = -(deltaK + deltaN);
906 theDerivatives[offsetMeas+
nMeasPerHit*iMsMeas ][offsetPar+2*
n ] = deltaN;
907 theDerivatives[offsetMeas+
nMeasPerHit*iMsMeas+1][offsetPar+2*n+1] = deltaN;
AlgebraicMatrix theInnerTrajectoryToCurvilinear
double z0() const
z coordinate
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 >p)
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())
AlgebraicMatrix theDerivatives
Geom::Phi< T > phi() const
static BoundPlanePointer build(const PositionType &pos, const RotationType &rot, const Bounds *bounds, MediumProperties *mp=0)
AlgebraicVector theParameters
AlgebraicVector theMeasurements
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)
tuple TSCBLBuilderNoMaterial
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
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const
const SurfaceSide surfaceSide(const PropagationDirection dir) const
CLHEP::HepMatrix AlgebraicMatrix
FreeTrajectoryState * freeState(bool withErrors=true) const
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
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &fts, const Plane &plane) const
propagation to plane with path length
GlobalVector momentum() const
MaterialEffectsUpdator * createUpdator(MaterialEffects materialEffects, double mass) const
const AlgebraicSymMatrix55 & matrix() const
unsigned int theNumberOfHits
AlgebraicVector theTrajectoryPositions
virtual void fillDerivatives(const AlgebraicMatrix &projection, const AlgebraicMatrix &fullJacobian, unsigned int iRow)
const LocalTrajectoryError & localError() const
GlobalVector momentum() const
double dxdz() const
dxdz slope
TransientTrackingRecHit::ConstRecHitContainer theRecHits
GlobalPoint position() const
AlgebraicSymMatrix theMeasurementsCov
std::vector< ConstRecHitPointer > ConstRecHitContainer
const AlgebraicVector & parameters() const
CLHEP::HepVector AlgebraicVector
unsigned int theNumberOfMsMeas
const GlobalTrajectoryParameters & globalParameters() const
AlgebraicVector5 mixedFormatVector() const
Unlimited (trivial) bounds.
const Surface & surface() const
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::vector< TrajectoryStateOnSurface > theTsosVec
double y0() const
y coordinate
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)
unsigned int theNumberOfPars
unsigned int theNumberOfMsPars
bool useRecHit(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr) const
double signedInverseMomentum() const
Signed inverse momentum q/p (zero for neutrals).
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
tuple size
Write out results.
double x0() const
x coordinate