Ratio plot

Hello

Iam rather new to ROOT so bare with me…
While drawing multiple histograms in one canvas I would like to also create a ratio plot just below the original histograms, is there any good way to accomplish this?

Thanks
Tomas

1 Like

see this example

Rene

void ratio() {
   TH1F *h1 = new TH1F("h1","test1",100,-3,3);
   h1->FillRandom("gaus",200000);
   h1->GetXaxis()->SetLabelFont(63); //font in pixels
   h1->GetXaxis()->SetLabelSize(16); //in pixels
   h1->GetYaxis()->SetLabelFont(63); //font in pixels
   h1->GetYaxis()->SetLabelSize(16); //in pixels
   TH1F *h2 = new TH1F("h2","test2",100,-3,3);
   h2->FillRandom("gaus",100000);
   TCanvas *c1 = new TCanvas("c1","example",600,700);
   TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1);
   pad1->SetBottomMargin(0);
   pad1->Draw();
   pad1->cd();
   h1->DrawCopy();
   h2->Draw("same");
   c1->cd();
   TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);
   pad2->SetTopMargin(0);
   pad2->Draw();
   pad2->cd();
   h1->Sumw2();
   h1->SetStats(0);
   h1->Divide(h2);
   h1->SetMarkerStyle(21);
   h1->Draw("ep");
   c1->cd();
}

Hi!

Is it possible to avoid that the 0 of the upper y axis gets truncated?

Thanks,

Sebastian

one possible way:

void ratio() {
   TH1F *h1 = new TH1F("h1","test1",100,-3,3);
   h1->FillRandom("gaus",200000);
   h1->GetXaxis()->SetLabelFont(63); //font in pixels
   h1->GetXaxis()->SetLabelSize(16); //in pixels
   h1->GetYaxis()->SetLabelFont(63); //font in pixels
   h1->GetYaxis()->SetLabelSize(16); //in pixels
   TH1F *h2 = new TH1F("h2","test2",100,-3,3);
   h2->FillRandom("gaus",100000);
   TCanvas *c1 = new TCanvas("c1","example",600,700);
   TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1);
   pad1->SetBottomMargin(0);
   pad1->Draw();
   pad1->cd();

   TH1F *h3=h1->DrawCopy();
   h3->SetMinimum(-100);
   h2->Draw("same");
   c1->cd();
   TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);
   pad2->SetTopMargin(0);
   pad2->Draw();
   pad2->cd();
   h1->Sumw2();
   h1->SetStats(0);
   h1->Divide(h2);
   h1->SetMarkerStyle(21);
   h1->Draw("ep");
   c1->cd();
}

Hi,

I have a similar problem, my upper number get truncated, but in the ratio (down) plot.
Is there a way to get the complete number in the bottom plot?

Thank you!

[url]SetAxisRange(0.0,1.0,"Y"); is ineffective
[url]Palette on a TProfile2d
[url]SetRangeUser doesn't work well

Thank you… but my problem is not setting the axis limits, but the upper number of the axis is truncated.

I assume that the problem is in the “vertical” direction (i.e. the upper part of the number is not visible). In this case, if you change the axis maximum (or your histogram maximum), the number which is truncated will also be moved in the picture (so it will either entirely disappear or it will become entirely visible).
Unless the problem is in the “horizontal” direction (e.g. that the left part of the number is not drawn).

Great! :slight_smile: Thank you!