#!/bin/bash
echo "test93: reweightprocess (15 sec)"

cat >test93.in <<!
	param histoFile=""
	physics QGSP_BERT 
	reweightprocess process=Decay ratio=2
	beam gaussian particle=pi+ meanMomentum=200 nEvents=10000
	box end height=1 width=1 length=1
	place end z=100000
	beamlossntuple test93 format=ascii require=ParentID==0
!

cat >test93.awk <<!
# print the average of column 3 (z)
BEGIN	{ n=0; sum=0; w=0; sumw=0;}
/^#/	{ next; }
	{ ++n; sum += \$3; w += \$12; sumw += \$3 * \$12; }
END	{ print sum/n, sumw/w, n, w; }
!

cat >test93.good <<-!
5613.61 11500
!

if ! g4bl test93.in >test93.out 2>&1
then
	echo "****** test93: g4bl FAILED! -- test93.* files left intact"
	exit 1
fi

awk -f test93.awk <test93.txt >test93.avg

if ! ./comparecols test93.avg test93.good 250 3000
then
	echo "****** test93: Output Files DIFFER -- test93.* files left intact"
	exit 1
fi


# clean up and exit
rm test93.*
exit 0