Is there a way of saving a THStack object to a root file? I have exactly the same question as was asked in https://root-forum.cern.ch/t/saving-tstack-to-root-file/56675 , but this time I’m not using a framework belonging to a collaboration.
MWE:
void TRatioPlotStack()
{
gStyle->SetHistLineColor(kBlack);
gStyle->SetMarkerStyle(8);
gStyle->SetMarkerSize(0.7);
TGaxis::SetMaxDigits(3);
gROOT->ForceStyle();
gStyle->SetOptStat(0);
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);
h1->Sumw2();
h1->SetOption("E");
h2->Scale(1. / 2.);
h2->SetFillColor(kRed);
h3->SetFillColor(kBlue);
THStack* st = new THStack("st","");
st->Add(h2);
st->Add(h3);
auto rp = new TRatioPlot(h1, st);
C->SetTicks(0, 1);
rp->Draw();
rp->GetLowYaxis()->SetNdivisions(505);
TFile* fFile = TFile::Open("~/Desktop/test.root","recreate");
// fFile->cd();
rp->Write();
fFile->Close();
}
What I would like is to be able to save an identical object to what’s produced interactively, ie this:
But what I get is this:
Where even clicking on h1/h2 doesn’t show anything

