TCanvas and GetEvent Problems


I’m new here and I have a (hopefully) little Problem with ROOT. Since I’m not an expert in ROOT and programming, please answer so that I can understand :wink:

I have a list of Spectra where I go through with an iterator to draw spectrum per spectrum. I want to go backward and foreward through this list with the courser keys left and right.
In principle this works.
BUT the problem is: after ROOT has drawn a histogram, I have to move the Mouse before ROOT recognizes when I hit the “next”/“previous”-button again.
when I hit buttons that have no effect on my program I can hit it as often as I want and ROOT notices it.
The Problem must be somewhere when/after I plot a new histogram.

I hope somebody knows this “feature” and can help me [-o<



Sorry, but I don’t really understand your problem…
What are the next/previous buttons? How did you make them (are they TGButton, or TButton)?
Is it in a GUI application?
Could you post a piece of code showing what you’re trying to achieve?


okay :slight_smile:

I have this list with the filenames of my spectra written in a vector.

then I take the first one, make a histogram out of the data and then draw it:

then in the Canvas/Pad I look for events:

MyCanvas *cc = (MyCanvas *)gPad;

int    event = gPad->GetEvent();
int    px = gPad->GetEventX();
int    py = gPad->GetEventY();

cc->HandleKey( event, px, py );[/code]

the HandleKey-function looks like that (only important stuff is shown)

if(px==0 && py==4116)
h = show();

else if(px==0 && py==4114)
  h = show();

iter is the iterator through my “list” (vector)

In principle this works.

But as I said above, when I have drawn a histogram, I have to move my mouse before I can hit the “next”-Button (cursor-right) again to show the next spectrum.
But I would like to hit the button to show me the next spectrum without moving my mouse everytime

OK, I undestand now :slight_smile:
I will check and let you know.

Cheers, Bertrand.

have you had time already to find a solution ? :slight_smile:

Hi Katy,

No solution yet, sorry… I’ll keep you in touch.


oh, good to know it’s not too simple :smiley:

I’ll wait :slight_smile:

Hi Katy,

Could you try the macro in attachment, please?
(this could be a simple solution to your problem)
If it doesn’t help, I would need your complete code to reproduce the problem and find another solution…

Cheers, Bertrand.
testevent.C (1.68 KB)

it seems to work :slight_smile:
Thank you very much.

Tomorrow I will try to put it into my skript and see if it will work

You’re welcome :slight_smile:
And please just let me know :wink:

– Bertrand.

It’s working now :smiley:

The principle Problem was:

If I use the Draw() - function to Plot each spectrum I have to move the mouse everytime before it takes any pressed keys.

But if I only Draw() the first spectrum and use the newSpectrum->Copy(*oldspectrum)
it works; it simply overwrites the old spectrum.
So I only have to move the mouse once at the beginning and than the rest works as I wanted it.

Thank you very much for your help :slight_smile:

You’re welcome :slight_smile: Glad to know your problem is fixed :slight_smile:

Cheers, Bertrand