Hi @couet,
Thank you for your useful example. I also had a look at exec1.C introduced in TPad.
As I am looking for a more versatile solution (I have many canvas to draw), I tried to use TCanvas::AddExec()
to make it canvas specific, but introducing division breaks the code.
In such case, if I modify pad1,2 or 3 I do no see any execution of the TExec
introduced by TCanvas::AddExec()
if I modify a subpad. I believe this should be executed, right?
I believe in this situation that subpads make TExec unusable.
I introduced some Propagator to fix that. Is there any better solution in your opinion ?
As there is this hierarchical structure between pad, would it be acceptable to introduce such propagation natively?
TCanvas *C;
TPad *p1, *p2, *p3;
TH1F *h1, *h2, *h3;
void MotherPadPropagator()
{
if (gPad && gPad->GetMother() != gPad) {
TList *execList = gPad->GetMother()->GetListOfExecs();
if (execList) {
for (int i = 0; i < execList->GetSize(); i++) {
TNamed *exec = (TNamed*)execList->At(i);
exec->Draw();
}
}
}
}
void GlobalZoom()
{
if (!gPad) return;
std::cout << "Selected Pad: " << gPad->GetName() << std::endl;
Int_t event = gPad->GetEvent();
int px = gPad->GetEventX();
int py = gPad->GetEventY();
TObject *select = gPad->GetSelected();
if (select && select->InheritsFrom(TAxis::Class())) {
TAxis *axis = (TAxis*) select;
double first = axis->GetFirst();
double last = axis->GetLast();
std::cout << "Selected Axis: (" << first << "," << last << ")" << std::endl;
}
}
void zoomdiv2() {
TCanvas *C = new TCanvas("C", "C", 500, 900);
C->Divide(1,3,0,0);
h1 = new TH1F("h1", "h1", 100, -5., 5.) ; h1->FillRandom("gaus", 10000);
h2 = new TH1F("h2", "h2", 100, -5., 5.) ; h2->FillRandom("gaus", 10000);
h3 = new TH1F("h3", "h3", 100, -5., 5.) ; h3->FillRandom("gaus", 10000);
p1 = (TPad*)C->cd(1); h1->Draw();
p2 = (TPad*)C->cd(2); h2->Draw();
p3 = (TPad*)C->cd(3); h3->Draw();
C->AddExec("GlobalZoom","GlobalZoom();");
TExec *exec = new TExec("MotherPadPropagator","MotherPadPropagator();");
exec->Draw();
}
Edit: I noticed that this method is not working for Y axis.