CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Alignment/CommonAlignmentParametrization/src/CompositeAlignmentDerivativesExtractor.cc

Go to the documentation of this file.
00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 
00003 #include "Alignment/CommonAlignment/interface/Alignable.h"
00004 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
00005 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
00006 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00007 
00008 #include "Alignment/CommonAlignmentParametrization/interface/CompositeAlignmentDerivativesExtractor.h"
00009 
00010 //--------------------------------------------------------------------------------------
00011 CompositeAlignmentDerivativesExtractor::
00012 CompositeAlignmentDerivativesExtractor( const std::vector< Alignable* > & alignables,
00013                                         const std::vector< AlignableDet* > & alignableDets,
00014                                         const std::vector< TrajectoryStateOnSurface > & tsos )
00015 {
00016   std::vector<AlignableDetOrUnitPtr> detOrUnits;
00017   detOrUnits.reserve(alignableDets.size());
00018 
00019   std::vector<AlignableDet*>::const_iterator it, itEnd;
00020   for (it = alignableDets.begin(), itEnd = alignableDets.end(); it != itEnd; ++it)
00021     detOrUnits.push_back(AlignableDetOrUnitPtr(*it));
00022 
00023   extractCurrentAlignment( alignables, detOrUnits, tsos );
00024 }
00025 
00026 //--------------------------------------------------------------------------------------
00027 CompositeAlignmentDerivativesExtractor::
00028 CompositeAlignmentDerivativesExtractor( const std::vector< Alignable* > & alignables,
00029                                         const std::vector< AlignableDetOrUnitPtr > & alignableDets,
00030                                         const std::vector< TrajectoryStateOnSurface > & tsos )
00031 {
00032   extractCurrentAlignment( alignables, alignableDets, tsos );
00033 }
00034 
00035 //--------------------------------------------------------------------------------------
00036 
00037 void CompositeAlignmentDerivativesExtractor::
00038 extractCurrentAlignment( const std::vector< Alignable* > & alignables,
00039                          const std::vector< AlignableDetOrUnitPtr > & alignableDets,
00040                          const std::vector< TrajectoryStateOnSurface > & tsos )
00041 {
00042 
00043   // sanity check
00044   if ( alignables.size() != alignableDets.size() )
00045   {
00046         edm::LogError("CompositeAlignmentDerivativesExtractor") 
00047           << "Inconsistent length of arguments: alignables=" << alignables.size() 
00048           << ", alignableDets=" << alignableDets.size();
00049     return;
00050   }
00051 
00052   if ( alignables.size() != tsos.size() )
00053         {
00054           edm::LogError("CompositeAlignmentDerivativesExtractor") 
00055                 << "Inconsistent length of arguments: alignables=" << alignables.size()
00056                 << ", tsos=" << tsos.size();
00057           return;
00058         }
00059 
00060   std::vector< Alignable* >::const_iterator itAlignable = alignables.begin();
00061   std::vector< AlignableDetOrUnitPtr >::const_iterator itAlignableDet = alignableDets.begin();
00062   std::vector< TrajectoryStateOnSurface >::const_iterator itTsos = tsos.begin();
00063 
00064   int nRow = 0;
00065   int nCollumn = 0;
00066   unsigned int nAlignables = 0;
00067 
00068   std::vector< AlgebraicMatrix > subDerivatives;
00069   std::vector< AlgebraicVector > subCorrectionTerm;
00070 
00071 
00072   // get the individual derivatives and correction term and determine the dimension
00073   while ( itAlignable != alignables.end() )
00074   {
00075     // Get the current estimate on the alignment parameters
00076     AlgebraicVector subAlignmentParameters = 
00077           ( *itAlignable )->alignmentParameters()->selectedParameters();
00078 
00079     // Get the derivatives or the local coordinates w.r.t. the corresponding alignment parameters
00080     AlgebraicMatrix subAlignmentDerivatives =
00081       ( *itAlignable )->alignmentParameters()->selectedDerivatives( *itTsos, *itAlignableDet );
00082 
00083     subDerivatives.push_back( subAlignmentDerivatives.T() );
00084     subCorrectionTerm.push_back( subAlignmentDerivatives.T()*subAlignmentParameters );
00085 
00086     nRow += 2;
00087     // check if it is the first occurrence of this Alignable
00088     if ( count( alignables.begin(), itAlignable, *itAlignable ) == 0 )
00089     {
00090           // matrix is transposed -> num_row() instead of num_col()
00091       nCollumn += subAlignmentDerivatives.num_row();
00092       nAlignables++;
00093     }
00094 
00095     itAlignable++;
00096     itAlignableDet++;
00097     itTsos++;
00098   }
00099 
00100   // construct derivatives and correction term with the right dimension
00101   theDerivatives = AlgebraicMatrix( nRow, nCollumn, 0 );
00102   theCorrectionTerm = AlgebraicVector( nRow, 0 );
00103 
00104   if ( alignables.size() == nAlignables )
00105     // One hit per alignable
00106     extractWithoutMultipleHits( subCorrectionTerm, subDerivatives );
00107   else
00108     // At least one alignable has two hits
00109     extractWithMultipleHits( subCorrectionTerm, subDerivatives, alignables );
00110 
00111   return;
00112 
00113 }
00114 
00115 //--------------------------------------------------------------------------------------
00116 
00117 void CompositeAlignmentDerivativesExtractor::
00118 extractWithoutMultipleHits( const std::vector< AlgebraicVector > & subCorrectionTerm,
00119                                                         const std::vector< AlgebraicMatrix > & subDerivatives )
00120 {
00121   std::vector< AlgebraicVector >::const_iterator itSubCorrectionTerm = subCorrectionTerm.begin();
00122   std::vector< AlgebraicMatrix >::const_iterator itSubDerivatives = subDerivatives.begin();
00123 
00124   int iRow = 1;
00125   int iCollumn = 1;
00126 
00127   // Fill in the individual terms
00128   while ( itSubCorrectionTerm != subCorrectionTerm.end() )
00129   {
00130     theCorrectionTerm.sub( iRow, *itSubCorrectionTerm );
00131     theDerivatives.sub( iRow, iCollumn, *itSubDerivatives );
00132 
00133     iRow += 2;
00134     iCollumn += ( *itSubDerivatives ).num_col();
00135 
00136     itSubCorrectionTerm++;
00137     itSubDerivatives++;
00138   }
00139 
00140   return;
00141 }
00142 
00143 //--------------------------------------------------------------------------------------
00144 
00145 void CompositeAlignmentDerivativesExtractor::
00146 extractWithMultipleHits( const std::vector< AlgebraicVector > & subCorrectionTerm,
00147                                                  const std::vector< AlgebraicMatrix > & subDerivatives,
00148                                                  const std::vector< Alignable* > & alignables )
00149 {
00150 
00151   std::vector< AlgebraicVector >::const_iterator itSubCorrectionTerm = subCorrectionTerm.begin();
00152   std::vector< AlgebraicMatrix >::const_iterator itSubDerivatives = subDerivatives.begin();
00153   std::vector< Alignable* >::const_iterator itAlignables = alignables.begin();
00154   std::vector< Alignable* >::const_iterator itPosition;
00155   std::vector< Alignable* >::const_iterator itLastPosition;
00156 
00157   int iRow = 1;
00158 
00159   // Fill in the individual terms
00160   while ( itAlignables != alignables.end() )
00161   {
00162     theCorrectionTerm.sub( iRow, *itSubCorrectionTerm );
00163 
00164     int iCollumn = 1;
00165     int iAlignable = 0;
00166 
00167     itLastPosition = find( alignables.begin(), itAlignables, *itAlignables );
00168 
00169     for ( itPosition = alignables.begin(); itPosition != itLastPosition; itPosition++ )
00170           {
00171                 if ( count( alignables.begin(), itPosition, *itPosition ) == 0 )
00172                   iCollumn += subDerivatives[iAlignable].num_col();
00173                 iAlignable++;
00174           }
00175 
00176     theDerivatives.sub( iRow, iCollumn, *itSubDerivatives );
00177 
00178     iRow += 2;
00179         
00180     itAlignables++;
00181     itSubCorrectionTerm++;
00182     itSubDerivatives++;
00183   }
00184 
00185   return;
00186 }
00187