Connect ("Navigation Button")

Dear all,
I am trying to create a graphical interface that allows me to visualise a TTrre event by event by clicking on navigation buttons
In other words my routine opens a TTree and, for the first entry (or a differnt one, passed with a variable fNEvent) it fills an plot two histograms. The I would like to be able to click on a navigation button and, when clicking “<–” , to visualize 2 histograms for the previou event.
I implemented

fButPrev->Connect(“Clicked()”, “TCustomizedBrowser”, fMain, “PrevAction()”);

and would like to pass to PrevAction the variable fNEvent, so that I can modify its value and plot the previous event, but I found no way to do so.
The only way I found is
fButPrev->Connect(“Clicked()”, “TCustomizedBrowser”, fMain, “PrevAction(=9)”);
or
fButPrev->Connect(“Clicked()”, “TCustomizedBrowser”, fMain, “PrevAction(=8)”);

but these are particular values and I’d need to pass a variable instead.
Could anyone give a look, please?

Thx,
Francesca

P.S.
Structure of the directories containing the routines.
In a directory HERE there are the files EventSignals.C and Makefile
In HERE/incl is the TCustomizeBrowser.h
In HERE/src is the TCustomizeBrowser.cxx
In HERE/bin the executable will be put
You need also a dir HERE/dict and a dir HERE/obj
TCustomizedBrowser.cxx (12.5 KB)
TCustomizedBrowser.h (5.67 KB)
Makefile.C (5.91 KB)
Event_Signals.C (1.2 KB)
fout.root (147 KB)

Hi,

I don’t understand your problem. Since fNEvent and fCurrentEvent are members of the same class (TCustomizedBrowser), you don’t need to pass any argument…
And since TCustomizedBrowser inherits from TGMainFrame, why do you use fMain? You’re over-complicating your code…

Cheers, Bertrand.

Hi.
Thank you for your reply.

The reason why I want to pass NEvent as a variable to PrevAction()
is that If I ask in PrevAction() to print the value of fNEvent, it gives a huge number, that does not
correspond to the real value at which fNEvent was initialized ( fNEvent = 10; in TCustomizedBrowser::TCustomizedBrowser(TString fname):filename(fname))

As for the second thing you pointed out (And since TCustomizedBrowser inherits from TGMainFrame, why do you use fMain? You’re over-complicating your code…), it’s the first time I “play” with classes :blush:
That’s the only way I succeeded to make a window for thegraphical interface to pop up…

Thank you,
Francesca

Hi Francesca,

OK, then please take a look at the modified TCustomizedBrowser.cxx (12.5 KB)
And note there are several issues with your code, and you will probably have to spend some time on it, I’m afraid…

Cheers, Bertrand.

I’ve just found out that the problem was that fNEvent=10 was appearing in the code after the button definition.
By inverting the order, its value is known by the Buttons definition and therefore by the functions called when
clicking the buttons.

Thx!
Francesca

P.S.
Any suggestion on how improving the code is welcome.

Dear Bertrand,
thank you a lot for your help!

Cheers,
Francesca

Hi Francesca,

You’re welcome! And I’ll check your code when I find some time…

Cheers, Bertrand.

Hi Francesca,

Here are a couple of changes to make in your code. Since you cannot save the GUI in a ROOT file, you should use 0 as class version in the ClassDef macro (in TCustomizeBrowser.h):

ClassDef(TCustomizedBrowser,0); ///< TCustomizeBrowser dictionary (to avoid error messages)
Then, use the correct syntax to open the file, and get the correct tree name:

void TCustomizedBrowser::LoadFile(TString fname) { //printf("Loading file %s\n",Form("%s",fname.Data())); printf("\033[40m\033[0;31m Loading file %s \033[0m \n",Form("%s",fname.Data())); fXY = TFile::Open(fname.Data(),"read"); treeXY = (TTree*)fXY->Get("tout"); } This should already help!

Cheers, Bertrand.

Hi.
Thank you a lot!
And…the problem of the fNEvent was not the order in the code, as I had said.
With your code,independently of the position of fNEvent,
wherever I put cout << fNEvent<<endl, its correct value is printed. Therefore th eproblem was one of the mistakes in my code.

Thanks!