Belle II Software development
GeoMagneticField Class Reference

The GeoMagneticField class. More...

#include <GeoMagneticField.h>

Inheritance diagram for GeoMagneticField:
CreatorBase

Public Member Functions

 GeoMagneticField ()
 Constructor of the GeoMagneticField class.
 
virtual ~GeoMagneticField ()
 The destructor of the GeoMagneticField class.
 
virtual void create (const GearDir &content, G4LogicalVolume &topVolume, geometry::GeometryTypes type) override
 Creates the global ROOT objects and prepares everything for other creators.
 
virtual void createFromDB (const std::string &, G4LogicalVolume &, geometry::GeometryTypes) override
 Nothing to be done when creating from DB, the payload should be found automatically.
 
virtual void createPayloads (const GearDir &content, const IntervalOfValidity &iov) override
 Function to create the geometry database.
 
MagneticField createConfiguration (const GearDir &content)
 Create a Database configuration from Gearbox parameters.
 
 BELLE2_DEFINE_EXCEPTION (DBNotImplemented, "Cannot create geometry from Database.")
 Exception that will be thrown in createFromDB if member is not yet implemented by creator.
 

Protected Types

typedef std::map< std::string, boost::function< void(const GearDir &) > > CompTypeMap
 Typedef for the map connecting the name of the component to the method reading the parameters.
 

Protected Member Functions

void readConstantBField (const GearDir &component)
 Reads the parameters for a homogeneous magnetic field and adds the component to the global magnetic field.
 
void readRadialBField (const GearDir &component)
 Reads the parameters for a radial magnetic field and adds the component to the global magnetic field.
 
void readQuadBField (const GearDir &component)
 Reads the parameters for a quadrupole magnetic field inside beam pipes and adds the component to the global magnetic field.
 
void readBeamlineBField (const GearDir &component)
 Reads the 3D Bfield map and parameters near beam pipes and adds the component to the global magnetic field.
 
void readKlm1BField (const GearDir &component)
 Reads the 2D Bfield map and parameters outside of solenoid and adds the component to the global magnetic field.
 
void read3dBField (const GearDir &component)
 Reads the parameters for 3d magnetic field (r,phi,z).
 
void addConstantBField (const GearDir &component, MagneticField &fieldmap)
 Add a constant field component to a magnetic field configuration for the DB.
 
void add3dBField (const GearDir &component, MagneticField &fielmap)
 Add a 3D field component to a magnetic field configuration for the DB.
 

Protected Attributes

CompTypeMap m_componentTypeMap
 Maps the name of the component to the function reading the parameters.
 

Detailed Description

The GeoMagneticField class.

The global creator for the magnetic field of the Belle II detector. It supports homogeneous and radial fields. Special field implementations for subdetectors should be added to the Belle II magnetic field inside the subdetectors' creators.

Definition at line 35 of file GeoMagneticField.h.

Member Typedef Documentation

◆ CompTypeMap

typedef std::map< std::string, boost::function < void (const GearDir&) > > CompTypeMap
protected

Typedef for the map connecting the name of the component to the method reading the parameters.

Definition at line 69 of file GeoMagneticField.h.

Constructor & Destructor Documentation

◆ GeoMagneticField()

Constructor of the GeoMagneticField class.

Definition at line 46 of file GeoMagneticField.cc.

