Skip to content

Commit 813cce4

Browse files
authored
Added examples to run EPOS4 on-the-fly (AliceO2Group#13543)
* Added examples to run EPOS4 on-the-fly
1 parent 2d48d1b commit 813cce4

File tree

6 files changed

+497
-0
lines changed

6 files changed

+497
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!-- doxy
2+
\page refrunSimExamplesHepMC_EPOS4 Example HepMC_EPOS4
3+
/doxy -->
4+
5+
The usage of EPOS4 with the O2 machinery is presented in this short manual.
6+
An in-depth explanation of the mechanisms behind the HepMC(3) data handling can be found in the
7+
HepMC_fifo folder of the MC examples. The scripts use the `cmd` parameter of `GeneratorHepMC`
8+
to spawn the EPOS4 generation via the `epos.sh` script.
9+
10+
EPOS4 uses the outdated HepMC2 libraries, so this had to be specified in the steering scripts
11+
of the generators configuration. If `HepMC.version=2` is removed then the scripts will not work
12+
anymore. This is to say that the balance achieved with the configurations provided is easily
13+
destroyed if the user base edits parts that are not understood completely.
14+
15+
# Scripts description
16+
17+
Four scripts are available to run the simulations
18+
- **epos.sh** &rarr; starts the actual EPOS4 generation
19+
- **runo2sim.sh** &rarr; allows the generation of events using o2-sim
20+
- **rundpg.sh** &rarr; starts the DPG machinery for event generation
21+
- **rundpl.sh** &rarr; starts the event generation with DPL
22+
23+
In addition an example.optns file is provided to start EPOS4, but more can be found in the generator example folder
24+
or in the website [epos4learn.web.cern.ch](https://epos4learn.docs.cern.ch/) where an extensive tutorial on the generator is provided.
25+
26+
## epos.sh
27+
28+
It can be run without the help of the other scripts to simply generate an .hepmc file or print
29+
to the stdout the HepMC results. It it worth nothing though that EPOS4 must be loaded (via cvmfs through AliGenerators or O2sim for example) or installed. In this case the user should simply redirect the stdout to a file:
30+
```
31+
./epos.sh -i test -s 234345 > test.hepmc
32+
```
33+
This example shows all the functionalities of the script (which are implemented in a similar way inside
34+
the generation steering scripts). In particular the `-i` flag allows to provide .optns parameters to EPOS4,
35+
`-s` feeds the generator with a user seed, and the HepMC output is given by test.hepmc by redirecting the
36+
stdout which will contain only the HepMC data thanks to the `-hepstd` flag set automatically in epos.sh and
37+
the `set ihepmc 2` option which **MUST** be set in the option file (otherwise either an hepmc file will be created - ihepmc 1 - or nothing will be generated - missing ihepmc or != 1|2 ).
38+
39+
It is important to note that setting an empty/null seed in the generator out of the box makes EPOS4 crash, so a protection was added in our steering epos.sh script which now generates a random number if 0 is provided.
40+
41+
## runo2sim.sh, rundpg.sh and rundpl.sh
42+
43+
The three scripts have little differences (especially in the first part), so they will be described together. They work after loading any O2sim version after the 20/09/2024 (included), since multiple modifications had to be performed on both EPOS4 and the introduction of AliGenO2 in order to be able to load both O2sim and EPOS4 simultaneously.
44+
45+
If no parameters are provided to the scripts, they will run with default values (energy and nevents provided in the example.optns file), but few flags are available to change the settings of the generation:
46+
- **-m , --more** &rarr; feeds the simulation with advanced parameters provided to the configuration key flags
47+
- **-n , --nevents** &rarr; changes the number of events in the .optns file or gets the one in the file if no events are provided
48+
- **-i , --input** &rarr; .optns filename to feed EPOS4, no extension must be set in the filename
49+
- **-j , --jobs** &rarr; sets the number of workers (jobs)
50+
- **-h , --help** &rarr; prints usage instructions
51+
- **-e , --ecm** &rarr; sets the center-of-mass energy in the options file
52+
53+
In the `rundpg.sh` script an additional flag is available
54+
- **-t , --tf** &rarr; number of timeframes to be generated
55+
56+
In this case the options file will be copied in each tf$n folder, otherwise the epos script won't be able to run with multiple timeframes.
57+
In o2sim and DPG scripts the randomly generated seed is set directly, instead this is not feasible with the DPL one, given that the --seed option is not able to redirect this number to GeneratorHepMC. So a seed 0 is automatically given to epos.sh which generates a random number in return.
58+
59+
Now the three scripts start to differ:
60+
61+
- **runo2sim.sh** &rarr; o2-sim is launched
62+
- **rundpg.sh** &rarr; first the o2dpg_sim_workflow.py script will be launched generating the json configuration, then the o2_dpg_workflow_runner.py script will start the workflow
63+
- **rundpl.sh** &rarr; o2-sim-dpl-eventgen is executed piping its results to o2-sim-mctracks-to-aod and afterwards to o2-analysis-mctracks-to-aod-simple-task
64+
65+
The last few lines of the scripts contain the execution of o2-sim, DPG worflow creator/runner and DPL software respectively, so this part can be modified by the users following their requirements. It's important not to delete from the configuration keys `GeneratorFileOrCmd.cmd=$cmd -i $optns;GeneratorFileOrCmd.bMaxSwitch=none;HepMC.version=2;` and it would be better to provide additional configurations via the -m flag. EPOS4 cannot set a maximum impact parameter value, so it's better to leave the bMaxSwitch to none, while the others serve the sole purpose of running successfully the generator using auto generated FIFOs.
66+
67+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# Script based on CRMC example
3+
# EPOS4 option files must contain ihepmc set to 2 to print HepMC
4+
# data on stdout. -hepmc flag is not needed anymore, but -hepstd is fundamental
5+
# in order not to print useless information on stdout (a z-*optns*.mtr file will be created)
6+
7+
optns="example"
8+
seed=$RANDOM
9+
10+
while test $# -gt 0 ; do
11+
case $1 in
12+
-i|--input) optns=$2 ; shift ;;
13+
-s|--seed) seed=$2 ; shift ;;
14+
-h|--help) usage; exit 0 ;;
15+
esac
16+
shift
17+
done
18+
19+
if [ ! -f $optns.optns ]; then
20+
echo "Error: Options file $optns.optns not found"
21+
exit 1
22+
fi
23+
24+
if [ $seed -eq 0 ]; then
25+
echo "Seed can't be 0, random number will be used"
26+
seed=$RANDOM
27+
fi
28+
29+
# Or filters the stdout with only HepMC2 useful data
30+
$EPOS4_ROOT/epos4/scripts/epos -hepstd -s $seed $optns | sed -n 's/^\(HepMC::\|[EAUWVP] \)/\1/p'
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
!--------------------------------------------------------------------
2+
! proton-proton collision no hydro no hadronic cascade
3+
!--------------------------------------------------------------------
4+
5+
!---------------------------------------
6+
! Define run
7+
!---------------------------------------
8+
9+
application hadron !hadron-hadron, hadron-nucleus, or nucleus-nucleus
10+
set laproj 1 !projectile atomic number
11+
set maproj 1 !projectile mass number
12+
set latarg 1 !target atomic number
13+
set matarg 1 !target mass number
14+
set ecms 7000 !sqrt(s)_pp
15+
set istmax 25 !max status considered for storage
16+
17+
ftime on !string formation time non-zero
18+
!suppressed decays:
19+
nodecays
20+
110 20 2130 -2130 2230 -2230 1130 -1130 1330 -1330 2330 -2330 3331 -3331
21+
end
22+
23+
set ninicon 1 !number of initial conditions used for hydro evolution
24+
core off !core/corona not activated
25+
hydro off !hydro not activated
26+
eos off !eos not activated
27+
hacas off !hadronic cascade not activated
28+
set nfreeze 1 !number of freeze out events per hydro event
29+
set modsho 1 !printout every modsho events
30+
set centrality 0 !0=min bias
31+
set ihepmc 2 !HepMC output enabled on stdout
32+
set nfull 10
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This script shows how to start the DPG simulation machinery starting EPOS4
4+
# automatically while using the FIFOs generated internally by GeneratorHepMC
5+
6+
# This script works only with O2sim version starting from the 20/09/2024
7+
8+
set -x
9+
if [ ! "${EPOS4_ROOT}" ]; then
10+
echo "This needs EPOS4 loaded; alienv enter ..."
11+
exit 1
12+
fi
13+
14+
# make sure O2DPG + O2 is loaded
15+
[ ! "${O2DPG_ROOT}" ] && echo "Error: This needs O2DPG loaded" && exit 1
16+
[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 1
17+
18+
19+
cmd="$PWD/epos.sh"
20+
NEV=-1
21+
more=""
22+
optns="example"
23+
TF=1
24+
eCM=-1
25+
JOBS=2
26+
27+
usage()
28+
{
29+
cat <<EOF
30+
Usage: $0 [OPTIONS]
31+
32+
Options:
33+
34+
-m,--more CONFIG More configurations ($more)
35+
-n,--nevents EVENTS Number of events ($nev)
36+
-i,--input INPUT Options file fed to EPOS4 ($optns)
37+
-j,--jobs JOBS Number of jobs ($JOBS)
38+
-h,--help Print these instructions
39+
-e,--ecm ENERGY Center-of-Mass energy
40+
-t,--tf TF Timeframes ($TF)
41+
-- Rest of command line sent to o2-sim
42+
43+
COMMAND must be quoted if it contains spaces or other special
44+
characters
45+
46+
Below follows the help output of o2dpg_sim_workflow
47+
48+
EOF
49+
}
50+
51+
if [ "$#" -lt 2 ]; then
52+
echo "Running with default values"
53+
fi
54+
55+
while test $# -gt 0 ; do
56+
case $1 in
57+
-m|--more) more="$2" ; shift ;;
58+
-n|--nevents) NEV=$2 ; shift ;;
59+
-i|--input) optns=$2 ; shift ;;
60+
-j|--jobs) JOBS=$2 ; shift ;;
61+
-e|--ecm) eCM=$2 ; shift ;;
62+
-h|--help) usage; ${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py --help ; exit 0 ;;
63+
-t|--tf) TF=$2 ; shift ;;
64+
--) shift ; break ;;
65+
*) echo "Unknown option '$1', did you forget '--'?" >/dev/stderr
66+
exit 3
67+
;;
68+
esac
69+
shift
70+
done
71+
72+
echo "Options file: $optns"
73+
74+
if [ ! -f $optns.optns ]; then
75+
echo "Error: Options file $optns.optns not found"
76+
exit 4
77+
fi
78+
79+
# Set number of events in optns file
80+
if [ ! $NEV -eq -1 ]; then
81+
echo "Setting number of events to $NEV"
82+
if grep -Fq "nfull" $optns.optns; then
83+
sed -i "/nfull/c\set nfull $NEV" $optns.optns
84+
else
85+
echo "set nfull $NEV" >> $optns.optns
86+
fi
87+
else
88+
echo "Number of events not set, checking optns file..."
89+
if grep -Fq "nfull" $optns.optns; then
90+
NEV=$(grep -F "nfull" $optns.optns | awk '{print $3}')
91+
echo "Number of events set to $NEV"
92+
else
93+
echo "Error: Number of events not set in EPOS4"
94+
exit 5
95+
fi
96+
fi
97+
98+
# Set ECM
99+
100+
if [ ! $eCM -eq -1 ]; then
101+
echo "Setting eCM to $eCM"
102+
if grep -Fq "ecms" $optns.optns; then
103+
sed -i "/ecms/c\set ecms $eCM" $optns.optns
104+
else
105+
echo "set ecms $eCM" >> $optns.optns
106+
fi
107+
else
108+
echo "Energy not set, checking optns file..."
109+
if grep -Fq "ecms" $optns.optns; then
110+
eCM=$(grep -F "ecms" $optns.optns | awk '{print $3}')
111+
echo "Energy set to $eCM"
112+
else
113+
echo "Error: eCM not set in EPOS4"
114+
exit 6
115+
fi
116+
fi
117+
118+
# Copy options file in each timeframe folder
119+
for i in $(seq 1 $TF); do
120+
if [ ! -d tf$i ]; then
121+
mkdir tf$i
122+
fi
123+
cp $optns.optns tf$i/$optns.optns
124+
done
125+
126+
# create workflow
127+
128+
${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py -eCM $eCM -ns $NEV -gen hepmc -tf $TF -j $JOBS \
129+
-interactionRate 500000 -confKey "GeneratorFileOrCmd.cmd=$cmd -i $optns;GeneratorFileOrCmd.bMaxSwitch=none;HepMC.version=2;${more}"
130+
131+
# Run workflow
132+
${O2DPG_ROOT}/MC/bin/o2_dpg_workflow_runner.py -f workflow.json -tt aod --stdout-on-failure
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This is a simple simulation example showing how to
4+
# start EPOS4 generation automatically using cmd with hepmc output on FIFO
5+
# and simultaneosly use o2-sim for transport
6+
7+
# This script works only with O2sim version starting from the 20/09/2024
8+
9+
# EPOS4 and O2 must be loaded
10+
set -x
11+
if [ ! "${EPOS4_ROOT}" ]; then
12+
echo "This needs EPOS4 loaded; alienv enter ..."
13+
exit 1
14+
fi
15+
16+
[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 2
17+
18+
cmd="$PWD/epos.sh"
19+
NEV=-1
20+
more=""
21+
optns="example"
22+
eCM=-1
23+
JOBS=2
24+
25+
usage()
26+
{
27+
cat <<EOF
28+
Usage: $0 [OPTIONS]
29+
30+
Options:
31+
32+
-m,--more CONFIG More configurations ($more)
33+
-n,--nevents EVENTS Number of events ($nev)
34+
-i,--input INPUT Options file fed to EPOS4 ($optns)
35+
-j,--jobs JOBS Number of jobs ($JOBS)
36+
-e,--ecm ENERGY Center-of-Mass energy
37+
-h,--help Print these instructions
38+
-- Rest of command line sent to o2-sim
39+
40+
COMMAND must be quoted if it contains spaces or other special
41+
characters
42+
43+
Below follows the help output of o2-sim-dpl-eventgen
44+
45+
EOF
46+
}
47+
48+
if [ "$#" -lt 2 ]; then
49+
echo "Running with default values"
50+
fi
51+
52+
while test $# -gt 0 ; do
53+
case $1 in
54+
-m|--more) more="$2" ; shift ;;
55+
-n|--nevents) NEV=$2 ; shift ;;
56+
-i|--input) optns=$2 ; shift ;;
57+
-j|--jobs) JOBS=$2 ; shift ;;
58+
-e|--ecm) eCM=$2 ; shift ;;
59+
-h|--help) usage; o2-sim-dpl-eventgen --help full ; exit 0 ;;
60+
--) shift ; break ;;
61+
*) echo "Unknown option '$1', did you forget '--'?" >/dev/stderr
62+
exit 3
63+
;;
64+
esac
65+
shift
66+
done
67+
68+
echo "Options file: $optns"
69+
70+
if [ ! -f $optns.optns ]; then
71+
echo "Error: Options file $optns.optns not found"
72+
exit 4
73+
fi
74+
75+
# Set number of events in optns file
76+
if [ ! $NEV -eq -1 ]; then
77+
echo "Setting number of events to $NEV"
78+
if grep -Fq "nfull" $optns.optns; then
79+
sed -i "/nfull/c\set nfull $NEV" $optns.optns
80+
else
81+
echo "set nfull $NEV" >> $optns.optns
82+
fi
83+
else
84+
echo "Number of events not set, checking optns file..."
85+
if grep -Fq "nfull" $optns.optns; then
86+
NEV=$(grep -F "nfull" $optns.optns | awk '{print $3}')
87+
echo "Number of events set to $NEV"
88+
else
89+
echo "Error: Number of events not set in EPOS4"
90+
exit 5
91+
fi
92+
fi
93+
94+
# Set ECM
95+
96+
if [ ! $eCM -eq -1 ]; then
97+
echo "Setting eCM to $eCM"
98+
if grep -Fq "ecms" $optns.optns; then
99+
sed -i "/ecms/c\set ecms $eCM" $optns.optns
100+
else
101+
echo "set ecms $eCM" >> $optns.optns
102+
fi
103+
else
104+
echo "Energy not set, checking optns file..."
105+
if grep -Fq "ecms" $optns.optns; then
106+
eCM=$(grep -F "ecms" $optns.optns | awk '{print $3}')
107+
echo "Energy set to $eCM"
108+
else
109+
echo "Error: eCM not set in EPOS4"
110+
exit 6
111+
fi
112+
fi
113+
114+
# Starting simulation => seed is fed automatically to epos with the --seed flag. HepMC.version = 2 is mandatory
115+
# otherwise the simulation won't work.
116+
# Seed is automatically set to Random by the epos.sh script because the --seed option with o2-sim-dpl-eventgen does not feed the number to GeneratorHepMC
117+
118+
o2-sim-dpl-eventgen -b --nEvents ${NEV} --generator hepmc --configKeyValues "GeneratorFileOrCmd.cmd=$cmd -i $optns;GeneratorFileOrCmd.bMaxSwitch=none;HepMC.version=2;${more}" |\
119+
o2-sim-mctracks-to-aod -b | o2-analysis-mctracks-to-aod-simple-task -b

0 commit comments

Comments
 (0)