Skip to content
Snippets Groups Projects
central_electrons.sh 3.28 KiB
#!/bin/bash

function print_the_help {
  echo "USAGE: ${0} [--rec-only]  "
  echo "  OPTIONS: "
  echo "            --rec-only   only run gaudi reconstruction part"
  exit 
}

REC_ONLY=
ANALYSIS_ONLY=

POSITIONAL=()
while [[ $# -gt 0 ]]
do
  key="$1"

  case $key in
    -h|--help)
      shift # past argument
      print_the_help
      ;;
    --rec-only)
      REC_ONLY=1
      shift # past value
      ;;
    --ana-only)
      ANALYSIS_ONLY=1
      shift # past value
      ;;
    *)    # unknown option
      #POSITIONAL+=("$1") # save it in an array for later
      echo "unknown option $1"
      print_the_help
      shift # past argument
      ;;
  esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters


print_env.sh

## To run the reconstruction, we need the following global variables:
## - JUGGLER_INSTALL_PREFIX:   Install prefix for Juggler (simu/recon)
## - JUGGLER_DETECTOR:         the detector package we want to use for this benchmark
## - JUGGLER_DETECTOR_VERSION: the detector package we want to use for this benchmark
## - DETECTOR_PATH:            full path to the detector definitions
##
## You can ready options/env.sh for more in-depth explanations of the variables
## and how they can be controlled.
export DETECTOR_PATH=${DETECTOR_PATH}

if [[ ! -n  "${JUGGLER_N_EVENTS}" ]] ; then 
  export JUGGLER_N_EVENTS=100
fi


export JUGGLER_FILE_NAME_TAG="central_electrons"
export JUGGLER_GEN_FILE="${JUGGLER_FILE_NAME_TAG}.hepmc"

export JUGGLER_SIM_FILE="sim_${JUGGLER_FILE_NAME_TAG}.root"
export JUGGLER_REC_FILE="rec_${JUGGLER_FILE_NAME_TAG}.root"

echo "JUGGLER_N_EVENTS = ${JUGGLER_N_EVENTS}"
echo "JUGGLER_DETECTOR = ${JUGGLER_DETECTOR}"


if [[ -z "${REC_ONLY}" && -z "${ANALYSIS_ONLY}" ]] ;
then

  ## generate the input events
  root -b -q "benchmarks/tracking/scripts/gen_central_electrons.cxx(${JUGGLER_N_EVENTS}, \"${JUGGLER_FILE_NAME_TAG}.hepmc\")"
  if [[ "$?" -ne "0" ]] ; then
    echo "ERROR running script"
    exit 1
  fi

  echo "Running geant4 simulation"
  ## run geant4 simulations
  npsim --runType batch \
    --part.minimalKineticEnergy 1000*GeV  \
    -v WARNING \
    --numberOfEvents ${JUGGLER_N_EVENTS} \
    --compactFile ${DETECTOR_PATH}/${JUGGLER_DETECTOR}.xml \
    --inputFiles  ${JUGGLER_FILE_NAME_TAG}.hepmc \
    --outputFile  ${JUGGLER_SIM_FILE}
  if [[ "$?" -ne "0" ]] ; then
    echo "ERROR running script"
    exit 1
  fi
fi

rootls -t ${JUGGLER_SIM_FILE}

if [[ -z "${ANALYSIS_ONLY}" ]] ;
then
  # Need to figure out how to pass file name to juggler from the commandline
  xenv -x ${JUGGLER_INSTALL_PREFIX}/Juggler.xenv gaudirun.py benchmarks/tracking/options/tracker_reconstruction.py
  if [[ "$?" -ne "0" ]] ; then
    echo "ERROR running juggler"
    exit 1
  fi
fi

mkdir -p results/tracking

root -b -q "benchmarks/tracking/scripts/rec_central_electrons.cxx(\"${JUGGLER_REC_FILE}\")"
if [[ "$?" -ne "0" ]] ; then
  echo "ERROR running root script"
  exit 1
fi

root -b -q "benchmarks/tracking/scripts/hits_central_electrons.cxx(\"${JUGGLER_SIM_FILE}\")"
if [[ "$?" -ne "0" ]] ; then
  echo "ERROR running root script"
  exit 1
fi

root_filesize=$(stat --format=%s "${JUGGLER_REC_FILE}")
if [[ "${JUGGLER_N_EVENTS}" -lt "500" ]] ; then 
  # file must be less than 10 MB to upload
  if [[ "${root_filesize}" -lt "10000000" ]] ; then 
    cp ${JUGGLER_REC_FILE} results/.
  fi
fi