LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MagneticField.h
Go to the documentation of this file.
1 // \file MagneticField.h
3 //
4 // \brief pure virtual base interface for magnetic fields
5 //
6 // \author ebrianne@fnal.gov
7 //
9 #ifndef MAG_MAGNETICFIELD_H
10 #define MAG_MAGNETICFIELD_H
11 
12 // std includes
13 #include <string>
14 #include <vector>
15 
16 // Geant4 includes
17 #include "Geant4/G4ThreeVector.hh"
18 
19 // ROOT includes
20 #include "TGeoVolume.h"
21 #include "TVector3.h"
22 
23 namespace mag {
24 
25  // assumes a square grid of R, Z samples for speed in lookup, starting at an origin 0,0
26  struct RZFieldMap
27  {
28  TVector3 CoordOffset;
29  TVector3 ZAxis;
30  float dr;
31  float dz;
32  std::vector<std::vector<float>> br;
33  std::vector<std::vector<float>> bz;
34  size_t nr() const { return br.size(); };
35  size_t nz() const
36  {
37  if(nr() > 0)
38  {
39  return br[0].size();
40  }
41  else
42  {
43  return 0;
44  }
45  };
46  };
47 
48  using Field3D = std::vector<std::vector<std::vector<float>>>;
49  struct XYZFieldMap
50  {
51  TVector3 CoordOffset;
52  TVector3 ZAxis;
54  float xo, yo, zo;
55  float dx, dy, dz;
59  };
60 
61  typedef enum MagneticFieldMode {
62  kAutomaticBFieldMode=-1, // Used by DriftElectronsAlg
63  kNoBFieldMode=0, // no field
64  kConstantBFieldMode=1, // constant field
65  kFieldRZMapMode= 2, // read a map as a function of r and z
66  kFieldXYZMapMode= 3 // read a map as a function of x,y,z
67  /*, kFieldMapMode, ... */
69 
71  {
73  G4ThreeVector fField;
75  TGeoVolume* fGeoVol;
76  std::string fFieldMapFilename;
79  float fScaleFactor;
80  };
81 
82  class MagneticField {
83  public:
84 
85  MagneticField(const MagneticField &) = delete;
86  MagneticField(MagneticField &&) = delete;
87  MagneticField& operator = (const MagneticField &) = delete;
88  MagneticField& operator = (MagneticField &&) = delete;
89  virtual ~MagneticField() = default;
90 
91  //Return std::vector<MagneticFieldDescription>
92  virtual std::vector<MagneticFieldDescription> const& Fields() const = 0;
93 
94  //Return the size of std::vector<MagneticFieldDescription>
95  virtual size_t NumFields() const = 0;
96 
97  //Return the field mode
98  virtual MagFieldMode_t const& UseField(size_t f) const = 0;
99 
100  //return the magnetized volumes
101  virtual std::string const& MagnetizedVolume(size_t f) const = 0;
102 
103  // return the field at a particular point
104  virtual G4ThreeVector const FieldAtPoint(G4ThreeVector const& p=G4ThreeVector(0)) const = 0;
105 
106  // This method will only return a uniform field based on the input
107  // volume name. If the input volume does not have a uniform field
108  // caveat emptor
109  virtual G4ThreeVector const UniformFieldInVolume(std::string const& volName) const = 0;
110 
111  protected:
112 
113  MagneticField() = default;
114 
115  };
116 
117 }
118 
119 #endif // MAG_MAGNETICFIELD_H
G4ThreeVector fField
description of the field (uniform only)
Definition: MagneticField.h:73
MagneticFieldMode
Definition: MagneticField.h:61
std::vector< std::vector< float > > br
Definition: MagneticField.h:32
float fScaleFactor
Used to scale the magnetic field.
Definition: MagneticField.h:79
std::string fFieldMapFilename
file name for reading in the field map
Definition: MagneticField.h:76
TFile f
Definition: plotHisto.C:6
TGeoVolume * fGeoVol
pointer to TGeoVolume with the field
Definition: MagneticField.h:75
MagFieldMode_t fMode
type of field used
Definition: MagneticField.h:72
size_t nz() const
Definition: MagneticField.h:35
RZFieldMap fRZFieldMap
RZ field map if needed.
Definition: MagneticField.h:77
std::vector< std::vector< float > > bz
Definition: MagneticField.h:33
TVector3 CoordOffset
Definition: MagneticField.h:28
enum mag::MagneticFieldMode MagFieldMode_t
size_t nr() const
Definition: MagneticField.h:34
TVector3 CoordOffset
Definition: MagneticField.h:51
std::vector< std::vector< std::vector< float >>> Field3D
Definition: MagneticField.h:48
G4String fVolume
G4 volume containing the field.
Definition: MagneticField.h:74
XYZFieldMap fXYZFieldMap
XYZ field map if needed.
Definition: MagneticField.h:78