Skip to content

Commit ea8c6d2

Browse files
committed
Possibility to bias magnetic field origin via env.var.
O2_DPL_FIELDORIGINBIAS="FieldOriginBias.x=...;FieldOriginBias.y=...;FieldOriginBias.z=..."
1 parent bd18612 commit ea8c6d2

6 files changed

Lines changed: 92 additions & 6 deletions

File tree

Common/Field/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ o2_add_library(Field
1616
src/MagFieldParam.cxx
1717
src/MagneticField.cxx
1818
src/MagneticWrapperChebyshev.cxx
19+
src/FieldOriginBiasParam.cxx
1920
src/ALICE3MagneticField.cxx
2021
PUBLIC_LINK_LIBRARIES O2::MathUtils FairRoot::Base O2::CommonUtils)
2122

@@ -26,6 +27,7 @@ o2_target_root_dictionary(Field
2627
include/Field/MagFieldContFact.h
2728
include/Field/MagFieldFast.h
2829
include/Field/MagFieldFact.h
30+
include/Field/FieldOriginBiasParam.h
2931
include/Field/ALICE3MagneticField.h)
3032

3133
o2_add_test(MagneticField
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2019-2026 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+
12+
/// \author ruben.shahoyan@cern.ch
13+
14+
/// parameters to bias the origin of the magnetic field
15+
16+
#ifndef ALICEO2_FIELDORIGIN_BIAS_PARAM_H
17+
#define ALICEO2_FIELDORIGIN_BIAS_PARAM_H
18+
19+
#include "CommonUtils/ConfigurableParam.h"
20+
#include "CommonUtils/ConfigurableParamHelper.h"
21+
22+
namespace o2
23+
{
24+
namespace field
25+
{
26+
27+
struct FieldOriginBiasParam : public o2::conf::ConfigurableParamHelper<FieldOriginBiasParam> {
28+
double x = 0.;
29+
double y = 0.;
30+
double z = 0.;
31+
32+
O2ParamDef(FieldOriginBiasParam, "FieldOriginBias");
33+
};
34+
35+
} // namespace field
36+
} // end namespace o2
37+
38+
#endif

Common/Field/include/Field/MagneticField.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace o2
3232
namespace field
3333
{
3434
class MagneticWrapperChebyshev;
35+
class FieldOriginBiasParam;
3536
}
3637
} // namespace o2
3738
namespace o2
@@ -249,6 +250,7 @@ class MagneticField : public FairField
249250
void setBeamType(MagFieldParam::BeamType_t type) { mBeamType = type; }
250251

251252
void setBeamEnergy(float energy) { mBeamEnergy = energy; }
253+
void checkOriginBias();
252254

253255
private:
254256
std::unique_ptr<MagneticWrapperChebyshev> mMeasuredMap; //! Measured part of the field map
@@ -273,6 +275,8 @@ class MagneticField : public FairField
273275

274276
TNamed mParameterNames; ///< file and parameterization loaded
275277

278+
static const FieldOriginBiasParam* gOriginBias;
279+
276280
static const Double_t sSolenoidToDipoleZ; ///< conventional Z of transition from L3 to Dipole field
277281
static const UShort_t sPolarityConvention; ///< convention for the mapping of the curr.sign on main component sign
278282

Common/Field/src/FieldLinkDef.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
#pragma link C++ class o2::field::MagFieldFast + ;
2323
#pragma link C++ class o2::field::ALICE3MagneticField + ;
2424

25+
#pragma link C++ class o2::field::FieldOriginBiasParam + ;
26+
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::field::FieldOriginBiasParam> + ;
27+
2528
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2019-2026 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+
12+
/// \author ruben.shahoyan@cern.ch
13+
14+
/// parameters to bias the origin of the magnetic field
15+
16+
#include "Field/FieldOriginBiasParam.h"
17+
18+
O2ParamImpl(o2::field::FieldOriginBiasParam);

Common/Field/src/MagneticField.cxx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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

2829
ClassImp(MagneticField);
2930

31+
const FieldOriginBiasParam* MagneticField::gOriginBias = nullptr;
32+
3033
const 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

9399
MagneticField::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

Comments
 (0)