Expanding all X axes on pads

Hi,

I have divided a Canvas into 8 pads and draw histograms on them.
Now I want to expand X axes of ALL pads when I expand any X axis
on any pad using cursor.

Please find the attached file which I use to draw the histograms.

Could you please suggest a solution to this?

Thanks & regards,

Ajay
draw_all.C (2.76 KB)

How to you execute your macro(s) ?

Processing draw_all.C...
Error: Function draw_all() is not defined in current scope  :-1:
*** Interpreter error recovered ***

Hello,

I do it in the following way:

root [0] TFile *f = new TFile(“sort.root”)
root [1] .L draw_all.C
root [2] adc1()
root [3] adc2()

…and so on. Please find the attached “sort.root” file for your reference.

Thanks

Ajay
draw_all.C (2.76 KB)
sort.root (1.32 MB)

Ok I see now. The best is that you make a macro looping on all the histograms plotted.
And you apply the same range on all of them:

h->GetYaxis()->SetRangeUser(x1,x2);

Hi,

Thanks for the suggestion. According to your suggestion, I have to create a macro with
and loop over all drawn spectra. I can do that.

But that is not what I am looking for. How easy or difficult it is to do this with mouse?
i.e. as explained in earlier posts: to expand all the drawn spectra when any one spectra is
expanded using mouse.

Please suggest.

Ajay

You can use signal / slot
here is an example (not finished) … I have some more urgent matters to look at now. I can look at it again later but this daft gives an idea.

TCanvas *c;
Bool_t connected = kFALSE;

void SlotAxisChanged()
{
   Double_t xmin, xmax;
   TPad *pad = dynamic_cast<TPad*>(gTQSender);
   if (pad == 0) return;
   xmin = pad->GetUxmin();
   xmax = pad->GetUxmax();
   cout << "xmin = " << xmin << " xmax = " << xmax << endl;   
   TList *prims=(TList*)pad->GetListOfPrimitives();
   TIter next(prims);
   TH1I *h1;
   Double_t x1,x2;
   while ((obj = next())) {
      if(obj->InheritsFrom(TH1I::Class()) ) {
         h1 = (TH1I*)obj;
         x1 = h1->GetXaxis()->GetXmin();
         x2 = h1->GetXaxis()->GetXmax();
         printf(">>> %g %g\n",x1,x2);
      }
   }

}

void connect()
{
   TQObject::Connect("TPad", "RangeAxisChanged()", 0, 0, "SlotAxisChanged()");
   connected = kTRUE;
}

void adc1()
{
    c = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("c1");
    if (c == 0) c = new TCanvas("c1", "c1");
    c->Clear();
    c->Divide(2,4);

    p[0] = (TPad *)c->cd(1); adc1R_hx00->Draw();
    gPad->SetLogy();
    p[1] = (TPad *)c->cd(2); tdc2_hx12->Draw();
    gPad->SetLogy();
    p[2] = (TPad *)c->cd(3); adc1R_hx01->Draw();
    gPad->SetLogy();
    p[3] = (TPad *)c->cd(4); tdc2_hx13->Draw();
    gPad->SetLogy();
    p[4] = (TPad *)c->cd(5); adc1R_hx02->Draw();
    gPad->SetLogy();
    p[5] = (TPad *)c->cd(6); tdc2_hx14->Draw();
    gPad->SetLogy();
    p[6] = (TPad *)c->cd(7); adc1R_hx03->Draw();
    gPad->SetLogy();
    p[7] = (TPad *)c->cd(8); tdc2_hx15->Draw();
    gPad->SetLogy();
    c->cd();
    if (!connected) connect();
}

void adc2()
{
    c = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("c1");
    if (c == 0) c = new TCanvas("c1", "c1");
    c->Clear();
    c->Divide(2,4);

    c->cd(1); adc2R_hx00->Draw();
    gPad->SetLogy();
    c->cd(2); tdc1_hx04->Draw();
    gPad->SetLogy();
    c->cd(3); adc2R_hx01->Draw();
    gPad->SetLogy();
    c->cd(4); tdc1_hx05->Draw();
    gPad->SetLogy();
    c->cd(5); adc2R_hx02->Draw();
    gPad->SetLogy();
    c->cd(6); tdc1_hx06->Draw();
    gPad->SetLogy();
    c->cd(7); adc2R_hx03->Draw();
    gPad->SetLogy();
    c->cd(8); tdc1_hx07->Draw();
    gPad->SetLogy();
    c->cd();
    if (!connected) connect();
}

