ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FieldMapReadBack.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FieldMapReadBack.cc
1 
2 #include "FieldMapReadBack.h"
3 
4 #include <phfield/PHField.h>
5 #include <phfield/PHField3DCartesian.h>
6 #include <phfield/PHFieldUtility.h>
7 
9 
10 #include <phool/PHCompositeNode.h>
11 
12 #include <Geant4/G4SystemOfUnits.hh>
13 
14 #include <iostream>
15 
16 //____________________________________________________________________________..
18 {
19  fieldmap = PHFieldUtility::GetFieldMapNode(nullptr, topNode);
20  if (fieldmap)
21  {
22  std::cout << "Found or created fieldmap" << std::endl;
23  }
24  else
25  {
26  std::cout << "Fieldmap not found or created" << std::endl;
27  }
29 }
30 
31 //____________________________________________________________________________..
33 {
34  double bfield[3];
35  // the output needs to be converted into the unit you want - here it is tesla
36  fieldmap->GetFieldValue(Point, bfield);
37  std::cout << "bx: " << bfield[0] / tesla
38  << " by: " << bfield[1] / tesla
39  << " bz: " << bfield[2] / tesla
40  << std::endl;
42 }
43 
44 void FieldMapReadBack::Load3dCartMap(const std::string &fname, const float magfield_rescale)
45 {
46  fieldmap = new PHField3DCartesian(fname, magfield_rescale);
47 }
48 
49 void FieldMapReadBack::PrintField(const double x, const double y, const double z, const double t)
50 {
51  SetFieldPoint(x, y, z, t);
52 
53  double Bf[3];
55  std::cout << "Point: " << x / cm << "/" << y / cm << "/" << z / cm << std::endl;
56  std::cout << "BField: " << Bf[0] / tesla << "/" << Bf[1] / tesla << "/" << Bf[2] / tesla << std::endl;
57  return;
58 }
59 
60 void FieldMapReadBack::SetFieldPoint(const double x, const double y, const double z, const double t)
61 {
62  Point[0] = x * cm;
63  Point[1] = y * cm;
64  Point[2] = z * cm;
65  Point[3] = t * s;
66 }
67 
68 void FieldMapReadBack::Verbosity(const int i)
69 {
70  if (fieldmap)
71  {
72  fieldmap->Verbosity(i);
73  }
75  return;
76 }