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
00020
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;
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
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
00063 FrameToFrameDerivative f2fDerivMaker;
00064 AlgebraicMatrix66 m(asSMatrix<6,6>(f2fDerivMaker.frameToFrameDerivative(&component, &mother)));
00065
00066
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
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
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
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
00106
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);
00113 const double yM2 = yM1 + halfLength;
00114
00115
00116
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
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
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);
00135 derivs.Place_at(derivs2, 0, 9);
00136
00137
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
00153
00154 AlgebraicMatrix69 derivs;
00155
00156 for (unsigned int iRow = 0; iRow < 6; ++iRow) {
00157
00158
00159
00160
00161 for (unsigned int iCol = 0; iCol < 3; ++iCol) {
00162 derivs(iRow, iCol) = f2f(iRow, iCol);
00163 }
00164
00165
00166
00167 derivs(iRow, 3) = halfWidth * f2f(iRow, 4);
00168
00169 derivs(iRow, 4) = halfLength * f2f(iRow, 3);
00170
00171 derivs(iRow, 5) = gammaScale * f2f(iRow, 5);
00172
00173
00174 for (unsigned int iCol = 6; iCol < 9; ++iCol) {
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
00187 return derivatives_(indParMother, indParComp);
00188 }