KFPTrack.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //----------------------------------------------------------------------------
  2. // Implementation of the KFParticle class
  3. // .
  4. // @author I.Kisel, I.Kulakov, M.Zyzak
  5. // @version 1.0
  6. // @since 20.08.13
  7. //
  8. //
  9. // -= Copyright &copy ALICE HLT and CBM L1 Groups =-
  10. //____________________________________________________________________________
  11. #ifndef KFPTrack_H
  12. #define KFPTrack_H
  13. /** @class KFPTrack
  14. ** @brief A scalar class for storage of the track in the cartesian parametrisation.
  15. ** @author M.Zyzak, I.Kisel
  16. ** @date 05.02.2019
  17. ** @version 1.0
  18. **
  19. ** A track is described with the state vector { X, Y, Z, Px, Py, Pz }
  20. ** and the corresponding covariance matrix. Also contains charge of the
  21. ** track, chi2 of the track fit, the corresponding number of degrees of freedom,
  22. ** the unique Id of the track and the field approximation along the track trajectory.
  23. **/
  24. #include <cmath>
  25. #include "TObject.h"
  26. class KFPTrack
  27. //#ifdef __ROOT__
  28. : public TObject
  29. //#endif
  30. {
  31. public:
  32. KFPTrack():fChi2(-1.f), fQ(0), fNDF(-1), fId(-1) { }
  33. ~KFPTrack() { }
  34. int GetID() const { return fId; } ///< Returns Id of the track.
  35. bool GetXYZPxPyPz(float *p) const
  36. {
  37. /** Fills an array p with the parameters of the track.
  38. ** \param[out] p - array where { X, Y, Z, Px, Py, Pz } are copied
  39. **/
  40. for(int i=0; i<6; i++)
  41. p[i] = fP[i];
  42. return 1;
  43. }
  44. bool GetCovarianceXYZPxPyPz(float cv[21]) const
  45. {
  46. /** Copies the covariance matrix of the track to the array of floats.
  47. ** \param[out] cv[21] - the output array, where the covariance matrix is copied
  48. **/
  49. for (int i=0; i<21; i++)
  50. cv[i] = fC[i];
  51. return 1;
  52. }
  53. bool GetCovarianceXYZPxPyPz(double cv[21]) const
  54. {
  55. /** Copies the covariance matrix of the track to the array of doubles.
  56. ** \param[out] cv[21] - the output array, where the covariance matrix is copied
  57. **/
  58. for (int i=0; i<21; i++)
  59. cv[i] = fC[i];
  60. return 1;
  61. }
  62. /** Copies position of the track to the output array of floats. \param[out] position - the output array with the position of the track **/
  63. void GetXYZ(float *position) const {position[0] = fP[0]; position[1] = fP[1]; position[2] = fP[2];}
  64. /** Copies 3 momentum components of the track to the output array of floats. \param[out] position - the output array with the momentum of the track **/
  65. void GetPxPyPz(float *position) const {position[0] = fP[3]; position[1] = fP[4]; position[2] = fP[5];}
  66. /** Copies position of the track to the output array of floats. \param[out] position - the output array with the position of the track **/
  67. void XvYvZv(float *position) const {position[0] = fP[0]; position[1] = fP[1]; position[2] = fP[2];}
  68. /** Copies 3 momentum components of the track to the output array of floats. \param[out] position - the output array with the momentum of the track **/
  69. void PxPyPz(float *position) const {position[0] = fP[3]; position[1] = fP[4]; position[2] = fP[5];}
  70. /** Copies position of the track to the output array of doubles. \param[out] position - the output array with the position of the track **/
  71. void XvYvZv(double *position) const {position[0] = fP[0]; position[1] = fP[1]; position[2] = fP[2];}
  72. /** Copies 3 momentum components of the track to the output array of doubles. \param[out] position - the output array with the momentum of the track **/
  73. void PxPyPz(double *position) const {position[0] = fP[3]; position[1] = fP[4]; position[2] = fP[5];}
  74. float GetX() const { return fP[0]; } ///< Returns X coordinate of the track.
  75. float GetY() const { return fP[1]; } ///< Returns Y coordinate of the track.
  76. float GetZ() const { return fP[2]; } ///< Returns Z coordinate of the track.
  77. float GetPx() const { return fP[3]; } ///< Returns Px component of the momentum of the track.
  78. float GetPy() const { return fP[4]; } ///< Returns Py component of the momentum of the track.
  79. float GetPz() const { return fP[5]; } ///< Returns Pz component of the momentum of the track.
  80. float GetPt() const { return sqrt(fP[3]*fP[3]+fP[4]*fP[4]); } ///< Returns Pt - transverse momentum of the track.
  81. float GetP() const { return sqrt(fP[3]*fP[3]+fP[4]*fP[4]+fP[5]*fP[5]); } ///< Returns P - momentum of the track.
  82. void GetCovarianceMatrix(float *covmatrix)
  83. {
  84. /** Copies the covariance matrix of the track to the array of floats.
  85. ** \param[out] covmatrix[21] - the output array, where the covariance matrix is copied
  86. **/
  87. for (int i=0; i<21; i++)
  88. covmatrix[i] = fC[i];
  89. }
  90. float GetParameter(int i) const { return fP[i]; } ///< Returns parameter "i" of the track. \param[in] i - index of the parameter to be returned
  91. float GetCovariance(int i) const { return fC[i]; } ///< Returns element of the covariance matrix "i" of the track. \param[in] i - index of the element to be returned
  92. int Charge() const { return fQ; } ///< Returns charge of the track.
  93. float GetChi2perNDF() const { return fChi2/fNDF; } ///< Returns Chi2/NDF of the track, NDF is a number of degrees of freedom.
  94. float GetChi2() const { return fChi2; } ///< Returns Chi2 of the track.
  95. int GetNDF() const { return fNDF; } ///< Returns number of degrees of freedom of the track.
  96. const float * GetTrack() const { return fP; } ///< Returns a pointer to the array of track parameters.
  97. const float * GetCovMatrix() const { return fC; } ///< Returns a pointer to the array of the covariance matrix elements stored in a lower triangular form.
  98. void SetParameters(const float *position)
  99. {
  100. /** Sets parameters { X, Y, Z, Px, Py, Pz } of the track from the input array of floats.
  101. ** \param[in] position - input array with the track parameters
  102. **/
  103. for(int i=0; i<6; i++)
  104. fP[i] = position[i];
  105. }
  106. void SetParameters(double *position)
  107. {
  108. /** Sets parameters { X, Y, Z, Px, Py, Pz } of the track from the input array of doubles.
  109. ** \param[in] position - input array with the track parameters
  110. **/
  111. for(int i=0; i<6; i++)
  112. fP[i] = position[i];
  113. }
  114. void SetParameters(float x, float y, float z, float px, float py, float pz)
  115. {
  116. /** Sets parameters { X, Y, Z, Px, Py, Pz } of the track.
  117. ** \param[in] x - X coordinate to be set
  118. ** \param[in] y - Y coordinate to be set
  119. ** \param[in] z - Z coordinate to be set
  120. ** \param[in] Px - Px momentum component to be set
  121. ** \param[in] Py - Py momentum component to be set
  122. ** \param[in] Pz - Pz momentum component to be set
  123. **/
  124. fP[0] = x; fP[1] = y; fP[2] = z;
  125. fP[3] = px; fP[4] = py; fP[5] = pz;
  126. }
  127. void SetXYZ(float x, float y, float z)
  128. {
  129. /** Sets position { X, Y, Z } of the track.
  130. ** \param[in] x - X coordinate to be set
  131. ** \param[in] y - Y coordinate to be set
  132. ** \param[in] z - Z coordinate to be set
  133. **/
  134. fP[0] = x; fP[1] = y; fP[2] = z;
  135. }
  136. void SetPxPyPz(float px, float py, float pz)
  137. {
  138. /** Sets momentum { Px, Py, Pz } of the track.
  139. ** \param[in] Px - Px momentum component to be set
  140. ** \param[in] Py - Py momentum component to be set
  141. ** \param[in] Pz - Pz momentum component to be set
  142. **/
  143. fP[3] = px; fP[4] = py; fP[5] = pz;
  144. }
  145. void SetID(int id) {fId = id;} ///< Sets Id of the track.
  146. void SetX(float x) { fP[0] = x; } ///< Sets X coordinate of the track.
  147. void SetY(float y) { fP[1] = y; } ///< Sets Y coordinate of the track.
  148. void SetZ(float z) { fP[2] = z; } ///< Sets Z coordinate of the track.
  149. void SetPx(float px) { fP[3] = px; } ///< Sets Px component of the track momentum.
  150. void SetPy(float py) { fP[4] = py; } ///< Sets Py component of the track momentum.
  151. void SetPz(float pz) { fP[5] = pz; } ///< Sets Pz component of the track momentum.
  152. void SetCharge(int q) { fQ = q; } ///< Sets charge of the track.
  153. void SetChi2(float chi) { fChi2 = chi; } ///< Sets a value of the track Chi2.
  154. void SetNDF(int ndf) { fNDF = ndf; } ///< Sets a value of the number of degrees of freedom.
  155. void SetCovarianceMatrix(const float *C)
  156. {
  157. /** Sets the covariance matrix from the input array of floats.
  158. ** \param[in] C[21] - array with the input elements of the covariance matrix stored in the lower triangular form
  159. **/
  160. for (int i=0; i<21; i++)
  161. fC[i] = C[i];
  162. }
  163. void SetCovarianceMatrix(const double *C)
  164. {
  165. /** Sets the covariance matrix from the input array of doubles.
  166. ** \param[in] C[21] - array with the input elements of the covariance matrix stored in the lower triangular form
  167. **/
  168. for (int i=0; i<21; i++)
  169. fC[i] = C[i];
  170. }
  171. /** Sets an element of the covariance matrix with index "i". \param[in] c - value to be set \param[in] i - index of the element */
  172. void SetCovariance(const int i, const float c) { fC[i]=c; }
  173. void RotateXY( float alpha ); // rotate on alpha in XY plane. Should be useful for CS change
  174. int Id() const { return fId; } ///< Returns Id of the track.
  175. void SetId( int id ){ fId = id; } ///< Sets Id of the track.
  176. #ifdef NonhomogeneousField
  177. const float* GetFieldCoeff() const { return fieldRegion; } ///< Returns array of the coefficients for field approximation.
  178. /** Sets a field coefficient with index "i". \param[in] c - value to be set \param[in] i - index of the element */
  179. void SetFieldCoeff(float c, int i) { fieldRegion[i] = c; }
  180. #endif
  181. private:
  182. float fP[6]; ///< Parameters of the track: { X, Y, Z, Px, Py, Pz }.
  183. float fC[21]; ///< Covariance matrix of the track parameters. Stored in the lower triangular form.
  184. float fChi2; ///< Chi-square of the track fit.
  185. char fQ; ///< Charge of the track.
  186. short fNDF; ///< Number of degree of freedom of the fit.
  187. int fId; ///< Id of the track.
  188. #ifdef NonhomogeneousField
  189. /** \brief Approximation of the magnetic field along the track trajectory.
  190. ** Each component (Bx, By, Bz) is approximated with the parabola depending on Z coordinate. Is defined in case of #ifdef NonhomogeneousField.
  191. **/
  192. float fieldRegion[10];
  193. #endif
  194. //#ifdef __ROOT__
  195. ClassDef(KFPTrack,1)
  196. //#endif
  197. };
  198. #endif