#!/bin/csh
# Generate calibration file and threshold files 
# This should be executed by phoncs@phoncs0 after calib.csh
# 3 feb 2004 added call to run_find.pl
#
#  > process_calib.csh

echo " *** Entering script process_calib.csh ***"
cd /home/phnxmvd/calib
run_find.pl
setenv RUN `cat runnumber_new`
echo $RUN

# Combine files and save to scratch disk
eventcombiner -n1000 /common/a1/calibdata/rc-$RUN-mvd.prdf /common/a1/calibdata/rc-0$RUN-MVD-*
echo "/common/a1/calibdata/rc-$RUN-mvd.prdf saved"

# Generate calibration file
cd /home/phnxmvd/calib/run
#source SetEnv
/bin/rm -f data.prdf
ln -s /common/a1/calibdata/rc-$RUN-mvd.prdf data.prdf
nice root -b < check.inp >& out2.txt 
echo "Ntuple file created !"

# Generate summaries of whether packets seem ok or not
# note that the output file name above (out2.txt) is hard-coded
# into the following script:
dogrep

# Generate threshold files
/bin/rm -f mvd*.thresh
nice root -b < calcthr.inp >& out3.txt 
tar -cf thresh$RUN.tar mvd*.thresh
cp thresh$RUN.tar ~/threshold_files
cp mvdsummary.txt mvdsummary$RUN.txt
gzip mvdsummary$RUN.txt 
echo "Threshold files created !"

