From b9a29e884d4bf76022634a68f826f54ced82854d Mon Sep 17 00:00:00 2001 From: swenzel Date: Wed, 31 Jan 2024 15:57:31 +0100 Subject: [PATCH] Possibility to take external config for Pythia8 In case of generator pythia8, we have so far always constructed a Pythia8 config file from the parameters given to o2dpg_sim_workflow.py However, some expert users may want to use an external configuration for Pythia8. This commit provides the possibility to do so via sensitivity to the `GeneratorPythia8.config` ConfigurableParam (so far ignored). An example is: ``` ${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py -eCM 14000 -col pp -gen pythia8 -proc cdiff -tf 2 \ -ns 20 -e ${SIMENGINE} \ -j ${NWORKERS} -interactionRate 500000 \ -run 302000 -seed 624 \ -confKey "GeneratorPythia8.config=/SOMEPATH/pythia8_powheg.cfg" ``` The new feature allows expert studies with specially setup Pythia8 configs. The development was motivated from https://its.cern.ch/jira/browse/O2-4549 However, note that options `-proc` `-eCM` etc. might have no effect or are ignored in such cases. --- MC/bin/o2dpg_sim_config.py | 2 ++ MC/bin/o2dpg_sim_workflow.py | 48 +++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/MC/bin/o2dpg_sim_config.py b/MC/bin/o2dpg_sim_config.py index d065998e8..22017086d 100755 --- a/MC/bin/o2dpg_sim_config.py +++ b/MC/bin/o2dpg_sim_config.py @@ -97,6 +97,8 @@ def create_geant_config(args, externalConfigString): # creates generic transport simulation config key values # based on arguments args (run number, energy, ...) originally passed # to o2dpg_sim_workflow.py + # + # returns a dictionary of mainkey -> dictionary of subkey : values config = {} def add(cfg, flatconfig): for entry in flatconfig: diff --git a/MC/bin/o2dpg_sim_workflow.py b/MC/bin/o2dpg_sim_workflow.py index 19a2e9b9a..4fe8781ee 100755 --- a/MC/bin/o2dpg_sim_workflow.py +++ b/MC/bin/o2dpg_sim_workflow.py @@ -21,7 +21,7 @@ import importlib.util import argparse from os import environ, mkdir, getcwd -from os.path import join, dirname, isdir +from os.path import join, dirname, isdir, isabs import random import json import itertools @@ -505,6 +505,9 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True): workflow['stages'].append(TPC_SPACECHARGE_DOWNLOADER_TASK) +# query initial configKey args for signal transport; mainly used to setup generators +simInitialConfigKeys = create_geant_config(args, args.confKey) + # loop over timeframes for tf in range(1, NTIMEFRAMES + 1): TFSEED = SIMSEED + tf @@ -627,19 +630,30 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True): SGN_CONFIG_task=createTask(name='gensgnconf_'+str(tf), tf=tf, cwd=timeframeworkdir) SGN_CONFIG_task['cmd'] = 'echo "placeholder / dummy task"' if GENERATOR == 'pythia8': - SGN_CONFIG_task['cmd'] = '${O2DPG_ROOT}/MC/config/common/pythia8/utils/mkpy8cfg.py \ - --output=pythia8.cfg \ - --seed='+str(TFSEED)+' \ - --idA='+str(PDGA)+' \ - --idB='+str(PDGB)+' \ - --eCM='+str(ECMS)+' \ - --eA='+str(EBEAMA)+' \ - --eB='+str(EBEAMB)+' \ - --process='+str(PROCESS)+' \ - --ptHatMin='+str(PTHATMIN)+' \ - --ptHatMax='+str(PTHATMAX) - if WEIGHTPOW > 0: - SGN_CONFIG_task['cmd'] = SGN_CONFIG_task['cmd'] + ' --weightPow=' + str(WEIGHTPOW) + # see if config is given externally + externalPythia8Config = simInitialConfigKeys.get("GeneratorPythia8", {}).get("config", None) + if externalPythia8Config != None: + # check if this refers to a file with ABSOLUTE path + if not isabs(externalPythia8Config): + print ('Error: Argument to GeneratorPythia8.config must be absolute path') + exit (1) + # in this case, we copy the external config to the local dir (maybe not even necessary) + SGN_CONFIG_task['cmd'] = 'cp ' + externalPythia8Config + ' pythia8.cfg' + else: + SGN_CONFIG_task['cmd'] = '${O2DPG_ROOT}/MC/config/common/pythia8/utils/mkpy8cfg.py \ + --output=pythia8.cfg \ + --seed='+str(TFSEED)+' \ + --idA='+str(PDGA)+' \ + --idB='+str(PDGB)+' \ + --eCM='+str(ECMS)+' \ + --eA='+str(EBEAMA)+' \ + --eB='+str(EBEAMB)+' \ + --process='+str(PROCESS)+' \ + --ptHatMin='+str(PTHATMIN)+' \ + --ptHatMax='+str(PTHATMAX) + if WEIGHTPOW > 0: + SGN_CONFIG_task['cmd'] = SGN_CONFIG_task['cmd'] + ' --weightPow=' + str(WEIGHTPOW) + # if we configure pythia8 here --> we also need to adjust the configuration # TODO: we need a proper config container/manager so as to combine these local configs with external configs etc. args.confKey = args.confKey + ";GeneratorPythia8.config=pythia8.cfg" @@ -647,9 +661,11 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True): # elif GENERATOR == 'extgen': what do we do if generator is not pythia8? # NOTE: Generator setup might be handled in a different file or different files (one per # possible generator) - workflow['stages'].append(SGN_CONFIG_task) + # determine final conf key for signal simulation + CONFKEY = constructConfigKeyArg(create_geant_config(args, args.confKey)) + # ----------------- # transport signals # ----------------- @@ -657,8 +673,6 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True): if (args.pregenCollContext == True): signalneeds.append(PreCollContextTask['name']) - # determine final configKey args for signal transport - CONFKEY = constructConfigKeyArg(create_geant_config(args, args.confKey)) # add embedIntoFile only if embeddPattern does contain a '@' embeddinto= "--embedIntoFile ../bkg_MCHeader.root" if (doembedding & ("@" in args.embeddPattern)) else ""