void adc3()
{
    c = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("c1");
    if (c == 0) c = new TCanvas("c1", "c1");
    c->Clear();
    c->Divide(2,4);

    c->cd(1); adc3R_hx00->Draw();
    gPad->SetLogy();
    c->cd(2); tdc1_hx08->Draw();
    gPad->SetLogy();
    c->cd(3); adc3R_hx01->Draw();
    gPad->SetLogy();
    c->cd(4); tdc1_hx09->Draw();
    gPad->SetLogy();
    c->cd(5); adc3R_hx02->Draw();
    gPad->SetLogy();
    c->cd(6); tdc1_hx10->Draw();
    gPad->SetLogy();
    c->cd(7); adc3R_hx03->Draw();
    gPad->SetLogy();
    c->cd(8); tdc1_hx11->Draw();
    gPad->SetLogy();
    c->cd();
    if (!connected) connect();
}

void adc4()
{
    c = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("c1");
    if (c == 0) c = new TCanvas("c1", "c1");
    c->Clear();
    c->Divide(2,4);

    c->cd(1); adc4R_hx00->Draw();
    gPad->SetLogy();
    c->cd(2); tdc1_hx12->Draw();
    gPad->SetLogy();
    c->cd(3); adc4R_hx01->Draw();
    gPad->SetLogy();
    c->cd(4); tdc1_hx13->Draw();
    gPad->SetLogy();
    c->cd(5); adc4R_hx02->Draw();
    gPad->SetLogy();
    c->cd(6); tdc1_hx14->Draw();
    gPad->SetLogy();
    c->cd(7); adc4R_hx03->Draw();
    gPad->SetLogy();
    c->cd(8); tdc1_hx15->Draw();
    gPad->SetLogy();
    c->cd();
    if (!connected) connect();
}

void adc5()
{
    c = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("c1");
    if (c == 0) c = new TCanvas("c1", "c1");
    c->Clear();
    c->Divide(2,4);

    c->cd(1); adc5R_hx00->Draw();
    gPad->SetLogy();
    c->cd(2); tdc2_hx04->Draw();
    gPad->SetLogy();
    c->cd(3); adc5R_hx01->Draw();
    gPad->SetLogy();
    c->cd(4); tdc2_hx05->Draw();
    gPad->SetLogy();
    c->cd(5); adc5R_hx02->Draw();
    gPad->SetLogy();
    c->cd(6); tdc2_hx06->Draw();
    gPad->SetLogy();
    c->cd(7); adc5R_hx03->Draw();
    gPad->SetLogy();
    c->cd(8); tdc2_hx07->Draw();
    gPad->SetLogy();
    c->cd();
    if (!connected) connect();
}
c->Pop();

Hello,

I appreciate your time and efforts.

I tried to run the macro but it doesn’t work. I used the following sequence:

root [0] TFile *f = new TFile(“sort.root”)
root [1] .L expandX.C //where expandX.C is the name of the macro you have supplied
root [2] adc1()

at this stage root crashes with the following error:

*** glibc detected *** free(): invalid next size (fast): 0x087ba900 ***

Please help.

Ajay

It worked for me. The idea is to use the signal slot mechanism to perform an action when an event occurs. In the macro SlotAxisChanged() you zoom all the other histograms according to the one you changed. As I said I have not investigated deeply but it might be that you may enter an infinite loop as the macro executed on the event RangeAxisChanged(0 will also generate RangeAxisChanged() events… At the end it might be easier to simply zoom using a macro as I first suggested.

Thanks.

Could you please post the version of the macro that worked for you.

In the earlier version of the macro I don’t see anything corresponding to “RangeAxisChanged()”.
Is the “RangeAxisChanged()” globally defined in the root libraries?

Ajay

draw_all_sig.C (4.16 KB)

Thank you very much for the macro.

I tried running it on my Linux machine with 2.6.9-89.35.1.EL kernel with ROOT 5.30/00 exactly the same way you have suggested. This resulted in the error:

root [0] TFile *f = new TFile(“sort.root”)
root [1] .L draw_all_sig.C
root [2] adc1()
*** glibc detected *** free(): invalid next size (fast): 0x0954b888 ***

So, I tried it on different machines and using ROOT 5.28 and 5.26. But that also crashed with the same error.

Am I doing something wrong?

Ajay

No you did nothing wrong.
We will check on linux.

adc1 is wrong. We forgot to remove the p[…] = …
adc2 is ok.
transform adc1 like adc2
Sorry for that

That is alright!

Now the macro doesn’t crash. However, it still doesn’t give the effect that I am looking for.
I remember that you said it is yet to be completed. When you get some time, could you please
complete it? I am not very much familiar with all the features of the ROOT. Therefore, I am not able to take it further.

Meanwhile, could you please suggest me how to proceed? I understand that when we expand X axis using mouse it gives “xmin” and “xmax”. How to use them further to redraw all the histograms with that range?

Regards,

Ajay

I also said that I am not sure if this will work because of the possible endless loop…

So you better macro a script looping on all the pad and the script apply the same zoom on all of them.

.x zoom(x1, x2)