# Run AMU pedestal calibration and generated ped files
#  > process_calib.csh
# 7 jan 04: added call to run_find.pl to catch advancing run numbers. HvH

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

# Combine files and save to scratch disk
eventcombiner -n2500 -f /common/a1/calibdata/rc-$RUN-mvd.prdf /common/a1/calibdata/rc-0$RUN-MVD-*

echo "/common/a1/calibdata/rc-$RUN-mvd.prdf saved"

# Generate ped files
cd /home/phnxmvd/calib/run
source SetEnv
/bin/rm -f data.prdf
ln -s /common/a1/calibdata/rc-$RUN-mvd.prdf data.prdf

/bin/rm -f mvd*.ped
nice root -b < calib_ped.inp >& out.txt 
/bin/rm -f ped.tar
tar -cf ped.tar mvd*.ped 
mv ped.tar ~/ped_files/ped$RUN.tar
echo "Ped files completed!"


