MpdFemtoHelix.h 7.0 KB

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