1 #ifndef OBS_DIAGCORR_HPP
2 #define OBS_DIAGCORR_HPP
4 #include "latlib/o815/o815.h"
6 #include "latlib/writeout.h"
8 #include "latlib/obstat.hpp"
15 #include <gsl/gsl_complex.h>
16 #include <gsl/gsl_math.h>
17 #include <gsl/gsl_eigen.h>
21 class obs_diagcorr : public o815::obs {
24 obs_diagcorr(o815 *_O815);
28 void _meas(bool loadedobs, const int& nthmeas);
32 static complex<double> effMass(vector < complex<double> > *preCalculated, vector< complex<double> > *excludedMeas, int nmeas, void *para);
33 static void preEffMass(vector< vector < complex<double> > > *allVals, vector < complex<double> > *preCalculated, void *para);
36 obstat< complex<double>, complex<double> > oC[16];
40 complex<double> *OM[16];
43 obs_diagcorr::obs_diagcorr(o815 *_O815) : o815::obs("diagcorr",
44 _O815->paraQ->getParaNames() +
47 _O815, 16*sizeof(complex<double>)*(_O815->comargs.lsize[1]/2) ) {
48 for (int ivar = 0; ivar<16; ivar++)
49 OM[ivar] = (complex<double>*)( obsMem + ivar*sizeof(complex<double>)*( _O815->comargs.lsize[1]/2 ) );
51 Sim = (sim*)O815->Sim;
52 spatialV = O815->comargs.lsize[0] * O815->comargs.lsize[0] * O815->comargs.lsize[0];
55 void obs_diagcorr::_start() {
56 //*out << "OBS_test: start" << endl;
59 void obs_diagcorr::_meas(bool loadedobs, const int& nthmeas) {
63 for (int icorr=0; icorr<16; icorr++)
64 oC[icorr].addMeas( OM[icorr], O815->comargs.lsize[1]/2 );
67 void obs_diagcorr::_finish() {
68 for (int itsep = 0; itsep < O815->comargs.lsize[1]/2; itsep++) {
69 gsl_complex matdata[16];
71 gsl_matrix_complex *m = gsl_matrix_complex_alloc(4,4);
73 for (int icorr = 0; icorr < 4; icorr++)
74 for (int jcorr = 0; jcorr < 4; jcorr++) {
75 int compid_corr = oC[icorr*4+jcorr].computeEasy(itsep);
78 tmpc.dat[0] = oC[icorr*4+jcorr].getMean(compid_corr).real();
79 tmpc.dat[1] = oC[icorr*4+jcorr].getMean(compid_corr).imag();
81 gsl_matrix_complex_set( m, icorr, jcorr, tmpc);
84 gsl_vector *evvec = gsl_vector_alloc(4);
86 gsl_eigen_herm_workspace *wspace = gsl_eigen_herm_alloc(100);
88 gsl_eigen_herm(m, evvec, wspace);
90 gsl_eigen_herm_free(wspace);
91 gsl_matrix_complex_free(m);
93 *out << O815->paraQ->getParaVals();
94 *out << "\t" << itsep;
95 for (int iev = 0; iev < 4; iev++) {
96 *out << "\t" << gsl_vector_get(evvec,iev);
100 gsl_vector_free(evvec);
104 // for (int itsep = 0; itsep < O815->comargs.lsize[1]/2; itsep++) {
109 for (int itsep = 0; itsep < O815->comargs.lsize[1]/2; itsep++) {
110 *out << O815->paraQ->getParaVals();
111 *out << "\t" << itsep;
112 for (int icorr = 0; icorr < 16; icorr++) {
113 *out << "\t" << real( oC[icorr].getMean(compid_corr[itsep][icorr]) );
119 for (int icorr = 0; icorr < 16; icorr++) {
124 void obs_diagcorr::corrCompute()
126 complex<double> phislice[4][O815->comargs.lsize[1]];
128 for (int it = 0; it < O815->comargs.lsize[1]; it++) {
134 for (int ix = 0; ix < spatialV; ix++) {
135 phislice[0][it] += conj(Sim->phi[ 0*Sim->lsize4 + it*spatialV + ix ]) * Sim->phi[ 0*Sim->lsize4 + it*spatialV + ix ];
136 phislice[1][it] += Sim->phi[ 0*Sim->lsize4 + it*spatialV + ix ] * Sim->phi[ 1*Sim->lsize4 + it*spatialV + ix ];
137 phislice[2][it] += conj(Sim->phi[ 0*Sim->lsize4 + it*spatialV + ix ]) * conj(Sim->phi[ 1*Sim->lsize4 + it*spatialV + ix ]);
138 phislice[3][it] += conj(Sim->phi[ 1*Sim->lsize4 + it*spatialV + ix ]) * Sim->phi[ 1*Sim->lsize4 + it*spatialV + ix ];
140 phislice[0][it] /= spatialV;
141 phislice[1][it] /= spatialV;
142 phislice[2][it] /= spatialV;
143 phislice[3][it] /= spatialV;
146 for (int icorr = 0; icorr < 4; icorr++)
147 for (int jcorr = 0; jcorr < 4; jcorr++) {
148 for (int itsep = 0; itsep < O815->comargs.lsize[1]/2; itsep++) {
149 OM[icorr*4+jcorr][itsep] = 0;
151 for (int it = 0; it < O815->comargs.lsize[1]; it++)
152 OM[icorr*4+jcorr][itsep] += phislice[icorr][ (it+itsep)%O815->comargs.lsize[1] ] * conj( phislice[jcorr][it] );
154 OM[icorr*4+jcorr][itsep] /= O815->comargs.lsize[1];