From: Hadaq @ Hades33 Date: Thu, 12 Jul 2018 15:19:21 +0000 (+0200) Subject: removed division by zero bug, Michael X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=2197de08fd8c1077d8f698b409e0e6b823cdbeb3;p=hadesdaq.git removed division by zero bug, Michael --- diff --git a/hmon/hmon_startrate.pl b/hmon/hmon_startrate.pl index 60580f9..b6f41c0 100755 --- a/hmon/hmon_startrate.pl +++ b/hmon/hmon_startrate.pl @@ -193,7 +193,24 @@ HPlot::PlotInit({ buffer => 1, curvewidth => 2, }); - + +HPlot::PlotInit({ + name => "StartPosition", + file => "files/StartPosition", + entries => 500, + type => HPlot::TYPE_HISTORY, + output => HPlot::OUT_PNG, + titles => ["X position","Y position"], + xlabel => "Seconds", + ylabel => "Strip", + sizex => 950, + sizey => 330, + ymin => "-0.5", + ymax => "15.5", + curves => 2, + xscale => 5, + buffer => 1, + }); my $str = Hmon::MakeTitle(13, 22, "Start / Veto Rate",0); $str .= qq@

Start X


\n@; @@ -215,14 +232,20 @@ $str .= qq@\n@; $str .= qq@
\n@; $str .= Hmon::MakeFooter(); Hmon::WriteFile("StartBars",$str); + +$str = Hmon::MakeTitle(13, 8, "Start Position",0); +$str .= qq@\n@; +Hmon::WriteFile("StartPosition",$str); + my $old; my $diff; my $oldtime; my $iter = 0; my @chan = qw(0 0 2 4 6 8 10 12 14 15 13 11 9 7 5 3 1); my @chanveto = qw(0 2 7 3 4 0 5 1 6); - + + while(1) { my $o = trb_registertime_read_mem(0xfe48,0xc000,0,17); # or die trb_strerror() or sleep 5 and next; @@ -239,7 +262,9 @@ while(1) { } $oldtime->{$b} = $o->{$b}{time}[0]; } - + + my ($sumx,$sumy,$avgx,$avgy) = (0,0,0,0); + for my $c (1..16) { HPlot::PlotAdd("StartRateXhist",$diff->{0x5000}[$c],$chan[$c]); HPlot::PlotAdd("StartRateYhist",$diff->{0x5001}[$c],$chan[$c]); @@ -247,14 +272,29 @@ while(1) { HPlot::PlotAdd("StartRateYhistbar",$diff->{0x5001}[$c],$chan[$c]); HPlot::PlotFill("StartXbar",$diff->{0x5000}[$c],$chan[$c]); HPlot::PlotFill("StartYbar",$diff->{0x5001}[$c],$chan[$c]); + + $sumx += $diff->{0x5000}[$c]; + $sumy += $diff->{0x5001}[$c]; + + $avgx += $diff->{0x5000}[$c]*$chan[$c]; + $avgy += $diff->{0x5001}[$c]*$chan[$c]; + } - + $avgx /= $sumx if($sumx !=0); + $avgy /= $sumy if($sumy !=0); + + $avgx = "NaN" if $sumx < 50; + $avgy = "NaN" if $sumy < 50; + + HPlot::PlotAdd("StartPosition",$avgx,0); + HPlot::PlotAdd("StartPosition",$avgy,1); + for my $c (1..8) { HPlot::PlotAdd("VetoRatehist",$diff->{0x5002}[$c],$chanveto[$c]); HPlot::PlotAdd("VetoRatehistbar",$diff->{0x5002}[$c],$chanveto[$c]); HPlot::PlotFill("Vetobar",$diff->{0x5002}[$c],$chanveto[$c]); } - + HPlot::PlotDraw('StartRateXhist') if ($iter == 0); HPlot::PlotDraw('StartRateYhist') if ($iter == 1); HPlot::PlotDraw('VetoRatehist') if ($iter == 2); @@ -264,11 +304,12 @@ while(1) { HPlot::PlotDraw('StartXbar') if ($iter == 6); HPlot::PlotDraw('StartYbar') if ($iter == 7); HPlot::PlotDraw('Vetobar') if ($iter == 8); - $iter = 0 if ($iter++ == 8) - + HPlot::PlotDraw('StartPosition') if ($iter == 9); + $iter = 0 if ($iter++ == 9) + } - - + + $old = $o; usleep(200000); - } \ No newline at end of file + }