#!/bin/tcsh -f
#

# 
# process HDF_Eventpar on selected hdf file
#

if ( `hostname` != 'asellus' ) then
   echo "Error, run this script on host 'asellus' only"
   exit
endif

set cdir=`FDMgetpath`	# get current path, starting from the AC_Bias root

echo ${cdir} | grep 'ACBias_Analysis' > /dev/null
if ( ${status} != 0 ) then
   echo "Error, processing is only allowed in 'analysis' path"
   exit
endif 

if ( ${cdir} == '' ) then
   echo "Error, no proper path for data processing"
   exit
endif

set ddir='/ssd'`echo ${cdir} | sed 's^Analysis^Measurements^'`

if ( ! -d ${ddir} ) then
   echo "Error, data directory does not exist on SSD disc: ${ddir}"
   exit
endif

setenv NO_AT_BRIDGE 1    # prevent unneccesary error messages from GTK3

#source /opt/local/TN/env/tesfdmtools.csh       # standard scripts
#========================================== # edited scripts ( temporarely )
#setenv PYTHONPATH  /home/devries/Athena/git/tesfdmtools
#set path = ( /home/devries/Athena/git/tesfdmtools/scripts /home/devries/Athena/git/bin $path )
#===========================================

if ( $# > 0 ) then

   mHDF_Crosstalk $*
   exit

endif

foreach file ( `ls -1 ${ddir}/*.h5` )

   echo "process: ${file}"

   mHDF_Crosstalk -f all -q --pdf -sum --txtout ${file}  
   set txtnam="Crosstalk_"`basename ${file} .h5`"_px*.txt"
   set txtnams=`ls -1 ${txtnam}`
   Crosstalkmatrix -f $txtnams[1] 
   
end

chgrp tesfdm *
chmod g+w *


