]> git.treefish.org Git - phys/heatbath.git/blob - obs_phip2_hist.hpp
...
[phys/heatbath.git] / obs_phip2_hist.hpp
1 #ifndef OBS_PHIP2_HIST_HPP
2 #define OBS_PHIP2_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 #include <stdlib.h>
12
13 using namespace std;
14
15 class obs_phip2_hist : public o815::obs {
16
17 public:
18   struct obsmem {
19     double phip2[4];
20   };
21   obs_phip2_hist(o815 *_O815, const int& avgmany=2);
22   
23 private:
24   void _start() {}
25   void _meas(bool loadedobs, const int& nthmeas);
26   void _finish() {}
27   obsmem *OM;
28   sim *Sim;
29   double avgphip2[4];
30   static string intToStr(const int& number);
31   int avgmany;
32 };
33
34 string obs_phip2_hist::intToStr(const int& number)
35 {
36   stringstream ss;
37   ss << number;
38   return ss.str();
39 }
40
41 obs_phip2_hist::obs_phip2_hist(o815 *_O815, const int& _avgmany) : o815::obs("phip2", 
42                                                                              _O815->paraQ->getParaNames() + "nthstep:imode:kt:kx:phip2absdiffequi", _O815, 
43                                                                              sizeof(obsmem), 
44                                                                              "_hist_avg" + intToStr(_avgmany) ) {
45   OM = (obsmem*)obsMem;
46   Sim = (sim*)O815->Sim;
47   avgmany = _avgmany;
48 }
49
50 void obs_phip2_hist::_meas(bool loadedobs, const int& nthmeas) {
51   for (int kpimode=0; kpimode<4; kpimode++) {
52     const double ppt = 2.*M_PI/O815->comargs.lsize[0] * ( 0 + int( kpimode/4. * O815->comargs.lsize[0] ) ) ;
53     const double ppx = 2.*M_PI/O815->comargs.lsize[1] * ( 0 + int( kpimode/4. * O815->comargs.lsize[1] ) );
54
55     if (!loadedobs) {
56       complex<double> phitildepp = 0;
57       
58       for (int ixpt = 0; ixpt < O815->comargs.lsize[0]; ixpt++)
59         for (int ixpx = 0; ixpx < O815->comargs.lsize[1]; ixpx++)
60           phitildepp += Sim->conf[ ixpt*O815->comargs.lsize[1] + ixpx ].phi 
61             * exp ( - _i_*(double)ppx*(double)ixpx - _i_*(double)ppt*(double)ixpt );
62       
63       OM->phip2[ kpimode ] = norm( phitildepp) / Sim->LSIZE2;
64     }
65
66     if ( nthmeas%avgmany == 0 )
67       avgphip2[kpimode] = 0;
68     
69     avgphip2[kpimode] += OM->phip2[ kpimode ];
70
71     if ( (nthmeas+1)%avgmany == 0 ) {
72       *out << O815->paraQ->getParaVals();
73       *out << "\t" << ( Sim->nequi + (nthmeas+1)*Sim->nskip );
74       *out << "\t" << kpimode;
75       *out << "\t" << 0 + int( kpimode/4. * O815->comargs.lsize[0] );
76       *out << "\t" << 0 + int( kpimode/4. * O815->comargs.lsize[1] );
77       *out << "\t" << abs( avgphip2[kpimode] / (double)avgmany - 1./(ppt*ppt + ppx*ppx + Sim->m*Sim->m) ) << endl;
78     }
79   }
80 };
81
82 #endif