1414// / \author ruben.shahoyan@cern.ch
1515
1616#include " Field/MagneticField.h"
17+ #include " Field/FieldOriginBiasParam.h"
1718#include < TFile.h> // for TFile
1819#include < TPRegexp.h> // for TPRegexp
1920#include < TString.h> // for TString
@@ -27,6 +28,8 @@ using namespace o2::field;
2728
2829ClassImp (MagneticField);
2930
31+ const FieldOriginBiasParam* MagneticField::gOriginBias = nullptr ;
32+
3033const Double_t MagneticField::sSolenoidToDipoleZ = -700 .;
3134
3235// / Explanation for polarity conventions: these are the mapping between the
@@ -88,6 +91,9 @@ MagneticField::MagneticField()
8891 * Default constructor
8992 */
9093 fType = 2 ; // flag non-constant field
94+ if (!gOriginBias ) {
95+ checkOriginBias ();
96+ }
9197}
9298
9399MagneticField::MagneticField (const char * name, const char * title, Double_t factorSol, Double_t factorDip,
@@ -116,8 +122,10 @@ MagneticField::MagneticField(const char* name, const char* title, Double_t facto
116122 /*
117123 * Constructor for human readable params
118124 */
119-
120125 setDataFileName (path.c_str ());
126+ if (!gOriginBias ) {
127+ checkOriginBias ();
128+ }
121129 CreateField ();
122130}
123131
@@ -145,8 +153,10 @@ MagneticField::MagneticField(const MagFieldParam& param)
145153 /*
146154 * Constructor for FairParam derived params
147155 */
148-
149156 setDataFileName (param.GetMapPath ());
157+ if (!gOriginBias ) {
158+ checkOriginBias ();
159+ }
150160 CreateField ();
151161}
152162
@@ -261,12 +271,12 @@ Bool_t MagneticField::loadParameterization()
261271 return kTRUE ;
262272}
263273
264- void MagneticField::Field (const Double_t* __restrict__ xyz , Double_t* __restrict__ b)
274+ void MagneticField::Field (const Double_t* __restrict__ xyzExt , Double_t* __restrict__ b)
265275{
266276 /*
267277 * query field value at point
268278 */
269-
279+ double xyz[ 3 ] = {xyzExt[ 0 ] + gOriginBias -> x , xyzExt[ 1 ] + gOriginBias -> y , xyzExt[ 2 ] + gOriginBias -> z };
270280 // b[0]=b[1]=b[2]=0.0;
271281 if (mFastField && mFastField ->Field (xyz, b)) {
272282 return ;
@@ -288,12 +298,12 @@ void MagneticField::Field(const Double_t* __restrict__ xyz, Double_t* __restrict
288298 }
289299}
290300
291- Double_t MagneticField::getBz (const Double_t* xyz ) const
301+ Double_t MagneticField::getBz (const Double_t* xyzExt ) const
292302{
293303 /*
294304 * query field Bz component at point
295305 */
296-
306+ double xyz[ 3 ] = {xyzExt[ 0 ] + gOriginBias -> x , xyzExt[ 1 ] + gOriginBias -> y , xyzExt[ 2 ] + gOriginBias -> z };
297307 if (mFastField ) {
298308 double bz = 0 ;
299309 if (mFastField ->GetBz (xyz, bz)) {
@@ -728,3 +738,14 @@ void MagneticField::AllowFastField(bool v)
728738 mFastField .reset (nullptr );
729739 }
730740}
741+
742+ // _____________________________________________________________________________
743+ void MagneticField::checkOriginBias ()
744+ {
745+ // posibility to globally bias all data members with the proper env.var
746+ if (const auto * biasString = std::getenv (" O2_DPL_FIELDORIGINBIAS" ); biasString && *biasString) {
747+ o2::conf::ConfigurableParam::updateFromString (biasString);
748+ }
749+ gOriginBias = &FieldOriginBiasParam::Instance ();
750+ LOGP (info, " Field origin is biased by: XYZ: {:.4f},{:.4f},{:.4f}" , gOriginBias ->x , gOriginBias ->y , gOriginBias ->z );
751+ }
0 commit comments