Пример #1
0
/*!
  Computes the first unpolarized moment
  
  \f[
  {\cal O}_{14} = \overline{q} \left[ \gamma_1 
  \stackrel{\displaystyle \leftrightarrow}{D}_4
  +\gamma_4 
  \stackrel{\displaystyle \leftrightarrow}{D}_1
  \right] q
  \f]
  
  with polarized projector
*/
void AlgNuc3pt::calc_EnergyMomentum(const ThreeMom& mom)
{
  OpenFile(); 
  Fprintf(fp,"The next is: Energy momentum k4 + 4k\n");
  CloseFile();
  for ( int n = 0; n < num_qprop; n++ ) {
    for (int i(X);i<4;i++){
      DIR d = DIR(i) ;
      Gamma Gx(d);
      Gamma Gt(T);
      Derivative Der_t(T);
      Derivative Der_x(d);
      
      Nuc3ptStru Xq_xt(mom,Gx, Der_t);
      Xq_xt.Calc3pt(*u_s_prop, *q_prop[n]);
      Xq_xt.Calc3pt(*d_s_prop, *q_prop[n]);
      
      Nuc3ptStru Xq_tx(mom,Gt,Der_x);
      Xq_tx.Calc3pt(*u_s_prop, *q_prop[n]);
      Xq_tx.Calc3pt(*d_s_prop, *q_prop[n]);
      
      Xq_xt += Xq_tx ;
      OpenFile(); 
      Xq_xt.Print(fp) ; 
      CloseFile();
    }
  }
}
Пример #2
0
void		send_players(t_env *env)
{
  int		pos;
  char		tmp[BUF_SIZE];

  pos = env->nb_team;
  while (pos < MAXCLIENT + 5)
    {
      if (env->clt[pos].level && env->clt[pos].state == alive && env->clt[pos].inteam)
	{
	  sprintf(tmp, "pnw %i %i %i %i %i %i\n", env->clt[pos].num_client,
		  env->clt[pos].posx, env->clt[pos].posy, DIR(env->clt[pos].dir),
		  env->clt[pos].level, env->clt[pos].num_team);
	  xsend(env->cs_graphic, tmp, strlen(tmp), "player");
	}
      pos++;
    }
  pos = 0;
  while (pos < MAXCLIENT + 5)
    if (env->clt[pos++].state == inegg)
      {
	sprintf(tmp, "enw %i %i %i %i\n", env->clt[pos - 1].num_client_egg,
		env->clt[pos - 1].num_client, env->clt[pos - 1].posx,
		env->clt[pos - 1].posy);
	xsend(env->cs_graphic, tmp, strlen(tmp), "player");
      }
}
Пример #3
0
void		do_droite(t_env *env, int cs)
{
  env->clt[cs].dir = ((env->clt[cs].dir == 3) ? (0) : (env->clt[cs].dir + 1));
  sprintf(env->clt[cs].buf_write, "ppo %i %i %i %i\n", env->clt[cs].num_client,
	  env->clt[cs].posx, env->clt[cs].posy, DIR(env->clt[cs].dir));
  xsend(env->cs_graphic, env->clt[cs].buf_write, strlen(env->clt[cs].buf_write)
	, "avance");
  xsend(cs, "ok\n", 3, "ok\n");
}
Пример #4
0
void runTree(char* dir="hist_pAu2", char* filter="16142010", unsigned int neventsIn = 0){  
  // If nEvents is negative, reset to the maximum possible value for an Int_t
  if( neventsIn <= 0 ) neventsIn = 1<<31-1;

  TSystemDirectory DIR(dir, dir);
  TList *files = DIR.GetListOfFiles();
  TChain* trees = new TChain();
  int nfile=0;
  if (files) {
      TSystemFile *file;
      TString fname;
      TIter next(files);
      while ((file=(TSystemFile*)next())) {
	  fname = file->GetName();
	  if (!file->IsDirectory() && fname.BeginsWith(filter) && fname.EndsWith("tree.root")) {
	      cout << Form("Adding %s/%s to TChain",dir,fname.Data())<<endl;
	      trees->AddFile(Form("%s/%s/dipi0",dir,fname.Data()));
	      nfile++;
	  }
      }
  }
  cout << Form("%d files added",nfile) << endl;

  // load the shared libraries
  std::cout << "***** Loading libraries *****" << endl;
  LoadLibs();

  // Create the analysis chain
  analysisChain = new StChain("dipi0Chain");
  
  //cout << "Constructing StFmsDbMaker" << endl;
  //StFmsDbMaker* fmsDbMkr = new StFmsDbMaker( "fmsDb" );
  //fmsDbMkrName = fgtDbMkr->GetName();

  gSystem->Load("StFmsDiPi0");
  StFmsDiPi0* dipi0=new StFmsDiPi0;
  TString filenameDiPi0(Form("%s/%s.dipi0.root",dir,filter));
  cout << "DiPi0 outfile name = " << filenameDiPi0.Data()<<endl;
  dipi0->setFileName(filenameDiPi0.Data());
  dipi0->setReadTree(trees);

  analysisChain->Init();

  Int_t ierr  = kStOK;  // err flag
  Int_t nevents = 0;    // cumulative number of events in
  for( ; nevents < neventsIn && !ierr; ++nevents ){
    if(nevents%10000==0) cout <<"event: "<< nevents <<endl;
    analysisChain->Clear();
    ierr = analysisChain->Make();
  } 
  analysisChain->Finish(); 

  analysisChain->Delete();
  return;
};
Пример #5
0
void THMapParcelsOverlay::drawCell(THRenderTarget* pCanvas, int iCanvasX,
                                   int iCanvasY, const THMap* pMap, int iNodeX,
                                   int iNodeY)
{
    const THMapNode *pNode = pMap->getNode(iNodeX, iNodeY);
    if(!pNode)
        return;
    if(m_pFont)
        _drawText(pCanvas, iCanvasX, iCanvasY, "%i", (int)pNode->iParcelId);
    if(m_pSprites)
    {
        uint16_t iParcel = pNode->iParcelId;
#define DIR(dx, dy, sprite) \
        pNode = pMap->getNode(iNodeX + dx, iNodeY + dy); \
        if(!pNode || pNode->iParcelId != iParcel) \
            m_pSprites->drawSprite(pCanvas, sprite, iCanvasX, iCanvasY, 0)
        DIR( 0, -1, 18);
        DIR( 1,  0, 19);
        DIR( 0,  1, 20);
        DIR(-1,  0, 21);
#undef DIR
    }
}
Пример #6
0
void map_parcels_overlay::draw_cell(render_target* pCanvas, int iCanvasX,
                                   int iCanvasY, const level_map* pMap, int iNodeX,
                                   int iNodeY)
{
    const map_tile *pNode = pMap->get_tile(iNodeX, iNodeY);
    if(!pNode)
        return;
    if(font)
        draw_text(pCanvas, iCanvasX, iCanvasY, std::to_string((int)pNode->iParcelId));
    if(sprites)
    {
        uint16_t iParcel = pNode->iParcelId;
#define DIR(dx, dy, sprite) \
        pNode = pMap->get_tile(iNodeX + dx, iNodeY + dy); \
        if(!pNode || pNode->iParcelId != iParcel) \
            sprites->draw_sprite(pCanvas, sprite, iCanvasX, iCanvasY, 0)
        DIR( 0, -1, 18);
        DIR( 1,  0, 19);
        DIR( 0,  1, 20);
        DIR(-1,  0, 21);
#undef DIR
    }
}
Пример #7
0
/*!
  Computes the conserved vector current using the
  \f[
  {\cal O}_\mu = \overline{q} \gamma_\mu q
  \f]
  
  all possible mometa are inserted
*/
void AlgNuc3pt::calc_Cons_Vector(int Nmom, ThreeMom* mom)
{     
  Gamma Gt(T);
  Nuc3ptCons VectCurr(Gt);
  const int MaxNmom=50;
  if(Nmom>MaxNmom)
    ERR.General(cname,"calc_Cons_Vector","Nmom(%d)>MaxNmom(%d)",Nmom,MaxNmom);
  Nuc3ptCons *VectCurrp[MaxNmom][4];
  for(int ip(0);ip<Nmom;ip++) for (int i(X);i<4;i++){
      DIR d = DIR(i) ;
      Gamma G(d);
      VectCurrp[ip][i] = new Nuc3ptCons(mom[ip],G) ;
    }
  
  for ( int n = 0; n < num_qprop; n++ ) {
    QPropW* quark = new QPropWGaussSrc(*q_prop[n]);
    
    VectCurr.Calc3pt(*u_s_prop,*quark);
    for(int ip(0);ip<Nmom;ip++) 
      for (int i(X);i<4;i++)
	VectCurrp[ip][i]->Calc3pt(*u_s_prop,*quark);
    
    u_s_prop->DeleteQPropLs();
    
    if(Nuc3pt_arg->DoConserved == 1) {
      char dummy[30];
      d_s_prop->RestoreQPropLs_ftom(dummy);
    }
    
    VectCurr.Calc3pt(*d_s_prop,*quark);
    for(int ip(0);ip<Nmom;ip++) for (int i(X);i<4;i++)
				  VectCurrp[ip][i]->Calc3pt(*d_s_prop,*quark);
    
    d_s_prop->DeleteQPropLs();
    
    OpenFile(); 
    VectCurr.Print(fp) ;
    for(int ip(0);ip<Nmom;ip++) for (int i(X);i<4;i++)
				  VectCurrp[ip][i]->Print(fp) ;
    CloseFile();
    
    delete quark;
  }

  for(int ip(0);ip<Nmom;ip++) 
    for (int i(X);i<4;i++)
      delete VectCurrp[ip][i];

}
Пример #8
0
/*!
  Computes the vector current using the
  \f[
  {\cal O}_\mu = \overline{q} \gamma_\mu q
  \f]
  
  all possible mometa are inserted
*/
void AlgNuc3pt::calc_Vector(const ThreeMom& q)
{     
  for (int i(X);i<4;i++){
    for ( int n = 0; n < num_qprop; n++ ) {
      DIR d = DIR(i) ;
      Gamma G(d);
      Nuc3ptGamma VectCurr(q,G) ;
      VectCurr.Calc3pt(*u_s_prop,*q_prop[n]);
      VectCurr.Calc3pt(*d_s_prop,*q_prop[n]);
      OpenFile(); 
      VectCurr.Print(fp) ;
      CloseFile();
    }
  }
}
Пример #9
0
/*!
  Computes the Axial vector current using the
  \f[
  {\cal O}_{5\mu} = i \overline{q} \gamma_5 \gamma_\mu q
  \f]  

  all possible mometa are inserted
*/
void AlgNuc3pt::calc_Axial(const ThreeMom& q)
{ 
  for ( int n = 0; n < num_qprop; n++ ) {
    for (int i(X);i<4;i++){
      DIR d = DIR(i) ;
      Gamma G5d(G5,d);
      Nuc3ptGamma AxialCurr(q,Complex(0.0,1.0),G5d) ;
      AxialCurr.Calc3pt(*u_s_prop,*q_prop[n]);
      AxialCurr.Calc3pt(*d_s_prop,*q_prop[n]);
      
      OpenFile();
    AxialCurr.Print(fp) ;
    CloseFile();
    }
  }
}
Пример #10
0
void add_node(node **root, int data, node *parent)
{
	if (NULL != *root)
	{
		parent = *root;
		add_node(&((*root)->link[DIR(data,(*root)->data)]), data, parent);
	}
	else
	{
		*root = create_node(data, parent);
     #ifdef HEAPSORT
      /* Created node, re-arrange it in the tree such that it is
		   smaller than its parent. If normalizing, then tree is used
		   used in heapsort. If normalizing is skipped, it is a regular
		   binary tree. */
		normalize_tree(*root);
     #endif /* HEAPSORT */  
	}
}
Пример #11
0
void            R_SUB()
{
  static FTYPE    SYN_STATE[NP];/* synthesis filter state */
  static FTYPE    POST_STATE_N[NP];	/* post-filter numerator state */
  static FTYPE    POST_STATE_D[NP];	/* post-filter denominator state */
  static FTYPE    POST_STATE_E;	/* post-emphasis filter state */
  static FTYPE    runningGain;	/* post-filter agc gain applied on 
                                 * sample-by-sample basis */
  FTYPE           beta;		/* pitch excitation gain */
  FTYPE           preEnergy;	/* energy before filter (both agc's) */
  FTYPE           postEnergy;	/* energy after filter (both agc's) */
  FTYPE           gain;		/* post-filter agc gain for subframe */
  int             R_LAG;	/* received lag */
  int             R_CODE;	/* received codeword for 1st codebook */
  int             R_CODE_A;	/* received codeword for 2nd codebook */
  int             R_GSP0;	/* received GSP0(P1) centroid */

  FTYPE          *tmpPtr, *tmpPtr2, *endPtr, temp1, temp2;

  /* retrieve codes from code buffer */
  if (*codes)
    R_LAG = *codes + LMIN - 1;
  else
    R_LAG = 0;
  codes++;
  R_CODE = *codes;
  codes++;
  R_CODE_A = *codes;
  codes++;
  R_GSP0 = *codes;
  codes++;

  /* construct pitch vector */
  if (R_LAG)
    P_EX(P_VEC, R_P_STATE, R_LAG);

  /* construct 1st-codebook excitation */
  B_CON(R_CODE, C_BITS, BITS);
  V_CON(BASIS, BITS, C_BITS, X_VEC);

  /* construct 2nd-codebook excitation */
  B_CON(R_CODE_A, C_BITS_A, BITS);
  V_CON(BASIS_A, BITS, C_BITS_A, X_A_VEC);

  /* if there is a pitch vector, get sqrt(rs/energy in pitch) */
  if (R_LAG)
    RS00 = RS_RR(P_VEC, RS);

  /* get sqrt(rs/energy in 1st-codebook excitation) */
  RS11 = RS_RR(X_VEC, RS);

  /* get sqrt(rs/energy in 2nd-codebook excitation) */
  RS22 = RS_RR(X_A_VEC, RS);

  /* scale and combine excitations, put result in T_VEC */
  beta = EXCITE(R_GSP0, R_LAG, RS00, RS11, RS22, P_VEC, X_VEC, X_A_VEC, T_VEC);

  /* perform one subframe's worth of delay on R_P_STATE */
  tmpPtr = R_P_STATE;
  tmpPtr2 = R_P_STATE + S_LEN;
  for (endPtr = R_P_STATE + LMAX; tmpPtr2 < endPtr; tmpPtr2++, tmpPtr++)
    *tmpPtr = *tmpPtr2;

  /* update the last subframe's worth of data in R_P_STATE with excitation */
  tmpPtr2 = T_VEC;
  for (; tmpPtr < endPtr; tmpPtr++, tmpPtr2++)
    *tmpPtr = *tmpPtr2;

  /* synthesize speech and put in output buffer */
  DIR(T_VEC, outBuf, SYN_STATE, COEF, S_LEN);

  /* adaptive postfilter */
  /* compute original energy in output speech for agc */
  preEnergy = 0.0;
  tmpPtr = outBuf;
  for (endPtr = tmpPtr + S_LEN; tmpPtr < endPtr; tmpPtr++)
    preEnergy += *tmpPtr * *tmpPtr;

  if (apply_postfilter)
  {
    /* implement spectral postfilter  */
        I_DIR(outBuf, outBuf, POST_STATE_N, N_COEF, S_LEN);
    DIR(outBuf, outBuf, POST_STATE_D, W_COEF, S_LEN);

    /* first order emphasis filter (boosts high frequencies)  */
        tmpPtr = outBuf;
    tmpPtr2 = tmpPtr;
    temp1 = *tmpPtr - POST_EMPH * POST_STATE_E;
    tmpPtr++;
    for (endPtr = outBuf + S_LEN; tmpPtr < endPtr; tmpPtr++, tmpPtr2++)
    {
      temp2 = *tmpPtr - POST_EMPH * *tmpPtr2;
      *tmpPtr2 = temp1;
      temp1 = temp2;
    }
    POST_STATE_E = *tmpPtr2;
    *tmpPtr2 = temp1;

    /* compute energy in post-filtered speech, compute new gain, scale */
    /* speech, and leave in outBuf */
        postEnergy = 0.0;
    tmpPtr = outBuf;
    for (endPtr = tmpPtr + S_LEN; tmpPtr < endPtr; tmpPtr++)
      postEnergy += *tmpPtr * *tmpPtr;

    gain = (postEnergy == 0.0) ? 0.0 : sqrt(preEnergy / postEnergy);

    temp1 = 1.0 - POST_AGC_COEF;
    tmpPtr = outBuf;
    for (endPtr = tmpPtr + S_LEN; tmpPtr < endPtr; tmpPtr++)
    {
      runningGain = gain * temp1 + runningGain * POST_AGC_COEF;
      *tmpPtr *= runningGain;
    }
  }
}
Пример #12
0
//------------------------------------------------------------------
//
//------------------------------------------------------------------
void AlgNuc3pt::run()
{
  char *fname = "run()";
  VRB.Func(cname,fname);

  if( Nuc3pt_arg->DoHalfFermion == 2 && Nuc3pt_arg->DoConserved == 1 ) {
    ERR.General(cname,fname,"DoConserved should be 2 when DoHalfFermion = 2!!!\n");
  }

  // Always do point sink...
  Nuc2pt Nuc_c5(NUC_G5C,POINT) ;
  // do a few mesons for kicks
  Meson pion;
  pion.setGamma(-5);
  Meson vector[3];
  vector[0].setGamma(0);
  vector[1].setGamma(1);
  vector[2].setGamma(2);
  char *MesonSrcTag ;
  switch (Nuc3pt_arg->src_type){
  case  POINT:
    MesonSrcTag = "POINT" ;
    break; 
  case  BOX:
    MesonSrcTag = "GFBOX" ;
    break; 
  case  GAUSS_GAUGE_INV:
    MesonSrcTag = "GSmear" ;
    break; 
  default: // It should  never get here! 
    MesonSrcTag = "" ;// make GCC happy!
    ERR.General(cname,fname,"OOPS!!!\n");
    break ;
  }
  pion.setSrc(MesonSrcTag);
  vector[0].setSrc(MesonSrcTag);
  vector[1].setSrc(MesonSrcTag);
  vector[2].setSrc(MesonSrcTag);

  int ZeroMom[3] ;
  ZeroMom[0]=ZeroMom[1]=ZeroMom[2]=0 ;
  
  ProjectType ptype[4] ;
  ptype[0] = PPAR_5X ;
  ptype[1] = PPAR_5Y ;
  ptype[2] = PPAR_5Z ;
  ptype[3] = PPAR_5  ;


  OpenFile();
  Fprintf(fp,"List of momenta:\n");
  int Nmom(56) ;
  ThreeMom sink_mom[56] ;
  int count(0);
  for(int p1=-2;p1<3;p1++)
    for(int p2=-2;p2<3;p2++)
      for(int p3=-2;p3<3;p3++)
	if((p1*p1+p2*p2+p3*p3)<=Nuc3pt_arg->MaxMom2)
	  if((p1*p1+p2*p2+p3*p3)!=0)// eliminate the p=0
	    {
	      Fprintf(fp,"\t\t\t%i: %i %i %i\n",count,p1,p2,p3);
	      sink_mom[count] = ThreeMom(p1,p2,p3);
	      count++ ;
	    }
  CloseFile();
  if(count>56)
    ERR.General(cname,fname,"No of momenta > 56\n");

  //set the number of momenta
  Nmom=count ; 
  // non-zero momentum give bad signal with BOX sources...
  // do not ever do it!!
  if( Nuc3pt_arg->src_type == BOX && (Nuc3pt_arg->BoxEnd - Nuc3pt_arg->BoxStart) != GJP.Xnodes()*GJP.XnodeSites()-1)  Nmom=0 ; 

  Float qmass(Nuc3pt_arg->Mass(0)) ;
  // Loop over source times
  OpenFile();
  Fprintf(fp,"Doing quark Mass: %g\n", qmass); 
  Fprintf(fp,"Doing %d sources inc= %d\n", 
	  Nuc3pt_arg->num_src, Nuc3pt_arg->source_inc); 
  CloseFile();


  // start: ts=t_source, then increment by "source_inc"
  int ts=Nuc3pt_arg->t_source;
  int mt[5];
  
  if ( Nuc3pt_arg->num_mult > 1) ts=Nuc3pt_arg->mt[0]; // use the t_source, source_inc counter if not doing MultGauss. -MFL

  for(int i_source=0; i_source < Nuc3pt_arg->num_src; i_source++)
    {
      int t_sink = (ts + Nuc3pt_arg->t_sink)%(GJP.Tnodes()*GJP.TnodeSites());
      OpenFile();
      Fprintf(fp,"Doing source/sink time slices: %d %d\n", ts, t_sink);
      CloseFile();

      // First calculate the needed two point functions
      Nuc_c5.Zero() ;
      pion.Zero() ;
      vector[0].Zero() ;
      vector[1].Zero() ;
      vector[2].Zero() ;
      char out_prop[200];

      // If we don't do the coherent sink, we only allocate 1 propagator
      // hence we reuse the memory for the propagator for different source locations.
      // Otherwise we need to have all the propagators present at the same time
      // -- MFL
      int n;
      if (Nuc3pt_arg->num_src == num_qprop) n = i_source;
      else n = 0;

      GetThePropagator(n, ts, qmass);

	Nuc_c5.calcNucleon(*q_prop[n]) ;
	pion.setMass(qmass,qmass) ;
	pion.calcMeson(*q_prop[n],*q_prop[n]) ;
	vector[0].setMass(qmass,qmass) ;
	vector[0].calcMeson(*q_prop[n],*q_prop[n]) ;
	vector[1].setMass(qmass,qmass) ;
	vector[1].calcMeson(*q_prop[n],*q_prop[n]) ;
	vector[2].setMass(qmass,qmass) ;
	vector[2].calcMeson(*q_prop[n],*q_prop[n]) ;

	// Print out 2pt function results
	//----------------------------------------------------------------
	OpenFile();
	Nuc_c5.Print(fp) ;
	pion.Print(fp) ;
	vector[0].Print(fp) ;
	vector[1].Print(fp) ;
	vector[2].Print(fp) ;
	CloseFile();
	
	//Do the projections needed for disconnected Ga
	for(int p(0);p<4;p++)
	  {
	    Nuc2pt Nuc_c5_p(NUC_G5C,POINT,ptype[p]) ;
//	    Nuc_c5_p.Zero();
	    
	    if(Nuc3pt_arg->DoGa1Proj||(p>2))
	      {
		Nuc_c5_p.calcNucleon(*q_prop[n]) ;
		
		OpenFile();
		Nuc_c5_p.Print(fp) ;
		CloseFile();
	      }
	    
	  }
	
	//do some non-zero momenta
	{
	  Nuc2pt Nuc_c5_p(NUC_G5C,POINT,PPAR_5) ;
	  for(int m(0);m<Nmom;m++)
	    {
	      
	      Nuc_c5.Zero() ;
	      Nuc_c5.calcMomNucleon(*q_prop[n],sink_mom[m]) ;
	      // Print out 2pt function results
	      //----------------------------------------------------------------
	      OpenFile();
	      Nuc_c5.Print(fp) ;
	      CloseFile();
	      
	      // Calculate the smeared smeared momentum two point function
	      // to extract alpha for  NEDM reweighting	    
	      Nuc_c5_p.Zero() ;
	      Nuc_c5_p.calcMomNucleon(*q_prop[n],sink_mom[m]) ;
	      // Print out 2pt function result
	      //----------------------------------------------------------------
	      OpenFile();
	      Nuc_c5_p.Print(fp) ;
	      CloseFile();


	    }// End momentum
	}

	//Do the smeared sink stuff
	if((Nuc3pt_arg->src_type==GAUSS_GAUGE_INV)&&(Nuc3pt_arg->DoSS2ptF)){
	  
	  Nuc2pt Nuc_c5_ss(NUC_G5C,GAUSS_GAUGE_INV) ;
	  
	  QPropWGaussSrc smr(*q_prop[n]) ;
	  QPropWGaussArg gauss_arg = q_prop[n]->GaussArg();
	  smr.GaussSmearSinkProp(gauss_arg);
	  
	  // First calculate the needed two point functions
	  Nuc_c5_ss.Zero() ;
	  Nuc_c5_ss.calcNucleon(smr) ;
	  
	  pion.Zero() ;
	  pion.calcMeson(smr,smr) ;
	  
	  
	  // Print out 2pt function results
	  //----------------------------------------------------------------
	  OpenFile();
	  Nuc_c5_ss.Print(fp) ;
	  pion.Print(fp) ;
	  CloseFile();
	  
	  //Do the projections needed for disconnected Ga
	  for(int p(0);p<4;p++)
	    {
	      Nuc2pt Nuc_c5_ss_p(NUC_G5C,GAUSS_GAUGE_INV,ptype[p]) ;
	      if(Nuc3pt_arg->DoGa1Proj||(p>2)){
		Nuc_c5_ss_p.calcNucleon(smr) ;
		OpenFile();
		Nuc_c5_ss_p.Print(fp) ;
		CloseFile();
	      }
	    }
	  
	  //do some non-zero momenta
	  {
	    Nuc2pt Nuc_c5_ss_p(NUC_G5C,GAUSS_GAUGE_INV,PPAR_5) ;
	    for(int m(0);m<Nmom;m++)
	      {
		Nuc_c5_ss.Zero() ;
		Nuc_c5_ss.calcMomNucleon(smr,sink_mom[m]) ;
		// Print out 2pt function results
		//----------------------------------------------------------------
		OpenFile();
		Nuc_c5_ss.Print(fp) ;
		CloseFile();
		
		// Calculate the smeared smeared momentum two point function
		// to extract alpha for  NEDM reweighting
		Nuc_c5_ss_p.Zero() ;
		Nuc_c5_ss_p.calcMomNucleon(smr,sink_mom[m]) ;
		// Print out 2pt function results
		//----------------------------------------------------------------
		OpenFile();
		Nuc_c5_ss_p.Print(fp) ;
		CloseFile();
	      }// End momentum
	    
	    
	    if(Nuc3pt_arg->DoHalfFermion == 2) {
	      OpenFile();
	      Fprintf(fp,"DoHalfFermion=%d non-rel nucleon 2-pt\n",Nuc3pt_arg->DoHalfFermion);
	      CloseFile();
	      
	      q_prop[n]->NonRelProp( 1 );
	      
	      {
		Nuc2pt Nuc_c5_p_nr(NUC_G5C,POINT) ;
		Nuc_c5_p_nr.Zero() ;
		Nuc_c5_p_nr.calcNucleon(*q_prop[n]) ;
		OpenFile();
		Nuc_c5_p_nr.Print(fp) ;
		CloseFile();
		
		for(int m(0);m<Nmom;m++) {
		  Nuc_c5_p_nr.Zero() ;
		  Nuc_c5_p_nr.calcMomNucleon(*q_prop[n],sink_mom[m]) ;
		  OpenFile();
		  Nuc_c5_p_nr.Print(fp);
		  CloseFile();
		}
	      }
	      
	      smr.NonRelProp( 0 );
	      
	      int dohalf = Nuc3pt_arg->DoHalfFermion;
	      // First calculate the needed two point functions
	      {
		Nuc2pt Nuc_c5_g_nr(NUC_G5C,GAUSS_GAUGE_INV) ;
		Nuc_c5_g_nr.Zero() ;
		Nuc_c5_g_nr.calcNucleon(smr) ;
		
		// Print out 2pt function results
		//----------------------------------------------------------------
		OpenFile();
		Nuc_c5_g_nr.Print(fp) ;
		CloseFile();
		
		//do some non-zero momenta
		for(int m(0);m<Nmom;m++)
		  {
		    Nuc_c5_g_nr.Zero() ;
		    Nuc_c5_g_nr.calcMomNucleon(smr,sink_mom[m]) ;
		    // Print out 2pt function results
		    //----------------------------------------------------------------
		    OpenFile();
		    Nuc_c5_g_nr.Print(fp) ;
		    CloseFile();
		  }// End momentum
	      }
	    } // DoHalfF = 2
 //         } // End loop over qprop
	  
	  // Finally, smear the sink at time t_sink for 3-pt functions (below) 
	  for(int nt=0; nt<Nuc3pt_arg->num_mult; nt++){
	    // Multi Gauss t_sink set
	    mt[nt]=Nuc3pt_arg->mt[nt]; //save
	    Nuc3pt_arg->mt[nt]+=Nuc3pt_arg->t_sink; // locations of the proton sinks
            Nuc3pt_arg->mt[nt]=Nuc3pt_arg->mt[nt]%(GJP.Tnodes()*GJP.TnodeSites());
	    q_prop[n]->GaussSmearSinkProp(Nuc3pt_arg->mt[nt],q_prop[n]->GaussArg());
          }
	  
	} //end smeared sink
      }


      //Now do the 3pt functions

      // If doing coherent sinks, don't calculate the 3pt functions until all the 
      // forward propagators have been calculated. --MFL
      int do_seq = 0;
//      int t_sink;

      if(Nuc3pt_arg->calc_seqQ != MULT_SEQ 
	&& Nuc3pt_arg->calc_seqQ != WRITE_MULT_SEQ 
	&& Nuc3pt_arg->calc_seqQ != READ_MULT_SEQ) {
	do_seq = 1;
        t_sink = ts + Nuc3pt_arg->t_sink;
      }
      // once all the forward propagators have been calculated,
      // do the sequential propagaotrs. --MFL
      else if (i_source == num_qprop-1) {
	do_seq = 1;
	t_sink = Nuc3pt_arg->t_source + Nuc3pt_arg->t_sink;
      }


      if(Nuc3pt_arg->DoUnPolarized && do_seq)
	{
	  // for conserved vector currents
	  Gamma Gt(T);
	  Nuc3ptCons VectCurr(Gt);
	  Nuc3ptCons *VectCurrp[4];
	  if(Nuc3pt_arg->DoConserved) {
	  for (int i(X);i<4;i++){
	    DIR d = DIR(i) ;
	    Gamma G(d);
	    VectCurrp[i] = new Nuc3ptCons(Nmom,G) ;
	  }
	  }

	  OpenFile();
	  Fprintf(fp,"UnPolarized Zero mom.\n");
	  CloseFile();

  	  //first do the zero momentum un-polarized stuff

	  //up-quark
	  GetTheSeqPropagator(t_sink,qmass,
			      PROT_U_SEQ,ZeroMom,PPAR);

	  //down-quark
	  GetTheSeqPropagator(t_sink,qmass,
			      PROT_D_SEQ,ZeroMom,PPAR);

	  calc_Scalar();         //needed for the sigma term
	  calc_Vector();	 //Vector current
	  calc_X_q_b();          //<x>_q (b) does not need non-zero momentum
	  for(int i(0) ; i<Nmom ; i++) calc_Vector(sink_mom[i]);

	  //conserved current
	  if(Nuc3pt_arg->DoConserved) {
	    if(GJP.Snodes()==2) u_s_prop->SwapQPropLs();

	    for ( int nt = 0; nt < num_qprop; nt++ ) {
	      VectCurr.Calc3pt(*u_s_prop,*q_prop[nt]);
	      for (int i(X);i<4;i++)
		VectCurrp[i]->Calc3pt(*u_s_prop,*q_prop[nt],Nmom,sink_mom);
	    }
	    char* dummy;
	    u_s_prop->RestoreOrgProp(dummy,1);
	    u_s_prop->DeleteQPropLs();

	    if(GJP.Snodes()==2) d_s_prop->SwapQPropLs();
	    
	    for ( int nt = 0; nt < num_qprop; nt++ ) {
	      VectCurr.Calc3pt(*d_s_prop,*q_prop[nt]);
	      for (int i(X);i<4;i++)
	      VectCurrp[i]->Calc3pt(*d_s_prop,*q_prop[nt],Nmom,sink_mom);
	    }
	    
	    d_s_prop->RestoreOrgProp(dummy,1);
	    d_s_prop->DeleteQPropLs();

	    OpenFile();
	    Fprintf(fp,"UnPolarized Zero mom Conserved Vector\n");
	    VectCurr.Print(fp) ;
	    for (int i(X);i<4;i++)
	      VectCurrp[i]->Print(fp,Nmom,sink_mom) ;
	    CloseFile();
	  }

	  if(Nuc3pt_arg->DoConserved) {
	  for (int i(X);i<4;i++)
	    delete VectCurrp[i];
	  }
	}

      if(Nuc3pt_arg->DoUnPolarizedMom && do_seq)
	{
	  OpenFile();
	  Fprintf(fp,"UnPolarized mom.\n");
	  CloseFile();
	  int UnitMom[3];
	  UnitMom[1]=1 ; // check the conventions
	  UnitMom[0]=UnitMom[2]=0 ;
	  
	  //up-quark
	  GetTheSeqPropagator(t_sink,qmass,
			      PROT_U_SEQ,UnitMom,PPAR);
	  //down-quark
	  GetTheSeqPropagator(t_sink,qmass,
			      PROT_D_SEQ,UnitMom,PPAR);

	  calc_Scalar();         //needed for the sigma term
	  calc_Vector();	 //Vector current
	  calc_X_q_b();          //<x>_q (b) does not need non-zero momentum
	  for(int i(0) ; i<Nmom ; i++) calc_Vector(sink_mom[i]);

	  calc_X_q_a(); //<x>_q (a) needs non-zero momentum
	  calc_X2_q(); //<x^2>_q    needs non-zero momentum
	  calc_X3_q(); //<x^3>_q    needs non-zero momentum

	}

      // Polarized 
      if(Nuc3pt_arg->DoPolarized && do_seq)
	{
	  // for conserved axial and vector currents
	  Gamma G5z(G5,Z);
	  Nuc3ptCons AxialCurr(Complex(0.0,1.0),G5z);
	  Nuc3ptCons *AxialCurrp[4];
	  Nuc3ptCons *VectCurrp[4];
	  if(Nuc3pt_arg->DoConserved) {
	  for (int i(X);i<4;i++){
	    DIR d = DIR(i);
	    Gamma G5d(G5,d);
	    AxialCurrp[i] = new Nuc3ptCons(Nmom,Complex(0.0,1.0),G5d);

	    d = DIR(i) ;
	    Gamma G(d);
	    VectCurrp[i] = new Nuc3ptCons(Nmom,G) ;
	  }
	  }

	  OpenFile();
	  Fprintf(fp,"Polarized Zero mom.\n");
	  CloseFile();
	  //
	  //up-quark
	  GetTheSeqPropagator(t_sink,qmass,
			      PROT_U_SEQ,ZeroMom,PPAR_5Z);

	  //down-quark
	  GetTheSeqPropagator(t_sink,qmass,
			      PROT_D_SEQ,ZeroMom,PPAR_5Z);
	  
	  calc_Axial(); //Axial-Vector current i Gamma_5 Gamma_z
	  calc_Tensor() ;//Tensor current i Gamma_5 Gamma_z Gamma_t
	  calc_X_Dq_b() ; 
	  calc_d1() ;
	  
	  for(int i(0) ; i<Nmom ; i++){
	    calc_Vector(sink_mom[i]);//neutron EDM and mangetic moment
	    calc_Axial(sink_mom[i]);//axial form factors
	    calc_EnergyMomentum(sink_mom[i]) ; // proton spin
	    calc_PScalar(sink_mom[i]);//pseudoscalar form factors
	  }

	  if(Nuc3pt_arg->DoConserved) {

	    if(GJP.Snodes()==2) {
	      u_s_prop->SwapQPropLs();
	      d_s_prop->SwapQPropLs();
	    }

	    for ( int nt = 0; nt < num_qprop; nt++ ) {

	      AxialCurr.Calc3pt(*u_s_prop,*q_prop[nt]);
	      for(int i(X);i<4;i++){
		AxialCurrp[i]->Calc3pt(*u_s_prop,*q_prop[nt],Nmom,sink_mom);
		VectCurrp[i]->Calc3pt(*u_s_prop,*q_prop[nt],Nmom,sink_mom);
	      }
	      
	      AxialCurr.Calc3pt(*d_s_prop,*q_prop[nt]);
	      for(int i(X);i<4;i++){
		AxialCurrp[i]->Calc3pt(*d_s_prop,*q_prop[nt],Nmom,sink_mom);
		VectCurrp[i]->Calc3pt(*d_s_prop,*q_prop[nt],Nmom,sink_mom);
	      }

	      OpenFile();
	      Fprintf(fp,"Polarized Zero mom Conserved Axial and Vector\n");
	      AxialCurr.Print(fp) ;
	      for (int i(X);i<4;i++) {
		VectCurrp[i]->Print(fp,Nmom,sink_mom) ;
	      }
	      for (int i(X);i<4;i++) {
		AxialCurrp[i]->Print(fp,Nmom,sink_mom) ;
	      }
	      CloseFile();
	    }
	    
	    char* dummy;
	    u_s_prop->RestoreOrgProp(dummy,1);
	    u_s_prop->DeleteQPropLs();
	    d_s_prop->RestoreOrgProp(dummy,1);
	    d_s_prop->DeleteQPropLs();
	  }
	  	  
	  if(Nuc3pt_arg->DoConserved) {
	    for(int i(X);i<4;i++) {
	      delete AxialCurrp[i];
	      delete VectCurrp[i];
	    }
	  }
	}

      
      if(Nuc3pt_arg->DoPolarizedMom && do_seq)
	{
	  OpenFile();
	  Fprintf(fp,"Polarized with mom.\n");
	  CloseFile();
	  int UnitMom[3];
	  UnitMom[1]=1 ; // check the conventions
	  UnitMom[0]=UnitMom[2]=0 ;
	  
	  //up-quark
	  GetTheSeqPropagator(t_sink,qmass,
			      PROT_U_SEQ,UnitMom,PPAR_5Z);
	  //down-quark
	  GetTheSeqPropagator(t_sink,qmass,
			      PROT_D_SEQ,UnitMom,PPAR_5Z);
	  
	  for(int i(0) ; i<Nmom ; i++){
	    calc_Vector(sink_mom[i]);//neutron EDM and magnetic moment
	    calc_Axial(sink_mom[i]);//axial form factors
	    calc_EnergyMomentum(sink_mom[i]) ; // proton spin
	  }
	  calc_X_Dq_a() ;
	  calc_X2_Dq() ;
	  calc_X_dq() ;
	  calc_d2() ;
	}

      if(Nuc3pt_arg->DoConserved) q_prop[n]->DeleteQPropLs();

      ts+=Nuc3pt_arg->source_inc;
      for(int nt=0; nt<Nuc3pt_arg->num_mult; nt++){
	Nuc3pt_arg->mt[nt]=mt[nt];
	Nuc3pt_arg->mt[nt]+=Nuc3pt_arg->source_inc;
      }

/*
      if(i_source==1){ // obsolete. commented out  --MFL
	ts+=Nuc3pt_arg->mt[4];
	for(int nt=0; nt<Nuc3pt_arg->num_mult; nt++){
	  Nuc3pt_arg->mt[nt]+=Nuc3pt_arg->mt[4];
	}
      }
*/
    } // end loop over source timeslices
} // end run