Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 08:15:38

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