Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Common/Field/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions Common/Field/include/Field/FieldOriginBiasParam.h
Original file line number Diff line number Diff line change
@@ -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<FieldOriginBiasParam> {
double x = 0.;
double y = 0.;
double z = 0.;

O2ParamDef(FieldOriginBiasParam, "FieldOriginBias");
};

} // namespace field
} // end namespace o2

#endif
4 changes: 4 additions & 0 deletions Common/Field/include/Field/MagneticField.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace o2
namespace field
{
class MagneticWrapperChebyshev;
class FieldOriginBiasParam;
}
} // namespace o2
namespace o2
Expand Down Expand Up @@ -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<MagneticWrapperChebyshev> mMeasuredMap; //! Measured part of the field map
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions Common/Field/src/FieldLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions Common/Field/src/FieldOriginBiasParam.cxx
Original file line number Diff line number Diff line change
@@ -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);
33 changes: 27 additions & 6 deletions Common/Field/src/MagneticField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/// \author ruben.shahoyan@cern.ch

#include "Field/MagneticField.h"
#include "Field/FieldOriginBiasParam.h"
#include <TFile.h> // for TFile
#include <TPRegexp.h> // for TPRegexp
#include <TString.h> // for TString
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -145,8 +153,10 @@ MagneticField::MagneticField(const MagFieldParam& param)
/*
* Constructor for FairParam derived params
*/

setDataFileName(param.GetMapPath());
if (!gOriginBias) {
checkOriginBias();
}
CreateField();
}

Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
}