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 
22 
23 using namespace std;
24 
26  const GlobalPoint& P1, const GlobalPoint& P2,double ip, double curv, double torlerance)
27  : theTolerance(torlerance)
28 {
29  init(P1,P2,ip,fabs(curv));
30 }
31 
32 
34  init( const GlobalPoint & P1, const GlobalPoint & P2, double ip, double curv)
35 {
36 // GlobalVector aX = GlobalVector( P2.x()-P1.x(), P2.y()-P1.y(), 0.).unit();
37  GlobalVector aX = GlobalVector( P1.x(), P1.y(), 0.).unit();
38  GlobalVector aY( -aX.y(), aX.x(), 0.);
39  GlobalVector aZ( 0., 0., 1.);
40  theRotation = Rotation(aX,aY,aZ);
41 
42  p1 = PointUV(Point2D(P1.x(),P1.y()), &theRotation);
43  p2 = PointUV(Point2D(P2.x(),P2.y()), &theRotation);
44 
45  Range ipRange(-ip, ip);
46  ipRange.sort();
47 
48  double ipIntyPlus = ipFromCurvature(0.,1);
49  double ipCurvPlus = ipFromCurvature(std::abs(curv), 1);
50  double ipCurvMinus = ipFromCurvature(std::abs(curv), -1);
51 
52 
53  Range ipRangePlus = Range(ipIntyPlus, ipCurvPlus); ipRangePlus.sort();
54  Range ipRangeMinus = Range(-ipIntyPlus, ipCurvMinus); ipRangeMinus.sort();
55 
56  theIpRangePlus = ipRangePlus.intersection(ipRange);
57  theIpRangeMinus = ipRangeMinus.intersection(ipRange);
58 }
59 
60 
62  double r, int c, double ip) const
63 {
64  //
65  // assume u=(1-alpha^2/2)/r v=alpha/r
66  // solve qudratic equation neglecting aplha^4 term
67  //
68  double A = coeffA(ip,c);
69  double B = coeffB(ip,c);
70 
71  double overR = 1./r;
72  double ipOverR = ip*overR;
73 
74  double delta = 1-4*(0.5*B+ipOverR)*(-B+A*r-ipOverR);
75  double sqrtdelta = (delta > 0) ? std::sqrt(delta) : 0.;
76  double alpha = (c>0)? (-c+sqrtdelta)/(B+2*ipOverR) : (-c-sqrtdelta)/(B+2*ipOverR);
77 
78  double v = alpha*overR;
79  double d2 = overR*overR - v*v;
80  double u = (d2 > 0) ? std::sqrt(d2) : 0.;
81 
82  return PointUV(u,v,&theRotation);
83 }
84 
86  double radius, int charge) const
87 {
88  Range predRPhi(1.,-1.);
89  Range ip = (charge > 0) ? theIpRangePlus : theIpRangeMinus;
90 
91  PointUV pred_tmp1 = findPointAtCurve(radius,charge,ip.min());
92  PointUV pred_tmp2 = findPointAtCurve(radius,charge,ip.max());
93 
94  double phi1 = pred_tmp1.unmap().phi();
95  while ( phi1 >= M_PI) phi1 -= 2*M_PI;
96  while ( phi1 < -M_PI) phi1 += 2*M_PI;
97  double phi2 = phi1+radius*(pred_tmp2.v()-pred_tmp1.v());
98 
99  if (ip.empty()) {
100  Range r1(phi1*radius-theTolerance, phi1*radius+theTolerance);
101  Range r2(phi2*radius-theTolerance, phi2*radius+theTolerance);
102  predRPhi = r1.intersection(r2);
103  } else {
104  Range r(phi1, phi2);
105  r.sort();
106  predRPhi= Range(radius*r.min()-theTolerance, radius*r.max()+theTolerance);
107  }
108 
109  return predRPhi;
110 }
111 
112 
114  double radius, int charge, int nIter) const
115 {
116  Range predRPhi(1.,-1.);
117 
118  double invr2 = 1/radius/radius;
119  double u = sqrt(invr2);
120  double v = 0.;
121 
122  Range ip = (charge > 0) ? theIpRangePlus : theIpRangeMinus;
123 
124  for (int i=0; i < nIter; ++i) {
125  v = predV(u, ip.min(), charge);
126  double d2 = invr2-sqr(v);
127  u = (d2 > 0) ? sqrt(d2) : 0.;
128  }
129  PointUV pred_tmp1(u, v, &theRotation);
130  double phi1 = pred_tmp1.unmap().phi();
131  while ( phi1 >= M_PI) phi1 -= 2*M_PI;
132  while ( phi1 < -M_PI) phi1 += 2*M_PI;
133 
134 
135  u = sqrt(invr2);
136  v=0;
137  for (int i=0; i < nIter; ++i) {
138  v = predV(u, ip.max(), charge);
139  double d2 = invr2-sqr(v);
140  u = (d2 > 0) ? sqrt(d2) : 0.;
141  }
142  PointUV pred_tmp2(u, v, &theRotation);
143  double phi2 = pred_tmp2.unmap().phi();
144  while ( phi2-phi1 >= M_PI) phi2 -= 2*M_PI;
145  while ( phi2-phi1 < -M_PI) phi2 += 2*M_PI;
146 
147 // check faster alternative, without while(..) it is enough to:
148 // phi2 = phi1+radius*(pred_tmp2.v()-pred_tmp1.v());
149 
150  if (ip.empty()) {
151  Range r1(phi1*radius-theTolerance, phi1*radius+theTolerance);
152  Range r2(phi2*radius-theTolerance, phi2*radius+theTolerance);
153  predRPhi = r1.intersection(r2);
154  } else {
155  Range r(phi1, phi2);
156  r.sort();
157  predRPhi= Range(radius*r.min()-theTolerance, radius*r.max()+theTolerance);
158  }
159  return predRPhi;
160 
161 }
162 
163 
165  ipFromCurvature(double curvature, int charge) const
166 {
167  double u1u2 = p1.u()*p2.u();
168  double du = p2.u() - p1.u();
169  double pv = p1.v()*p2.u() - p2.v()*p1.u();
170 
171  double inInf = -charge*pv/(du*u1u2);
172  return inInf-curvature/(2.*u1u2);
173 }
174 
175 
176 
178  predV( double u, double ip, int charge) const
179 {
180  return -charge*( coeffA(ip,charge) - coeffB(ip,charge)*u - ip*sqr(u));
181 }
dbl * delta
Definition: mlp_gen.cc:36
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
T max() const
Range rangeRPhiSlow(double radius, int charge, int nIter=5) const
T y() const
Definition: PV3DBase.h:57
#define abs(x)
Definition: mlp_lapack.h:159
bool empty() const
T min() const
double charge(const std::vector< uint8_t > &Ampls)
Basic2DVector< double > Point2D
Basic3DVector< double > Point3D
void init(const GlobalPoint &P1, const GlobalPoint &P2, double ip, double curv)
double predV(double u, double ip, int charge) const
T curvature(T InversePt, const edm::EventSetup &iSetup)
double coeffB(double impactParameter, int charge) const
T sqrt(T t)
Definition: SSEVec.h:28
PixelRecoRange< double > Ranged
Vector3DBase unit() const
Definition: Vector3DBase.h:57
#define M_PI
Definition: BFit3D.cc:3
ThirdHitPredictionFromInvParabola(const GlobalPoint &P1, const GlobalPoint &P2, double ip, double curv, double tolerance)
Range rangeRPhi(double radius, int charge) const
double coeffA(double impactParameter, int charge) const
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
Square< F >::type sqr(const F &f)
Definition: Square.h:13
Geom::Phi< T > phi() const
Definition: Basic2DVector.h:81
PointUV findPointAtCurve(double radius, int charge, double ip) const
T x() const
Definition: PV3DBase.h:56
mathSSE::Vec4< T > v
Global3DVector GlobalVector
Definition: GlobalVector.h:10
double ipFromCurvature(double curvature, int charge) const