Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:44

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 
0003 #include "Alignment/CommonAlignment/interface/Alignable.h"
0004 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
0005 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
0006 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0007 
0008 #include "Alignment/CommonAlignmentParametrization/interface/CompositeAlignmentDerivativesExtractor.h"
0009 
0010 //--------------------------------------------------------------------------------------
0011 CompositeAlignmentDerivativesExtractor::CompositeAlignmentDerivativesExtractor(
0012     const align::Alignables &alignables,
0013     const std::vector<AlignableDet *> &alignableDets,
0014     const std::vector<TrajectoryStateOnSurface> &tsos) {
0015   std::vector<AlignableDetOrUnitPtr> detOrUnits;
0016   detOrUnits.reserve(alignableDets.size());
0017 
0018   std::vector<AlignableDet *>::const_iterator it, itEnd;
0019   for (it = alignableDets.begin(), itEnd = alignableDets.end(); it != itEnd; ++it)
0020     detOrUnits.push_back(AlignableDetOrUnitPtr(*it));
0021 
0022   extractCurrentAlignment(alignables, detOrUnits, tsos);
0023 }
0024 
0025 //--------------------------------------------------------------------------------------
0026 CompositeAlignmentDerivativesExtractor::CompositeAlignmentDerivativesExtractor(
0027     const align::Alignables &alignables,
0028     const std::vector<AlignableDetOrUnitPtr> &alignableDets,
0029     const std::vector<TrajectoryStateOnSurface> &tsos) {
0030   extractCurrentAlignment(alignables, alignableDets, tsos);
0031 }
0032 
0033 //--------------------------------------------------------------------------------------
0034 
0035 void CompositeAlignmentDerivativesExtractor::extractCurrentAlignment(
0036     const align::Alignables &alignables,
0037     const std::vector<AlignableDetOrUnitPtr> &alignableDets,
0038     const std::vector<TrajectoryStateOnSurface> &tsos) {
0039   // sanity check
0040   if (alignables.size() != alignableDets.size()) {
0041     edm::LogError("CompositeAlignmentDerivativesExtractor")
0042         << "Inconsistent length of arguments: alignables=" << alignables.size()
0043         << ", alignableDets=" << alignableDets.size();
0044     return;
0045   }
0046 
0047   if (alignables.size() != tsos.size()) {
0048     edm::LogError("CompositeAlignmentDerivativesExtractor")
0049         << "Inconsistent length of arguments: alignables=" << alignables.size() << ", tsos=" << tsos.size();
0050     return;
0051   }
0052 
0053   align::Alignables::const_iterator itAlignable = alignables.begin();
0054   std::vector<AlignableDetOrUnitPtr>::const_iterator itAlignableDet = alignableDets.begin();
0055   std::vector<TrajectoryStateOnSurface>::const_iterator itTsos = tsos.begin();
0056 
0057   int nRow = 0;
0058   int nCollumn = 0;
0059   unsigned int nAlignables = 0;
0060 
0061   std::vector<AlgebraicMatrix> subDerivatives;
0062   std::vector<AlgebraicVector> subCorrectionTerm;
0063 
0064   // get the individual derivatives and correction term and determine the
0065   // dimension
0066   while (itAlignable != alignables.end()) {
0067     // Get the current estimate on the alignment parameters
0068     AlgebraicVector subAlignmentParameters = (*itAlignable)->alignmentParameters()->selectedParameters();
0069 
0070     // Get the derivatives or the local coordinates w.r.t. the corresponding
0071     // alignment parameters
0072     AlgebraicMatrix subAlignmentDerivatives =
0073         (*itAlignable)->alignmentParameters()->selectedDerivatives(*itTsos, *itAlignableDet);
0074 
0075     subDerivatives.push_back(subAlignmentDerivatives.T());
0076     subCorrectionTerm.push_back(subAlignmentDerivatives.T() * subAlignmentParameters);
0077 
0078     nRow += 2;
0079     // check if it is the first occurrence of this Alignable
0080     if (count(alignables.begin(), itAlignable, *itAlignable) == 0) {
0081       // matrix is transposed -> num_row() instead of num_col()
0082       nCollumn += subAlignmentDerivatives.num_row();
0083       nAlignables++;
0084     }
0085 
0086     ++itAlignable;
0087     ++itAlignableDet;
0088     ++itTsos;
0089   }
0090 
0091   // construct derivatives and correction term with the right dimension
0092   theDerivatives = AlgebraicMatrix(nRow, nCollumn, 0);
0093   theCorrectionTerm = AlgebraicVector(nRow, 0);
0094 
0095   if (alignables.size() == nAlignables)
0096     // One hit per alignable
0097     extractWithoutMultipleHits(subCorrectionTerm, subDerivatives);
0098   else
0099     // At least one alignable has two hits
0100     extractWithMultipleHits(subCorrectionTerm, subDerivatives, alignables);
0101 
0102   return;
0103 }
0104 
0105 //--------------------------------------------------------------------------------------
0106 
0107 void CompositeAlignmentDerivativesExtractor::extractWithoutMultipleHits(
0108     const std::vector<AlgebraicVector> &subCorrectionTerm, const std::vector<AlgebraicMatrix> &subDerivatives) {
0109   std::vector<AlgebraicVector>::const_iterator itSubCorrectionTerm = subCorrectionTerm.begin();
0110   std::vector<AlgebraicMatrix>::const_iterator itSubDerivatives = subDerivatives.begin();
0111 
0112   int iRow = 1;
0113   int iCollumn = 1;
0114 
0115   // Fill in the individual terms
0116   while (itSubCorrectionTerm != subCorrectionTerm.end()) {
0117     theCorrectionTerm.sub(iRow, *itSubCorrectionTerm);
0118     theDerivatives.sub(iRow, iCollumn, *itSubDerivatives);
0119 
0120     iRow += 2;
0121     iCollumn += (*itSubDerivatives).num_col();
0122 
0123     ++itSubCorrectionTerm;
0124     ++itSubDerivatives;
0125   }
0126 
0127   return;
0128 }
0129 
0130 //--------------------------------------------------------------------------------------
0131 
0132 void CompositeAlignmentDerivativesExtractor::extractWithMultipleHits(
0133     const std::vector<AlgebraicVector> &subCorrectionTerm,
0134     const std::vector<AlgebraicMatrix> &subDerivatives,
0135     const align::Alignables &alignables) {
0136   std::vector<AlgebraicVector>::const_iterator itSubCorrectionTerm = subCorrectionTerm.begin();
0137   std::vector<AlgebraicMatrix>::const_iterator itSubDerivatives = subDerivatives.begin();
0138   align::Alignables::const_iterator itAlignables = alignables.begin();
0139   align::Alignables::const_iterator itPosition;
0140   align::Alignables::const_iterator itLastPosition;
0141 
0142   int iRow = 1;
0143 
0144   // Fill in the individual terms
0145   while (itAlignables != alignables.end()) {
0146     theCorrectionTerm.sub(iRow, *itSubCorrectionTerm);
0147 
0148     int iCollumn = 1;
0149     int iAlignable = 0;
0150 
0151     itLastPosition = find(alignables.begin(), itAlignables, *itAlignables);
0152 
0153     for (itPosition = alignables.begin(); itPosition != itLastPosition; ++itPosition) {
0154       if (count(alignables.begin(), itPosition, *itPosition) == 0)
0155         iCollumn += subDerivatives[iAlignable].num_col();
0156       iAlignable++;
0157     }
0158 
0159     theDerivatives.sub(iRow, iCollumn, *itSubDerivatives);
0160 
0161     iRow += 2;
0162 
0163     ++itAlignables;
0164     ++itSubCorrectionTerm;
0165     ++itSubDerivatives;
0166   }
0167 
0168   return;
0169 }