Tools for comparing alignables
Namespace for common calculations in alignment.
Namespace for common type definitions used in alignment.
typedef std::vector<Alignable*> align::Alignables |
Definition at line 28 of file Utilities.h.
typedef math::Vector<6>::type align::AlignParams |
Definition at line 38 of file Definitions.h.
typedef std::map<std::pair<Alignable*, Alignable*>, AlgebraicMatrix> align::Correlations |
Definition at line 31 of file Utilities.h.
typedef unsigned int(* align::Counter)(align::ID) |
Definition at line 26 of file Counters.h.
typedef AlgebraicMatrix align::Derivatives |
Definition at line 37 of file Definitions.h.
typedef math::Error<6>::type align::ErrorMatrix |
Definition at line 39 of file Definitions.h.
typedef AlgebraicVector align::EulerAngles |
Definition at line 36 of file Definitions.h.
typedef Point3DBase<Scalar, GlobalTag> align::GlobalPoint |
Definition at line 31 of file Definitions.h.
typedef std::vector<GlobalPoint> align::GlobalPoints |
Definition at line 23 of file Utilities.h.
typedef Vector3DBase<Scalar, GlobalTag> align::GlobalVector |
Definition at line 33 of file Definitions.h.
typedef std::vector<GlobalVector> align::GlobalVectors |
Definition at line 24 of file Utilities.h.
typedef uint32_t align::ID |
Definition at line 26 of file Definitions.h.
typedef Point3DBase<Scalar, LocalTag> align::LocalPoint |
Definition at line 32 of file Definitions.h.
typedef std::vector<LocalPoint> align::LocalPoints |
Definition at line 25 of file Utilities.h.
typedef Vector3DBase<Scalar, LocalTag> align::LocalVector |
Definition at line 34 of file Definitions.h.
typedef std::vector< LocalVector > align::LocalVectors |
Definition at line 26 of file Utilities.h.
typedef std::vector<AlignmentParameters*> align::Parameters |
Definition at line 29 of file Utilities.h.
typedef Point3DBase<Scalar, GlobalTag> align::PositionType |
Definition at line 30 of file Definitions.h.
typedef TkRotation<Scalar> align::RotationType |
Definition at line 29 of file Definitions.h.
typedef double align::Scalar |
Definition at line 27 of file Definitions.h.
typedef std::vector<Scalar> align::Scalars |
Definition at line 22 of file Utilities.h.
enum align::StructureType |
Enumerate the types of structure an alignable can be.
Basically list the levels in the detector's hierarchy.
Definition at line 17 of file StructureType.h.
{ invalid = 0, AlignableDetUnit, AlignableDet, // Barrel Pixel TPBModule, TPBLadder, TPBLayer, // = 5 TPBHalfBarrel, TPBBarrel, // Forward Pixel TPEModule, TPEPanel, TPEBlade, // = 10 TPEHalfDisk, TPEHalfCylinder, TPEEndcap, // Tracker Inner Barrel TIBModule, TIBString, // = 15 TIBSurface, TIBHalfShell, TIBLayer, TIBHalfBarrel, TIBBarrel, // = 20 // Tracker Inner Disks TIDModule, TIDSide, TIDRing, TIDDisk, TIDEndcap, // = 25 // Tracker Outer Barrel TOBModule, TOBRod, TOBLayer, TOBHalfBarrel, TOBBarrel, // = 30 // Tracker Endcaps TECModule, TECRing, TECPetal, TECSide, TECDisk, // = 35 TECEndcap, Pixel, Strip, Tracker, // = 39 // Muon Detector, not touching these now AlignableDTBarrel = 100, AlignableDTWheel, AlignableDTStation, AlignableDTChamber, AlignableDTSuperLayer, AlignableDTLayer, // = 105 AlignableCSCEndcap, AlignableCSCStation, AlignableCSCRing, AlignableCSCChamber, AlignableCSCLayer, // = 110 AlignableMuon, Detector, // = 112 (what for?) Extras = 1000, BeamSpot };
align::GlobalVector align::centerOfMass | ( | const GlobalVectors & | theVs | ) |
Find the CM of a set of points.
Definition at line 185 of file Utilities.cc.
References j.
Referenced by MuonGeometryArrange::compareGeometries(), and diffAlignables().
void align::createPoints | ( | align::GlobalVectors * | Vs, |
Alignable * | ali, | ||
const std::string & | weightBy, | ||
bool | weightById, | ||
const std::vector< unsigned int > & | weightByIdVector | ||
) |
Creates the points which are used in diffAlignables A set of points corresponding to lowest daughters
Definition at line 92 of file AlignTools.cc.
References AlignableDet, AlignableDetUnit, Alignable::alignableObjectId(), Alignable::components(), filterCSVwithJSON::copy, error, i, Alignable::id(), j, SurveyDet::localPoints(), Alignable::mother(), readModuleList(), Alignable::setSurvey(), Alignable::surface(), Alignable::survey(), AlignableSurface::toGlobal(), x, detailsBasic3DVector::y, and z.
Referenced by MuonGeometryArrange::compareGeometries(), and diffAlignables().
{ std::string copy=weightBy; std::transform(copy.begin(), copy.end(), copy.begin(), (int(*)(int)) toupper); if(copy != "SELF"){ const align::Alignables& comp = ali->components(); unsigned int nComp = comp.size(); for (unsigned int i = 0; i < nComp; ++i) align::createPoints(Vs, comp[i], weightBy, weightById, weightByIdVector); // double the weight for SS modules if weight by Det if ((ali->alignableObjectId() == align::AlignableDet)&&(weightBy == "Det")){ for (unsigned int i = 0; i < nComp; ++i) align::createPoints(Vs, comp[i], weightBy, weightById, weightByIdVector); } //only create points for lowest hiearchical level if (ali->alignableObjectId() == align::AlignableDetUnit){ //check if the raw id or the mother's raw id is on the list bool createPointsForDetUnit = true; if (weightById) createPointsForDetUnit = align::readModuleList( ali->id(), ali->mother()->id(), weightByIdVector); if (createPointsForDetUnit){ //if no survey information, create local points if(!(ali->survey())){ align::ErrorMatrix error; ali->setSurvey( new SurveyDet (ali->surface(), error*1e-6) ); } const align::GlobalPoints& points = ali->surface().toGlobal(ali->survey()->localPoints()); for (unsigned int j = 0; j < points.size(); ++j){ align::GlobalVector dummy(points[j].x(),points[j].y(),points[j].z()); Vs->push_back(dummy); } } } } else{ bool createPointsForDetUnit = true; if (weightById) createPointsForDetUnit = align::readModuleList( ali->id(), ali->mother()->id(), weightByIdVector); if (createPointsForDetUnit){ //if no survey information, create local points if(!(ali->survey())){ align::ErrorMatrix error; ali->setSurvey( new SurveyDet (ali->surface(), error*1e-6) ); } const align::GlobalPoints& points = ali->surface().toGlobal(ali->survey()->localPoints()); for (unsigned int j = 0; j < points.size(); ++j){ align::GlobalVector dummy(points[j].x(),points[j].y(),points[j].z()); Vs->push_back(dummy); } } } }
const AlignTransform & align::DetectorGlobalPosition | ( | const Alignments & | allGlobals, |
const DetId & | id | ||
) |
Definition at line 10 of file DetectorGlobalPosition.cc.
References Exception, and Alignments::m_align.
Referenced by AlignmentMonitorAsAnalyzer::analyze(), TrackerGeometryIntoNtuples::analyze(), AlignmentProducer::beginOfJob(), TrackerGeometryCompare::createROOTGeometry(), AlignmentProducer::endOfJob(), MuonAlignmentInputDB::newAlignableMuon(), TrackerDigiGeometryESModule::produce(), CSCGeometryESModule::produce(), and DTGeometryESModule::produce().
{ for (std::vector<AlignTransform>::const_iterator iter = allGlobals.m_align.begin(); iter != allGlobals.m_align.end(); ++iter) { if (iter->rawId() == id.rawId()) { return *iter; } } throw cms::Exception("RecordNotFound") << "DetId(" << id.rawId() << ") not found in GlobalPositionRcd" << std::endl; }
AlgebraicVector align::diffAlignables | ( | Alignable * | refAli, |
Alignable * | curAli, | ||
const std::string & | weightBy, | ||
bool | weightById, | ||
const std::vector< unsigned int > & | weightByIdVector | ||
) |
Finds the TR between two alignables - first alignable is reference. Returns a vector with 12 components. First six are global, second six are local.
Definition at line 10 of file AlignTools.cc.
References Alignable::alignableObjectId(), centerOfMass(), createPoints(), diffR(), diffRot(), Exception, Alignable::globalPosition(), Alignable::id(), gen::k, TkRotation< T >::multiplyInverse(), Alignable::surface(), theW, toAngles(), AlignableSurface::toLocal(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().
Referenced by TrackerGeometryCompare::compareGeometries(), MuonGeometryArrange::compareGeometries(), and TrackerGeometryCompare::diffCommonTrackerSystem().
{ //check they are the same if (refAli->alignableObjectId() != curAli->alignableObjectId()){ if (refAli->id() != curAli->id()){ throw cms::Exception("Geometry Error") << "[AlignTools] Error, Alignables do not match"; } } //create points align::GlobalVectors refVs; align::GlobalVectors curVs; align::createPoints(&refVs, refAli, weightBy, weightById, weightByIdVector); align::createPoints(&curVs, curAli, weightBy, weightById, weightByIdVector); //redefine the set of points //find the translational difference align::GlobalVector theR = align::diffR(curVs,refVs); //CM difference (needed below in rotational transformation) align::GlobalVector pointsCM = align::centerOfMass(curVs); align::PositionType alignableCM = curAli->globalPosition(); align::GlobalVector cmdiff(alignableCM.x()-pointsCM.x(), alignableCM.y()-pointsCM.y(), alignableCM.z()-pointsCM.z()); //readjust points before finding rotation align::GlobalVector CMref = align::centerOfMass(refVs); align::GlobalVector CMcur = align::centerOfMass(curVs); for (unsigned int k = 0; k < refVs.size(); ++k){ refVs[k] -= CMref; curVs[k] -= CMcur; } //find rotational difference (global) align::RotationType rot = align::diffRot(curVs, refVs); align::EulerAngles theW = align::toAngles( rot ); //convert to local rotation align::RotationType localrot = refAli->surface().toLocal(rot); align::EulerAngles theLocalW = align::toAngles( localrot ); //adjust translational difference factoring in different rotational CM //needed because rotateInGlobalFrame is about CM of alignable, not points align::GlobalVector::BasicVectorType lpvgf = cmdiff.basicVector(); align::GlobalVector moveV( rot.multiplyInverse(lpvgf) - lpvgf); align::GlobalVector theRprime(theR + moveV); //convert to local movement align::LocalVector theLocalRprime = refAli->surface().toLocal(theRprime); AlgebraicVector deltaRW(12); // global values deltaRW(1) = theRprime.x(); deltaRW(2) = theRprime.y(); deltaRW(3) = theRprime.z(); deltaRW(4) = theW(1); deltaRW(5) = theW(2); deltaRW(6) = theW(3); // local values deltaRW(7) = theLocalRprime.x(); deltaRW(8) = theLocalRprime.y(); deltaRW(9) = theLocalRprime.z(); deltaRW(10) = theLocalW(1); deltaRW(11) = theLocalW(2); deltaRW(12) = theLocalW(3); refVs.clear(); curVs.clear(); return deltaRW; }
align::GlobalVector align::diffR | ( | const GlobalVectors & | current, |
const GlobalVectors & | nominal | ||
) |
Definition at line 166 of file Utilities.cc.
References j.
Referenced by diffAlignables(), and CreateSurveyRcds::setGeometry().
{ GlobalVector nCM(0,0,0); GlobalVector cCM(0,0,0); unsigned int nPoints = nominal.size(); for (unsigned int j = 0; j < nPoints; ++j) { nCM += nominal[j]; cCM += current[j]; } nCM -= cCM; return nCM /= static_cast<Scalar>(nPoints); }
align::RotationType align::diffRot | ( | const GlobalVectors & | current, |
const GlobalVectors & | nominal | ||
) |
Find matrix to rotate from nominal to current vectors. Assume both sets of vectors have the same size and order.
Definition at line 71 of file Utilities.cc.
References trackerHits::c, prof2calltree::count, gather_cfg::cout, cond::rpcobimon::current, Exhume::I, j, TkRotation< T >::multiplyInverse(), csvReporter::r, toMatrix(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().
Referenced by SurveyResidual::calculate(), MuonGeometryArrange::compareGeometries(), diffAlignables(), and SurveyResidual::sensorResidual().
{ // Find the matrix needed to rotate the nominal surface to the current one // using small angle approximation through the equation: // // I * dOmega = dr * r (sum over points) // // where dOmega is a vector of small rotation angles about (x, y, z)-axes, // and I is the inertia tensor defined as // // I_ij = delta_ij * r^2 - r_i * r_j (sum over points) // // delta_ij is the identity matrix. i, j are indices for (x, y, z). // // On the rhs of the first eq, r * dr is the cross product of r and dr. // In this case, r is the nominal vector and dr is the displacement of the // current point from its nominal point (current vector - nominal vector). // // Since the solution of dOmega (by inverting I) gives angles that are small, // we rotate the current surface by -dOmega and repeat the process until the // dOmega^2 is less than a certain tolerance value. // (In other words, we move the current surface by small angular steps till // it matches the nominal surface.) // The full rotation is found by adding up the rotations (given by dOmega) // in each step. (More precisely, the product of all the matrices.) // // Note that, in some cases, if the angular displacement between current and // nominal is pi, the algorithm can return an identity (no rotation). // This is because dr = -r and r * dr is all zero. // This is not a problem since we are dealing with small angles in alignment. static const double tolerance = 1e-12; RotationType rot; // rotation from nominal to current; init to identity // Initial values for dr and I; I is always the same in each step AlgebraicSymMatrix I(3); // inertia tensor GlobalVectors rotated = current; // rotated current vectors in each step unsigned int nPoints = nominal.size(); for (unsigned int j = 0; j < nPoints; ++j) { const GlobalVector& r = nominal[j]; // Inertial tensor: I_ij = delta_ij * r^2 - r_i * r_j (sum over points) I.fast(1, 1) += r.y() * r.y() + r.z() * r.z(); I.fast(2, 2) += r.x() * r.x() + r.z() * r.z(); I.fast(3, 3) += r.y() * r.y() + r.x() * r.x(); I.fast(2, 1) -= r.x() * r.y(); // row index must be >= col index I.fast(3, 1) -= r.x() * r.z(); I.fast(3, 2) -= r.y() * r.z(); } int count=0; while (true) { AlgebraicVector rhs(3); // sum of dr * r for (unsigned int j = 0; j < nPoints; ++j) { const GlobalVector& r = nominal[j]; const GlobalVector& c = rotated[j]; // Cross product of dr * r = c * r (sum over points) rhs(1) += c.y() * r.z() - c.z() * r.y(); rhs(2) += c.z() * r.x() - c.x() * r.z(); rhs(3) += c.x() * r.y() - c.y() * r.x(); } EulerAngles dOmega = CLHEP::solve(I, rhs); rot *= toMatrix(dOmega); // add to rotation if (dOmega.normsq() < tolerance) break; // converges, so exit loop count++; if(count>100000){ std::cout<<"diffRot infinite loop: dOmega is "<<dOmega.normsq()<<"\n"; break; } // Not yet converge; move current vectors to new positions and find dr for (unsigned int j = 0; j < nPoints; ++j) { rotated[j] = GlobalVector( rot.multiplyInverse( current[j].basicVector() ) ); } } return rot; }
align::PositionType align::motherPosition | ( | const std::vector< const PositionType * > & | dauPos | ) |
Find mother's position from the average of its daughters' positions.
Definition at line 51 of file Utilities.cc.
References i, python::tagInventory::inv, point, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().
Referenced by SurveyResidual::calculate().
{ unsigned int nDau = dauPos.size(); Scalar posX(0.), posY(0.), posZ(0.); // position of mother for (unsigned int i = 0; i < nDau; ++i) { const PositionType* point = dauPos[i]; posX += point->x(); posY += point->y(); posZ += point->z(); } Scalar inv = 1. / static_cast<Scalar>(nDau); return PositionType(posX *= inv, posY *= inv, posZ *= inv); }
void align::moveAlignable | ( | Alignable * | ali, |
AlgebraicVector | diff | ||
) |
Moves the alignable by the AlgebraicVector.
Finds the TR between 2 sets of alignables For example, if TIB/TID were to move as one unit
Definition at line 81 of file AlignTools.cc.
References Alignable::move(), Alignable::rotateInGlobalFrame(), and toMatrix().
Referenced by TrackerGeometryCompare::compareGeometries(), MuonGeometryArrange::compareGeometries(), and TrackerGeometryCompare::setCommonTrackerSystem().
{ GlobalVector dR(diff[0],diff[1],diff[2]); align::EulerAngles dOmega(3); dOmega[0] = diff[3]; dOmega[1] = diff[4]; dOmega[2] = diff[5]; align::RotationType dRot = align::toMatrix(dOmega); ali->move(dR); ali->rotateInGlobalFrame(dRot); }
bool align::readModuleList | ( | unsigned int | aliId, |
unsigned int | motherId, | ||
const std::vector< unsigned int > & | weightByIdVector | ||
) |
Definition at line 142 of file AlignTools.cc.
References i.
Referenced by MuonGeometryArrange::compareGeometries(), and createPoints().
void align::rectify | ( | RotationType & | rot | ) |
Correct a rotation matrix for rounding errors.
Definition at line 196 of file Utilities.cc.
References toAngles(), and toMatrix().
Referenced by BeamSpotAlignmentParameters::apply(), RigidBodyAlignmentParameters::apply(), TwoBowedSurfacesAlignmentParameters::apply(), BowedSurfaceAlignmentParameters::apply(), AlignmentParameterStore::applyAlignableAbsolutePositions(), MuonAlignmentInputXML::set_one_position(), and SurveyAlignment::shiftSensors().
{ // Use ROOT for better numerical precision but slower. // ROOT::Math::Rotation3D temp( rot.xx(), rot.xy(), rot.xz(), // rot.yx(), rot.yy(), rot.yz(), // rot.zx(), rot.zy(), rot.zz() ); // // temp.Rectify(); // // Scalar elems[9]; // // temp.GetComponents(elems); // rot = RotationType(elems); rot = toMatrix( toAngles(rot) ); // fast rectification but less precise }
align::EulerAngles align::toAngles | ( | const RotationType & | rot | ) |
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition at line 7 of file Utilities.cc.
References abs, 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 AlignmentParameterStore::acquireRelativeParameters(), MuonGeometryArrange::compareGeometries(), diffAlignables(), RigidBodyAlignmentParameters::displacementFromAlignable(), MuonAlignmentInputXML::do_setposition(), KalmanAlignmentUserVariables::extractTrueParameters(), MuonGeometryArrange::fillTree(), TrackerGeometryCompare::fillTree(), KalmanAlignmentUserVariables::histogramParameters(), rectify(), BeamSpotAlignmentParameters::rotation(), SurveyResidual::sensorResidual(), AlignableSurface::toGlobal(), AlignableSurface::toLocal(), KalmanAlignmentUserVariables::update(), SurveyOutput::write(), and MuonAlignmentOutputXML::writeComponents().
{ const Scalar one = 1; // to ensure same precison is used in comparison EulerAngles angles(3); if (std::abs( rot.zx() ) > one) { edm::LogWarning("Alignment") << "Rounding errors in\n" << rot; } if (std::abs( rot.zx() ) < one) { angles(1) = -std::atan2( rot.zy(), rot.zz() ); angles(2) = std::asin( rot.zx() ); angles(3) = -std::atan2( rot.yx(), rot.xx() ); } else if (rot.zx() >= one) { angles(1) = std::atan2(rot.xy() + rot.yz(), rot.yy() - rot.xz() ); angles(2) = std::asin(one); angles(3) = 0; } else if (rot.zx() <= -one) { angles(1) = std::atan2(rot.xy() - rot.yz(), rot.yy() + rot.xz() ); angles(2) = std::asin(-one); angles(3) = 0; } return angles; }
align::RotationType align::toMatrix | ( | const EulerAngles & | angles | ) |
Convert rotation angles about x-, y-, z-axes to matrix.
Definition at line 40 of file Utilities.cc.
References alignmentValidation::c1, funct::cos(), indexGen::s2, and funct::sin().
Referenced by BeamSpotAlignmentParameters::apply(), RigidBodyAlignmentParameters::apply(), TwoBowedSurfacesAlignmentParameters::apply(), BowedSurfaceAlignmentParameters::apply(), KalmanAlignmentAlgorithm::applyAlignmentParameters(), PedeSteerer::correctToReferenceSystem(), diffRot(), MuonAlignmentInputXML::do_setposition(), MuonGeometryArrange::fillTree(), KalmanAlignmentUserVariables::histogramParameters(), KalmanAlignmentAlgorithm::initializeAlignmentParameters(), moveAlignable(), rectify(), AlignmentParameterStore::setAlignmentPositionError(), TrackerGeometryCompare::setCommonTrackerSystem(), SurveyAlignment::shiftSensors(), AlignmentProducer::simpleMisalignment_(), AlignableSurface::toGlobal(), AlignableSurface::toLocal(), and KalmanAlignmentUserVariables::update().
{ Scalar s1 = std::sin(angles[0]), c1 = std::cos(angles[0]); Scalar s2 = std::sin(angles[1]), c2 = std::cos(angles[1]); Scalar s3 = std::sin(angles[2]), c3 = std::cos(angles[2]); return RotationType( c2 * c3, c1 * s3 + s1 * s2 * c3, s1 * s3 - c1 * s2 * c3, -c2 * s3, c1 * c3 - s1 * s2 * s3, s1 * c3 + c1 * s2 * s3, s2, -s1 * c2, c1 * c2); }