Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-19 23:20:26

0001 #!/bin/bash
0002 
0003 ##############################################################################
0004 #
0005 #
0006 # Line Segment Tracking Standalone Code Run Script
0007 #
0008 #
0009 ##############################################################################
0010 
0011 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
0012 
0013 # Help
0014 usage()
0015 {
0016   echo "ERROR - Usage:"
0017   echo
0018   echo "      sh $(basename $0) OPTIONSTRINGS ..."
0019   echo
0020   echo "Options:"
0021   echo "  -h    Help                    (Display this message)"
0022   echo "  -f    compilation flags       (Compilation flags e.g. mc NOTE: Must start with '-' e.g. '-mc')"
0023   echo "  -s    sample name             (Sample name e.g. PU200, muonGun, ...)"
0024   echo "  -n    number of events        (Number of events to run over)"
0025   echo "  -t    tag for this run        (Tag for this run)"
0026   echo "  -d    delete previous output  (Delete the previous outputs and re-run)"
0027   echo "  -b    backend                 (Select a backend: cuda or cpu; default cuda)"
0028   echo "  -a    arguments               (Add command line arguments to the lst command)"
0029   echo
0030   exit
0031 }
0032 
0033 DELETE=false
0034 
0035 # Parsing command-line opts
0036 while getopts ":f:s:n:t:b:a:dh" OPTION; do
0037   case $OPTION in
0038     f) FLAGS=${OPTARG};;
0039     s) SAMPLE=${OPTARG};;
0040     n) NEVENTS=${OPTARG};;
0041     t) TAG=${OPTARG};;
0042     b) BACKEND=${OPTARG};;
0043     a) ARGUMENTS=${OPTARG};;
0044     d) DELETE=true;;
0045     h) usage;;
0046     :) usage;;
0047   esac
0048 done
0049 
0050 # If the command line options are not provided set it to default value of false
0051 if [ -z ${FLAGS} ]; then PRECOMPILED=true; else PRECOMPILED=false; fi
0052 if [ -z ${SAMPLE} ]; then usage; fi
0053 if [ -z ${NEVENTS} ]; then NEVENTS=-1; fi
0054 if [ -z ${TAG} ]; then usage; fi
0055 if [ -z ${BACKEND} ]; then  BACKEND="default"; fi
0056 if [ -z ${ARGUMENTS} ]; then  ARGUMENTS=""; fi
0057 
0058 # Check that the FLAGS start with "-" character
0059 if [[ ${PRECOMPILED} == true ]] || [[ ${FLAGS:0:1} == "-" ]]; then
0060     :
0061 else
0062     echo "ERROR:"
0063     echo ""
0064     echo "Compilation flag Option provided is '-f ${FLAGS}'"
0065     echo "However, compilation flags must start with '-' e.g. '-mc'"
0066     echo ""
0067     exit
0068 fi
0069 
0070 # Shift away the parsed options
0071 shift $(($OPTIND - 1))
0072 
0073 # Move to the TRACKLOOPERDIR
0074 pushd ${TRACKLOOPERDIR}
0075 
0076 if [[ ${PRECOMPILED} == true ]]; then
0077   FLAGS="No compilation"
0078 fi
0079 
0080 # Verbose
0081 echo "====================================================="
0082 echo "Line Segment Tracking Run Script                     "
0083 echo "====================================================="
0084 echo ""
0085 echo "  COMPILATION FLAG  : ${FLAGS}"
0086 echo "  SAMPLE            : ${SAMPLE}"
0087 echo "  NEVENTS           : ${NEVENTS}"
0088 echo "  TAG               : ${TAG}"
0089 echo "  DELETE            : ${DELETE}"
0090 echo "  BACKEND           : ${BACKEND}"
0091 echo "  ARGUMENTS         : ${ARGUMENTS}"
0092 echo ""
0093 echo "  (cf. Run > sh $(basename $0) -h to see all options)"
0094 echo ""
0095 
0096 JOBTAG=${TAG}_${SAMPLE}_NEVT${NEVENTS}
0097 LSTNTUPLEOUTPUT=${LSTOUTPUTDIR}/${JOBTAG}__LSTNtuple.root
0098 LSTNUMDENOUTPUT=${LSTOUTPUTDIR}/${JOBTAG}__LSTNumDen.root
0099 
0100 # Help
0101 file_already_exists()
0102 {
0103   echo "ERROR - Output already exists!"
0104   echo ""
0105   echo "  Out of caution, the lst_run fails to run if the following .root output files already exists:"
0106   echo ""
0107   if [ -f "$LSTNTUPLEOUTPUT" ]; then
0108       echo "  $LSTNTUPLEOUTPUT   already exists."
0109   fi
0110   if [ -f "$LSTNUMDENOUTPUT" ]; then
0111       echo "  $LSTNUMDENOUTPUT   already exists."
0112   fi
0113   echo ""
0114   echo "  Please delete these files before running them again."
0115   echo ""
0116   echo "  or, use -d options to delete previous outputs! use with caution!"
0117   echo
0118   exit
0119 }
0120 
0121 if [ "$DELETE" = true ]; then
0122     rm -rf ${LSTNTUPLEOUTPUT};
0123     rm -rf ${LSTNUMDENOUTPUT};
0124 else
0125     if [ -f "$LSTNTUPLEOUTPUT" ]; then file_already_exists; fi
0126     if [ -f "$LSTNUMDENOUTPUT" ]; then file_already_exists; fi
0127 fi
0128 
0129 # Create output directory
0130 mkdir -p ${LSTOUTPUTDIR}
0131 
0132 rm -f ${LSTOUTPUTDIR}/${JOBTAG}__LSTRun.log
0133 if [[ ${PRECOMPILED} != true ]]; then
0134   echo "Compiling code..."
0135   lst_make_tracklooper ${FLAGS} >> ${LSTOUTPUTDIR}/${JOBTAG}__LSTRun.log
0136 fi
0137 
0138 # If a backend is specified then make sure that corresponding library exists
0139 # and make a symbolic link to the correct binary
0140 if [ "${BACKEND}" == "cuda" ]; then
0141   if [ ! -f ${TRACKLOOPERDIR}/LST/liblst_cuda.so ]; then
0142     echo "Error: CUDA backend was not compiled."
0143     exit 1
0144   fi
0145   ln -s -f ${TRACKLOOPERDIR}/bin/lst_cuda ${TRACKLOOPERDIR}/bin/lst
0146 elif [ "${BACKEND}" == "cpu" ]; then
0147   if [ ! -f ${TRACKLOOPERDIR}/LST/liblst_cpu.so ]; then
0148     echo "Error: CPU backend was not compiled."
0149     exit 1
0150   fi
0151   ln -s -f ${TRACKLOOPERDIR}/bin/lst_cpu ${TRACKLOOPERDIR}/bin/lst
0152 elif [ "${BACKEND}" == "rocm" ]; then
0153   if [ ! -f ${TRACKLOOPERDIR}/LST/liblst_rocm.so ]; then
0154     echo "Error: ROCM backend was not compiled."
0155     exit 1
0156   fi
0157   ln -s -f ${TRACKLOOPERDIR}/bin/lst_rocm ${TRACKLOOPERDIR}/bin/lst
0158 elif [ "${BACKEND}" == "default" ]; then
0159   if [[ ! -e ${TRACKLOOPERDIR}/bin/lst ]]; then
0160     echo "Error: default backend was not found. Please recompile."
0161     exit 1
0162   fi
0163 else
0164   echo "Error: backend options are cpu, cuda, rocm, or default."
0165   exit 1
0166 fi
0167 
0168 echo "Running LST code..."
0169 lst -i ${SAMPLE} -o ${LSTOUTPUTDIR}/${JOBTAG}__LSTNtuple.root -n ${NEVENTS} ${ARGUMENTS} >> ${LSTOUTPUTDIR}/${JOBTAG}__LSTRun.log 2>&1 || { echo 'ERROR: lst command failed!' ; exit 1; }
0170 echo "Creating performance histograms..."
0171 createPerfNumDenHists -i ${LSTOUTPUTDIR}/${JOBTAG}__LSTNtuple.root -o ${LSTOUTPUTDIR}/${JOBTAG}__LSTNumDen.root >> ${LSTOUTPUTDIR}/${JOBTAG}__LSTRun.log 2>&1 || { echo 'ERROR: createPerfNumDenHists command failed!' ; exit 1; }
0172 echo "Creating plots..."
0173 python3 efficiency/python/lst_plot_performance.py ${LSTOUTPUTDIR}/${JOBTAG}__LSTNumDen.root -t ${LSTOUTPUTDIR}/${JOBTAG} >> ${LSTOUTPUTDIR}/${JOBTAG}__LSTRun.log 2>&1 || { echo 'ERROR: lst_plot_performance.py command failed!' ; exit 1; }
0174 echo "Done!"