Old/ShadabCorr/corr2dc.c
//function to define the sampling and the bin
function to define the sampling and the bin
function to define the sampling and the bin
int find_bin(double *axyz, double *bxyz, int samp, int *nsamp, double *sampbound, 
      int los, int pbc, double *blen,int *rx, int *ry) {
   double difxyz[3], difmag=0, difDOTlos=0;
   double losxyz[3], losmag=0;
   double xsep=0,ysep=0, xcoord=0, ycoord=0;
   int ii;
   if (los==0 || los==2 || los==3) {
      for (ii=0;ii<3;ii++){
         difxyz[ii]=axyz[ii]-bxyz[ii];
	 if(los==0) losxyz[ii]=0.5*(axyz[ii]+bxyz[ii]); 
	 else if(los==2) losxyz[ii]=axyz[ii];
	 else losxyz[ii]=bxyz[ii]; 
         losmag=losmag+losxyz[ii]*losxyz[ii];
         difmag=difmag+difxyz[ii]*difxyz[ii];
         difDOTlos=difDOTlos+difxyz[ii]*losxyz[ii];
      }
      difmag=sqrt(difmag);
      losmag=sqrt(losmag);
      ycoord=difDOTlos/losmag;  
      xcoord=sqrt(difmag*difmag-ycoord*ycoord);
   }
   else if(los==1) {
      for (ii=0;ii<3;ii++)
         difxyz[ii]=axyz[ii]-bxyz[ii];
      if(pbc==1) { 
	 relwrap(difxyz, blen); 
      }
      ycoord=difxyz[2];
      xcoord=sqrt(difxyz[0]*difxyz[0]+difxyz[1]*difxyz[1]);
   }
   if(samp==0) { 
      xsep=sqrt(xcoord*xcoord+ycoord*ycoord);
      ysep=fabs(ycoord/xsep); 
   }
   else if (samp==1) { 
      ysep=ycoord;
      xsep=xcoord;
   }
   else if (samp==2) { 
      xsep=sqrt(xcoord*xcoord+ycoord*ycoord);
      ysep=acos(ycoord/xsep);
   }
   else if (samp==3) { 
      ysep=ycoord;
      xsep=log10(xcoord);
   }
   else if (samp==4) { 
      xsep=sqrt(xcoord*xcoord+ycoord*ycoord);
      ysep=acos(ycoord/xsep);
      xsep=log10(xsep);
   }
   else {
      printf("\ninvalid sampling mode %d\n",samp);
      exit(0);
   }
   if(xsep > sampbound[0] && xsep < sampbound[1] && ysep >sampbound[2] && ysep <sampbound[3])
   {
      int xbin_n = floor((xsep-sampbound[0])*nsamp[0]/(sampbound[1]-sampbound[0]));
      int ybin_n = floor((ysep-sampbound[2])*nsamp[1]/(sampbound[3]-sampbound[2]));
      if(xbin_n == nsamp[0]) xbin_n -= 1;
      if(ybin_n == nsamp[1]) ybin_n -= 1;
      *rx=xbin_n;
      *ry=ybin_n;
      return 0;
   }
   else {
      *rx=-1;
      *ry=-1;
      return -1;
   }
   return -1;
}
int find_bin ( double * axyz , double * bxyz , int samp , int * nsamp , double * sampbound , int los , int pbc , double * blen , int * rx , int * ry ) { double difxyz [ 3 ] , difmag = 0 , difDOTlos = 0 ; double losxyz [ 3 ] , losmag = 0 ; double xsep = 0 , ysep = 0 , xcoord = 0 , ycoord = 0 ; int ii ; if ( los == 0 || los == 2 || los == 3 ) { for ( ii = 0 ; ii < 3 ; ii ++ ) { difxyz [ ii ] = axyz [ ii ] - bxyz [ ii ] ; if ( los == 0 ) losxyz [ ii ] = 0.5 * ( axyz [ ii ] + bxyz [ ii ] ) ; else if ( los == 2 ) losxyz [ ii ] = axyz [ ii ] ; else losxyz [ ii ] = bxyz [ ii ] ; losmag = losmag + losxyz [ ii ] * losxyz [ ii ] ; difmag = difmag + difxyz [ ii ] * difxyz [ ii ] ; difDOTlos = difDOTlos + difxyz [ ii ] * losxyz [ ii ] ; } difmag = sqrt ( difmag ) ; losmag = sqrt ( losmag ) ; ycoord = difDOTlos / losmag ; xcoord = sqrt ( difmag * difmag - ycoord * ycoord ) ; } else if ( los == 1 ) { for ( ii = 0 ; ii < 3 ; ii ++ ) difxyz [ ii ] = axyz [ ii ] - bxyz [ ii ] ; if ( pbc == 1 ) { relwrap ( difxyz , blen ) ; } ycoord = difxyz [ 2 ] ; xcoord = sqrt ( difxyz [ 0 ] * difxyz [ 0 ] + difxyz [ 1 ] * difxyz [ 1 ] ) ; } if ( samp == 0 ) { xsep = sqrt ( xcoord * xcoord + ycoord * ycoord ) ; ysep = fabs ( ycoord / xsep ) ; } else if ( samp == 1 ) { ysep = ycoord ; xsep = xcoord ; } else if ( samp == 2 ) { xsep = sqrt ( xcoord * xcoord + ycoord * ycoord ) ; ysep = acos ( ycoord / xsep ) ; } else if ( samp == 3 ) { ysep = ycoord ; xsep = log10 ( xcoord ) ; } else if ( samp == 4 ) { xsep = sqrt ( xcoord * xcoord + ycoord * ycoord ) ; ysep = acos ( ycoord / xsep ) ; xsep = log10 ( xsep ) ; } else { printf ( " \n \n " , samp ) ; exit ( 0 ) ; } if ( xsep > sampbound [ 0 ] && xsep < sampbound [ 1 ] && ysep > sampbound [ 2 ] && ysep < sampbound [ 3 ] ) { int xbin_n = floor ( ( xsep - sampbound [ 0 ] ) * nsamp [ 0 ] / ( sampbound [ 1 ] - sampbound [ 0 ] ) ) ; int ybin_n = floor ( ( ysep - sampbound [ 2 ] ) * nsamp [ 1 ] / ( sampbound [ 3 ] - sampbound [ 2 ] ) ) ; if ( xbin_n == nsamp [ 0 ] ) xbin_n -= 1 ; if ( ybin_n == nsamp [ 1 ] ) ybin_n -= 1 ; * rx = xbin_n ; * ry = ybin_n ; return 0 ; } else { * rx = -1 ; * ry = -1 ; return -1 ; } return -1 ; }
function to define the sampling and the bin
function to define the sampling and the bin
//Defining the line of sight // the los is along the mid/first/second galaxy co-ordinate //los is along the mid point //los is along the first galaxy // los is along the second galaxy //the los is along the Z axis //pbc can be applied only with los=1 along z axis //Using a given sampling definition for 2d correlation function //sampling in rmu space //consider positive and negative mu together //rpar-rper //r theta //log rperp- rpar //log(r)-theta //Determine the bin in which the pair lies