Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions run/SimExamples/HepMC_EPOS4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!-- doxy
\page refrunSimExamplesHepMC_EPOS4 Example HepMC_EPOS4
/doxy -->

The usage of EPOS4 with the O2 machinery is presented in this short manual.
An in-depth explanation of the mechanisms behind the HepMC(3) data handling can be found in the
HepMC_fifo folder of the MC examples. The scripts use the `cmd` parameter of `GeneratorHepMC`
to spawn the EPOS4 generation via the `epos.sh` script.

EPOS4 uses the outdated HepMC2 libraries, so this had to be specified in the steering scripts
of the generators configuration. If `HepMC.version=2` is removed then the scripts will not work
anymore. This is to say that the balance achieved with the configurations provided is easily
destroyed if the user base edits parts that are not understood completely.

# Scripts description

Four scripts are available to run the simulations
- **epos.sh** &rarr; starts the actual EPOS4 generation
- **runo2sim.sh** &rarr; allows the generation of events using o2-sim
- **rundpg.sh** &rarr; starts the DPG machinery for event generation
- **rundpl.sh** &rarr; starts the event generation with DPL

In addition an example.optns file is provided to start EPOS4, but more can be found in the generator example folder
or in the website [epos4learn.web.cern.ch](https://epos4learn.docs.cern.ch/) where an extensive tutorial on the generator is provided.

## epos.sh

It can be run without the help of the other scripts to simply generate an .hepmc file or print
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:
```
./epos.sh -i test -s 234345 > test.hepmc
```
This example shows all the functionalities of the script (which are implemented in a similar way inside
the generation steering scripts). In particular the `-i` flag allows to provide .optns parameters to EPOS4,
`-s` feeds the generator with a user seed, and the HepMC output is given by test.hepmc by redirecting the
stdout which will contain only the HepMC data thanks to the `-hepstd` flag set automatically in epos.sh and
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 ).

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.

## runo2sim.sh, rundpg.sh and rundpl.sh

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.

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:
- **-m , --more** &rarr; feeds the simulation with advanced parameters provided to the configuration key flags
- **-n , --nevents** &rarr; changes the number of events in the .optns file or gets the one in the file if no events are provided
- **-i , --input** &rarr; .optns filename to feed EPOS4, no extension must be set in the filename
- **-j , --jobs** &rarr; sets the number of workers (jobs)
- **-h , --help** &rarr; prints usage instructions
- **-e , --ecm** &rarr; sets the center-of-mass energy in the options file

In the `rundpg.sh` script an additional flag is available
- **-t , --tf** &rarr; number of timeframes to be generated

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.
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.

Now the three scripts start to differ:

- **runo2sim.sh** &rarr; o2-sim is launched
- **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
- **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

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.


30 changes: 30 additions & 0 deletions run/SimExamples/HepMC_EPOS4/epos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
# Script based on CRMC example
# EPOS4 option files must contain ihepmc set to 2 to print HepMC
# data on stdout. -hepmc flag is not needed anymore, but -hepstd is fundamental
# in order not to print useless information on stdout (a z-*optns*.mtr file will be created)

optns="example"
seed=$RANDOM

while test $# -gt 0 ; do
case $1 in
-i|--input) optns=$2 ; shift ;;
-s|--seed) seed=$2 ; shift ;;
-h|--help) usage; exit 0 ;;
esac
shift
done

if [ ! -f $optns.optns ]; then
echo "Error: Options file $optns.optns not found"
exit 1
fi

if [ $seed -eq 0 ]; then
echo "Seed can't be 0, random number will be used"
seed=$RANDOM
fi

# Or filters the stdout with only HepMC2 useful data
$EPOS4_ROOT/epos4/scripts/epos -hepstd -s $seed $optns | sed -n 's/^\(HepMC::\|[EAUWVP] \)/\1/p'
32 changes: 32 additions & 0 deletions run/SimExamples/HepMC_EPOS4/example.optns
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
!--------------------------------------------------------------------
! proton-proton collision no hydro no hadronic cascade
!--------------------------------------------------------------------

!---------------------------------------
! Define run
!---------------------------------------

application hadron !hadron-hadron, hadron-nucleus, or nucleus-nucleus
set laproj 1 !projectile atomic number
set maproj 1 !projectile mass number
set latarg 1 !target atomic number
set matarg 1 !target mass number
set ecms 7000 !sqrt(s)_pp
set istmax 25 !max status considered for storage

