TMath Documentation

Hi, I was not sure where to post but actually I would like to state that I find the Root documentation in general very poor. In my specific case, I am not getting any conclusion out of the documentation regarding how to use the TMath::Mean function. So even if not the correct chat (since I can not post in the Math tools thread), would it be possible to have a minimum example how to use this function please? Many thanks

Hi, the documentation of the Mean method is avalaible here. What is unclear for you?

Hi! To me it is not clear how to define the iterator. Plus, I realized in the meantime that you can also use an “old-style” version where you can add the number of values to be considered and then you enter the array variable, e.g.

Int_t x[5]={1,2,3,4,5};
the output is 3 (and hence correct). But when defining a second array w of the same size as x with weights in order to calculate the weighted mean, I am getting an error doing this
In theory according to a root documentation (not provided on your side but somewhere else) this “old-style” syntax should work but it does not.

In any case I would like to get familiar with the syntax using iterators. What exactly are the steps to define these iterators? I am repeating myself that just writing the blank syntax with indicating what kind of variables to use instead of showing a concrete example is sometimes unclear, at least to me.


So, concerning the “old-style”, it works here if I do

double x[5]={1,2,3,4,5} root [1] TMath::Mean(5,x) (Double_t) 3.000000e+00 root [2] double w[5]={1,2,3,4,5} root [3] TMath::Mean(5,x,w) (Double_t) 3.666667e+00
What do you get?

Concerning the iterator, they are useful if you use for example vector

root [0] vector < double > x (vector<double> &) @0x7f3bfc071018 root [1] for(double i=1 ; i<=5 ; i++) x.push_back(i) root [2] TMath::Mean(x.begin(),x.end()) (Double_t) 3.000000e+00