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,
11  const TrajectoryStateOnSurface& tsos,
12  const MeasurementEstimator& est)
13  {
14  const Plane& startPlane = det->surface();
15  auto maxDistance = est.maximalLocalDisplacement( tsos, startPlane);
16  return std::copysign(calculatePhiWindow(maxDistance, tsos, startPlane),maxDistance.x());
17  }
18 
19 
20  float
22  const TrajectoryStateOnSurface& ts,
23  const Plane& plane)
24  {
25  MeasurementEstimator::Local2DVector maxDistance(std::abs(imaxDistance.x()),std::abs(imaxDistance.y()));
26 
27  constexpr float tolerance=1.e-6;
29  // std::cout << "plane z " << plane.normalVector() << std::endl;
30  float dphi=0;
31  if LIKELY(std::abs(1.f-std::abs(plane.normalVector().z()))<tolerance) {
32  auto ori = plane.toLocal(GlobalPoint(0.,0.,0.));
33  auto xc = std::abs(start.x() - ori.x());
34  auto yc = std::abs(start.y() - ori.y());
35 
36  if (yc<maxDistance.y() && xc<maxDistance.x()) return M_PI;
37 
38  auto hori = yc>maxDistance.y(); // quadrant 1 (&2), otherwiase quadrant 1&4
39  auto y0 = hori ? yc + std::copysign(maxDistance.y(), xc - maxDistance.x()) : xc - maxDistance.x();
40  auto x0 = hori ? xc - maxDistance.x() : -yc - maxDistance.y();
41  auto y1 = hori ? yc - maxDistance.y() : xc - maxDistance.x();
42  auto x1 = hori ? xc + maxDistance.x() : -yc + maxDistance.y();
43 
44  auto sp = (x0*x1+y0*y1)/std::sqrt((x0*x0+y0*y0)*(x1*x1+y1*y1));
45  sp = std::min(std::max(sp,-1.f),1.f);
46  dphi = std::acos(sp);
47 
48  return dphi;
49  }
50 
51 
52  // generic algo
53  float corners[] = { plane.toGlobal(LocalPoint( start.x()+maxDistance.x(), start.y()+maxDistance.y() )).barePhi(),
54  plane.toGlobal(LocalPoint( start.x()-maxDistance.x(), start.y()+maxDistance.y() )).barePhi(),
55  plane.toGlobal(LocalPoint( start.x()-maxDistance.x(), start.y()-maxDistance.y() )).barePhi(),
56  plane.toGlobal(LocalPoint( start.x()+maxDistance.x(), start.y()-maxDistance.y() )).barePhi()
57  };
58 
59  float phimin = corners[0];
60  float phimax = phimin;
61  for ( int i = 1; i<4; i++) {
62  float cPhi = corners[i];
63  if ( Geom::phiLess(cPhi, phimin) ) { phimin = cPhi; }
64  if ( Geom::phiLess( phimax, cPhi) ) { phimax = cPhi; }
65  }
66  float phiWindow = phimax - phimin;
67  if ( phiWindow < 0.) { phiWindow += 2.*Geom::pi();}
68  // std::cout << "phiWindow " << phiWindow << ' ' << dphi << ' ' << dphi-phiWindow << std::endl;
69  return phiWindow;
70  }
71 
72 
73 
74 
75 }
Definition: start.py:1
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:32
T y() const
Definition: PV2DBase.h:46
const double tolerance
GlobalVector normalVector() const
Definition: Plane.h:41
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
#define LIKELY(x)
Definition: Likely.h:20
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
Definition: Plane.h:17
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
Definition: TkDetUtil.cc:10
T barePhi() const
Definition: PV3DBase.h:68
T sqrt(T t)
Definition: SSEVec.h:18
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58
#define M_PI
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:23
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
constexpr double pi()
Definition: Pi.h:31
T x() const
Definition: PV2DBase.h:45
T x() const
Definition: PV3DBase.h:62
#define constexpr
float calculatePhiWindow(const MeasurementEstimator::Local2DVector &imaxDistance, const TrajectoryStateOnSurface &ts, const Plane &plane)
Definition: TkDetUtil.cc:21