GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4RollingGraph.cxx
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#include "TGo4RollingGraph.h"
15
16#include "TMath.h"
17
27
33TGo4RollingGraph::TGo4RollingGraph(Int_t NumPoints, Int_t UpdateInterval)
34 : TGraphErrors(), fiNumPoints(NumPoints), fiUpdateInterval(UpdateInterval), fiCounter(0), fdSum(0.),
36{
37}
38
43
51void TGo4RollingGraph::Fill(Double_t value, Double_t xerror, Double_t yerror)
52{
53 if (fiNumPoints)
54 {
55 Int_t NumAverage = fiCounter % fiUpdateInterval + 1;
56 // Create a new bin and reset internal value for averaging if counter is a multiple of fiUpdateInterval
57 if (NumAverage == 1)
58 {
59 NextBin();
60 fdSum = 0.;
61 }
62
63 // Add value for averaging
64 fdSum += value;
65 fdSumAveraged = fdSum / static_cast<Double_t>(NumAverage);
66
67 // Draw new averaged value
68 SetPoint(fNpoints-1, static_cast<Double_t>(fiCounter / fiUpdateInterval), fdSumAveraged);
69 if (xerror < 0)
70 xerror = 0.5;
71 if (yerror < 0)
72 yerror = fdSumAveraged / TMath::Sqrt(NumAverage);
73 SetPointError(fNpoints-1, xerror, yerror);
74 }
75 fiCounter++;
76}
77
83{
84 if (fiNumPoints)
85 {
86 if (fiNumPoints <= fNpoints)
87 {
88 // Move points to the left
89 memmove (&fX[0], &fX[1], (fNpoints-1)*sizeof(Double_t));
90 memmove (&fEX[0], &fEX[1], (fNpoints-1)*sizeof(Double_t));
91 memmove (&fY[0], &fY[1], (fNpoints-1)*sizeof(Double_t));
92 memmove (&fEY[0], &fEY[1], (fNpoints-1)*sizeof(Double_t));
93 }
94 else
95 {
96 // Create a new point
97 Set(fNpoints+1);
98 }
99 }
100}
101
107{
108 for (Int_t i = 0; i < fiNumPoints; ++i)
109 RemovePoint(i);
110
111 Set(0);
112 fdSum = 0.;
113}
114
ClassImp(TGo4RollingGraph)
Graphs that renew themselves iteratively to monitor a value.
Int_t fiUpdateInterval
Number of Fill() functions to call before a new average is started.
void Clear(Option_t *option="") override
Clear all points.
Int_t fiNumPoints
Nominal size of the graph, i.e. number of points to display.
Long64_t fiCounter
No. of values filled in total.
virtual void Fill(Double_t value, Double_t xerror=-1, Double_t yerror=-1)
Fills a new value into the rolling graph.
virtual ~TGo4RollingGraph()
Destructor.
Double_t fdSum
Summed total value in the current Bin.
void NextBin()
Create a new bin.
TGo4RollingGraph()
Default constructor.
Double_t fdSumAveraged
Averaged summed total value in the current Bin.