CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/Alignment/CommonAlignment/src/AlignmentParameters.cc

Go to the documentation of this file.
00001 #include "FWCore/Utilities/interface/Exception.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 #include "Alignment/CommonAlignment/interface/Alignable.h"
00005 
00006 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
00007 
00008 
00009 //__________________________________________________________________________________________________
00010 AlignmentParameters::AlignmentParameters() :
00011   theAlignable( 0),
00012   theUserVariables( 0),
00013   bValid(true)
00014 {}
00015 
00016 
00017 //__________________________________________________________________________________________________
00018 AlignmentParameters::AlignmentParameters(Alignable* object, const AlgebraicVector& par, 
00019                                          const AlgebraicSymMatrix& cov) :
00020   theAlignable(object),
00021   theData( DataContainer( new AlignmentParametersData(par,cov) ) ),
00022   theUserVariables(0),
00023   bValid(true)
00024 {
00025   // is the data consistent?
00026   theData->checkConsistency();
00027 }
00028 
00029 
00030 //__________________________________________________________________________________________________
00031 AlignmentParameters::AlignmentParameters(Alignable* object, const AlgebraicVector& par, 
00032                                          const AlgebraicSymMatrix& cov, 
00033                                          const std::vector<bool>& sel) :
00034   theAlignable(object),
00035   theData( DataContainer( new AlignmentParametersData(par,cov,sel) ) ),
00036   theUserVariables(0),
00037   bValid(true)
00038 {
00039   // is the data consistent?
00040   theData->checkConsistency();
00041 }
00042 
00043 
00044 //__________________________________________________________________________________________________
00045 AlignmentParameters::AlignmentParameters(Alignable* object,
00046                                          const AlignmentParametersData::DataContainer& data ) :
00047   theAlignable(object),
00048   theData(data),
00049   theUserVariables(0),
00050   bValid(true)
00051 {
00052   // is the data consistent?
00053   theData->checkConsistency();
00054 }
00055 
00056 
00057 //__________________________________________________________________________________________________
00058 AlignmentParameters::~AlignmentParameters()
00059 { 
00060   if ( theUserVariables ) delete theUserVariables;
00061 }
00062 
00063 
00064 //__________________________________________________________________________________________________
00065 const std::vector<bool>& AlignmentParameters::selector(void) const
00066 { 
00067   return theData->selector();
00068 }
00069 
00070 //__________________________________________________________________________________________________
00071 int AlignmentParameters::numSelected(void) const
00072 {
00073   return theData->numSelected();
00074 }
00075 
00076 
00077 //__________________________________________________________________________________________________
00078 AlgebraicVector AlignmentParameters::selectedParameters(void) const
00079 { 
00080   return collapseVector( theData->parameters(), theData->selector() );
00081 }
00082 
00083 
00084 //__________________________________________________________________________________________________
00085 AlgebraicSymMatrix AlignmentParameters::selectedCovariance(void) const
00086 { 
00087   return collapseSymMatrix( theData->covariance(), theData->selector() );
00088 }
00089 
00090 
00091 //__________________________________________________________________________________________________
00092 const AlgebraicVector& AlignmentParameters::parameters(void) const
00093 { 
00094   return theData->parameters();
00095 }
00096 
00097 
00098 //__________________________________________________________________________________________________
00099 const AlgebraicSymMatrix& AlignmentParameters::covariance(void) const
00100 { 
00101   return theData->covariance();
00102 }
00103 
00104 //__________________________________________________________________________________________________
00105 AlgebraicMatrix
00106 AlignmentParameters::selectedDerivatives(const TrajectoryStateOnSurface& tsos,
00107                                          const AlignableDetOrUnitPtr &alignableDet) const
00108 {
00109   const AlgebraicMatrix dev(this->derivatives(tsos, alignableDet));
00110 
00111   const int ncols  = dev.num_col();
00112   const int nrows  = dev.num_row();
00113   const int nsel   = numSelected();
00114 
00115   AlgebraicMatrix seldev(nsel, ncols);
00116 
00117   int ir2 = 0;
00118   for (int irow = 0; irow < nrows; ++irow) {
00119     if (this->selector()[irow]) {
00120       for (int icol = 0; icol < ncols; ++icol) {
00121         seldev[ir2][icol] = dev[irow][icol];
00122       }
00123       ++ir2;
00124     }
00125   }
00126 
00127   return seldev;
00128 }
00129 
00130 //__________________________________________________________________________________________________
00131 void  AlignmentParameters::setUserVariables(AlignmentUserVariables* auv)
00132 { 
00133   if ( theUserVariables ) delete theUserVariables;
00134   theUserVariables = auv;
00135 }
00136 
00137 
00138 //__________________________________________________________________________________________________
00139 AlignmentUserVariables*  AlignmentParameters::userVariables(void) const
00140 { 
00141   return theUserVariables;
00142 }
00143 
00144 
00145 //__________________________________________________________________________________________________
00146 Alignable* AlignmentParameters::alignable(void) const
00147 { 
00148   return theAlignable;
00149 }
00150 
00151 //__________________________________________________________________________________________________
00152 unsigned int AlignmentParameters::hierarchyLevel() const
00153 {
00154   if (!theAlignable) {
00155     edm::LogError("Alignment") << "@SUB=AlignmentParameters::hierarchyLevel"
00156                                << "Called for AlignmentParameters without pointer to Alignable";
00157     return 0;
00158   }
00159 
00160   std::vector<Alignable*> comps;
00161   theAlignable->firstCompsWithParams(comps);
00162   if (comps.empty()) return 0;
00163 
00164   unsigned int maxLevelOfComp = 0;
00165   for (std::vector<Alignable*>::const_iterator iAli = comps.begin(), iAliEnd = comps.end();
00166        iAli != iAliEnd; ++iAli) {// firstCompsWithParams guaranties that alignmentParameters() != 0:
00167     const unsigned int compResult = (*iAli)->alignmentParameters()->hierarchyLevel();
00168     // levels might be different for components, get largest:
00169     if (maxLevelOfComp < compResult) maxLevelOfComp = compResult;
00170   }
00171 
00172   return maxLevelOfComp + 1;
00173 }
00174 
00175 
00176 //__________________________________________________________________________________________________
00177 int AlignmentParameters::size(void) const
00178 { 
00179   return theData->parameters().num_row();
00180 }
00181 
00182 
00183 //__________________________________________________________________________________________________
00184 bool AlignmentParameters::isValid(void) const
00185 { 
00186   return bValid;
00187 }
00188 
00189 
00190 //__________________________________________________________________________________________________
00191 void AlignmentParameters::setValid(bool v)
00192 { 
00193   bValid=v;
00194 }
00195 
00196 
00197 //__________________________________________________________________________________________________
00198 AlgebraicSymMatrix 
00199 AlignmentParameters::collapseSymMatrix(const AlgebraicSymMatrix& m,
00200                                        const std::vector<bool>& sel ) const
00201 {
00202 
00203   int nRows = m.num_row();
00204   int size  = sel.size();
00205 
00206   // Check size matching
00207   if ( nRows != size ) 
00208     throw cms::Exception("LogicError") << "Size mismatch in parameters";
00209 
00210   // If OK, continue
00211   std::vector<int> rowvec;
00212   for ( int i=0; i<nRows; i++ ) 
00213     if ( sel[i] ) rowvec.push_back(i);
00214  
00215   int nSelectedRows = rowvec.size();
00216   AlgebraicSymMatrix result( nSelectedRows, 0 );
00217   for (int i=0; i<nSelectedRows; i++) 
00218     for (int j=0; j<nSelectedRows; j++)
00219       result[i][j] = m[ rowvec[i] ][ rowvec[j] ];
00220 
00221   return result;
00222 
00223 }
00224 
00225 
00226 //__________________________________________________________________________________________________
00227 AlgebraicVector AlignmentParameters::collapseVector(const AlgebraicVector& m, 
00228                                                     const std::vector<bool>& sel ) const
00229 {
00230 
00231   int nRows = m.num_row();
00232   int size  = sel.size();
00233 
00234   // Check size matching
00235   if ( nRows != size ) 
00236     throw cms::Exception("LogicError") << "Size mismatch in parameters";
00237 
00238   // If OK, continue
00239   std::vector<int> rowvec;
00240   for ( int i=0; i<nRows; i++ ) 
00241     if ( sel[i] ) rowvec.push_back(i);
00242 
00243   int nSelectedRows=rowvec.size();
00244   AlgebraicVector result( nSelectedRows, 0 );
00245   for ( int i=0; i<nSelectedRows; i++ )
00246     result[i] = m[ (int)rowvec[i] ];
00247 
00248   return result;
00249 
00250 }
00251 
00252 
00253 //__________________________________________________________________________________________________
00254 AlgebraicSymMatrix AlignmentParameters::expandSymMatrix(const AlgebraicSymMatrix& m, 
00255                                                         const std::vector<bool>& sel) const
00256 {
00257 
00258   int nRows = m.num_row();
00259   int size  = sel.size();
00260 
00261   std::vector<int> rowvec;
00262   for ( int i=0; i<size; i++ ) 
00263     if ( sel[i] ) rowvec.push_back(i);
00264 
00265   // Check size matching
00266   if( nRows != static_cast<int>(rowvec.size()) ) 
00267     throw cms::Exception("LogicError") << "Size mismatch in parameters";
00268 
00269   // If OK, continue
00270   AlgebraicSymMatrix result(size,0);
00271   for ( int i=0; i<nRows; i++ )
00272     for (int j=0; j<nRows; j++)
00273       result[ rowvec[i] ][ rowvec[j] ] = m[i][j];
00274 
00275   return result;
00276 }
00277 
00278 
00279 //__________________________________________________________________________________________________
00280 AlgebraicVector AlignmentParameters::expandVector(const AlgebraicVector& m, 
00281                                                   const std::vector<bool>& sel) const
00282 {
00283 
00284   int nRows = m.num_row();
00285   int size  = sel.size();
00286 
00287   std::vector<int> rowvec;
00288   for ( int i=0; i<size; i++ ) 
00289     if (sel[i]==true) rowvec.push_back(i);
00290 
00291   // Check size matching
00292   if( nRows != static_cast<int>(rowvec.size()) ) 
00293     throw cms::Exception("LogicError") << "Size mismatch in parameters";
00294 
00295   // If OK, continue
00296   AlgebraicVector result(size,0);
00297   for (int i=0; i<nRows; i++) result[ rowvec[i] ] = m[i];
00298   return result;
00299 
00300 }