CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/CommonAlignmentParametrization/src/ParametersToParametersDerivatives.cc

Go to the documentation of this file.
00001 
00007 #include "Alignment/CommonAlignmentParametrization/interface/ParametersToParametersDerivatives.h"
00008 
00009 #include "CondFormats/Alignment/interface/Definitions.h"
00010 #include "Alignment/CommonAlignment/interface/Alignable.h"
00011 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
00012 #include "Alignment/CommonAlignmentParametrization/interface/FrameToFrameDerivative.h"
00013 #include "Alignment/CommonAlignmentParametrization/interface/AlignmentParametersFactory.h"
00014 #include "Alignment/CommonAlignmentParametrization/interface/BowedSurfaceAlignmentDerivatives.h"
00015 #include "Alignment/CommonAlignmentParametrization/interface/TwoBowedSurfacesAlignmentParameters.h"
00016 
00017 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 // already in header:
00020 // #include "DataFormats/Math/interface/AlgebraicROOTObjects.h"
00021 
00022 //_________________________________________________________________________________________________
00023 ParametersToParametersDerivatives
00024 ::ParametersToParametersDerivatives(const Alignable &component, const Alignable &mother)
00025   : isOK_(component.alignmentParameters() && mother.alignmentParameters())
00026 {
00027   if (isOK_) {
00028     isOK_ = this->init(component, component.alignmentParameters()->type(),
00029                        mother,    mother   .alignmentParameters()->type());
00030   }
00031 }
00032 
00033 //_________________________________________________________________________________________________
00034 bool ParametersToParametersDerivatives::init(const Alignable &component, int typeComponent,
00035                                              const Alignable &mother, int typeMother)
00036 {
00037   using namespace AlignmentParametersFactory; // for kRigidBody etc.
00038   if ((typeMother    == kRigidBody || typeMother    == kRigidBody4D) &&
00039       (typeComponent == kRigidBody || typeComponent == kRigidBody4D)) {
00040     return this->initRigidRigid(component, mother);
00041   } else if ((typeMother == kRigidBody || typeMother == kRigidBody4D) &&
00042              typeComponent == kBowedSurface) {
00043     return this->initBowedRigid(component, mother);
00044   } else if ((typeMother == kRigidBody || typeMother == kRigidBody4D) &&
00045              typeComponent == kTwoBowedSurfaces) {
00046     return this->init2BowedRigid(component, mother);
00047   } else {
00048     // missing: mother with bows and component without, i.e. having 'common' bow parameters
00049     edm::LogError("Alignment") << "@SUB=ParametersToParametersDerivatives::init"
00050                                << "Mother " << parametersTypeName(parametersType(typeMother))
00051                                << ", component " << parametersTypeName(parametersType(typeComponent))
00052                                << ": not supported.";
00053     return false;
00054   }
00055 
00056 }
00057 
00058 //_________________________________________________________________________________________________
00059 bool ParametersToParametersDerivatives::initRigidRigid(const Alignable &component,
00060                                                        const Alignable &mother)
00061 {
00062   // simply frame to frame!
00063   FrameToFrameDerivative f2fDerivMaker;
00064   AlgebraicMatrix66 m(asSMatrix<6,6>(f2fDerivMaker.frameToFrameDerivative(&component, &mother)));
00065 
00066   // copy to TMatrix
00067   derivatives_.ResizeTo(6,6);
00068   derivatives_.SetMatrixArray(m.begin());
00069 
00070   return true;
00071 }
00072 
00073 //_________________________________________________________________________________________________
00074 bool ParametersToParametersDerivatives::initBowedRigid(const Alignable &component,
00075                                                        const Alignable &mother)
00076 {
00077   // component is bowed surface, mother rigid body
00078   FrameToFrameDerivative f2fMaker;
00079   const AlgebraicMatrix66 f2f(asSMatrix<6,6>(f2fMaker.frameToFrameDerivative(&component,&mother)));
00080   const double halfWidth  = 0.5 * component.surface().width();
00081   const double halfLength = 0.5 * component.surface().length();
00082   const AlgebraicMatrix69 m(this->dBowed_dRigid(f2f, halfWidth, halfLength));
00083 
00084   // copy to TMatrix
00085   derivatives_.ResizeTo(6,9);
00086   derivatives_.SetMatrixArray(m.begin());
00087 
00088   return true;
00089 }
00090 
00091 //_________________________________________________________________________________________________
00092 bool ParametersToParametersDerivatives::init2BowedRigid(const Alignable &component,
00093                                                         const Alignable &mother)
00094 {
00095   // component is two bowed surfaces, mother rigid body
00096   const TwoBowedSurfacesAlignmentParameters *aliPar = 
00097     dynamic_cast<TwoBowedSurfacesAlignmentParameters*>(component.alignmentParameters());
00098 
00099   if (!aliPar) {
00100     edm::LogError("Alignment") << "@SUB=ParametersToParametersDerivatives::init2BowedRigid"
00101                                << "dynamic_cast to TwoBowedSurfacesAlignmentParameters failed.";
00102     return false;
00103   }
00104 
00105   // We treat the two surfaces as independent objects, i.e.
00106   // 1) get the global position of each surface, depending on the ySplit value,
00107   const double ySplit = aliPar->ySplit();
00108   const double halfWidth   = 0.5 * component.surface().width();
00109   const double halfLength  = 0.5 * component.surface().length();
00110   const double halfLength1 = 0.5 * (halfLength + ySplit);
00111   const double halfLength2 = 0.5 * (halfLength - ySplit);
00112   const double yM1 = 0.5 * (ySplit - halfLength); // y_mean of surface 1
00113   const double yM2 = yM1 + halfLength;            // y_mean of surface 2
00114   // The sensor positions and orientations could be adjusted using
00115   // TwoBowedSurfacesDeformation attached to the component,
00116   // but that should be 2nd order effect.
00117   const align::GlobalPoint posSurf1(component.surface().toGlobal(align::LocalPoint(0.,yM1,0.)));
00118   const align::GlobalPoint posSurf2(component.surface().toGlobal(align::LocalPoint(0.,yM2,0.)));
00119 
00120   // 2) get derivatives for both,
00121   FrameToFrameDerivative f2fMaker;
00122   const AlgebraicMatrix66 f2fSurf1(f2fMaker.getDerivative(component.globalRotation(),
00123                                                           mother.globalRotation(),
00124                                                           posSurf1, mother.globalPosition()));
00125   const AlgebraicMatrix66 f2fSurf2(f2fMaker.getDerivative(component.globalRotation(),
00126                                                           mother.globalRotation(),
00127                                                           posSurf2, mother.globalPosition()));
00128   const AlgebraicMatrix69 derivs1(this->dBowed_dRigid(f2fSurf1, halfWidth, halfLength1));
00129   const AlgebraicMatrix69 derivs2(this->dBowed_dRigid(f2fSurf2, halfWidth, halfLength2));
00130 
00131   // 3) fill the common matrix by merging the two.
00132   typedef ROOT::Math::SMatrix<double,6,18,ROOT::Math::MatRepStd<double,6,18> > AlgebraicMatrix6_18;
00133   AlgebraicMatrix6_18 derivs;
00134   derivs.Place_at(derivs1, 0, 0); // left half
00135   derivs.Place_at(derivs2, 0, 9); // right half
00136 
00137   // copy to TMatrix
00138   derivatives_.ResizeTo(6, 18);
00139   derivatives_.SetMatrixArray(derivs.begin());
00140 
00141   return true;
00142 }
00143 
00144 //_________________________________________________________________________________________________
00145 ParametersToParametersDerivatives::AlgebraicMatrix69
00146 ParametersToParametersDerivatives::dBowed_dRigid(const AlgebraicMatrix66 &f2f,
00147                                                  double halfWidth, double halfLength) const
00148 {
00149   typedef BowedSurfaceAlignmentDerivatives BowedDerivs;
00150   const double gammaScale = BowedDerivs::gammaScale(2.*halfWidth, 2.*halfLength);
00151 
00152   // 1st index (column) is parameter of the mother (<6),
00153   // 2nd index (row) that of component (<9):
00154   AlgebraicMatrix69 derivs;
00155 
00156   for (unsigned int iRow = 0; iRow < 6; ++iRow) { // 6 rigid body parameters of mother
00157     // First copy the common rigid body part, e.g.:
00158     // - (0,0): du_comp/du_moth
00159     // - (0,1): dv_comp/du_moth
00160     // - (1,2): dw_comp/dv_moth
00161     for (unsigned int iCol = 0; iCol < 3; ++iCol) { // 3 movements of component
00162       derivs(iRow, iCol) = f2f(iRow, iCol);  
00163     }
00164 
00165     // Now we have to take care of order and scales for rotation-like parameters:
00166     // slopeX -> halfWidth * beta
00167     derivs(iRow, 3) = halfWidth  * f2f(iRow, 4); // = dslopeX_c/dpar_m = hw * db_c/dpar_m
00168     // slopeY -> halfLength * alpha
00169     derivs(iRow, 4) = halfLength * f2f(iRow, 3); // = dslopeY_c/dpar_m = hl * da_c/dpar_m
00170     // rotZ -> gammaScale * gamma
00171     derivs(iRow, 5) = gammaScale * f2f(iRow, 5); // = drotZ_c/dpar_m = gscale * dg_c/dpar_m
00172 
00173     // Finally, movements and rotations have no influence on surface internals:
00174     for (unsigned int iCol = 6; iCol < 9; ++iCol) { // 3 sagittae of component
00175       derivs(iRow, iCol) = 0.;  
00176     }
00177   }
00178 
00179   return derivs;
00180 }
00181 
00182 //_________________________________________________________________________________________________
00183 double ParametersToParametersDerivatives::operator() (unsigned int indParMother,
00184                                                       unsigned int indParComp) const
00185 {
00186   // Do range checks?
00187   return derivatives_(indParMother, indParComp);
00188 }