Auto refreshing histograms

I’m working on a simple ROOT gui with an embedded canvas. I want the histogram which is on the canvas to refresh itself every 3 seconds or so. What’s the best way to do this?

Our current application uses an infinite loop and ROOT’s sleep functionality. It works but is a little sluggish.

Use a Timer (see class TTimer) and an example in tutorial anim.C


another, but very similar solution:

TTimer *timer = new TTimer(100);
timer->Connect(“Timeout()”, “TCanvas”, my_canvas, “Update()” );

See also ROOT games from $ROOTSYS/test:
Tetris, Aclock, Hello

Do these methods start a new thread for the update?

No, it doesn’t start any new thread. It appends an event to the event queue to be processed with the next event loop.


I’m trying to refresh an histogram each 10 seconds (I take one sample each second, that here is ramdomly generated). After 400 samples (more or less) the histogram(s) lose(s) its inherited properties (TMarkerSize, TMarkerColor, etc).

Appart from that, I’ts working fine.
I tried, of course, moving the histo
“marker” settings to different places :open_mouth:

I think that it’s a bug, isn’t ?

Here you have a minimum sample code that reproduces the problem.
bugtest.tar (20 KB)

When using TH1::SetBinContent(bin,value) and you have set the automatic rebinning option, the number of bins is automatically icreased to be >=bin.
In your case, you start with 10 bins, then get 20, 40,20,160,320,640,1280,etc.
When displaying the histogram, the paint routine detects if you have more bins than the actual resolution of your display. If it is the case, it switches automatically to the so-called “low-resolution” mode and the original attributes may not be taken into account.
You can force the painting in high resolution mode by using the option “9”


Thak you very much!

It was written there in the THistPainter class :blush:
But I’ve never changed the resolution.