Skip to content
Snippets Groups Projects
dvmp.sh 5.37 KiB
Newer Older
Sylvester Joosten's avatar
Sylvester Joosten committed
## =============================================================================
## Run the DVMP benchmarks in 5 steps:
## 1. Parse the command line and setup environment
## 2. Detector simulation through npsim
## 3. Digitization and reconstruction through Juggler
## 4. Root-based Physics analyses
## 5. Finalize
Sylvester Joosten's avatar
Sylvester Joosten committed
## =============================================================================
Sylvester Joosten's avatar
Sylvester Joosten committed
## make sure we launch this script from the project root directory
PROJECT_ROOT="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"/..
pushd ${PROJECT_ROOT}
echo "Running the DVMP benchmarks"


Sylvester Joosten's avatar
Sylvester Joosten committed
## =============================================================================
## Step 1: Setup the environment variables
Sylvester Joosten's avatar
Sylvester Joosten committed
##
## First parse the command line flags.
## This sets the following environment variables:
## - CONFIG:   The specific generator configuration
## - EBEAM:    The electron beam energy
## - PBEAM:    The ion beam energy
## - DECAY:    The decay particle for the generator
## - LEADING:  Leading particle of interest (J/psi)
export REQUIRE_DECAY=1
export REQUIRE_LEADING=1
source util/parse_cmd.sh $@

## To run the reconstruction, we need the following global variables:
Sylvester Joosten's avatar
Sylvester Joosten committed
## - JUGGLER_INSTALL_PREFIX: Install prefix for Juggler (simu/recon)
## - JUGGLER_DETECTOR:       the detector package we want to use for this benchmark
## - DETECTOR_PATH:          full path to the detector definitions
##
## You can ready config/env.sh for more in-depth explanations of the variables
## and how they can be controlled.
source config/env.sh
## We also need the following benchmark-specific variables:
##
## - BENCHMARK_TAG: Unique identified for this benchmark process.
## - BEAM_TAG:      Identifier for the chosen beam configuration
## - INPUT_PATH:    Path for generator-level input to the benchmarks
## - TMP_PATH:      Path for temporary data (not exported as artifacts)
## - RESULTS_PATH:  Path for benchmark output figures and files
##
## You can read dvmp/env.sh for more in-depth explanations of the variables.
source dvmp/env.sh
## Get a unique file names based on the configuration options
GEN_FILE=${INPUT_PATH}/gen-${CONFIG}_${DECAY}_${JUGGLER_N_EVENTS}.hepmc
SIM_FILE=${TMP_PATH}/sim-${CONFIG}_${DECAY}.root
SIM_LOG=${TMP_PATH}/sim-${CONFIG}_${DECAY}.log

REC_FILE=${TMP_PATH}/rec-${CONFIG}_${DECAY}.root
REC_LOG=${TMP_PATH}/sim-${CONFIG}_${DECAY}.log

PLOT_TAG=${CONFIG}_${DECAY}
Sylvester Joosten's avatar
Sylvester Joosten committed
## =============================================================================
## Step 2: Run the simulation
echo "Running Geant4 simulation"
      --part.minimalKineticEnergy 100*GeV  \
      -v WARNING \
      --numberOfEvents ${JUGGLER_N_EVENTS} \
Sylvester Joosten's avatar
Sylvester Joosten committed
      --compactFile ${DETECTOR_PATH}/${JUGGLER_DETECTOR}.xml \
      --inputFiles ${GEN_FILE} \
Sylvester Joosten's avatar
Sylvester Joosten committed
if [ "$?" -ne "0" ] ; then
  echo "ERROR running npsim"
Sylvester Joosten's avatar
Sylvester Joosten committed
## =============================================================================
## Step 3: Run digitization & reconstruction
echo "Running the digitization and reconstruction"
## FIXME Need to figure out how to pass file name to juggler from the commandline
## the tracker_reconstruction.py options file uses the following environment
## variables:
## - JUGGLER_SIM_FILE:    input detector simulation
## - JUGGLER_REC_FILE:    output reconstructed data
## - JUGGLER_DETECTOR_PATH: Location of the detector geometry
## - JUGGLER_N_EVENTS:    number of events to process (part of global environment)
## - JUGGLER_DETECTOR:    detector package (part of global environment)
export JUGGLER_SIM_FILE=${SIM_FILE}
export JUGGLER_REC_FILE=${REC_FILE}
export JUGGLER_DETECTOR_PATH=${DETECTOR_PATH}
xenv -x ${JUGGLER_INSTALL_PREFIX}/Juggler.xenv \
  gaudirun.py options/tracker_reconstruction.py \
  2>&1 > ${REC_LOG}
## on-error, first retry running juggler again as there is still a random
## crash we need to address FIXME
Sylvester Joosten's avatar
Sylvester Joosten committed
if [ "$?" -ne "0" ] ; then
  echo "Juggler crashed, retrying..."
  xenv -x ${JUGGLER_INSTALL_PREFIX}/Juggler.xenv \
    gaudirun.py options/tracker_reconstruction.py \
    2>&1 > ${REC_LOG}
  if [ "$?" -ne "0" ] ; then
    echo "ERROR running juggler, both attempts failed"
    exit 1
  fi
Sylvester Joosten's avatar
Sylvester Joosten committed
## =============================================================================
## Step 4: Analysis

## write a temporary configuration file for the analysis script
CONFIG="${TMP_PATH}/${PLOT_TAG}.json"
cat << EOF > ${CONFIG}
{
  "rec_file": "${REC_FILE}",
  "vm_name": "${LEADING}",
  "decay": "${DECAY}",
  "detector": "${JUGGLER_DETECTOR}",
  "output_prefix": "${RESULTS_PATH}/${PLOT_TAG}",
  "test_tag": "${LEADING}_${DECAY}_${BEAM_TAG}"
}
EOF
#cat ${CONFIG}

## run the analysis script with this configuration
root -b -q "dvmp/analysis/vm_mass.cxx(\"${CONFIG}\")"
root -b -q "dvmp/analysis/vm_invar.cxx(\"${CONFIG}\")"
Sylvester Joosten's avatar
Sylvester Joosten committed
if [ "$?" -ne "0" ] ; then
  echo "ERROR running root script"
  exit 1
fi
Sylvester Joosten's avatar
Sylvester Joosten committed
## =============================================================================
## Step 5: finalize
echo "Finalizing DVMP benchmark"
Sylvester Joosten's avatar
Sylvester Joosten committed

## Copy over reconsturction artifacts as long as we don't have
## too many events
if [ "${JUGGLER_N_EVENTS}" -lt "500" ] ; then 
## Always move over log files to the results path
mv ${SIM_LOG} ${REC_LOG} ${RESULTS_PATH}

Sylvester Joosten's avatar
Sylvester Joosten committed
## cleanup output files
Sylvester Joosten's avatar
Sylvester Joosten committed

## =============================================================================
## All done!
echo "DVMP benchmarks complete"