File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535#include < filesystem>
3636#include < CommonUtils/FileSystemUtils.h>
3737#include " SimConfig/GlobalProcessCutSimParam.h"
38+ #include < FairRunSim.h>
39+ #include < FairField.h> // full type: FairField derives from TVirtualMagField
40+ #include < TVirtualMC.h>
3841#include " DetectorsBase/GeometryManagerParam.h"
3942#include < TGeoParallelWorld.h>
4043#include < TGeoVolume.h>
@@ -124,6 +127,23 @@ void O2MCApplicationBase::PreTrack()
124127
125128void O2MCApplicationBase::ConstructGeometry ()
126129{
130+ // The transport engine constructs the geometry from inside its own
131+ // constructor, long before FairMCApplication::InitMC() attaches the magnetic
132+ // field to it. The media built below read the field through
133+ // Detector::initFieldTrackingParams(), so without this they all silently fall
134+ // back to hardcoded defaults. The run has known the field since
135+ // build_geometry.C, which runs before Init() -- hand it over now.
136+ if (auto * vmc = TVirtualMC::GetMC (); vmc != nullptr && vmc->GetMagField () == nullptr ) {
137+ auto * run = FairRunSim::Instance ();
138+ if (run != nullptr && run->GetField () != nullptr ) {
139+ vmc->SetMagField (run->GetField ());
140+ LOG (info) << " Magnetic field attached to the engine before media creation" ;
141+ } else {
142+ LOG (warn) << " No magnetic field available at geometry construction; media "
143+ " will be initialised with default tracking parameters" ;
144+ }
145+ }
146+
127147 // fill the mapping
128148 mModIdToName .clear ();
129149 o2::detectors::DetID::mask_t dmask{};
You can’t perform that action at this time.
0 commit comments