7 HelixExtrapolatorToLine2Order::HelixExtrapolatorToLine2Order(
const PositionType&
point,
8 const DirectionType& direction,
18 double px = direction.x();
19 double py = direction.y();
20 double pz = direction.z();
21 double pt = px*px+py*py;
22 double p =
sqrt(pt+pz*pz);
24 theDirection = DirectionTypeDouble(px/pt,py/pt,pz/pt);
31 std::pair<bool,double>
32 HelixExtrapolatorToLine2Order::pathLength (
const GlobalPoint& point)
const {
35 DirectionTypeDouble helix2(-0.5*theRho*theDirection.y(),
36 0.5*theRho*theDirection.x(),
38 DirectionTypeDouble deltaPos(thePosition-
position);
43 ceq[3] = 2*helix2.mag2();
46 ceq[1] = theDirection.mag2()+2*deltaPos.dot(helix2);
47 ceq[0] = deltaPos.dot(theDirection);
49 return pathLengthFromCoefficients(ceq);
55 std::pair<bool,double>
56 HelixExtrapolatorToLine2Order::pathLength (
const Line&
line)
const {
60 PositionTypeDouble linePosition(line.
position());
61 DirectionTypeDouble lineDirection(line.
direction());
62 DirectionTypeDouble helix2(-0.5*theRho*theDirection.y(),
63 0.5*theRho*theDirection.x(),
65 DirectionTypeDouble deltaPos(thePosition-linePosition);
66 DirectionTypeDouble helix1p(theDirection-lineDirection*theDirection.dot(lineDirection));
67 DirectionTypeDouble helix2p(helix2-lineDirection*helix2.dot(lineDirection));
72 ceq[3] = 2*helix2.dot(helix2p);
75 ceq[2] = 3*theDirection.dot(lineDirection)*helix2.dot(lineDirection);
76 ceq[1] = theDirection.dot(helix1p)+2*deltaPos.dot(helix2p);
77 ceq[0] = deltaPos.dot(helix1p);
79 return pathLengthFromCoefficients(ceq);
85 std::pair<bool,double>
86 HelixExtrapolatorToLine2Order::pathLengthFromCoefficients (
const double ceq[4])
const
92 unsigned int nRaw = solve3rdOrder(ceq,solutions);
97 for (
unsigned int i=0;
i<nRaw;
i++ ) {
101 solutions[nDir++] = solutions[
i];
103 if ( nDir==0 )
return std::make_pair(
false,0.);
107 unsigned int nMin(0);
108 for (
unsigned int i=0;
i<nDir;
i++ ) {
109 double st = solutions[
i];
110 double deri2 = (3*ceq[3]*st+2*ceq[2])*st+ceq[1];
111 if ( deri2>0. ) solutions[nMin++] = st;
113 if ( nMin==0 )
return std::make_pair(
false,0.);
117 double dSt = solutions[0];
118 for (
unsigned int i=1;
i<nMin;
i++ ) {
119 if ( fabs(solutions[
i])<fabs(dSt) ) dSt = solutions[
i];
122 return std::make_pair(
true,dSt/theSinTheta);
126 HelixExtrapolatorToLine2Order::solve3rdOrder (
const double ceq[],
127 double solutions[])
const
132 if ( fabs(ceq[3])>FLT_MIN ) {
134 double q = (ceq[2]*ceq[2]-3*ceq[3]*ceq[1]) / (ceq[3]*ceq[3]) / 9.;
135 double r = (2*ceq[2]*ceq[2]*ceq[2]-9*ceq[3]*ceq[2]*ceq[1]+27*ceq[3]*ceq[3]*ceq[0])
136 / (ceq[3]*ceq[3]*ceq[3]) / 54.;
139 double phi = acos(r/
sqrt(q3))/3.;
140 double rootq =
sqrt(q);
141 for (
int i=0;
i<3;
i++ ) {
142 solutions[
i] = -2*rootq*
cos(phi) - ceq[2]/ceq[3]/3.;
148 double a =
pow(fabs(r)+
sqrt(r*r-q3),1./3.);
150 double b = fabs(a)>FLT_MIN ? q/a : 0.;
151 solutions[0] = a + b - ceq[2]/ceq[3]/3.;
159 else if ( fabs(ceq[2])>FLT_MIN ) {
160 return solve2ndOrder(ceq,solutions);
166 solutions[0] = -ceq[0]/ceq[1];
172 HelixExtrapolatorToLine2Order::solve2ndOrder (
const double coeff[],
173 double solutions[])
const
176 double deq1 = coeff[1]*coeff[1];
177 double deq2 = coeff[2]*coeff[0];
178 if ( fabs(deq1)<FLT_MIN || fabs(deq2/deq1)>1.
e-6 ) {
182 double deq = deq1+2*deq2;
183 if ( deq<0. )
return 0;
184 double ceq = -0.5*(coeff[1]+(coeff[1]>0?1:-1)*
sqrt(deq));
185 solutions[0] = -2*ceq/coeff[2];
186 solutions[1] = coeff[0]/ceq;
193 double ceq = coeff[1]/coeff[2];
194 double deq = deq2/deq1;
196 solutions[0] = -ceq*deq;
197 solutions[1] = ceq*(2+deq);
214 HelixExtrapolatorToLine2Order::PositionTypeDouble
215 HelixExtrapolatorToLine2Order::positionInDouble (
double s)
const {
217 double st = s*theSinTheta;
218 return PositionTypeDouble(thePosition.x()+(theDirection.x()-st*0.5*theRho*theDirection.y())*st,
219 thePosition.y()+(theDirection.y()+st*0.5*theRho*theDirection.x())*st,
220 thePosition.z()+st*theDirection.z());
226 HelixExtrapolatorToLine2Order::direction (
double s)
const {
230 return DirectionType(directionInDouble(s));
235 HelixExtrapolatorToLine2Order::DirectionTypeDouble
236 HelixExtrapolatorToLine2Order::directionInDouble (
double s)
const {
238 double dph = s*theRho*theSinTheta;
239 return DirectionTypeDouble(theDirection.x()-(theDirection.y()+0.5*theDirection.x()*dph)*dph,
240 theDirection.y()+(theDirection.x()-0.5*theDirection.y()*dph)*dph,
DirectionType direction() const
static int position[TOTALCHAMBERS][3]
PositionType position() const
Point3DBase< Scalar, GlobalTag > PositionType
T curvature(T InversePt, const edm::EventSetup &iSetup)
Cos< T >::type cos(const T &t)
Power< A, B >::type pow(const A &a, const B &b)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point