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), void *para=NULL);
21 int computeJack(void (*preMeasFunc)(vector< vector <meastype> > *allVals, vector <meastype> *preCalculated, void *para),
22 restype (*measFunc)(vector <meastype> *preCalculated, vector <meastype> *excludedmeas, void *para), void *para=NULL);
24 restype getMean(int compid) { return computations[compid].val; }
25 restype getErr(int compid) { return computations[compid].err; }
35 vector< vector<meastype> > measurements;
36 vector<result> computations;
38 int mean(vector< vector <meastype> > *meas, const int& ival);
41 template <typename meastype, typename restype>
42 void obstat<meastype,restype>::reset()
48 template <typename meastype, typename restype>
49 void obstat<meastype,restype>::addMeas(const meastype& val)
51 measurements.push_back( vector<meastype>(1,val) );
54 template <typename meastype, typename restype>
55 void obstat<meastype,restype>::addMeas(meastype val[], int valsize)
57 vector<meastype> tmpvec;
58 for (int i=0; i<valsize; i++)
59 tmpvec.push_back(val[i]);
60 measurements.push_back(tmpvec);
63 template <typename meastype, typename restype>
64 int obstat<meastype,restype>::mean(vector< vector<meastype> > *meas, const int& ival)
71 int nmeas = meas->size();
73 for (typename vector< vector<meastype> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
74 meanres.val += (*measIt)[ival];
77 for (typename vector< vector<meastype> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
78 meanres.err += pow( (*measIt)[ival] - meanres.val, 2 );
79 meanres.err = sqrt( meanres.err ) / (restype)nmeas;
81 computations.push_back(meanres);
83 return computations.size()-1;
86 template <typename meastype, typename restype>
87 int obstat<meastype,restype>::computeJack(restype (*func)(vector< vector<meastype> > *vals, void *para), void *para)
89 int nmeas=measurements.size();
90 restype manymeans[nmeas];
97 for(typename vector< vector<meastype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++)
99 vector<meastype> removed = *removedIt;
101 *removedIt = measurements.back();
102 measurements.pop_back();
104 manymeans[imeas] = func(&measurements, para);
105 jackres.val += manymeans[imeas];
107 measurements.push_back( *removedIt );
108 *removedIt = removed;
110 jackres.val /= nmeas;
112 for(int imean=0; imean<nmeas; imean++)
113 jackres.err += pow( manymeans[imean] - jackres.val, 2 );
114 jackres.err *= (double)(nmeas-1)/nmeas;
115 jackres.err = sqrt(jackres.err);
117 computations.push_back(jackres);
119 return computations.size()-1;
122 template <typename meastype, typename restype>
123 int obstat<meastype,restype>::computeJack(void (*preMeasFunc)(vector< vector <meastype> > *allVals, vector<meastype> *preCalculated, void *para),
124 restype (*measFunc)(vector<meastype> *preCalculated, vector<meastype> *excludedmeas, void *para),
126 int nmeas=measurements.size();
127 restype manymeans[nmeas];
129 vector<meastype> preCalculated;
134 preMeasFunc(&measurements, &preCalculated, para);
137 for(typename vector< vector<meastype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++) {
138 manymeans[imeas] = measFunc(&preCalculated, &(*removedIt), para);
139 jackres.val += manymeans[imeas];
141 jackres.val /= nmeas;
143 for(int imean=0; imean<nmeas; imean++)
144 jackres.err += pow( manymeans[imean] - jackres.val, 2 );
145 jackres.err *= (double)(nmeas-1)/nmeas;
146 jackres.err = sqrt(jackres.err);
148 computations.push_back(jackres);
150 return computations.size()-1;