Doubts on h->Divide() and h->Add()


  1. I wrote a macro to calculate the ratio between data and MC following the ratioplot example.

To be sure that it works fine, I tried to define the ratio dividing an histogram by itself i.e.

TH1F *ratio0 = (TH1F *)hExp0->Clone("ratio");

I expect the ratio is 1 , but I get this plot… (i.e. the ratio is not 1)

Am I missing something?

detratio.c (4.7 KB)

  1. Similarly I wrote a macro to plot the difference between the histograms I wrote a second macro and to test it I tried to subtract a histogram by itself i.e.
TH1F *diff0 = (TH1F *)hExp0->Clone("diff0");
diff0->Add(hExp0, -1.);

I expected the difference is 0, but I get

detdiff.c (4.7 KB)


You must not call “Sumw2(kFALSE)” for both scalled histograms.

Hi @Wile_E_Coyote , if I don’t call


I still get a ratio that isn’t 1, and I also get a bad upper plot. Indeed, 2 days ago, you said me to use “Sumw2(kFALSE) ” to preserve the quality of plots

This plot is fine (the “green band” are the errors of the “ratio”).
You may try to add:
hSim0->SetOption("HIST"); hExp0->SetOption("HIST"); c01->Modified(); c01->Update();

Ah ok @Wile_E_Coyote , if the green are the errors the ratio is fine!

hSim0->SetOption("HIST"); hExp0->SetOption("HIST"); c01->Modified(); c01->Update();

improved the quality just of the MC plot

detratio.c (4.8 KB)

Instead of “hExp0->Draw("SAME");”, you need “hExp0->Draw("HIST SAME");”.

Thank you @Wile_E_Coyote
now I applied it to the real macro (i.e. the data/MC ratio) and I get this plot

it looks like to me that it isn’t dividing the data plot by the MC one, but in the ratio pad it is plotting just the data plot…

maybe is not really dividing when I use 2 different histos?

detratio.c (4.8 KB)

If they have different x-axis binnings, then it will not work.

Thank you @Wile_E_Coyote , it solved !

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