Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:58

0001 #include "OuterDetCompatibility.h"
0002 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
0003 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
0004 
0005 using namespace std;
0006 
0007 bool OuterDetCompatibility::operator()(const BoundPlane& plane) const {
0008   if (barrel) {
0009     if (!checkPhi(plane.phiSpan()))
0010       return false;
0011     if (!checkZ(plane.zSpan()))
0012       return false;
0013   } else {
0014     if (!checkPhi(plane.phiSpan()))
0015       return false;
0016     if (!checkR(plane.rSpan()))
0017       return false;
0018   }
0019   return true;
0020 }
0021 
0022 bool OuterDetCompatibility::checkPhi(const OuterHitPhiPrediction::Range& detPhiRange) const {
0023   return rangesIntersect(detPhiRange, hitDetPhiRange, [](auto x, auto y) { return Geom::phiLess(x, y); });
0024 }
0025 
0026 bool OuterDetCompatibility::checkR(const Range& detRRange) const { return rangesIntersect(detRRange, hitDetRRange); }
0027 
0028 bool OuterDetCompatibility::checkZ(const Range& detZRange) const { return rangesIntersect(detZRange, hitDetZRange); }
0029 
0030 GlobalPoint OuterDetCompatibility::center() const {
0031   float phi = hitDetPhiRange.mean();
0032   float r = hitDetRRange.mean();
0033   return GlobalPoint(r * cos(phi), r * sin(phi), hitDetZRange.mean());
0034 }
0035 
0036 MeasurementEstimator::Local2DVector OuterDetCompatibility::maximalLocalDisplacement(const GlobalPoint& ts,
0037                                                                                     const BoundPlane& plane) const {
0038   float x_loc = 0.;
0039   float y_loc = 0.;
0040   if (barrel) {
0041     double radius = ts.perp();
0042     GlobalVector planeNorm = plane.normalVector();
0043     GlobalVector tsDir = GlobalVector(ts.x(), ts.y(), 0.).unit();
0044     double ts_phi = tsDir.phi();
0045     if (!hitDetPhiRange.inside(ts_phi)) {
0046       while (ts_phi >= hitDetPhiRange.max())
0047         ts_phi -= 2 * M_PI;
0048       while (ts_phi < hitDetPhiRange.min())
0049         ts_phi += 2 * M_PI;
0050       if (!hitDetPhiRange.inside(ts_phi))
0051         return MeasurementEstimator::Local2DVector(0., 0.);
0052     }
0053     double cosGamma = tsDir.dot(planeNorm);
0054 
0055     double dx1 = loc_dist(radius, ts_phi, hitDetPhiRange.min(), cosGamma);
0056     double dx2 = loc_dist(radius, ts_phi, hitDetPhiRange.max(), cosGamma);
0057 
0058     double ts_z = ts.z();
0059     double dy1 = ts_z - hitDetZRange.min();
0060     double dy2 = hitDetZRange.max() - ts_z;
0061 
0062     x_loc = max(dx1, dx2);
0063     y_loc = max(dy1, dy2);
0064 
0065     // debug only
0066     /*
0067     double r1 = dx1 * fabs(cosGamma) / sin(ts_phi-hitDetPhiRange.min());
0068     double r2 = dx2 * fabs(cosGamma) / sin(hitDetPhiRange.max()-ts_phi);
0069     GlobalPoint p1( r1* cos(hitDetPhiRange.min()), r1 * sin(hitDetPhiRange.min()), hitDetZRange.min());
0070     GlobalPoint p2( r2* cos(hitDetPhiRange.max()), r2 * sin(hitDetPhiRange.max()), hitDetZRange.min());
0071     GlobalPoint p3( r1* cos(hitDetPhiRange.min()), r1 * sin(hitDetPhiRange.min()), hitDetZRange.max());
0072     GlobalPoint p4( r2* cos(hitDetPhiRange.max()), r2 * sin(hitDetPhiRange.max()), hitDetZRange.max());
0073     cout << " Local1: " << plane.toLocal(ts-p1) << endl;
0074     cout << " Local2: " << plane.toLocal(ts-p2) << endl;
0075     cout << " Local3: " << plane.toLocal(ts-p3) << endl;
0076     cout << " Local4: " << plane.toLocal(ts-p4) << endl;
0077 */
0078   } else {
0079     LocalPoint ts_loc = plane.toLocal(ts);
0080     GlobalVector planeNorm = plane.normalVector();
0081 
0082     double x_glob[4], y_glob[4], z_glob[4];
0083     x_glob[0] = hitDetRRange.min() * cos(hitDetPhiRange.min());
0084     y_glob[0] = hitDetRRange.min() * sin(hitDetPhiRange.min());
0085     x_glob[1] = hitDetRRange.max() * cos(hitDetPhiRange.min());
0086     y_glob[1] = hitDetRRange.max() * sin(hitDetPhiRange.min());
0087     x_glob[2] = hitDetRRange.min() * cos(hitDetPhiRange.max());
0088     y_glob[2] = hitDetRRange.min() * sin(hitDetPhiRange.max());
0089     x_glob[3] = hitDetRRange.max() * cos(hitDetPhiRange.max());
0090     y_glob[3] = hitDetRRange.max() * sin(hitDetPhiRange.max());
0091 
0092     for (int idx = 0; idx < 4; idx++) {
0093       double dx_glob = x_glob[idx] - ts.x();
0094       double dy_glob = y_glob[idx] - ts.y();
0095       double dz_glob = -(dx_glob * planeNorm.x() + dy_glob * planeNorm.y()) / planeNorm.z();
0096       z_glob[idx] = dz_glob + ts.z();
0097     }
0098 
0099     for (int idx = 0; idx < 4; idx++) {
0100       LocalPoint lp = plane.toLocal(GlobalPoint(x_glob[idx], y_glob[idx], z_glob[idx]));
0101       x_loc = max(x_loc, fabs(lp.x() - ts_loc.x()));
0102       y_loc = max(y_loc, fabs(lp.y() - ts_loc.y()));
0103     }
0104   }
0105   MeasurementEstimator::Local2DVector distance(x_loc, y_loc);
0106   return distance;
0107 }
0108 
0109 double OuterDetCompatibility::loc_dist(double radius, double ts_phi, double range_phi, double cosGamma) const {
0110   double sinDphi = sin(ts_phi - range_phi);
0111   double cosDphi = sqrt(1 - sinDphi * sinDphi);
0112   double sinGamma = sqrt(1 - cosGamma * cosGamma);
0113   double sinBeta = fabs(cosDphi * cosGamma - sinDphi * sinGamma);
0114   return radius * fabs(sinDphi) / sinBeta;
0115 }