ftime on !string formation time non-zero
!suppressed decays:
nodecays
110 20 2130 -2130 2230 -2230 1130 -1130 1330 -1330 2330 -2330 3331 -3331
end

set ninicon 1 !number of initial conditions used for hydro evolution
core off !core/corona not activated
hydro off !hydro not activated
eos off !eos not activated
hacas off !hadronic cascade not activated
set nfreeze 1 !number of freeze out events per hydro event
set modsho 1 !printout every modsho events
set centrality 0 !0=min bias
set ihepmc 2 !HepMC output enabled on stdout
set nfull 10
132 changes: 132 additions & 0 deletions run/SimExamples/HepMC_EPOS4/rundpg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env bash
#
# This script shows how to start the DPG simulation machinery starting EPOS4
# automatically while using the FIFOs generated internally by GeneratorHepMC

# This script works only with O2sim version starting from the 20/09/2024

set -x
if [ ! "${EPOS4_ROOT}" ]; then
echo "This needs EPOS4 loaded; alienv enter ..."
exit 1
fi

# make sure O2DPG + O2 is loaded
[ ! "${O2DPG_ROOT}" ] && echo "Error: This needs O2DPG loaded" && exit 1
[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 1


cmd="$PWD/epos.sh"
NEV=-1
more=""
optns="example"
TF=1
eCM=-1
JOBS=2

usage()
{
cat <<EOF
Usage: $0 [OPTIONS]

Options:

-m,--more CONFIG More configurations ($more)
-n,--nevents EVENTS Number of events ($nev)
-i,--input INPUT Options file fed to EPOS4 ($optns)
-j,--jobs JOBS Number of jobs ($JOBS)
-h,--help Print these instructions
-e,--ecm ENERGY Center-of-Mass energy
-t,--tf TF Timeframes ($TF)
-- Rest of command line sent to o2-sim

COMMAND must be quoted if it contains spaces or other special
characters

Below follows the help output of o2dpg_sim_workflow

EOF
}

if [ "$#" -lt 2 ]; then
echo "Running with default values"
fi

while test $# -gt 0 ; do
case $1 in
-m|--more) more="$2" ; shift ;;
-n|--nevents) NEV=$2 ; shift ;;
-i|--input) optns=$2 ; shift ;;
-j|--jobs) JOBS=$2 ; shift ;;
-e|--ecm) eCM=$2 ; shift ;;
-h|--help) usage; ${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py --help ; exit 0 ;;
-t|--tf) TF=$2 ; shift ;;
--) shift ; break ;;
*) echo "Unknown option '$1', did you forget '--'?" >/dev/stderr
exit 3
;;
esac
shift
done

echo "Options file: $optns"

if [ ! -f $optns.optns ]; then
echo "Error: Options file $optns.optns not found"
exit 4
fi

# Set number of events in optns file
if [ ! $NEV -eq -1 ]; then
echo "Setting number of events to $NEV"
if grep -Fq "nfull" $optns.optns; then
sed -i "/nfull/c\set nfull $NEV" $optns.optns
else
echo "set nfull $NEV" >> $optns.optns
fi
else
echo "Number of events not set, checking optns file..."
if grep -Fq "nfull" $optns.optns; then
NEV=$(grep -F "nfull" $optns.optns | awk '{print $3}')
echo "Number of events set to $NEV"
else
echo "Error: Number of events not set in EPOS4"
exit 5
fi
fi

# Set ECM

if [ ! $eCM -eq -1 ]; then
echo "Setting eCM to $eCM"
if grep -Fq "ecms" $optns.optns; then
sed -i "/ecms/c\set ecms $eCM" $optns.optns
else
echo "set ecms $eCM" >> $optns.optns
fi
else
echo "Energy not set, checking optns file..."
if grep -Fq "ecms" $optns.optns; then
eCM=$(grep -F "ecms" $optns.optns | awk '{print $3}')
echo "Energy set to $eCM"
else
echo "Error: eCM not set in EPOS4"
exit 6
fi
fi

# Copy options file in each timeframe folder
for i in $(seq 1 $TF); do
if [ ! -d tf$i ]; then
mkdir tf$i
fi
cp $optns.optns tf$i/$optns.optns
done

