Standard Deviation

is there a function that can calculate the standard deviation of an array or a vector?


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi,
one (admittedly awkward) way to do it is to fill a histogram with the elements of the array and then ask the histogram its standard deviation. Binning might also make the result imprecise.

If you have ROOT v6.14, you can use ROOT::VecOps::RVec instead. It should be as simple as:

using namespace ROOT::VecOps;
RVec<float> rv = yourstdvectorofnumbers;
auto srddev = StdDev(rv);

I don’t know of another function that evaluates the standard deviation of a std::vector or an array directly in ROOT. Maybe @moneta knows :slight_smile:

Cheers,
Enrico

Hello,
is the TMath::RMS function what you’re looking for? I know it’s called RMS but it looks like the standard deviation.

i used the code, with my own variables and i received the following error message:

*** Break *** segmentation violation

[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)

[<unknown binary>] (no debug info)

Yes, you can use TMath::RMS or TMath::StdDev

std::vector<double> x(100);
gRandom->RndmArray(x.size(),x.data());
TMath::StdDev(x.begin(), x.end() ); 

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.