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(restype (*func)(vector< vector <meastype> > *vals, void *para)=NULL, void *para=NULL);
22 restype getMean(int compid) { return computations[compid].val; }
23 restype getErr(int compid) { return computations[compid].err; }
33 vector< vector<meastype> > measurements;
34 vector<result> computations;
36 int mean(vector< vector <meastype> > *meas, const int& ival);
39 template <typename meastype, typename restype>
40 void obstat<meastype,restype>::reset()
46 template <typename meastype, typename restype>
47 void obstat<meastype,restype>::addMeas(const meastype& val)
49 measurements.push_back( vector<meastype>(1,val) );
52 template <typename meastype, typename restype>
53 void obstat<meastype,restype>::addMeas(meastype val[], int valsize)
55 vector<meastype> tmpvec;
56 for (int i=0; i<valsize; i++)
57 tmpvec.push_back(val[i]);
58 measurements.push_back(tmpvec);
61 template <typename meastype, typename restype>
62 int obstat<meastype,restype>::mean(vector< vector<meastype> > *meas, const int& ival)
69 int nmeas = meas->size();
71 for (typename vector< vector<meastype> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
72 meanres.val += (*measIt)[ival];
75 for (typename vector< vector<meastype> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
76 meanres.err += pow( (*measIt)[ival] - meanres.val, 2 );
77 meanres.err = sqrt( meanres.err ) / (restype)nmeas;
79 computations.push_back(meanres);
81 return computations.size()-1;
84 template <typename meastype, typename restype>
85 int obstat<meastype,restype>::computeJack(restype (*func)(vector< vector<meastype> > *vals, void *para), void *para)
87 int nmeas=measurements.size();
88 restype manymeans[nmeas];
95 for(typename vector< vector<meastype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++)
97 vector<meastype> removed = *removedIt;
99 *removedIt = measurements.back();
100 measurements.pop_back();
102 manymeans[imeas] = func(&measurements, para);
103 jackres.val += manymeans[imeas];
105 measurements.push_back( *removedIt );
106 *removedIt = removed;
108 jackres.val /= nmeas;
110 for(int imean=0; imean<nmeas; imean++)
111 jackres.err += pow( manymeans[imean] - jackres.val, 2 );
112 jackres.err *= (double)(nmeas-1)/nmeas;
113 jackres.err = sqrt(jackres.err);
115 computations.push_back(jackres);
117 return computations.size()-1;