Scaling histograms


Suppose that you have two TH1F histograms, h1 with N1 bins and range x1min to x1max, and h2 with N2 bins and range x2min to x2max.

How would you scale the two histograms so that their integral over the range xmin = Max(x1min, x2min), xmax = Min(x1max,x2max) becomes identical? (In other words, if you superpose them in a figure and they depict the same spectrum over the range xmin and xmax, the match dispays correctly).

Could you do this using “Scale” only, or you need to manually account for the different numbers of bins?

How would you normalize a function (say a PDF) to a histogram h1 for correct display if you superpose the two?


Scale the second histogram (via TH1::Scale) with the ratio of the 2 integrals.
If the bin widths are different, multiply the ratio of the integrals by the ratio
of the bin widths, such that one single call to Scale will do the job.