REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestAxionMagneticField.h
1 /*************************************************************************
2  * This file is part of the REST software framework. *
3  * *
4  * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5  * For more information see http://gifna.unizar.es/trex *
6  * *
7  * REST is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * REST is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have a copy of the GNU General Public License along with *
18  * REST in $REST_PATH/LICENSE. *
19  * If not, see http://www.gnu.org/licenses/. *
20  * For the list of contributors see $REST_PATH/CREDITS. *
21  *************************************************************************/
22 
23 #ifndef _TRestAxionMagneticField
24 #define _TRestAxionMagneticField
25 
26 #include <TRestMetadata.h>
27 #include <iostream>
28 
29 #include "TCanvas.h"
30 #include "TH2D.h"
31 #include "TVector3.h"
32 #include "TVectorD.h"
33 
34 #include "TRestMesh.h"
35 
38 struct MagneticFieldVolume {
40  TVector3 position;
41 
43  TRestMesh mesh;
44 
46  std::vector<std::vector<std::vector<TVector3>>> field;
47 };
48 
51  private:
53  std::vector<std::string> fFileNames; //<
54 
56  std::vector<TVector3> fPositions; //<
57 
59  std::vector<TVector3> fConstantField; //<
60 
62  std::vector<TVector3> fMeshSize; //<
63 
65  std::vector<TString> fMeshType; //<
66 
68  std::vector<TVector3> fBoundMax; //<
69 
71  std::vector<MagneticFieldVolume> fMagneticFieldVolumes;
72 
74  TH2D* fHisto;
75 
77  TCanvas* fCanvas;
78 
79  void Initialize();
80 
81  void InitFromConfigFile();
82 
83  void LoadMagneticFieldData(MagneticFieldVolume& mVol, std::vector<std::vector<Float_t>> data);
84 
85  TVector3 GetMagneticVolumeNode(MagneticFieldVolume mVol, TVector3 pos);
86 
89  Bool_t FieldLoaded() { return GetNumberOfVolumes() == fMagneticFieldVolumes.size(); }
90 
92  MagneticFieldVolume* GetMagneticVolume(Int_t id) {
93  if (!FieldLoaded()) LoadMagneticVolumes();
94  if (fMagneticFieldVolumes.size() > id)
95  return &fMagneticFieldVolumes[id];
96  else {
97  RESTError << "TRestAxionMagneticField::GetMagneticVolume. Id outside limits!" << RESTendl;
98  return NULL;
99  }
100  }
101 
102  public:
103  void LoadMagneticVolumes();
104 
106  Bool_t IsFieldConstant(Int_t id) {
107  if (GetMagneticVolume(id)) return GetMagneticVolume(id)->field.size() == 0;
108  return true;
109  }
110 
112  Int_t GetNumberOfVolumes() { return fPositions.size(); }
113 
114  Bool_t CheckOverlaps();
115 
116  std::vector<TVector3> GetVolumeBoundaries(TVector3 pos, TVector3 dir, Int_t id = 0);
117  std::vector<TVector3> GetFieldBoundaries(TVector3 pos, TVector3 dir, Double_t precision = 0,
118  Int_t id = 0);
119 
120  TVector3 GetMagneticField(Double_t x, Double_t y, Double_t z);
121  TVector3 GetMagneticField(TVector3 pos, Bool_t showWarning = true);
122 
123  Double_t GetPhotonMass(Double_t x, Double_t y, Double_t z, Double_t en);
124  Double_t GetPhotonMass(TVector3 pos, Double_t en);
125  Double_t GetPhotonMass(Int_t id, Double_t en);
126 
127  Double_t GetPhotonAbsorptionLength(Double_t x, Double_t y, Double_t z, Double_t en);
128  Double_t GetPhotonAbsorptionLength(TVector3 pos, Double_t en);
129  Double_t GetPhotonAbsorptionLength(Int_t id, Double_t en);
130 
131  Int_t GetVolumeIndex(TVector3 pos);
132  Bool_t IsInside(TVector3 pos);
133 
134  TVector3 GetVolumePosition(Int_t id);
135  TVector3 GetVolumeCenter(Int_t id);
136 
137  Double_t GetTransversalComponent(TVector3 position, TVector3 direction);
138 
139  std::vector<Double_t> GetTransversalComponentAlongPath(TVector3 from, TVector3 to, Double_t dl = 1.,
140  Int_t Nmax = 0);
141 
142  Double_t GetTransversalFieldAverage(TVector3 from, TVector3 to, Double_t dl = 1., Int_t Nmax = 0);
143 
144  TVector3 GetFieldAverageTransverseVector(TVector3 from, TVector3 to, Double_t dl = 10., Int_t Nmax = 0);
145 
146  TCanvas* DrawHistogram(TString projection, TString Bcomp, Int_t volIndex = -1, Double_t step = -1,
147  TString style = "COLZ0", Double_t depth = -100010.0);
148 
149  TCanvas* DrawTracks(TVector3 vanishingPoint, Int_t divisions, Int_t volId = 0);
150 
151  void PrintMetadata();
152 
154  TRestAxionMagneticField(const char* cfgFileName, std::string name = "");
156 
157  ClassDef(TRestAxionMagneticField, 3);
158 };
159 #endif
std::vector< TVector3 > fMeshSize
The size of a grid element from the mesh in mm.
std::vector< TVector3 > fBoundMax
A vector to store the maximum bounding box values.
A class to load magnetic field maps and evaluate the field on those maps including interpolation...
std::vector< TString > fMeshType
The type of the mesh used (default is cylindrical)
std::vector< TVector3 > fConstantField
A constant field component that will be added to the field map.
Int_t GetNumberOfVolumes()
The number of magnetic volumes loaded into the object.
TCanvas * fCanvas
A canvas to insert the histogram drawing.
std::vector< TVector3 > fPositions
The absolute position of each of the magnetic volumes defined in this class.
std::vector< std::string > fFileNames
The name of the filenames containing the field data.
Bool_t IsFieldConstant(Int_t id)
It returns true if no magnetic field map was loaded for that volume.
Bool_t FieldLoaded()
This private method returns true if the magnetic field volumes loaded are the same as the volumes def...
std::vector< MagneticFieldVolume > fMagneticFieldVolumes
A magnetic field volume structure to store field data and mesh.
TH2D * fHisto
A helper histogram to plot the field.
A base class for any REST metadata class.
Definition: TRestMetadata.h:70
A basic class inheriting from TObject to help creating a node grid definition.
Definition: TRestMesh.h:38
MagneticFieldVolume * GetMagneticVolume(Int_t id)
It returns a pointer to the corresponding magnetic volume id.