]> git.treefish.org Git - phys/heatbath.git/blobdiff - obs_phi2_hist.hpp
Added phi2_hist.
[phys/heatbath.git] / obs_phi2_hist.hpp
diff --git a/obs_phi2_hist.hpp b/obs_phi2_hist.hpp
new file mode 100644 (file)
index 0000000..b97d38c
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef OBS_PHI2_HIST_HPP
+#define OBS_PHI2_HIST_HPP
+
+#include "latlib/o815/o815.h"
+
+#include "latlib/writeout.h"
+
+#include "latlib/obstat.hpp"
+
+#include <iostream>
+
+using namespace std;
+
+class obs_phi2_hist : public o815::obs {
+
+public:
+  struct obsmem {
+    double phi2;
+  };
+  obs_phi2_hist(o815 *_O815);
+  
+private:
+  void _start() {}
+  void _meas(bool loadedobs, const int& nthmeas);
+  void _finish() {}
+  obsmem* OM;
+  void phi2Compute();
+  sim *Sim;
+};
+
+obs_phi2_hist::obs_phi2_hist(o815 *_O815) : o815::obs("phi2", 
+                                                     _O815->paraQ->getParaNames() + "nthstep:phi2:phi2_err", 
+                                                     _O815, sizeof(obsmem), "_hist") {
+  OM = (obsmem*)obsMem;
+  Sim = (sim*)O815->Sim;
+}
+
+void obs_phi2_hist::_meas(bool loadedobs, const int& nthmeas) {
+  if (!loadedobs)
+    phi2Compute();
+  
+  *out << O815->paraQ->getParaVals();
+  *out << "\t" << ( Sim->nequi + (nthmeas+1)*Sim->nskip );
+  *out << "\t" << OM->phi2 << endl;
+};
+
+void obs_phi2_hist::phi2Compute()
+{
+  OM->phi2 = 0;
+  
+  for (int ix = 0; ix < Sim->LSIZE2; ix++)
+    OM->phi2 += norm( Sim->conf[ix].phi );
+
+  OM->phi2 /= Sim->LSIZE2;
+}
+
+#endif