Skip to content

Commit c9b657d

Browse files
jackal1-66sawenzel
authored andcommitted
Included deep trigger example with impact parameter
1 parent ed78d60 commit c9b657d

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

MC/bin/o2_hybrid_gen.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def main():
5757
parser.add_argument('--mode', type=str, help='Run generator in sequential or parallel mode for quicker event generation (multi-threading)')
5858
parser.add_argument('--output', type=str, required=True, help='Output JSON file path')
5959
parser.add_argument('--clone', type=int, help='Number of clones to make of the generator list')
60+
parser.add_argument('--trigger', action='store_true', help='Add triggers to the template JSON file')
6061

6162
args = parser.parse_args()
6263

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

75-
trgbase = {
76-
"mode": "off",
77-
"specs": [
78-
{
79-
"macro": "",
80-
"function": ""
81-
}
82-
]
83-
}
76+
add_trigger = lambda d: d.update({"triggers": {"mode": "off", "specs": [{"macro": "", "function": ""}]}}) if args.trigger else None
8477

8578
# put in a list all the elementes in the gen flag
8679
noConfGen = ["pythia8pp", "pythia8hf", "pythia8hi", "pythia8powheg"]
@@ -96,25 +89,25 @@ def main():
9689
configs = [get_params(cmd_instance, cmd_params), get_params(gens_instances[gen], gens_params[gen])]
9790
gens.append({
9891
'name': gen,
99-
'triggers': trgbase,
10092
'config': {
10193
"configcmd": configs[0],
10294
"confighepmc": configs[1]
10395
}
10496
})
97+
add_trigger(gens[-1])
10598
else:
10699
configs = get_params(gens_instances[gen],gens_params[gen])
107100
gens.append({
108101
'name': gen,
109-
'triggers': trgbase,
110102
'config': configs
111103
})
104+
add_trigger(gens[-1])
112105
elif gen in noConfGen:
113106
gens.append({
114107
"name": gen,
115-
'triggers': trgbase,
116108
"config": ""
117109
})
110+
add_trigger(gens[-1])
118111
else:
119112
print(f"Generator {gen} not found in the list of available generators")
120113
exit(1)
@@ -129,9 +122,9 @@ def main():
129122
configs["iniFile"] = ini
130123
gens.append({
131124
'name': 'external',
132-
'triggers': trgbase,
133125
'config': configs
134126
})
127+
add_trigger(gens[-1])
135128

136129
if args.clone:
137130
if args.clone < 2:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "Generators/Trigger.h"
2+
#include "TParticle.h"
3+
#include <iostream>
4+
5+
// a very simple trigger example, examining generated particles
6+
o2::eventgen::Trigger trigger()
7+
{
8+
//
9+
return [](const std::vector<TParticle>& particles) -> bool {
10+
std::cout << "Running trigger on event with size " << particles.size() << "\n";
11+
if (particles.size() > 10000) {
12+
return true;
13+
}
14+
return false;
15+
};
16+
}
17+
18+
#include "Pythia8/Pythia.h"
19+
#include "Pythia8/HIInfo.h"
20+
#include <fairlogger/Logger.h>
21+
// a deep trigger example, looking into the internal generator state
22+
o2::eventgen::DeepTrigger
23+
trigger_impactb_pythia8(double bmin = 5., double bmax = 10.)
24+
{
25+
return [bmin, bmax](void* interface, std::string name) -> bool {
26+
if (!name.compare("pythia8")) {
27+
auto py8 = reinterpret_cast<Pythia8::Pythia*>(interface);
28+
#if PYTHIA_VERSION_INTEGER < 8300
29+
auto hiinfo = py8->info.hiinfo;
30+
#else
31+
auto hiinfo = py8->info.hiInfo;
32+
#endif
33+
if (!hiinfo) {
34+
LOG(fatal) << "Cannot define impact parameter: is \'pythia8\' running in heavy-ion mode?";
35+
}
36+
auto b = hiinfo->b();
37+
auto selected = (b > bmin && b < bmax);
38+
LOG(info) << "Impact parameter = " << b << " fm: " << (selected ? "selected" : "rejected");
39+
return selected;
40+
} else {
41+
LOG(fatal) << "Cannot define impact parameter for generator interface \'" << name << "\'";
42+
}
43+
return false;
44+
};
45+
}

0 commit comments

Comments
 (0)