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 
21 
22 using namespace std;
23 
25  const GlobalPoint& P1, const GlobalPoint& P2,double ip, double curv, double torlerance)
26  : theTolerance(torlerance)
27 {
28  init(P1,P2,ip,std::abs(curv));
29 }
30 
31 
33  init( const GlobalPoint & P1, const GlobalPoint & P2, double ip, double curv)
34 {
35 // GlobalVector aX = GlobalVector( P2.x()-P1.x(), P2.y()-P1.y(), 0.).unit();
36 
37  Point2D p1 = P1.basicVector().xy();
38  Point2D p2 = P2.basicVector().xy();
39  theRotation = Rotation(p1);
40  p1 = transform(p1); // (1./P1.xy().mag(),0);
41  p2 = transform(p2);
42 
43 
44  u1u2 = p1.x()*p2.x();
45  overDu = 1./(p2.x() - p1.x());
46  pv = p1.y()*p2.x() - p2.y()*p1.x();
47  dv = p2.y() - p1.y();
48  su = p2.x() + p1.x();
49 
50  RangeD ipRange(-ip, ip);
51  ipRange.sort();
52 
53  double ipIntyPlus = ipFromCurvature(0.,1);
54  double ipCurvPlus = ipFromCurvature(curv, 1);
55  double ipCurvMinus = ipFromCurvature(curv, -1);
56 
57 
58  RangeD ipRangePlus(ipIntyPlus, ipCurvPlus); ipRangePlus.sort();
59  RangeD ipRangeMinus(-ipIntyPlus, ipCurvMinus); ipRangeMinus.sort();
60 
61  theIpRangePlus = ipRangePlus.intersection(ipRange);
62  theIpRangeMinus = ipRangeMinus.intersection(ipRange);
63 }
64 
65 
66 
69 {
70  double charge = icharge; // will (icharge>0) ? 1. : -1; be faster?
71 
72  RangeD ip = (charge > 0) ? theIpRangePlus : theIpRangeMinus;
73 
74 
75  // it will vectorize with gcc 4.7 (with -O3 -fno-math-errno)
76  double ipv[2]={ip.min(),ip.max()};
77  double u[2], v[2];
78  for (int i=0; i!=2; ++i)
79  findPointAtCurve(radius, charge, ipv[i],u[i],v[i]);
80 
81 
82  double phi1 = theRotation.rotateBack(Point2D(u[0],v[0])).barePhi();
83  double phi2 = phi1+(v[1]-v[0]);
84 
85  if (ip.empty()) {
86  Range r1(phi1*radius-theTolerance, phi1*radius+theTolerance);
87  Range r2(phi2*radius-theTolerance, phi2*radius+theTolerance);
88  return r1.intersection(r2);
89  }
90 
91  if (phi2<phi1) std::swap(phi1, phi2);
92  return Range(radius*phi1-theTolerance, radius*phi2+theTolerance);
93 
94 }
95 
96 /*
97 ThirdHitPredictionFromInvParabola::Range ThirdHitPredictionFromInvParabola::rangeRPhiSlow(
98  double radius, int charge, int nIter) const
99 {
100  Range predRPhi(1.,-1.);
101 
102  double invr2 = 1/(radius*radius);
103  double u = sqrt(invr2);
104  double v = 0.;
105 
106  Range ip = (charge > 0) ? theIpRangePlus : theIpRangeMinus;
107 
108  for (int i=0; i < nIter; ++i) {
109  v = predV(u, ip.min(), charge);
110  double d2 = invr2-sqr(v);
111  u = (d2 > 0) ? sqrt(d2) : 0.;
112  }
113  Point2D pred_tmp1(u, v);
114  double phi1 = transformBack(pred_tmp1).phi();
115  while ( phi1 >= M_PI) phi1 -= 2*M_PI;
116  while ( phi1 < -M_PI) phi1 += 2*M_PI;
117 
118 
119  u = sqrt(invr2);
120  v=0;
121  for (int i=0; i < nIter; ++i) {
122  v = predV(u, ip.max(), charge);
123  double d2 = invr2-sqr(v);
124  u = (d2 > 0) ? sqrt(d2) : 0.;
125  }
126  Point2D pred_tmp2(u, v);
127  double phi2 = transformBack(pred_tmp2).phi();
128  while ( phi2-phi1 >= M_PI) phi2 -= 2*M_PI;
129  while ( phi2-phi1 < -M_PI) phi2 += 2*M_PI;
130 
131 // check faster alternative, without while(..) it is enough to:
132 // phi2 = phi1+radius*(pred_tmp2.v()-pred_tmp1.v());
133 
134  if (ip.empty()) {
135  Range r1(phi1*radius-theTolerance, phi1*radius+theTolerance);
136  Range r2(phi2*radius-theTolerance, phi2*radius+theTolerance);
137  predRPhi = r1.intersection(r2);
138  } else {
139  Range r(phi1, phi2);
140  r.sort();
141  predRPhi= Range(radius*r.min()-theTolerance, radius*r.max()+theTolerance);
142  }
143  return predRPhi;
144 
145 }
146 */
147 
int i
Definition: DBlmapReader.cc:9
Basic2DVector< T > xy() const
T max() const
#define abs(x)
Definition: mlp_lapack.h:159
bool empty() const
T barePhi() const
T min() const
double charge(const std::vector< uint8_t > &Ampls)
Basic2DVector< double > Point2D
void init(const GlobalPoint &P1, const GlobalPoint &P2, double ip, double curv)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double p2[4]
Definition: TauolaWrapper.h:90
T y() const
Cartesian y coordinate.
double ipFromCurvature(double curvature, double charge) const
PixelRecoRange< double > Ranged
ThirdHitPredictionFromInvParabola(const GlobalPoint &P1, const GlobalPoint &P2, double ip, double curv, double tolerance)
double p1[4]
Definition: TauolaWrapper.h:89
Range rangeRPhi(double radius, int charge) const __attribute__((optimize(3
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
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
mathSSE::Vec4< T > v
T x() const
Cartesian x coordinate.
void findPointAtCurve(double radius, double charge, double ip, double &u, double &v) const