46 : CreatorBase()
47{
48 //Add the function pointers called for reading the components to the map
49 m_componentTypeMap.insert(make_pair("Constant", boost::bind(&GeoMagneticField::readConstantBField, this, boost::placeholders::_1)));
50 m_componentTypeMap.insert(make_pair("Radial", boost::bind(&GeoMagneticField::readRadialBField, this, boost::placeholders::_1)));
51 m_componentTypeMap.insert(make_pair("Quad", boost::bind(&GeoMagneticField::readQuadBField, this, boost::placeholders::_1)));
52 m_componentTypeMap.insert(make_pair("Beamline", boost::bind(&GeoMagneticField::readBeamlineBField, this, boost::placeholders::_1)));
53 m_componentTypeMap.insert(make_pair("Klm1", boost::bind(&GeoMagneticField::readKlm1BField, this, boost::placeholders::_1)));
54 m_componentTypeMap.insert(make_pair("3d", boost::bind(&GeoMagneticField::read3dBField, this, boost::placeholders::_1)));
55}
void readConstantBField(const GearDir &component)
Reads the parameters for a homogeneous magnetic field and adds the component to the global magnetic f...
void readBeamlineBField(const GearDir &component)
Reads the 3D Bfield map and parameters near beam pipes and adds the component to the global magnetic ...
void readKlm1BField(const GearDir &component)
Reads the 2D Bfield map and parameters outside of solenoid and adds the component to the global magne...
CompTypeMap m_componentTypeMap
Maps the name of the component to the function reading the parameters.
void readRadialBField(const GearDir &component)
Reads the parameters for a radial magnetic field and adds the component to the global magnetic field.
void read3dBField(const GearDir &component)
Reads the parameters for 3d magnetic field (r,phi,z).
void readQuadBField(const GearDir &component)
Reads the parameters for a quadrupole magnetic field inside beam pipes and adds the component to the ...
CreatorBase()
Default Constructor.
Definition: CreatorBase.h:33

Member Function Documentation

◆ add3dBField()

void add3dBField ( const GearDir component,
MagneticField fielmap 
)
protected

Add a 3D field component to a magnetic field configuration for the DB.

Definition at line 89 of file GeoMagneticField.cc.

90{
91 string mapFilename = component.getString("MapFilename");
92 int mapSizeR = component.getInt("NumberGridPointsR");
93 int mapSizeZ = component.getInt("NumberGridPointsZ");
94 int mapSizePhi = component.getInt("NumberGridPointsPhi");
95
96 double minZ = component.getLength("ZMin");
97 double maxZ = component.getLength("ZMax");
98 double minR = component.getLength("RadiusMin");
99 double maxR = component.getLength("RadiusMax");
100
101 const string fullPath = FileSystem::findFile("/data/" + mapFilename);
102 if (!FileSystem::fileExists(fullPath)) {
103 B2ERROR("The 3d magnetic field map file '" << mapFilename << "' could not be found !");
104 return;
105 }
106
107 std::vector<ROOT::Math::XYZVector> bmap;
108 bmap.reserve(mapSizeR * mapSizeZ * mapSizePhi);
109 // Load B-field map file
110 boost::iostreams::filtering_istream fieldMapFile;
111 fieldMapFile.push(boost::iostreams::gzip_decompressor());
112 fieldMapFile.push(boost::iostreams::file_source(fullPath));
113
114 char tmp[256];
115 for (int k = 0; k < mapSizeZ; k++) { // z
116 for (int i = 0; i < mapSizeR; i++) { // r
117 for (int j = 0; j < mapSizePhi; j++) { // phi
118 double Br, Bz, Bphi;
119 //r[m] phi[deg] z[m] Br[T] Bphi[T] Bz[T]
120 fieldMapFile.getline(tmp, 256);
121 // sscanf(tmp+33,"%lf %lf %lf",&Br,&Bphi,&Bz);
122 char* next;
123 Br = strtod(tmp + 33, &next);
124 Bphi = strtod(next, &next);
125 Bz = strtod(next, nullptr);
126 bmap.emplace_back(-Br * Unit::T, -Bphi * Unit::T, -Bz * Unit::T);
127 }
128 }
129 }
130 auto* field = new MagneticFieldComponent3D(
131 minR, maxR, minZ, maxZ,
132 mapSizeR, mapSizePhi, mapSizeZ,
133 std::move(bmap)
134 );
135 fieldmap.addComponent(field);
136}
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:151
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
Definition: FileSystem.cc:32
Describe one component of the Geometry.
static const double T
[tesla]
Definition: Unit.h:120

