Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:38:57

0001 /** \file BowedSurfaceAlignmentParameters.cc
0002  *
0003  *  Version    : $Revision: 1.14 $
0004  *  last update: $Date: 2008/09/02 15:08:12 $
0005  *  by         : $Author: flucke $
0006  */
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 
0011 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0012 
0013 #include "Alignment/CommonAlignment/interface/Alignable.h"
0014 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
0015 #include "Alignment/CommonAlignmentParametrization/interface/AlignmentParametersFactory.h"
0016 #include "Alignment/CommonAlignmentParametrization/interface/KarimakiAlignmentDerivatives.h"
0017 #include "CondFormats/Alignment/interface/Definitions.h"
0018 #include "Geometry/CommonTopologies/interface/BowedSurfaceDeformation.h"
0019 
0020 // This class's header
0021 #include "Alignment/CommonAlignmentParametrization/interface/BowedSurfaceAlignmentParameters.h"
0022 
0023 #include <iostream>
0024 //_________________________________________________________________________________________________
0025 BowedSurfaceAlignmentParameters::BowedSurfaceAlignmentParameters(Alignable *ali)
0026     : AlignmentParameters(ali, AlgebraicVector(N_PARAM), AlgebraicSymMatrix(N_PARAM, 0)) {}
0027 
0028 //_________________________________________________________________________________________________
0029 BowedSurfaceAlignmentParameters ::BowedSurfaceAlignmentParameters(Alignable *alignable,
0030                                                                   const AlgebraicVector &parameters,
0031                                                                   const AlgebraicSymMatrix &covMatrix)
0032     : AlignmentParameters(alignable, parameters, covMatrix) {
0033   if (parameters.num_row() != N_PARAM) {
0034     throw cms::Exception("BadParameters") << "in BowedSurfaceAlignmentParameters(): " << parameters.num_row()
0035                                           << " instead of " << N_PARAM << " parameters.";
0036   }
0037 }
0038 
0039 //_________________________________________________________________________________________________
0040 BowedSurfaceAlignmentParameters ::BowedSurfaceAlignmentParameters(Alignable *alignable,
0041                                                                   const AlgebraicVector &parameters,
0042                                                                   const AlgebraicSymMatrix &covMatrix,
0043                                                                   const std::vector<bool> &selection)
0044     : AlignmentParameters(alignable, parameters, covMatrix, selection) {
0045   if (parameters.num_row() != N_PARAM) {
0046     throw cms::Exception("BadParameters") << "in BowedSurfaceAlignmentParameters(): " << parameters.num_row()
0047                                           << " instead of " << N_PARAM << " parameters.";
0048   }
0049 }
0050 
0051 //_________________________________________________________________________________________________
0052 BowedSurfaceAlignmentParameters *BowedSurfaceAlignmentParameters::clone(const AlgebraicVector &parameters,
0053                                                                         const AlgebraicSymMatrix &covMatrix) const {
0054   BowedSurfaceAlignmentParameters *rbap =
0055       new BowedSurfaceAlignmentParameters(this->alignable(), parameters, covMatrix, selector());
0056 
0057   if (this->userVariables())
0058     rbap->setUserVariables(this->userVariables()->clone());
0059   rbap->setValid(this->isValid());
0060 
0061   return rbap;
0062 }
0063 
0064 //_________________________________________________________________________________________________
0065 BowedSurfaceAlignmentParameters *BowedSurfaceAlignmentParameters::cloneFromSelected(
0066     const AlgebraicVector &parameters, const AlgebraicSymMatrix &covMatrix) const {
0067   return this->clone(this->expandVector(parameters, this->selector()),
0068                      this->expandSymMatrix(covMatrix, this->selector()));
0069 }
0070 
0071 //_________________________________________________________________________________________________
0072 AlgebraicMatrix BowedSurfaceAlignmentParameters::derivatives(const TrajectoryStateOnSurface &tsos,
0073                                                              const AlignableDetOrUnitPtr &alidet) const {
0074   const Alignable *ali = this->alignable();  // Alignable of these parameters
0075 
0076   if (ali == alidet) {
0077     const AlignableSurface &surf = ali->surface();
0078     return BowedDerivs()(tsos, surf.width(), surf.length());
0079   } else {
0080     // We could give this a meaning by applying frame-to-frame derivatives
0081     // to the first six parameters (be careful that alpha and beta changed
0082     // their scale and switched their place compared to RigidBody!) and
0083     // keep the remaining three untouched in local meaning.
0084     // In this way we could do higher level alignment and determine 'average'
0085     // surface structures for the components.
0086     throw cms::Exception("MisMatch") << "BowedSurfaceAlignmentParameters::derivatives: The hit alignable "
0087                                         "must match the "
0088                                      << "aligned one (i.e. bowed surface parameters cannot be used for "
0089                                         "composed alignables)\n";
0090     return AlgebraicMatrix(N_PARAM, 2);  // please compiler
0091   }
0092 }
0093 
0094 //_________________________________________________________________________________________________
0095 align::LocalVector BowedSurfaceAlignmentParameters::translation() const {
0096   // align::LocalVector uses double while LocalVector uses float only!
0097   const AlgebraicVector &params = theData->parameters();
0098   return align::LocalVector(params[dx], params[dy], params[dz]);
0099 }
0100 
0101 //_________________________________________________________________________________________________
0102 align::EulerAngles BowedSurfaceAlignmentParameters::rotation() const {
0103   const AlgebraicVector &params = theData->parameters();
0104   const Alignable *alignable = this->alignable();
0105   const AlignableSurface &surface = alignable->surface();
0106 
0107   align::EulerAngles eulerAngles(3);
0108   // Note that dslopeX <-> -beta and dslopeY <-> alpha:
0109   // Should we use atan of these values? Anyway it is small...
0110   eulerAngles[0] = params[dslopeY] * 2. / surface.length();
0111   eulerAngles[1] = -params[dslopeX] * 2. / surface.width();
0112   const double aScale = BowedDerivs::gammaScale(surface.width(), surface.length());
0113   eulerAngles[2] = params[drotZ] / aScale;
0114 
0115   return eulerAngles;
0116 }
0117 
0118 //_________________________________________________________________________________________________
0119 void BowedSurfaceAlignmentParameters::apply() {
0120   Alignable *alignable = this->alignable();
0121   if (!alignable) {
0122     throw cms::Exception("BadParameters") << "BowedSurfaceAlignmentParameters::apply: parameters without "
0123                                              "alignable";
0124   }
0125 
0126   // Get translation in local frame, transform to global and apply:
0127   alignable->move(alignable->surface().toGlobal(this->translation()));
0128 
0129   // Rotation in local frame
0130   const align::EulerAngles angles(this->rotation());
0131   // original code:
0132   //  alignable->rotateInLocalFrame( align::toMatrix(angles) );
0133   // correct for rounding errors:
0134   align::RotationType rot(alignable->surface().toGlobal(align::toMatrix(angles)));
0135   align::rectify(rot);
0136   alignable->rotateInGlobalFrame(rot);
0137 
0138   // only update the surface deformations if they were selected for alignment
0139   if (selector()[dsagittaX] || selector()[dsagittaXY] || selector()[dsagittaY]) {
0140     const auto &params = theData->parameters();
0141     const BowedSurfaceDeformation deform{params[dsagittaX], params[dsagittaXY], params[dsagittaY]};
0142 
0143     // FIXME: true to propagate down?
0144     //        Needed for hierarchy with common deformation parameter,
0145     //        but that is not possible now anyway.
0146     alignable->addSurfaceDeformation(&deform, false);
0147   }
0148 }
0149 
0150 //_________________________________________________________________________________________________
0151 int BowedSurfaceAlignmentParameters::type() const { return AlignmentParametersFactory::kBowedSurface; }
0152 
0153 //_________________________________________________________________________________________________
0154 void BowedSurfaceAlignmentParameters::print() const {
0155   std::cout << "Contents of BowedSurfaceAlignmentParameters:"
0156             << "\nParameters: " << theData->parameters() << "\nCovariance: " << theData->covariance() << std::endl;
0157 }