MpdFieldMap.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // -------------------------------------------------------------------------
  2. // MpdFieldMap header file -----
  3. // Created 23/07/13 by P. Batyuk (MPD) <batyuk@jinr.ru> -----
  4. // from MpdFieldMap (PNDROOT) -----
  5. // -------------------------------------------------------------------------
  6. #ifndef PNDFIELDMAP_H
  7. #define PNDFIELDMAP_H 1
  8. #include "FairField.h"
  9. class TArrayF;
  10. class MpdFieldMapData;
  11. class MpdFieldPar;
  12. class MpdFieldMap : public FairField {
  13. public:
  14. /** Default constructor **/
  15. MpdFieldMap();
  16. /** Standard constructor
  17. ** @param name Name of field map
  18. ** @param fileType R = ROOT file, A = ASCII
  19. **/
  20. MpdFieldMap(const char* mapName, const char* fileType = "R");
  21. /** Constructor from MpdFieldPar **/
  22. MpdFieldMap(MpdFieldPar* fieldPar);
  23. /** Destructor **/
  24. virtual ~MpdFieldMap();
  25. /** Initialisation (read map from file) **/
  26. virtual void Init();
  27. /** Get the field components at a certain point
  28. ** @param x,y,z Point coordinates (global) [cm]
  29. ** @value Bx,By,Bz Field components [kG]
  30. **/
  31. virtual Double_t GetBx(Double_t x, Double_t y, Double_t z);
  32. virtual Double_t GetBy(Double_t x, Double_t y, Double_t z);
  33. virtual Double_t GetBz(Double_t x, Double_t y, Double_t z);
  34. virtual void GetFieldValue(const Double_t point[3], Double_t* bField);
  35. virtual void GetBxyz(const Double_t point[3], Double_t* bField);
  36. /** Determine whether a point is inside the field map **/
  37. virtual bool IsInside(double x, double y, double z);
  38. /** Write the field map to an ASCII file **/
  39. void WriteAsciiFile(const char* fileName);
  40. /** Write field map data to a ROOT file **/
  41. void WriteRootFile(const char* fileName, const char* mapName);
  42. /** Set the position of the field centre **/
  43. void SetPosition(Double_t x, Double_t y, Double_t z);
  44. /** Set a global field scaling factor **/
  45. void SetScale(Double_t factor) { fScale = factor; }
  46. /** Accessors to field parameters in local coordinate system **/
  47. Double_t GetXmin() const { return fXmin; }
  48. Double_t GetYmin() const { return fYmin; }
  49. Double_t GetZmin() const { return fZmin; }
  50. Double_t GetXmax() const { return fXmax; }
  51. Double_t GetYmax() const { return fYmax; }
  52. Double_t GetZmax() const { return fZmax; }
  53. Double_t GetXstep() const { return fXstep; }
  54. Double_t GetYstep() const { return fYstep; }
  55. Double_t GetZstep() const { return fZstep; }
  56. Int_t GetNx() const { return fNx; }
  57. Int_t GetNy() const { return fNy; }
  58. Int_t GetNz() const { return fNz; }
  59. Double_t GetUnit() const {return funit; }
  60. /** Accessor to field centre position in global system **/
  61. Double_t GetPositionX() const { return fPosX; }
  62. Double_t GetPositionY() const { return fPosY; }
  63. Double_t GetPositionZ() const { return fPosZ; }
  64. /** Accessor to global scaling factor **/
  65. Double_t GetScale() const { return fScale; }
  66. /** Accessors to the field value arrays **/
  67. TArrayF* GetBx() const { return fBx; }
  68. TArrayF* GetBy() const { return fBy; }
  69. TArrayF* GetBz() const { return fBz; }
  70. /** Accessor to field map file **/
  71. const char* GetFileName() { return fFileName.Data(); }
  72. /** Screen output **/
  73. virtual void Print();
  74. protected:
  75. /** Reset the field parameters and data **/
  76. void Reset();
  77. /** Read the field map from an ASCII file **/
  78. void ReadAsciiFile(const char* fileName);
  79. /** Read field map from a ROOT file **/
  80. void ReadRootFile(const char* fileName, const char* mapName);
  81. /** Set field parameters and data **/
  82. void SetField(const MpdFieldMapData* data);
  83. /** Get field values by interpolation of the grid.
  84. ** @param dx,dy,dz Relative distance from grid point [cell units]
  85. **/
  86. Double_t Interpolate(Double_t dx, Double_t dy, Double_t dz);
  87. /// Calculate Phi-angle in the Polar Reference Frame
  88. Double_t MPDCalcPhi(Double_t x, Double_t y);
  89. /// Interpolation of Br-component of the magnetic field
  90. Double_t MPDCalcBr(Double_t x, Double_t y);
  91. /// Interpolation of Bz-component of the magnetic field
  92. Double_t MPDCalcBz(Double_t x, Double_t y);
  93. ///
  94. /** Map file name **/
  95. TString fFileName;
  96. /** Global scaling factor (w.r.t. map on file) **/
  97. Double_t fScale;
  98. /** Units used in map file**/
  99. Double_t funit;
  100. /** Field centre position in global coordinates **/
  101. Double_t fPosX, fPosY, fPosZ;
  102. /** Field limits in local coordinate system **/
  103. Double_t fXmin, fXmax, fXstep;
  104. Double_t fYmin, fYmax, fYstep;
  105. Double_t fZmin, fZmax, fZstep;
  106. /** Number of grid points **/
  107. Int_t fNx, fNy, fNz;
  108. /** Arrays with the field values **/
  109. TArrayF* fBx;
  110. TArrayF* fBy;
  111. TArrayF* fBz;
  112. /** Variables for temporary storage
  113. ** Used in the very frequently called method GetFieldValue **/
  114. Double_t fHa[2][2][2]; //! Field at corners of a grid cell
  115. Double_t fHb[2][2]; //! Interpolated field (2-dim)
  116. Double_t fHc[2]; //! Interpolated field (1-dim)
  117. ClassDef(MpdFieldMap,1)
  118. };
  119. #endif