◆ addConstantBField()

void addConstantBField ( const GearDir component,
MagneticField fieldmap 
)
protected

Add a constant field component to a magnetic field configuration for the DB.

Definition at line 75 of file GeoMagneticField.cc.

76{
77 double xValue = component.getWithUnit("X");
78 double yValue = component.getWithUnit("Y");
79 double zValue = component.getWithUnit("Z");
80 double RminValue = component.getLength("MinR", 0); // stored in cm
81 double RmaxValue = component.getLength("MaxR"); // stored in cm
82 double ZminValue = component.getLength("MinZ"); // stored in cm
83 double ZmaxValue = component.getLength("MaxZ"); // stored in cm
84 auto field = new MagneticFieldComponentConstant(ROOT::Math::XYZVector(xValue, yValue, zValue),
85 RminValue, RmaxValue, ZminValue, ZmaxValue);
86 fieldmap.addComponent(field);
87}
Describe one component of the Geometry.
void addComponent(MagneticFieldComponent *component)
Add a new component to the magnetic field.
Definition: MagneticField.h:59

◆ create()

void create ( const GearDir content,
G4LogicalVolume &  topVolume,
geometry::GeometryTypes  type 
)
overridevirtual

Creates the global ROOT objects and prepares everything for other creators.

Parameters
contentA reference to the content part of the parameter description, which should to be used to create the ROOT objects.
topVolumeGeant4 logical top volume.
typeGeometry type.

Implements CreatorBase.

Definition at line 145 of file GeoMagneticField.cc.

146{
147 // clear any existing BField
149
150 //Loop over all components of the magnetic field
151 CompTypeMap::iterator findIter;
152 for (const GearDir& component : content.getNodes("Components/Component")) {
153 //Get the type of the magnetic field and call the appropriate function
154 string compType = component.getString("attribute::type");
155 B2DEBUG(10, "GeoMagneticField creator: Loading the parameters for the component type'" << compType << "'");
156
157 findIter = m_componentTypeMap.find(compType);
158 if (findIter != m_componentTypeMap.end()) {
159 findIter->second(component);
160 } else {
161 B2ERROR("The magnetic field component type '" << compType << "' is unknown !");
162 }
163 }
164
166}
void initialize()
Initialize the magnetic field after adding all components.
Definition: BFieldMap.cc:21
void clear()
Clear the existing components.
Definition: BFieldMap.cc:33
static BFieldMap & Instance()
Static method to get a reference to the BFieldMap instance.
Definition: BFieldMap.cc:15
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31

◆ createConfiguration()

MagneticField createConfiguration ( const GearDir content)

Create a Database configuration from Gearbox parameters.

Definition at line 60 of file GeoMagneticField.cc.

61{
62 MagneticField fieldmap;
63 //Read the magnetic field components
64 for (const GearDir& component : content.getNodes("Components/Component")) {
65 //Get the type of the magnetic field and call the appropriate function
66 string compType = component.getString("attribute::type");
67 B2DEBUG(10, "GeoMagneticField creator: Loading the parameters for the component type'" << compType << "'");
68 if (compType == "3d") add3dBField(component, fieldmap);
69 else if (compType == "Constant") addConstantBField(component, fieldmap);
70 else B2ERROR("The magnetic field type " << compType << " can not yet be stored in the database");
71 }
72 return fieldmap;
73}
void add3dBField(const GearDir &component, MagneticField &fielmap)
Add a 3D field component to a magnetic field configuration for the DB.
void addConstantBField(const GearDir &component, MagneticField &fieldmap)
Add a constant field component to a magnetic field configuration for the DB.
Magnetic field map.
Definition: MagneticField.h:32

◆ createFromDB()

virtual void createFromDB ( const std::string &  ,
G4LogicalVolume &  ,
geometry::GeometryTypes   
)
inlineoverridevirtual

