How to use TExec (use-case #2)?

Hello,

Documentation for TExec is mentioning 3 use-cases. ROOT: TExec Class Reference

I want to use the second case to modify some histogram features (e.g. title, etc…) using a macro.C. I know gPad is known, but is it always pointing to the pad containing the histogram ?
The documentation doesn’t provide example how to get back the corresponding histogram.

From documentation, I believe when TH1 is drawn in a TBrowser, the macro is also called.
Is that correct ?

Case 2:

The TExec object may be added to the list of functions of a TH1 or TGraph object via hist->GetListOfFunctions()->Add("",""). When the histogram (or graph) is drawn, the TExec will be executed. If the histogram is made persistent on a file, the TExec object is also saved with the histogram. When redrawing the histogram in a new session, the TExec will be executed.

Example:

Assume an histogram TH1F *h already filled.

TExec *ex1 = new TExec("ex1","DoSomething()");
TExec *ex2 = new TExec("ex2",".x macro.C");
h->GetListOfFunctions()->Add(ex1);
h->GetListOfFunctions()->Add(ex2);
h->Draw();
When the Paint function for the histogram will be called, the "DoSomething" function will be called (interpreted or compiled) and also the macro.C.

Thank you very much.
M.

Dear @meyerma ,

Thanks for reaching out to the forum! Maybe @couet can help you here.
Cheers,
Vincenzo

It depends on how your macro is written, but yes, if you create a histogram, it should appear in the list of gPad primitives. Is it not working for you? Do you have a small example to reproduce the issue?

1 Like

Thank you, as usual @couet, I understand now I should use gPad.
Sorry it didn’t came up to my mind. I just tested I can retrieve the histogram from gPad primitives.
It looks good to me :slight_smile:

1 Like