Find Maximum of THn?

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

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

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

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

Any help would be appreciated!

Maybe @moneta or @Axel can help

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:

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