Skip to content

Commit 6ddb56c

Browse files
committed
Init mag.field before initializing generator
1 parent 594ae1d commit 6ddb56c

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

run/O2PrimaryServerDevice.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <SimConfig/SimConfig.h>
2828
#include <CommonUtils/ConfigurableParam.h>
2929
#include <CommonUtils/RngHelper.h>
30+
#include "Field/MagneticField.h"
31+
#include <TGeoGlobalMagField.h>
3032
#include <typeinfo>
3133
#include <thread>
3234
#include <TROOT.h>
@@ -60,6 +62,31 @@ class O2PrimaryServerDevice final : public FairMQDevice
6062
TStopwatch timer;
6163
timer.Start();
6264
auto& conf = o2::conf::SimConfig::Instance();
65+
66+
// init magnetic field as it might be needed by the generator
67+
int fld = conf.getConfigData().mField, fldAbs = std::abs(fld);
68+
float fldCoeff;
69+
o2::field::MagFieldParam::BMap_t fldType;
70+
switch (fldAbs) {
71+
case 5:
72+
fldType = o2::field::MagFieldParam::k5kG;
73+
fldCoeff = fld > 0 ? 1. : -1;
74+
break;
75+
case 0:
76+
fldType = o2::field::MagFieldParam::k5kG;
77+
fldCoeff = 0;
78+
break;
79+
case 2:
80+
fldType = o2::field::MagFieldParam::k2kG;
81+
fldCoeff = fld > 0 ? 1. : -1;
82+
break;
83+
default:
84+
LOG(FATAL) << "Field option " << fld << " is not supported, use +-2, +-5 or 0";
85+
};
86+
auto field = new o2::field::MagneticField("Maps", "Maps", fldCoeff, fldCoeff, fldType);
87+
TGeoGlobalMagField::Instance()->SetField(field);
88+
TGeoGlobalMagField::Instance()->Lock();
89+
6390
o2::eventgen::GeneratorFactory::setPrimaryGenerator(conf, &mPrimGen);
6491
mPrimGen.SetEvent(&mEventHeader);
6592

0 commit comments

Comments
 (0)