Select data with mouse in TH2

Hello,

I am currently working on a qtroot program, and I would like to add feature allowing the user to select data in a TH2 object with his mouse, maybe something quite rudimentary, like drawing two diagonal lines and keeping the data between the two. I have been searching for methods to do that in the TPad and TCanvas class without finding anything interesting, so if someone would have a tutorial or an example of how to capture mouse event with root I will be very thankful.

Best.

Hi,

You could take a look at the $ROOTSYS/tutorials/hist/DynamicSlice.C macro…

Cheers, Bertrand.

Thanks bellenot, it was inspiring.

I now have two questions:
-to use a AddExec in my qtroot (associated with the tqtwidget canvas) I had to put the function called in a .c file, is it possible to keep that function in my main code?
-I didn’t found how to ‘listen’ to mouse clicks, only to follow the mouse movement, like in the example, is there a TPad method listening to those events?

Best,
1989.

[quote]I didn’t found how to ‘listen’ to mouse clicks, only to follow the mouse movement, like in the example, is there a TPad method listening to those events?[/quote] Yes, you can connect to the TCanvas:ProcessedEvent(Int_t,Int_t,Int_t,TObject*) signal. See for example the $ROOTSYS/tutorials/gui/exec3.C macro…

Cheers, Bertrand.

Hi,

thanks bellenot, but I still didn’t manage to add my function called by AddExec in my qt program, I tried to paste the function in the main cpp file, without success, not that surprising. I read the link you pasted, but without learning anything.

Otherwise, I think I know how to realize the feature with a TCutG object, the only thing I missed is to write to code that says that when the CutG has finished beeing drawned by the mouse (closed, ie the last point equals the first one) redraws the TH2 with the cut, I was thinking about checking if the coordinates of the last click are the same as the one of the first click, but I haven’t found a way to access the coordinates of a point in a TCutG object. It must be possible, so if someone knows…

edit: a method verifying if the polygon is closed would work too

Hi,
I managed to solve some part of my problems, but I am now stuck with new ones :confused:

-How can I retrieve a pointer to a tree that has been drawn in a TCanvas, gROOT->GetListOfSpecials()->FindObject and gPad->GetPrimitive don’t work for me.

-Is it possible to fill a TH2 with a TTree with 2 branches taking account on a TCutG? I know how to draw it with the TCutG but no more for the moment.

-I still didn’t manage to add my code (the AddExec function) inside the QtRoot project, does someone have an example of it working? It would be really thankful.

Best, 1989.

edit: for my second question, when I plot the TTree with the TCutG, a TH2F object with pointer is created, but it is empty, the GetEntries method returns 0 and if I save it to a file and open it in a new session, the TH2F is empty :confused:

edit2: I solved it using a mytree->Draw(“x:y>>hist2”,“mycut”,“hist2”)

[quote]-How can I retrieve a pointer to a tree that has been drawn in a TCanvas, gROOT->GetListOfSpecials()->FindObject and gPad->GetPrimitive don’t work for me.[/quote]What do you mean? There is no ‘trace of’/‘link to’ the original TTree in any of the objects that are part of the Canvas.

[quote]-I still didn’t manage to add my code (the AddExec function) inside the QtRoot project, does someone have an example of it working? It would be really thankful.[/quote]I recommend opening a separate thread for this question.

Cheers,
Philippe.