|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# This is a simple simulation example on how to generate HEPMC3 data from |
| 4 | +# HERWIG7 and run an ALICE simulation using the o2-sim executable |
| 5 | +# In the script we assume that the .run file has the same name of the input file, so change it accordingly. |
| 6 | +# This script works only with AliGenO2 version containing the HERWIG7 generator |
| 7 | + |
| 8 | +# HERWIG7 and O2 must be loaded |
| 9 | +set -x |
| 10 | +if [ ! "${HERWIG_ROOT}" ]; then |
| 11 | + echo "This needs HERWIG7 loaded; alienv enter ..." |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 2 |
| 16 | + |
| 17 | +NEV=-1 |
| 18 | +more="" |
| 19 | +input="LHC" |
| 20 | +eCM=-1 |
| 21 | +JOBS=2 |
| 22 | + |
| 23 | +usage() |
| 24 | +{ |
| 25 | + cat <<EOF |
| 26 | +Usage: $0 [OPTIONS] |
| 27 | +
|
| 28 | +Options: |
| 29 | +
|
| 30 | + -m,--more CONFIG More configurations ($more) |
| 31 | + -n,--nevents EVENTS Number of events ($nev) |
| 32 | + -i,--input INPUT Options file fed to HERWIG7 ($input) |
| 33 | + -j,--jobs JOBS Number of jobs ($JOBS) |
| 34 | + -e,--ecm ENERGY Center-of-Mass energy |
| 35 | + -h,--help Print these instructions |
| 36 | + -- Rest of command line sent to o2-sim |
| 37 | +
|
| 38 | +COMMAND must be quoted if it contains spaces or other special |
| 39 | +characters |
| 40 | +
|
| 41 | +Below follows the help output of o2-sim |
| 42 | +
|
| 43 | +EOF |
| 44 | +} |
| 45 | + |
| 46 | +if [ "$#" -lt 2 ]; then |
| 47 | + echo "Running with default values" |
| 48 | +fi |
| 49 | + |
| 50 | +while test $# -gt 0 ; do |
| 51 | + case $1 in |
| 52 | + -m|--more) more="$2" ; shift ;; |
| 53 | + -n|--nevents) NEV=$2 ; shift ;; |
| 54 | + -i|--input) input=$2 ; shift ;; |
| 55 | + -j|--jobs) JOBS=$2 ; shift ;; |
| 56 | + -e|--ecm) eCM=$2 ; shift ;; |
| 57 | + -h|--help) usage; o2-sim --help full ; exit 0 ;; |
| 58 | + --) shift ; break ;; |
| 59 | + *) echo "Unknown option '$1', did you forget '--'?" >/dev/stderr |
| 60 | + exit 3 |
| 61 | + ;; |
| 62 | + esac |
| 63 | + shift |
| 64 | +done |
| 65 | + |
| 66 | +echo "Input file: $input" |
| 67 | + |
| 68 | +if [ ! -f $input.in ]; then |
| 69 | + echo "Error: Input file $input.in not found" |
| 70 | + exit 4 |
| 71 | +else |
| 72 | + if grep -Fq "saverun" $input.in; then |
| 73 | + sed -i "/saverun/c\saverun $input EventGenerator" $input.in |
| 74 | + else |
| 75 | + echo "saverun $input EventGenerator" >> $input.in |
| 76 | + fi |
| 77 | +fi |
| 78 | + |
| 79 | +# Set number of events to write in HepMC in input file |
| 80 | +if [ ! $NEV -eq -1 ]; then |
| 81 | + echo "Setting number of events to $NEV" |
| 82 | + if grep -Fq "PrintEvent" $input.in; then |
| 83 | + sed -i "/PrintEvent/c\set /Herwig/Analysis/HepMC:PrintEvent $NEV" $input.in |
| 84 | + else |
| 85 | + echo "set /Herwig/Analysis/HepMC:PrintEvent $NEV" >> $input.in |
| 86 | + fi |
| 87 | +else |
| 88 | + echo "Number of events not set, checking input file..." |
| 89 | + if grep -Fq "PrintEvent" $input.in; then |
| 90 | + NEV=$(grep -F "PrintEvent" $input.in | awk '{print $3}') |
| 91 | + echo "Number of events set to $NEV" |
| 92 | + else |
| 93 | + echo "Error: Number of events not set in HERWIG7" |
| 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 "Energy" $input.in; then |
| 103 | + sed -i "/Energy/c\set EventGenerator:EventHandler:LuminosityFunction:Energy $eCM" $input.in |
| 104 | + else |
| 105 | + echo "set EventGenerator:EventHandler:LuminosityFunction:Energy $eCM" >> $input.in |
| 106 | + fi |
| 107 | +else |
| 108 | + echo "Energy not set, checking input file..." |
| 109 | + if grep -Fq "Energy" $input.in; then |
| 110 | + eCM=$(grep -F "Energy" $input.in | awk '{print $3}') |
| 111 | + echo "Energy set to $eCM" |
| 112 | + else |
| 113 | + echo "Error: eCM not set in HERWIG7" |
| 114 | + exit 6 |
| 115 | + fi |
| 116 | +fi |
| 117 | + |
| 118 | +# Generating events using HERWIG7 |
| 119 | +Herwig read --repo=${HERWIG_ROOT}/share/Herwig/HerwigDefaults.rpo $input.in |
| 120 | +Herwig run -N $NEV $input.run |
| 121 | + |
| 122 | +# Starting simulation with o2-sim |
| 123 | +o2-sim -j $JOBS -n ${NEV} -g hepmc \ |
| 124 | + --configKeyValues "GeneratorFileOrCmd.fileNames=herwig.hepmc;${more}" |
0 commit comments