Skip to content

Commit 74684c5

Browse files
committed
Better support to treat events from HepMC event files (multi-timeframe case)
Some users give existing .hepmc files to the event generator. So far, this was problematic because separate timeframes will read from the same file and due to a lack of synchronization, each timeframe read the same events. This is now fixed. Whenever an hepmc event file is given as input to O2DPG-MC, we make sure that timeframes read from the HepMC file incrementally. This is achieved through: - sequentially producing events for timeframes - communication of the number processed from one timeframe to the next (via HepMCEventSkip.json file).
1 parent 370b6e6 commit 74684c5

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

MC/bin/o2dpg_sim_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ def add(cfg, flatconfig):
108108
d[sk] = flatconfig[entry]
109109
cfg[mk] = d
110110

111+
# ----- special setting for hepmc generator -----
112+
if args.gen == "hepmc":
113+
eventSkipPresent = config.get("HepMC",{}).get("eventsToSkip")
114+
if eventSkipPresent == None:
115+
# add it
116+
add(config, {"HepMC.eventsToSkip" : '${HEPMCEVENTSKIP:-0}'})
117+
111118
# ----- add default settings -----
112119

113120
add(config, {"MFTBase.buildAlignment" : "true"})

MC/bin/o2dpg_sim_workflow.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,29 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True):
715715

716716
# (separate) event generation task
717717
sep_event_mode = args.event_gen_mode == 'separated'
718-
SGNGENtask=createTask(name='sgngen_'+str(tf), needs=signalneeds, tf=tf, cwd='tf'+str(tf), lab=["GEN"],
718+
sgngenneeds=signalneeds
719+
# for HepMC we need some special treatment since we need
720+
# to ensure that different timeframes read different events from this file
721+
if GENERATOR=="hepmc" and tf > 1:
722+
sgngenneeds=signalneeds + ['sgngen_' + str(tf-1)] # we serialize event generation
723+
SGNGENtask=createTask(name='sgngen_'+str(tf), needs=sgngenneeds, tf=tf, cwd='tf'+str(tf), lab=["GEN"],
719724
cpu=1, mem=1000)
720-
SGNGENtask['cmd']='${O2_ROOT}/bin/o2-sim --noGeant -j 1 --field ccdb --vertexMode kCCDB' \
725+
726+
SGNGENtask['cmd']=''
727+
if GENERATOR=="hepmc" and tf > 1:
728+
# determine the skip number
729+
cmd = 'export HEPMCEVENTSKIP=$(${O2DPG_ROOT}/UTILS/ReadHepMCEventSkip.sh ../HepMCEventSkip.json ' + str(tf) + ');'
730+
SGNGENtask['cmd'] = cmd
731+
SGNGENtask['cmd'] +='${O2_ROOT}/bin/o2-sim --noGeant -j 1 --field ccdb --vertexMode kCCDB' \
721732
+ ' --run ' + str(args.run) + ' ' + str(CONFKEY) + str(TRIGGER) \
722733
+ ' -g ' + str(GENERATOR) + ' ' + str(INIFILE) + ' -o genevents ' + embeddinto \
723734
+ ('', ' --timestamp ' + str(args.timestamp))[args.timestamp!=-1] \
724735
+ ' --seed ' + str(TFSEED) + ' -n ' + str(NSIGEVENTS)
736+
725737
if args.pregenCollContext == True:
726738
SGNGENtask['cmd'] += ' --fromCollContext collisioncontext.root:' + signalprefix
739+
if GENERATOR=="hepmc":
740+
SGNGENtask['cmd'] += "; RC=$?; ${O2DPG_ROOT}/UTILS/UpdateHepMCEventSkip.sh ../HepMCEventSkip.json " + str(tf) + '; [[ ${RC} == 0 ]]'
727741
if sep_event_mode == True:
728742
workflow['stages'].append(SGNGENtask)
729743
signalneeds = signalneeds + [SGNGENtask['name']]
@@ -742,7 +756,6 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True):
742756
SGNtask['cmd'] += ' --readoutDetectors ' + " ".join(activeDetectors)
743757
if args.pregenCollContext == True:
744758
SGNtask['cmd'] += ' --fromCollContext collisioncontext.root'
745-
746759
workflow['stages'].append(SGNtask)
747760

748761
# some tasks further below still want geometry + grp in fixed names, so we provide it here

UTILS/ReadHepMCEventSkip.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Path to the JSON file
4+
JSON_FILE=$1
5+
tf=$2
6+
JQCOMMAND="jq '[.[] | select(.tf < ${tf}) | .HepMCEventCount] | add' ${JSON_FILE}"
7+
eval ${JQCOMMAND}

UTILS/UpdateHepMCEventSkip.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# Path to the JSON file
4+
JSON_FILE=${1:-HepMC_EventSkip_ALT.json}
5+
tf=$2
6+
7+
# Value to set or add
8+
EVENTS=$(grep "DISTRIBUTING" ../tf${tf}/sgngen_*.log | tail -n 1 | awk '//{print $5}')
9+
10+
[ -f $JSON_FILE ] || echo "[]" > ${JSON_FILE} # init json file if it doesn't exist
11+
# insert event count ... if a count for this tf does not already exist
12+
JQ_COMMAND="jq 'if any(.[]; .tf == ${tf}) then . else . + [{\"tf\": ${tf}, "HepMCEventCount": ${EVENTS}}] end' ${JSON_FILE} > tmp_123.json; mv tmp_123.json ${JSON_FILE}"
13+
eval ${JQ_COMMAND}

0 commit comments

Comments
 (0)