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
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
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
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 const 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
00106 void AlignmentParameters::setUserVariables(AlignmentUserVariables* auv)
00107 {
00108 if ( theUserVariables ) delete theUserVariables;
00109 theUserVariables = auv;
00110 }
00111
00112
00113
00114 AlignmentUserVariables* AlignmentParameters::userVariables(void) const
00115 {
00116 return theUserVariables;
00117 }
00118
00119
00120
00121 Alignable* AlignmentParameters::alignable(void) const
00122 {
00123 return theAlignable;
00124 }
00125
00126
00127 unsigned int AlignmentParameters::hierarchyLevel() const
00128 {
00129 if (!theAlignable) {
00130 edm::LogError("Alignment") << "@SUB=AlignmentParameters::hierarchyLevel"
00131 << "Called for AlignmentParameters without pointer to Alignable";
00132 return 0;
00133 }
00134
00135 std::vector<Alignable*> comps;
00136 theAlignable->firstCompsWithParams(comps);
00137 if (comps.empty()) return 0;
00138
00139 unsigned int maxLevelOfComp = 0;
00140 for (std::vector<Alignable*>::const_iterator iAli = comps.begin(), iAliEnd = comps.end();
00141 iAli != iAliEnd; ++iAli) {
00142 const unsigned int compResult = (*iAli)->alignmentParameters()->hierarchyLevel();
00143
00144 if (maxLevelOfComp < compResult) maxLevelOfComp = compResult;
00145 }
00146
00147 return maxLevelOfComp + 1;
00148 }
00149
00150
00151
00152 const int AlignmentParameters::size(void) const
00153 {
00154 return theData->parameters().num_row();
00155 }
00156
00157
00158
00159 const bool AlignmentParameters::isValid(void) const
00160 {
00161 return bValid;
00162 }
00163
00164
00165
00166 void AlignmentParameters::setValid(bool v)
00167 {
00168 bValid=v;
00169 }
00170
00171
00172
00173 AlgebraicSymMatrix
00174 AlignmentParameters::collapseSymMatrix(const AlgebraicSymMatrix& m,
00175 const std::vector<bool>& sel ) const
00176 {
00177
00178 int nRows = m.num_row();
00179 int size = sel.size();
00180
00181
00182 if ( nRows != size )
00183 throw cms::Exception("LogicError") << "Size mismatch in parameters";
00184
00185
00186 std::vector<int> rowvec;
00187 for ( int i=0; i<nRows; i++ )
00188 if ( sel[i] ) rowvec.push_back(i);
00189
00190 int nSelectedRows = rowvec.size();
00191 AlgebraicSymMatrix result( nSelectedRows, 0 );
00192 for (int i=0; i<nSelectedRows; i++)
00193 for (int j=0; j<nSelectedRows; j++)
00194 result[i][j] = m[ rowvec[i] ][ rowvec[j] ];
00195
00196 return result;
00197
00198 }
00199
00200
00201
00202 AlgebraicVector AlignmentParameters::collapseVector(const AlgebraicVector& m,
00203 const std::vector<bool>& sel ) const
00204 {
00205
00206 int nRows = m.num_row();
00207 int size = sel.size();
00208
00209
00210 if ( nRows != size )
00211 throw cms::Exception("LogicError") << "Size mismatch in parameters";
00212
00213
00214 std::vector<int> rowvec;
00215 for ( int i=0; i<nRows; i++ )
00216 if ( sel[i] ) rowvec.push_back(i);
00217
00218 int nSelectedRows=rowvec.size();
00219 AlgebraicVector result( nSelectedRows, 0 );
00220 for ( int i=0; i<nSelectedRows; i++ )
00221 result[i] = m[ (int)rowvec[i] ];
00222
00223 return result;
00224
00225 }
00226
00227
00228
00229 AlgebraicSymMatrix AlignmentParameters::expandSymMatrix(const AlgebraicSymMatrix& m,
00230 const std::vector<bool>& sel) const
00231 {
00232
00233 int nRows = m.num_row();
00234 int size = sel.size();
00235
00236 std::vector<int> rowvec;
00237 for ( int i=0; i<size; i++ )
00238 if ( sel[i] ) rowvec.push_back(i);
00239
00240
00241 if( nRows != static_cast<int>(rowvec.size()) )
00242 throw cms::Exception("LogicError") << "Size mismatch in parameters";
00243
00244
00245 AlgebraicSymMatrix result(size,0);
00246 for ( int i=0; i<nRows; i++ )
00247 for (int j=0; j<nRows; j++)
00248 result[ rowvec[i] ][ rowvec[j] ] = m[i][j];
00249
00250 return result;
00251 }
00252
00253
00254
00255 AlgebraicVector AlignmentParameters::expandVector(const AlgebraicVector& m,
00256 const std::vector<bool>& sel) const
00257 {
00258
00259 int nRows = m.num_row();
00260 int size = sel.size();
00261
00262 std::vector<int> rowvec;
00263 for ( int i=0; i<size; i++ )
00264 if (sel[i]==true) rowvec.push_back(i);
00265
00266
00267 if( nRows != static_cast<int>(rowvec.size()) )
00268 throw cms::Exception("LogicError") << "Size mismatch in parameters";
00269
00270
00271 AlgebraicVector result(size,0);
00272 for (int i=0; i<nRows; i++) result[ rowvec[i] ] = m[i];
00273 return result;
00274
00275 }