MpdConstField.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // -------------------------------------------------------------------------
  2. // MpdContField source file -----
  3. // Created 23/07/13 by P. Batyuk (MPD) <batyuk@jinr.ru> -----
  4. // from MpdContField (PNDROOT) -----
  5. // -------------------------------------------------------------------------
  6. /// Last modified: 24.07.2013, P.B.
  7. #include <iomanip>
  8. #include <iostream>
  9. #include "MpdConstField.h"
  10. #include "MpdConstPar.h"
  11. using namespace std;
  12. // ----- Default constructor -------------------------------------------
  13. MpdConstField::MpdConstField() {
  14. fXmin = fXmax = fYmin = fYmax = fZmin = fZmax = fBx = fBy = fBz = 0.;
  15. fType = 0;
  16. }
  17. // ----- Standard constructor ------------------------------------------
  18. MpdConstField::MpdConstField(const char* name, Double_t xMin,
  19. Double_t xMax, Double_t yMin,
  20. Double_t yMax, Double_t zMin,
  21. Double_t zMax, Double_t bX,
  22. Double_t bY, Double_t bZ)
  23. : FairField(name) {
  24. fXmin = xMin;
  25. fXmax = xMax;
  26. fYmin = yMin;
  27. fYmax = yMax;
  28. fZmin = zMin;
  29. fZmax = zMax;
  30. fBx = bX;
  31. fBy = bY;
  32. fBz = bZ;
  33. fType = 0;
  34. }
  35. // -------- Constructor from MpdFieldPar -------------------------------
  36. MpdConstField::MpdConstField(MpdConstPar* fieldPar)
  37. :FairField()
  38. {
  39. if ( ! fieldPar ) {
  40. cerr << "-W- MpdConstField::MpdConstField: empty parameter container!"
  41. << endl;
  42. fXmin = fXmax = fYmin = fYmax = fZmin = fZmax = fBx = fBy = fBz = 0.;
  43. fType= -1;
  44. }
  45. else {
  46. fXmin = fieldPar->GetXmin();
  47. fXmax = fieldPar->GetXmax();
  48. fYmin = fieldPar->GetYmin();
  49. fYmax = fieldPar->GetYmax();
  50. fZmin = fieldPar->GetZmin();
  51. fZmax = fieldPar->GetZmax();
  52. fBx = fieldPar->GetBx();
  53. fBy = fieldPar->GetBy();
  54. fBz = fieldPar->GetBz();
  55. fType = fieldPar->GetType();
  56. }
  57. }
  58. // ----- Destructor ----------------------------------------------------
  59. MpdConstField::~MpdConstField() { }
  60. // ----- Set field region ----------------------------------------------
  61. void MpdConstField::SetFieldRegion(Double_t xMin, Double_t xMax,
  62. Double_t yMin, Double_t yMax,
  63. Double_t zMin, Double_t zMax) {
  64. fXmin = xMin;
  65. fXmax = xMax;
  66. fYmin = yMin;
  67. fYmax = yMax;
  68. fZmin = zMin;
  69. fZmax = zMax;
  70. }
  71. // ----- Set field values ----------------------------------------------
  72. void MpdConstField::SetField(Double_t bX, Double_t bY, Double_t bZ) {
  73. fBx = bX;
  74. fBy = bY;
  75. fBz = bZ;
  76. }
  77. // ----- Get x component of field --------------------------------------
  78. Double_t MpdConstField::GetBx(Double_t x, Double_t y, Double_t z) {
  79. if ( x <= fXmin || x >= fXmax ||
  80. y <= fYmin || y >= fYmax ||
  81. z <= fZmin || z >= fZmax ) return 0.;
  82. return fBx;
  83. }
  84. // ----- Get y component of field --------------------------------------
  85. Double_t MpdConstField::GetBy(Double_t x, Double_t y, Double_t z) {
  86. if ( x <= fXmin || x >= fXmax ||
  87. y <= fYmin || y >= fYmax ||
  88. z <= fZmin || z >= fZmax ) return 0.;
  89. return fBy;
  90. }
  91. // ----- Get z component of field --------------------------------------
  92. Double_t MpdConstField::GetBz(Double_t x, Double_t y, Double_t z) {
  93. if ( x <= fXmin || x >= fXmax ||
  94. y <= fYmin || y >= fYmax ||
  95. z <= fZmin || z >= fZmax ) return 0.;
  96. return fBz;
  97. }
  98. // -------------------------------------------------------------------------
  99. void MpdConstField::GetFieldValue(const Double_t point[3], Double_t* bField)
  100. {
  101. bField[0]=GetBx(point[0],point[1],point[2]);
  102. bField[1]=GetBy(point[0],point[1],point[2]);
  103. bField[2]=GetBz(point[0],point[1],point[2]);
  104. }
  105. // -------------------------------------------------------------------------
  106. void MpdConstField::GetBxyz(const Double_t point[3], Double_t* bField)
  107. {
  108. GetFieldValue(point,bField);
  109. }
  110. // ----- Screen output -------------------------------------------------
  111. void MpdConstField::Print() {
  112. cout << "======================================================" << endl;
  113. cout << "---- " << fTitle << " : " << fName << endl;
  114. cout << "----" << endl;
  115. cout << "---- Field type : constant" << endl;
  116. cout << "----" << endl;
  117. cout << "---- Field regions : " << endl;
  118. cout << "---- x = " << setw(4) << fXmin << " to " << setw(4)
  119. << fXmax << " cm" << endl;
  120. cout << "---- y = " << setw(4) << fYmin << " to " << setw(4)
  121. << fYmax << " cm" << endl;
  122. cout << "---- z = " << setw(4) << fZmin << " to " << setw(4)
  123. << fZmax << " cm" << endl;
  124. cout.precision(4);
  125. cout << "---- B = ( " << fBx << ", " << fBy << ", " << fBz << " ) kG"
  126. << endl;
  127. cout << "======================================================" << endl;
  128. }
  129. ClassImp(MpdConstField)