Sure, here is a simple example to replicate the issues:
void MakeRatio(){
TString LegendTitle = "Preliminary";
TH1F *uds_plot_M = new TH1F("uds M", "uds", 50, 0.2,1);
TH1F *Background_M = new TH1F("Backg. Unc.", "Backg. Unc.", 50, 0.2,1);
TH1F *tau_plot_M_weighted = new TH1F("#tau M", "#tau signal", 50, 0.2,1);
TH1F *tauD_plot_M_weighted = new TH1F("#tau M", "#tau non-signal", 50, 0.2,1);
TH1F *data_plot_M = new TH1F("data", "data", 50, 0.2,1);
uds_plot_M->FillRandom("gaus",200);
tau_plot_M_weighted->FillRandom("gaus",2000);
tauD_plot_M_weighted->FillRandom("gaus",500);
data_plot_M->FillRandom("gaus",3000);
for(int bin=0; bin<data_plot_M->GetNbinsX(); bin++){
double content = data_plot_M->GetBinContent(bin);
double newcontent = (0.1)*content;
Background_M->SetBinContent (bin, newcontent);
data_plot_M->SetBinError(bin,0.1*content+sqrt(content));
}
TCanvas *c9 = new TCanvas();
tau_plot_M_weighted->SetFillColor(kBlue);
tauD_plot_M_weighted->SetFillColor(kViolet-10);
uds_plot_M->SetFillColor(kMagenta);
Background_M->SetFillStyle(3144);
tau_plot_M_weighted->SetLineColor(kBlue);
tauD_plot_M_weighted->SetLineColor(kViolet-10);
uds_plot_M->SetLineColor(kMagenta);
Background_M->SetFillColor(kBlack);
Background_M->SetLineColor(kBlack);
c9->cd();
THStack *Mh = new THStack("Mh ","Mh ");
Mh->Add(uds_plot_M);
Mh->Add(tauD_plot_M_weighted);
Mh->Add(tau_plot_M_weighted);
//Mh->Add(Background_M); Option 1 (works but no lower limit)
Mh->Draw("hist");
auto rp9 = new TRatioPlot(Mh, data_plot_M);
rp9->GetXaxis()->SetTitle("m_{h} [GeV]");
rp9->Draw("same");
rp9->GetLowerRefYaxis()->SetTitle("MC/Data");
rp9->GetUpperRefXaxis()->SetTitle("m_{h}");
rp9->GetUpperRefYaxis()->SetTitle("Entries");
gPad->Modified();
gPad->Update();
TPad *p9 = rp9->GetUpperPad();
Background_M->Draw("histsame"); //Option2 (doesnt work) - would need to change bin content to make this work for real obviously!
auto leg9 = p9->BuildLegend(0.1,0.7,0.48,0.9, "","f");
rp9->GetUpperPad();
auto *th3 = new TText(0.9,0.823,"Preliminary");// TODO: This doesnt show up opn top pad
th3->SetTextAlign(31); th3->SetTextSize(0.5);
th3->Draw();
leg9->SetHeader(LegendTitle,"L");
leg9->AddEntry(data_plot_M,"data","pl");
p9->Modified();
p9->Update();
c9->Draw();
}
You can see for the background issue I tried 2 options. Option 1 gives me that upper limit but no way of getting the lower. Option 2 is preferable and would lead to me adding a second for the lower limit, nothing is added to the canvas when Option 2 is used. I also have the added Text option to show how that issue is occurring.