# create workflow

${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py -eCM $eCM -ns $NEV -gen hepmc -tf $TF -j $JOBS \
-interactionRate 500000 -confKey "GeneratorFileOrCmd.cmd=$cmd -i $optns;GeneratorFileOrCmd.bMaxSwitch=none;HepMC.version=2;${more}"

# Run workflow
${O2DPG_ROOT}/MC/bin/o2_dpg_workflow_runner.py -f workflow.json -tt aod --stdout-on-failure
119 changes: 119 additions & 0 deletions run/SimExamples/HepMC_EPOS4/rundpl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env bash
#
# This is a simple simulation example showing how to
# start EPOS4 generation automatically using cmd with hepmc output on FIFO
# and simultaneosly use o2-sim for transport

# This script works only with O2sim version starting from the 20/09/2024

# EPOS4 and O2 must be loaded
set -x
if [ ! "${EPOS4_ROOT}" ]; then
echo "This needs EPOS4 loaded; alienv enter ..."
exit 1
fi

[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 2

cmd="$PWD/epos.sh"
NEV=-1
more=""
optns="example"
eCM=-1
JOBS=2

usage()
{
cat <<EOF
Usage: $0 [OPTIONS]

Options:

-m,--more CONFIG More configurations ($more)
-n,--nevents EVENTS Number of events ($nev)
-i,--input INPUT Options file fed to EPOS4 ($optns)
-j,--jobs JOBS Number of jobs ($JOBS)
-e,--ecm ENERGY Center-of-Mass energy
-h,--help Print these instructions
-- Rest of command line sent to o2-sim

COMMAND must be quoted if it contains spaces or other special
characters

Below follows the help output of o2-sim-dpl-eventgen

EOF
}

if [ "$#" -lt 2 ]; then
echo "Running with default values"
fi

while test $# -gt 0 ; do
case $1 in
-m|--more) more="$2" ; shift ;;
-n|--nevents) NEV=$2 ; shift ;;
-i|--input) optns=$2 ; shift ;;
-j|--jobs) JOBS=$2 ; shift ;;
-e|--ecm) eCM=$2 ; shift ;;
-h|--help) usage; o2-sim-dpl-eventgen --help full ; exit 0 ;;
--) shift ; break ;;
*) echo "Unknown option '$1', did you forget '--'?" >/dev/stderr
exit 3
;;
esac
shift
done

echo "Options file: $optns"

if [ ! -f $optns.optns ]; then
echo "Error: Options file $optns.optns not found"
exit 4
fi

# Set number of events in optns file
if [ ! $NEV -eq -1 ]; then
echo "Setting number of events to $NEV"
if grep -Fq "nfull" $optns.optns; then
sed -i "/nfull/c\set nfull $NEV" $optns.optns
else
echo "set nfull $NEV" >> $optns.optns
fi
else
echo "Number of events not set, checking optns file..."
if grep -Fq "nfull" $optns.optns; then
NEV=$(grep -F "nfull" $optns.optns | awk '{print $3}')
echo "Number of events set to $NEV"
else
echo "Error: Number of events not set in EPOS4"
exit 5
fi
fi

# Set ECM

if [ ! $eCM -eq -1 ]; then
echo "Setting eCM to $eCM"
if grep -Fq "ecms" $optns.optns; then
sed -i "/ecms/c\set ecms $eCM" $optns.optns
else
echo "set ecms $eCM" >> $optns.optns
fi
else
echo "Energy not set, checking optns file..."
if grep -Fq "ecms" $optns.optns; then
eCM=$(grep -F "ecms" $optns.optns | awk '{print $3}')
echo "Energy set to $eCM"
else
echo "Error: eCM not set in EPOS4"
exit 6
fi
fi

# Starting simulation => seed is fed automatically to epos with the --seed flag. HepMC.version = 2 is mandatory
# otherwise the simulation won't work.
# 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

o2-sim-dpl-eventgen -b --nEvents ${NEV} --generator hepmc --configKeyValues "GeneratorFileOrCmd.cmd=$cmd -i $optns;GeneratorFileOrCmd.bMaxSwitch=none;HepMC.version=2;${more}" |\
o2-sim-mctracks-to-aod -b | o2-analysis-mctracks-to-aod-simple-task -b
Loading