File indexing completed on 2026-05-23 08:12:16
0001
0002 export USER="$(id -u -n)"
0003 export LOGNAME=${USER}
0004 export HOME=/sphenix/u/${LOGNAME}/macros/detectors/sPHENIX/
0005
0006
0007 runnumber=0
0008 outDir=""
0009 triggertype="MB"
0010 dosubmit=false
0011 triggertype="MB"
0012 prodtype="26"
0013 condor_testfile="condor_blank.job"
0014 verbose=false
0015 superverbose=false
0016 allsegments=false
0017 filedensity=25
0018 nfiles=100
0019 makedatalist=false
0020 forcechunk=false
0021
0022
0023
0024 make_condor_jobs()
0025 {
0026 if [[ $nfiles -eq 0 ]]; then
0027 nfiles=`wc -l < ${triggertype}_data/jet_density_${filedensity}.list`
0028 fi
0029 P_or_H='true'
0030 if [[ $triggertype = *"Herwig"* ]]; then
0031 P_or_H='false'
0032 fi
0033 for i in $(seq 0 ${nfiles}); do
0034 j=$(( i+1 ))
0035 if [ $i -eq $nfiles ]; then
0036 break
0037 fi
0038 condor_file="$(pwd)/condor_file_dir/condor_"$triggertype"_seg_"$i"_counter.job"
0039 condor_out_file=$(pwd)"/condor_file_dir/condor_"$triggertype"_seg_"$i"_counter.out"
0040 condor_err_file=$(pwd)"/condor_file_dir/condor_"$triggertype"_seg_"$i"_counter.err"
0041 condor_log_file=$(pwd)"/condor_file_dir/condor_"$triggertype"_seg_"$i"_counter.log"
0042 global=`sed "${j}q;d" ${triggertype}_data/global_density_${filedensity}.list`
0043 truth=`sed "${j}q;d" ${triggertype}_data/truth_density_${filedensity}.list`
0044 jet=`sed "${j}q;d" ${triggertype}_data/jet_density_${filedensity}.list`
0045 calo=`sed "${j}q;d" ${triggertype}_data/calo_density_${filedensity}.list`
0046
0047 if [ "$vebose_mode" = true ]; then
0048 echo "Producing condor job file " $condor_file
0049 fi
0050 IFS=$'\n' read -d '' -r -a blanklines < $condor_testfile
0051 echo "${blanklines[0]}" > $condor_file
0052 echo "${blanklines[1]}"$(pwd)"/run_VandySkimmerTruthCounter.sh" >> $condor_file
0053 echo "${blanklines[2]}"$calo $truth $jet $global $outDir $MYINSTALL $(pwd) $P_or_H>> $condor_file
0054 echo "${blanklines[3]}"$condor_out_file >> $condor_file
0055 echo "${blanklines[4]}"$condor_err_file >> $condor_file
0056 echo "${blanklines[5]}"$condor_log_file >> $condor_file
0057 echo "${blanklines[6]} $outDir" >>$condor_file
0058 echo "${blanklines[7]}" >> $condor_file
0059 echo "${blanklines[8]}" >> $condor_file
0060 echo "${blanklines[9]}" " " $USER >> $condor_file
0061 echo "${blanklines[10]}" >> $condor_file
0062 echo "${blanklines[11]}" >> $condor_file
0063 echo "${blanklines[12]}" >> $condor_file
0064 echo "${blanklines[13]}" >> $condor_file
0065 done
0066 }
0067 make_home_dir()
0068 {
0069 if [ ! -d ${HOME} ]; then
0070 if [[ "$verbose" == true ]]; then
0071 echo "Home Directory doesn't exist. Creating now"
0072 fi
0073 mkdir -p ${HOME}
0074 fi
0075 }
0076
0077 set_out_dir()
0078 {
0079 if [[ "$outDir" == "" ]]; then
0080 outDir=/sphenix/tg/tg01/jets/${USER}/VandyDSTs/
0081 fi
0082 if [ ! -d ${outDir} ]; then
0083 if [[ "$verbose" == true ]]; then
0084 echo "Output Directory doesn't exist. Creating now"
0085 fi
0086 mkdir -p ${outDir}
0087 fi
0088 }
0089
0090 get_dst_list()
0091 {
0092 base_dir=$(pwd)
0093 if [ "$verbose" = true ]; then
0094 echo "Checking if data directory exists for ${triggertype}"
0095 fi
0096 if [ ! -d ${triggertype}"_data" ]; then
0097 if [ "$verbose" = true ]; then
0098 echo "data directory doesn't exist for ${triggertype}, fixing now"
0099 fi
0100
0101 mkdir -p ${triggertype}"_data"
0102 fi
0103 if [ "$verbose" = true ]; then
0104 echo "Create DST for ${triggertype}"
0105 fi
0106 cd ${triggertype}_data
0107 converttriggertype
0108 CreateFileList.pl -nopileup -type ${prodtype} -run 28 G4Hits DST_TRUTH_JET DST_CALO_CLUSTER DST_GLOBAL
0109 mv g4hits.list truth.list
0110 mv dst_truth_jet.list jet.list
0111 mv dst_calo_cluster.list calo.list
0112 mv dst_global.list global.list
0113 cd ${base_dir}
0114 }
0115 chunk_dst_list()
0116 {
0117 base_dir=$(pwd)
0118 cd ${triggertype}_data
0119 if [ "$verbose" = true ]; then
0120 echo "Checking if lookup file and file list exist for a per job density of ${filedensity} exists"
0121 fi
0122 listdir=lists_${filedensity}_per_file
0123 if [ ! -d ${listdir} ]; then
0124 mkdir -p $listdir
0125 fi
0126 if [ ! -f truth_density_${filedensity}.list ]; then
0127 forcechunk=true
0128 fi
0129 if [ "$forcechunk" = true ]; then
0130 if [ "$verbose" = true ]; then
0131 echo "Creating file lists and lookup files"
0132 fi
0133 if [ -f truth_density_${filedensity}.list ]; then
0134 rm truth_density_${filedensity}.list
0135 rm jet_density_${filedensity}.list
0136 rm calo_density_${filedensity}.list
0137 rm global_density_${filedensity}.list
0138 rm ${listdir}/*
0139 fi
0140 touch truth_density_${filedensity}.list
0141 touch jet_density_${filedensity}.list
0142 touch calo_density_${filedensity}.list
0143 touch global_density_${filedensity}.list
0144
0145 nChunks=0
0146 Nseg=`wc -l < truth.list`
0147 nSegsUsed=0
0148 while [ $nSegsUsed -le $Nseg ]; do
0149 nStop=$(( nSegsUsed + filedensity - 1 ))
0150 truthChunk=$(pwd)/${listdir}/truth_seg_${nSegsUsed}_to_${nStop}.list
0151 jetChunk=$(pwd)/${listdir}/jet_seg_${nSegsUsed}_to_${nStop}.list
0152 caloChunk=$(pwd)/${listdir}/calo_seg_${nSegsUsed}_to_${nStop}.list
0153 globalChunk=$(pwd)/${listdir}/global_seg_${nSegsUsed}_to_${nStop}.list
0154 if [ "$superverbose" = true ]; then
0155 echo "Building the following files"
0156 echo " Truth data (g4Hits): " $truthChunk
0157 echo " Jet data : " $jetChunk
0158 echo " Calo data : " $caloChunk
0159 echo " Global data: " $globalChunk
0160 fi
0161 touch ${truthChunk}
0162 touch ${jetChunk}
0163 touch ${caloChunk}
0164 touch ${globalChunk}
0165
0166 echo ${truthChunk} >> truth_density_${filedensity}.list
0167 echo ${jetChunk} >> jet_density_${filedensity}.list
0168 echo ${caloChunk} >> calo_density_${filedensity}.list
0169 echo ${globalChunk} >> global_density_${filedensity}.list
0170 line0=$(( nChunks * filedensity ))
0171 for i in $(seq 0 $filedensity); do
0172 j=$(( line0 + i + 1 ))
0173 nSegsUsed=$(( nSegsUsed + 1 ))
0174 if [[ $j -gt $Nseg || $j -gt $nStop ]]; then
0175 break
0176 fi
0177 if [ "$superverbose" = true ]; then
0178 echo "Looking at line " $j
0179 fi
0180 truth=`sed "${j}q;d" truth.list`
0181 jet=`sed "${j}q;d" jet.list`
0182 calo=`sed "${j}q;d" calo.list`
0183 global=`sed "${j}q;d" global.list`
0184
0185 echo ${truth} >> ${truthChunk}
0186 echo ${jet} >> ${jetChunk}
0187 echo ${calo} >> ${caloChunk}
0188 echo ${global} >> ${globalChunk}
0189 done
0190 nChunks=$(( nChunks + 1 ))
0191 if [[ $nSegsUsed -gt $Nseg ]]; then
0192 break
0193 fi
0194 done
0195 fi
0196 cd ${base_dir}
0197 }
0198 submit_condor_jobs(){
0199
0200 for n in $(seq 0 ${nfiles}); do
0201 if [ $n -ge ${nfiles} ]; then
0202 break
0203 fi
0204 i=$(pwd)"/condor_file_dir/condor_"$triggertype"_seg_"$n".job"
0205 condor_submit $i
0206 done
0207 }
0208
0209 has_argument(){
0210 [[ ("$1" == *=* && -n ${1
0211 }
0212
0213 extract_argument() {
0214 echo "${2:-${1#*=}}"
0215 }
0216
0217 handle_options()
0218 {
0219 while [ $
0220 case $1 in
0221 -h | --help)
0222 echo "Options for MC running of Vandy Skimmer"
0223 echo "$0 [OPTIONS]"
0224 echo "This script run the vandy skimmer over MC files"
0225 echo " "
0226 echo " -h, --help Display this message"
0227 echo " -v, --verbose Enable verbose job creation (Default false) "
0228 echo " -s, --submit Submit condor jobs (default false)"
0229 echo " -g, --get Makes the filelist for selected sample before running (default false)"
0230 echo " -c, --chunk Forces the recreation of the data chunks (default off, on if -g is called"
0231 echo " "
0232 echo " -t, --type Which trigger type "
0233 echo " MB (default)"
0234 echo " Jets:Jet5, Jet15, Jet20, Jet30, Jet40, Jet50"
0235 echo " PhotonJets: PhotonJet5, PhotonJet10"
0236 echo " "
0237 echo " -G, --generator Which generator "
0238 echo " Pythia (default), Herwig "
0239 echo " "
0240 echo " -n, --number How many files per chunk (default 25, 0 is all) "
0241 echo " "
0242 echo " -j, -jobs How many chunks/jobs to submit/make (default 100, 0 is all)"
0243 echo " "
0244 exit 0
0245 ;;
0246 -v | --verbose)
0247 verbose=true
0248 shift
0249 ;;
0250 -V )
0251 superverbose=true
0252 verbose=true
0253 shift
0254 ;;
0255 -s | --submit)
0256 dosubmit=true
0257 shift
0258 ;;
0259 -g | --get)
0260 makedatalist=true
0261 forcechunk=true
0262 shift
0263 ;;
0264 -c | --chunk)
0265 forcechunk=true
0266 shift
0267 ;;
0268 -t | --type)
0269 triggertype=$(extract_argument $@)
0270 shift
0271 shift
0272 ;;
0273 -n | --number)
0274 filedensity=$(extract_argument $@)
0275 shift
0276 shift
0277 ;;
0278 -G | --generator)
0279 gen=$(extract_argument $@)
0280 if [[ $gen = *"Herwig"* ]]; then
0281 trigger_type=${gen}${trigger_type}
0282 fi
0283 shift
0284 shift
0285 ;;
0286 -o | --outdir)
0287 outDir=$(extract_argument $@)
0288 shift
0289 shift
0290 ;;
0291 -j | --jobs)
0292 nfiles=$(extract_argument $@)
0293 if [ "$verbose" = true ]; then
0294 echo "Will submit ${nfiles} jobs with ${filedensity} segment(s) each"
0295 fi
0296 shift
0297 shift
0298 ;;
0299 *)
0300 echo "Invalid option: $1 "
0301 exit 1
0302 ;;
0303 esac
0304 done
0305 }
0306 converttriggertype()
0307 {
0308 if [ "${triggertype}" = "MB" ]; then
0309 prodtype=26
0310 elif [ "${triggertype}" = "Jet5" ]; then
0311 prodtype=36
0312 elif [ "${triggertype}" = "Jet10" ]; then
0313 prodtype=12
0314 elif [ "${triggertype}" = "Jet12" ]; then
0315 prodtype=39
0316 elif [ "${triggertype}" = "Jet15" ]; then
0317 prodtype=33
0318 elif [ "${triggertype}" = "Jet20" ]; then
0319 prodtype=21
0320 elif [ "${triggertype}" = "Jet30" ]; then
0321 prodtype=11
0322 elif [ "${triggertype}" = "Jet40" ]; then
0323 prodtype=19
0324 elif [ "${triggertype}" = "Jet50" ]; then
0325 prodtype=34
0326 elif [ "${triggertype}" = "Jet60" ]; then
0327 prodtype=38
0328 elif [ "${triggertype}" = "PhotonJet5" ]; then
0329 prodtype=27
0330 elif [ "${triggertype}" = "PhotonJet10" ]; then
0331 prodtype=28
0332 elif [ "${triggertype}" = "PhotonJet10" ]; then
0333 prodtype=29
0334 elif [ "${triggertype}" = "HerwigMB" ]; then
0335 prodtype=30
0336 elif [ "${triggertype}" = "HerwigJet5" ]; then
0337 prodtype=40
0338 elif [ "${triggertype}" = "HerwigJet10" ]; then
0339 prodtype=31
0340 elif [ "${triggertype}" = "HerwigJet12" ]; then
0341 prodtype=41
0342 elif [ "${triggertype}" = "HerwigJet15" ]; then
0343 prodtype=33
0344 elif [ "${triggertype}" = "HerwigJet20" ]; then
0345 prodtype=42
0346 elif [ "${triggertype}" = "HerwigJet30" ]; then
0347 prodtype=28
0348 elif [ "${triggertype}" = "HerwigJet40" ]; then
0349 prodtype=43
0350 elif [ "${triggertype}" = "HerwigJet50" ]; then
0351 prodtype=44
0352 elif [ "${triggertype}" = "HerwigJet60" ]; then
0353 prodtype=38
0354 elif [ "${triggertype}" = "HerwigPhotonJet5" ]; then
0355 prodtype=45
0356 elif [ "${triggertype}" = "HerwigPhotonJet10" ]; then
0357 prodtype=46
0358 elif [ "${triggertype}" = "HerwigPhotonJet10" ]; then
0359 prodtype=47
0360 fi
0361 }
0362 handle_options "$@"
0363 make_home_dir
0364 set_out_dir
0365 if [ "$verbose" = true ]; then
0366 echo "Running over ${nfiles} segement(s)"
0367 fi
0368 if [ "$makedatalist" = true ]; then
0369 get_dst_list
0370 fi
0371 chunk_dst_list
0372 make_condor_jobs
0373 if [ "$dosubmit" = true ]; then
0374 submit_condor_jobs
0375 fi
0376