#!/bin/bash
echo "This will take a while ... grab a coffee/tea/water"
mkdir -p logs
mkdir -p plots
fit_var="M3,angle_bl"
nice_fit_var=`echo $fit_var | sed 's/,/_/g'`
N_JOBS=4

echo "Using the fit variable(s): $fit_var"
# input_folder=/hdfs/TopQuarkGroup/run2/dpsData/data/normalisation/background_subtraction/
input_folder=data/normalisation/background_subtraction/
output_folder=tables/background_subtraction/
com=13
# typical_systematics="${output_folder}/${com}TeV/FullPS/typical_systematics_${com}TeV_combined.tex"
# typical_systematics_vis="${output_folder}/${com}TeV/VisiblePS/typical_systematics_${com}TeV_combined.tex"
# if [ -e $typical_systematics ];
# then
# 	echo "Cleaning up old typical systematics file for full phase space"
# 	rm $typical_systematics
# fi

# if [ -e $typical_systematics_vis ];
# then
# 	echo "Cleaning up old typical systematics file for visible phase space"
# 	rm $typical_systematics_vis
# fi

echo "Visible phase space ..."
i=0
for var in MET HT ST WPT lepton_pt abs_lepton_eta NJets; do
	echo "Tabulating diff. x-section for distribution: $var"
	# nohup time python dps/analysis/xsection/05_make_tables.py -v $var -c 13 -p $input_folder -o $output_folder -a --visiblePS &> logs/05_${var}_table_13TeV_vis.log &
	nohup python dps/analysis/xsection/05_make_systematic_plots.py -v $var --visiblePS  -p $input_folder -o $output_folder  &> logs/05_${var}_systematics_13TeV_vis.log &
	let i+=1
	if (( $i % N_JOBS == 0 ))
	then
		echo "Waiting on the above to finish."
    	wait;
	fi
done

wait;
echo "All done!"
