# to remove erroneous jobs:
# for job in `qstat | grep ${USER} | awk '{print $1;}'`; do qdel ${job}@farm-ce; done

swsource=$HOME/STAging/macros/CCEScan
scripts=$swsource/batch
logs=/disk/data1/hep/elena/logs/ST/CCEScan

vals=(3 5 7)
rads=(75 45 40)

echo "Backup file!"
echo "cp /disk/data1/hep/elena/data/ST/Aging/CCEScan.root /disk/data1/hep/elena/data/ST/Aging/CCEScan_backup_Jan16.root"
cp /disk/data1/hep/elena/data/ST/Aging/CCEScan.root /disk/data1/hep/elena/data/ST/Aging/CCEScan_backup_Jan16.root


#echo "Submitting TT:"
#onefill=(4643)
#for fill in `cat $swsource/Fills.dat`
##for fill in $onefill
#do
#    echo "    Submitting fill "$fill
#    for sector in `cat $swsource/TTsectors.dat`
#    do
#	echo "        Sector "$sector
#	scriptname="landauFit_TT_f${fill}_s${sector}_allSteps_allVal"
#	cp $scripts/base.sh $scripts/temp_scripts/${scriptname}.sh
#	for i in {0..65}
#	do
#	    for val in "${vals[@]}"
#	    do
#		echo "${swsource}/landauFit -d TT -l TTaU -s ${sector} -f ${fill} -c ${i} -v ${val} -b -ss" >> $scripts/temp_scripts/${scriptname}.sh
#	    done
#	done
#	qsub -l cput=75000 $scripts/temp_scripts/${scriptname}.sh -o ${logs}/${scriptname}.log -e ${logs}/${scriptname}.log -j oe
#	#sleep 2
#    done
#done
#
#echo "Submitting TT inner sectors:"
#for fill in `cat $swsource/Fills.dat`
#onefill=(4643)
##for fill in $onefill
#do
#    echo "    Submitting fill "$fill
#    for sector in `cat $swsource/TTinner.dat`
#    do
#	echo "        Sector "$sector
#	scriptname="landauFit_TTinner_f${fill}_s${sector}_allSteps_allVal_allRads"
#	cp $scripts/base.sh $scripts/temp_scripts/${scriptname}.sh
#	for i in {0..65}
#	do
#	    for val in "${vals[@]}"
#	    do
#		for rad in "${rads[@]}"
#		do
#		    echo "${swsource}/landauFit -d TT -l TTaU -s ${sector} -f ${fill} -c ${i} -v ${val} -r ${rad} -b -ss" >> $scripts/temp_scripts/${scriptname}.sh
#		done
#	    done
#	done
#	qsub -l cput=225000 $scripts/temp_scripts/${scriptname}.sh -o ${logs}/${scriptname}.log -e ${logs}/${scriptname}.log -j oe
#	#sleep 2
#    done
#done
#


onefill=(4643)

echo "Submitting IT:"
for sector in `cat $swsource/ITsectors.dat`
do
    echo "    Sector " $sector
    #for fill in $onefill
    for fill in `cat $swsource/Fills.dat`
    do
	echo "        Fill "$fill
	val=7
	scriptname="landauFit_IT_s${sector}_f${fill}_allSteps_v${val}"
	echo "Creating file " $scripts/temp_scripts/${scriptname}.sh
	cp $scripts/base.sh $scripts/temp_scripts/${scriptname}.sh
	for i in {0..65}
	do
	    echo "${swsource}/landauFit -d IT -l T3X2 -s ${sector} -f ${fill} -c ${i} -v ${val} -b -ss" >> $scripts/temp_scripts/${scriptname}.sh
	done
	qsub -l cput=24000 $scripts/temp_scripts/${scriptname}.sh -o ${logs}/${scriptname}.log -e ${logs}/${scriptname}.log -j oe
	sleep 1
    done
done

echo "Submitting IT inner sectors:"
for sector in `cat $swsource/ITinner.dat`
do
    echo "    Sector " $sector
    #for fill in $onefill
    for fill in `cat $swsource/Fills.dat`
    do
	echo "        Fill "$fill
	val=7
	scriptname="landauFit_ITinner_s${sector}_f${fill}_allSteps_v${val}_r175"
	cp $scripts/base.sh $scripts/temp_scripts/${scriptname}.sh
	for i in {0..65}
	do
	    echo "${swsource}/landauFit -d IT -l T3X2 -s ${sector} -f ${fill} -c ${i} -v ${val} -r 175 -b -ss" >> $scripts/temp_scripts/${scriptname}.sh
	done
	qsub -l cput=24000 $scripts/temp_scripts/${scriptname}.sh -o ${logs}/${scriptname}.log -e ${logs}/${scriptname}.log -j oe
	sleep 1
    done
done


