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
10#ifndef FIELD_SHIPBFIELDMAP_H_
11#define FIELD_SHIPBFIELDMAP_H_
12
13#include <string>
14#include <utility>
15#include <vector>
16
17#include "TGeoMatrix.h"
18#include "TVirtualMagField.h"
19
20class ShipBFieldMap : public TVirtualMagField {
21 public:
23
42 ShipBFieldMap(const std::string& label, const std::string& mapFileName,
43 Float_t xOffset = 0.0, Float_t yOffset = 0.0,
44 Float_t zOffset = 0.0, Float_t phi = 0.0, Float_t theta = 0.0,
45 Float_t psi = 0.0, Float_t scale = 1.0,
46 Bool_t isSymmetric = kFALSE);
47
50
66 ShipBFieldMap(const std::string& newName, const ShipBFieldMap& rhs,
67 Float_t newXOffset, Float_t newYOffset, Float_t newZOffset,
68 Float_t newPhi = 0.0, Float_t newTheta = 0.0,
69 Float_t newPsi = 0.0, Float_t newScale = 1.0);
70
72 virtual ~ShipBFieldMap();
73
75
80 virtual void Field(const Double_t* position, Double_t* B);
81
83 typedef std::vector<std::vector<Float_t>> floatArray;
84
86
89 floatArray* getFieldMap() const { return fieldMap_; }
90
92
95 void SetXOffset(Float_t xValue) { xOffset_ = xValue; }
96
98
101 void SetYOffset(Float_t yValue) { yOffset_ = yValue; }
102
104
107 void SetZOffset(Float_t zValue) { zOffset_ = zValue; }
108
110
113 void SetPhi(Float_t phi) { phi_ = phi; }
114
116
120 void SetTheta(Float_t theta) { theta_ = theta; }
121
123
127 void SetPsi(Float_t psi) { psi_ = psi; }
128
130
133 void SetScale(Float_t scale) { scale_ = scale; }
134
136
139 void UseSymmetry(Bool_t flag) { isSymmetric_ = flag; }
140
142
145 std::string GetMapFileName() const { return mapFileName_; }
146
148
151 Int_t GetNx() const { return Nx_; }
152
154
157 Int_t GetNy() const { return Ny_; }
158
160
163 Int_t GetNz() const { return Nz_; }
164
166
169 Int_t GetNBins() const { return N_; }
170
172
175 Float_t GetXMin() const { return xMin_; }
176
178
181 Float_t GetXMax() const { return xMax_; }
182
184
187 Float_t GetdX() const { return dx_; }
188
190
193 Float_t GetXRange() const { return xRange_; }
194
196
199 Float_t GetYMin() const { return yMin_; }
200
202
205 Float_t GetYMax() const { return yMax_; }
206
208
211 Float_t GetdY() const { return dy_; }
212
214
217 Float_t GetYRange() const { return yRange_; }
218
220
223 Float_t GetZMin() const { return zMin_; }
224
226
229 Float_t GetZMax() const { return zMax_; }
230
232
235 Float_t GetdZ() const { return dz_; }
236
238
241 Float_t GetZRange() const { return zRange_; }
242
244
247 Float_t GetXOffset() const { return xOffset_; }
248
250
253 Float_t GetYOffset() const { return yOffset_; }
254
256
259 Float_t GetZOffset() const { return zOffset_; }
260
262
265 Float_t GetPhi() const { return phi_; }
266
269
273 Float_t GetTheta() const { return theta_; }
274
277
280 Float_t GetPsi() const { return psi_; }
281
283
286 Float_t GetScale() const { return scale_; }
287
289
292 Bool_t HasSymmetry() const { return isSymmetric_; }
293
295
298 Bool_t IsACopy() const { return isCopy_; }
299
302
303 protected:
304 private:
305 ShipBFieldMap(const ShipBFieldMap& rhs) = delete;
306 ShipBFieldMap& operator=(const ShipBFieldMap& rhs) = delete;
307
309 enum CoordAxis { xAxis = 0, yAxis, zAxis };
310
312 void initialise();
313
315 void readMapFile();
316
318 void readRootFile();
319
321 void readTextFile();
322
323 // ! Set the coordinate limits from information stored in the datafile
324 void setLimits();
325
327
333 Bool_t insideRange(Float_t x, Float_t y, Float_t z);
334
336 typedef std::pair<Int_t, Float_t> binPair;
337
339
346 binPair getBinInfo(Float_t x, CoordAxis theAxis);
347
349
355 Int_t getMapBin(Int_t iX, Int_t iY, Int_t iZ);
356
359
364 Float_t BInterCalc(CoordAxis theAxis);
365
369
371 std::string mapFileName_;
372
375
378 Bool_t isCopy_;
379
381 Int_t Nx_;
382
384 Int_t Ny_;
385
387 Int_t Nz_;
388
390 Int_t N_;
391
393 Float_t xMin_;
394
396 Float_t xMax_;
397
399 Float_t dx_;
400
402 Float_t xRange_;
403
405 Float_t yMin_;
406
408 Float_t yMax_;
409
411 Float_t dy_;
412
414 Float_t yRange_;
415
417 Float_t zMin_;
418
420 Float_t zMax_;
421
423 Float_t dz_;
424
426 Float_t zRange_;
427
429 Float_t xOffset_;
430
432 Float_t yOffset_;
433
435 Float_t zOffset_;
436
438 Float_t phi_;
439
441 Float_t theta_;
442
444 Float_t psi_;
445
447 Float_t scale_;
448
451
453 TGeoMatrix* theTrans_;
454
456 Float_t Tesla_;
457
459 Int_t binA_;
460
462 Int_t binB_;
463
465 Int_t binC_;
466
468 Int_t binD_;
469
471 Int_t binE_;
472
474 Int_t binF_;
475
477 Int_t binG_;
478
480 Int_t binH_;
481
483 Float_t xFrac_;
484
486 Float_t yFrac_;
487
489 Float_t zFrac_;
490
492 Float_t xFrac1_;
493
495 Float_t yFrac1_;
496
498 Float_t zFrac1_;
499};
500
501#endif // FIELD_SHIPBFIELDMAP_H_
Definition: diagrams_b.h:4
Class that defines a (3d) magnetic field map (distances in cm, fields in tesla)
Definition: ShipBFieldMap.h:20
Float_t zFrac_
Fractional bin distance along z.
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.
Int_t binD_
Bin D for the trilinear interpolation.
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.
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.
Float_t zFrac1_
Complimentary fractional bin distance along z.
Int_t binE_
Bin E for the trilinear interpolation.
Float_t BInterCalc(CoordAxis theAxis)
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.
std::vector< std::vector< Float_t > > floatArray
Typedef for a vector containing a vector of floats.
Definition: ShipBFieldMap.h:83
Int_t N_
The total number of bins.
Float_t GetTheta() const
floatArray * fieldMap_
Float_t yFrac1_
Complimentary fractional bin distance along y.
Float_t xFrac_
Fractional bin distance along x.
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.
Float_t yFrac_
Fractional bin distance along y.
Int_t binC_
Bin C for the trilinear interpolation.
Bool_t IsACopy() const
Get the boolean flag to specify if we are a "copy".
virtual void Field(const Double_t *position, Double_t *B)
Implementation of evaluating the B field.
Int_t binG_
Bin G for the trilinear interpolation.
Int_t binH_
Bin H for the trilinear interpolation.
Float_t xMin_
The minimum value of x for the map.
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.
Int_t binB_
Bin B for the trilinear interpolation.
Int_t binF_
Bin F for the trilinear interpolation.
CoordAxis
Enumeration to specify the coordinate type.
void SetXOffset(Float_t xValue)
Set the x global coordinate shift.
Definition: ShipBFieldMap.h:95
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.
Definition: ShipBFieldMap.h:89
void UseSymmetry(Bool_t flag)
Set the boolean to specify if we have quadrant symmetry.
Float_t GetPsi() const
ClassDef(ShipBFieldMap, 1)
ClassDef for ROOT.
Int_t Nx_
The number of bins along x.
Float_t GetdY() const
Get the bin width along y for the map.
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.
void SetTheta(Float_t theta)
Set the second Euler rotation angle theta about the new x axis.
virtual ~ShipBFieldMap()
Destructor.
void readRootFile()
Process the ROOT file containing the field map data.
Float_t GetdZ() const
Get the bin width along z for the map.
Float_t xFrac1_
Complimentary fractional bin distance along x.
Int_t binA_
Bin A for the trilinear interpolation.
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.