Skip to content

Commit c275684

Browse files
committed
Integrate non-uniform InteractionSampler into CollisionContextTool
1 parent 6db969d commit c275684

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

DataFormats/simulation/src/InteractionSampler.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ bool NonUniformMuInteractionSampler::setBCIntensityScales(const TH1F& hist)
202202

203203
std::vector<float> NonUniformMuInteractionSampler::determineBCIntensityScalesFromHistogram(const TH1F& hist)
204204
{
205+
if (mInteractingBCs.size() == 0) {
206+
LOG(error) << " Initialize bunch crossing scheme before assigning scales";
207+
}
205208
std::vector<float> scales;
206209
// we go through the BCs and query the count from histogram
207210
for (auto bc : mInteractingBCs) {

Steer/src/CollisionContextTool.cxx

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ struct Options {
6464
// This is useful when someone else is creating the contexts (MC-data embedding) and we
6565
// merely want to pass these through. If this is given, we simply take the timeframe ID, number of orbits
6666
// and copy the right amount of timeframes into the destination folder (implies individualTFextraction)
67+
std::string nontrivial_mu_distribution = ""; // path to fetch a non-uniform MC(BC) distribution for the interaction sampler
68+
// can be: (a) ccdb, (b) a ROOT file with the histogram included
6769
};
6870

6971
enum class InteractionLockMode {
@@ -216,8 +218,8 @@ bool parseOptions(int argc, char* argv[], Options& optvalues)
216218
"timestamp", bpo::value<long>(&optvalues.timestamp)->default_value(-1L), "Timestamp for CCDB queries / anchoring")(
217219
"extract-per-timeframe", bpo::value<std::string>(&optvalues.individualTFextraction)->default_value(""),
218220
"Extract individual timeframe contexts. Format required: time_frame_prefix[:comma_separated_list_of_signals_to_offset]")(
219-
"import-external", bpo::value<std::string>(&optvalues.external_path)->default_value(""),
220-
"Take collision contexts (per timeframe) from external files for instance for data-anchoring use-case. Needs timeframeID and number of orbits to be given as well.");
221+
"import-external", bpo::value<std::string>(&optvalues.external_path)->default_value(""), "Take collision contexts (per timeframe) from external files for instance for data-anchoring use-case. Needs timeframeID and number of orbits to be given as well.")(
222+
"nontrivial-mu-distribution", bpo::value<std::string>(&optvalues.nontrivial_mu_distribution)->default_value(""), "Distribution for MU(BC)");
221223

222224
options.add_options()("help,h", "Produce help message.");
223225

@@ -397,6 +399,37 @@ int main(int argc, char* argv[])
397399
auto mode = ispecs[id].syncmode;
398400
if (mode == InteractionLockMode::NOLOCK) {
399401
auto sampler = std::make_unique<o2::steer::InteractionSampler>();
402+
TH1F* mu_hist = nullptr;
403+
404+
// we check if there is a realistic bunch crossing distribution available
405+
const auto& mu_distr_source = options.nontrivial_mu_distribution;
406+
if (mu_distr_source.size() > 0) {
407+
if (mu_distr_source == "ccdb") {
408+
auto& inst = o2::ccdb::BasicCCDBManager::instance();
409+
// we fetch it from CCDB ... but allow empty response
410+
auto backup = inst.getFatalWhenNull();
411+
inst.setFatalWhenNull(false);
412+
auto local_hist = inst.getForTimeStamp<TH1F>("Users/s/swenzel/GLO/HBCTVX", options.timestamp);
413+
inst.setFatalWhenNull(backup);
414+
mu_hist = (TH1F*)(local_hist->Clone("h2")); // we need to clone since ownership of local_hist is with TFile
415+
} else {
416+
// we interpret the file as a ROOT file and open it to extract the wanted histogram
417+
auto mudistr_file = TFile::Open(mu_distr_source.c_str(), "OPEN");
418+
if (mudistr_file && !mudistr_file->IsZombie()) {
419+
auto local_hist = mudistr_file->Get<TH1F>("hBcTVX");
420+
mu_hist = (TH1F*)(local_hist->Clone("h2")); // we need to clone since ownership of local_hist is with TFile
421+
mudistr_file->Close();
422+
}
423+
}
424+
if (mu_hist) {
425+
LOG(info) << "Found an external mu distribution with mean BC value " << mu_hist->GetMean();
426+
427+
// do some checks
428+
429+
// reset to correct interaction Sampler type
430+
sampler.reset(new o2::steer::NonUniformMuInteractionSampler());
431+
}
432+
}
400433

401434
// for debug purposes: allows to instantiate trivial sampler
402435
if (const char* env = getenv("ALICEO2_ENFORCE_TRIVIAL_BC_SAMPLER")) {
@@ -418,11 +451,17 @@ int main(int argc, char* argv[])
418451
if (!options.bcpatternfile.empty()) {
419452
setBCFillingHelper(*sampler, options.bcpatternfile);
420453
}
454+
sampler->init();
455+
if (auto sampler_cast = dynamic_cast<o2::steer::NonUniformMuInteractionSampler*>(sampler.get())) {
456+
if (mu_hist) {
457+
sampler_cast->setBCIntensityScales(*mu_hist);
458+
}
459+
}
460+
421461
o2::InteractionTimeRecord record;
422462
// this loop makes sure that the first collision is within the range of orbits asked (if noEmptyTF is enabled)
423463
do {
424464
sampler->setFirstIR(o2::InteractionRecord(options.firstBC, orbitstart));
425-
sampler->init();
426465
record = sampler->generateCollisionTime();
427466
} while (options.noEmptyTF && usetimeframelength && record.orbit >= orbitstart + orbits_total);
428467
int count = 0;

0 commit comments

Comments
 (0)