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:
Once “entry” will get above 100 the number of bins in the histogram will be doubled as stated here
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?
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?
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);
}