Skip to content

Commit 6b7c06f

Browse files
committed
Added hybrid trigger example
1 parent d610459 commit 6b7c06f

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- doxy
2+
\page refrunSimExamplesHybrid Example Hybrid
3+
/doxy -->
4+
5+
The usage of the Hybrid generator with the o2-sim is presented in this short manual.
6+
All the other generators are implemented as sub-generators and they can be called thanks to a
7+
JSON file, fed to o2-sim via the GeneratorHybrid.configFile parameter. The O2sim package needs to be loaded in order to use this example.
8+
9+
The example can be run automatically using the runo2sim.sh script, which contains most of the
10+
available generators in O2. The JSON template can be generated using the ${O2DPG_ROOT}/MC/bin/o2_hybrid_gen.py script. To use this example the user can simply copy the entire Hybrid example folder and execute the script after giving it execution permissions (`chmod +x runo2sim.sh`).
11+
12+
# Files description
13+
14+
- **runo2sim.sh** &rarr; allows to use the hybrid generator example
15+
- **hybridconfig.json** &rarr; example JSON file for the hybrid generator configuration
16+
- **example.optns** &rarr; options file to be used in EPOS4 implemented as subgenerator in this example (the .optns must be available in the current working directory)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"generators": [
3+
{
4+
"cocktail": [
5+
{
6+
"name": "pythia8hi",
7+
"triggers": {
8+
"mode": "or",
9+
"specs": [
10+
{
11+
"macro": "${PWD}/trigger.macro",
12+
"function": "trigger_impactb_pythia8(0.,5.)"
13+
}
14+
]
15+
},
16+
"config": ""
17+
},
18+
{
19+
"name": "external",
20+
"config": {
21+
"fileName": "${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGDQ/external/generator/GeneratorPromptCharmonia.C",
22+
"funcName": "GeneratorParamPromptJpsiToElectronEvtGen_pp13TeV()",
23+
"iniFile": ""
24+
}
25+
}
26+
]
27+
}
28+
],
29+
"fractions": [
30+
1
31+
]
32+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Hybrid generator simulation example with triggers and cocktail:
4+
# the simulation is configured using a JSON file (hybridconfig.json in this folder), whose
5+
# template can be generated using the script ${O2DPG_ROOT}/MC/bin/o2_hybrid_gen.py.
6+
# Trigger is taken from the trigger.macro and it's a simple impact parameter selection for
7+
# heavy ion collisions
8+
set -x
9+
if [ ! "${O2DPG_ROOT}" ]; then
10+
echo "This needs O2DPG loaded; alienv enter ..."
11+
exit 1
12+
fi
13+
14+
[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 2
15+
16+
NEV=1
17+
more=""
18+
JOBS=2
19+
20+
usage()
21+
{
22+
cat <<EOF
23+
Usage: $0 [OPTIONS]
24+
25+
Options:
26+
27+
-m,--more CONFIG More configurations ($more)
28+
-n,--nevents EVENTS Number of events ($NEV)
29+
-j,--jobs JOBS Number of jobs ($JOBS)
30+
-h,--help Print these instructions
31+
-- Rest of command line sent to o2-sim
32+
33+
COMMAND must be quoted if it contains spaces or other special
34+
characters
35+
36+
Below follows the help output of o2-sim
37+
38+
EOF
39+
}
40+
41+
if [ "$#" -lt 2 ]; then
42+
echo "Running with default values"
43+
fi
44+
45+
while test $# -gt 0 ; do
46+
case $1 in
47+
-m|--more) more="$2" ; shift ;;
48+
-n|--nevents) NEV=$2 ; shift ;;
49+
-j|--jobs) JOBS=$2 ; shift ;;
50+
-h|--help) usage; o2-sim --help full ; exit 0 ;;
51+
--) shift ; break ;;
52+
*) echo "Unknown option '$1', did you forget '--'?" >/dev/stderr
53+
exit 3
54+
;;
55+
esac
56+
shift
57+
done
58+
59+
# Starting simulation with Hybrid generator
60+
${O2_ROOT}/bin/o2-sim --noGeant -j $JOBS --field ccdb --vertexMode kCCDB --run 300000 --configKeyValues "MFTBase.buildAlignment=true;GeneratorHybrid.configFile=$PWD/hybridconfig.json;GeneratorHybrid.randomize=false;${more}" -g hybrid -o genevents --timestamp 1546300800000 --seed 836302859 -n $NEV
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)