Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:18:31

0001 #! /bin/bash
0002 
0003 ### Stephen Kay, University of York
0004 ### 22/04/24
0005 ### stephen.kay@york.ac.uk
0006 ### A script to process some commands within eic-shell. In this example, the simulation is run and then reconstructed.
0007 ### Steps to generate files from an event generator can be included in the relevant section.
0008 ### This script can be run on its own, or fed into a job on the farm
0009 ### VERIFY that it runs interactively for a small sample before submitting a large job!
0010 
0011 SimDir="/group/eic/users/${USER}/ePIC/" # Put in the path of your directory here (where your eic-shell is)
0012 echo "Running as ${USER}"
0013 echo "Assuming simulation directory - ${SimDir}"
0014 if [ ! -d $SimDir ]; then   
0015     echo "!!! WARNING !!!"
0016     echo "!!! $SimDir - Does not exist - Double check pathing and try again !!!"
0017     echo "!!! WARNNING !!!"
0018     exit 1
0019 fi
0020 
0021 FileNum=$1 # First arg is the number of files to run
0022 if [[ -z "$1" ]]; then
0023     echo "I need a number of files to run!"
0024     echo "Please provide a number of files to run as the first argument"
0025     exit 2
0026 fi
0027 NumEvents=$2 # Second argument is an output file name
0028 if [[ -z "$2" ]]; then
0029     echo "I need a number of events to generate per file!"
0030     echo "Please provide a number of event to generate per file as the second argument"
0031     exit 3
0032 fi
0033 
0034 # Check if an argument was provided for Arg3, if not, set 10
0035 if [[ -z "$3" ]]; then
0036     Arg3=10
0037     echo "Arg3 not specified, defaulting to 10"
0038 else
0039     Arg=$3
0040 fi
0041 
0042 # Check if an argument was provided for Arg4, if not, set 10
0043 if [[ -z "$4" ]]; then
0044     Arg4=10
0045     echo "Arg4 not specified, defaulting to 10"
0046 else
0047     Arg4=$4
0048 fi
0049 
0050 # Change output path as desired
0051 OutputPath="/volatile/eic/${USER}" # Change as needed, should match JLab_Farming.sh!
0052 export Output_tmp="$OutputPath/im_${FileNum}_${NumEvents}_${Arg3/./p}_${Arg4/./p}"
0053 if [ ! -d "${Output_tmp}" ]; then # Add this in this script too so it can be run interactively
0054     mkdir $Output_tmp
0055 else
0056     if [ "$(ls -A $Output_tmp)" ]; then # If directory is NOT empty, prompt a warning
0057         if [[ "${HOSTNAME}" == *"ifarm"* ]]; then # Only print this warning if running interactively
0058             echo "!!!!! Warning, ${Output_tmp} directory exists and is not empty! Files may be overwritten! !!!!!"
0059         fi
0060     fi
0061 fi
0062 
0063 export EICSHELL=${SimDir}/eic-shell # Point to wherever your eic-shell is!
0064 cd ${SimDir}
0065 # Run EIC shell, generate the events, afterburn them, run the simulation, reconstruct the events
0066 if test -f "${Output_tmp}/ddsimOut_${FileNum}_${NumEvents}.edm4hep.root"; then # If simulatuon file exists, only run the reconstruction
0067     # Should add additional checks on this, check how old files is (if before 2024, run anyway, if small, re-rerun etc)
0068     echo "${Output_tmp}/ddsimOut_${FileNum}_${NumEvents}.edm4hep.root already exists, running reconstruction only"
0069 # Init_Env.sh is a script to source various things when in eic-shell
0070 cat <<EOF | $EICSHELL
0071 source Init_Env.sh
0072 cd $Output_tmp
0073 eicrecon -Pjana:nevents=${NumEvents} -Phistsfile=EICReconOut_${FileNum}_${NumEvents}.root ${Output_tmp}/ddsimOut_${FileNum}_${NumEvents}.edm4hep.root 
0074 sleep 5
0075 
0076 echo; echo; echo "Reconstruction finished, output file is - ${Output_tmp}/EICReconOut_${FileNum}_${NumEvents}.root"; echo; echo;
0077 EOF
0078 # If simulation file doen't exist, generate files, run simulation and then reconstruction
0079 else
0080 cat <<EOF | $EICSHELL
0081 source Init_Env.sh
0082 
0083 # Add any event generation steps here
0084 
0085 # Add any input files in as needed
0086 npsim -v 4 --inputFiles PATH_TO_INPUT_FILE --outputFile ${Output_tmp}/ddsimOut_${FileNum}_${NumEvents}.edm4hep.root --compactFile ${SimDir}/epic/epic_ip6.xml -N ${NumEvents}
0087 sleep 5
0088 
0089 # Run reconstruction, add any plugins you want to use
0090 echo; echo; echo "Simulation finished, running reconstruction."; echo; echo;
0091 cd $Output_tmp
0092 eicrecon -Pplugins=PLUGINS -Pjana:nevents=${NumEvents} -Phistsfile=EICReconOut_${FileNum}_${NumEvents}.root ${Output_tmp}/ddsimOut_${FileNum}_${NumEvents}.edm4hep.root 
0093 sleep 5
0094 
0095 echo; echo; echo "Reconstruction finished, output file is - ${Output_tmp}/EICReconOut_${FileNum}_${NumEvents}.root"; echo; echo;
0096 
0097 EOF
0098 fi
0099 
0100 exit 0