Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-08-31 08:24:38

0001 #!/bin/bash
0002 #
0003 # prorun_mbdtrkz.sh <runnumber> [--nevents N] [-n fun4all_nevents]
0004 #                               [--trkdst clus|tracks] [--listdir DIR]
0005 #
0006 # Creates MBDTRKZ/<runnumber>/<zero-padded trkseg>/, generates seed/clus/fit lists there,
0007 # and runs Fun4All_MBD_TrackVertex.C (tracks mode) or Fun4All_MBD_TrackFitting.C
0008 # once per clus file (clus mode).
0009 #
0010 #   --trkseg S           segment of track dst (default 0)
0011 #   --nevents N          events per block passed to make_mbdtrkz_lists.py (default 100000)
0012 #   -n fun4all_n         nEvents passed to Fun4All (default 0 = all)
0013 #   --trkdst clus|tracks DST type (default: tracks)
0014 #   --listdir DIR        base list directory passed to make_mbdtrkz_lists.py
0015 #
0016 # Under condor: stages files to _CONDOR_SCRATCH_DIR, runs there, copies
0017 # output back to the MBDTRKZ subdir.
0018 #
0019 
0020 usage() {
0021   #echo "Usage: $0 <runnumber> [--skip S] [--nevents N] [-n fun4all_nevents] [--trkdst clus|tracks] [--listdir DIR]" >&2
0022   echo "Usage: $0 <runnumber> [--nevents N] [-n fun4all_nevents] [--trkdst clus|tracks] [--listdir DIR]" >&2
0023   exit 1
0024 }
0025 
0026 echo "PWD=${PWD}"
0027 echo "HOST=$(hostname)"
0028 ORIG_DIR="${PWD}"
0029 
0030 ulimit -c 0   # no core files
0031 
0032 SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
0033 
0034 runnumber=""
0035 #skip=0
0036 trkseg=0
0037 list_nevents=1000
0038 nevents=0
0039 trkdst="tracks"
0040 listdir=""
0041 
0042 while [[ $# -gt 0 ]]; do
0043   case "$1" in
0044 #    --skip|--skip=*)
0045 #      if [[ "$1" == *=* ]]; then skip="${1#*=}"; shift
0046 #      else [[ $# -lt 2 ]] && usage; skip=$2; shift 2; fi ;;
0047     --trkseg|--trkseg=*)
0048       if [[ "$1" == *=* ]]; then trkseg="${1#*=}"; shift
0049       else [[ $# -lt 2 ]] && usage; trkseg=$2; shift 2; fi ;;
0050     --nevents|--nevents=*)
0051       if [[ "$1" == *=* ]]; then nevents="${1#*=}"; shift
0052       else [[ $# -lt 2 ]] && usage; nevents=$2; shift 2; fi ;;
0053     --trkdst|--trkdst=*)
0054       if [[ "$1" == *=* ]]; then trkdst="${1#*=}"; shift
0055       else [[ $# -lt 2 ]] && usage; trkdst=$2; shift 2; fi
0056       [[ "$trkdst" == "clus" || "$trkdst" == "tracks" ]] || { echo "ERROR: --trkdst must be clus or tracks" >&2; exit 1; } ;;
0057     --listdir|--listdir=*)
0058       if [[ "$1" == *=* ]]; then listdir="${1#*=}"; shift
0059       else [[ $# -lt 2 ]] && usage; listdir=$2; shift 2; fi ;;
0060     --nevtperjob|--nevtperjob=*)
0061       if [[ "$1" == *=* ]]; then list_nevents="${1#*=}"; shift
0062       else [[ $# -lt 2 ]] && usage; list_nevents=$2; shift 2; fi ;;
0063     -*)    usage ;;
0064     *)     [[ -n "$runnumber" ]] && usage; runnumber=$1; shift ;;
0065   esac
0066 done
0067 
0068 [[ -z "$runnumber" ]] && usage
0069 
0070 subdir="${ORIG_DIR}/MBDTRKZ/${runnumber}/$(printf '%04d' ${trkseg})"
0071 echo $subdir
0072 mkdir -p "${subdir}"
0073 
0074 cd "${subdir}"
0075 
0076 ln -sf "${SCRIPTDIR}/Fun4All_MBD_TrackVertex.C" .
0077 ln -sf "${SCRIPTDIR}/Fun4All_MBD_TrackSeeding.C" .
0078 ln -sf "${SCRIPTDIR}/Fun4All_MBD_TrackFitting.C" .
0079 ln -sf /pdata/chiu/25_CALIBPRODUCTION/results/ .
0080 
0081 python3 "${SCRIPTDIR}/make_mbdtrkz_lists.py" "$runnumber" --trkseg "$trkseg" --nevents "$list_nevents" --trkdst "$trkdst" \
0082   ${listdir:+--listdir "$listdir"} || exit 1
0083 
0084 # tracks mode: stage files and run Fun4All_MBD_TrackVertex.C as before
0085 if [[ -n "${_CONDOR_SCRATCH_DIR}" ]]; then
0086   mkdir -p "${_CONDOR_SCRATCH_DIR}"
0087   cp -p *.C *.list "${_CONDOR_SCRATCH_DIR}/"
0088   cd "${_CONDOR_SCRATCH_DIR}"
0089   ln -sf /pdata/chiu/25_CALIBPRODUCTION/results/ .
0090   time getinputfiles.pl --filelist fit.list
0091   [[ -f clus.list ]] && time getinputfiles.pl --filelist clus.list
0092   [[ -f seed.list ]] && time getinputfiles.pl --filelist seed.list  # never used
0093   [[ -f tracks.list ]] && time getinputfiles.pl --filelist tracks.list
0094 fi
0095 
0096 if [[ "$trkdst" == "clus" ]]; then
0097   # Run Fun4All_MBD_TrackFitting.C once per file in clus.list
0098   while IFS= read -r clusfile; do
0099     [[ -z "$clusfile" ]] && continue
0100     echo root.exe -b -q "Fun4All_MBD_TrackSeeding.C(${nevents},\"${clusfile}\")"
0101     root.exe -b -q "Fun4All_MBD_TrackSeeding.C(${nevents},\"${clusfile}\")" || exit 1
0102     seedfile=DST_TRKR_SEED${clusfile#DST_TRKR_CLUSTER}
0103     echo root.exe -b -q "Fun4All_MBD_TrackFitting.C(${nevents},\"${seedfile}\")"
0104     root.exe -b -q "Fun4All_MBD_TrackFitting.C(${nevents},\"${seedfile}\")" || exit 1
0105   done < clus.list
0106 
0107   ls DST_TRKR_TRACK*.root > tracks.list
0108 else
0109   if [[ -n "${_CONDOR_SCRATCH_DIR}" ]]; then
0110     time getinputfiles.pl --filelist tracks.list
0111   fi
0112 fi
0113 
0114 [[ -s tracks.list ]] || { echo "ERROR: tracks.list is empty" >&2; exit 1; }
0115 [[ -s fit.list ]] || { echo "ERROR: fit.list is empty" >&2; exit 1; }
0116 
0117 tracks_dst_file=$(head -1 tracks.list)
0118 mbd_dst_file=$(head -1 fit.list)
0119 echo root.exe -b -q Fun4All_MBD_TrackVertex.C\(${nevents},\"${tracks_dst_file}\",\"${mbd_dst_file}\"\)
0120 root.exe -b -q Fun4All_MBD_TrackVertex.C\(${nevents},\"${tracks_dst_file}\",\"${mbd_dst_file}\"\) || exit 1
0121 
0122 if [[ -n "${_CONDOR_SCRATCH_DIR}" ]]; then
0123   pwd
0124   df -h
0125   ls -l
0126   cp -p mbdtrk_*.root "${subdir}/"
0127   cd "${ORIG_DIR}"
0128 fi