58 (
config.materialEffects >= brokenLinesCoarse) ? 1 : refTsos.localParameters().mixedFormatVector().kSize,
60 (
config.materialEffects >= brokenLinesCoarse)
62 : ((
config.materialEffects == breakPoints)
65 (
config.materialEffects >= brokenLinesCoarse)
67 : ((
config.materialEffects == breakPoints)
71 materialEffects_(
config.materialEffects),
74 includeAPEs_(
config.includeAPEs),
75 allowZeroMaterial_(
config.allowZeroMaterial) {
79 if (
config.hitsAreReverse) {
81 fwdRecHits.reserve(
recHits.size());
82 for (TransientTrackingRecHit::ConstRecHitContainer::const_reverse_iterator it =
recHits.rbegin();
85 fwdRecHits.push_back(*it);
100 (
config.materialEffects >= brokenLinesCoarse)
102 : ((
config.materialEffects == breakPoints) ? 2 * nHits - 2 : 0),
103 (
config.materialEffects >= brokenLinesCoarse)
105 : ((
config.materialEffects == breakPoints) ? 2 * nHits - 2 : 0)),
107 materialEffects_(
config.materialEffects),
110 includeAPEs_(
config.includeAPEs),
111 allowZeroMaterial_(
config.allowZeroMaterial) {}
124 if (!aMaterialEffectsUpdator.get())
128 std::vector<AlgebraicMatrix> allJacobians;
134 std::vector<AlgebraicSymMatrix> allCurvatureChanges;
139 std::vector<AlgebraicMatrix> allProjections;
141 std::vector<AlgebraicSymMatrix> allDeltaParameterCovs;
145 std::vector<AlgebraicMatrix> allLocalToCurv;
147 std::vector<double> allSteps;
149 std::vector<AlgebraicMatrix> allCurvlinJacobians;
154 unsigned int iRow = 0;
164 if (!tsctbl.isValid()) {
165 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::construct"
166 <<
"TrajectoryStateClostestToBeamLine invalid. Skip track.";
175 std::pair<TrajectoryStateOnSurface, double> tsosWithPath =
propagator.propagateWithPath(pcaFts, refTsos.
surface());
177 if (!tsosWithPath.first.isValid())
191 allRecHits.push_back(bsRecHit);
195 TransientTrackingRecHit::ConstRecHitContainer::const_iterator itRecHit;
196 for (itRecHit =
recHits.begin(); itRecHit !=
recHits.end(); ++itRecHit) {
198 allRecHits.push_back(hitPtr);
201 for (itRecHit = allRecHits.begin(); itRecHit != allRecHits.end(); ++itRecHit) {
209 allJacobians.push_back(fullJacobian);
212 const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
217 allLocalToCurv.push_back(localToCurvilinear);
218 allSteps.push_back(0.);
219 allCurvlinJacobians.push_back(firstCurvlinJacobian);
224 double nextStep = 0.;
227 if (!this->
propagate(previousHitPtr->det()->surface(),
238 allJacobians.push_back(nextJacobian);
239 fullJacobian = nextJacobian * previousChangeInCurvature * fullJacobian;
243 const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
244 allLocalToCurv.push_back(localToCurvilinear);
245 if (nextStep == 0.) {
246 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::construct"
247 <<
"step 0. from id " << previousHitPtr->geographicalId() <<
" to "
248 << hitPtr->det()->geographicalId() <<
".";
251 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::construct"
256 allSteps.push_back(nextStep);
257 allCurvlinJacobians.push_back(nextCurvlinJacobian);
266 if (!updatedTsos.isValid())
269 if (
theTsosVec.back().localParameters().charge()) {
271 theTsosVec.back().localParameters().signedInverseMomentum();
275 allDeltaParameterCovs.push_back(asHepMatrix<5>(updatedTsos.localError().matrix()));
276 allCurvatureChanges.push_back(previousChangeInCurvature);
282 previousHitPtr = hitPtr;
304 msOK = this->
addMaterialEffectsCov(allJacobians, allProjections, allCurvatureChanges, allDeltaParameterCovs);
308 allJacobians, allProjections, allCurvatureChanges, allDeltaParameterCovs, allLocalToCurv);
312 allProjections, allDeltaParameterCovs, allLocalToCurv, allSteps, refTsos.
globalParameters());
318 allDeltaParameterCovs,
327 allCurvlinJacobians, allProjections, allCurvatureChanges, allDeltaParameterCovs, allLocalToCurv);
351 switch (materialEffects) {
377 const Plane &newSurface,
393 const std::pair<TrajectoryStateOnSurface, double> tsosWithPath =
397 if (!tsosWithPath.first.isValid())
400 nextStep = tsosWithPath.second;
404 tsosWithPath.first.globalPosition(),
405 tsosWithPath.first.globalMomentum(),
406 tsosWithPath.second);
407 const AlgebraicMatrix curvilinearJacobian = asHepMatrix<5, 5>(aJacobian.jacobian());
411 const AlgebraicMatrix localToCurvilinear = asHepMatrix<5>(startTrafo.jacobian());
415 const AlgebraicMatrix curvilinearToLocal = asHepMatrix<5>(endTrafo.jacobian());
419 newCurvlinJacobian = curvilinearJacobian;
420 newJacobian = curvilinearToLocal * curvilinearJacobian * localToCurvilinear;
421 newTsos = tsosWithPath.first;
439 const auto &newHitPtr = hitPtr;
443 const LocalPoint localMeasurement = newHitPtr->localPosition();
444 const LocalError localMeasurementCov = newHitPtr->localPositionError();
454 auto det = static_cast<const TrackerGeomDet *>(newHitPtr->det());
455 const auto localAPE = det->localAlignmentError();
456 if (localAPE.valid()) {
472 for (
int j = 0;
j < projectedJacobian.num_row(); ++
j) {
485 for (
int i = 0;
i < localPosition.num_row(); ++
i) {
493 const std::vector<AlgebraicMatrix> &allProjections,
494 const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
495 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs) {
513 for (
unsigned int k = 1;
k < allJacobians.size(); ++
k) {
515 paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allJacobians[
k]);
518 deltaMaterialEffectsCov = paramMaterialEffectsCov.similarity(allProjections[
k]);
525 paramMaterialEffectsCov += allDeltaParameterCovs[
k];
527 tempParameterCov = paramMaterialEffectsCov;
530 for (
unsigned int l =
k + 1;
l < allJacobians.size(); ++
l) {
531 tempParameterCov = allJacobians[
l] * allCurvatureChanges[
l] * tempParameterCov;
532 tempMeasurementCov = allProjections[
l] * tempParameterCov * allProjections[
k].T();
549 paramMaterialEffectsCov = paramMaterialEffectsCov.similarity(allCurvatureChanges[
k]);
559 const std::vector<AlgebraicMatrix> &allProjections,
560 const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
561 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
562 const std::vector<AlgebraicMatrix> &allLocalToCurv) {
565 int offsetMeas =
nMeasPerHit * allJacobians.size();
570 MSprojection[0][1] = 1;
571 MSprojection[1][2] = 1;
576 for (
unsigned int k = 1;
k < allJacobians.size(); ++
k) {
579 tempJacobian = allJacobians[
k] * allCurvatureChanges[
k];
580 tempMSCov = allDeltaParameterCovs[
k - 1].similarity(allLocalToCurv[
k - 1]);
581 tempMSCovProj = tempMSCov.similarity(MSprojection);
587 tempMSJacProj = (allProjections[
k] * (tempJacobian * allLocalToCurv[
k - 1].inverse(ierr))) * MSprojection.T();
589 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBp"
590 <<
"Inversion 1 for break points failed: " << ierr;
598 for (
unsigned int l =
k + 1;
l < allJacobians.size(); ++
l) {
601 tempJacobian = allJacobians[
l] * allCurvatureChanges[
l] * tempJacobian;
602 tempMSJacProj = (allProjections[
l] * (tempJacobian * allLocalToCurv[
k - 1].inverse(ierr))) * MSprojection.T();
604 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBp"
605 <<
"Inversion 2 for break points failed: " << ierr;
621 const std::vector<AlgebraicMatrix> &allProjections,
622 const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
623 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
624 const std::vector<AlgebraicMatrix> &allLocalToCurv,
635 int offsetMeas =
nMeasPerHit * allCurvlinJacobians.size();
639 double cosLambda =
sqrt((
p.x() *
p.x() +
p.y() *
p.y()) / (
p.x() *
p.x() +
p.y() *
p.y() +
p.z() *
p.z()));
643 QbypToCurv[0][0] = 1.;
645 AngleToCurv[1][1] = 1.;
646 AngleToCurv[2][0] = 1. / cosLambda;
648 CurvToAngle[1][1] = 1.;
649 CurvToAngle[0][2] = cosLambda;
651 OffsetToCurv[3][0] = 1.;
652 OffsetToCurv[4][1] = 1.;
654 CurvToOffset[0][3] = 1.;
655 CurvToOffset[1][4] = 1.;
659 TrajToQbyp[0][0] = 1.;
661 TrajToOff1[0][1] = 1.;
662 TrajToOff1[1][2] = 1.;
664 TrajToOff2[0][3] = 1.;
665 TrajToOff2[1][4] = 1.;
668 AlgebraicMatrix JacCurvToOffsetL, JacOffsetToOffsetL, JacAngleToOffsetL, JacQbypToOffsetL, JacOffsetToAngleL;
669 AlgebraicMatrix JacCurvToOffsetN, JacOffsetToOffsetN, JacAngleToOffsetN, JacQbypToOffsetN, JacOffsetToAngleN;
673 JacCurvToOffsetN = CurvToOffset * allCurvlinJacobians[1];
674 JacOffsetToOffsetN = JacCurvToOffsetN * OffsetToCurv;
676 JacCurvToOffsetN * AngleToCurv;
677 JacQbypToOffsetN = JacCurvToOffsetN * QbypToCurv;
678 JacOffsetToAngleN = JacAngleToOffsetN.inverse(ierr);
680 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
681 <<
"Inversion 1 for fine broken lines failed: " << ierr;
684 JacOffsetToAngleC = -(JacOffsetToAngleN * JacOffsetToOffsetN);
685 JacQbypToAngleC = -(JacOffsetToAngleN * JacQbypToOffsetN);
688 JacQbypToAngleC * TrajToQbyp + JacOffsetToAngleC * TrajToOff1 + JacOffsetToAngleN * TrajToOff2;
693 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
694 <<
"Inversion 2 for fine broken lines failed: " << ierr;
705 for (
unsigned int k = 0;
k < allCurvlinJacobians.size(); ++
k) {
707 JacOffsetToMeas = (allProjections[
k] * allLocalToCurv[
k].inverse(ierr)) * OffsetToCurv;
709 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
710 <<
"Inversion 3 for fine broken lines failed: " << ierr;
720 for (
unsigned int k = 1;
k < allCurvlinJacobians.size() - 1; ++
k) {
727 tempMSCov = allDeltaParameterCovs[
k].similarity(allLocalToCurv[
k]);
728 tempMSCovProj = tempMSCov.similarity(CurvToAngle);
734 tempJacL = allCurvlinJacobians[
k] * tempJacobian;
735 JacCurvToOffsetL = CurvToOffset * tempJacL.inverse(ierr);
738 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
739 <<
"Inversion 4 for fine broken lines failed: " << ierr;
743 JacCurvToOffsetL * OffsetToCurv;
745 JacCurvToOffsetL * AngleToCurv;
747 JacCurvToOffsetL * QbypToCurv;
748 JacOffsetToAngleL = -JacAngleToOffsetL.inverse(ierr);
750 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
751 <<
"Inversion 5 for fine broken lines failed: " << ierr;
754 tempJacobian = tempJacobian * allCurvatureChanges[
k];
755 tempJacN = allCurvlinJacobians[
n] * tempJacobian;
756 JacCurvToOffsetN = CurvToOffset * tempJacN;
758 JacCurvToOffsetN * OffsetToCurv;
760 JacCurvToOffsetN * AngleToCurv;
762 JacCurvToOffsetN * QbypToCurv;
763 JacOffsetToAngleN = JacAngleToOffsetN.inverse(ierr);
765 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
766 <<
"Inversion 6 for fine broken lines failed: " << ierr;
769 JacOffsetToAngleC = -(JacOffsetToAngleL * JacOffsetToOffsetL + JacOffsetToAngleN * JacOffsetToOffsetN);
770 JacQbypToAngleC = -(JacOffsetToAngleL * JacQbypToOffsetL + JacOffsetToAngleN * JacQbypToOffsetN);
799 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
800 const std::vector<AlgebraicMatrix> &allLocalToCurv,
801 const std::vector<double> &allSteps,
803 const double minStep) {
814 double cosLambda =
sqrt((
p.x() *
p.x() +
p.y() *
p.y()) / (
p.x() *
p.x() +
p.y() *
p.y() +
p.z() *
p.z()));
818 double delta(1.0 / allSteps[1]);
829 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
830 <<
"Inversion 1 for coarse broken lines failed: " << ierr;
835 CurvToAngle[1][1] = 1.;
836 CurvToAngle[0][2] = cosLambda;
838 OffsetToCurv[3][0] = 1.;
839 OffsetToCurv[4][1] = 1.;
846 std::vector<unsigned int>
first(allSteps.size());
847 std::vector<unsigned int>
last(allSteps.size());
848 std::vector<unsigned int> plane(allSteps.size());
849 std::vector<double> sPlane(allSteps.size());
850 unsigned int nPlane = 0;
853 for (
unsigned int k = 1;
k < allSteps.size(); ++
k) {
855 if (fabs(allSteps[
k]) > minStep) {
861 sPlane[nPlane] += sTot;
868 for (
unsigned int k = 0;
k <= nPlane; ++
k) {
874 for (
unsigned int k = 0;
k < allSteps.size(); ++
k) {
877 JacOffsetToMeas = (allProjections[
k] * allLocalToCurv[
k].inverse(ierr)) * OffsetToCurv;
879 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsBrl"
880 <<
"Inversion 2 for coarse broken lines failed: " << ierr;
884 unsigned int iPlane = plane[
k];
892 if (fabs(sTot) < fabs(sPlane[iPlane])) {
893 jPlane = (iPlane > 0) ? iPlane - 1 : 1;
895 jPlane = (iPlane < nPlane) ? iPlane + 1 : nPlane - 1;
898 double sDiff = sPlane[iPlane] - sPlane[jPlane];
899 double iFrac = (sTot - sPlane[jPlane]) / sDiff;
900 double jFrac = 1.0 - iFrac;
915 for (
unsigned int i = 1;
i < nPlane; ++
i) {
923 tempMSCov = allDeltaParameterCovs[
k].similarity(allLocalToCurv[
k]);
924 tempMSCovProj = tempMSCov.similarity(CurvToAngle);
930 double stepK = sPlane[
i] - sPlane[
l];
931 double stepN = sPlane[
n] - sPlane[
i];
932 double deltaK(1.0 / stepK);
933 double deltaN(1.0 / stepN);
953 const std::vector<AlgebraicMatrix> &allProjections,
954 const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
955 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs) {
959 const double minPrec = 1.0;
962 OffsetToLocal[3][0] = 1.;
963 OffsetToLocal[4][1] = 1.;
965 SlopeToLocal[1][0] = 1.;
966 SlopeToLocal[2][1] = 1.;
969 Eigen::Matrix2d covariance, scatPrecision, proLocalToMeas;
970 Matrix5d jacPointToPoint;
971 auto identity = Matrix5d::Identity();
972 Eigen::Vector2d measurement, measPrecDiag;
973 auto scatterer = Eigen::Vector2d::Zero();
978 unsigned int numHits = allJacobians.size();
979 std::vector<GblPoint> GblPointList;
980 GblPointList.reserve(numHits);
981 for (
unsigned int k = 0;
k < numHits; ++
k) {
983 clhep2eigen(allJacobians[
k] * allCurvatureChanges[
k], jacPointToPoint);
986 GblPoint aGblPoint(jacPointToPoint);
989 clhep2eigen(allProjections[
k] * OffsetToLocal, proLocalToMeas);
1001 for (
unsigned int row = 0; row < 2; ++row) {
1002 measPrecDiag(row) = (0. < covariance(row, row) ? 1.0 / covariance(row, row) : 0.);
1004 aGblPoint.addMeasurement(proLocalToMeas, measurement, measPrecDiag, minPrec);
1007 aGblPoint.addMeasurement(proLocalToMeas, measurement, covariance.inverse(), minPrec);
1011 clhep2eigen(allDeltaParameterCovs[
k].similarityT(SlopeToLocal), scatPrecision);
1012 if (!(scatPrecision.colPivHouseholderQr().isInvertible())) {
1014 throw cms::Exception(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsLocalGbl"
1015 <<
"\nEncountered singular scatter covariance-matrix without allowing "
1016 <<
"for zero material.";
1020 aGblPoint.addScatterer(scatterer, scatPrecision.inverse());
1023 GblPointList.push_back(aGblPoint);
1034 const std::vector<AlgebraicMatrix> &allProjections,
1035 const std::vector<AlgebraicSymMatrix> &allCurvatureChanges,
1036 const std::vector<AlgebraicSymMatrix> &allDeltaParameterCovs,
1037 const std::vector<AlgebraicMatrix> &allLocalToCurv) {
1041 const double minPrec = 1.0;
1045 OffsetToCurv[3][0] = 1.;
1046 OffsetToCurv[4][1] = 1.;
1051 Eigen::Matrix2d covariance, proLocalToMeas;
1052 Matrix5d jacPointToPoint, firstLocalToCurv;
1053 Eigen::Vector2d measurement, measPrecDiag, scatPrecDiag;
1054 auto scatterer = Eigen::Vector2d::Zero();
1057 unsigned int numHits = allCurvlinJacobians.size();
1058 std::vector<GblPoint> GblPointList;
1059 GblPointList.reserve(numHits);
1060 for (
unsigned int k = 0;
k < numHits; ++
k) {
1062 JacOffsetToMeas = (allProjections[
k] * allLocalToCurv[
k].inverse(ierr)) * OffsetToCurv;
1064 edm::LogError(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsGbl"
1065 <<
"Inversion 1 for general broken lines failed: " << ierr;
1070 clhep2eigen(allCurvlinJacobians[
k] * allCurvatureChanges[
k], jacPointToPoint);
1073 GblPoint aGblPoint(jacPointToPoint);
1088 for (
unsigned int row = 0; row < 2; ++row) {
1089 measPrecDiag(row) = (0. < covariance(row, row) ? 1.0 / covariance(row, row) : 0.);
1091 aGblPoint.addMeasurement(proLocalToMeas, measurement, measPrecDiag, minPrec);
1094 aGblPoint.addMeasurement(proLocalToMeas, measurement, covariance.inverse(), minPrec);
1098 tempMSCov = allDeltaParameterCovs[
k].similarity(allLocalToCurv[
k]);
1099 for (
unsigned int row = 0; row < 2; ++row) {
1100 scatPrecDiag(row) = 1.0 / tempMSCov[row + 1][row + 1];
1104 bool singularCovariance{
false};
1105 for (
int row = 0; row < scatPrecDiag.rows(); ++row) {
1107 singularCovariance =
true;
1112 throw cms::Exception(
"Alignment") <<
"@SUB=ReferenceTrajectory::addMaterialEffectsCurvlinGbl"
1113 <<
"\nEncountered singular scatter covariance-matrix without allowing "
1114 <<
"for zero material.";
1118 aGblPoint.addScatterer(scatterer, scatPrecDiag);
1121 GblPointList.push_back(aGblPoint);
1125 theGblInput.push_back(std::make_pair(GblPointList, firstLocalToCurv));
1131 template <
typename Derived>
1133 static_assert(Derived::ColsAtCompileTime == 1,
"clhep2eigen: 'out' must be of vector type");
1134 for (
int row = 0; row <
in.num_row(); ++row) {
1139 template <
typename Derived>
1141 for (
int row = 0; row <
in.num_row(); ++row) {
1148 template <
typename Derived>
1150 for (
int row = 0; row <
in.num_row(); ++row) {
1163 switch (hitPtr->dimension()) {
1165 return getHitProjectionMatrixT<1>(hitPtr);
1167 return getHitProjectionMatrixT<2>(hitPtr);
1169 return getHitProjectionMatrixT<3>(hitPtr);
1171 return getHitProjectionMatrixT<4>(hitPtr);
1173 return getHitProjectionMatrixT<5>(hitPtr);
1175 throw cms::Exception(
"ReferenceTrajectory::getHitProjectionMatrix")
1176 <<
"Unexpected hit dimension: " << hitPtr->dimension() <<
"\n";
1185 template <
unsigned int N>
1200 holder.
setup<
N>(&
r, &
V, &
pf, &rMeas, &VMeas, dummyPars, dummyErr);
1201 hitPtr->getKfComponents(holder);