Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:21:01

0001 #!/usr/bin/bash
0002 
0003 ############################################
0004 # Blair Seidlitz
0005 # this script does an iterative emcal calib
0006 # which runs event skimming on condor and 
0007 # does fitting locally.
0008 #
0009 # iteration 0 -> iter=0
0010 # pulls a calibration from currenttly calling it 
0011 # local_calib_copy.root to use in calotowercalib 
0012 # iteration 1
0013 # tower slope method
0014 # iteration >= 2 
0015 # pi0 iterative method
0016 #############################################
0017 
0018 
0019 export TargetDir="$PWD"/condorout
0020 
0021 iter=0
0022 
0023 while read dir; do 
0024   rm inputdata.txt
0025   for file in /sphenix/lustre01/sphnxpro/commissioning/DST_ana.395_2023p007/DST_CALO*-000"$dir"-*.root
0026   do
0027 cat >>inputdata.txt<< EOF
0028 $file
0029 EOF
0030 done
0031 done < runList.txt # redirect the input of the
0032 
0033 
0034 if [ "$iter" -eq 0 ]; then
0035   root "../Fun4All_EMCal.C(0,\"inputdata.txt\",0,\"local_calib_copy.root\")"
0036   iter=$((iter+1))
0037 fi
0038 
0039 
0040 # upper bound on x determines number of iterations
0041 for((x=0;x<35;x++));
0042 do
0043 
0044 if [ -d ${TargetDir} ]; then
0045   if [ -n "$(ls -A ${TargetDir}/OutDir*)" ]; then
0046     rm -rf ${TargetDir}/OutDir*
0047   fi
0048 else
0049   mkdir ${TargetDir}
0050 fi
0051 
0052 i=0
0053 while read dir; do 
0054   li=$(printf "%04d" $i)
0055 
0056   rm inputdata.txt
0057   
0058   # creates a list of all files for a particular run
0059   for file in /sphenix/lustre01/sphnxpro/commissioning/DST_ana395_2023p007/DST_CALO*-000"$dir"-*.root
0060   do
0061 cat >>inputdata.txt<< EOF
0062 $file
0063 EOF
0064 done
0065 
0066   if [ "$iter" -le 3 ]; then
0067     j=16
0068   else
0069     j=100
0070   fi
0071   tot_files=$( cat inputdata.txt | wc -l )
0072   echo "total files: $tot_files"
0073   rem=$(( $tot_files%$j ))
0074   files_per_job=$(( $tot_files/$j ))
0075   njob=$j
0076   if [ $rem -ne 0 ]; then
0077     files_per_job=$(( $files_per_job+1 ))
0078   fi
0079   rem2=$(( $tot_files%$files_per_job ))
0080   njob=$(( $tot_files/$files_per_job ))
0081   if [ $rem2 -ne 0 ]; then
0082     njob=$(( ($tot_files/$files_per_job)+1 ))
0083   fi
0084   echo "files per job: $files_per_job"
0085   echo "njob: $njob"
0086 
0087 
0088   for((q=0;q<$njob;q++));
0089   do
0090 
0091     mkdir ${TargetDir}/OutDir$i
0092     export WorkDir="${TargetDir}/OutDir$i"
0093     echo "WorkDir:" ${WorkDir}
0094     start_file=$(( $q*$files_per_job+1 ))
0095     end_file=$(( $start_file+$files_per_job-1 ))
0096     echo "start file: $start_file   end file: $end_file"
0097 
0098     sed -n $start_file\,${end_file}p inputdata.txt > tmp.txt
0099     mv tmp.txt ${WorkDir}/inputdata.txt
0100     
0101     pushd ${WorkDir}
0102 
0103       
0104     
0105     cp -v "$PWD"/../../CondorRun.sh CondorRunJob$li.sh
0106     cp -v "$PWD"/../../local_calib_copy.root . 
0107     cp "$PWD"/../../../Fun4All_EMCal.C .
0108 
0109     sed -i "s/iteration/$iter/g" CondorRunJob$li.sh
0110 
0111     chmod +x CondorRunJob$li.sh
0112         
0113     
0114     cat >>ff.sub<< EOF
0115 +JobFlavour                   = "workday"
0116 transfer_input_files          = ${WorkDir}/CondorRunJob$li.sh, ${WorkDir}/inputdata.txt,${WorkDir}/Fun4All_EMCal.C
0117 Executable                    = CondorRunJob$li.sh
0118 request_memory                = 2GB
0119 Universe                      = vanilla
0120 Notification                  = Never
0121 GetEnv                        = True
0122 Priority                      = +12
0123 Output                        = condor.out
0124 Error                         = condor.err
0125 Log                           = /tmp/condor$li.log
0126 Notify_user                   = bs3402@columbia.edu
0127 
0128 Queue
0129 EOF
0130 
0131     condor_submit ff.sub
0132     popd
0133   
0134     i=$((i+1))
0135   done
0136 done < runList.txt # redirect the input of the
0137 
0138 # Set the directory where the files are located
0139 file_directory="${TargetDir}/OutDir*/DONE.root"
0140 
0141 while [ $(ls $file_directory | wc -l) -lt $((i)) ]; do
0142      current_file_count=$(ls $file_directory | wc -l)
0143     echo "Waiting for $((i)) files, currently $current_file_count"
0144     sleep 30  # Adjust the sleep duration as needed
0145 done
0146 
0147 export TargetHadd="$PWD"/combine_out
0148 
0149 if [ ! -d ${TargetHadd} ]; then
0150   mkdir ${TargetHadd}
0151 fi
0152 
0153 file_to_hadd="${TargetDir}/OutDir*/OUTHIST_iter*.root"
0154 
0155 hist_out=${TargetHadd}/out${iter}.root
0156 
0157 rm $hist_out 
0158 
0159 hadd -k $hist_out $file_to_hadd 
0160 
0161 ################################
0162 # FITTING (not done with condor
0163 
0164 if [ "$iter" -le 3 ]; then
0165   root -b "../doTscFit.C(\"${hist_out}\",\"local_calib_copy.root\",$iter)"
0166 else
0167   root -b "../doFitAndCalibUpdate.C(\"${hist_out}\",\"local_calib_copy.root\",$iter)"
0168 fi
0169 
0170 iter=$((iter+1))
0171 
0172 done