Skip to content

Commit

Permalink
add scripts for processing ntuples from the ntuple maker
Browse files Browse the repository at this point in the history
  • Loading branch information
nitish-nayak committed Jul 29, 2024
1 parent 93bb2c6 commit 981d26e
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
63 changes: 63 additions & 0 deletions scripts/processing/prepare_process.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# Make box around text @climagic
function box() { t="$1xxxx";c=${2:-=}; echo ${t//?/$c}; echo "$c $1 $c"; echo ${t//?/$c}; }

usage() { echo "Usage: $0 [-i <path to input txt files>] [-o <path to output directory>] [-n] (optional : for numi)" 1>&2; exit 1; }

numi=false
while getopts ":i:o:nh" opt; do
case "$opt" in
i)
inputtxt="$OPTARG"
;;
o)
outdir="$OPTARG"
;;
n)
numi=true
;;
h | *)
usage
exit 1
;;
esac
done

if [[ ! -e "$inputtxt" || -z "$outdir" ]]; then
echo "Either an invalid input text file provided with -i or an invalid output directory with -o - Exiting!"
usage
exit 1
fi

if [[ ! -d "$outdir" ]]; then
echo "Making output directory"
mkdir -p "$outdir"
fi

if [[ "$numi" ]]; then
box "Processing for NuMI"
fi

box "Pruning CV to "$outdir"/cv.root"
prune_checkout_trees $inputtxt $outdir"/cv.root"

# process systs
systs=("UBGenieFluxSmallUni" \
"expskin_FluxUnisim" "horncurrent_FluxUnisim" "kminus_PrimaryHadronNormalization" \
"kplus_PrimaryHadronFeynmanScaling" "kzero_PrimaryHadronSanfordWang" "nucleoninexsec_FluxUnisim" "nucleonqexsec_FluxUnisim" "nucleontotxsec_FluxUnisim" \
"piminus_PrimaryHadronSWCentralSplineVariation" "pioninexsec_FluxUnisim" "pionqexsec_FluxUnisim" "piontotxsec_FluxUnisim" "piplus_PrimaryHadronSWCentralSplineVariation" \
\
"reinteractions_piminus_Geant4" "reinteractions_piplus_Geant4" "reinteractions_proton_Geant4")

box "Launching threads for pruning the systematic files"
for syst in "${systs[@]}"; do
echo $syst
if [[ "$numi" ]]; then
prune_weightsep24_trees $inputtxt $outdir"/"$syst".root" $syst &
else
prune_weightsep24_trees_numi $inputtxt $outdir"/"$syst".root" $syst &
fi
sleep 10
done
wait
92 changes: 92 additions & 0 deletions scripts/processing/process_checkout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# Make box around text @climagic
function box() { t="$1xxxx";c=${2:-=}; echo ${t//?/$c}; echo "$c $1 $c"; echo ${t//?/$c}; }

usage() { echo "Usage: $0 [-c <path to pruned cv file>] [-s <path to folder containing pruned syst files>] [-o <path to output folder>] [-p \"prefix name for the output CV file\"]" 1>&2; exit 1; }

data=false
while getopts ":c:s:o:p:h" opt; do
case "$opt" in
c)
inputcv="$OPTARG"
;;
s)
inputsystfolder="$OPTARG"
;;
o)
outfolder="$OPTARG"
;;
p)
outcvname="$OPTARG"
;;
h | *)
usage
exit 1
;;
esac
done

if [[ -z "$inputsystfolder" ]]; then
echo "No input syst folder provided. Assuming data!"
data=true
fi

if [[ -z "$outfolder" || -z "$outcvname" ]]; then
echo "Either no output folder (with -o) or no output prefix provided (with -p). Exiting!"
usage
exit 1
fi

if [[ ! -e "$inputcv" ]]; then
echo "Provide valid input cv file with -c - Exiting!"
usage
exit 1
fi

if [[ ! -d "$inputsystfolder" ]]; then
echo "Could not find input syst folder provided by -s - Exiting!"
usage
exit 1
fi

if [[ ! -d "$outfolder" ]]; then
echo "Making output directory"
mkdir -p "$outfolder"
fi

if [[ ! -d $outfolder"/systs" && ! "$data" ]]; then
echo "Making output directory for systs"
mkdir -p $outfolder"/systs"
fi


systs=("UBGenieFluxSmallUni" \
"expskin_FluxUnisim" "horncurrent_FluxUnisim" "kminus_PrimaryHadronNormalization" \
"kplus_PrimaryHadronFeynmanScaling" "kzero_PrimaryHadronSanfordWang" "nucleoninexsec_FluxUnisim" "nucleonqexsec_FluxUnisim" "nucleontotxsec_FluxUnisim" \
"piminus_PrimaryHadronSWCentralSplineVariation" "pioninexsec_FluxUnisim" "pionqexsec_FluxUnisim" "piontotxsec_FluxUnisim" "piplus_PrimaryHadronSWCentralSplineVariation" \
"reinteractions_piminus_Geant4" "reinteractions_piplus_Geant4" "reinteractions_proton_Geant4")

# process CV first
box "Processing CV"

box "BDT Convert"
bdt_convert $inputcv cv_bdt.tmp.root

cvfile=$outfolder"/"$outcvname".root"

box "Converting CV and writing to "$cvfile
convert_cv_spec "cv_bdt.tmp.root" $cvfile
rm cv_bdt.tmp.root

# process systs
if [[ !"$data" ]]; then
box "Processing for systematics"

for syst in "${systs[@]}"; do
box $syst
merge_xf $cvfile $inputsystfolder"/"$syst".root" $outfolder"/systs/"$syst".root" $syst &
sleep 5
done
wait
fi

0 comments on commit 981d26e

Please sign in to comment.