Nothing to be done when creating from DB, the payload should be found automatically.

Reimplemented from CreatorBase.

Definition at line 59 of file GeoMagneticField.h.

59{}

◆ createPayloads()

void createPayloads ( const GearDir content,
const IntervalOfValidity iov 
)
overridevirtual

Function to create the geometry database.

This function should be implemented to convert Gearbox parameters to one or more database payloads

Parameters
contentGearDir pointing to the parameters which should be used for construction
iovinterval of validity to use when generating payloads

Reimplemented from CreatorBase.

Definition at line 138 of file GeoMagneticField.cc.

139{
141 importObj.construct(createConfiguration(content));
142 importObj.import(iov);
143}
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:36
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
MagneticField createConfiguration(const GearDir &content)
Create a Database configuration from Gearbox parameters.

◆ read3dBField()

void read3dBField ( const GearDir component)
protected

Reads the parameters for 3d magnetic field (r,phi,z).

Parameters
componentThe GearDir pointing to the component parameter block from which the parameters should be read.

Definition at line 289 of file GeoMagneticField.cc.

290{
291 string mapFilename = component.getString("MapFilename");
292 int mapSizeR = component.getInt("NumberGridPointsR");
293 int mapSizeZ = component.getInt("NumberGridPointsZ");
294 int mapSizePhi = component.getInt("NumberGridPointsPhi");
295
296 double mapRegionMinZ = component.getLength("ZMin");
297 double mapRegionMaxZ = component.getLength("ZMax");
298 double mapOffset = component.getLength("ZOffset");
299
300 double mapRegionMinR = component.getLength("RadiusMin");
301 double mapRegionMaxR = component.getLength("RadiusMax");
302
303 double gridPitchR = component.getLength("GridPitchR");
304 double gridPitchZ = component.getLength("GridPitchZ");
305 double gridPitchPhi = component.getLength("GridPitchPhi");
306 bool mirrorPhi = bool(component.getInt("MirrorPhi"));
307
308 double excludeRegionMinZ = component.getLength("ExcludeZMin");
309 double excludeRegionMaxZ = component.getLength("ExcludeZMax");
310 double excludeRegionMinR = component.getLength("ExcludeRadiusMin");
311 double excludeRegionMaxR = component.getLength("ExcludeRadiusMax");
312
313 double errorRegionMinR = component.getLength("BiasRadiusMin");
314 double errorRegionMaxR = component.getLength("BiasRadiusMax");
315 double errorBr = component.getDouble("BiasBr");
316 double errorBphi = component.getDouble("BiasBphi");
317 double errorBz = component.getDouble("BiasBz");
318
319 bool doInterpolation = bool(component.getInt("enableInterpolation"));
320 string enableCoordinate = component.getString("EnableCoordinate");
321
323 bComp.setMapFilename(mapFilename);
324 bComp.setMapSize(mapSizeR, mapSizePhi, mapSizeZ);
325 bComp.setMapRegionZ(mapRegionMinZ, mapRegionMaxZ, mapOffset);
326 bComp.setMapRegionR(mapRegionMinR, mapRegionMaxR);
327 bComp.setGridPitch(gridPitchR, gridPitchPhi, gridPitchZ);
328 bComp.setExcludeRegionZ(excludeRegionMinZ, excludeRegionMaxZ);
329 bComp.setExcludeRegionR(excludeRegionMinR, excludeRegionMaxR);
330 bComp.setErrorRegionR(errorRegionMinR, errorRegionMaxR, errorBr, errorBphi, errorBz);
331 bComp.mirrorPhi(mirrorPhi);
332 bComp.doInterpolation(doInterpolation);
333 bComp.enableCoordinate(enableCoordinate);
334
335}
The BFieldComponent3d class.
void setMapFilename(const std::string &filename)
Sets the filename of the magnetic field map.
BFIELDCOMP & addBFieldComponent()
Adds a new BField component to the Belle II magnetic field.
Definition: BFieldMap.h:98

