X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/f88ac5417385884367cf8cd5fc105ec4ffda8904..380a1f7e45365618048e031e4a730563cc4e225d:/obs.hpp?ds=sidebyside diff --git a/obs.hpp b/obs.hpp index 2501f14..4d20bd6 100644 --- a/obs.hpp +++ b/obs.hpp @@ -35,6 +35,7 @@ private: map computations; void mean(const string& compid, vector< vector > *meas, const int& ival); + void mean(const string& compid, vector< vector > *meas, const int& ival); }; @@ -73,8 +74,24 @@ void obs::mean(const string& compid, vector< vector > *meas, co for(vector< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 ); - computations[compid].err /= nmeas*(nmeas-1); - computations[compid].err = sqrt( computations[compid].err ); + computations[compid].err = sqrt( computations[compid].err ) / nmeas; +} + +template +void obs::mean(const string& compid, vector< vector > *meas, const int& ival) +{ + computations[compid].val = 0; + computations[compid].err = 0; + + int nmeas = meas->size(); + + for(vector< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) + computations[compid].val += (*measIt)[ival]; + computations[compid].val /= nmeas; + + for(vector< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) + computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 ); + computations[compid].err = sqrt( computations[compid].err ) / nmeas; } template