int main()
{
  read_pars("analysis_pars");
  
  read_ensemble_pars(base_path,T,TSEP,ibeta,nmass,mass,iml_un,nlight,ntheta,theta,ist_th,njack,data_list_file);
  TH=L=T/2;
  
  //we stick to the light-heavy
  int im_spec=0;
  
  //load the 2 points and fits M and Z
  jack M[nmass];
  jack Z[nmass];
  for(int im_S0=0;im_S0<nmass;im_S0++)
    {
      int ith_S0=ist_th;
      fit_ZM_2pts(M[im_S0],Z[im_S0],im_spec,im_S0,ith_S0);
    }
  
  ofstream FT_file("FT.dat");
  ofstream FP_file("FP.dat");
  ofstream FM_file("FM.dat");
  ofstream F0_file("F0.dat");
  FILE *Q2_file=open_file("Q2_combo","w");
  
  //loop over all the theta combination
  for(int ith_S1=0;ith_S1<ntheta;ith_S1++)
    for(int ith_S0=ith_S1;ith_S0<ntheta;ith_S0++)
      {
	//compute energy
	jack E_source=Eth(M[gen_im_S0],ith_S0);
	jack E_sink=Eth(M[gen_im_S1],ith_S1);
	
	//construct time dependance
	jvec time_dep(T,njack);
	for(int t=0;t<T;t++)
	  {
	    jack coef=Z[gen_im_S0]*Z[gen_im_S1]/sqrt(2*E_source*2*E_sink);
	    jack forw,back;
	    if(t<TSEP)
	      {
		forw=exp(-E_source*t-E_sink*(TSEP-t));
		back=exp(-E_source*(T-t)-E_sink*(T-(TSEP-t)));
	      }
	    else
	      {
		forw=exp(-E_source*(T-t)-E_sink*(t-TSEP));
		back=exp(-E_source*t-E_sink*(T-(t-TSEP)));
	      }
	    time_dep[t]=coef*(forw+back);
	  }
	
	//loop over matrix element
	int iV0=0,iVK=1,iTK=2;
	char MEL_name[3][4]={"V0","VK","TK"};
	jack MEL[3];
	jvec MEL_corr[3];
	for(int iMEL=0;iMEL<3;iMEL++)
	  {
	    //load 3pts
	    jvec P5MELP5;
	    
	    switch(iMEL)
	      {
	      case 0:P5MELP5=load_P5V0P5(gen_im_S0,ith_S0,gen_im_S1,ith_S1);break;
	      case 1:P5MELP5=load_P5VKP5(gen_im_S0,ith_S0,gen_im_S1,ith_S1);break;
	      case 2:P5MELP5=load_P5TKP5(gen_im_S0,ith_S0,gen_im_S1,ith_S1);break;
	      }
	    
	    P5MELP5.subset(1,TSEP).print_to_file(combine("P5%sP5/%02d_%d_%02d_%d.xmg",MEL_name[iMEL],gen_im_S0,ith_S0,gen_im_S1,ith_S1).c_str());
	    
	    time_dep.subset(1,TSEP).print_to_file(combine("time_dep/%02d_%d_%02d_%d.xmg",gen_im_S0,ith_S0,gen_im_S1,ith_S1).c_str());
	    
	    //compute remotion of time dependance
	    MEL_corr[iMEL]=P5MELP5/time_dep;
	    MEL[iMEL]=constant_fit(MEL_corr[iMEL].subset(1,TSEP),tmin_MEL,tmax_MEL,combine("%s/%02d_%d_%02d_%d.xmg",MEL_name[iMEL],gen_im_S0,ith_S0,gen_im_S1,ith_S1).c_str());
	  }
	
	//ratios
	jvec VK_fr_TK_corr=MEL_corr[iVK]/MEL_corr[iTK];
	jack VK_fr_TK=constant_fit(VK_fr_TK_corr.subset(1,TSEP),tmin_MEL,tmax_MEL,combine("VK_fr_TK/%02d_%d_%02d_%d.xmg",gen_im_S0,ith_S0,gen_im_S1,ith_S1).c_str());
	jvec V0_fr_TK_corr=MEL_corr[iV0]/MEL_corr[iTK];
	jack V0_fr_TK=constant_fit(V0_fr_TK_corr.subset(1,TSEP),tmin_MEL,tmax_MEL,combine("V0_fr_TK/%02d_%d_%02d_%d.xmg",gen_im_S0,ith_S0,gen_im_S1,ith_S1).c_str());
	
	//////////////////////////// compute_form_factors ///////////////////////
	
	//2*Zv
	MEL[iVK]/=-2*1.69;
	MEL[iV0]/=-2*1.69;
	
	//impulses
	jack M_source=M[gen_im_S0],M_sink=M[gen_im_S1];
	double p_source=M_PI*theta[ith_S0]/L,p_sink=M_PI*theta[ith_S1]/L;
	jack P0=E_source+E_sink,Q0=E_source-E_sink;
	double Pi=p_source+p_sink,Qi=p_source-p_sink;
	jack Q2=Q0*Q0-3*Qi*Qi;
	jack P2=P0*P0-3*Pi*Pi;
	jack DM2=M_source*M_source-M_sink*M_sink;
	
	//TK=(E_source*p_sink-p_source*E_sink)*2FT/(M_source+M_sink)
	jack FT=MEL[iTK]*0.5*(M_source+M_sink)/(E_source*p_sink-p_source*E_sink);
	
	//FP,F0
	jack FM,FP,F0;
        if(ith_S0!=iopp[ith_S1])
          {
            jack DET=P0*Qi-Q0*Pi;
            //calculate (f+) and (f-)*Q2/(M_K^2-M_Pi^2)
            FP=(MEL[iV0]*Qi-Q0*MEL[iVK])/DET;
            FM=(P0*MEL[iVK]-MEL[iV0]*Pi)/DET;
            F0=FP+Q2/DM2*FM;
          }
        else
          {
            //calculate (f+) and (f-)*Q2/(M_K^2-M_Pi^2)
            FM=MEL[iVK]/Qi;
            FP=(MEL[iV0]-Q0*FM)/P0;
            F0=FP+Q2/DM2*FM;
          }
	
	FT_file<<Q2<<" "<<FT<<" "<<Pi<<endl;
	FP_file<<Q2<<" "<<FP<<" "<<Pi<<endl;
	FM_file<<Q2<<" "<<FM<<" "<<Pi<<endl;
	F0_file<<Q2<<" "<<F0<<" "<<Pi<<endl;
	
	fprintf(Q2_file,"th0=%f\t" "th1=%f\t" "Q2=%f\n",theta[ith_S0],theta[ith_S1],Q2.med());
    }

  fclose(Q2_file);
  
  return 0;
}
Beispiel #2
0
void normalToStdVector(omxMatrix *cov, omxMatrix *mean, omxMatrix *slope, omxMatrix *thr,
		       int numOrdinal, std::vector< omxThresholdColumn > &ti,
		       Eigen::Ref<Eigen::VectorXd> out)
{
	// order of elements: (c.f. lav_model_wls, lavaan 0.6-2)
	// 1. thresholds + means (interleaved)
	// 2. slopes (if any, columnwise per exo)
	// 3. variances (continuous indicators only)
	// 4. covariances; not correlations (lower triangle)

	EigenMatrixAdaptor Ecov(cov);
	if (numOrdinal == 0) {
		int dx = 0;
		if (mean) {
			EigenVectorAdaptor Emean(mean);
			for (int rx=0; rx < cov->cols; ++rx) {
				out[dx++] = Emean(rx);
			}
		}
		if (slope) {
			EigenMatrixAdaptor Eslope(slope);
			for (int cx=0; cx < Eslope.cols(); ++cx) {
				for (int rx=0; rx < Eslope.rows(); ++rx) {
					out[dx++] = Eslope(rx,cx);
				}
			}
		}
		for (int cx=0; cx < cov->cols; ++cx) {
			out[dx++] = Ecov(cx,cx);
		}
		for (int cx=0; cx < cov->cols-1; ++cx) {
			for (int rx=cx+1; rx < cov->rows; ++rx) {
				out[dx++] = Ecov(rx,cx);
			}
		}
		return;
	}
	if (!mean) Rf_error("ordinal indicators and no mean vector");

	EigenVectorAdaptor Emean(mean);
	EigenMatrixAdaptor Eth(thr);
	Eigen::VectorXd sdTmp(1.0/Ecov.diagonal().array().sqrt());
	Eigen::DiagonalMatrix<double, Eigen::Dynamic> sd(Emean.size());
	sd.setIdentity();
	
	int dx = 0;
	for (auto &th : ti) {
		for (int t1=0; t1 < th.numThresholds; ++t1) {
			double sd1 = sdTmp[th.dColumn];
			out[dx++] = (Eth(t1, th.column) - Emean[th.dColumn]) * sd1;
			sd.diagonal()[th.dColumn] = sd1;
		}
		if (!th.numThresholds) {
			out[dx++] = Emean[th.dColumn];
		}
	}
	
	if (slope) {
		EigenMatrixAdaptor Eslope(slope);
		for (int cx=0; cx < Eslope.cols(); ++cx) {
			for (int rx=0; rx < Eslope.rows(); ++rx) {
				out[dx++] = Eslope(rx,cx);
			}
		}
	}

	Eigen::MatrixXd stdCov(sd * Ecov * sd);

	for (int cx=0; cx < cov->cols; ++cx) {
		if (ti[cx].numThresholds) continue;
		out[dx++] = stdCov(cx,cx);
	}

	for (int cx=0; cx < cov->cols-1; ++cx) {
		for (int rx=cx+1; rx < cov->rows; ++rx) {
			out[dx++] = stdCov(rx,cx);
		}
	}
}