1 ///////////////////////////////////////////////////////////////////////////
3 // AliFmHelix: a helper helix class //
5 ///////////////////////////////////////////////////////////////////////////
13 #include "AliFmThreeVector.h"
15 #if !defined(ST_NO_NAMESPACES)
27 #define __FUNCTION__ "__FILE__:__LINE__"
32 /// curvature, dip angle, phase, origin, h
33 AliFmHelix(double c, double dip, double phase,
34 const AliFmThreeVector<double>& o, int h=-1);
36 virtual ~AliFmHelix();
37 // AliFmHelix(const AliFmHelix&); // use default
38 // AliFmHelix& operator=(const AliFmHelix&); // use default
40 double DipAngle() const;
41 double Curvature() const; /// 1/R in xy-plane
42 double Phase() const; /// aziumth in xy-plane measured from ring center
43 double XCenter() const; /// x-center of circle in xy-plane
44 double YCenter() const; /// y-center of circle in xy-plane
45 int H() const; /// -sign(q*B);
47 const AliFmThreeVector<double>& Origin() const; /// starting point
49 void SetParameters(double c, double dip, double phase, const AliFmThreeVector<double>& o, int h);
51 double X(double s) const;
52 double Y(double s) const;
53 double Z(double s) const;
55 AliFmThreeVector<double> At(double s) const;
57 /// returns period length of helix
58 double Period() const;
60 /// path length at given r (cylindrical r)
61 pair<double, double> PathLength(double r) const;
63 /// path length at given r (cylindrical r, cylinder axis at x,y)
64 pair<double, double> PathLength(double r, double x, double y, bool scanPeriods = true);
66 /// path length at distance of closest approach to a given point
67 double PathLength(const AliFmThreeVector<double>& p, bool scanPeriods = true) const;
69 /// path length at intersection with plane
70 double PathLength(const AliFmThreeVector<double>& r,
71 const AliFmThreeVector<double>& n) const;
73 /// path length at distance of closest approach in the xy-plane to a given point
74 double PathLength(double x, double y) const;
76 /// path lengths at dca between two helices
77 pair<double, double> PathLengths(const AliFmHelix& h, bool scanPeriods = true) const;
79 /// minimal distance between point and helix
80 double Distance(const AliFmThreeVector<double>& p, bool scanPeriods = true) const;
82 /// checks for valid parametrization
83 bool Valid(double world = 1.e+5) const {return !Bad(world);}
84 int Bad(double world = 1.e+5) const;
86 /// move the origin along the helix to s which becomes then s=0
87 virtual void MoveOrigin(double s);
89 static const double fgkNoSolution; // coinstant indicating lack of solution
94 void SetCurvature(double d); /// performs also various checks
95 void SetPhase(double d);
96 void SetDipAngle(double d);
98 /// value of S where distance in x-y plane is minimal
99 double FudgePathLength(const AliFmThreeVector<double>& v) const;
102 bool fSingularity; // true for straight line case (B=0)
103 AliFmThreeVector<double> fOrigin; // Helix origin
104 double fDipAngle; // Helix dip angle
105 double fCurvature; // curvature
106 double fPhase; // phase
107 int fH; // -sign(q*B);
109 double fCosDipAngle; // cosine of the dip angle
110 double fSinDipAngle; // sine of the dip angle
111 double fCosPhase; // cosine of the phase
112 double fSinPhase; // sine of the phase
114 ClassDef(AliFmHelix,1)
119 // Non-member functions
121 int operator== (const AliFmHelix&, const AliFmHelix&);
122 int operator!= (const AliFmHelix&, const AliFmHelix&);
123 ostream& operator<<(ostream&, const AliFmHelix&);
128 inline int AliFmHelix::H() const {return fH;}
130 inline double AliFmHelix::DipAngle() const {return fDipAngle;}
132 inline double AliFmHelix::Curvature() const {return fCurvature;}
134 inline double AliFmHelix::Phase() const {return fPhase;}
136 inline double AliFmHelix::X(double s) const
139 return fOrigin.x() - s*fCosDipAngle*fSinPhase;
141 return fOrigin.x() + (cos(fPhase + s*fH*fCurvature*fCosDipAngle)-fCosPhase)/fCurvature;
144 inline double AliFmHelix::Y(double s) const
147 return fOrigin.y() + s*fCosDipAngle*fCosPhase;
149 return fOrigin.y() + (sin(fPhase + s*fH*fCurvature*fCosDipAngle)-fSinPhase)/fCurvature;
152 inline double AliFmHelix::Z(double s) const
154 return fOrigin.z() + s*fSinDipAngle;
157 inline const AliFmThreeVector<double>& AliFmHelix::Origin() const {return fOrigin;}
159 inline AliFmThreeVector<double> AliFmHelix::At(double s) const
161 return AliFmThreeVector<double>(X(s), Y(s), Z(s));
164 inline double AliFmHelix::PathLength(double x, double y) const
166 return FudgePathLength(AliFmThreeVector<double>(x, y, 0));
168 inline int AliFmHelix::Bad(double WorldSize) const
172 if (!TMath::Finite(fDipAngle )) return 11;
173 if (!TMath::Finite(fCurvature )) return 12;
175 ierr = fOrigin.Bad(WorldSize);
176 if (ierr) return 3+ierr*100;
178 if (::fabs(fDipAngle) >1.58) return 21;
179 double qwe = ::fabs(::fabs(fDipAngle)-M_PI/2);
180 if (qwe < 1./WorldSize ) return 31;
182 if (::fabs(fCurvature) > WorldSize) return 22;
183 if (fCurvature < 0 ) return 32;
185 if (abs(fH) != 1 ) return 24;