Skip to content

Commit 1e433db

Browse files
shahor02sawenzel
authored andcommitted
utility macro to init B-field and geometry produced by o2sim
1 parent 9bd6cdb commit 1e433db

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

macro/initSimGeomAndField.C

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#if !defined(__CLING__) || defined(__ROOTCLING__)
2+
#include <TFile.h>
3+
#include <TGeoGlobalMagField.h>
4+
#include "Field/MagneticField.h"
5+
#include "DataFormatsParameters/GRPObject.h"
6+
#include <string>
7+
#endif
8+
9+
10+
using o2field = o2::field::MagneticField;
11+
using GRP = o2::parameters::GRPObject;
12+
void initFieldFromGRP(const o2::parameters::GRPObject* grp);
13+
14+
int initSimGeomAndField(std::string geomFileName="O2geometry.root",
15+
std::string grpFileName="o2sim_grp.root",
16+
std::string geomName="FAIRGeom",
17+
std::string grpName="GRP")
18+
{
19+
printf("Loading geometry from %s\n",geomFileName.data());
20+
TFile flGeom(geomFileName.data());
21+
if ( flGeom.IsZombie() ) {
22+
return -1;
23+
}
24+
if ( !flGeom.Get(geomName.data()) ) {
25+
return -2;
26+
}
27+
28+
//
29+
printf("Loading field from GRP of %s\n",grpFileName.data());
30+
TFile flGRP(grpFileName.data());
31+
if ( flGRP.IsZombie() ) {
32+
return -10;
33+
}
34+
auto grp = static_cast<GRP*>(flGRP.GetObjectChecked(grpName.data(),
35+
GRP::Class()));
36+
if (!grp) {
37+
return -12;
38+
}
39+
grp->print();
40+
initFieldFromGRP(grp);
41+
return 0;
42+
}
43+
44+
void initFieldFromGRP(const GRP* grp)
45+
{
46+
if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
47+
if (TGeoGlobalMagField::Instance()->GetField()->TestBit(o2field::kOverrideGRP)) {
48+
printf("ExpertMode!!! GRP information will be ignored\n");
49+
printf("ExpertMode!!! Running with the externally locked B field\n");
50+
return;
51+
}
52+
else {
53+
printf("Destroying existing B field instance\n");
54+
delete TGeoGlobalMagField::Instance();
55+
}
56+
}
57+
auto fld = o2field::createFieldMap(grp->getL3Current(), grp->getDipoleCurrent());
58+
TGeoGlobalMagField::Instance()->SetField( fld );
59+
TGeoGlobalMagField::Instance()->Lock();
60+
printf("Running with the B field constructed out of GRP\n");
61+
printf("Access field via TGeoGlobalMagField::Instance()->Field(xyz,bxyz) or via\n");
62+
printf("auto o2field = static_cast<o2::field::MagneticField*>( TGeoGlobalMagField::Instance()->GetField() )\n");
63+
64+
}

0 commit comments

Comments
 (0)