CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ThirdHitPredictionFromInvParabola.cc
Go to the documentation of this file.
1 
3 
4 #include <cmath>
7 
11 
13 
14 namespace {
15  template <class T> inline T sqr( T t) {return t*t;}
16 }
17 
18 using namespace std;
19 
21  const GlobalPoint& P1, const GlobalPoint& P2,Scalar ip, Scalar curv, Scalar tolerance)
22  : theTolerance(tolerance)
23 {
24  init(P1,P2,ip,std::abs(curv));
25 }
26 
27 
29 // GlobalVector aX = GlobalVector( P2.x()-P1.x(), P2.y()-P1.y(), 0.).unit();
30 
31  Point2D p1(x1,y1);
32  Point2D p2(x2,y2);
33  theRotation = Rotation(p1);
34  p1 = transform(p1); // (1./P1.xy().mag(),0);
35  p2 = transform(p2);
36 
37 
38  u1u2 = p1.x()*p2.x();
39  overDu = 1./(p2.x() - p1.x());
40  pv = p1.y()*p2.x() - p2.y()*p1.x();
41  dv = p2.y() - p1.y();
42  su = p2.x() + p1.x();
43 
44  RangeD ipRange(-ip, ip);
45  ipRange.sort();
46 
47  Scalar ipIntyPlus = ipFromCurvature(0.,true);
48  Scalar ipCurvPlus = ipFromCurvature(curv, true);
49  Scalar ipCurvMinus = ipFromCurvature(curv, false);
50 
51 
52  RangeD ipRangePlus(ipIntyPlus, ipCurvPlus); ipRangePlus.sort();
53  RangeD ipRangeMinus(-ipIntyPlus, ipCurvMinus); ipRangeMinus.sort();
54 
55  theIpRangePlus = ipRangePlus.intersection(ipRange);
56  theIpRangeMinus = ipRangeMinus.intersection(ipRange);
57 }
58 
59 
60 
63 {
64  bool pos = icharge>0;
65 
67 
68 
69  // it will vectorize with gcc 4.7 (with -O3 -fno-math-errno)
70  // change sign as intersect assume -ip for negative charge...
71  Scalar ipv[2]={(pos)? ip.min() : -ip.min() ,(pos)? ip.max() : -ip.max()};
72  Scalar u[2], v[2];
73  for (int i=0; i!=2; ++i)
74  findPointAtCurve(radius,ipv[i],u[i],v[i]);
75 
76  //
77  Scalar phi1 = theRotation.rotateBack(Point2D(u[0],v[0])).barePhi();
78  Scalar phi2 = phi1+(v[1]-v[0]);
79 
80  if (ip.empty()) {
81  Range r1(phi1*radius-theTolerance, phi1*radius+theTolerance);
82  Range r2(phi2*radius-theTolerance, phi2*radius+theTolerance);
83  return r1.intersection(r2);
84  }
85 
86  if (phi2<phi1) std::swap(phi1, phi2);
87  return Range(radius*phi1-theTolerance, radius*phi2+theTolerance);
88 
89 }
90 
91 /*
92 ThirdHitPredictionFromInvParabola::Range ThirdHitPredictionFromInvParabola::rangeRPhiSlow(
93  Scalar radius, int charge, int nIter) const
94 {
95  Range predRPhi(1.,-1.);
96 
97  Scalar invr2 = 1/(radius*radius);
98  Scalar u = sqrt(invr2);
99  Scalar v = 0.;
100 
101  Range ip = (charge > 0) ? theIpRangePlus : theIpRangeMinus;
102 
103  for (int i=0; i < nIter; ++i) {
104  v = predV(u, charge*ip.min());
105  Scalar d2 = invr2-sqr(v);
106  u = (d2 > 0) ? sqrt(d2) : 0.;
107  }
108  Point2D pred_tmp1(u, v);
109  Scalar phi1 = transformBack(pred_tmp1).phi();
110  while ( phi1 >= M_PI) phi1 -= 2*M_PI;
111  while ( phi1 < -M_PI) phi1 += 2*M_PI;
112 
113 
114  u = sqrt(invr2);
115  v=0;
116  for (int i=0; i < nIter; ++i) {
117  v = predV(u, ip.max(), charge);
118  Scalar d2 = invr2-sqr(v);
119  u = (d2 > 0) ? sqrt(d2) : 0.;
120  }
121  Point2D pred_tmp2(u, v);
122  Scalar phi2 = transformBack(pred_tmp2).phi();
123  while ( phi2-phi1 >= M_PI) phi2 -= 2*M_PI;
124  while ( phi2-phi1 < -M_PI) phi2 += 2*M_PI;
125 
126 // check faster alternative, without while(..) it is enough to:
127 // phi2 = phi1+radius*(pred_tmp2.v()-pred_tmp1.v());
128 
129  if (ip.empty()) {
130  Range r1(phi1*radius-theTolerance, phi1*radius+theTolerance);
131  Range r2(phi2*radius-theTolerance, phi2*radius+theTolerance);
132  predRPhi = r1.intersection(r2);
133  } else {
134  Range r(phi1, phi2);
135  r.sort();
136  predRPhi= Range(radius*r.min()-theTolerance, radius*r.max()+theTolerance);
137  }
138  return predRPhi;
139 
140 }
141 */
142 
int i
Definition: DBlmapReader.cc:9
T max() const
#define abs(x)
Definition: mlp_lapack.h:159
bool empty() const
T barePhi() const
T min() const
void init(const GlobalPoint &P1, const GlobalPoint &P2, Scalar ip, Scalar curv)
Range rangeRPhi(Scalar radius, int charge) const __attribute__((optimize(3
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double p2[4]
Definition: TauolaWrapper.h:90
T y() const
Cartesian y coordinate.
Scalar ipFromCurvature(Scalar curvature, bool pos) const
void findPointAtCurve(Scalar radius, Scalar ip, Scalar &u, Scalar &v) const
double p1[4]
Definition: TauolaWrapper.h:89
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
Square< F >::type sqr(const F &f)
Definition: Square.h:13
BasicVector rotateBack(const BasicVector &v) const
long double T
T x() const
Cartesian x coordinate.