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

echo "Using the fit variable(s): $fit_var"

i=0
for var in MET HT ST WPT MT; do
	echo "Plotting fit correlations for distribution: $var"
	nohup time python dps/analysis/xsection/98_fit_cross_checks.py -v $var -e 7 --fit-variables $fit_var &> logs/98_${var}_fit_cross_checks_7TeV_${nice_fit_var}.log &
	let i+=1
		if (( $i % N_JOBS == 0 ))
	then
		echo "Waiting on the above to finish."
    	wait;
	fi
	
	nohup time python dps/analysis/xsection/98_fit_cross_checks.py -v $var -e 8 --fit-variables $fit_var &> logs/98_${var}_fit_cross_checks_8TeV_${nice_fit_var}.log &
	let i+=1
	if (( $i % N_JOBS == 0 ))
	then
		echo "Waiting on the above to finish."
    	wait;
	fi
done

wait;
echo "98_fit_cross_checks all done!"

# For this check, fit results for all combinations of fit variables are needed. Uncomment manually before running.
#i=0
#for var in MET HT ST WPT MT; do
#	echo "Doing 98b cross checks for distribution: $var"
#	nohup time python dps/analysis/xsection/98b_fit_cross_checks.py -v $var -e 7 &> logs/98b_${var}_fit_cross_checks_7TeV_${nice_fit_var}.log &
#	let i+=1
#	nohup time python dps/analysis/xsection/98b_fit_cross_checks.py -v $var -e 8 &> logs/98b_${var}_fit_cross_checks_8TeV_${nice_fit_var}.log &
#	let i+=1
#	if (( $i % N_JOBS == 0 ))
#	then
#		echo "Waiting on the above to finish."
#    	wait;
#	fi
#done
#echo "98b_fit_cross_checks all done! Moving on to 98c_fit_cross_checks."

# For this check, fit results for all combinations of fit variables are needed. Uncomment manually before running.
#i=0
#for var in MET HT ST WPT MT; do
#	echo "Doing 98c cross checks for distribution: $var"
#	nohup time python dps/analysis/xsection/98c_fit_cross_checks.py -v $var -e 7 &> logs/98c_${var}_fit_cross_checks_7TeV_${nice_fit_var}.log &
#	let i+=1
#	nohup time python dps/analysis/xsection/98c_fit_cross_checks.py -v $var -e 8 &> logs/98c_${var}_fit_cross_checks_8TeV_${nice_fit_var}.log &
#	let i+=1
#	if (( $i % N_JOBS == 0 ))
#	then
#		echo "Waiting on the above to finish."
#    	wait;
#	fi
#done
#echo "98c_fit_cross_checks all done! Moving on to 98c_fit_cross_checks."