StFemtoHelix.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /**
  2. * \class StFemtoHelix
  3. * \brief Helix parametrization that uses TVector3
  4. *
  5. * Parametrization of a helix. Can also work with straight tracks, i.e. with
  6. * zero curvature. This represents only the mathematical model of a helix.
  7. *
  8. * \author Grigory Nigmatkulov; e-mail: nigmatkulov@gmail.com
  9. * \date May 07 2018
  10. */
  11. #ifndef StFemtoHelix_h
  12. #define StFemtoHelix_h
  13. // C++ headers
  14. #include <math.h>
  15. #include <utility>
  16. #include <algorithm>
  17. // ROOT headers
  18. #include "TVector3.h"
  19. // StFemtoEvent headers
  20. #ifdef _VANILLA_ROOT_
  21. #include "SystemOfUnits.h"
  22. #else
  23. #include "StarClassLibrary/SystemOfUnits.h"
  24. #endif
  25. // Declare C++ namespaces
  26. #if !defined(ST_NO_NAMESPACES)
  27. using std::pair;
  28. using std::swap;
  29. using std::max;
  30. #endif
  31. //_________________
  32. class StFemtoHelix {
  33. public:
  34. /// Empty constructor
  35. StFemtoHelix();
  36. /// Constructor that takes next arguments:
  37. /// curvature, dip angle, phase, origin, h
  38. StFemtoHelix(Double_t c, Double_t dip, Double_t phase,
  39. const TVector3& o, Int_t h=-1);
  40. /// Copy constructor
  41. StFemtoHelix(const StFemtoHelix &h);
  42. /// Destructor
  43. virtual ~StFemtoHelix();
  44. // StFemtoHelix& operator=(const StFemtoHelix&); // use default
  45. /// Return dipAngle
  46. Double_t dipAngle() const;
  47. /// Return curvature which is 1/R in xy-plane
  48. Double_t curvature() const;
  49. /// Return aziumth in xy-plane measured from ring center
  50. Double_t phase() const;
  51. /// Return x-center of circle in xy-plane
  52. Double_t xcenter() const;
  53. /// Return y-center of circle in xy-plane
  54. Double_t ycenter() const;
  55. /// Return -sign(q*B);
  56. Int_t h() const;
  57. /// Return starting point
  58. const TVector3& origin() const;
  59. /// Set helix parameters
  60. void setParameters(Double_t c, Double_t dip, Double_t phase, const TVector3& o, Int_t h);
  61. /// X coordinate of helix at point s
  62. Double_t x(Double_t s) const;
  63. /// Y coordinate of helix at point s
  64. Double_t y(Double_t s) const;
  65. /// Z coordinate of helix at point s
  66. Double_t z(Double_t s) const;
  67. /// Coordinates of helix at point s
  68. TVector3 at(Double_t s) const;
  69. /// Pointing vector of helix at point s
  70. Double_t cx(Double_t s) const;
  71. Double_t cy(Double_t s) const;
  72. Double_t cz(Double_t s = 0) const;
  73. TVector3 cat(Double_t s) const;
  74. /// returns period length of helix
  75. Double_t period() const;
  76. /// path length at given r (cylindrical r)
  77. pair<Double_t, Double_t> pathLength(Double_t r) const;
  78. /// path length at given r (cylindrical r, cylinder axis at x,y)
  79. pair<Double_t, Double_t> pathLength(Double_t r, Double_t x, Double_t y);
  80. /// path length at distance of closest approach to a given point
  81. Double_t pathLength(const TVector3& p, Bool_t scanPeriods = true) const;
  82. /// path length at intersection with plane
  83. Double_t pathLength(const TVector3& r,
  84. const TVector3& n) const;
  85. /// path length at distance of closest approach in the xy-plane to a given point
  86. Double_t pathLength(Double_t x, Double_t y) const;
  87. /// path lengths at dca between two helices
  88. pair<Double_t, Double_t> pathLengths(const StFemtoHelix&,
  89. Double_t minStepSize = 10*micrometer,
  90. Double_t minRange = 10*centimeter) const;
  91. /// minimal distance between point and helix
  92. Double_t distance(const TVector3& p, Bool_t scanPeriods = true) const;
  93. /// checks for valid parametrization
  94. Bool_t valid(Double_t world = 1.e+5) const { return !bad(world); }
  95. Int_t bad(Double_t world = 1.e+5) const;
  96. /// Move the origin along the helix to s which becomes then s=0
  97. virtual void moveOrigin(Double_t s);
  98. static const Double_t NoSolution;
  99. protected:
  100. //StFemtoHelix(); // Was here in the original version
  101. /// Set curvature of the helix
  102. void setCurvature(Double_t); /// performs also various checks
  103. /// Set phase of the helix
  104. void setPhase(Double_t);
  105. /// Set dip angle of the helix
  106. void setDipAngle(Double_t);
  107. /// Value of S where distance in x-y plane is minimal
  108. Double_t fudgePathLength(const TVector3&) const;
  109. protected:
  110. /// True for straight line case (B=0)
  111. Bool_t mSingularity;
  112. /// Starting point of a helix
  113. TVector3 mOrigin;
  114. /// Dip angle
  115. Double_t mDipAngle;
  116. /// Curvature = 1./R
  117. Double_t mCurvature;
  118. /// Phase
  119. Double_t mPhase;
  120. /// -sign(q*B);
  121. Int_t mH;
  122. /// Cosine of dip angle
  123. Double_t mCosDipAngle;
  124. /// Sine of dip angle
  125. Double_t mSinDipAngle;
  126. /// Cosine of phase
  127. Double_t mCosPhase;
  128. /// Sine of phase
  129. Double_t mSinPhase;
  130. ClassDef(StFemtoHelix,1)
  131. };
  132. //
  133. // Non-member functions
  134. //
  135. Int_t operator== (const StFemtoHelix&, const StFemtoHelix&);
  136. Int_t operator!= (const StFemtoHelix&, const StFemtoHelix&);
  137. std::ostream& operator<<(std::ostream&, const StFemtoHelix&);
  138. //
  139. // Inline functions
  140. //
  141. inline Int_t StFemtoHelix::h() const {return mH;}
  142. inline Double_t StFemtoHelix::dipAngle() const {return mDipAngle;}
  143. inline Double_t StFemtoHelix::curvature() const {return mCurvature;}
  144. inline Double_t StFemtoHelix::phase() const {return mPhase;}
  145. inline Double_t StFemtoHelix::x(Double_t s) const {
  146. if (mSingularity)
  147. return mOrigin.x() - s*mCosDipAngle*mSinPhase;
  148. else
  149. return mOrigin.x() + (cos(mPhase + s*mH*mCurvature*mCosDipAngle)-mCosPhase)/mCurvature;
  150. }
  151. inline Double_t StFemtoHelix::y(Double_t s) const {
  152. if (mSingularity)
  153. return mOrigin.y() + s*mCosDipAngle*mCosPhase;
  154. else
  155. return mOrigin.y() + (sin(mPhase + s*mH*mCurvature*mCosDipAngle)-mSinPhase)/mCurvature;
  156. }
  157. inline Double_t StFemtoHelix::z(Double_t s) const {
  158. return mOrigin.z() + s*mSinDipAngle;
  159. }
  160. inline Double_t StFemtoHelix::cx(Double_t s) const {
  161. if (mSingularity)
  162. return -mCosDipAngle*mSinPhase;
  163. else
  164. return -sin(mPhase + s*mH*mCurvature*mCosDipAngle)*mH*mCosDipAngle;
  165. }
  166. inline Double_t StFemtoHelix::cy(Double_t s) const {
  167. if (mSingularity)
  168. return mCosDipAngle*mCosPhase;
  169. else
  170. return cos(mPhase + s*mH*mCurvature*mCosDipAngle)*mH*mCosDipAngle;
  171. }
  172. inline Double_t StFemtoHelix::cz(Double_t /* s */) const { return mSinDipAngle; }
  173. inline const TVector3& StFemtoHelix::origin() const { return mOrigin; }
  174. inline TVector3 StFemtoHelix::at(Double_t s) const { return TVector3(x(s), y(s), z(s)); }
  175. inline TVector3 StFemtoHelix::cat(Double_t s) const { return TVector3(cx(s), cy(s), cz(s)); }
  176. inline Double_t StFemtoHelix::pathLength(Double_t X, Double_t Y) const
  177. { return fudgePathLength(TVector3(X, Y, 0)); }
  178. inline Int_t StFemtoHelix::bad(Double_t WorldSize) const {
  179. Int_t ierr;
  180. if ( !::finite(mDipAngle) ) {
  181. return 11;
  182. }
  183. if ( !::finite(mCurvature) ) {
  184. return 12;
  185. }
  186. //ierr = mOrigin.bad(WorldSize);
  187. /// The line above is commented and the StThreeVector::bad(double)
  188. /// is rewritten here
  189. for(Int_t iIter=0; iIter<3; iIter++) {
  190. Double_t tmpVal;
  191. /// Value StThreeVector.mX1[iter] ???
  192. switch(iIter) {
  193. case 0: tmpVal = mOrigin.X(); break;
  194. case 1: tmpVal = mOrigin.Y(); break;
  195. case 2: tmpVal = mOrigin.Z(); break;
  196. default: tmpVal = NAN;
  197. };
  198. if ( !::finite( tmpVal ) ) {
  199. ierr = 10 + iIter;
  200. }
  201. if ( ::fabs( tmpVal ) > WorldSize ) {
  202. ierr = 20 + iIter;
  203. }
  204. } //for(Int_t iIter=0; iIter<3; iIter+)
  205. if (ierr) {
  206. return (3+ierr*100);
  207. }
  208. if ( ::fabs(mDipAngle) > 1.58 ) {
  209. return 21;
  210. }
  211. Double_t qwe = ::fabs( ::fabs(mDipAngle) - M_PI/2 );
  212. if ( qwe < 1./WorldSize ) {
  213. return 31;
  214. }
  215. if ( ::fabs(mCurvature) > WorldSize ) {
  216. return 22;
  217. }
  218. if ( mCurvature < 0 ) {
  219. return 32;
  220. }
  221. if (abs(mH) != 1 ) {
  222. return 24;
  223. }
  224. return 0;
  225. }
  226. #endif