X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/79dc42fe36820965127efc5755be1450521b0a26..8d11db1cf57b103fcec701d71c9d620b1c381b73:/obstat.hpp?ds=inline diff --git a/obstat.hpp b/obstat.hpp index 2996043..6a2cf6e 100644 --- a/obstat.hpp +++ b/obstat.hpp @@ -17,7 +17,8 @@ public: int computeEasy(const int& ival=0) { return mean(&measurements, ival); } - int computeJack(restype (*func)(vector< vector > *vals, void *para)=NULL, void *para=NULL); + int computeJack(void (*preMeasFunc)(vector< vector > *allVals, vector *preCalculated, void *para), + restype (*measFunc)(vector *preCalculated, vector *excludedmeas, int nmeas, void *para), void *para=NULL); restype getMean(int compid) { return computations[compid].val; } restype getErr(int compid) { return computations[compid].err; } @@ -82,31 +83,26 @@ int obstat::mean(vector< vector > *meas, const int& } template -int obstat::computeJack(restype (*func)(vector< vector > *vals, void *para), void *para) -{ +int obstat::computeJack(void (*preMeasFunc)(vector< vector > *allVals, vector *preCalculated, void *para), + restype (*measFunc)(vector *preCalculated, vector *excludedmeas, int nmeas, void *para), + void *para) { int nmeas=measurements.size(); - restype manymeans[nmeas]; + restype *manymeans = new restype[nmeas]; result jackres; + vector preCalculated; jackres.val = 0; jackres.err = 0; + preMeasFunc(&measurements, &preCalculated, para); + int imeas=0; - for(typename vector< vector >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++) - { - vector removed = *removedIt; - - *removedIt = measurements.back(); - measurements.pop_back(); - - manymeans[imeas] = func(&measurements, para); - jackres.val += manymeans[imeas]; - - measurements.push_back( *removedIt ); - *removedIt = removed; - } + for(typename vector< vector >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++) { + manymeans[imeas] = measFunc(&preCalculated, &(*removedIt), measurements.size(), para); + jackres.val += manymeans[imeas]; + } jackres.val /= nmeas; - + for(int imean=0; imean::computeJack(restype (*func)(vector< vector