#include <SurveyResidual.h>
Public Member Functions | |
AlgebraicSymMatrix | inverseCovariance () const |
Get inverse of survey covariance wrt given structure type in constructor. | |
align::LocalVectors | pointsResidual () const |
AlgebraicVector | sensorResidual () const |
SurveyResidual (const Alignable &, align::StructureType, bool bias=false) | |
bool | valid () const |
Private Member Functions | |
void | calculate (const Alignable &) |
Find the nominal and current vectors. | |
void | findSisters (const Alignable *, bool bias) |
Private Attributes | |
align::ErrorMatrix | theCovariance |
align::GlobalVectors | theCurrentVs |
const Alignable * | theMother |
align::GlobalVectors | theNominalVs |
const std::vector< bool > & | theSelector |
std::vector< const Alignable * > | theSisters |
const AlignableSurface & | theSurface |
Class to find the residuals for survey constraint alignment.
For more info, please refer to https://www.pha.jhu.edu/~gritsan/cms/cms-note-survey.pdf
Definition at line 22 of file SurveyResidual.h.
SurveyResidual::SurveyResidual | ( | const Alignable & | ali, |
align::StructureType | type, | ||
bool | bias = false |
||
) |
Constructor from an alignable whose residuals are to be found. The type of residuals (panel, disc etc.) is given by StructureType. Set bias to true for biased residuals. Default is to find unbiased residuals.
Definition at line 11 of file SurveyResidual.cc.
References Alignable::alignableObjectId(), calculate(), Exception, findSisters(), Alignable::geomDetId(), Alignable::mother(), DetId::rawId(), theMother, and theSisters.
: theMother(0), theSurface( ali.surface() ), theSelector( ali.alignmentParameters()->selector() ) { // Find mother matching given type theMother = &ali; // start finding from this alignable while (theMother->alignableObjectId() != type) { theMother = theMother->mother(); // move up a level if (!theMother) return; // { // throw cms::Exception("ConfigError") // << "Alignable (id = " << ali.geomDetId().rawId() // << ") does not belong to a composite of type " << type; // } } if ( !theMother->mother() ) { throw cms::Exception("ConfigError") << "The type " << type << " does not have a survey residual defined!\n" << "You have probably set the highest hierarchy. Choose a lower level."; } findSisters(theMother, bias); if (theSisters.size() == 0) { throw cms::Exception("ConfigError") << "You are finding an unbiased residual of an alignable " << " (id = " << ali.geomDetId().rawId() << ") which has no sister. Abort!"; } calculate(ali); }
void SurveyResidual::calculate | ( | const Alignable & | ali | ) | [private] |
Find the nominal and current vectors.
Definition at line 166 of file SurveyResidual.cc.
References a, PV3DBase< T, PVType, FrameType >::basicVector(), deltaR(), align::diffRot(), Exception, Alignable::geomDetId(), SurveyDet::globalPoints(), Alignable::globalPosition(), Alignable::globalRotation(), i, j, SurveyDet::localPoints(), Alignable::mother(), align::motherPosition(), SurveyDet::position(), DetId::rawId(), Alignable::surface(), Alignable::survey(), theCovariance, theCurrentVs, theMother, theNominalVs, theSisters, theSurface, AlignableSurface::toGlobal(), TkRotation< T >::xx(), TkRotation< T >::xy(), TkRotation< T >::xz(), TkRotation< T >::yx(), TkRotation< T >::yy(), TkRotation< T >::yz(), TkRotation< T >::zx(), TkRotation< T >::zy(), and TkRotation< T >::zz().
Referenced by SurveyResidual().
{ unsigned int nSister = theSisters.size(); // First get sisters' positions std::vector<const PositionType*> nominalSisPos; // nominal sisters' pos std::vector<const PositionType*> currentSisPos; // current sisters' pos nominalSisPos.reserve(nSister); currentSisPos.reserve(nSister); for (unsigned int i = 0; i < nSister; ++i) { const Alignable* sis = theSisters[i]; const SurveyDet* survey = sis->survey(); if (!survey) { throw cms::Exception("ConfigError") << "No survey info is found for Alignable " << " (id = " << sis->geomDetId().rawId() << "). Abort!"; } nominalSisPos.push_back( &survey->position() ); currentSisPos.push_back( &sis->globalPosition() ); } // Then find mother's position using sisters' positions PositionType nominalMomPos = motherPosition(nominalSisPos); PositionType currentMomPos = motherPosition(currentSisPos); // Now find rotation from nominal mother to current mother GlobalVectors nominalSisVs; // nominal sisters' pos from mother's pos GlobalVectors currentSisVs; // current sisters' pos from mother's pos for (unsigned int i = 0; i < nSister; ++i) { const Alignable* sis = theSisters[i]; const GlobalPoints& nominalSisPoints = sis->survey()->globalPoints(); const GlobalPoints& currentSisPoints = sis->surface().toGlobal( sis->survey()->localPoints() ); for (unsigned int j = 0; j < nominalSisPoints.size(); ++j) { nominalSisVs.push_back(nominalSisPoints[j] - *nominalSisPos[i]); currentSisVs.push_back(currentSisPoints[j] - *currentSisPos[i]); // nominalSisVs.push_back(nominalSisPoints[j] - nominalMomPos); // currentSisVs.push_back(currentSisPoints[j] - currentMomPos); } } RotationType toCurrent = diffRot(currentSisVs, nominalSisVs); // Finally shift and rotate nominal sensor to current sensor const SurveyDet* survey = ali.survey(); if (!survey) { throw cms::Exception("ConfigError") << "No survey info is found for Alignable " << " (id = " << ali.geomDetId().rawId() << "). Abort!"; } const GlobalPoints& nominalPoints = survey->globalPoints(); const GlobalPoints& currentPoints = theSurface.toGlobal( survey->localPoints() ); for (unsigned int j = 0; j < nominalPoints.size(); ++j) { align::GlobalVector nv = nominalPoints[j] - nominalMomPos; theNominalVs.push_back( align::GlobalVector( toCurrent * nv.basicVector() ) ); theCurrentVs.push_back(currentPoints[j] - currentMomPos); } // Find the covariance const RotationType& currentFrame = ali.globalRotation(); for ( const Alignable* a = &ali; a != theMother->mother(); a = a->mother() ) { RotationType deltaR = currentFrame * a->survey()->rotation().transposed(); math::Matrix<6, 6>::type jac; // 6 by 6 Jacobian init to 0 jac(0, 0) = deltaR.xx(); jac(0, 1) = deltaR.xy(); jac(0, 2) = deltaR.xz(); jac(1, 0) = deltaR.yx(); jac(1, 1) = deltaR.yy(); jac(1, 2) = deltaR.yz(); jac(2, 0) = deltaR.zx(); jac(2, 1) = deltaR.zy(); jac(2, 2) = deltaR.zz(); jac(3, 3) = deltaR.xx(); jac(3, 4) = deltaR.xy(); jac(3, 5) = deltaR.xz(); jac(4, 3) = deltaR.yx(); jac(4, 4) = deltaR.yy(); jac(4, 5) = deltaR.yz(); jac(5, 3) = deltaR.zx(); jac(5, 4) = deltaR.zy(); jac(5, 5) = deltaR.zz(); theCovariance += ROOT::Math::Similarity( jac, a->survey()->errors() ); } }
void SurveyResidual::findSisters | ( | const Alignable * | ali, |
bool | bias | ||
) | [private] |
Find the terminal sisters of an alignable. bias = true to include itself in the list.
Definition at line 146 of file SurveyResidual.cc.
References Alignable::components(), Alignable::deepComponents(), i, Alignable::mother(), and theSisters.
Referenced by SurveyResidual().
{ theSisters.clear(); theSisters.reserve(1000); const std::vector<Alignable*>& comp = ali->mother()->components(); unsigned int nComp = comp.size(); for (unsigned int i = 0; i < nComp; ++i) { const Alignable* dau = comp[i]; if (dau != ali || bias) theSisters.insert( theSisters.end(), dau->deepComponents().begin(), dau->deepComponents().end() ); // if (dau != ali || bias) theSisters.push_back(dau); } }
AlgebraicSymMatrix SurveyResidual::inverseCovariance | ( | ) | const |
Get inverse of survey covariance wrt given structure type in constructor.
Definition at line 114 of file SurveyResidual.cc.
References Exception, cmsPerfPublish::fail(), i, j, theCovariance, and theSelector.
Referenced by SurveyAlignmentSensor::findAlignPars(), and HIPAlignmentAlgorithm::terminate().
{ if (theSelector.size() != ErrorMatrix::kRows) { throw cms::Exception("LogicError") << "Mismatched number of dof between ErrorMatrix and Selector."; } std::vector<unsigned int> indices; // selected indices indices.reserve(ErrorMatrix::kRows); for (unsigned int i = 0; i < ErrorMatrix::kRows; ++i) if (theSelector[i]) indices.push_back(i); AlgebraicSymMatrix invCov( indices.size() ); for (unsigned int i = 0; i < indices.size(); ++i) for (unsigned int j = 0; j <= i; ++j) invCov.fast(i + 1, j + 1) = theCovariance(indices[i], indices[j]); int fail(0); invCov.invert(fail); if (fail) { throw cms::Exception("ConfigError") << "Cannot invert survey error " << invCov; } return invCov; }
LocalVectors SurveyResidual::pointsResidual | ( | ) | const |
Find residuals in local frame for points on the alignable (current - nominal vectors).
Definition at line 98 of file SurveyResidual.cc.
References j, theCurrentVs, theNominalVs, theSurface, and AlignableSurface::toLocal().
Referenced by SurveyAlignmentPoints::findAlignPars().
{ LocalVectors residuals; unsigned int nPoint = theNominalVs.size(); residuals.reserve(nPoint); for (unsigned int j = 0; j < nPoint; ++j) { residuals.push_back( theSurface.toLocal(theCurrentVs[j] - theNominalVs[j]) ); } return residuals; }
AlgebraicVector SurveyResidual::sensorResidual | ( | ) | const |
Find residual for the alignable in local frame. Returns a vector based on the alignable's dof.
Definition at line 54 of file SurveyResidual.cc.
References deltaR(), align::diffRot(), j, theCurrentVs, theNominalVs, theSelector, theSurface, align::toAngles(), AlignableSurface::toLocal(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().
Referenced by AlignmentMonitorSurvey::book(), SurveyAlignmentSensor::findAlignPars(), and HIPAlignmentAlgorithm::terminate().
{ std::vector<Scalar> pars; // selected parameters pars.reserve(AlignParams::kSize); // Find linear displacements. align::LocalVector deltaR = theSurface.toLocal(theCurrentVs[0] - theNominalVs[0]); if (theSelector[0]) pars.push_back( deltaR.x() ); if (theSelector[1]) pars.push_back( deltaR.y() ); if (theSelector[2]) pars.push_back( deltaR.z() ); // Match the centers of current and nominal surfaces to find the angular // displacements about the center. Only do this if angular dof are selected. if (theSelector[3] || theSelector[4] || theSelector[5]) { GlobalVectors nominalVs = theNominalVs; GlobalVectors currentVs = theCurrentVs; for (unsigned int j = 0; j < nominalVs.size(); ++j) { nominalVs[j] -= theNominalVs[0]; // move to nominal pos currentVs[j] -= theCurrentVs[0]; // move to current pos } RotationType rot = diffRot(nominalVs, currentVs); // frame rotation EulerAngles deltaW = toAngles( theSurface.toLocal(rot) ); if (theSelector[3]) pars.push_back( deltaW(1) ); if (theSelector[4]) pars.push_back( deltaW(2) ); if (theSelector[5]) pars.push_back( deltaW(3) ); } AlgebraicVector deltaRW( pars.size() ); // (deltaR, deltaW) for (unsigned int j = 0; j < pars.size(); ++j) deltaRW(j + 1) = pars[j]; return deltaRW; }
bool SurveyResidual::valid | ( | ) | const [inline] |
Check if survey residual is valid (theMother != 0). This check must be done before calling the other methods so that calculations can be performed correctly.
Definition at line 84 of file SurveyResidual.h.
References theMother.
Referenced by SurveyAlignmentPoints::findAlignPars(), SurveyAlignmentSensor::findAlignPars(), and HIPAlignmentAlgorithm::terminate().
{ return theMother != 0; }
Definition at line 81 of file SurveyResidual.h.
Referenced by calculate(), and inverseCovariance().
Definition at line 79 of file SurveyResidual.h.
Referenced by calculate(), pointsResidual(), and sensorResidual().
const Alignable* SurveyResidual::theMother [private] |
Definition at line 68 of file SurveyResidual.h.
Referenced by calculate(), SurveyResidual(), and valid().
Definition at line 78 of file SurveyResidual.h.
Referenced by calculate(), pointsResidual(), and sensorResidual().
const std::vector<bool>& SurveyResidual::theSelector [private] |
Definition at line 73 of file SurveyResidual.h.
Referenced by inverseCovariance(), and sensorResidual().
std::vector<const Alignable*> SurveyResidual::theSisters [private] |
Definition at line 75 of file SurveyResidual.h.
Referenced by calculate(), findSisters(), and SurveyResidual().
const AlignableSurface& SurveyResidual::theSurface [private] |
Definition at line 71 of file SurveyResidual.h.
Referenced by calculate(), pointsResidual(), and sensorResidual().