#!/bin/tcsh
set package = /data/sleipnir1/marc/PawianPhase/Pawian/Examples/JpsiGamKsKlKK/

set singleFiles = "components.pdf"
foreach dir (`find -type d -name "????"|sort`)
	
     if (! (-e $dir/finalResult.dat )) then
	echo No final result for directory $dir 
        continue
    endif

     echo $dir
     
     cd $dir
	
     set singleFiles = "$singleFiles $dir/tmp.pdf $dir/qaPlots.ps"
     
     #$package/bin/gcc-4.1.2/release/link-static/MJpsiGamKlKsKKApp -c MassIndep.cfg --paramFile finalResult.dat --mode qaMode
     
     $package/scripts/makeTexTable.pl ../$dir/finalResult.dat

     root -b -q -x $package/plotQA.C
     
     rm tmp.aux tmp.tex tmp.log 

    cd ..
    
end

rm MassIndep.root
find -name "*.root" | xargs -n10 hadd -f MassIndep.root 
root -b -q -x $package'/plotMassIndep.C+("MassIndep.root")'

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=FitResultsQa.pdf $singleFiles
