Skip to content

Commit 18a680c

Browse files
aphecetchesawenzel
authored andcommitted
Allow the creation of a(n almost) full geometry w/o a prior VMC instance (#1113)
* Allow the creation of a(n almost) full geometry without a prior VMC instance. Whenever a VMC instance is not present, allow to use direct TGeo constructs for material/medium construction. This allows to perform standalone tests without having to instantiate simulation.
1 parent 7069ede commit 18a680c

3 files changed

Lines changed: 80 additions & 34 deletions

File tree

Detectors/Base/src/Detector.cxx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include "Field/MagneticField.h"
1919
#include "TString.h" // for TString
2020

21-
using std::endl;
2221
using std::cout;
22+
using std::endl;
2323
using std::fstream;
2424
using std::ios;
2525
using std::ostream;
@@ -95,19 +95,21 @@ void Detector::defineLayerTurbo(Int_t nlay, Double_t phi0, Double_t r, Int_t nla
9595

9696
void Detector::initFieldTrackingParams(int& integration, float& maxfield)
9797
{
98-
auto vmc = TVirtualMC::GetMC();
99-
auto field = vmc->GetMagField();
10098
// set reasonable default values
10199
integration = 2;
102100
maxfield = 10;
103-
// see if we can query the o2 field
104-
if (auto o2field = dynamic_cast<o2::field::MagneticField*>(field)) {
105-
integration = o2field->Integral(); // default integration method?
106-
maxfield = o2field->Max();
107-
} else {
108-
LOG(INFO) << "No magnetic field found; using default tracking values " << integration << " " << maxfield
109-
<< " to initialize media\n";
101+
auto vmc = TVirtualMC::GetMC();
102+
if (vmc) {
103+
auto field = vmc->GetMagField();
104+
// see if we can query the o2 field
105+
if (auto o2field = dynamic_cast<o2::field::MagneticField*>(field)) {
106+
integration = o2field->Integral(); // default integration method?
107+
maxfield = o2field->Max();
108+
return;
109+
}
110110
}
111+
LOG(INFO) << "No magnetic field found; using default tracking values " << integration << " " << maxfield
112+
<< " to initialize media\n";
111113
}
112114

113115
TClonesArray* Detector::GetCollection(int) const

Detectors/Base/src/MaterialManager.cxx

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
/// \brief Implementation of the MaterialManager class
1313

1414
#include "DetectorsBase/MaterialManager.h"
15-
#include <TVirtualMC.h> // for TVirtualMC, gMC
16-
#include "TString.h" // for TString
15+
#include "TVirtualMC.h"
16+
#include "TString.h" // for TString
1717
#include <TGeoMedium.h>
1818
#include <TGeoManager.h>
1919
#include <TList.h>
@@ -34,25 +34,63 @@ void MaterialManager::Material(const char* modname, Int_t imat, const char* name
3434
uniquename.Append("_");
3535
uniquename.Append(name);
3636

37-
// Check this!!!
38-
int kmat = -1;
39-
TVirtualMC::GetMC()->Material(kmat, uniquename.Data(), a, z, dens * mDensityFactor, radl, absl, buf, nwbuf);
40-
mMaterialMap[modname][imat] = kmat;
41-
insertMaterialName(uniquename.Data(), kmat);
37+
if (TVirtualMC::GetMC()) {
38+
// Check this!!!
39+
int kmat = -1;
40+
TVirtualMC::GetMC()->Material(kmat, uniquename.Data(), a, z, dens * mDensityFactor, radl, absl, buf, nwbuf);
41+
mMaterialMap[modname][imat] = kmat;
42+
insertMaterialName(uniquename.Data(), kmat);
43+
} else {
44+
auto uid = gGeoManager->GetListOfMaterials()->GetSize();
45+
auto mat = gGeoManager->Material(uniquename.Data(), a, z, dens * mDensityFactor, uid, radl, absl);
46+
mMaterialMap[modname][imat] = uid;
47+
insertMaterialName(uniquename.Data(), uid);
48+
}
4249
}
4350

51+
/// Define a mixture or a compound
52+
/// @param imat local (to detector/module) mixture identifier
53+
/// @param a,z,wmat arrays of size abs(nlmat) defining the materials
54+
/// @param nlmat indicates what wmat array represents
55+
///
56+
/// If nlmat > 0 then wmat contains the proportion by
57+
/// weights of each basic material in the mixture.
58+
///
59+
/// If nlmat < 0 then wmat contains the number of atoms
60+
/// of a given kind into the molecule of the compound.
61+
/// In this case, wmat in output is changed to relative
62+
/// weights.
4463
void MaterialManager::Mixture(const char* modname, Int_t imat, const char* name, Float_t* a, Float_t* z, Float_t dens,
4564
Int_t nlmat, Float_t* wmat)
4665
{
4766
TString uniquename = modname;
4867
uniquename.Append("_");
4968
uniquename.Append(name);
5069

51-
// Check this!!!
52-
int kmat = -1;
53-
TVirtualMC::GetMC()->Mixture(kmat, uniquename.Data(), a, z, dens * mDensityFactor, nlmat, wmat);
54-
mMaterialMap[modname][imat] = kmat;
55-
insertMaterialName(uniquename.Data(), kmat);
70+
if (TVirtualMC::GetMC()) {
71+
// Check this!!!
72+
int kmat = -1;
73+
TVirtualMC::GetMC()->Mixture(kmat, uniquename.Data(), a, z, dens * mDensityFactor, nlmat, wmat);
74+
mMaterialMap[modname][imat] = kmat;
75+
insertMaterialName(uniquename.Data(), kmat);
76+
77+
} else {
78+
auto uid = gGeoManager->GetListOfMaterials()->GetSize();
79+
if (nlmat < 0) {
80+
nlmat = -nlmat;
81+
Double_t amol = 0;
82+
Int_t i;
83+
for (i = 0; i < nlmat; i++) {
84+
amol += a[i] * wmat[i];
85+
}
86+
for (i = 0; i < nlmat; i++) {
87+
wmat[i] *= a[i] / amol;
88+
}
89+
}
90+
auto mix = gGeoManager->Mixture(uniquename.Data(), a, z, dens * mDensityFactor, nlmat, wmat, uid);
91+
mMaterialMap[modname][imat] = uid;
92+
insertMaterialName(uniquename.Data(), uid);
93+
}
5694
}
5795

5896
void MaterialManager::Medium(const char* modname, Int_t numed, const char* name, Int_t nmat, Int_t isvol, Int_t ifield,
@@ -63,14 +101,23 @@ void MaterialManager::Medium(const char* modname, Int_t numed, const char* name,
63101
uniquename.Append("_");
64102
uniquename.Append(name);
65103

66-
// Check this!!!
67-
int kmed = -1;
68-
const int kmat = getMaterialID(modname, nmat);
69-
TVirtualMC::GetMC()->Medium(kmed, uniquename.Data(), kmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil,
70-
stmin, ubuf, nbuf);
71-
mMediumMap[modname][numed] = kmed;
72-
insertMediumName(uniquename.Data(), kmed);
73-
insertTGeoMedium(modname, numed);
104+
if (TVirtualMC::GetMC()) {
105+
// Check this!!!
106+
int kmed = -1;
107+
const int kmat = getMaterialID(modname, nmat);
108+
TVirtualMC::GetMC()->Medium(kmed, uniquename.Data(), kmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil,
109+
stmin, ubuf, nbuf);
110+
mMediumMap[modname][numed] = kmed;
111+
insertMediumName(uniquename.Data(), kmed);
112+
insertTGeoMedium(modname, numed);
113+
} else {
114+
auto uid = gGeoManager->GetListOfMedia()->GetSize();
115+
auto med = gGeoManager->Medium(uniquename.Data(), uid, getMaterialID(modname, nmat), isvol, ifield, fieldm, tmaxfd,
116+
stemax, deemax, epsil, stmin);
117+
mMediumMap[modname][numed] = uid;
118+
insertMediumName(uniquename.Data(), uid);
119+
insertTGeoMedium(modname, numed);
120+
}
74121
}
75122

76123
void MaterialManager::printMaterials() const
@@ -141,7 +188,3 @@ TGeoMedium* MaterialManager::getTGeoMedium(const char* mediumname)
141188
}
142189

143190
ClassImp(o2::Base::MaterialManager)
144-
145-
146-
147-

macro/o2sim.C

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void o2sim()
3131
auto genconfig = confref.getGenerator();
3232

3333
auto run = new FairRunSim();
34+
//run->SetImportTGeoToVMC(true); // geometry is created by TGeo and then fed to VMC
3435
run->SetImportTGeoToVMC(false); // do not import TGeo to VMC since the latter is built together with TGeo
3536
run->SetSimSetup([confref]() { o2::SimSetup::setup(confref.getMCEngine().c_str()); });
3637
std::string outputfilename = confref.getOutPrefix() + ".root";

0 commit comments

Comments
 (0)