22#include <fairlogger/Logger.h>
30const Double_t MagneticField::sSolenoidToDipoleZ = -700.;
68 mMeasuredMap(nullptr),
74 mDefaultIntegration(0),
76 mMultipicativeFactorSolenoid(1.),
77 mMultipicativeFactorDipole(1.),
79 mDipoleOnOffFlag(kFALSE),
80 mQuadrupoleGradient(0),
82 mCompensatorField2C(0),
83 mCompensatorField1A(0),
84 mCompensatorField2A(0),
85 mParameterNames(
"",
"")
98 Double_t fmax,
const std::string
path)
100 mMeasuredMap(nullptr),
106 mDefaultIntegration(integ),
108 mMultipicativeFactorSolenoid(1.),
109 mMultipicativeFactorDipole(1.),
111 mDipoleOnOffFlag(factorDip == 0.),
112 mQuadrupoleGradient(0),
114 mCompensatorField2C(0),
115 mCompensatorField1A(0),
116 mCompensatorField2A(0),
117 mParameterNames(
"",
"")
133 float fldCoeffL3, fldCoeffDip;
136 fldCoeffL3 =
float(fld) / 5.;
137 fldCoeffDip = fld > 0 ? 1. : -1;
140 switch (std::abs(fld)) {
143 fldCoeffL3 = fldCoeffDip = fld > 0 ? 1. : -1;
147 fldCoeffL3 = fldCoeffDip = 0;
151 fldCoeffL3 = fldCoeffDip = fld > 0 ? 1. : -1;
154 LOG(fatal) <<
"Field option " << fld <<
" is not supported, use +-2, +-5 or 0 or <int_kilogauss>U";
169 if (mDefaultIntegration < 0 || mDefaultIntegration > 2) {
170 LOG(warning) <<
"MagneticField::CreateField: Invalid magnetic field flag: " << mDefaultIntegration
171 <<
"; Helix tracking chosen instead";
172 mDefaultIntegration = 2;
174 if (mDefaultIntegration == 0) {
187 LOG(info) <<
"MagneticField::CreateField: Maximim possible beam energy for requested beam is assumed";
190 const char* parname =
nullptr;
193 parname = mDipoleOnOffFlag ?
"Sol12_Dip0_Hole" :
"Sol12_Dip6_Hole";
195 parname = mDipoleOnOffFlag ?
"Sol30_Dip0_Hole" :
"Sol30_Dip6_Hole";
197 parname =
"Sol30_Dip6_Uniform";
199 LOG(fatal) <<
"MagneticField::CreateField: Unknown field identifier " << mMapType <<
" is requested\n";
211 double xyz[3] = {0., 0., 0.};
212 mSolenoid =
getBz(xyz);
228 gSystem->ExpandPathName(fname);
229 TFile*
file = TFile::Open(fname);
231 LOG(fatal) <<
"MagneticField::loadParameterization: Failed to open magnetic field data file " << fname <<
"\n";
237 LOG(fatal) <<
"MagneticField::loadParameterization: Did not find field " <<
getParameterName() <<
" in " << fname
250 double xyz[3] = {xyzExt[0] - gOriginBias->
x, xyzExt[1] - gOriginBias->
y, xyzExt[2] - gOriginBias->
z};
252 if (mFastField && mFastField->Field(xyz,
b)) {
256 if (mMeasuredMap && xyz[2] > mMeasuredMap->getMinZ() && xyz[2] < mMeasuredMap->getMaxZ()) {
257 mMeasuredMap->Field(xyz,
b);
258 if (xyz[2] > sSolenoidToDipoleZ || mDipoleOnOffFlag) {
259 for (
int i = 3;
i--;) {
260 b[
i] *= mMultipicativeFactorSolenoid;
263 for (
int i = 3;
i--;) {
264 b[
i] *= mMultipicativeFactorDipole;
277 double xyz[3] = {xyzExt[0] - gOriginBias->
x, xyzExt[1] - gOriginBias->
y, xyzExt[2] - gOriginBias->
z};
280 if (mFastField->GetBz(xyz, bz)) {
284 if (mMeasuredMap && xyz[2] > mMeasuredMap->getMinZ() && xyz[2] < mMeasuredMap->getMaxZ()) {
285 double bz = mMeasuredMap->getBz(xyz);
286 return (xyz[2] > sSolenoidToDipoleZ || mDipoleOnOffFlag) ? bz * mMultipicativeFactorSolenoid
287 : bz * mMultipicativeFactorDipole;
300 if (
src.mMeasuredMap) {
303 SetName(
src.GetName());
304 mSolenoid =
src.mSolenoid;
305 mBeamType =
src.mBeamType;
306 mBeamEnergy =
src.mBeamEnergy;
307 mDefaultIntegration =
src.mDefaultIntegration;
308 mPrecisionInteg =
src.mPrecisionInteg;
309 mMultipicativeFactorSolenoid =
src.mMultipicativeFactorSolenoid;
310 mMultipicativeFactorDipole =
src.mMultipicativeFactorDipole;
311 mMaxField =
src.mMaxField;
312 mDipoleOnOffFlag =
src.mDipoleOnOffFlag;
313 mParameterNames =
src.mParameterNames;
322 mQuadrupoleGradient = mDipoleField = mCompensatorField2C = mCompensatorField1A = mCompensatorField2A = 0.;
326 double rigScale = benergy / 7000.;
329 rigScale *= 208. / 82.;
334 mQuadrupoleGradient = 22.0002 * rigScale;
335 mDipoleField = 37.8781 * rigScale;
338 mCompensatorField2C = -9.6980;
340 mCompensatorField1A = -13.2247;
341 mCompensatorField2A = 11.7905;
348 const Double_t kBComp1CZ = 1075., kBComp1hDZ = 260. / 2., kBComp1SqR = 4.0 * 4.0;
349 const Double_t kBComp2CZ = 2049., kBComp2hDZ = 153. / 2., kBComp2SqR = 4.5 * 4.5;
351 const Double_t kTripQ1CZ = 2615., kTripQ1hDZ = 637. / 2., kTripQ1SqR = 3.5 * 3.5;
352 const Double_t kTripQ2CZ = 3480., kTripQ2hDZ = 550. / 2., kTripQ2SqR = 3.5 * 3.5;
353 const Double_t kTripQ3CZ = 4130., kTripQ3hDZ = 550. / 2., kTripQ3SqR = 3.5 * 3.5;
354 const Double_t kTripQ4CZ = 5015., kTripQ4hDZ = 637. / 2., kTripQ4SqR = 3.5 * 3.5;
356 const Double_t kDip1CZ = 6310.8, kDip1hDZ = 945. / 2., kDip1SqRC = 4.5 * 4.5, kDip1SqRA = 3.375 * 3.375;
357 const Double_t kDip2CZ = 12640.3, kDip2hDZ = 945. / 2., kDip2SqRC = 4.5 * 4.5, kDip2SqRA = 3.75 * 3.75;
358 const Double_t kDip2DXC = 9.7, kDip2DXA = 9.4;
360 double rad2 =
x[0] *
x[0] +
x[1] *
x[1];
362 b[0] =
b[1] =
b[2] = 0;
366 if (TMath::Abs(
x[2] + kBComp2CZ) < kBComp2hDZ && rad2 < kBComp2SqR) {
367 b[0] = mCompensatorField2C * mMultipicativeFactorDipole;
368 }
else if (TMath::Abs(
x[2] + kTripQ1CZ) < kTripQ1hDZ && rad2 < kTripQ1SqR) {
369 b[0] = mQuadrupoleGradient *
x[1];
370 b[1] = mQuadrupoleGradient *
x[0];
371 }
else if (TMath::Abs(
x[2] + kTripQ2CZ) < kTripQ2hDZ && rad2 < kTripQ2SqR) {
372 b[0] = -mQuadrupoleGradient *
x[1];
373 b[1] = -mQuadrupoleGradient *
x[0];
374 }
else if (TMath::Abs(
x[2] + kTripQ3CZ) < kTripQ3hDZ && rad2 < kTripQ3SqR) {
375 b[0] = -mQuadrupoleGradient *
x[1];
376 b[1] = -mQuadrupoleGradient *
x[0];
377 }
else if (TMath::Abs(
x[2] + kTripQ4CZ) < kTripQ4hDZ && rad2 < kTripQ4SqR) {
378 b[0] = mQuadrupoleGradient *
x[1];
379 b[1] = mQuadrupoleGradient *
x[0];
380 }
else if (TMath::Abs(
x[2] + kDip1CZ) < kDip1hDZ && rad2 < kDip1SqRC) {
382 }
else if (TMath::Abs(
x[2] + kDip2CZ) < kDip2hDZ && rad2 < kDip2SqRC) {
383 double dxabs = TMath::Abs(
x[0]) - kDip2DXC;
384 if ((dxabs * dxabs +
x[1] *
x[1]) < kDip2SqRC) {
385 b[1] = -mDipoleField;
392 if (TMath::Abs(
x[2] - kBComp1CZ) < kBComp1hDZ && rad2 < kBComp1SqR) {
394 b[0] = mCompensatorField1A * mMultipicativeFactorDipole;
397 if (TMath::Abs(
x[2] - kBComp2CZ) < kBComp2hDZ && rad2 < kBComp2SqR) {
398 b[0] = mCompensatorField2A * mMultipicativeFactorDipole;
399 }
else if (TMath::Abs(
x[2] - kTripQ1CZ) < kTripQ1hDZ && rad2 < kTripQ1SqR) {
400 b[0] = -mQuadrupoleGradient *
x[1];
401 b[1] = -mQuadrupoleGradient *
x[0];
402 }
else if (TMath::Abs(
x[2] - kTripQ2CZ) < kTripQ2hDZ && rad2 < kTripQ2SqR) {
403 b[0] = mQuadrupoleGradient *
x[1];
404 b[1] = mQuadrupoleGradient *
x[0];
405 }
else if (TMath::Abs(
x[2] - kTripQ3CZ) < kTripQ3hDZ && rad2 < kTripQ3SqR) {
406 b[0] = mQuadrupoleGradient *
x[1];
407 b[1] = mQuadrupoleGradient *
x[0];
408 }
else if (TMath::Abs(
x[2] - kTripQ4CZ) < kTripQ4hDZ && rad2 < kTripQ4SqR) {
409 b[0] = -mQuadrupoleGradient *
x[1];
410 b[1] = -mQuadrupoleGradient *
x[0];
411 }
else if (TMath::Abs(
x[2] - kDip1CZ) < kDip1hDZ && rad2 < kDip1SqRA) {
412 b[1] = -mDipoleField;
413 }
else if (TMath::Abs(
x[2] - kDip2CZ) < kDip2hDZ && rad2 < kDip2SqRA) {
414 double dxabs = TMath::Abs(
x[0]) - kDip2DXA;
415 if ((dxabs * dxabs +
x[1] *
x[1]) < kDip2SqRA) {
424 b[0] =
b[1] =
b[2] = 0.0;
426 mMeasuredMap->getTPCIntegral(xyz,
b);
427 for (
int i = 3;
i--;) {
428 b[
i] *= mMultipicativeFactorSolenoid;
435 b[0] =
b[1] =
b[2] = 0.0;
437 mMeasuredMap->getTPCRatIntegral(xyz,
b);
444 b[0] =
b[1] =
b[2] = 0.0;
446 mMeasuredMap->getTPCIntegralCylindrical(rphiz,
b);
447 for (
int i = 3;
i--;) {
448 b[
i] *= mMultipicativeFactorSolenoid;
455 b[0] =
b[1] =
b[2] = 0.0;
457 mMeasuredMap->getTPCRatIntegralCylindrical(rphiz,
b);
464 switch (sPolarityConvention) {
466 mMultipicativeFactorSolenoid = -fc;
469 mMultipicativeFactorSolenoid = -fc;
472 mMultipicativeFactorSolenoid = fc;
482 switch (sPolarityConvention) {
484 mMultipicativeFactorDipole = fc;
487 mMultipicativeFactorDipole = -fc;
490 mMultipicativeFactorDipole = fc;
497 switch (sPolarityConvention) {
499 return -mMultipicativeFactorSolenoid;
501 return -mMultipicativeFactorSolenoid;
503 return mMultipicativeFactorSolenoid;
509 switch (sPolarityConvention) {
511 return mMultipicativeFactorDipole;
513 return -mMultipicativeFactorDipole;
515 return mMultipicativeFactorDipole;
522 float sclL3 = l3Cur, sclDip = diCur;
524 if (map != mMapType) {
525 LOGP(fatal,
"Provided L3current={} DipCurrent={} uniform={} leads to map type {}, incompatible with loaded {}", l3Cur, diCur, uniform, (
int)map, (
int)mMapType);
529 LOGP(info,
"Updating magnetic field: L3current={} DipCurrent={} uniform={}", l3Cur, diCur, uniform);
535 const float l3NominalCurrent1 = 30000.f;
536 const float l3NominalCurrent2 = 12000.f;
537 const float diNominalCurrent = 6000.f;
539 const float tolerance = 0.03;
540 const float zero = 77.f;
544 float l3sav = l3, dipsav = dip;
546 float l3Pol = l3 > 0 ? 1 : -1;
547 float diPol = dip > 0 ? 1 : -1;
550 dip = TMath::Abs(dip);
551 static bool overrideL3 = std::getenv(
"O2_OVERRIDE_L3_CURRENT") !=
nullptr;
552 static bool overrideDIP = std::getenv(
"O2_OVERRIDE_DIPOLE_CURRENT") !=
nullptr;
553 static bool warnL3Done =
false, warnDipDone =
false, warnPolarityDone =
false;
555 if (TMath::Abs((sclDip = dip / diNominalCurrent) - 1.) > tolerance && !uniform) {
560 LOG(fatal) <<
"MagneticField::createFieldMap: Wrong dipole current (" << dipsav <<
" A)!";
563 LOGP(
error,
"Dipole current was overridden to unsupported value {}", dipsav);
573 sclL3 = l3 / l3NominalCurrent1;
575 if (TMath::Abs((sclL3 = l3 / l3NominalCurrent1) - 1.) < tolerance) {
577 }
else if (TMath::Abs((sclL3 = l3 / l3NominalCurrent2) - 1.) < tolerance) {
579 }
else if (l3 <= zero && dip <= zero) {
585 LOG(fatal) <<
"MagneticField::createFieldMap: Wrong L3 current (" << l3sav <<
" A)!";
588 LOGP(
error,
"L3 current was overridden to unsupported value {}", l3sav);
592 sclL3 = l3 / l3NominalCurrent1;
598 ((convention ==
kConvLHC && l3Pol != diPol) || (convention ==
kConvDCS2008 && l3Pol == diPol))) {
599 if (overrideL3 || overrideDIP) {
600 if (!warnPolarityDone) {
601 LOG(
error) <<
"Overriden currents have wrong combination for L3/Dipole polarities ("
602 << (l3Pol > 0 ?
'+' :
'-') <<
"/" << (diPol > 0 ?
'+' :
'-') <<
") for convention "
604 warnPolarityDone =
true;
607 LOG(fatal) <<
"MagneticField::createFieldMap: Wrong combination for L3/Dipole polarities ("
608 << (l3Pol > 0 ?
'+' :
'-') <<
"/" << (diPol > 0 ?
'+' :
'-') <<
") for convention "
613 l3 = (l3Pol < 0) ? -sclL3 : sclL3;
614 dip = (diPol < 0) ? -sclDip : sclDip;
619 float beamenergy,
const Char_t* beamtype,
const std::string
path)
621 float sclL3 = l3Cur, sclDip = diCur;
624 TString btypestr = beamtype;
626 TPRegexp protonBeam(R
"((proton|p)\s*-?\s*\1)");
627 TPRegexp ionBeam(R"((lead|pb|ion|a|A)\s*-?\s*\1)");
628 TPRegexp protonionBeam(R"((proton|p)\s*-?\s*(lead|pb|ion|a|A))");
629 TPRegexp ionprotonBeam(R"((lead|pb|ion|a|A)\s*-?\s*(proton|p))");
630 if (btypestr.Contains(ionBeam)) {
632 }
else if (btypestr.Contains(protonBeam)) {
634 }
else if (btypestr.Contains(protonionBeam)) {
636 }
else if (btypestr.Contains(ionprotonBeam)) {
639 LOG(info) <<
"Assume no LHC magnet field for the beam type " << beamtype;
642 snprintf(ttl, 79,
"L3: %+5d Dip: %+4d kA; %s | Polarities in %s convention", (
int)TMath::Sign(l3Cur,
float(sclL3)),
643 (
int)TMath::Sign(diCur,
float(sclDip)), uniform ?
" Constant" :
"",
644 convention ==
kConvLHC ?
"LHC" :
"DCS2008");
650 return new MagneticField(
"MagneticFieldMap", ttl, sclL3, sclDip, map, btype, beamenergy, 2, 10.,
path);
655 const char* beamNA =
"No Beam";
656 const char* beamPP =
"p-p";
657 const char* beamPbPb =
"A-A";
658 const char* beamPPb =
"p-A";
659 const char* beamPbP =
"A-p";
679 LOG(info) <<
"MagneticField::Print: " << GetName() <<
":" << GetTitle();
682 << (mDipoleOnOffFlag ?
"OFF" :
"ON") <<
" (" <<
getFactorDipole() <<
") "
684 if (opts.Contains(
"a")) {
685 LOG(info) <<
"MagneticField::Print: Machine B fields for " <<
getBeamTypeText() <<
" beam (" << mBeamEnergy
686 <<
" GeV): QGrad: " << mQuadrupoleGradient <<
" Dipole: " << mDipoleField;
699 mFastField.reset(
nullptr);
707 if (
const auto* biasString = std::getenv(
"O2_DPL_FIELDORIGINBIAS"); biasString && *biasString) {
711 LOGP(info,
"Field origin is set to: XYZ: {:.4f},{:.4f},{:.4f}", gOriginBias->
x, gOriginBias->
y, gOriginBias->
z);
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
configStandalone Reconstruction rec_tpc float
char error[CURL_ERROR_SIZE]
Definition of the MagF class.
static const FieldOriginBiasParam & Instance()
static void updateFromString(std::string const &)
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.
void getTPCRatIntegralCylindrical(const Double_t *rphiz, Double_t *b) const
void MachineField(const Double_t *__restrict__ x, Double_t *__restrict__ b) const
const char * getBeamTypeText() const
Returns beam type in text form.
Bool_t loadParameterization()
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 getFactorSolenoid() const
Returns the sign*scale of the current in the Dipole according to sPolarityConventionthe.
static Int_t getPolarityConvention()
void Field(const Double_t *__restrict__ point, Double_t *__restrict__ bField) override
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)
void Print(Option_t *opt) const override
Prints short or long info.
Char_t * getParameterName() const
MagneticField()
Default constructor.
void setFactorSolenoid(float fc=1.)
Sets the sign/scale of the current in the L3 according to sPolarityConvention.
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
void initializeMachineField(MagFieldParam::BeamType_t btype, Double_t benergy)
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
GLsizei const GLchar *const * path
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"