project(latlib)
-add_library(obs obs.cpp)
add_library(configcache configcache.cpp)
-target_link_libraries(configcache boost_iostreams)
\ No newline at end of file
+target_link_libraries(configcache boost_iostreams)
+++ /dev/null
-#include "obs.h"
-
-#include <math.h>
-
-using namespace std;
-
-template <class obstype>
-void obs<obstype>::addMeas(obstype val[], int valsize)
-{
- for(int i=0; i<valsize; i++) measurements.push_back(val[i]);
-}
-
-template <class obstype>
-void obs<obstype>::addMeas(const obstype& val)
-{
- measurements.push_back(val);
-}
-
-template <class obstype>
-void obs<obstype>::mean(const string& compid, const list<double>& meas)
-{
- computations[compid][0] = 0;
- computations[compid][1] = 0;
- int nmeas = meas.size();
-
- for(list<double>::iterator measIt = meas.begin(); measIt != meas.end(); ++measIt)
- computations[compid][0] += *measIt;
- computations[compid][0] /= nmeas;
-
- for(list<double>::iterator measIt = meas.begin(); measIt != meas.end(); ++measIt)
- computations[compid][1] += pow( *measIt - computations[compid][0], 2 );
- computations[compid][1] /= nmeas*(nmeas-1);
- computations[compid][1] = sqrt(computations[compid][1]);
-}
-
-template <class obstype>
-void obs<obstype>::computeJack(const string& compid, double (*func)(const list<obstype>& vals, void *para), void *para)
-{
- int nmeas=measurements.size();
- double manymeans[nmeas];
-
- computations[compid][0] = 0;
- computations[compid][1] = 0;
-
- int imeas=0;
- for(typename list<obstype>::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++)
- {
- obstype removed = *removedIt;
-
- typename list<obstype>::iterator nextAfterIt = removedIt;
- ++nextAfterIt;
-
- measurements.erase(removedIt);
-
- manymeans[imeas] = func(measurements, para);
- computations[compid][0] += manymeans[imeas];
-
- measurements.insert(nextAfterIt, removed);
- }
- computations[compid][0] /= nmeas;
-
- for(int imean=0; imean<nmeas; imean++)
- computations[compid][1] += pow( computations[compid][0] - manymeans[imean], 2 );
- computations[compid][1] *= (double)(nmeas-1)/nmeas;
- computations[compid][1] = sqrt(computations[compid][1]);
-}
+++ /dev/null
-#ifndef OBS_H
-#define OBS_H
-
-#include <list>
-#include <string>
-#include <map>
-
-using namespace std;
-
-template <class obstype>
-class obs
-{
- public:
- void addMeas(obstype val[], int valsize);
- void addMeas(const obstype& val);
-
- void computeMean(const string& compid) { mean(compid, measurements); }
- void computeJack(const string& compid, double (*func)(const list<obstype>& vals, void *para), void *para=NULL);
-
- private:
- list<obstype> measurements;
- map<string,double[2]> computations;
-
- void mean(const string& compid, const list<double>& meas);
-};
-
-#endif
--- /dev/null
+#ifndef OBS_HPP
+#define OBS_HPP
+
+#include <list>
+#include <string>
+#include <map>
+#include <math.h>
+
+using namespace std;
+
+template <typename obstype>
+class obs
+{
+ struct result{
+ double val;
+ double err;
+ };
+
+public:
+ void addMeas(obstype val[], int valsize);
+ void addMeas(const obstype& val);
+
+ void computeMean(const string& compid) { mean(compid, &measurements); }
+ void computeJack(const string& compid, double (*func)(list<obstype> *vals, void *para), void *para=NULL);
+
+ double getMean(const string& compid) { return computations[compid].val; }
+ double getErr(const string& compid) { return computations[compid].err; }
+
+private:
+ list<obstype> measurements;
+ map<string,result> computations;
+
+ void mean(const string& compid, list<double> *meas);
+};
+
+template <typename obstype>
+void obs<obstype>::addMeas(obstype val[], int valsize)
+{
+ for(int i=0; i<valsize; i++) measurements.push_back(val[i]);
+}
+
+template <typename obstype>
+void obs<obstype>::addMeas(const obstype& val)
+{
+ measurements.push_back(val);
+}
+
+template <typename obstype>
+void obs<obstype>::mean(const string& compid, list<double> *meas)
+{
+ 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;
+ computations[compid].val /= nmeas;
+
+ for(list<double>::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt)
+ computations[compid].err += pow( *measIt - 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)
+{
+ int nmeas=measurements.size();
+ double manymeans[nmeas];
+
+ computations[compid].val = 0;
+ computations[compid].err = 0;
+
+ int imeas=0;
+ for(typename list<obstype>::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++)
+ {
+ obstype removed = *removedIt;
+
+ typename list<obstype>::iterator nextAfterIt = removedIt;
+ ++nextAfterIt;
+
+ measurements.erase(removedIt);
+
+ manymeans[imeas] = func(&measurements, para);
+ computations[compid].val += manymeans[imeas];
+
+ measurements.insert(nextAfterIt, removed);
+
+ removedIt = nextAfterIt;
+ }
+ computations[compid].val /= nmeas;
+
+ for(int imean=0; imean<nmeas; imean++)
+ computations[compid].err += pow( computations[compid].val - manymeans[imean], 2 );
+ computations[compid].err *= (double)(nmeas-1)/nmeas;
+ computations[compid].err = sqrt(computations[compid].err);
+}
+
+#endif