#!/bin/sh  
# \
exec tclsh "$0" "$@"

set input "forwardtrack.out"
set output "forwardtrack_rmcorr.sdds"


set c 299792458
set s56 [exec sddsanalyzebeam $input -pipe=out -correctedOnly | sddsprintout -pipe=in -column=s56 -noTitle -noLabel]
set s55 [exec sddsanalyzebeam $input -pipe=out -correctedOnly | sddsprintout -pipe=in -column=s55 -noTitle -noLabel]
set mom [exec sddsanalyzebeam $input -pipe=out -correctedOnly | sddsprintout -pipe=in -column=pAverage -noTitle -noLabel]
set ct  [exec sddsanalyzebeam $input -pipe=out -correctedOnly | sddsprintout -pipe=in -column=Ct -noTitle -noLabel]

set s11 [exec sddsanalyzebeam $input -pipe=out -correctedOnly | sddsprintout -pipe=in -column=s11 -noTitle -noLabel]
set s12 [exec sddsanalyzebeam $input -pipe=out -correctedOnly | sddsprintout -pipe=in -column=s12 -noTitle -noLabel]


set correl [expr $s56 / $s55 ]
set coeff  [expr 1.0 / ($correl * $mom)]

set coefx [expr $s11 / $s12]

puts $correl 
puts $coeff


#rematch only z,d
set dummy [exec sddsprocess $input $output "-redefine=col,t,t $ct - $coeff p * -" ]
# rematch both x,x' and z,delta
#set dummy [exec sddsprocess $input $output "-redefine=col,t,t $ct - $coeff p * -" "-redefine=col,x,x $coefx xp * -"]
 
exec sddsplot -graph=dot,vary $input $output -column=t,p -mode=x=center 
exec sddsplot -graph=dot,vary $input $output -column=x,xp 
