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
6 changes: 5 additions & 1 deletion Common/SimConfig/include/SimConfig/SimParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ struct SimCutParams : public o2::conf::ConfigurableParamHelper<SimCutParams> {
struct SimMaterialParams : public o2::conf::ConfigurableParamHelper<SimMaterialParams> {
// Local density value takes precedence over global density value, i.e. local values overwrite the global value.
float globalDensityFactor = 1.f; // global factor that scales all material densities for systematic studies
std::string localDensityFactor; // Expected format: "SimMaterialParams.localDensityFactor=<mod1>:<value1>,<mod2>:<value2>,..."
// String to set densities on module or material level. Expected format:
// "SimMaterialParams.localDensityFactor=<mod1/matname>:<value1>,<mod2>:<value2>,..."
// Example: "SimMaterialParams.localDensityFactor=TPC/Air:1.2,ITS:5." will scale the density of the Air in TPC
// with 1.2 and to 5.0 for all materials in ITS".
std::string localDensityFactor;

O2ParamDef(SimMaterialParams, "SimMaterialParams");
};
Expand Down
2 changes: 1 addition & 1 deletion Detectors/Base/include/DetectorsBase/MaterialManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class MaterialManager
std::unordered_map<std::string, float> mDensityMap;

void initDensityMap();
float getDensity(std::string const& modname);
float getDensity(std::string const& modname, std::string const& matname);

// Hide details by providing these private methods so it cannot happen that special settings
// are applied as default settings by accident using a boolean flag
Expand Down
41 changes: 35 additions & 6 deletions Detectors/Base/src/MaterialManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,51 @@ void MaterialManager::initDensityMap()
mDensityMapInitialized = true;
}

float MaterialManager::getDensity(std::string const& modname)
float MaterialManager::getDensity(std::string const& modname, std::string const& matname)
{
// This function returns the final density for a material of name matname inside module modname.
// The priority is
// - return density for a specific module + material if it exists in the lookup
// - return density for the module if it exists in the the lookup
// - return global density factor

auto debug = getenv("O2SIM_MATMGR_LOCALDENSITY_DEBUG");

if (!mDensityMapInitialized) {
initDensityMap();
}
if (mDensityMap.find(modname) != mDensityMap.end()) {
return mDensityMap[modname];
// density on final material level
// (this works by a name lookup of pair "modname/matname")
std::string lookupstring = modname + "/" + matname;
auto iter = mDensityMap.find(lookupstring);
if (iter != mDensityMap.end()) {
if (debug) {
LOG(info) << "MatManager - " << modname << "/" << matname << " : applying density " << iter->second << " from material match";
}
return iter->second;
}
return o2::conf::SimMaterialParams::Instance().globalDensityFactor;
// density on module level
iter = mDensityMap.find(modname);
if (iter != mDensityMap.end()) {
if (debug) {
LOG(info) << "MatManager - " << modname << "/" << matname << " : applying density " << iter->second << " from module match";
}
return iter->second;
}
// global factor
const auto global = o2::conf::SimMaterialParams::Instance().globalDensityFactor;
if (debug && global != 1.0) {
LOG(info) << "MatManager - " << modname << "/" << matname << " : applying global density " << iter->second;
}
return global;
}

void MaterialManager::Material(const char* modname, Int_t imat, const char* name, Float_t a, Float_t z, Float_t dens,
Float_t radl, Float_t absl, Float_t* buf, Int_t nwbuf)
{
TString uniquename = modname;
auto densityFactor = getDensity(modname);
auto densityFactor = getDensity(modname, name);

uniquename.Append("_");
uniquename.Append(name);
if (TVirtualMC::GetMC()) {
Expand Down Expand Up @@ -173,7 +202,7 @@ void MaterialManager::Mixture(const char* modname, Int_t imat, const char* name,
Int_t nlmat, Float_t* wmat)
{
TString uniquename = modname;
auto densityFactor = getDensity(modname);
auto densityFactor = getDensity(modname, name);
uniquename.Append("_");
uniquename.Append(name);

Expand Down