From ab2223c6b38540d7c575ae9038d3ce4d398d9d19 Mon Sep 17 00:00:00 2001 From: shahoian Date: Mon, 6 Jul 2026 15:58:42 +0200 Subject: [PATCH] Possibility to bias magnetic field origin via env.var. O2_DPL_FIELDORIGINBIAS="FieldOriginBias.x=...;FieldOriginBias.y=...;FieldOriginBias.z=..." --- Common/Field/CMakeLists.txt | 2 + .../include/Field/FieldOriginBiasParam.h | 38 +++++++++++++++++++ Common/Field/include/Field/MagneticField.h | 4 ++ Common/Field/src/FieldLinkDef.h | 3 ++ Common/Field/src/FieldOriginBiasParam.cxx | 18 +++++++++ Common/Field/src/MagneticField.cxx | 33 +++++++++++++--- 6 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 Common/Field/include/Field/FieldOriginBiasParam.h create mode 100644 Common/Field/src/FieldOriginBiasParam.cxx diff --git a/Common/Field/CMakeLists.txt b/Common/Field/CMakeLists.txt index fd00d77accfd3..719e7bc3a6440 100644 --- a/Common/Field/CMakeLists.txt +++ b/Common/Field/CMakeLists.txt @@ -16,6 +16,7 @@ o2_add_library(Field src/MagFieldParam.cxx src/MagneticField.cxx src/MagneticWrapperChebyshev.cxx + src/FieldOriginBiasParam.cxx src/ALICE3MagneticField.cxx PUBLIC_LINK_LIBRARIES O2::MathUtils FairRoot::Base O2::CommonUtils) @@ -26,6 +27,7 @@ o2_target_root_dictionary(Field include/Field/MagFieldContFact.h include/Field/MagFieldFast.h include/Field/MagFieldFact.h + include/Field/FieldOriginBiasParam.h include/Field/ALICE3MagneticField.h) o2_add_test(MagneticField diff --git a/Common/Field/include/Field/FieldOriginBiasParam.h b/Common/Field/include/Field/FieldOriginBiasParam.h new file mode 100644 index 0000000000000..c7c815924c5f3 --- /dev/null +++ b/Common/Field/include/Field/FieldOriginBiasParam.h @@ -0,0 +1,38 @@ +// Copyright 2019-2026 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \author ruben.shahoyan@cern.ch + +/// parameters to bias the origin of the magnetic field + +#ifndef ALICEO2_FIELDORIGIN_BIAS_PARAM_H +#define ALICEO2_FIELDORIGIN_BIAS_PARAM_H + +#include "CommonUtils/ConfigurableParam.h" +#include "CommonUtils/ConfigurableParamHelper.h" + +namespace o2 +{ +namespace field +{ + +struct FieldOriginBiasParam : public o2::conf::ConfigurableParamHelper { + double x = 0.; + double y = 0.; + double z = 0.; + + O2ParamDef(FieldOriginBiasParam, "FieldOriginBias"); +}; + +} // namespace field +} // end namespace o2 + +#endif diff --git a/Common/Field/include/Field/MagneticField.h b/Common/Field/include/Field/MagneticField.h index d2639a902f3a9..7c95feacb8787 100644 --- a/Common/Field/include/Field/MagneticField.h +++ b/Common/Field/include/Field/MagneticField.h @@ -32,6 +32,7 @@ namespace o2 namespace field { class MagneticWrapperChebyshev; +class FieldOriginBiasParam; } } // namespace o2 namespace o2 @@ -249,6 +250,7 @@ class MagneticField : public FairField void setBeamType(MagFieldParam::BeamType_t type) { mBeamType = type; } void setBeamEnergy(float energy) { mBeamEnergy = energy; } + void checkOriginBias(); private: std::unique_ptr mMeasuredMap; //! Measured part of the field map @@ -273,6 +275,8 @@ class MagneticField : public FairField TNamed mParameterNames; ///< file and parameterization loaded + static const FieldOriginBiasParam* gOriginBias; + static const Double_t sSolenoidToDipoleZ; ///< conventional Z of transition from L3 to Dipole field static const UShort_t sPolarityConvention; ///< convention for the mapping of the curr.sign on main component sign diff --git a/Common/Field/src/FieldLinkDef.h b/Common/Field/src/FieldLinkDef.h index cd1b035341284..3571644096a73 100644 --- a/Common/Field/src/FieldLinkDef.h +++ b/Common/Field/src/FieldLinkDef.h @@ -22,4 +22,7 @@ #pragma link C++ class o2::field::MagFieldFast + ; #pragma link C++ class o2::field::ALICE3MagneticField + ; +#pragma link C++ class o2::field::FieldOriginBiasParam + ; +#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::field::FieldOriginBiasParam> + ; + #endif diff --git a/Common/Field/src/FieldOriginBiasParam.cxx b/Common/Field/src/FieldOriginBiasParam.cxx new file mode 100644 index 0000000000000..140b862fcdc07 --- /dev/null +++ b/Common/Field/src/FieldOriginBiasParam.cxx @@ -0,0 +1,18 @@ +// Copyright 2019-2026 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \author ruben.shahoyan@cern.ch + +/// parameters to bias the origin of the magnetic field + +#include "Field/FieldOriginBiasParam.h" + +O2ParamImpl(o2::field::FieldOriginBiasParam); diff --git a/Common/Field/src/MagneticField.cxx b/Common/Field/src/MagneticField.cxx index a6e07e2f12548..768e42bef6875 100644 --- a/Common/Field/src/MagneticField.cxx +++ b/Common/Field/src/MagneticField.cxx @@ -14,6 +14,7 @@ /// \author ruben.shahoyan@cern.ch #include "Field/MagneticField.h" +#include "Field/FieldOriginBiasParam.h" #include // for TFile #include // for TPRegexp #include // for TString @@ -27,6 +28,8 @@ using namespace o2::field; ClassImp(MagneticField); +const FieldOriginBiasParam* MagneticField::gOriginBias = nullptr; + const Double_t MagneticField::sSolenoidToDipoleZ = -700.; /// Explanation for polarity conventions: these are the mapping between the @@ -88,6 +91,9 @@ MagneticField::MagneticField() * Default constructor */ fType = 2; // flag non-constant field + if (!gOriginBias) { + checkOriginBias(); + } } 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 /* * Constructor for human readable params */ - setDataFileName(path.c_str()); + if (!gOriginBias) { + checkOriginBias(); + } CreateField(); } @@ -145,8 +153,10 @@ MagneticField::MagneticField(const MagFieldParam& param) /* * Constructor for FairParam derived params */ - setDataFileName(param.GetMapPath()); + if (!gOriginBias) { + checkOriginBias(); + } CreateField(); } @@ -261,12 +271,12 @@ Bool_t MagneticField::loadParameterization() return kTRUE; } -void MagneticField::Field(const Double_t* __restrict__ xyz, Double_t* __restrict__ b) +void MagneticField::Field(const Double_t* __restrict__ xyzExt, Double_t* __restrict__ b) { /* * query field value at point */ - + double xyz[3] = {xyzExt[0] - gOriginBias->x, xyzExt[1] - gOriginBias->y, xyzExt[2] - gOriginBias->z}; // b[0]=b[1]=b[2]=0.0; if (mFastField && mFastField->Field(xyz, b)) { return; @@ -288,12 +298,12 @@ void MagneticField::Field(const Double_t* __restrict__ xyz, Double_t* __restrict } } -Double_t MagneticField::getBz(const Double_t* xyz) const +Double_t MagneticField::getBz(const Double_t* xyzExt) const { /* * query field Bz component at point */ - + double xyz[3] = {xyzExt[0] - gOriginBias->x, xyzExt[1] - gOriginBias->y, xyzExt[2] - gOriginBias->z}; if (mFastField) { double bz = 0; if (mFastField->GetBz(xyz, bz)) { @@ -728,3 +738,14 @@ void MagneticField::AllowFastField(bool v) mFastField.reset(nullptr); } } + +//_____________________________________________________________________________ +void MagneticField::checkOriginBias() +{ + // posibility to globally bias all data members with the proper env.var + if (const auto* biasString = std::getenv("O2_DPL_FIELDORIGINBIAS"); biasString && *biasString) { + o2::conf::ConfigurableParam::updateFromString(biasString); + } + gOriginBias = &FieldOriginBiasParam::Instance(); + LOGP(info, "Field origin is set to: XYZ: {:.4f},{:.4f},{:.4f}", gOriginBias->x, gOriginBias->y, gOriginBias->z); +}