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)(vector< vector <obstype> > *vals, void *para)=NULL, void *para=NULL);
21 void computeJack(double (*func)(vector< 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; }
34 vector< vector<obstype> > measurements;
35 map<string,result> computations;
37 void mean(const string& compid, vector< vector <double> > *meas, const int& ival);
38 void mean(const string& compid, vector< vector <int> > *meas, const int& ival);
42 template <typename obstype>
43 void obs<obstype>::reset()
49 template <typename obstype>
50 void obs<obstype>::addMeas(const obstype& val)
52 measurements.push_back( vector<obstype>(1,val) );
55 template <typename obstype>
56 void obs<obstype>::addMeas(obstype val[], int valsize)
58 vector<obstype> tmpvec;
59 for(int i=0; i<valsize; i++) tmpvec.push_back(val[i]);
60 measurements.push_back(tmpvec);
63 template <typename obstype>
64 void obs<obstype>::mean(const string& compid, vector< vector<double> > *meas, const int& ival)
66 computations[compid].val = 0;
67 computations[compid].err = 0;
69 int nmeas = meas->size();
71 for(vector< vector<double> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
72 computations[compid].val += (*measIt)[ival];
73 computations[compid].val /= nmeas;
75 for(vector< vector<double> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
76 computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 );
77 computations[compid].err = sqrt( computations[compid].err ) / nmeas;
80 template <typename obstype>
81 void obs<obstype>::mean(const string& compid, vector< vector<int> > *meas, const int& ival)
83 computations[compid].val = 0;
84 computations[compid].err = 0;
86 int nmeas = meas->size();
88 for(vector< vector<int> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
89 computations[compid].val += (*measIt)[ival];
90 computations[compid].val /= nmeas;
92 for(vector< vector<int> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
93 computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 );
94 computations[compid].err = sqrt( computations[compid].err ) / nmeas;
97 template <typename obstype>
98 void obs<obstype>::computeJack(const string& compid, double (*func)(vector< vector<obstype> > *vals, void *para), void *para)
100 int nmeas=measurements.size();
101 double manymeans[nmeas];
103 computations[compid].val = 0;
104 computations[compid].err = 0;
107 for(typename vector< vector<obstype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++)
109 vector<obstype> removed = *removedIt;
111 *removedIt = measurements.back();
112 measurements.pop_back();
114 manymeans[imeas] = func(&measurements, para);
115 computations[compid].val += manymeans[imeas];
117 measurements.push_back( *removedIt );
118 *removedIt = removed;
120 computations[compid].val /= nmeas;
122 for(int imean=0; imean<nmeas; imean++)
123 computations[compid].err += pow( manymeans[imean] - computations[compid].val, 2 );
124 computations[compid].err *= (double)(nmeas-1)/nmeas;
125 computations[compid].err = sqrt(computations[compid].err);