How to update histogram statistics?

I have an array of values and want to fill it in a histogram. When I do it like this:

for (int i=0;i<size;i++){
	hist->SetBinContent(i+1,array[i]);
}

everything is fine. However, I thought it would be nice to write it more compact like this:

std::copy(array,array+size,hist->fArray+1);

This also worked fine, unless I try to get the mean value via hist->GetMean();. The reason is that when I directly write to the data of the histogram, the statistics arent updated. Recently I was looking at the implementation of other methods (e.g. getMinimum()) and realized, that anyhow these methods do not use precomputed results, but only when calling them the result is determined (e.g. by looping over all entries and determining the minimum). Thus I was a bit surprised, that this is not the case for GetMean().

How can I update the statistics of the histogram after filling it (via accesing fArray directly) ?

Hi,

You need to call TH1::ResetStats() to force the re-computation of the statistics.

Lorenzo