11 template <typename obstype>
20 void addMeas(obstype val[], int valsize);
21 void addMeas(const obstype& val);
23 void computeMean(const string& compid) { mean(compid, &measurements); }
24 void computeJack(const string& compid, double (*func)(list<obstype> *vals, void *para), void *para=NULL);
26 double getMean(const string& compid) { return computations[compid].val; }
27 double getErr(const string& compid) { return computations[compid].err; }
30 list<obstype> measurements;
31 map<string,result> computations;
33 void mean(const string& compid, list<double> *meas);
36 template <typename obstype>
37 void obs<obstype>::addMeas(obstype val[], int valsize)
39 for(int i=0; i<valsize; i++) measurements.push_back(val[i]);
42 template <typename obstype>
43 void obs<obstype>::addMeas(const obstype& val)
45 measurements.push_back(val);
48 template <typename obstype>
49 void obs<obstype>::mean(const string& compid, list<double> *meas)
51 computations[compid].val = 0;
52 computations[compid].err = 0;
54 int nmeas = meas->size();
56 for(list<double>::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
57 computations[compid].val += *measIt;
58 computations[compid].val /= nmeas;
60 for(list<double>::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
61 computations[compid].err += pow( *measIt - computations[compid].val, 2 );
62 computations[compid].err /= nmeas*(nmeas-1);
63 computations[compid].err = sqrt( computations[compid].err );
66 template <typename obstype>
67 void obs<obstype>::computeJack(const string& compid, double (*func)(list<obstype> *vals, void *para), void *para)
69 int nmeas=measurements.size();
70 double manymeans[nmeas];
72 computations[compid].val = 0;
73 computations[compid].err = 0;
76 for(typename list<obstype>::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++)
78 obstype removed = *removedIt;
80 typename list<obstype>::iterator nextAfterIt = removedIt;
83 measurements.erase(removedIt);
85 manymeans[imeas] = func(&measurements, para);
86 computations[compid].val += manymeans[imeas];
88 measurements.insert(nextAfterIt, removed);
90 removedIt = nextAfterIt;
92 computations[compid].val /= nmeas;
94 for(int imean=0; imean<nmeas; imean++)
95 computations[compid].err += pow( computations[compid].val - manymeans[imean], 2 );
96 computations[compid].err *= (double)(nmeas-1)/nmeas;
97 computations[compid].err = sqrt(computations[compid].err);