TRatioPlot TH1/THStack instead of THStack/TH1 in ratio plot

Dear ROOT developers,

In Dec 2017, this(TRatioPlot h1/h2 instead of h2/h1) was raised but I found no solution.
When one uses TRatioPlot with THStack the ratio plot only shows the THStack/TH1 value which in my case means MC/data. Is it possible to reciprocate this ratio in order to get data/MC instead?

Best regards,
Federico Diaz Capriles


ROOT Version: 6.10.04-x86_64-slc6-gcc62-opt


Do you have a small macro showing what we are talking about ?

Yeah, sorry. Here is what I am trying to do:
h_stack is MC added together as a THStack and h_data are the data points as a TH1F. These are projected from trees in root files.

TRatioPlot *rp = new TRatioPlot(h_stack, h_data, "pois");
rp->Draw();

Though this can be shown easily with the example given in the reference:

void ratioplot1() {
   gStyle->SetOptStat(0);
   auto c1 = new TCanvas("c1", "A ratio example");
   auto h1 = new TH1D("h1", "h1", 50, 0, 10);
   auto h2 = new TH1D("h2", "h2", 50, 0, 10);
   auto f1 = new TF1("f1", "exp(- x/[0] )");
   f1->SetParameter(0, 3);
   h1->FillRandom("f1", 1900);
   h2->FillRandom("f1", 2000);
   h1->Sumw2();
   h2->Scale(1.9 / 2.);
   h1->GetXaxis()->SetTitle("x");
   h1->GetYaxis()->SetTitle("y");
   auto rp = new TRatioPlot(h1, h2);
   c1->SetTicks(0, 1);
   rp->Draw();
   c1->Update();
}

When one draws the TRatioPlot, it will have the ratio of h1/h2 on the bottom pad. Now, if one wants to have h2/h1 instead, one can just do auto rp = new TRatioPlot(h2, h1); instead of what is shown above. However, TRatioPlot only accepts THStack as the first argument and can only show a THStack/TH1 ratio. I would like to have the ability to have a TH1/THStack ratio instead.

I see now. In fact the TRatioPlot constructor using THStack converts the stack to a regular sum of its containing histograms. So, as an easy workaround, you can do the same before constructing the TRatioplot and use the normal constructor using two TH1.

Alright. Thanks, I’ll do that.

Note that the constructor you are requesting makes sense.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.