Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:22

0001 #!/usr/bin/bash
0002 #
0003 # Run the mbd calibrations
0004 #
0005 #
0006 
0007 # Default values
0008 runno=
0009 outbase="DST_MBD_CALIBRATION_run3auau"
0010 outdir="/sphenix/user/chiu/sphenix_bbc/run2025/CALIBPRODUCTION/TEST"
0011 logdir="/sphenix/user/chiu/sphenix_bbc/run2025/CALIBPRODUCTION/TEST/log"
0012 logbase="DST_MBD_CALIBRATION_run3auau"
0013 build="new"
0014 dbtag="ProdA_2024"
0015 pass0dir=""      # only set if using local private pass0 calibs, otherwise use CDB
0016 nevents=0        # by default process all events
0017 
0018 #echo $@ 
0019 
0020 # Use getopt to parse options
0021 PARSED=$(getopt -o "r:b:d:p:n:h" -l "outbase:,outdir:,logbase:,logdir:,run:,build:,dbtag:,pass0dir:,nevents:,help" -- "$@")
0022 if [[ $? -ne 0 ]]; then
0023     echo "Failed to parse arguments" >&2
0024     exit 1
0025 fi
0026 
0027 # Apply the parsed arguments
0028 eval set -- "$PARSED"
0029 
0030 # Extract options and their arguments
0031 while true; do
0032     case "$1" in
0033         --outbase)
0034             outbase="$2"
0035             shift 2
0036             ;;
0037         --outdir)
0038             outdir="$2"
0039             shift 2
0040             ;;
0041         --logbase)
0042             logbase="$2"
0043             shift 2
0044             ;;
0045         --logdir)
0046             logdir="$2"
0047             shift 2
0048             ;;
0049         -r|--run)
0050             runno="$2"
0051             shift 2
0052             ;;
0053         -b|--build)
0054             build="$2"
0055             shift 2
0056             ;;
0057         -d|--dbtag)
0058             dbtag="$2"
0059             shift 2
0060             ;;
0061         -p|--pass0dir)
0062             pass0dir="$2"
0063             shift 2
0064             ;;
0065         -n|--nevents)
0066             nevents="$2"
0067             shift 2
0068             ;;
0069         -h|--help)
0070             echo "Usage: $0 [--OPTIONS] inputfile"
0071             echo
0072             echo " The inputfile can be a list file, DST, or PRDF"
0073             echo
0074             echo " The options are"
0075             echo
0076             echo "          [--outbase BASENAME] [--outdir DIR]"
0077             echo "          [--logbase LOGBASE] [--logdir LOGDIR]"
0078             echo "          [--run RUNNUMBER]"
0079             echo "          [--build BUILD] [--dbtag CDBTAG]"
0080             echo "          [--nevents NEVENTS]"
0081             echo "          [--pass0dir PASS0DIR]  # only for using local (text-based) pass0 calib"
0082             exit 0
0083             ;;
0084         --)
0085             shift
0086             break
0087             ;;
0088         *)
0089             echo "Unknown option: $1"
0090             exit 1
0091             ;;
0092     esac
0093 done
0094 
0095 
0096 # Validate required option(s)
0097 if [[ -z "$runno" ]]; then
0098     echo "Error: --run is required" >&2
0099     exit 1
0100 fi
0101 
0102 
0103 # Get input files, concatentate into comma-separated string
0104 inputs=$1
0105 shift
0106 for arg in "$@"; do
0107   inputs=${inputs},${arg}
0108 done
0109 echo $inputs 
0110 
0111 # update the base names with the build, tag, and run number
0112 outbase=${outbase}_${build}_${dbtag}_$(printf "%08d" ${runno})
0113 logbase=${logbase}_${build}_${dbtag}_$(printf "%08d" ${runno})
0114 
0115 
0116 {
0117 
0118 echo run:     ${runno}
0119 echo inputs:  ${inputs}
0120 echo outbase: ${outbase}
0121 echo outdir:  ${outdir}
0122 echo logbase: ${logbase}
0123 echo logdir:  ${logdir}
0124 echo build:   ${build}
0125 echo dbtag:   ${dbtag}
0126 echo pass0dir: ${pass0dir}
0127 echo nevents: ${nevents}
0128 
0129 
0130 if [[ $runno -lt 44100 ]]
0131 then
0132   runtype=1  # pp200
0133 else
0134   runtype=0  # auau200
0135 fi
0136 
0137 echo runtype $runtype
0138 
0139 export USER="$(id -u -n)"
0140 export LOGNAME=${USER}
0141 export HOME=/sphenix/u/${USER}
0142 
0143 if [[ $build != "none" ]]   # use none to keep existing env
0144 then
0145   echo source /opt/sphenix/core/bin/sphenix_setup.sh -n ${build}
0146   source /opt/sphenix/core/bin/sphenix_setup.sh -n ${build}
0147 fi
0148 
0149 export ODBCINI=./odbc.ini
0150  
0151 # There ought to be just one here... but ymmv...
0152 echo "Input files: " ${inputs}
0153 
0154 #if test -f cupstest.py
0155 #then
0156 #   mv cupstest.py cups.py
0157 #fi
0158 
0159 # Flag as started
0160 #./cups.py -r ${runno} -s ${segment} -d ${outbase} started
0161 
0162 ################################################
0163 # make local calibration directory and fill it
0164 caldir=${PWD}/results/${runno}
0165 echo mkdir -p ${caldir}
0166 mkdir -p ${caldir}
0167 
0168 
0169 ################################################
0170 # If using local files, stage PASS0 calibrations
0171 if [[ ! -z ${pass0dir} ]]
0172 then
0173 #  ./cups.py -r ${runno} -s ${segment} -d ${outbase} message "Stage in pass0 from ${pass0dir}"
0174   for calib in mbd_shape.calib mbd_sherr.calib mbd_timecorr.calib mbd_slewcorr.calib mbd_tt_t0.calib mbd_tq_t0.calib
0175   do
0176     echo Stagein ${pass0dir}/${calib} to ${caldir}
0177     cp -p ${pass0dir}/${calib} ${caldir}/
0178   done
0179 fi
0180 
0181 # Flag as started
0182 #./cups.py -r ${runno} -s ${segment} -d ${outbase} running
0183 
0184 ################################################
0185 # Pass 1 calibrations
0186 echo "###############################################################################################################"
0187 echo "Running pass1 calibration"
0188 #./cups.py -r ${runno} -s ${segment} -d ${outbase} message "Running PASS 1 calibration"
0189 echo root.exe -q -b Fun4All_MBD_CalPass.C\(\"${inputs}\",1,-1,0,\"${dbtag}\"\) 
0190 root.exe -q -b Fun4All_MBD_CalPass.C\(\"${inputs}\",1,-1,0,\"${dbtag}\"\) 
0191 
0192 echo "Pass 1 calibration done"
0193 ls -la *.root
0194 
0195 ################################################
0196 # Pass 2 calibrations waveforms
0197 #./cups.py -r ${runnumber} -s ${segment} -d ${outbase} message "Running PASS 2 calibration, process waveforms"
0198 echo root.exe -q -b Fun4All_MBD_CalPass.C\(\"${inputs}\",2,${nevents},0,\"${dbtag}\"\)
0199 root.exe -q -b Fun4All_MBD_CalPass.C\(\"${inputs}\",2,${nevents},0,\"${dbtag}\"\)
0200 
0201 echo "Pass 2 calibration done (waveforms processed)"
0202 ls -la *.root
0203 
0204 # Flag as started
0205 #./cups.py -r ${runnumber} -s ${segment} -d ${outbase} running
0206 
0207 ################################################
0208 # Pass 2 calibrations (t0 offsets)
0209 # Pass 2 calibrations mip fits
0210 fname=$(ls -tr DST_UNCALMBD*.root | tail -1)
0211 
0212 echo "###############################################################################################################"
0213 echo "Running pass2.0 calibration"
0214 #./cups.py -r ${runnumber} -s ${segment} -d ${outbase} message "Running PASS 2.0 calibration"
0215 pass=0
0216 echo root.exe -q -b cal_mbd.C\(\"${fname}\",${pass},${nevents}\)
0217 root.exe -q -b cal_mbd.C\(\"${fname}\",${pass},${nevents}\)
0218 cp -p results/${runno}/pass0_mbd_tt_t0.calib results/${runno}/mbd_tt_t0.calib
0219 cp -p results/${runno}/pass0_mbd_tq_t0.calib results/${runno}/mbd_tq_t0.calib
0220 mv results/${runno}/pass0_mbd_tt_t0.root results/${runno}/mbd_tt_t0-${runno}.root
0221 mv results/${runno}/pass0_mbd_tq_t0.root results/${runno}/mbd_tq_t0-${runno}.root
0222 
0223 echo "###############################################################################################################"
0224 echo "Running pass2.3 calibration"
0225 #./cups.py -r ${runnumber} -s ${segment} -d ${outbase} message "Running PASS 2.2 calibration"
0226 pass=3
0227 echo root.exe -q -b cal_mbd.C\(\"${fname}\",${pass},${nevents},${runtype}\)
0228 root.exe -q -b cal_mbd.C\(\"${fname}\",${pass},${nevents},${runtype},\"${dbtag}\"\)
0229 mv results/${runno}/mbd_qfit.root results/${runno}/mbd_qfit-${runno}.root
0230 
0231 echo "###############################################################################################################"
0232 echo "Running pass2.4 calibration"
0233 echo root.exe -q calib_t0mean.C\(\"results/${runno}/calmbdpass2.3_q_${runno}.root\"\)
0234 root.exe -q calib_t0mean.C\(\"results/${runno}/calmbdpass2.3_q-${runno}.root\"\)
0235 mv results/${runno}/mbd_t0corr.root results/${runno}/mbd_t0corr-${runno}.root
0236 
0237 # Flag as done
0238 #./cups.py -r ${runno} -s ${segment} -d ${outbase} message "Done"
0239 #./cups.py -r ${runno} -s ${segment} -d ${outbase} finished -e 0
0240 
0241 # Copy out files
0242 mkdir -p ${outdir}/${runno}
0243 cp -p ${fname} ${outdir}/${runno}/
0244 for r in ${caldir}/*
0245 do
0246     # skip linked files
0247     if [[ -h $r ]]
0248     then
0249       continue
0250     fi
0251 
0252     cp -p ${r} ${outdir}/${runno}/
0253 
0254 done
0255 
0256 ################################################
0257 
0258 # Flag run as finished.  Increment nevents by zero
0259 #echo ./cups.py -v -r ${runno} -s ${segment} -d ${outbase} finished -e 0 --nevents 0 --inc 
0260 #     ./cups.py -v -r ${runno} -s ${segment} -d ${outbase} finished -e 0 --nevents 0 --inc 
0261 
0262 
0263 }  > ${logbase}.out 2>${logbase}.err 
0264 
0265 [[ "${logdir%/}" != "." ]] && cp -p ${logbase}.out  ${logdir}
0266 [[ "${logdir%/}" != "." ]] && cp -p ${logbase}.err  ${logdir}
0267