Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #!/bin/bash
0002 
0003 currDir=$PWD
0004 
0005 cosmicsFile=$1 #cosmics runs
0006 tsFile=$2      #file to write merged TS root files to
0007 mergeNum=$3    #how many TS files to merge after given cosmics run #
0008 run_ohcal=$4   # true/false: run HCALOUT
0009 run_ihcal=$5   # true/false: run HCALIN
0010 
0011 
0012 dummyFile="dummy.txt"  #file to hold first 'x' files after cosmics run # - sort of a staging file to ensure we got right files
0013 tag="cosmics"          #when searching for merged ts files, make sure to look for "merged_XXXXX.root" and not the merged root files with "cosmics" in name - given we use cosmics in the name for this scripts output
0014 
0015 mkdir -p merged
0016 
0017 while IFS= read -r line
0018 do
0019 
0020     echo "looking at run " 
0021     echo "${IFS}" 
0022     x=0  #counter
0023     incr=$line
0024 
0025     #path to LCE output files
0026    # cd /sphenix/u/bseidlitz/work/macros/calibrations/calo/hcal_towerSlope_y2/cos_only_tsc_spec_output2/
0027    cd /sphenix/user/anjsmenon/work/macros/calibrations/calo/hcal_calib_year2/condor_histmaker/out_run/ 
0028 
0029     touch $dummyFile
0030 
0031     while [ $x -lt $mergeNum ]
0032     do
0033         
0034         incr=$(($incr+1))
0035 
0036         if [ $incr -gt 70000 ]; then
0037             echo "Incr has exceeded 60000, exiting loop."
0038             break
0039         fi
0040 
0041 
0042         FILE=`find ~+ -name "*$incr*" -not -name "*$tag*" -print -quit`
0043 
0044         if [[ -a $FILE ]]
0045         then
0046             echo $FILE >> $dummyFile
0047             x=$((x+1))
0048         fi
0049 
0050     done
0051     # Before running hadd, check if dummy.txt is empty
0052         if [ ! -s $dummyFile ]; then
0053              echo "No valid files found for run $line, skipping..."
0054               continue
0055         fi
0056 
0057     echo "Merging these files..."
0058     cat $dummyFile  
0059 
0060     #merge files in dummyFile and send to new text file
0061     string="$currDir/merged/mergedTS_cosmics_$line.root"
0062 
0063     rm $string 
0064     bash -c "hadd -f $string @$dummyFile"
0065 
0066     echo "$string" >> $tsFile
0067 
0068     rm $dummyFile
0069 
0070 done < $cosmicsFile
0071 
0072 mv $tsFile $currDir
0073 
0074 #execute fitting macro
0075 cd $currDir
0076 
0077 mkdir -p "$currDir/fitResults"
0078 
0079 
0080 root.exe -b -q run_cosmicsTS.C\(\"$cosmicsFile\",\"$tsFile\",$run_ohcal,$run_ihcal\) 
0081 
0082 echo "Finished running get_ts_files.sh."
0083 echo "All done!"