ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHFieldBeast.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHFieldBeast.cc
1 #include "PHFieldBeast.h"
2 
3 #include <BeastMagneticField.h>
4 
5 #include <Geant4/G4SystemOfUnits.hh>
6 
7 #include <TSystem.h>
8 
9 #include <iostream>
10 
11 using namespace std;
12 
13 PHFieldBeast::PHFieldBeast(const string &filename, const int verb, const float magfield_rescale)
14  : PHField(verb)
15  , m_MagFieldScale(magfield_rescale)
16 {
17  m_BeastMagneticField = new BeastMagneticField(filename.c_str());
18  if (m_BeastMagneticField->ValidMapImported())
19  {
20  // Turn linear interpolation on;
21  m_BeastMagneticField->UseInterpolation();
22  }
23  else
24  {
25  cout << "error reading " << filename << endl;
26  gSystem->Exit(1);
27  }
28 }
29 
30 void PHFieldBeast::GetFieldValue(const double point[4], double *Bfield) const
31 {
32  double x = point[0] / cm;
33  double y = point[1] / cm;
34  double z = point[2] / cm;
35 
36  if (!m_BeastMagneticField->GetFieldValue(x, y, z, Bfield[0], Bfield[1], Bfield[2]))
37  {
38  Bfield[0] = 0.0;
39  Bfield[1] = 0.0;
40  Bfield[2] = 0.0;
41  }
42  else
43  {
44  Bfield[0] *= (tesla * m_MagFieldScale);
45  Bfield[1] *= (tesla * m_MagFieldScale);
46  Bfield[2] *= (tesla * m_MagFieldScale);
47  }
48  if (Verbosity() > 2)
49  {
50  cout << "PHFieldBeast::GetFieldValue: bx: " << Bfield[0] / tesla
51  << ", by: " << Bfield[1] / tesla << ", bz: " << Bfield[2] / tesla << endl;
52  }
53  return;
54 }