]> git.treefish.org Git - phys/latlib.git/commitdiff
...
authorAlex Schmidt <alex@treefish.org>
Thu, 24 May 2012 13:18:55 +0000 (15:18 +0200)
committerAlex Schmidt <alex@treefish.org>
Thu, 24 May 2012 13:18:55 +0000 (15:18 +0200)
CMakeLists.txt
obs.cpp [deleted file]
obs.h [deleted file]
obs.hpp [new file with mode: 0644]

index 117984c46918e593a0919ee78da7aa32de508ec2..be72077d5ef152e6c1113e773b4be800716a0b7d 100644 (file)
@@ -1,6 +1,5 @@
 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)
diff --git a/obs.cpp b/obs.cpp
deleted file mode 100644 (file)
index 75c1d93..0000000
--- a/obs.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-#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]);
-}
diff --git a/obs.h b/obs.h
deleted file mode 100644 (file)
index 38fce5a..0000000
--- a/obs.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#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
diff --git a/obs.hpp b/obs.hpp
new file mode 100644 (file)
index 0000000..ae544e4
--- /dev/null
+++ b/obs.hpp
@@ -0,0 +1,100 @@
+#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