◆ readBeamlineBField()

void readBeamlineBField ( const GearDir component)
protected

Reads the 3D Bfield map and parameters near beam pipes and adds the component to the global magnetic field.

Definition at line 238 of file GeoMagneticField.cc.

239{
240 string mapFilenameHER = component.getString("MapFilenameHER");
241 string mapFilenameLER = component.getString("MapFilenameLER");
242 string interFilenameHER = component.getString("InterFilenameHER");
243 string interFilenameLER = component.getString("InterFilenameLER");
244
245 double mapRegionMinZ = component.getLength("ZMin");
246 double mapRegionMaxZ = component.getLength("ZMax");
247
248 double mapRegionMinR = component.getLength("RadiusMin");
249 double mapRegionMaxR = component.getLength("RadiusMax");
250
251 double beamAngle = component.getLength("BeamAngle");
252
254 bComp.setMapFilename(mapFilenameHER, mapFilenameLER);
255 bComp.setInterpolateFilename(interFilenameHER, interFilenameLER);
256 bComp.setMapRegionZ(mapRegionMinZ, mapRegionMaxZ);
257 bComp.setMapRegionR(mapRegionMinR, mapRegionMaxR);
258 bComp.setBeamAngle(beamAngle);
259}
The BFieldComponentBeamline class.
void setMapFilename(const std::string &filename_her, const std::string &filename_ler)
Sets the filename of the magnetic field map.

◆ readConstantBField()

void readConstantBField ( const GearDir component)
protected

Reads the parameters for a homogeneous magnetic field and adds the component to the global magnetic field.

Parameters
componentThe GearDir pointing to the component parameter block from which the parameters should be read.

Definition at line 173 of file GeoMagneticField.cc.

174{
175 double xValue = component.getDouble("X");
176 double yValue = component.getDouble("Y");
177 double zValue = component.getDouble("Z");
178 double RmaxValue = component.getLength("MaxR"); // stored in cm
179 double ZminValue = component.getLength("MinZ"); // stored in cm
180 double ZmaxValue = component.getLength("MaxZ"); // stored in cm
181
183 bComp.setMagneticFieldValues(xValue, yValue, zValue, RmaxValue, ZminValue, ZmaxValue);
184}
The BFieldComponentConstant class.
void setMagneticFieldValues(double x, double y, double z, double rmax, double zmin, double zmax)
Sets the values for the homogeneous magnetic field vector.

◆ readKlm1BField()

void readKlm1BField ( const GearDir component)
protected

Reads the 2D Bfield map and parameters outside of solenoid and adds the component to the global magnetic field.

Magnetic field map in Belle I are used.

Definition at line 261 of file GeoMagneticField.cc.

262{
263 string mapFilename = component.getString("MapFilename");
264
265 int nBarrelLayers = component.getInt("NumberBarrelLayers");
266 int nEndcapLayers = component.getInt("NumberEndcapLayers");
267
268 double barrelRMin = component.getLength("BarrelRadiusMin");
269 double barrelZMax = component.getLength("BarrelZMax");
270 double mapOffset = component.getLength("ZOffset");
271
272 double endcapRMin = component.getLength("EdncapRadiusMin");
273 double endcapZMin = component.getLength("EndcapZMin");
274
275 double barrelGapHeightLayer0 = component.getLength("BarrelGapHeightLayer0");
276 double barrelIronThickness = component.getLength("BarrelIronThickness");
277 double endcapGapHeight = component.getLength("EndcapGapHeight");
278 double dLayer = component.getLength("DLayer");
279
280
282 bComp.setMapFilename(mapFilename);
283 bComp.setNLayers(nBarrelLayers, nEndcapLayers);
284 bComp.setBarrelRegion(barrelRMin, barrelZMax, mapOffset);
285 bComp.setEndcapRegion(endcapRMin, endcapZMin);
286 bComp.setLayerParam(barrelGapHeightLayer0, barrelIronThickness, endcapGapHeight, dLayer);
287}
The Bfieldcomponentklm1 class.
void setMapFilename(const std::string &filename)
Sets the filename of the magnetic field map.

