GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
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 
24  : TGraphErrors(), fiNumPoints(0), fiUpdateInterval(1), fiCounter(0), fdSum(0.), fdSumAveraged(0.)
25 {
26 }
27 
33 TGo4RollingGraph::TGo4RollingGraph(Int_t NumPoints, Int_t UpdateInterval)
34  : TGraphErrors(), fiNumPoints(NumPoints), fiUpdateInterval(UpdateInterval), fiCounter(0), fdSum(0.),
35  fdSumAveraged(0.)
36 {
37 }
38 
41 {
42 }
43 
49 void TGo4RollingGraph::Fill(Double_t value, Double_t xerror, Double_t yerror)
50 {
51  if (fiNumPoints)
52  {
53  Int_t NumAverage = fiCounter % fiUpdateInterval + 1;
54  // Create a new bin and reset internal value for averaging if counter is a multiple of fiUpdateInterval
55  if (NumAverage == 1)
56  {
57  NextBin();
58  fdSum = 0.;
59  }
60 
61  // Add value for averaging
62  fdSum += value;
63  fdSumAveraged = fdSum / static_cast<Double_t>(NumAverage);
64 
65  // Draw new averaged value
66  SetPoint(fNpoints-1, static_cast<Double_t>(fiCounter / fiUpdateInterval), fdSumAveraged);
67  if (xerror < 0)
68  xerror = 0.5;
69  if (yerror < 0)
70  yerror = fdSumAveraged / TMath::Sqrt(NumAverage);
71  SetPointError(fNpoints-1, xerror, yerror);
72  }
73  fiCounter++;
74 }
75 
81 {
82  if (fiNumPoints)
83  {
84  if (fiNumPoints <= fNpoints)
85  {
86  // Move points to the left
87  memmove (&fX[0], &fX[1], (fNpoints-1)*sizeof(Double_t));
88  memmove (&fEX[0], &fEX[1], (fNpoints-1)*sizeof(Double_t));
89  memmove (&fY[0], &fY[1], (fNpoints-1)*sizeof(Double_t));
90  memmove (&fEY[0], &fEY[1], (fNpoints-1)*sizeof(Double_t));
91  }
92  else
93  {
94  // Create a new point
95  Set(fNpoints+1);
96  }
97  }
98 }
99 
104 void TGo4RollingGraph::Clear(Option_t *)
105 {
106  for (Int_t i = 0; i < fiNumPoints; ++i)
107  RemovePoint(i);
108 
109  Set(0);
110  fdSum = 0.;
111 }
112 
Int_t fiNumPoints
Nominal size of the graph, i.e. number of points to display.
void Clear(Option_t *option="") override
Clear all points.
Graphs that renew themselves iteratively to monitor a value.
virtual void Fill(Double_t value, Double_t xerror=-1, Double_t yerror=-1)
Fills a new value into the rolling graph.
Int_t fiUpdateInterval
Number of Fill() functions to call before a new average is started.
void NextBin()
Create a new bin.
Long64_t fiCounter
No. of values filled in total.
virtual ~TGo4RollingGraph()
Destructor.
Double_t fdSum
Summed total value in the current Bin.
TGo4RollingGraph()
Default constructor.
Double_t fdSumAveraged
Averaged summed total value in the current Bin.
ClassImp(TGo4RollingGraph)