Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:20

0001 #!/usr/bin/bash
0002 
0003 
0004 export TargetDir="$PWD"/condorout
0005 
0006 iter=1
0007 
0008 if [ "$iter" -eq 0 ]; then
0009   root -b "/sphenix/u/bseidlitz/work/cvpDev/analysis/EMCal_pi0_Calib_2023/macros/Fun4All_EMCal.C(0,\"inputdata.txt\",0,\"local_calib_copy.root\")"
0010   iter=$((iter+1))
0011 fi
0012 
0013 for((x=0;x<10;x++));
0014 do
0015 
0016 if [ -d ${TargetDir} ]; then
0017   if [ -d ${TargetDir}/OutDir0 ]; then
0018     rm -rf ${TargetDir}/OutDir*
0019   fi
0020 else
0021   mkdir ${TargetDir}
0022 fi
0023 condor_rm bseidlitz
0024 
0025 i=0
0026 while read dir; do 
0027   li=$(printf "%04d" $i)
0028 
0029   rm inputdata.txt
0030   
0031   # creates a list of all files for a particular run
0032   for file in /sphenix/lustre01/sphnxpro/commissioning/DST_ana.387_2023p003/DST_CALOR-000"$dir"-*.root
0033   do
0034 cat >>inputdata.txt<< EOF
0035 $file
0036 EOF
0037 done
0038 
0039   if [ "$iter" -eq 1 ]; then
0040     j=5
0041   else
0042     j=100
0043   fi
0044   tot_files=$( cat inputdata.txt | wc -l )
0045   echo "total files: $tot_files"
0046   rem=$(( $tot_files%$j ))
0047   files_per_job=$(( $tot_files/$j ))
0048   njob=$j
0049   if [ $rem -ne 0 ]; then
0050     files_per_job=$(( $files_per_job+1 ))
0051   fi
0052   rem2=$(( $tot_files%$files_per_job ))
0053   njob=$(( $tot_files/$files_per_job ))
0054   if [ $rem2 -ne 0 ]; then
0055     njob=$(( ($tot_files/$files_per_job)+1 ))
0056   fi
0057   echo "files per job: $files_per_job"
0058   echo "njob: $njob"
0059 
0060 
0061   for((q=0;q<$njob;q++));
0062   do
0063 
0064     mkdir ${TargetDir}/OutDir$i
0065     export WorkDir="${TargetDir}/OutDir$i"
0066     echo "WorkDir:" ${WorkDir}
0067     start_file=$(( $q*$files_per_job+1 ))
0068     end_file=$(( $start_file+$files_per_job-1 ))
0069     echo "start file: $start_file   end file: $end_file"
0070 
0071     sed -n $start_file\,${end_file}p inputdata.txt > tmp.txt
0072     mv tmp.txt ${WorkDir}/inputdata.txt
0073     
0074     pushd ${WorkDir}
0075 
0076       
0077     
0078     cp -v "$PWD"/../../CondorRun.sh CondorRunJob$li.sh
0079     cp -v "$PWD"/../../local_calib_copy.root . 
0080 
0081     sed -i "s/iteration/$iter/g" CondorRunJob$li.sh
0082 
0083     chmod +x CondorRunJob$li.sh
0084         
0085     
0086     cat >>ff.sub<< EOF
0087 +JobFlavour                   = "workday"
0088 transfer_input_files          = ${WorkDir}/CondorRunJob$li.sh, ${WorkDir}/input.txt
0089 Executable                    = CondorRunJob$li.sh
0090 request_memory                = 10GB
0091 Universe                      = vanilla
0092 Notification                  = Never
0093 GetEnv                        = True
0094 Priority                      = +12
0095 Output                        = condor.out
0096 Error                         = condor.err
0097 Log                           = /tmp/condor$li.log
0098 Notify_user                   = bs3402@columbia.edu
0099 
0100 Queue
0101 EOF
0102 
0103     condor_submit ff.sub
0104     popd
0105   
0106     i=$((i+1))
0107   done
0108 done < runList.txt # redirect the input of the
0109 
0110 # Set the directory where the files are located
0111 file_directory="${TargetDir}/OutDir*/DONE.root"
0112 
0113 while [ $(ls $file_directory | wc -l) -lt $((i-1)) ]; do
0114      current_file_count=$(ls $file_directory | wc -l)
0115     echo "Waiting for $((i-1)) files, currently $current_file_count"
0116     sleep 30  # Adjust the sleep duration as needed
0117 done
0118 
0119 export TargetHadd="$PWD"/combine_out
0120 
0121 if [ ! -d ${TargetHadd} ]; then
0122   mkdir ${TargetHadd}
0123 fi
0124 
0125 file_to_hadd="${TargetDir}/OutDir*/OUTHIST_iter*.root"
0126 
0127 hist_out=${TargetHadd}/out${iter}.root
0128 
0129 rm $hist_out 
0130 
0131 hadd -k $hist_out $file_to_hadd 
0132 
0133 ##################
0134 # FITTING (not done with condor
0135 ###################
0136 
0137 if [ "$iter" -eq 1 ]; then
0138   root -b "../doTscFit.C(\"${hist_out}\",\"local_calib_copy.root\")"
0139 else
0140   root -b "../doFitAndCalibUpdate.C(\"${hist_out}\",\"local_calib_copy.root\",$iter)"
0141 fi
0142 
0143 iter=$((iter+1))
0144 
0145 done