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 /= nmeas*(nmeas-1);
78 computations[compid].err = sqrt( computations[compid].err );
81 template <typename obstype>
82 void obs<obstype>::mean(const string& compid, vector< vector<int> > *meas, const int& ival)
84 computations[compid].val = 0;
85 computations[compid].err = 0;
87 int nmeas = meas->size();
89 for(vector< vector<int> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
90 computations[compid].val += (*measIt)[ival];
91 computations[compid].val /= nmeas;
93 for(vector< vector<int> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
94 computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 );
95 computations[compid].err /= nmeas*(nmeas-1);
96 computations[compid].err = sqrt( computations[compid].err );
99 template <typename obstype>
100 void obs<obstype>::computeJack(const string& compid, double (*func)(vector< vector<obstype> > *vals, void *para), void *para)
102 int nmeas=measurements.size();
103 double manymeans[nmeas];
105 computations[compid].val = 0;
106 computations[compid].err = 0;
109 for(typename vector< vector<obstype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++)
111 vector<obstype> removed = *removedIt;
113 *removedIt = measurements.back();
114 measurements.pop_back();
116 manymeans[imeas] = func(&measurements, para);
117 computations[compid].val += manymeans[imeas];
119 measurements.push_back( *removedIt );
120 *removedIt = removed;
122 computations[compid].val /= nmeas;
124 for(int imean=0; imean<nmeas; imean++)
125 computations[compid].err += pow( manymeans[imean] - computations[compid].val, 2 );
126 computations[compid].err *= (double)(nmeas-1)/nmeas;
127 computations[compid].err = sqrt(computations[compid].err);