Skip to content

Commit c8d9fa3

Browse files
sawenzelalcaliva
authored andcommitted
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). (cherry picked from commit 74684c5)
1 parent df71dae commit c8d9fa3

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
@@ -704,15 +704,29 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True):
704704

705705
# (separate) event generation task
706706
sep_event_mode = args.event_gen_mode == 'separated'
707-
SGNGENtask=createTask(name='sgngen_'+str(tf), needs=signalneeds, tf=tf, cwd='tf'+str(tf), lab=["GEN"],
707+
sgngenneeds=signalneeds
708+
# for HepMC we need some special treatment since we need
709+
# to ensure that different timeframes read different events from this file
710+
if GENERATOR=="hepmc" and tf > 1:
711+
sgngenneeds=signalneeds + ['sgngen_' + str(tf-1)] # we serialize event generation
712+
SGNGENtask=createTask(name='sgngen_'+str(tf), needs=sgngenneeds, tf=tf, cwd='tf'+str(tf), lab=["GEN"],
708713
cpu=1, mem=1000)
709-
SGNGENtask['cmd']='${O2_ROOT}/bin/o2-sim --noGeant -j 1 --field ccdb --vertexMode kCCDB' \
714+
715+
SGNGENtask['cmd']=''
716+
if GENERATOR=="hepmc" and tf > 1:
717+
# determine the skip number
718+
cmd = 'export HEPMCEVENTSKIP=$(${O2DPG_ROOT}/UTILS/ReadHepMCEventSkip.sh ../HepMCEventSkip.json ' + str(tf) + ');'
719+
SGNGENtask['cmd'] = cmd
720+
SGNGENtask['cmd'] +='${O2_ROOT}/bin/o2-sim --noGeant -j 1 --field ccdb --vertexMode kCCDB' \
710721
+ ' --run ' + str(args.run) + ' ' + str(CONFKEY) + str(TRIGGER) \
711722
+ ' -g ' + str(GENERATOR) + ' ' + str(INIFILE) + ' -o genevents ' + embeddinto \
712723
+ ('', ' --timestamp ' + str(args.timestamp))[args.timestamp!=-1] \
713724
+ ' --seed ' + str(TFSEED) + ' -n ' + str(NSIGEVENTS)
725+
714726
if args.pregenCollContext == True:
715727
SGNGENtask['cmd'] += ' --fromCollContext collisioncontext.root:' + signalprefix
728+
if GENERATOR=="hepmc":
729+
SGNGENtask['cmd'] += "; RC=$?; ${O2DPG_ROOT}/UTILS/UpdateHepMCEventSkip.sh ../HepMCEventSkip.json " + str(tf) + '; [[ ${RC} == 0 ]]'
716730
if sep_event_mode == True:
717731
workflow['stages'].append(SGNGENtask)
718732
signalneeds = signalneeds + [SGNGENtask['name']]
@@ -731,7 +745,6 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True):
731745
SGNtask['cmd'] += ' --readoutDetectors ' + " ".join(activeDetectors)
732746
if args.pregenCollContext == True:
733747
SGNtask['cmd'] += ' --fromCollContext collisioncontext.root'
734-
735748
workflow['stages'].append(SGNtask)
736749

737750
# 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)