EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicMagneticField.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicMagneticField.h
1 //
2 // AYK (ayk@bnl.gov), 2014/08/29
3 //
4 // EIC magnetic field map handler;
5 //
6 
7 #include <set>
8 
9 // Make it easy (do not expect the code to be used on iphones, right?);
10 //#ifdef __APPLE__
11 //#include <libgen.h>
12 //#endif
13 
14 #include <FairField.h>
15 
16 #include <PndSolenoidMap.h>
17 
18 //#include <EicDetector.h>
19 #include <EicMagneticFieldMap.h>
20 #include <EicBeamLineElementMap.h>
21 #include <EicBeamLineElementGrad.h>
22 #include <EicConstantField.h>
23 
24 #ifndef _EIC_MAGNETIC_FIELD_
25 // It looks I can not alwyas use EicMagneticField::ClassName(); NB: never change this,
26 // since magnetic field object will be encoded with this name in simulation.root file;
27 #define _EIC_MAGNETIC_FIELD_ ("EicMagneticField")
28 
29 // Need this crappy interface for the transition period; remove once debugging
30 // of EicMagneticFieldMap classes is over; NB: ignore Position() calls, etc; so
31 // basically assume map has no 3D transformation from local to global system;
33 {
34  public:
35  EicPndFieldMap(PndFieldMap *map = 0): mMap(map), //mBufferString(map ? map->GetFileName() : ""),
36 #if 1
37  // basename() is clearly a hack; assume these maps are all in 'input' directory
38  // without subdirectory structure; eventually will get rid of this stuff anyway;
39  // NB: I need to help EicMagneticFieldMap::GetMD5Signature() somehow;
40  EicMagneticFieldMap(map ? BasenameWrapper(map->GetFileName()) : 0) {};
41 #endif
42  //EicMagneticFieldMap(map ? map->GetFileName() : 0) {};
43  //EicPndFieldMap(const char *mapName, const char *mapType) {
44  //mMap = new PndFieldMap(mapName, mapType);
45  //};
47 
48  int Initialize() {
49  if (!mMap) return -1;
50 
51  // No return codes, whatsoever, fine;
52  mMap->Init();
53 
55  };
56 
57  bool Contains(const double xx[]) const {
58  int ix, iy, iz;
59  double dx, dy, dz;
60 
61  return mMap->IsInside(xx[0], xx[1], xx[2], ix, iy, iz, dx, dy, dz);
62  };
63 
64  int GetFieldValue(const double xx[], double B[]) const {
65  if (!mMap) return -1;
66 
67  // Again, no return codes; great;
68  mMap->GetBxyz(xx, B);
69  //printf("%f %f %f\n", B[0], B[1], B[2]);
70 
71  return 0;
72  };
73 
74  private:
75  PndFieldMap *mMap; // PndFieldMap structure
76 
78 };
79 
80 class EicMagneticField: public FairField
81 {
82  public:
83  EicMagneticField(const char *fileName = 0);
85 
87  mMaps.push_back(map);
88  };
89  int AddBeamLineElementMaps(const char *directory, float fieldScaler = 1., int color = _DEFAULT_YOKE_COLOR_);
90  int AddBeamLineElementGrads(const char *directory, float fieldScaler = 1., int color = _DEFAULT_YOKE_COLOR_);
91 
92  enum XYZ {eX, eY, eZ};
93 
94  //
95  // FairRoot methods follow;
96  //
97 
98  void Init() { InitializeFieldMaps(); };
99 
100  // FIXME: perhaps arrange a look-up table?;
101  Double_t GetBx(Double_t x, Double_t y, Double_t z) { return GetBxyzCore(x, y, z, eX); };
102  Double_t GetBy(Double_t x, Double_t y, Double_t z) { return GetBxyzCore(x, y, z, eY); };
103  Double_t GetBz(Double_t x, Double_t y, Double_t z) { return GetBxyzCore(x, y, z, eZ); };
104 
105  void GetBxyz(const Double_t point[3], Double_t* bField) {
106  GetFieldSumValue(point, bField);
107  };
108 
109  void SuppressYokeCreation(const char *name) { mSuppressedYokes.insert(name); };
110 
111  // NB: this call should be *after* all the AddFieldMap(new EicBeamLineElementMap()) calls;
112  int CreateYokeVolumes(Bool_t Active = kFALSE);
113 
114  int Export(const char *fileName) const;
115 
116  private:
117  Bool_t mInitialized;
118 
119  std::set<TString> mSuppressedYokes;
120  //Bool_t mCreateYokeVolumes; //! indicates whether yoke volumes should be created for beam line maps
121 
122  std::vector<EicMagneticFieldMap*> mMaps; // magnetic field maps
123 
124  int InitializeFieldMaps();
125 
126  // A single point of access for field quering routines;
127  int GetFieldSumValue(const double xx[], double B[]);
128 
129  Double_t GetBxyzCore(Double_t x, Double_t y, Double_t z, XYZ coord) {
130  double xx[3] = {x, y, z}, B[3];
131 
132  int ret = GetFieldSumValue(xx, B);
133 
134  // In fact gets reset to 0.0 in GetFieldSumValue() anyway; ok, shoot twice;
135  return (ret ? 0.0 : B[coord]);
136  };
137 
138  ClassDef(EicMagneticField,8)
139 };
140 
141 #endif