From: Alex Schmidt Date: Thu, 24 May 2012 15:27:12 +0000 (+0200) Subject: ...2 X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/d7a3df98c51fc1660f664835131a6ad349d1f270 ...2 --- diff --git a/obs.hpp b/obs.hpp index ae544e4..bba6687 100644 --- a/obs.hpp +++ b/obs.hpp @@ -10,61 +10,65 @@ using namespace std; template class obs -{ - struct result{ - double val; - double err; - }; - +{ public: - void addMeas(obstype val[], int valsize); void addMeas(const obstype& val); + void addMeas(obstype val[], int valsize); + + void computeEasy(const string& compid="one", const int& ival=0) { mean(compid, &measurements, ival); } - void computeMean(const string& compid) { mean(compid, &measurements); } - void computeJack(const string& compid, double (*func)(list *vals, void *para), void *para=NULL); + void computeJack(const string& compid, double (*func)(list< vector > *vals, void *para)=NULL, void *para=NULL); + void computeJack(double (*func)(list< vector > *vals, void *para)=NULL, void *para=NULL) { computeJack("one",func,para); } - double getMean(const string& compid) { return computations[compid].val; } - double getErr(const string& compid) { return computations[compid].err; } + double getMean(const string& compid="one") { return computations[compid].val; } + double getErr(const string& compid="one") { return computations[compid].err; } private: - list measurements; + struct result{ + double val; + double err; + }; + + list< vector > measurements; map computations; - void mean(const string& compid, list *meas); + void mean(const string& compid, list< vector > *meas, const int& ival); }; -template -void obs::addMeas(obstype val[], int valsize) +template +void obs::addMeas(const obstype& val) { - for(int i=0; i(1,val) ); } -template -void obs::addMeas(const obstype& val) +template +void obs::addMeas(obstype val[], int valsize) { - measurements.push_back(val); + vector tmpvec; + for(int i=0; i -void obs::mean(const string& compid, list *meas) +void obs::mean(const string& compid, list< vector > *meas, const int& ival) { computations[compid].val = 0; computations[compid].err = 0; int nmeas = meas->size(); - for(list::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) - computations[compid].val += *measIt; + for(list< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) + computations[compid].val += (*measIt)[ival]; computations[compid].val /= nmeas; - for(list::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) - computations[compid].err += pow( *measIt - computations[compid].val, 2 ); + for(list< 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 ); } template -void obs::computeJack(const string& compid, double (*func)(list *vals, void *para), void *para) +void obs::computeJack(const string& compid, double (*func)(list< vector > *vals, void *para), void *para) { int nmeas=measurements.size(); double manymeans[nmeas]; @@ -73,11 +77,11 @@ void obs::computeJack(const string& compid, double (*func)(list::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++) + for(typename list< vector >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++) { - obstype removed = *removedIt; + vector removed = *removedIt; - typename list::iterator nextAfterIt = removedIt; + typename list< vector >::iterator nextAfterIt = removedIt; ++nextAfterIt; measurements.erase(removedIt);