11 template <typename meastype, typename restype>
15 void addMeas(const meastype& val);
16 void addMeas(meastype val[], int valsize);
18 int computeEasy(const int& ival=0) { return mean(&measurements, ival); }
20 int computeJack(void (*preMeasFunc)(vector< vector <meastype> > *allVals, vector <meastype> *preCalculated, void *para),
21 restype (*measFunc)(vector <meastype> *preCalculated, vector <meastype> *excludedmeas, int nmeas, void *para), void *para=NULL);
23 restype getMean(int compid) { return computations[compid].val; }
24 restype getErr(int compid) { return computations[compid].err; }
34 vector< vector<meastype> > measurements;
35 vector<result> computations;
37 int mean(vector< vector <meastype> > *meas, const int& ival);
40 template <typename meastype, typename restype>
41 void obstat<meastype,restype>::reset()
47 template <typename meastype, typename restype>
48 void obstat<meastype,restype>::addMeas(const meastype& val)
50 measurements.push_back( vector<meastype>(1,val) );
53 template <typename meastype, typename restype>
54 void obstat<meastype,restype>::addMeas(meastype val[], int valsize)
56 vector<meastype> tmpvec;
57 for (int i=0; i<valsize; i++)
58 tmpvec.push_back(val[i]);
59 measurements.push_back(tmpvec);
62 template <typename meastype, typename restype>
63 int obstat<meastype,restype>::mean(vector< vector<meastype> > *meas, const int& ival)
70 int nmeas = meas->size();
72 for (typename vector< vector<meastype> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
73 meanres.val += (*measIt)[ival];
76 for (typename vector< vector<meastype> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
77 meanres.err += pow( (*measIt)[ival] - meanres.val, 2 );
78 meanres.err = sqrt( meanres.err ) / (restype)nmeas;
80 computations.push_back(meanres);
82 return computations.size()-1;
85 template <typename meastype, typename restype>
86 int obstat<meastype,restype>::computeJack(void (*preMeasFunc)(vector< vector <meastype> > *allVals, vector<meastype> *preCalculated, void *para),
87 restype (*measFunc)(vector<meastype> *preCalculated, vector<meastype> *excludedmeas, int nmeas, void *para),
89 int nmeas=measurements.size();
90 restype *manymeans = new restype[nmeas];
92 vector<meastype> preCalculated;
97 preMeasFunc(&measurements, &preCalculated, para);
100 for(typename vector< vector<meastype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++) {
101 manymeans[imeas] = measFunc(&preCalculated, &(*removedIt), measurements.size(), para);
102 jackres.val += manymeans[imeas];
104 jackres.val /= nmeas;
106 for(int imean=0; imean<nmeas; imean++)
107 jackres.err += pow( manymeans[imean] - jackres.val, 2 );
108 jackres.err *= (double)(nmeas-1)/nmeas;
109 jackres.err = sqrt(jackres.err);
111 computations.push_back(jackres);
115 return computations.size()-1;