CMS 3D CMS Logo

TkDetUtil.cc
Go to the documentation of this file.
1 #include "TkDetUtil.h"
2 
7 
8 namespace tkDetUtil {
9 
10  float computeWindowSize(const GeomDet* det, const TrajectoryStateOnSurface& tsos, const MeasurementEstimator& est) {
11  const Plane& startPlane = det->surface();
12  auto maxDistance = est.maximalLocalDisplacement(tsos, startPlane);
13  return std::copysign(calculatePhiWindow(maxDistance, tsos, startPlane), maxDistance.x());
14  }
15 
17  const TrajectoryStateOnSurface& ts,
18  const Plane& plane) {
19  MeasurementEstimator::Local2DVector maxDistance(std::abs(imaxDistance.x()), std::abs(imaxDistance.y()));
20 
21  constexpr float tolerance = 1.e-6;
23  // std::cout << "plane z " << plane.normalVector() << std::endl;
24  float dphi = 0;
25  if LIKELY (std::abs(1.f - std::abs(plane.normalVector().z())) < tolerance) {
26  auto ori = plane.toLocal(GlobalPoint(0., 0., 0.));
27  auto xc = std::abs(start.x() - ori.x());
28  auto yc = std::abs(start.y() - ori.y());
29 
30  if (yc < maxDistance.y() && xc < maxDistance.x())
31  return M_PI;
32 
33  auto hori = yc > maxDistance.y(); // quadrant 1 (&2), otherwiase quadrant 1&4
34  auto y0 = hori ? yc + std::copysign(maxDistance.y(), xc - maxDistance.x()) : xc - maxDistance.x();
35  auto x0 = hori ? xc - maxDistance.x() : -yc - maxDistance.y();
36  auto y1 = hori ? yc - maxDistance.y() : xc - maxDistance.x();
37  auto x1 = hori ? xc + maxDistance.x() : -yc + maxDistance.y();
38 
39  auto sp = (x0 * x1 + y0 * y1) / std::sqrt((x0 * x0 + y0 * y0) * (x1 * x1 + y1 * y1));
40  sp = std::min(std::max(sp, -1.f), 1.f);
41  dphi = std::acos(sp);
42 
43  return dphi;
44  }
45 
46  // generic algo
47  float corners[] = {plane.toGlobal(LocalPoint(start.x() + maxDistance.x(), start.y() + maxDistance.y())).barePhi(),
48  plane.toGlobal(LocalPoint(start.x() - maxDistance.x(), start.y() + maxDistance.y())).barePhi(),
49  plane.toGlobal(LocalPoint(start.x() - maxDistance.x(), start.y() - maxDistance.y())).barePhi(),
50  plane.toGlobal(LocalPoint(start.x() + maxDistance.x(), start.y() - maxDistance.y())).barePhi()};
51 
52  float phimin = corners[0];
53  float phimax = phimin;
54  for (int i = 1; i < 4; i++) {
55  float cPhi = corners[i];
56  if (Geom::phiLess(cPhi, phimin)) {
57  phimin = cPhi;
58  }
59  if (Geom::phiLess(phimax, cPhi)) {
60  phimax = cPhi;
61  }
62  }
63  float phiWindow = phimax - phimin;
64  if (phiWindow < 0.) {
65  phiWindow += 2. * Geom::pi();
66  }
67  // std::cout << "phiWindow " << phiWindow << ' ' << dphi << ' ' << dphi-phiWindow << std::endl;
68  return phiWindow;
69  }
70 
71  float computeYdirWindowSize(const GeomDet* det,
72  const TrajectoryStateOnSurface& tsos,
73  const MeasurementEstimator& est) {
74  const Plane& startPlane = det->surface();
76  return maxDistance.y();
77  }
78 
79  std::array<int, 3> findThreeClosest(const std::vector<RingPar>& ringParams,
80  const std::vector<GlobalPoint>& ringCrossing,
81  const int ringSize) {
82  std::array<int, 3> theBins = {{-1, -1, -1}};
83  theBins[0] = 0;
84  float initialR = ringParams[0].theRingR;
85  float rDiff0 = std::abs(ringCrossing[0].perp() - initialR);
86  float rDiff1 = -1.;
87  float rDiff2 = -1.;
88  for (int i = 1; i < ringSize; i++) {
89  float ringR = ringParams[i].theRingR;
90  float testDiff = std::abs(ringCrossing[i].perp() - ringR);
91  if (testDiff < rDiff0) {
92  rDiff2 = rDiff1;
93  rDiff1 = rDiff0;
94  rDiff0 = testDiff;
95  theBins[2] = theBins[1];
96  theBins[1] = theBins[0];
97  theBins[0] = i;
98  } else if (rDiff1 < 0 || testDiff < rDiff1) {
99  rDiff2 = rDiff1;
100  rDiff1 = testDiff;
101  theBins[2] = theBins[1];
102  theBins[1] = i;
103  } else if (rDiff2 < 0 || testDiff < rDiff2) {
104  rDiff2 = testDiff;
105  theBins[2] = i;
106  }
107  }
108 
109  return theBins;
110  }
111 
112  bool overlapInR(const TrajectoryStateOnSurface& tsos, int index, double ymax, const std::vector<RingPar>& ringParams) {
113  // assume "fixed theta window", i.e. margin in local y = r is changing linearly with z
114  float tsRadius = tsos.globalPosition().perp();
115  float thetamin =
116  (std::max(0., tsRadius - ymax)) / (std::abs(tsos.globalPosition().z()) + 10.f); // add 10 cm contingency
117  float thetamax = (tsRadius + ymax) / (std::abs(tsos.globalPosition().z()) - 10.f);
118 
119  // do the theta regions overlap ?
120 
121  return !(thetamin > ringParams[index].thetaRingMax || ringParams[index].thetaRingMin > thetamax);
122  }
123 
125  float ringMinZ = std::abs(ringDisk.position().z()) - ringDisk.bounds().thickness() / 2.;
126  float ringMaxZ = std::abs(ringDisk.position().z()) + ringDisk.bounds().thickness() / 2.;
127  RingPar tempPar;
128  tempPar.thetaRingMin = ringDisk.innerRadius() / ringMaxZ;
129  tempPar.thetaRingMax = ringDisk.outerRadius() / ringMinZ;
130  tempPar.theRingR = (ringDisk.innerRadius() + ringDisk.outerRadius()) / 2.;
131  return tempPar;
132  }
133 
134 } // namespace tkDetUtil
Definition: start.py:1
bool overlapInR(const TrajectoryStateOnSurface &tsos, int index, double ymax, const std::vector< RingPar > &ringParams)
Definition: TkDetUtil.cc:112
T perp() const
Definition: PV3DBase.h:69
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
T z() const
Definition: PV3DBase.h:61
const double tolerance
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
#define LIKELY(x)
Definition: Likely.h:20
T x() const
Definition: PV2DBase.h:43
LocalPoint toLocal(const GlobalPoint &gp) const
std::array< int, 3 > findThreeClosest(const std::vector< RingPar > &ringParams, const std::vector< GlobalPoint > &ringCrossing, const int ringSize)
Definition: TkDetUtil.cc:79
Definition: Plane.h:16
T barePhi() const
Definition: PV3DBase.h:65
T y() const
Definition: PV2DBase.h:44
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
Definition: TkDetUtil.cc:10
float computeYdirWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
Definition: TkDetUtil.cc:71
GlobalPoint globalPosition() const
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
RingPar fillRingParametersFromDisk(const BoundDisk &ringDisk)
Definition: TkDetUtil.cc:124
T perp() const
Magnitude of transverse component.
#define M_PI
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:18
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
GlobalVector normalVector() const
Definition: Plane.h:41
constexpr double pi()
Definition: Pi.h:31
float calculatePhiWindow(const MeasurementEstimator::Local2DVector &imaxDistance, const TrajectoryStateOnSurface &ts, const Plane &plane)
Definition: TkDetUtil.cc:16