Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:53

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   //     std::cout << "SurfaceDeformation::positionCorrection2Bowed: Cannot yet deal "
0043   //          << " with different widthes, take " << widthHighY << " not " << widthLowY
0044   //          << std::endl;
0045   //   }
0046   //   const double width = widthHighY;
0047 
0048   // Some signs depend on whether we are in surface part below or above ySplit:
0049   const double sign = (localPos.y() < ySplit ? +1. : -1.);
0050   const double yMiddle = ySplit * 0.5 - sign * length * .25;
0051   // 'calibrate' y length and transform y to be w.r.t. surface middle
0052   const double myY = localPos.y() - yMiddle;
0053   const double myLength = length * 0.5 + sign * ySplit;
0054 
0055   double uRel = 2. * localPos.x() / width;  // relative u (-1 .. +1)
0056   double vRel = 2. * myY / myLength;        // relative v (-1 .. +1)
0057   // 'range check':
0058   const double cutOff = 1.5;
0059   if (uRel < -cutOff) {
0060     uRel = -cutOff;
0061   } else if (uRel > cutOff) {
0062     uRel = cutOff;
0063   }
0064   if (vRel < -cutOff) {
0065     vRel = -cutOff;
0066   } else if (vRel > cutOff) {
0067     vRel = cutOff;
0068   }
0069 
0070   auto pars = theParameters;
0071   // 1st, get dw effect depending
0072   // - on the surface sagittas (Legendre polynomials),
0073   //   see BowedSurfaceAlignmentDerivatives::operator()(..)
0074   // - relative dw
0075   // - surface specific dalpha (note that this shifts surface specific dw)
0076   // - surface specific dbeta
0077   const double dw = (uRel * uRel - 1. / 3.) * (pars[0] + sign * pars[9])     // sagittaX
0078                     + uRel * vRel * (pars[1] + sign * pars[10])              // sagittaXY
0079                     + (vRel * vRel - 1. / 3.) * (pars[2] + sign * pars[11])  // sagittaY
0080                     + sign * pars[5]                                         // different dw
0081                     + myY * sign * pars[6]                                   // different dalpha
0082                     - localPos.x() * sign * pars[7];                         // different dbeta
0083   // 2nd, translate the dw effect to shifts in x and y
0084   // Positive dxdz/dydz and positive dw mean negative shift in x/y:
0085   Local2DVector::ScalarType x = -dw * localAngles.dxdz();
0086   Local2DVector::ScalarType y = -dw * localAngles.dydz();
0087   // 3rd, treat in-plane differences depending on surface from xy-shifts...
0088   x += (sign * pars[3]);  // different du
0089   y += (sign * pars[4]);  // different dv
0090   //     ...and gamma-rotation
0091   x -= myY * (sign * pars[8]);           // different dgamma for u
0092   y += localPos.x() * (sign * pars[8]);  // different dgamma for v
0093 
0094   return Local2DVector(x, y);
0095 }
0096 
0097 //------------------------------------------------------------------------------
0098 bool TwoBowedSurfacesDeformation::add(const SurfaceDeformation &other) {
0099   if (this->type() == other.type()) {
0100     const std::vector<double> otherParameters(other.parameters());
0101     if (otherParameters.size() == parameterSize()) {
0102       // Second check in case it is really adding, either way DO NOT check equality directly
0103       if (fabs(theParameters[k_ySplit()] - otherParameters[k_ySplit()]) < 1e-5 ||
0104           fabs(otherParameters[k_ySplit()]) < 1e-5) {
0105         for (unsigned int i = 0; i != parameterSize() - 1; ++i) {  // -1 for ySplit
0106           // mean bows, delta shifts, delta angles and delta bows can simply be added up
0107           theParameters[i] += otherParameters[i];
0108         }
0109         return true;
0110       } else {  // ySplit values are different!
0111         edm::LogError("Alignment") << "@SUB=TwoBowedSurfacesDeformation::add"
0112                                    << "Different ySplit: this " << theParameters[k_ySplit()] << ", to add "
0113                                    << otherParameters[k_ySplit()];
0114       }
0115     }  // same size
0116   }    // same type
0117 
0118   edm::LogError("Alignment") << "@SUB=TwoBowedSurfacesDeformation::add"
0119                              << "Types are different!";
0120 
0121   return false;
0122 }
0123 
0124 //------------------------------------------------------------------------------
0125 std::vector<double> TwoBowedSurfacesDeformation::parameters() const {
0126   return std::vector<double>(theParameters, theParameters + parameterSize());
0127 }