]> git.treefish.org Git - phys/heatbath.git/blob - obs_phi2_hist.hpp
Averaging phip2 over 2 successive measurements.
[phys/heatbath.git] / obs_phi2_hist.hpp
1 #ifndef OBS_PHI2_HIST_HPP
2 #define OBS_PHI2_HIST_HPP
3
4 #include "latlib/o815/o815.h"
5
6 #include "latlib/writeout.h"
7
8 #include "latlib/obstat.hpp"
9
10 #include <iostream>
11
12 using namespace std;
13
14 class obs_phi2_hist : public o815::obs {
15
16 public:
17   struct obsmem {
18     double phi2;
19   };
20   obs_phi2_hist(o815 *_O815);
21   
22 private:
23   void _start() {}
24   void _meas(bool loadedobs, const int& nthmeas);
25   void _finish() {}
26   obsmem* OM;
27   void phi2Compute();
28   sim *Sim;
29 };
30
31 obs_phi2_hist::obs_phi2_hist(o815 *_O815) : o815::obs("phi2", 
32                                                       _O815->paraQ->getParaNames() + "nthstep:phi2", 
33                                                       _O815, sizeof(obsmem), "_hist") {
34   OM = (obsmem*)obsMem;
35   Sim = (sim*)O815->Sim;
36 }
37
38 void obs_phi2_hist::_meas(bool loadedobs, const int& nthmeas) {
39   if (!loadedobs)
40     phi2Compute();
41   
42   *out << O815->paraQ->getParaVals();
43   *out << "\t" << ( Sim->nequi + (nthmeas+1)*Sim->nskip );
44   *out << "\t" << OM->phi2 << endl;
45 };
46
47 void obs_phi2_hist::phi2Compute()
48 {
49   OM->phi2 = 0;
50   
51   for (int ix = 0; ix < Sim->LSIZE2; ix++)
52     OM->phi2 += norm( Sim->conf[ix].phi );
53
54   OM->phi2 /= Sim->LSIZE2;
55 }
56
57 #endif