Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:59

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 if [[ $runno -le 53880 ]]
0134 then
0135   runtype=1  # pp200
0136 else
0137   runtype=0  # auau200
0138 fi
0139 
0140 echo runtype $runtype
0141 
0142 export USER="$(id -u -n)"
0143 export LOGNAME=${USER}
0144 export HOME=/sphenix/u/${USER}
0145 
0146 if [[ "$build" != "none" ]]   # use none to keep existing env
0147 then
0148   echo source /opt/sphenix/core/bin/sphenix_setup.sh -n ${build}
0149   source /opt/sphenix/core/bin/sphenix_setup.sh -n ${build}
0150 fi
0151 
0152 export ODBCINI=./odbc.ini
0153  
0154 # There ought to be just one here... but ymmv...
0155 echo "Input files: " ${inputs}
0156 
0157 #if test -f cupstest.py
0158 #then
0159 #   mv cupstest.py cups.py
0160 #fi
0161 
0162 # Flag as started
0163 #./cups.py -r ${runno} -s ${segment} -d ${outbase} started
0164 
0165 ################################################
0166 # make local calibration directory and fill it
0167 caldir=${PWD}/results/${runno}
0168 echo mkdir -p ${caldir}
0169 mkdir -p ${caldir}
0170 
0171 
0172 ################################################
0173 # If using local files, stage PASS0 calibrations
0174 if [[ ! -z ${pass0dir} ]]
0175 then
0176 #  ./cups.py -r ${runno} -s ${segment} -d ${outbase} message "Stage in pass0 from ${pass0dir}"
0177   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
0178   do
0179     echo Stagein ${pass0dir}/${calib} to ${caldir}
0180     cp -p ${pass0dir}/${calib} ${caldir}/
0181   done
0182 fi
0183 
0184 # Flag as started
0185 #./cups.py -r ${runno} -s ${segment} -d ${outbase} running
0186 
0187 ################################################
0188 # Pass 1 calibrations
0189 echo "###############################################################################################################"
0190 echo "Running pass1 calibration"
0191 #./cups.py -r ${runno} -s ${segment} -d ${outbase} message "Running PASS 1 calibration"
0192 echo root.exe -q -b Fun4All_MBD_CalPass.C\(\"${inputs}\",1,-1,0,\"${dbtag}\"\) 
0193 root.exe -q -b Fun4All_MBD_CalPass.C\(\"${inputs}\",1,-1,0,\"${dbtag}\"\) 
0194 
0195 echo "Pass 1 calibration done"
0196 ls -la *.root
0197 
0198 ################################################
0199 # Pass 2 calibrations waveforms
0200 #./cups.py -r ${runnumber} -s ${segment} -d ${outbase} message "Running PASS 2 calibration, process waveforms"
0201 echo root.exe -q -b Fun4All_MBD_CalPass.C\(\"${inputs}\",2,${nevents},0,\"${dbtag}\"\)
0202 root.exe -q -b Fun4All_MBD_CalPass.C\(\"${inputs}\",2,${nevents},0,\"${dbtag}\"\)
0203 
0204 echo "Pass 2 calibration done (waveforms processed)"
0205 ls -la *.root
0206 
0207 # Flag as started
0208 #./cups.py -r ${runnumber} -s ${segment} -d ${outbase} running
0209 
0210 ################################################
0211 # Pass 2 calibrations (t0 offsets)
0212 # Pass 2 calibrations mip fits
0213 fname=$(ls -tr DST_UNCALMBD*.root | tail -1)
0214 echo Waveform processing done
0215 ls -ltr
0216 
0217 echo "###############################################################################################################"
0218 echo "Running pass2.0 calibration"
0219 #./cups.py -r ${runnumber} -s ${segment} -d ${outbase} message "Running PASS 2.0 calibration"
0220 pass=0
0221 echo root.exe -q -b cal_mbd.C\(\"${fname}\",${pass},${nevents}\)
0222 root.exe -q -b cal_mbd.C\(\"${fname}\",${pass},${nevents}\)
0223 #cp -p results/${runno}/pass0_mbd_tt_t0.calib results/${runno}/mbd_tt_t0.calib
0224 #cp -p results/${runno}/pass0_mbd_tq_t0.calib results/${runno}/mbd_tq_t0.calib
0225 mv results/${runno}/pass0_mbd_tt_t0.root results/${runno}/mbd_tt_t0-${runno}.root
0226 mv results/${runno}/pass0_mbd_tq_t0.root results/${runno}/mbd_tq_t0-${runno}.root
0227 
0228 echo "###############################################################################################################"
0229 echo "Running pass2.3 calibration"
0230 #./cups.py -r ${runnumber} -s ${segment} -d ${outbase} message "Running PASS 2.3 calibration"
0231 pass=3
0232 echo root.exe -q -b cal_mbd.C\(\"${fname}\",${pass},${nevents},${runtype}\)
0233 root.exe -q -b cal_mbd.C\(\"${fname}\",${pass},${nevents},${runtype},\"${dbtag}\"\)
0234 mv results/${runno}/mbd_qfit.root results/${runno}/mbd_qfit-${runno}.root
0235 
0236 echo "###############################################################################################################"
0237 echo "Running pass2.4 calibration"
0238 echo root.exe -q calib_t0mean.C\(\"results/${runno}/calmbdpass2.3_q_${runno}.root\"\)
0239 root.exe -q calib_t0mean.C\(\"results/${runno}/calmbdpass2.3_q-${runno}.root\"\)
0240 mv results/${runno}/mbd_t0corr.root results/${runno}/mbd_t0corr-${runno}.root
0241 
0242 # Flag as done
0243 #./cups.py -r ${runno} -s ${segment} -d ${outbase} message "Done"
0244 #./cups.py -r ${runno} -s ${segment} -d ${outbase} finished -e 0
0245 
0246 # Copy out files
0247 mkdir -p ${outdir}/${runno}
0248 #cp -p ${fname} ${outdir}/${runno}/   # dst_uncal root file
0249 for r in ${caldir}/*
0250 do
0251     # skip linked files
0252     if [[ -h $r ]]
0253     then
0254       continue
0255     fi
0256 
0257     cp -p ${r} ${outdir}/${runno}/
0258 
0259 done
0260 
0261 ################################################
0262 
0263 # Flag run as finished.  Increment nevents by zero
0264 #echo ./cups.py -v -r ${runno} -s ${segment} -d ${outbase} finished -e 0 --nevents 0 --inc 
0265 #     ./cups.py -v -r ${runno} -s ${segment} -d ${outbase} finished -e 0 --nevents 0 --inc 
0266 
0267 
0268 }  > ${logbase}.out 2>${logbase}.err 
0269 
0270 mkdir -p $logdir
0271 [[ "${logdir%/}" != "." ]] && cp -p ${logbase}.out  ${logdir}
0272 [[ "${logdir%/}" != "." ]] && cp -p ${logbase}.err  ${logdir}
0273 
0274 echo LOGBASE LOGDIR
0275 echo $logbase
0276 echo $logdir