forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitSimGeomAndField.C
More file actions
78 lines (70 loc) · 2.71 KB
/
initSimGeomAndField.C
File metadata and controls
78 lines (70 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <FairLogger.h>
#include <TFile.h>
#include <TGeoGlobalMagField.h>
#include <string>
#include "DataFormatsParameters/GRPObject.h"
#include "Field/MagneticField.h"
#include "DetectorsBase/GeometryManager.h"
#endif
int initFieldFromGRP(const o2::parameters::GRPObject* grp);
int initFieldFromGRP(const std::string grpFileName = "o2sim_grp.root", std::string grpName = "GRP");
int initSimGeom(std::string geom = "");
int initSimGeomAndField(std::string geom = "", std::string grpFileName = "o2sim_grp.root", std::string grpName = "GRP")
{
int res = 0;
res = initSimGeom(geom);
if (res) {
return res;
}
res = initFieldFromGRP(grpFileName, grpName);
return res;
}
int initSimGeom(std::string geom)
{
/// load geometry from the file
o2::base::GeometryManager::loadGeometry(geom);
return 0;
}
//____________________________________________________________
int initFieldFromGRP(const std::string grpFileName, std::string grpName)
{
/// load grp and init magnetic field
std::cout << "Loading field from GRP of " << grpFileName << std::endl;
TFile flGRP(grpFileName.data());
if (flGRP.IsZombie()) {
std::cout << "Failed to open " << grpFileName << std::endl;
return -10;
}
auto grp =
static_cast<o2::parameters::GRPObject*>(flGRP.GetObjectChecked(grpName.data(), o2::parameters::GRPObject::Class()));
if (!grp) {
std::cout << "Did not find GRP object named " << grpName << std::endl;
return -12;
}
grp->print();
return initFieldFromGRP(grp);
}
//____________________________________________________________
int initFieldFromGRP(const o2::parameters::GRPObject* grp)
{
/// init mag field from GRP data and attach it to TGeoGlobalMagField
if (TGeoGlobalMagField::Instance()->IsLocked()) {
if (TGeoGlobalMagField::Instance()->GetField()->TestBit(o2::field::MagneticField::kOverrideGRP)) {
std::cout << "ExpertMode!!! GRP information will be ignored" << std::endl;
std::cout << "ExpertMode!!! Running with the externally locked B field" << std::endl;
return 0;
} else {
std::cout << "Destroying existing B field instance" << std::endl;
delete TGeoGlobalMagField::Instance();
}
}
auto fld = o2::field::MagneticField::createFieldMap(grp->getL3Current(), grp->getDipoleCurrent());
TGeoGlobalMagField::Instance()->SetField(fld);
TGeoGlobalMagField::Instance()->Lock();
std::cout << "Running with the B field constructed out of GRP" << std::endl;
std::cout << "Access field via TGeoGlobalMagField::Instance()->Field(xyz,bxyz) or via" << std::endl;
std::cout << "auto o2field = static_cast<o2::field::MagneticField*>( TGeoGlobalMagField::Instance()->GetField() )"
<< std::endl;
return 0;
}