Project
Loading...
Searching...
No Matches
MagneticField.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef ALICEO2_FIELD_MAGNETICFIELD_H_
17#define ALICEO2_FIELD_MAGNETICFIELD_H_
18
19#include "FairField.h" // for FairField
20#include "Field/MagFieldParam.h"
21#include "Field/MagneticWrapperChebyshev.h" // for MagneticWrapperChebyshev
22#include "Field/MagFieldFast.h"
23#include "TSystem.h"
24#include "Rtypes.h" // for Double_t, Char_t, Int_t, Float_t, etc
25#include "TNamed.h" // for TNamed
26#include <memory> // for str::unique_ptr
27
28namespace o2
29{
30namespace field
31{
32class MagneticWrapperChebyshev;
33class FieldOriginBiasParam;
34}
35} // namespace o2
36namespace o2
37{
38namespace field
39{
40
45{
46
47 public:
51 enum { kOverrideGRP = BIT(14) }; // don't recreate from GRP if set
52
55
59 MagneticField(const char* name, const char* title, Double_t factorSol = 1., Double_t factorDip = 1.,
61 MagFieldParam::BeamType_t btype = MagFieldParam::kBeamTypepp, Double_t benergy = -1, Int_t integ = 2,
62 Double_t fmax = 15, const std::string path = "$(O2_ROOT)/share/Common/maps/mfchebKGI_sym.root");
63
65
67 ~MagneticField() override = default;
68
70 static MagneticField* createNominalField(int fld, bool uniform = false);
71
73 void CreateField();
74
76 void AllowFastField(bool v = true);
77
78 bool fastFieldExists() const
79 {
80 return !(mMapType == MagFieldParam::k5kGUniform || mDipoleOnOffFlag == true);
81 }
82
83 void rescaleField(float l3Cur, float diCur, bool uniform, int convention = 0);
84
86
88 Double_t GetBx(Double_t x, Double_t y, Double_t z) override
89 {
90 double xyz[3] = {x, y, z}, b[3];
92 return b[0];
93 }
94
96 Double_t GetBy(Double_t x, Double_t y, Double_t z) override
97 {
98 double xyz[3] = {x, y, z}, b[3];
100 return b[1];
101 }
102
104 Double_t GetBz(Double_t x, Double_t y, Double_t z) override
105 {
106 double xyz[3] = {x, y, z};
107 return getBz(xyz);
108 }
109
112 void Field(const Double_t* __restrict__ point, Double_t* __restrict__ bField) override;
113
114 void field(const math_utils::Point3D<float> xyz, float bxyz[3])
115 {
116 double xyzd[3] = {xyz.X(), xyz.Y(), xyz.Z()}, bxyzd[3] = {0};
117 Field(xyzd, bxyzd);
118 bxyz[0] = bxyzd[0];
119 bxyz[1] = bxyzd[1];
120 bxyz[2] = bxyzd[2];
121 }
122
123 void field(const math_utils::Point3D<double> xyz, double bxyz[3])
124 {
125 double xyzd[3] = {xyz.X(), xyz.Y(), xyz.Z()};
126 Field(xyzd, bxyz);
127 }
128
129 void field(const double* __restrict__ point, double* __restrict__ bField)
130 {
131 Field(point, bField);
132 }
133
134 void field(const float* __restrict__ point, float* __restrict__ bField)
135 {
136 double xyz[3] = {point[0], point[1], point[2]}, bxyz[3] = {0};
137 Field(xyz, bxyz);
138 bField[0] = bxyz[0];
139 bField[1] = bxyz[1];
140 bField[2] = bxyz[2];
141 }
142
144 void GetBxyz(const Double_t p[3], Double_t* b) override { MagneticField::Field(p, b); }
145
147 void getTPCIntegral(const Double_t* xyz, Double_t* b) const;
148
150 void getTPCRatIntegral(const Double_t* xyz, Double_t* b) const;
151
153 void getTPCIntegralCylindrical(const Double_t* rphiz, Double_t* b) const;
154
157 void getTPCRatIntegralCylindrical(const Double_t* rphiz, Double_t* b) const;
158
160 Double_t getBz(const Double_t* xyz) const;
161
162 MagneticWrapperChebyshev* getMeasuredMap() const { return mMeasuredMap.get(); }
163
165 const MagFieldFast* getFastField() const { return mFastField.get(); }
166
167 // Former MagF methods or their aliases
168
170 void setFactorSolenoid(float fc = 1.);
171
173 void setFactorDipole(float fc = 1.);
174
176 Double_t getFactorSolenoid() const;
177
179 Double_t getFactorDipole() const;
180
181 Double_t Factor() const { return getFactorSolenoid(); }
182
183 Double_t getCurrentSolenoid() const
184 {
185 return getFactorSolenoid() * (mMapType == MagFieldParam::k2kG ? 12000 : 30000);
186 }
187
188 Double_t getCurrentDipole() const { return getFactorDipole() * 6000; }
189
190 Bool_t IsUniform() const { return mMapType == MagFieldParam::k5kGUniform; }
191
192 void MachineField(const Double_t* __restrict__ x, Double_t* __restrict__ b) const;
193
194 MagFieldParam::BMap_t getMapType() const { return mMapType; }
195
196 MagFieldParam::BeamType_t getBeamType() const { return mBeamType; }
197
199 const char* getBeamTypeText() const;
200
201 Double_t getBeamEnergy() const { return mBeamEnergy; }
202
203 Double_t Max() const { return mMaxField; }
204
205 Int_t Integral() const { return mDefaultIntegration; }
206
207 Int_t precIntegral() const { return mPrecisionInteg; }
208
209 Double_t solenoidField() const { return mSolenoid; }
210
211 Char_t* getDataFileName() const { return (Char_t*)mParameterNames.GetName(); }
212
213 Char_t* getParameterName() const { return (Char_t*)mParameterNames.GetTitle(); }
214
215 void setDataFileName(const Char_t* nm) { mParameterNames.SetName(nm); }
216
217 void setParameterName(const Char_t* nm) { mParameterNames.SetTitle(nm); }
218
220 void Print(Option_t* opt) const override;
221
222 Bool_t loadParameterization();
223
224 static Int_t getPolarityConvention() { return Int_t(sPolarityConvention); }
225
226 static MagFieldParam::BMap_t getFieldMapScale(float& l3, float& dip, bool uniform, int convention = 0);
227
234 static MagneticField* createFieldMap(float l3Current = -30000., float diCurrent = -6000., Int_t convention = 0,
235 Bool_t uniform = kFALSE, float beamenergy = 7000, const Char_t* btype = "pp",
236 const std::string path = std::string(gSystem->Getenv("VMCWORKDIR")) +
237 std::string("/Common/maps/mfchebKGI_sym.root"));
238
239 protected:
240 // not supposed to be changed during the run, set only at the initialization via constructor
241 void initializeMachineField(MagFieldParam::BeamType_t btype, Double_t benergy);
242
244
245 void setBeamEnergy(float energy) { mBeamEnergy = energy; }
246 void checkOriginBias();
247
248 private:
249 std::unique_ptr<MagneticWrapperChebyshev> mMeasuredMap;
250 std::unique_ptr<MagFieldFast> mFastField; // ! optional fast parametrization
251 MagFieldParam::BMap_t mMapType;
252 Double_t mSolenoid;
253 MagFieldParam::BeamType_t mBeamType;
254 Double_t mBeamEnergy;
255
256 Int_t mDefaultIntegration;
257 Int_t mPrecisionInteg;
258 Double_t mMultipicativeFactorSolenoid;
259 Double_t mMultipicativeFactorDipole;
260 Double_t mMaxField;
261 Bool_t mDipoleOnOffFlag;
262
263 Double_t mQuadrupoleGradient;
264 Double_t mDipoleField;
265 Double_t mCompensatorField2C;
266 Double_t mCompensatorField1A;
267 Double_t mCompensatorField2A;
268
269 TNamed mParameterNames;
270
271 static const FieldOriginBiasParam* gOriginBias;
272
273 static const Double_t sSolenoidToDipoleZ;
274 static const UShort_t sPolarityConvention;
275
277
278 ClassDefOverride(o2::field::MagneticField,
279 3) // Class for all Alice MagField wrapper for measured data + Tosca parameterization
280};
281} // namespace field
282} // namespace o2
283
284#endif
Definition of the fast magnetic field parametrization MagFieldFast.
Definition of the MagFieldParam: ALICE mag. field type enumerations.
void setBeamType(MagFieldParam::BeamType_t type)
const MagFieldFast * getFastField() const
get fast field direct pointer
static MagFieldParam::BMap_t getFieldMapScale(float &l3, float &dip, bool uniform, int convention=0)
Double_t getBz(const Double_t *xyz) const
Method to calculate the field at point xyz.
Double_t getFactorDipole() const
Return the sign*scale of the current in the Dipole according to sPolarityConventionthe.
Double_t GetBz(Double_t x, Double_t y, Double_t z) override
Z component.
Double_t GetBx(Double_t x, Double_t y, Double_t z) override
Virtual methods from FairField.
void getTPCRatIntegralCylindrical(const Double_t *rphiz, Double_t *b) const
void field(const math_utils::Point3D< double > xyz, double bxyz[3])
void MachineField(const Double_t *__restrict__ x, Double_t *__restrict__ b) const
const char * getBeamTypeText() const
Returns beam type in text form.
void field(const math_utils::Point3D< float > xyz, float bxyz[3])
void getTPCRatIntegral(const Double_t *xyz, Double_t *b) const
Method to calculate the integral_0^z of br,bt,bz.
void rescaleField(float l3Cur, float diCur, bool uniform, int convention=0)
void getTPCIntegralCylindrical(const Double_t *rphiz, Double_t *b) const
Method to calculate the integral_0^z of br,bt,bz in cylindrical coordinates ( -pi<phi<pi convention )
Char_t * getDataFileName() const
void setDataFileName(const Char_t *nm)
static MagneticField * createFieldMap(float l3Current=-30000., float diCurrent=-6000., Int_t convention=0, Bool_t uniform=kFALSE, float beamenergy=7000, const Char_t *btype="pp", const std::string path=std::string(gSystem->Getenv("VMCWORKDIR"))+std::string("/Common/maps/mfchebKGI_sym.root"))
void setFactorDipole(float fc=1.)
Sets the sign*scale of the current in the Dipole according to sPolarityConvention.
MagneticField & operator=(const MagneticField &src)
void AllowFastField(bool v=true)
allow fast field param
Double_t GetBy(Double_t x, Double_t y, Double_t z) override
Y component, avoid using since slow.
Double_t getBeamEnergy() const
void setBeamEnergy(float energy)
Double_t getCurrentDipole() const
void field(const float *__restrict__ point, float *__restrict__ bField)
Double_t getFactorSolenoid() const
Returns the sign*scale of the current in the Dipole according to sPolarityConventionthe.
Double_t getCurrentSolenoid() const
static Int_t getPolarityConvention()
void Field(const Double_t *__restrict__ point, Double_t *__restrict__ bField) override
MagFieldParam::BeamType_t getBeamType() const
MagFieldParam::BMap_t getMapType() const
void getTPCIntegral(const Double_t *xyz, Double_t *b) const
Method to calculate the integral_0^z of br,bt,bz.
void setParameterName(const Char_t *nm)
~MagneticField() override=default
Default destructor.
void Print(Option_t *opt) const override
Prints short or long info.
Char_t * getParameterName() const
MagneticField()
Default constructor.
void GetBxyz(const Double_t p[3], Double_t *b) override
3d field query alias for Alias Method to calculate the field at point xyz
void setFactorSolenoid(float fc=1.)
Sets the sign/scale of the current in the L3 according to sPolarityConvention.
void field(const double *__restrict__ point, double *__restrict__ bField)
MagneticWrapperChebyshev * getMeasuredMap() const
void CreateField()
real field creation is here
static MagneticField * createNominalField(int fld, bool uniform=false)
create field from rounded value, i.e. +-5 or +-2 kGauss
Double_t solenoidField() const
void initializeMachineField(MagFieldParam::BeamType_t btype, Double_t benergy)
Double_t Factor() const
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...