Online Histogram Update through Macro

Hi guys,

I’m trying to do a simple online display - a histogram that every second updates with new data arriving.
I did a sample code that reads a tree file that gets update on the go by the daq process (different c++ program)

How do i get the histogram to fill again and redraw? also how do i make my canvas responding while waiting for new data to arrive?

for testing i just want the hist to fill random and redraw itself every second.
i’m running the file with .x OnlineViewer.C

[code]void OnlineViewer()
{
TH1F * OccupancyHist = new TH1F(“Occupancy”,“Occupancy”,200,-5,5);

//Creating the gui canvases 
TCanvas cOccupancy("Occupancy","Occupancy",0,0,1000,700);
cOccupancy.cd();
cOccupancy.Update();
OccupancyHist->FillRandom("gaus");
OccupancyHist->Draw();
cOccupancy.Update();


while ( true )
{
    gSystem->Sleep(1000);
    OccupancyHist->FillRandom("gaus");
    cOccupancy.cd();
    OccupancyHist->Draw();
}

}[/code]

all i’m getting now is a frozen canvas that doesn’t updates at all.
I realize that my problem is fundamental so i would love to get some guidelines & better practices.

Thanks

Hi,

You could use a separate thread if you need to do some other tasks in your application, but simply adding gSystem->ProcessEvents() in the loop is enough to make it working. See for example your code, modified:

while (true) { gSystem->Sleep(100); OccupancyHist->Reset(); OccupancyHist->FillRandom("gaus"); cOccupancy.Modified(); cOccupancy.Update(); if (gSystem->ProcessEvents()) break; }
gSystem->ProcessEvents() is required to let the system handle the application events. To interrupt the loop, simply select “Interrupt” fro the "Options " entry of the Canvas menu. And BTW, TH1::Draw() should only be called once, and then simply use TPad/TCanvas::Modified()/Update(), as shown in the code above.

Cheers, Bertrand.

To complete a bit this thread. I think the following page can help to understand how it works.
root.cern.ch/drupal/content/graphics-pad

To complete a bit the “2D Graphics -> The Graphics Pad” page, I think the following can help.
In may places in the ROOT documentation one finds that doing “gPad->Update();” is sufficient to “repaint” the pad. I do remember cases, however, when I modified some already painted object and “gPad->Update();” did NOT “refresh” it. That’s why I always advertise the sequence “gPad->Modified(); gPad->Update();” as it never failed to “repaint” everything (well, at least up to now), even though “gPad->Modified();” may not be necessary in many cases.

You are right. I have modified the page accordingly.