# Find Maximum of THn?

**URL:** <https://root-forum.cern.ch/t/find-maximum-of-thn/53797>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [February 27, 2023, 9:54am UTC](https://root-forum.cern.ch/t/find-maximum-of-thn/53797 "2023-02-27T09:54:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lost0431](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/9fc29f/32.png) [@lost0431](https://root-forum.cern.ch/u/lost0431)\
**Post date:** [February 27, 2023, 9:54am UTC](https://root-forum.cern.ch/t/find-maximum-of-thn/53797/1 "2023-02-27T09:54:50Z")

</div>

I am creating a four dimensional histogram, using THn. Now I want to normalize it. Previously, for lower dimensions, I used

```auto
hist -> Scale(1./hist -> GetMaximum());

```

but this does not work for THn. I get the error

```auto
error: no member named 'GetMaximum' in 'THn'

```

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [February 27, 2023, 9:58am UTC](https://root-forum.cern.ch/t/find-maximum-of-thn/53797/2 "2023-02-27T09:58:36Z")

</div>

Maybe @moneta or @Axel can help

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [February 28, 2023, 5:48pm UTC](https://root-forum.cern.ch/t/find-maximum-of-thn/53797/3 "2023-02-28T17:48:16Z")

</div>

Hi,

There is no such function in THn, but you can easily compute it, looping at the bins. Here is an example code, assuming the histogram is of double content type:

```auto
int n = hist->GetNbins();
auto & array = static_cast<TNDArrayT<double>&>(hist->GetArray())
std::vector<double> x(n);
std::generate(x.begin(), x.end(), [ibin=0]() mutable{ ibin++; return array.At(ibin);});
double maxValue = *(std::max_element(x.begin(),x.end());

```

Cheers

Lorenzo
