Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:28

0001 ///  \author    : Gero Flucke
0002 ///  date       : October 2010
0003 
0004 #include "Geometry/CommonTopologies/interface/TwoBowedSurfacesDeformation.h"
0005 #include "Geometry/CommonTopologies/interface/SurfaceDeformationFactory.h"
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 // already included via header:
0010 // #include <vector>
0011 
0012 //------------------------------------------------------------------------------
0013 TwoBowedSurfacesDeformation::TwoBowedSurfacesDeformation(const std::vector<double> &pars) {
0014   if (pars.size() != parameterSize()) {
0015     edm::LogError("BadSetup") << "@SUB=TwoBowedSurfacesDeformation"
0016                               << "Input vector of wrong size " << pars.size() << " instead of " << parameterSize()
0017                               << ", add zeros to fill up!";
0018   }
0019   for (unsigned int i = 0; i != std::min((unsigned int)(pars.size()), parameterSize()); ++i)
0020     theParameters[i] = pars[i];
0021   for (unsigned int i = pars.size(); i != parameterSize(); ++i)
0022     theParameters[i] = 0;
0023 }
0024 
0025 //------------------------------------------------------------------------------
0026 TwoBowedSurfacesDeformation *TwoBowedSurfacesDeformation::clone() const {
0027   return new TwoBowedSurfacesDeformation(*this);
0028 }
0029 
0030 //------------------------------------------------------------------------------
0031 int TwoBowedSurfacesDeformation::type() const { return SurfaceDeformationFactory::kTwoBowedSurfaces; }
0032 
0033 //------------------------------------------------------------------------------
0034 SurfaceDeformation::Local2DVector TwoBowedSurfacesDeformation::positionCorrection(const Local2DPoint &localPos,
0035                                                                                   const LocalTrackAngles &localAngles,
0036                                                                                   double length,
0037                                                                                   double width) const {
0038   const double ySplit = theParameters[k_ySplit()];
0039 
0040   // treatment of different widthes at high/low y could be done by theRelWidthLowY or so
0041   //   if (widthLowY > 0. && widthHighY != widthLowY) {
0042   //     edm::LogVerbatim("CommonTopologies") << "SurfaceDeformation::positionCorrection2Bowed: Cannot yet deal "
0043   //          << " with different widthes, take " << widthHighY << " not " << widthLowY;
0044   //   }
0045   //   const double width = widthHighY;
0046 
0047   // Some signs depend on whether we are in surface part below or above ySplit:
0048   const double sign = (localPos.y() < ySplit ? +1. : -1.);
0049   const double yMiddle = ySplit * 0.5 - sign * length * .25;
0050   // 'calibrate' y length and transform y to be w.r.t. surface middle
0051   const double myY = localPos.y() - yMiddle;
0052   const double myLength = length * 0.5 + sign * ySplit;
0053 
0054   double uRel = 2. * localPos.x() / width;  // relative u (-1 .. +1)
0055   double vRel = 2. * myY / myLength;        // relative v (-1 .. +1)
0056   // 'range check':
0057   const double cutOff = 1.5;
0058   if (uRel < -cutOff) {
0059     uRel = -cutOff;
0060   } else if (uRel > cutOff) {
0061     uRel = cutOff;
0062   }
0063   if (vRel < -cutOff) {
0064     vRel = -cutOff;
0065   } else if (vRel > cutOff) {
0066     vRel = cutOff;
0067   }
0068 
0069   auto pars = theParameters;
0070   // 1st, get dw effect depending
0071   // - on the surface sagittas (Legendre polynomials),
0072   //   see BowedSurfaceAlignmentDerivatives::operator()(..)
0073   // - relative dw
0074   // - surface specific dalpha (note that this shifts surface specific dw)
0075   // - surface specific dbeta
0076   const double dw = (uRel * uRel - 1. / 3.) * (pars[0] + sign * pars[9])     // sagittaX
0077                     + uRel * vRel * (pars[1] + sign * pars[10])              // sagittaXY
0078                     + (vRel * vRel - 1. / 3.) * (pars[2] + sign * pars[11])  // sagittaY
0079                     + sign * pars[5]                                         // different dw
0080                     + myY * sign * pars[6]                                   // different dalpha
0081                     - localPos.x() * sign * pars[7];                         // different dbeta
0082   // 2nd, translate the dw effect to shifts in x and y
0083   // Positive dxdz/dydz and positive dw mean negative shift in x/y:
0084   Local2DVector::ScalarType x = -dw * localAngles.dxdz();
0085   Local2DVector::ScalarType y = -dw * localAngles.dydz();
0086   // 3rd, treat in-plane differences depending on surface from xy-shifts...
0087   x += (sign * pars[3]);  // different du
0088   y += (sign * pars[4]);  // different dv
0089   //     ...and gamma-rotation
0090   x -= myY * (sign * pars[8]);           // different dgamma for u
0091   y += localPos.x() * (sign * pars[8]);  // different dgamma for v
0092 
0093   return Local2DVector(x, y);
0094 }
0095 
0096 //------------------------------------------------------------------------------
0097 bool TwoBowedSurfacesDeformation::add(const SurfaceDeformation &other) {
0098   if (this->type() == other.type()) {
0099     const std::vector<double> otherParameters(other.parameters());
0100     if (otherParameters.size() == parameterSize()) {
0101       // Second check in case it is really adding, either way DO NOT check equality directly
0102       if (fabs(theParameters[k_ySplit()] - otherParameters[k_ySplit()]) < 1e-5 ||
0103           fabs(otherParameters[k_ySplit()]) < 1e-5) {
0104         for (unsigned int i = 0; i != parameterSize() - 1; ++i) {  // -1 for ySplit
0105           // mean bows, delta shifts, delta angles and delta bows can simply be added up
0106           theParameters[i] += otherParameters[i];
0107         }
0108         return true;
0109       } else {  // ySplit values are different!
0110         edm::LogError("Alignment") << "@SUB=TwoBowedSurfacesDeformation::add"
0111                                    << "Different ySplit: this " << theParameters[k_ySplit()] << ", to add "
0112                                    << otherParameters[k_ySplit()];
0113       }
0114     }  // same size
0115   }  // same type
0116 
0117   edm::LogError("Alignment") << "@SUB=TwoBowedSurfacesDeformation::add"
0118                              << "Types are different!";
0119 
0120   return false;
0121 }
0122 
0123 //------------------------------------------------------------------------------
0124 std::vector<double> TwoBowedSurfacesDeformation::parameters() const {
0125   return std::vector<double>(theParameters, theParameters + parameterSize());
0126 }