◆ readQuadBField()

void readQuadBField ( const GearDir component)
protected

Reads the parameters for a quadrupole magnetic field inside beam pipes and adds the component to the global magnetic field.

Parameters
componentThe GearDir pointing to the component parameter block from which the parameters should be read.

Definition at line 217 of file GeoMagneticField.cc.

218{
219 string mapFilenameHER = component.getString("MapFilenameHER");
220 string mapFilenameLER = component.getString("MapFilenameLER");
221 string mapFilenameHERleak = component.getString("MapFilenameHERleak");
222 string apertFilenameHER = component.getString("ApertFilenameHER");
223 string apertFilenameLER = component.getString("ApertFilenameLER");
224
225 int mapSizeHER = component.getInt("MapSizeHER");
226 int mapSizeLER = component.getInt("MapSizeLER");
227 int mapSizeHERleak = component.getInt("MapSizeHERleak");
228 int apertSizeHER = component.getInt("ApertSizeHER");
229 int apertSizeLER = component.getInt("ApertSizeLER");
230
232 bComp.setMapFilename(mapFilenameHER, mapFilenameLER, mapFilenameHERleak);
233 bComp.setApertFilename(apertFilenameHER, apertFilenameLER);
234 bComp.setMapSize(mapSizeHER, mapSizeLER, mapSizeHERleak);
235 bComp.setApertSize(apertSizeHER, apertSizeLER);
236}
The BFieldComponentQuad class.
void setMapFilename(const std::string &filenameHER, const std::string &filenameLER, const std::string &filenameHERleak)
Sets the filename of the magnetic field map.

◆ readRadialBField()

void readRadialBField ( const GearDir component)
protected

Reads the parameters for a radial magnetic field and adds the component to the global magnetic field.

Parameters
componentThe GearDir pointing to the component parameter block from which the parameters should be read.

Definition at line 187 of file GeoMagneticField.cc.

188{
189 string mapFilename = component.getString("MapFilename");
190 int mapSizeR = component.getInt("NumberGridPointsR");
191 int mapSizeZ = component.getInt("NumberGridPointsZ");
192
193 double mapRegionMinZ = component.getLength("ZMin");
194 double mapRegionMaxZ = component.getLength("ZMax");
195 double mapOffset = component.getLength("ZOffset");
196
197 double mapRegionMinR = component.getLength("RadiusMin");
198 double mapRegionMaxR = component.getLength("RadiusMax");
199
200 double gridPitchR = component.getLength("GridPitchR");
201 double gridPitchZ = component.getLength("GridPitchZ");
202
203 double slotRMin = component.getLength("SlotRMin");
204 double endyokeZMin = component.getLength("EndyokeZMin");
205 double gapHeight = component.getLength("GapHeight");
206 double ironThickness = component.getLength("IronPlateThickness");
207
209 bComp.setMapFilename(mapFilename);
210 bComp.setMapSize(mapSizeR, mapSizeZ);
211 bComp.setMapRegionZ(mapRegionMinZ, mapRegionMaxZ, mapOffset);
212 bComp.setMapRegionR(mapRegionMinR, mapRegionMaxR);
213 bComp.setGridPitch(gridPitchR, gridPitchZ);
214 bComp.setKlmParameters(slotRMin, endyokeZMin, gapHeight, ironThickness);
215}
The BFieldComponentRadial class.
void setMapFilename(const std::string &filename)
Sets the filename of the magnetic field map.

Member Data Documentation

◆ m_componentTypeMap

CompTypeMap m_componentTypeMap
protected

Maps the name of the component to the function reading the parameters.

Definition at line 70 of file GeoMagneticField.h.


The documentation for this class was generated from the following files: