FairShip
Loading...
Searching...
No Matches
ShipBFieldMap.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
9
10#ifndef FIELD_SHIPBFIELDMAP_H_
11#define FIELD_SHIPBFIELDMAP_H_
12
13#include <array>
14#include <string>
15#include <utility>
16#include <vector>
17
18#include "TGeoMatrix.h"
19#include "TVirtualMagField.h"
20
21class TTree;
22
23class ShipBFieldMap : public TVirtualMagField {
24 public:
26
45 ShipBFieldMap(const std::string& label, const std::string& mapFileName,
46 Float_t xOffset = 0.0, Float_t yOffset = 0.0,
47 Float_t zOffset = 0.0, Float_t phi = 0.0, Float_t theta = 0.0,
48 Float_t psi = 0.0, Float_t scale = 1.0,
49 Bool_t isSymmetric = kFALSE);
50
53
69 ShipBFieldMap(const std::string& newName, const ShipBFieldMap& rhs,
70 Float_t newXOffset, Float_t newYOffset, Float_t newZOffset,
71 Float_t newPhi = 0.0, Float_t newTheta = 0.0,
72 Float_t newPsi = 0.0, Float_t newScale = 1.0);
73
75 ~ShipBFieldMap() override;
76
78
83 void Field(const Double_t* position, Double_t* B) override;
84
87 typedef std::vector<std::array<Float_t, 3>> floatArray;
88
90
93 floatArray* getFieldMap() const { return fieldMap_; }
94
96
99 void SetXOffset(Float_t xValue) { xOffset_ = xValue; }
100
102
105 void SetYOffset(Float_t yValue) { yOffset_ = yValue; }
106
108
111 void SetZOffset(Float_t zValue) { zOffset_ = zValue; }
112
114
117 void SetPhi(Float_t phi) { phi_ = phi; }
118
120
124 void SetTheta(Float_t theta) { theta_ = theta; }
125
127
131 void SetPsi(Float_t psi) { psi_ = psi; }
132
134
137 void SetScale(Float_t scale) { scale_ = scale; }
138
140
143 void UseSymmetry(Bool_t flag) { isSymmetric_ = flag; }
144
146
149 std::string GetMapFileName() const { return mapFileName_; }
150
152
155 Int_t GetNx() const { return Nx_; }
156
158
161 Int_t GetNy() const { return Ny_; }
162
164
167 Int_t GetNz() const { return Nz_; }
168
170
173 Int_t GetNBins() const { return N_; }
174
176
179 Float_t GetXMin() const { return xMin_; }
180
182
185 Float_t GetXMax() const { return xMax_; }
186
188
191 Float_t GetdX() const { return dx_; }
192
194
197 Float_t GetXRange() const { return xRange_; }
198
200
203 Float_t GetYMin() const { return yMin_; }
204
206
209 Float_t GetYMax() const { return yMax_; }
210
212
215 Float_t GetdY() const { return dy_; }
216
218
221 Float_t GetYRange() const { return yRange_; }
222
224
227 Float_t GetZMin() const { return zMin_; }
228
230
233 Float_t GetZMax() const { return zMax_; }
234
236
239 Float_t GetdZ() const { return dz_; }
240
242
245 Float_t GetZRange() const { return zRange_; }
246
248
251 Float_t GetXOffset() const { return xOffset_; }
252
254
257 Float_t GetYOffset() const { return yOffset_; }
258
260
263 Float_t GetZOffset() const { return zOffset_; }
264
266
269 Float_t GetPhi() const { return phi_; }
270
273
277 Float_t GetTheta() const { return theta_; }
278
281
284 Float_t GetPsi() const { return psi_; }
285
287
290 Float_t GetScale() const { return scale_; }
291
293
296 Bool_t HasSymmetry() const { return isSymmetric_; }
297
299
302 Bool_t IsACopy() const { return isCopy_; }
303
306
307 protected:
308 private:
309 ShipBFieldMap(const ShipBFieldMap& rhs) = delete;
310 ShipBFieldMap& operator=(const ShipBFieldMap& rhs) = delete;
311
313 enum CoordAxis { xAxis = 0, yAxis, zAxis };
314
316 void initialise();
317
319 void readMapFile();
320
322 void readRootFile();
323
325 void readTextFile();
326
328
332 void checkRootFileOrdering(TTree* dTree);
333
334 // ! Set the coordinate limits from information stored in the datafile
335 void setLimits();
336
338
344 Bool_t insideRange(Float_t x, Float_t y, Float_t z);
345
347 typedef std::pair<Int_t, Float_t> binPair;
348
350
357 binPair getBinInfo(Float_t x, CoordAxis theAxis);
358
360
366 Int_t getMapBin(Int_t iX, Int_t iY, Int_t iZ);
367
370
373 static Float_t triLinearInterp(Float_t A, Float_t B, Float_t C, Float_t D,
374 Float_t E, Float_t F, Float_t G, Float_t H,
375 Float_t xFrac, Float_t xFrac1, Float_t yFrac,
376 Float_t yFrac1, Float_t zFrac, Float_t zFrac1);
377
381
383 std::string mapFileName_;
384
387
390 Bool_t isCopy_;
391
393 Int_t Nx_;
394
396 Int_t Ny_;
397
399 Int_t Nz_;
400
402 Int_t N_;
403
405 Float_t xMin_;
406
408 Float_t xMax_;
409
411 Float_t dx_;
412
414 Float_t xRange_;
415
417 Float_t yMin_;
418
420 Float_t yMax_;
421
423 Float_t dy_;
424
426 Float_t yRange_;
427
429 Float_t zMin_;
430
432 Float_t zMax_;
433
435 Float_t dz_;
436
438 Float_t zRange_;
439
441 Float_t xOffset_;
442
444 Float_t yOffset_;
445
447 Float_t zOffset_;
448
450 Float_t phi_;
451
453 Float_t theta_;
454
456 Float_t psi_;
457
459 Float_t scale_;
460
463
465 TGeoMatrix* theTrans_;
466
468 Float_t Tesla_;
469};
470
471#endif // FIELD_SHIPBFIELDMAP_H_
Float_t xMax_
The maximum value of x for the map.
void SetZOffset(Float_t zValue)
Set the z global coordinate shift.
void SetScale(Float_t scale)
Set the field magnitude scaling factor.
Float_t GetZMin() const
Get the minimum value of z for the map.
Float_t dy_
The bin width along y.
Float_t GetXMax() const
Get the maximum value of x for the map.
static Float_t triLinearInterp(Float_t A, Float_t B, Float_t C, Float_t D, Float_t E, Float_t F, Float_t G, Float_t H, Float_t xFrac, Float_t xFrac1, Float_t yFrac, Float_t yFrac1, Float_t zFrac, Float_t zFrac1)
Float_t psi_
The third Euler rotation angle about the new z axis.
Int_t GetNBins() const
Get the total number of bins.
Float_t dz_
The bin width along z.
Float_t zRange_
The coordinate range along z.
std::pair< Int_t, Float_t > binPair
Typedef for an int-double pair.
ShipBFieldMap(const ShipBFieldMap &rhs)=delete
Bool_t HasSymmetry() const
Get the boolean flag to specify if we have quadrant symmetry.
Float_t GetYOffset() const
Get the y offset coordinate of the map for global positioning.
ShipBFieldMap(const std::string &label, const std::string &mapFileName, Float_t xOffset=0.0, Float_t yOffset=0.0, Float_t zOffset=0.0, Float_t phi=0.0, Float_t theta=0.0, Float_t psi=0.0, Float_t scale=1.0, Bool_t isSymmetric=kFALSE)
Constructor.
Int_t Nz_
The number of bins along z.
Float_t Tesla_
Double converting Tesla to kiloGauss (for VMC/FairRoot B field units).
Float_t GetXRange() const
Get the x coordinate range for the map.
Int_t N_
The total number of bins.
Float_t GetTheta() const
floatArray * fieldMap_
Int_t GetNy() const
Get the number of bins along y.
Float_t yMin_
The minimum value of y for the map.
Float_t zOffset_
The z value of the positional offset for the map.
std::string mapFileName_
The name of the map file.
Bool_t initialised_
Initialisation boolean.
void SetPhi(Float_t phi)
Set the first Euler rotation angle phi about the z axis.
ShipBFieldMap & operator=(const ShipBFieldMap &rhs)=delete
Int_t Ny_
The number of bins along y.
Float_t GetdX() const
Get the bin width along x for the map.
std::string GetMapFileName() const
Get the name of the map file.
Float_t theta_
The second Euler rotation angle about the new x axis.
Bool_t IsACopy() const
Get the boolean flag to specify if we are a "copy".
Float_t xMin_
The minimum value of x for the map.
void Field(const Double_t *position, Double_t *B) override
Implementation of evaluating the B field.
void initialise()
Initialisation.
void SetYOffset(Float_t yValue)
Set the y global coordinate shift.
Int_t GetNz() const
Get the number of bins along z.
CoordAxis
Enumeration to specify the coordinate type.
void SetXOffset(Float_t xValue)
Set the x global coordinate shift.
Float_t GetYRange() const
Get the y coordinate range for the map.
Float_t GetScale() const
Get the field magnitude scaling factor.
void SetPsi(Float_t psi)
Set the third Euler rotation angle psi about the new z axis.
floatArray * getFieldMap() const
Retrieve the field map.
void UseSymmetry(Bool_t flag)
Set the boolean to specify if we have quadrant symmetry.
Float_t GetPsi() const
Int_t Nx_
The number of bins along x.
ClassDefOverride(ShipBFieldMap, 1)
ClassDef for ROOT.
Float_t GetdY() const
Get the bin width along y for the map.
void checkRootFileOrdering(TTree *dTree)
Check that the ROOT map really uses the assumed data ordering.
Float_t xRange_
The coordinate range along x.
Float_t yOffset_
The y value of the positional offset for the map.
void readTextFile()
Process the text file containing the field map data.
Float_t scale_
The B field magnitude scaling factor.
TGeoMatrix * theTrans_
The combined translation and rotation transformation.
binPair getBinInfo(Float_t x, CoordAxis theAxis)
Get the bin number and fractional distance from the leftmost bin edge.
Float_t GetPhi() const
Get the first Euler rotation angle about the z axis for global positioning.
Bool_t insideRange(Float_t x, Float_t y, Float_t z)
Check to see if a point is within the map validity range.
std::vector< std::array< Float_t, 3 > > floatArray
void SetTheta(Float_t theta)
Set the second Euler rotation angle theta about the new x axis.
void readRootFile()
Process the ROOT file containing the field map data.
Float_t GetdZ() const
Get the bin width along z for the map.
~ShipBFieldMap() override
Destructor.
void readMapFile()
Read the field map data and store the information internally.
Float_t GetXOffset() const
Get the x offset coordinate of the map for global positioning.
Int_t getMapBin(Int_t iX, Int_t iY, Int_t iZ)
Find the vector entry of the field map data given the bins iX, iY and iZ.
Float_t yMax_
The maximum value of y for the map.
Float_t yRange_
The coordinate range along y.
Float_t zMax_
The maximum value of z for the map.
Float_t phi_
The first Euler rotation angle about the z axis.
Float_t GetZMax() const
Get the maximum value of z for the map.
Float_t GetYMax() const
Get the maximum value of y for the map.
Float_t zMin_
The minimum value of z for the map.
Float_t GetYMin() const
Get the minimum value of y for the map.
Float_t dx_
The bin width along x.
Float_t GetXMin() const
Get the minimum value of x for the map.
Bool_t isSymmetric_
The boolean specifying if we have quadrant symmetry.
Int_t GetNx() const
Get the number of bins along x.
Float_t xOffset_
The x value of the positional offset for the map.
Float_t GetZRange() const
Get the z coordinate range for the map.
Float_t GetZOffset() const
Get the z offset coordinate of the map for global positioning.