Skip to content

Commit

Permalink
Included deep trigger example with impact parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jackal1-66 committed Jan 23, 2025
1 parent ebb4854 commit 5e9bdb8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
19 changes: 6 additions & 13 deletions MC/bin/o2_hybrid_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def main():
parser.add_argument('--mode', type=str, help='Run generator in sequential or parallel mode for quicker event generation (multi-threading)')
parser.add_argument('--output', type=str, required=True, help='Output JSON file path')
parser.add_argument('--clone', type=int, help='Number of clones to make of the generator list')
parser.add_argument('--trigger', action='store_true', help='Add triggers to the template JSON file')

args = parser.parse_args()

Expand All @@ -72,15 +73,7 @@ def main():
# Available options for trigger are "off", "or", "and"
# in all the other cases the trigger is forced "off"

trgbase = {
"mode": "off",
"specs": [
{
"macro": "",
"function": ""
}
]
}
add_trigger = lambda d: d.update({"triggers": {"mode": "off", "specs": [{"macro": "", "function": ""}]}}) if args.trigger else None

# put in a list all the elementes in the gen flag
noConfGen = ["pythia8pp", "pythia8hf", "pythia8hi", "pythia8powheg"]
Expand All @@ -96,25 +89,25 @@ def main():
configs = [get_params(cmd_instance, cmd_params), get_params(gens_instances[gen], gens_params[gen])]
gens.append({
'name': gen,
'triggers': trgbase,
'config': {
"configcmd": configs[0],
"confighepmc": configs[1]
}
})
add_trigger(gens[-1])
else:
configs = get_params(gens_instances[gen],gens_params[gen])
gens.append({
'name': gen,
'triggers': trgbase,
'config': configs
})
add_trigger(gens[-1])
elif gen in noConfGen:
gens.append({
"name": gen,
'triggers': trgbase,
"config": ""
})
add_trigger(gens[-1])
else:
print(f"Generator {gen} not found in the list of available generators")
exit(1)
Expand All @@ -129,9 +122,9 @@ def main():
configs["iniFile"] = ini
gens.append({
'name': 'external',
'triggers': trgbase,
'config': configs
})
add_trigger(gens[-1])

if args.clone:
if args.clone < 2:
Expand Down
45 changes: 45 additions & 0 deletions MC/config/examples/trigger/trigger_impactb.macro
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "Generators/Trigger.h"
#include "TParticle.h"
#include <iostream>

// a very simple trigger example, examining generated particles
o2::eventgen::Trigger trigger()
{
//
return [](const std::vector<TParticle>& particles) -> bool {
std::cout << "Running trigger on event with size " << particles.size() << "\n";
if (particles.size() > 10000) {
return true;
}
return false;
};
}

#include "Pythia8/Pythia.h"
#include "Pythia8/HIInfo.h"
#include <fairlogger/Logger.h>
// a deep trigger example, looking into the internal generator state
o2::eventgen::DeepTrigger
trigger_impactb_pythia8(double bmin = 5., double bmax = 10.)
{
return [bmin, bmax](void* interface, std::string name) -> bool {
if (!name.compare("pythia8")) {
auto py8 = reinterpret_cast<Pythia8::Pythia*>(interface);
#if PYTHIA_VERSION_INTEGER < 8300
auto hiinfo = py8->info.hiinfo;
#else
auto hiinfo = py8->info.hiInfo;
#endif
if (!hiinfo) {
LOG(fatal) << "Cannot define impact parameter: is \'pythia8\' running in heavy-ion mode?";
}
auto b = hiinfo->b();
auto selected = (b > bmin && b < bmax);
LOG(info) << "Impact parameter = " << b << " fm: " << (selected ? "selected" : "rejected");
return selected;
} else {
LOG(fatal) << "Cannot define impact parameter for generator interface \'" << name << "\'";
}
return false;
};
}

0 comments on commit 5e9bdb8

Please sign in to comment.