Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions Detectors/Base/src/Detector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include "Field/MagneticField.h"
#include "TString.h" // for TString

using std::endl;
using std::cout;
using std::endl;
using std::fstream;
using std::ios;
using std::ostream;
Expand Down Expand Up @@ -95,19 +95,21 @@ void Detector::defineLayerTurbo(Int_t nlay, Double_t phi0, Double_t r, Int_t nla

void Detector::initFieldTrackingParams(int& integration, float& maxfield)
{
auto vmc = TVirtualMC::GetMC();
auto field = vmc->GetMagField();
// set reasonable default values
integration = 2;
maxfield = 10;
// see if we can query the o2 field
if (auto o2field = dynamic_cast<o2::field::MagneticField*>(field)) {
integration = o2field->Integral(); // default integration method?
maxfield = o2field->Max();
} else {
LOG(INFO) << "No magnetic field found; using default tracking values " << integration << " " << maxfield
<< " to initialize media\n";
auto vmc = TVirtualMC::GetMC();
if (vmc) {
auto field = vmc->GetMagField();
// see if we can query the o2 field
if (auto o2field = dynamic_cast<o2::field::MagneticField*>(field)) {
integration = o2field->Integral(); // default integration method?
maxfield = o2field->Max();
return;
}
}
LOG(INFO) << "No magnetic field found; using default tracking values " << integration << " " << maxfield
<< " to initialize media\n";
}

TClonesArray* Detector::GetCollection(int) const
Expand Down
91 changes: 67 additions & 24 deletions Detectors/Base/src/MaterialManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
/// \brief Implementation of the MaterialManager class

#include "DetectorsBase/MaterialManager.h"
#include <TVirtualMC.h> // for TVirtualMC, gMC
#include "TString.h" // for TString
#include "TVirtualMC.h"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why these changes? They are not necessary for this PR, I guess.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum, no, indeed. In the original commit that include was no longer needed, then I put it back in the second commit but as a quotes include instead of angled include, out of habit I guess (as I've never quite understood why is Root considered a system include ;-) )

#include "TString.h" // for TString
#include <TGeoMedium.h>
#include <TGeoManager.h>
#include <TList.h>
Expand All @@ -34,25 +34,63 @@ void MaterialManager::Material(const char* modname, Int_t imat, const char* name
uniquename.Append("_");
uniquename.Append(name);

// Check this!!!
int kmat = -1;
TVirtualMC::GetMC()->Material(kmat, uniquename.Data(), a, z, dens * mDensityFactor, radl, absl, buf, nwbuf);
mMaterialMap[modname][imat] = kmat;
insertMaterialName(uniquename.Data(), kmat);
if (TVirtualMC::GetMC()) {
// Check this!!!
int kmat = -1;
TVirtualMC::GetMC()->Material(kmat, uniquename.Data(), a, z, dens * mDensityFactor, radl, absl, buf, nwbuf);
mMaterialMap[modname][imat] = kmat;
insertMaterialName(uniquename.Data(), kmat);
} else {
auto uid = gGeoManager->GetListOfMaterials()->GetSize();
auto mat = gGeoManager->Material(uniquename.Data(), a, z, dens * mDensityFactor, uid, radl, absl);
mMaterialMap[modname][imat] = uid;
insertMaterialName(uniquename.Data(), uid);
}
}

/// Define a mixture or a compound
/// @param imat local (to detector/module) mixture identifier
/// @param a,z,wmat arrays of size abs(nlmat) defining the materials
/// @param nlmat indicates what wmat array represents
///
/// If nlmat > 0 then wmat contains the proportion by
/// weights of each basic material in the mixture.
///
/// If nlmat < 0 then wmat contains the number of atoms
/// of a given kind into the molecule of the compound.
/// In this case, wmat in output is changed to relative
/// weights.
void MaterialManager::Mixture(const char* modname, Int_t imat, const char* name, Float_t* a, Float_t* z, Float_t dens,
Int_t nlmat, Float_t* wmat)
{
TString uniquename = modname;
uniquename.Append("_");
uniquename.Append(name);

// Check this!!!
int kmat = -1;
TVirtualMC::GetMC()->Mixture(kmat, uniquename.Data(), a, z, dens * mDensityFactor, nlmat, wmat);
mMaterialMap[modname][imat] = kmat;
insertMaterialName(uniquename.Data(), kmat);
if (TVirtualMC::GetMC()) {
// Check this!!!
int kmat = -1;
TVirtualMC::GetMC()->Mixture(kmat, uniquename.Data(), a, z, dens * mDensityFactor, nlmat, wmat);
mMaterialMap[modname][imat] = kmat;
insertMaterialName(uniquename.Data(), kmat);

} else {
auto uid = gGeoManager->GetListOfMaterials()->GetSize();
if (nlmat < 0) {
nlmat = -nlmat;
Double_t amol = 0;
Int_t i;
for (i = 0; i < nlmat; i++) {
amol += a[i] * wmat[i];
}
for (i = 0; i < nlmat; i++) {
wmat[i] *= a[i] / amol;
}
}
auto mix = gGeoManager->Mixture(uniquename.Data(), a, z, dens * mDensityFactor, nlmat, wmat, uid);
mMaterialMap[modname][imat] = uid;
insertMaterialName(uniquename.Data(), uid);
}
}

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

// Check this!!!
int kmed = -1;
const int kmat = getMaterialID(modname, nmat);
TVirtualMC::GetMC()->Medium(kmed, uniquename.Data(), kmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil,
stmin, ubuf, nbuf);
mMediumMap[modname][numed] = kmed;
insertMediumName(uniquename.Data(), kmed);
insertTGeoMedium(modname, numed);
if (TVirtualMC::GetMC()) {
// Check this!!!
int kmed = -1;
const int kmat = getMaterialID(modname, nmat);
TVirtualMC::GetMC()->Medium(kmed, uniquename.Data(), kmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil,
stmin, ubuf, nbuf);
mMediumMap[modname][numed] = kmed;
insertMediumName(uniquename.Data(), kmed);
insertTGeoMedium(modname, numed);
} else {
auto uid = gGeoManager->GetListOfMedia()->GetSize();
auto med = gGeoManager->Medium(uniquename.Data(), uid, getMaterialID(modname, nmat), isvol, ifield, fieldm, tmaxfd,
stemax, deemax, epsil, stmin);
mMediumMap[modname][numed] = uid;
insertMediumName(uniquename.Data(), uid);
insertTGeoMedium(modname, numed);
}
}

void MaterialManager::printMaterials() const
Expand Down Expand Up @@ -141,7 +188,3 @@ TGeoMedium* MaterialManager::getTGeoMedium(const char* mediumname)
}

ClassImp(o2::Base::MaterialManager)




1 change: 1 addition & 0 deletions macro/o2sim.C
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void o2sim()
auto genconfig = confref.getGenerator();

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