Dividing two 1D histograms

Hi all,

I have been trying to divide, in a for loop, two 1D histograms in the following way:
these are the 1D histograms filled in the for loop:

   TH1D *H1[const_size];
   TH1D *H2[const_size];
   TH1D *ratio[const_size];

Inside the for loop:

   ratio[i] = (TH1D*)H2[i]->Clone(Form("ratio_%d",i));  
   ratio[i]->SetTitle(Form("ratio_%d", i));
   ratio[i]->Write(Form("ratio_%d", i));

Assuming that this is the right way to proceed (is it?), I do not know why, it keeps on plotting on the Y axis the ratio value times ** 10^{-9}**, which is the Y order of magnitude of both H1 and H2 histograms.
I also picked up two histograms from H1 and H2 to divide them outside the for loop and indeed that 10^{-9} does not show up and the ratio value is correct.
What am I doing wrong in the for loop?

Moreover, what is the difference in doing:



ratio[i]->Divide(H1[i], H2[i])); 


Thanks in advance!

The source code, that you show, seems fine to me.
Neither “Clone” nor “Divide” nor “SetTitle” nor “Write” will draw anything. It seems to me that you see something else drawn (not the “ratio[i]”, if the “magnitudes” are wrong).

See also method descriptions:

Bool_t TH1::Divide(const TH1 *h1)

Bool_t TH1::Divide(const TH1 *h1, const TH1 *h2, Double_t c1 = 1, Double_t c2 = 1, Option_t *option = “”)

Thanks for your reply.
Sorry I do not get what you mean: I wrote in my root file the ratio plot, at least I do get what it seems like a ratio plot (even though I am not sure it is 100% correct…).

Thanks in advance!

Hi @chigi,

Thanks for the previous answer, @Wile_E_Coyote. I will also invite @couet to this thread, as he might be able to provide some additional information.


As @Wile_E_Coyote said your code looks fine. But to help you further we will need something more complete, something we can run.