#!/bin/bash

DCFILESPATH=/nfs/magic/CaCodata/2004_03_19
SOURCE=Mrk421
BIN=./psffit

DCFILES=$(ls ${DCFILESPATH}/*${SOURCE}*.root)
#echo DCFILES ${DCFILES}

echo RUN SRCX SRCY
for DCFILE in ${DCFILES}
do
  DCFILE=${DCFILE//${DCFILESPATH}/.}
  #echo DCFILE ${DCFILE}
  RUN=${DCFILE:25:5}
  #echo RUN ${RUN}
  if [ RUN != '00000' ]; then
      SRCPOS=$(./${BIN} ${DCFILESPATH}/${DCFILE} | tail -1)
      #echo SRCPOS ${SRCPOS}
      SRCX=$(echo ${SRCPOS} | gawk '{print $2}') 
      SIGX=$(echo ${SRCPOS} | gawk '{print $3}') 
      SRCY=$(echo ${SRCPOS} | gawk '{print $4}')
      SIGY=$(echo ${SRCPOS} | gawk '{print $5}')
      CHI2=$(echo ${SRCPOS} | gawk '{print $6}')
      #echo ${RUN}  ${SRCX} ${SIGX} ${SRCY} ${SIGY} ${CHI2}
      echo ${RUN} ${SRCX} ${SRCY}
  fi
done
