From ebb485449240a01e795b2da663e44b4fc5d4d49a Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Thu, 16 Jan 2025 12:33:35 +0100 Subject: [PATCH 1/2] Included trigger in template generator --- MC/bin/o2_hybrid_gen.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/MC/bin/o2_hybrid_gen.py b/MC/bin/o2_hybrid_gen.py index 2aa23a9f1..0d471724d 100755 --- a/MC/bin/o2_hybrid_gen.py +++ b/MC/bin/o2_hybrid_gen.py @@ -69,6 +69,19 @@ def main(): else: print(f"Running in {mode} mode") + # Available options for trigger are "off", "or", "and" + # in all the other cases the trigger is forced "off" + + trgbase = { + "mode": "off", + "specs": [ + { + "macro": "", + "function": "" + } + ] + } + # put in a list all the elementes in the gen flag noConfGen = ["pythia8pp", "pythia8hf", "pythia8hi", "pythia8powheg"] gens = [] @@ -83,6 +96,7 @@ 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] @@ -92,11 +106,13 @@ def main(): configs = get_params(gens_instances[gen],gens_params[gen]) gens.append({ 'name': gen, + 'triggers': trgbase, 'config': configs }) elif gen in noConfGen: gens.append({ "name": gen, + 'triggers': trgbase, "config": "" }) else: @@ -113,6 +129,7 @@ def main(): configs["iniFile"] = ini gens.append({ 'name': 'external', + 'triggers': trgbase, 'config': configs }) From 5e9bdb82ddd5a674b199ce82e8522f04d422140d Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Fri, 17 Jan 2025 16:27:43 +0100 Subject: [PATCH 2/2] Included deep trigger example with impact parameter --- MC/bin/o2_hybrid_gen.py | 19 +++----- .../examples/trigger/trigger_impactb.macro | 45 +++++++++++++++++++ 2 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 MC/config/examples/trigger/trigger_impactb.macro diff --git a/MC/bin/o2_hybrid_gen.py b/MC/bin/o2_hybrid_gen.py index 0d471724d..b3f0e9048 100755 --- a/MC/bin/o2_hybrid_gen.py +++ b/MC/bin/o2_hybrid_gen.py @@ -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() @@ -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"] @@ -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) @@ -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: diff --git a/MC/config/examples/trigger/trigger_impactb.macro b/MC/config/examples/trigger/trigger_impactb.macro new file mode 100644 index 000000000..076af058c --- /dev/null +++ b/MC/config/examples/trigger/trigger_impactb.macro @@ -0,0 +1,45 @@ +#include "Generators/Trigger.h" +#include "TParticle.h" +#include + +// a very simple trigger example, examining generated particles +o2::eventgen::Trigger trigger() +{ + // + return [](const std::vector& 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 +// 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(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; + }; +}