CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Alignment/CommonAlignmentParametrization/src/BowedSurfaceAlignmentParameters.cc

Go to the documentation of this file.
00001 
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00012 
00013 #include "Alignment/CommonAlignment/interface/Alignable.h"
00014 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
00015 #include "Alignment/CommonAlignmentParametrization/interface/KarimakiAlignmentDerivatives.h"
00016 #include "Alignment/CommonAlignmentParametrization/interface/AlignmentParametersFactory.h"
00017 #include "CondFormats/Alignment/interface/Definitions.h"
00018 #include "Geometry/CommonTopologies/interface/BowedSurfaceDeformation.h"
00019 
00020 
00021 // This class's header 
00022 #include "Alignment/CommonAlignmentParametrization/interface/BowedSurfaceAlignmentParameters.h"
00023 
00024 #include <iostream>
00025 //_________________________________________________________________________________________________
00026 BowedSurfaceAlignmentParameters::BowedSurfaceAlignmentParameters(Alignable *ali) :
00027   AlignmentParameters(ali, AlgebraicVector(N_PARAM), AlgebraicSymMatrix(N_PARAM, 0))
00028 {
00029 }
00030 
00031 //_________________________________________________________________________________________________
00032 BowedSurfaceAlignmentParameters
00033 ::BowedSurfaceAlignmentParameters(Alignable *alignable, 
00034                                   const AlgebraicVector &parameters, 
00035                                   const AlgebraicSymMatrix &covMatrix) :
00036   AlignmentParameters(alignable, parameters, covMatrix)
00037 {
00038   if (parameters.num_row() != N_PARAM) {
00039     throw cms::Exception("BadParameters") << "in BowedSurfaceAlignmentParameters(): "
00040                                           << parameters.num_row() << " instead of " << N_PARAM 
00041                                           << " parameters.";
00042   }
00043 }
00044 
00045 //_________________________________________________________________________________________________
00046 BowedSurfaceAlignmentParameters
00047 ::BowedSurfaceAlignmentParameters(Alignable *alignable, 
00048                                   const AlgebraicVector &parameters, 
00049                                   const AlgebraicSymMatrix &covMatrix,
00050                                   const std::vector<bool> &selection) :
00051   AlignmentParameters(alignable, parameters, covMatrix, selection)
00052 {  
00053   if (parameters.num_row() != N_PARAM) {
00054     throw cms::Exception("BadParameters") << "in BowedSurfaceAlignmentParameters(): "
00055                                           << parameters.num_row() << " instead of " << N_PARAM 
00056                                           << " parameters.";
00057   }
00058 }
00059 
00060 //_________________________________________________________________________________________________
00061 BowedSurfaceAlignmentParameters* 
00062 BowedSurfaceAlignmentParameters::clone(const AlgebraicVector &parameters, 
00063                                        const AlgebraicSymMatrix &covMatrix) const 
00064 {
00065   BowedSurfaceAlignmentParameters* rbap = 
00066     new BowedSurfaceAlignmentParameters(this->alignable(), parameters, covMatrix, selector());
00067 
00068   if (this->userVariables()) rbap->setUserVariables(this->userVariables()->clone());
00069   rbap->setValid(this->isValid());
00070 
00071   return rbap;
00072 }
00073 
00074 //_________________________________________________________________________________________________
00075 BowedSurfaceAlignmentParameters* 
00076 BowedSurfaceAlignmentParameters::cloneFromSelected(const AlgebraicVector &parameters,
00077                                                    const AlgebraicSymMatrix &covMatrix) const
00078 {
00079   return this->clone(this->expandVector(parameters, this->selector()),
00080                      this->expandSymMatrix(covMatrix, this->selector()));
00081 
00082 }
00083 
00084 //_________________________________________________________________________________________________
00085 AlgebraicMatrix 
00086 BowedSurfaceAlignmentParameters::derivatives(const TrajectoryStateOnSurface &tsos,
00087                                              const AlignableDetOrUnitPtr &alidet) const
00088 {
00089   const Alignable *ali = this->alignable(); // Alignable of these parameters
00090 
00091   if (ali == alidet) {
00092     const AlignableSurface &surf = ali->surface();
00093     return BowedDerivs()(tsos, surf.width(), surf.length());
00094   } else {
00095     // We could give this a meaning by applying frame-to-frame derivatives 
00096     // to the first six parameters (be careful that alpha and beta changed
00097     // their scale and switched their place compared to RigidBody!) and
00098     // keep the remaining three untouched in local meaning.
00099     // In this way we could do higher level alignment and determine 'average'
00100     // surface structures for the components.
00101     throw cms::Exception("MisMatch")
00102       << "BowedSurfaceAlignmentParameters::derivatives: The hit alignable must match the "
00103       << "aligned one (i.e. bowed surface parameters cannot be used for composed alignables)\n";
00104     return AlgebraicMatrix(N_PARAM, 2); // please compiler
00105   }
00106 
00107 }
00108 
00109 //_________________________________________________________________________________________________
00110 align::LocalVector BowedSurfaceAlignmentParameters::translation() const
00111 { 
00112   // align::LocalVector uses double while LocalVector uses float only!
00113   const AlgebraicVector &params = theData->parameters();
00114   return align::LocalVector(params[dx], params[dy], params[dz]);
00115 }
00116 
00117 
00118 //_________________________________________________________________________________________________
00119 align::EulerAngles BowedSurfaceAlignmentParameters::rotation() const
00120 {
00121   const AlgebraicVector &params = theData->parameters();
00122   const Alignable *alignable = this->alignable();
00123   const AlignableSurface &surface = alignable->surface();
00124 
00125   align::EulerAngles eulerAngles(3);
00126   // Note that dslopeX <-> -beta and dslopeY <-> alpha:
00127   // Should we use atan of these values? Anyway it is small...
00128   eulerAngles[0] =  params[dslopeY] * 2. / surface.length();
00129   eulerAngles[1] = -params[dslopeX] * 2. / surface.width();
00130   const double aScale = BowedDerivs::gammaScale(surface.width(), surface.length());
00131   eulerAngles[2] =  params[drotZ] / aScale;
00132 
00133   return eulerAngles;
00134 }
00135 
00136 //_________________________________________________________________________________________________
00137 void BowedSurfaceAlignmentParameters::apply()
00138 {
00139   Alignable *alignable = this->alignable();
00140   if (!alignable) {
00141     throw cms::Exception("BadParameters") 
00142       << "BowedSurfaceAlignmentParameters::apply: parameters without alignable";
00143   }
00144   
00145   // Get translation in local frame, transform to global and apply:
00146   alignable->move(alignable->surface().toGlobal(this->translation()));
00147 
00148   // Rotation in local frame
00149   const align::EulerAngles angles(this->rotation());
00150   // original code:
00151   //  alignable->rotateInLocalFrame( align::toMatrix(angles) );
00152   // correct for rounding errors:
00153   align::RotationType rot(alignable->surface().toGlobal(align::toMatrix(angles)));
00154   align::rectify(rot);
00155   alignable->rotateInGlobalFrame(rot);
00156 
00157   const AlgebraicVector &params = theData->parameters();
00158   const BowedSurfaceDeformation deform(params[dsagittaX], params[dsagittaXY], params[dsagittaY]);
00159 
00160   // FIXME: true to propagate down?
00161   //        Needed for hierarchy with common deformation parameter,
00162   //        but that is not possible now anyway.
00163   alignable->addSurfaceDeformation(&deform, false);
00164 }
00165 
00166 //_________________________________________________________________________________________________
00167 int BowedSurfaceAlignmentParameters::type() const
00168 {
00169   return AlignmentParametersFactory::kBowedSurface;
00170 }
00171 
00172 //_________________________________________________________________________________________________
00173 void BowedSurfaceAlignmentParameters::print() const
00174 {
00175   std::cout << "Contents of BowedSurfaceAlignmentParameters:"
00176             << "\nParameters: " << theData->parameters()
00177             << "\nCovariance: " << theData->covariance() << std::endl;
00178 }