From: <ro...@us...> - 2011-03-13 14:40:14
|
Revision: 1833 http://nsclspectcl.svn.sourceforge.net/nsclspectcl/?rev=1833&view=rev Author: ron-fox Date: 2011-03-13 14:40:08 +0000 (Sun, 13 Mar 2011) Log Message: ----------- First crack at y3f plots. Modified Paths: -------------- branches/LLNLMadcChainSpecTcl/CMultiplicity.cpp branches/LLNLMadcChainSpecTcl/CMultiplicity.h branches/LLNLMadcChainSpecTcl/SpecTclRC.tcl Added Paths: ----------- branches/LLNLMadcChainSpecTcl/ploty3f.tcl Modified: branches/LLNLMadcChainSpecTcl/CMultiplicity.cpp =================================================================== --- branches/LLNLMadcChainSpecTcl/CMultiplicity.cpp 2011-03-13 13:58:18 UTC (rev 1832) +++ branches/LLNLMadcChainSpecTcl/CMultiplicity.cpp 2011-03-13 14:40:08 UTC (rev 1833) @@ -1135,8 +1135,44 @@ double cbar = numerator/norm; // Really the centroid of the multiplicity distribution. return cbar; } - + +/* +** Calculate pair count: +**/ +double +CMultiplicity::pairs(int gate) +{ + double ps = 0.0; + + vector<unsigned> mult = getGateMultiplicities(gate); + + + for (int i = 1; i < mult.size(); i++) { + double coef = binomial(i,2); + ps += coef*mult[i]; + } + + return ps; +} + /** + ** Calculate triple count + */ +double +CMultiplicity::triples(int gate) +{ + double ts = 0.0; + + vector<unsigned> mult = getGateMultiplicities(gate); + + + for (int i = 1; i < mult.size(); i++) { + double coef = binomial(i,3); + ts += coef*mult[i]; + } + return ts; +} +/** ** Calclate the y2f or the feynman variance of the multiplicity for gate n ** @param gate - Gate number for which to calculate the y2f ** @return double @@ -1146,20 +1182,12 @@ CMultiplicity::y2f(int gate) { double cb = cbar(gate); - double pairs = 0.0; if (cb == 0.0) return 0.0; // special case. + double ps = pairs(gate);; - vector<unsigned> mult = getGateMultiplicities(gate); - - - for (int i = 2; i < mult.size(); i++) { - double coef = binomial(i,2); - pairs += coef*mult[i]; - } - - double result = (pairs/(cb*nbks(gate)) - 0.5*cb); + double result = (ps/(cb*nbks(gate)) - 0.5*cb); return result; } /** @@ -1171,25 +1199,22 @@ ** @param gate - Gate number for which to comput3 y3f. ** @return double ** @retval - y3f(gate). + ** + ** Formula: + ** y3(i) = triples[i] - cbar[i]*pairs[i] + 1/3 cbar[i]^3 + ** y3f(i) = y3(i)/cbar[i] */ double CMultiplicity::y3f(int gate) { double cb = cbar(gate); - double pairs = 0.0; if (cb == 0.0) return 0.0; // special case. + double ts = triples(gate); + double ps = pairs(gate); + double y = ts - cb*ps + cb*cb*cb/3.0; + return y/cb; - vector<unsigned> mult = getGateMultiplicities(gate); - - - for (int i = 3; i < mult.size(); i++) { - double coef = binomial(i,3); - pairs += coef*mult[i]; - } - - double result = (pairs/(cb*nbks(gate)) - 0.5*cb); - return result; } Modified: branches/LLNLMadcChainSpecTcl/CMultiplicity.h =================================================================== --- branches/LLNLMadcChainSpecTcl/CMultiplicity.h 2011-03-13 13:58:18 UTC (rev 1832) +++ branches/LLNLMadcChainSpecTcl/CMultiplicity.h 2011-03-13 14:40:08 UTC (rev 1833) @@ -180,6 +180,8 @@ // Utitities: private: + double pairs(int i); + double triples(int i); void saveTreeVariables(); void readTreeVariables(CTCLInterpreter& rInterp); void establishTraces(CTCLInterpreter& rInterp); Modified: branches/LLNLMadcChainSpecTcl/SpecTclRC.tcl =================================================================== --- branches/LLNLMadcChainSpecTcl/SpecTclRC.tcl 2011-03-13 13:58:18 UTC (rev 1832) +++ branches/LLNLMadcChainSpecTcl/SpecTclRC.tcl 2011-03-13 14:40:08 UTC (rev 1833) @@ -183,4 +183,8 @@ source [file join $here ploty2f.tcl] button .py2f -text {Y2f} -command [list Y2f .y2f] pack .py2f -fill x -expand 1 -puts done \ No newline at end of file + +source [file join $here ploty3f.tcl] +button .py3f -text {Y3f} -command [list Y3f .y3f] +pack .py3f -fill x -expand 1 +puts done Added: branches/LLNLMadcChainSpecTcl/ploty3f.tcl =================================================================== --- branches/LLNLMadcChainSpecTcl/ploty3f.tcl (rev 0) +++ branches/LLNLMadcChainSpecTcl/ploty3f.tcl 2011-03-13 14:40:08 UTC (rev 1833) @@ -0,0 +1,237 @@ +# This software is Copyright by the Board of Trustees of Michigan +# State University (c) Copyright 2009. +# +# You may use this software under the terms of the GNU public license +# (GPL). The terms of this license are described at: +# +# http://www.gnu.org/licenses/gpl.txt +# +# Author: +# Ron Fox +# NSCL +# Michigan State University +# East Lansing, MI 48824-1321 + + +package require Tk +package require snit + + +# +# Code to plot y2f as a function of time gate. +# +# The following control panel controls the plot: +# +# +--------------------------------------------------------------+ +# | [ ] Log Scale | +# | ( ) View ( ) Postscript | +# | XTitle [Gate ] | +# | YTitle [Y2f ] | +# | Title [Y2f v Gate ] | +# +--------------------------------------------------------------+ +# | [ Plot ] [ Cancel ] | +# +--------------------------------------------------------------+ + +snit::widget Y3f { + hulltype toplevel + # + # Default values for 'stuff' + # + typevariable defaultLogScale 0 + typevariable defaultPostscript 0 + typevariable defaultXtitle {Gate} + typevariable defaultYtitle {Y3f} + typevariable defaultTitle {Y3f vs. Gate} + + + # The following hold the actual values through the life of the dialog + + variable logScale + variable postscript + variable Xtitle + variable Ytitle + variable title + + + constructor args { + + + # + # Build the widgets: + # + + set work [ttk::frame $win.work -relief groove -borderwidth 3]; # Top frame with work controls + set action [ttk::frame $win.action]; # Bottom frame with action buttons. + + # Work area controls. + + ttk::checkbutton $work.log -text {Log Scale} -variable [myvar logScale] + ttk::radiobutton $work.screen -text {View} -variable [myvar postscript] -value 0 + ttk::radiobutton $work.postscript -text {Postscript} -variable [myvar postscript] -value 1 + ttk::label $work.xtitlel -text {X title} + ttk::entry $work.xtitle -textvariable [myvar Xtitle] + ttk::label $work.ytitlel -text {Y title} + ttk::entry $work.ytitle -textvariable [myvar Ytitle] + ttk::label $work.titlel -text {Plot Title} + ttk::entry $work.title -textvariable [myvar title] + + # Action area controls: + + ttk::button $action.plot -text {Plot} -command [mymethod plot] + ttk::button $action.cancel -text {Cancel} -command [mymethod cancel] + + # Layout the widgets + + grid $work.log -sticky w + grid $work.screen $work.postscript -sticky w + grid $work.xtitlel $work.xtitle -sticky w + grid $work.ytitlel $work.ytitle -sticky w + grid $work.titlel $work.title -sticky w + + grid $action.plot $action.cancel + + grid $work -sticky ew + grid $action -sticky ew + + # Apply the defaults + + set logScale $defaultLogScale + set postscript $defaultPostscript + set Xtitle $defaultXtitle + set Ytitle $defaultYtitle + set title $defaultTitle + + } + #------------------------- Action methods ------------------------------------- + + # + # cancel - called when the cancel action area button is clicked. + # $win is destroyed and no changes made to the typevariables. + # + method cancel {} { + after 100 [list destroy $win]; # Done to allow us exit before destruction. + } + # + # plot - Called when the plot button is clicked. A GNU Plot session is + # created and controlled via a pipe to plot the data + # + method plot {} { + $self gnuPlot + $self updateDefaults + $self cancel; # Kill the widget after the plot is done. + } + + #------------------------ Private methods --------------------------------- + + # Make the last set of values sticky to the next invocation + # + method updateDefaults {} { + set defaultLogScale $logScale + set defaultPostscript $postscript + set defaultXtitle $Xtitle + set defaultYtitle $Ytitle + set defaultTitle $title + + } + # + # Actually plot the data. + # + method gnuPlot {} { + set gateCount ${::multiplicity.bins}; # This many gates need plotting. + set binWidth ${::multiplicity.mintime}; # Width of each bin in nsec. + + set binWidth [expr $binWidth/1000.0]; # With in usec. + + # Create the data file: + + set dataFile [exec mktemp] + set df [open $dataFile w] + + set maxy 0.0 + for {set i 0} {$i < $gateCount} {incr i} { + set y [y3f $i] + if {$y > $maxy} { + set maxy $y + } + set t [expr $binWidth * ($i + 1)]; # t in usec. + set ty [list $t $y] + puts $df $ty + } + + close $df + + # Open the gnu plot and tell it what to do: + # note that if we're making postscript we need to prompt for the + # output file and set the appropriate paramters in gnuplot for postscript + # output to that file: + + set gp [open |gnuplot w] + +# set gp [open gnuplot.cmd w] + + if {$postscript} { + set outputFile [tk_getSaveFile \ + -defaultextension .ps \ + -title {Output file} \ + -filetypes { + {{Postscript} {.ps} } + {{All files} * } + } + ] + # + # An emtpy filename means he wants to reconsider the settings: + + if {$outputFile eq ""} return + puts $gp "set size 1.0, 0.6" + puts $gp "set terminal postscript portrait enhanced mono dashed lw 1 'Helvetica' 14" + puts $gp "set output '$outputFile'" + } + puts $gp "set title '$title'" + puts $gp "set xlabel '$Xtitle'" + puts $gp "set ylabel '$Ytitle'" + if {$logScale} { + puts $gp "set logscale y" + } + puts $gp "set key off" + + # Labels in the plot frame: + + set labelBase [expr $maxy - $maxy/20] + set labelX [expr $t/2] + set labelIncr [expr $maxy/15] + + puts $gp "set label \"[$self dataSourceLabel]\" at $labelX,$labelBase left" + + # End of the plot frame labels + + + + puts $gp "plot '$dataFile' with points 3 7"; # blue solid circles, red lines. + + puts $gp "pause mouse button3 'Click right mouse button in window to close'" + puts $gp " exit" + flush $gp + fconfigure $gp -blocking 0; # otherwise the close will hang until gnuplot exits. + close $gp + + if {$postscript} { + exec gv $outputFile & + } + + + } + # + # This method determines the data source label for the plot + #`< + method dataSourceLabel {} { + set rawSource [attach -list] + set type [lindex $rawSource 0] + if {$type eq "File:"} { + return [file tail [lindex $rawSource 1]] + } else { + return "Online" + } + } + + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |