#!/bin/csh -f

setenv COATJAVA /volatile/clas12/devita/tutorial/coatjava-4a.8.2
setenv PATH /group/clas12/groovy-2.4.10/bin/:$PATH


# go to work directory for this tutorial exercise
cd /volatile/clas12/devita/tutorial/

# list files there: the directory contains a 10000 event simulation of elastic event at 6.4 GeV beam energy
# ...evio : gemc output
# ...hipo : gemc output vonverted to hipo
# ...rec.hipo : reconstructed file
ls -l


# browsing the content of evio (gemc files) and hipo files with eviodump
$COATJAVA/bin/eviodump e64_th5_35_p05.00100.evio 

# look at evio XML dictionary
ls /volatile/clas12/devita/tutorial/coatjava-4a.8.2/bin/..//etc/bankdefs/clas12
 more $COATJAVA/etc/bankdefs/clas12/FTOF.xml

# check "decoded" hipo file
$COATJAVA/bin/eviodump e64_th5_35_p05.00100.hipo

# check "cooked" file
$COATJAVA/bin/eviodump e64_th5_35_p05.00100.rec.hipo

# look at hipo banks
ls $COATJAVA/etc/bankdefs/hipo/
more $COATJAVA/etc/bankdefs/hipo/DC.json


# filter file wirh hipo-util
# check available options
$COATJAVA/bin/hipo-utils 

# run filter to keep a subset of the original banks
$COATJAVA/bin/hipo-utils -o filteredFile.hipo -keep RUN:MC:REC e64_th5_35_p05.00100.rec.hipo 
$COATJAVA/bin/eviodump filteredFile.hipo

# run filter to keep a subset of the original banks filtering events with one forward track
$COATJAVA/bin/hipo-utils -o filteredFile.hipo -keep RUN:MC:REC -filter TimeBasedTrkg::TBTracks e64_th5_35_p05.00100.rec.hipo 
$COATJAVA/bin/eviodump filteredFile.hipo

# filter with groovy script
$COATJAVA/bin/run-groovy filter_tracks.groovy e64_th5_35_p05.00100.rec.hipo
