Last 100 Entries in Histogram with timeDisplay

Hello Rooters,

I have two questions concerning the time mode of an histogram. In a Histogram I want to show the last 100 entries
of a value. The following code shows what I want to archive:

void timetest()
{
	TTimer * tim = new TTimer();
	TH1D* h = new TH1D("TimeTest","Time Test Histo", 100,0,100);
	h->SetOption("p0c");
	TDatime d;
	gStyle->SetTimeOffset(d.Convert());
	h->GetXaxis()->SetTimeDisplay(1);
	h->GetXaxis()->SetTimeFormat("%H:%M:%S");
	h->GetXaxis()->SetLabelSize(0.03);

	tim->SetCommand("fillHisto()");
	tim->Start(500);
}
void fillHisto()
{
	static int entry;
	double someValue = gRandom->Gaus(0,120);

	TimeTest->SetBinContent(entry,someValue);
	entry++;
}

Now my questions are:

  1. Once “entry” will get above 100 the number of bins in the histogram will be doubled as stated here

root.cern.ch/root/html/TH1D.html … BinContent

This is not what I want. I want that only the last 100 entries will be displayed, when the entry will be > 100
the first entry will be thrown away. How do I do that?

  1. As one can see, the entry that will be inserted is not inserted at the time that is displayed on the axis.
    I guess it is off by the factor of 2. What do I have to do in order to synchronize the entries with the real time?

Thank you,
Lutz

Here is an example. When the bin entry is > 100, the 50 last bins are shifted on left and the and the filling starts again at bin 50. Also the time offset is changed.

void timetest()
{
   TTimer * tim = new TTimer();
   TH1D* h = new TH1D("TimeTest","Time Test Histo", 100,0,100);
   h->SetOption("p0c");
   TDatime d;
   gStyle->SetTimeOffset(d.Convert());
   h->GetXaxis()->SetTimeDisplay(1);
   h->GetXaxis()->SetTimeFormat("%H:%M:%S");
   h->GetXaxis()->SetLabelSize(0.03);
   tim->SetCommand("fillHisto()");
   tim->Start(500);
}
                                                                                
void fillHisto()
{
   static int entry = 0;
   double someValue = gRandom->Gaus(0,120);
   double v;
   entry++;
   if (entry>100) {
      for (int i=1; i<=49; i++) {
         v = TimeTest->GetBinContent(i+49);
         TimeTest->SetBinContent(i,v);
      }
      entry = 50;
      TDatime d;
      TimeTest->GetXaxis()->SetTimeOffset(d.Convert());
   }
   TimeTest->SetBinContent(entry,someValue);
}

Olivier,

To get the macro working correctly, I modified it as follows;

[code]void timetest()
{
TTimer * tim = new TTimer();
TH1D* h = new TH1D(“TimeTest”,“Time Test Histo”, 100,0,100);
TDatime d;
gStyle->SetTimeOffset(d.Convert());
h->GetXaxis()->SetTimeDisplay(1);
h->GetXaxis()->SetTimeFormat("%H:%M:%S");
h->GetXaxis()->SetLabelSize(0.03);
h->SetMarkerStyle(21);
h->Draw(“pl”);
tim->SetCommand(“fillHisto()”);
tim->Start(100);
}

void fillHisto()
{
static int entry = 0;
double someValue = gRandom->Gaus(0,120);
double v;
entry++;
if (entry>100) {
for (int i=1; i<=50; i++) {
v = TimeTest->GetBinContent(i+50);
TimeTest->SetBinContent(i,v);
TimeTest->SetBinContent(i+50,0);
}
entry = 50;
TDatime d;
TimeTest->GetXaxis()->SetTimeOffset(d.Convert());
}
TimeTest->SetBinContent(entry,someValue);
gPad->Modified();
gPad->Update();
}

[/code]Rene

Yes, i agree. In fact I was plotting the result from outside the macro (the histogram being filled in the background).