Skip to content

Commit 91a7d8b

Browse files
committed
MaterialManager: Allow density modification on the individual material level
We can now scale the material density beyond the module level. We simply need to use "MODULENAME/MATERIAL" strings in the configurable param. Matching on individual material takes precedence over matching on the module level. An example is ``` o2-sim --configKeyValues "SimMaterialParams.localDensityFactor=TPC/Air:1.2,TPC:2.0,ITS:5." ``` which will scale TPC air with a factor 1.2, the rest of TPC with factor 2.0 and all of ITS with factor 5.0 Fixes https://its.cern.ch/jira/browse/O2-6294
1 parent aca5f47 commit 91a7d8b

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

Common/SimConfig/include/SimConfig/SimParams.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ struct SimCutParams : public o2::conf::ConfigurableParamHelper<SimCutParams> {
4444
struct SimMaterialParams : public o2::conf::ConfigurableParamHelper<SimMaterialParams> {
4545
// Local density value takes precedence over global density value, i.e. local values overwrite the global value.
4646
float globalDensityFactor = 1.f; // global factor that scales all material densities for systematic studies
47-
std::string localDensityFactor; // Expected format: "SimMaterialParams.localDensityFactor=<mod1>:<value1>,<mod2>:<value2>,..."
47+
// String to set densities on module or material level. Expected format:
48+
// "SimMaterialParams.localDensityFactor=<mod1/matname>:<value1>,<mod2>:<value2>,..."
49+
// Example: "SimMaterialParams.localDensityFactor=TPC/Air:1.2,ITS:5." will scale the density of the Air in TPC
50+
// with 1.2 and to 5.0 for all materials in ITS".
51+
std::string localDensityFactor;
4852

4953
O2ParamDef(SimMaterialParams, "SimMaterialParams");
5054
};

Detectors/Base/include/DetectorsBase/MaterialManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class MaterialManager
218218
std::unordered_map<std::string, float> mDensityMap;
219219

220220
void initDensityMap();
221-
float getDensity(std::string const& modname);
221+
float getDensity(std::string const& modname, std::string const& matname);
222222

223223
// Hide details by providing these private methods so it cannot happen that special settings
224224
// are applied as default settings by accident using a boolean flag

Detectors/Base/src/MaterialManager.cxx

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,51 @@ void MaterialManager::initDensityMap()
123123
mDensityMapInitialized = true;
124124
}
125125

126-
float MaterialManager::getDensity(std::string const& modname)
126+
float MaterialManager::getDensity(std::string const& modname, std::string const& matname)
127127
{
128+
// This function returns the final density for a material of name matname inside module modname.
129+
// The priority is
130+
// - return density for a specific module + material if it exists in the lookup
131+
// - return density for the module if it exists in the the lookup
132+
// - return global density factor
133+
134+
auto debug = getenv("O2SIM_MATMGR_LOCALDENSITY_DEBUG");
135+
128136
if (!mDensityMapInitialized) {
129137
initDensityMap();
130138
}
131-
if (mDensityMap.find(modname) != mDensityMap.end()) {
132-
return mDensityMap[modname];
139+
// density on final material level
140+
// (this works by a name lookup of pair "modname/matname")
141+
std::string lookupstring = modname + "/" + matname;
142+
auto iter = mDensityMap.find(lookupstring);
143+
if (iter != mDensityMap.end()) {
144+
if (debug) {
145+
LOG(info) << "MatManager - " << modname << "/" << matname << " : applying density " << iter->second << " from material match";
146+
}
147+
return iter->second;
133148
}
134-
return o2::conf::SimMaterialParams::Instance().globalDensityFactor;
149+
// density on module level
150+
iter = mDensityMap.find(modname);
151+
if (iter != mDensityMap.end()) {
152+
if (debug) {
153+
LOG(info) << "MatManager - " << modname << "/" << matname << " : applying density " << iter->second << " from module match";
154+
}
155+
return iter->second;
156+
}
157+
// global factor
158+
const auto global = o2::conf::SimMaterialParams::Instance().globalDensityFactor;
159+
if (debug && global != 1.0) {
160+
LOG(info) << "MatManager - " << modname << "/" << matname << " : applying global density " << iter->second;
161+
}
162+
return global;
135163
}
136164

137165
void MaterialManager::Material(const char* modname, Int_t imat, const char* name, Float_t a, Float_t z, Float_t dens,
138166
Float_t radl, Float_t absl, Float_t* buf, Int_t nwbuf)
139167
{
140168
TString uniquename = modname;
141-
auto densityFactor = getDensity(modname);
169+
auto densityFactor = getDensity(modname, name);
170+
142171
uniquename.Append("_");
143172
uniquename.Append(name);
144173
if (TVirtualMC::GetMC()) {
@@ -173,7 +202,7 @@ void MaterialManager::Mixture(const char* modname, Int_t imat, const char* name,
173202
Int_t nlmat, Float_t* wmat)
174203
{
175204
TString uniquename = modname;
176-
auto densityFactor = getDensity(modname);
205+
auto densityFactor = getDensity(modname, name);
177206
uniquename.Append("_");
178207
uniquename.Append(name);
179208

0 commit comments

Comments
 (0)