11 template <typename obstype>
15 void addMeas(const obstype& val);
16 void addMeas(obstype val[], int valsize);
18 void computeEasy(const string& compid="one", const int& ival=0) { mean(compid, &measurements, ival); }
20 void computeJack(const string& compid, double (*func)(list< vector <obstype> > *vals, void *para)=NULL, void *para=NULL);
21 void computeJack(double (*func)(list< vector <obstype> > *vals, void *para)=NULL, void *para=NULL) { computeJack("one",func,para); }
23 double getMean(const string& compid="one") { return computations[compid].val; }
24 double getErr(const string& compid="one") { return computations[compid].err; }
32 list< vector<obstype> > measurements;
33 map<string,result> computations;
35 void mean(const string& compid, list< vector <double> > *meas, const int& ival);
38 template <typename obstype>
39 void obs<obstype>::addMeas(const obstype& val)
41 measurements.push_back( vector<obstype>(1,val) );
44 template <typename obstype>
45 void obs<obstype>::addMeas(obstype val[], int valsize)
47 vector<obstype> tmpvec;
48 for(int i=0; i<valsize; i++) tmpvec.push_back(val[i]);
49 measurements.push_back(tmpvec);
52 template <typename obstype>
53 void obs<obstype>::mean(const string& compid, list< vector<double> > *meas, const int& ival)
55 computations[compid].val = 0;
56 computations[compid].err = 0;
58 int nmeas = meas->size();
60 for(list< vector<double> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
61 computations[compid].val += (*measIt)[ival];
62 computations[compid].val /= nmeas;
64 for(list< vector<double> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
65 computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 );
66 computations[compid].err /= nmeas*(nmeas-1);
67 computations[compid].err = sqrt( computations[compid].err );
70 template <typename obstype>
71 void obs<obstype>::computeJack(const string& compid, double (*func)(list< vector<obstype> > *vals, void *para), void *para)
73 int nmeas=measurements.size();
74 double manymeans[nmeas];
76 computations[compid].val = 0;
77 computations[compid].err = 0;
80 for(typename list< vector<obstype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++)
82 vector<obstype> removed = *removedIt;
84 typename list< vector<obstype> >::iterator nextAfterIt = removedIt;
87 measurements.erase(removedIt);
89 manymeans[imeas] = func(&measurements, para);
90 computations[compid].val += manymeans[imeas];
92 measurements.insert(nextAfterIt, removed);
94 removedIt = nextAfterIt;
96 computations[compid].val /= nmeas;
98 for(int imean=0; imean<nmeas; imean++)
99 computations[compid].err += pow( computations[compid].val - manymeans[imean], 2 );
100 computations[compid].err *= (double)(nmeas-1)/nmeas;
101 computations[compid].err = sqrt(computations[compid].err);