TRatioPlot* rp = new TRatioPlot(hData,hStack);
rp->Draw();
rp->GetUpperPad()->cd();
((THStack*)rp->GetUpperRefObject())->GetXaxis()->SetTitle(hData->GetXaxis()->GetTitle());
((THStack*)rp->GetUpperRefObject())->GetYaxis()->SetTitle(hData->GetYaxis()->GetTitle());
worked fine in root 6.36 but fails at runtime in root 6.38, giving a bus error when I try to do GetXaxis(). Can anyone tell me the correct way to set axis titles of a ratio plot in 6.38?
@Danilo Looks like an incompatible change in ROOT.
The GetUpperRefObject (correctly) returns hData in ROOT 6.38 and (incorrectly) hStack in ROOT 6.36 (and ROOT 6.34).
@bethlong06 Try with (it should work with any ROOT version): TRatioPlot *rp = new TRatioPlot(hStack, hData);
I made a complete example. With master (3.39) it fails. I will try with 6.36.
void TRatioPlotStack()
{
auto C = new TCanvas("C", "A ratio example");
auto h1 = new TH1D("h1", "TRatioPlot Example; x; y", 50, 0, 10);
auto h2 = new TH1D("h2", "h2", 50, 0, 10);
auto h3 = new TH1D("h3", "h3", 50, 0, 10);
auto f1 = new TF1("f1", "exp(- x/[0] )");
f1->SetParameter(0, 3);
for(int ii=0; ii<h1->GetXaxis()->GetNbins(); ii++) h1->SetBinContent(ii+1,150);
h2->FillRandom("f1", 2000);
h3->FillRandom("f1", 2000);
THStack* st = new THStack("st","");
st->Add(h2);
st->Add(h3);
auto rp = new TRatioPlot(h1, st); // Fail
// auto rp = new TRatioPlot(st, h1); // Work
rp->Draw();
rp->GetUpperPad()->cd();
((THStack*)rp->GetUpperRefObject())->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());
}
From what I understand, for the “TRatioPlot(first, second)”, the “GetUpperRefObject” should always return the “first” (and NOT the “second”, regardless of the types of the “first” and “second”).