template <typename obstype>
class obs
-{
- struct result{
- double val;
- double err;
- };
-
+{
public:
- void addMeas(obstype val[], int valsize);
void addMeas(const obstype& val);
+ void addMeas(obstype val[], int valsize);
+
+ void computeEasy(const string& compid="one", const int& ival=0) { mean(compid, &measurements, ival); }
- void computeMean(const string& compid) { mean(compid, &measurements); }
- void computeJack(const string& compid, double (*func)(list<obstype> *vals, void *para), void *para=NULL);
+ void computeJack(const string& compid, double (*func)(list< vector <obstype> > *vals, void *para)=NULL, void *para=NULL);
+ void computeJack(double (*func)(list< vector <obstype> > *vals, void *para)=NULL, void *para=NULL) { computeJack("one",func,para); }
- double getMean(const string& compid) { return computations[compid].val; }
- double getErr(const string& compid) { return computations[compid].err; }
+ double getMean(const string& compid="one") { return computations[compid].val; }
+ double getErr(const string& compid="one") { return computations[compid].err; }
private:
- list<obstype> measurements;
+ struct result{
+ double val;
+ double err;
+ };
+
+ list< vector<obstype> > measurements;
map<string,result> computations;
- void mean(const string& compid, list<double> *meas);
+ void mean(const string& compid, list< vector <double> > *meas, const int& ival);
};
-template <typename obstype>
-void obs<obstype>::addMeas(obstype val[], int valsize)
+template <typename obstype>
+void obs<obstype>::addMeas(const obstype& val)
{
- for(int i=0; i<valsize; i++) measurements.push_back(val[i]);
+ measurements.push_back( vector<obstype>(1,val) );
}
-template <typename obstype>
-void obs<obstype>::addMeas(const obstype& val)
+template <typename obstype>
+void obs<obstype>::addMeas(obstype val[], int valsize)
{
- measurements.push_back(val);
+ vector<obstype> tmpvec;
+ for(int i=0; i<valsize; i++) tmpvec.push_back(val[i]);
+ measurements.push_back(tmpvec);
}
template <typename obstype>
-void obs<obstype>::mean(const string& compid, list<double> *meas)
+void obs<obstype>::mean(const string& compid, list< vector<double> > *meas, const int& ival)
{
computations[compid].val = 0;
computations[compid].err = 0;
int nmeas = meas->size();
- for(list<double>::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
- computations[compid].val += *measIt;
+ for(list< vector<double> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
+ computations[compid].val += (*measIt)[ival];
computations[compid].val /= nmeas;
- for(list<double>::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
- computations[compid].err += pow( *measIt - computations[compid].val, 2 );
+ for(list< vector<double> >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
+ computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 );
computations[compid].err /= nmeas*(nmeas-1);
computations[compid].err = sqrt( computations[compid].err );
}
template <typename obstype>
-void obs<obstype>::computeJack(const string& compid, double (*func)(list<obstype> *vals, void *para), void *para)
+void obs<obstype>::computeJack(const string& compid, double (*func)(list< vector<obstype> > *vals, void *para), void *para)
{
int nmeas=measurements.size();
double manymeans[nmeas];
computations[compid].err = 0;
int imeas=0;
- for(typename list<obstype>::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++)
+ for(typename list< vector<obstype> >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++)
{
- obstype removed = *removedIt;
+ vector<obstype> removed = *removedIt;
- typename list<obstype>::iterator nextAfterIt = removedIt;
+ typename list< vector<obstype> >::iterator nextAfterIt = removedIt;
++nextAfterIt;
measurements.erase(removedIt);