# How to get the maximum of the normalized histogram?

Dear ROOTers!

I am trying to get the maximum of the histogram after normalization:

h1->SetNormFactor(1);
max = h1->GetMaximum();

The problem is that the returned maximum is for the histogram before normalization. Could you please give me a hint how I can get the maximum of the normalized histogram?

Thanks,

Kirill

Hmmm… I’d say it was a bug…

``` root [0] TH1F bob ("bob", "bob", 10, 0.5, 10.5) root [1] bob.Fill(4,4) (Int_t)(4) root [2] bob.Draw() <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 root [3] bob.SetNormFactor(1) root [4] bob.Draw() root [5] bob.GetMaximum() (const Double_t)4.00000000000000000e+00 root [6] TH1F bob ("bob", "bob", 10, 0.5, 10.5) Warning in <TROOT::Append>: Replacing existing TH1: bob (Potential memory leak). root [7] bob.Fill(4,4) (Int_t)(4) root [8] bob.Scale( 1./bob.Integral() ) root [9] bob.GetMaximum() (const Double_t)1.00000000000000000e+00 root [10] bob.Draw() ```

The first time I drew the histogram, it showed a maximum of 4 (what you’d expect). I used SetNormFactor(1) and it showed a maximum of 1, but GetMaximum() returned 4. If I Scaled it “by hand”, it worked as expected.

So, for now, try using Scale and Integral (although be careful if you have overflow bins…)

Cheers,
Charles

TH1::SetNormFactor does not change the bin contents. It stores only a normalization parameter used by Draw/Paint to paint the contents normalized.
If you want to modify the bin contents use TH1::Scale instead.

Rene

Dear Charles, Rene,

Thank you very much for the info!

Kirill