Index: /trunk/Cosmo/SimLSS/cmvdefsurv.cc
===================================================================
--- /trunk/Cosmo/SimLSS/cmvdefsurv.cc	(revision 3364)
+++ /trunk/Cosmo/SimLSS/cmvdefsurv.cc	(revision 3365)
@@ -21,4 +21,5 @@
  --- */
 
+//-----------------------------------------------------------------------------------------------------------
 inline double rad2deg(double trad) {return trad/M_PI*180.;}
 inline double rad2min(double trad) {return trad/M_PI*180.*60.;}
@@ -28,16 +29,24 @@
 inline double sec2rad(double tsec) {return tsec*M_PI/(180.*3600.);}
 
+double LargeurDoppler(double v /* km/s */, double nu);
+double DzFrV(double v /* km/s */, double zred);
+double DNuFrDz(double dzred,double nu_at_0,double zred);
+double DzFrDNu(double dnu_at_0,double nu_at_0,double zred);
+double DzFrDNuApprox(double dnu_at_0,double nu_at_0,double zred);
+double ZFrLos(double loscom /* Mpc com */,CosmoCalc& univ);
+double AngsolEqTelescope(double nu /* GHz */,double telsurf /* m^2 */);
 void usage(void);
+
 void usage(void) {
-  cout<<"cmvdefsurv [options] -x adtx,atxlarg[,unit_x] -y adty,atylarg[,unit_y] -z dred,redlarg[,unit_z] redshift"<<endl
+  cout<<"cmvdefsurv [options] -x dx,txlarg[,unit_x] -y dy,tylarg[,unit_y] -z dz,tzlarg[,unit_z] redshift"<<endl
       <<"----------------"<<endl
-      <<" -x adtx,atxlarg : resolution et largeur dans le plan transverse selon X"<<endl
-      <<" -y adty,atylarg : idem selon Y, si <=0 meme que X"<<endl
-      <<" -z dred,redlarg : resolution et largeur sur la ligne de visee"<<endl
+      <<" -x dx,txlarg[,unit_x] : resolution et largeur dans le plan transverse selon X"<<endl
+      <<" -y dy,tylarg[,unit_y] : idem selon Y, si <=0 meme que X"<<endl
+      <<" -z dz,tzlarg[,unit_z] : resolution et largeur sur la ligne de visee"<<endl
       <<"-- Unites pour X-Y:"<<endl
-      <<"   \'A\' : en angles (pour X-Y)     : resolution=ArcMin, largeur=Degre (defaut)"<<endl
-      <<"   \'Z\' : en redshift (pour Z)     : resolution et largeur en redshift (defaut)"<<endl
-      <<"   \'F\' : en frequence (pour Z)    : resolution et largeur MHz"<<endl
-      <<"   \'M\' : en distance (pour X-Y-Z) : resolution et largeur Mpc"<<endl
+      <<"   \'A\' : en angles (pour X-Y)  : resolution=ArcMin, largeur=Degre (defaut)"<<endl
+      <<"   \'Z\' : en redshift (pour Z)  : resolution et largeur en redshift (defaut)"<<endl
+      <<"   \'F\' : en frequence (pour Z) : resolution et largeur MHz"<<endl
+      <<"   \'M\' : en longeur comobile (pour X-Y-Z) : resolution et largeur Mpc"<<endl
       <<"----------------"<<endl
       <<" -K k,dk,pk : k(Mpc^-1) dk(Mpc^-1) pk(a z=0 en Mpc^-3) pour estimer la variance cosmique"<<endl
@@ -45,9 +54,9 @@
       <<" -O surf,tobs,eta : surface effective (m^2), temps d\'observation (s), efficacite d\'ouverture"<<endl
       <<" -N Tsys : temperature du system (K)"<<endl
-      <<" -L lobewidth,freqlob : taille du lobe d\'observation (FWHM) en arcmin (def= 1\')"<<endl
+      <<" -L lobewidth,freqlob : taille du lobe d\'observation (FWHM) en arcmin (def= rien)"<<endl
       <<"                        pour la frequence freqlob en MHz"<<endl
-      <<"            Si lobewidth<=0 : l'angle solide du lobe = celui du pixel"<<endl
       <<"            Si freqlob<=0 : la frequence de reference est celle du redshift etudie"<<endl
       <<"            Si freqlob absent : la frequence de reference 1.4 GHz"<<endl
+      <<"            lobewidth est pris comme la FWHM du lobe gaussien equivalent"<<endl
       <<" -2 : two polarisations measured"<<endl
       <<" -M  : masse de HI de reference (MSol), si <=0 mean schechter in pixel"<<endl
@@ -65,11 +74,16 @@
 }
 
+//-------------------------------------------------------------------------------------------
 int main(int narg,char *arg[])
 {
- // --- Valeurs fixes
- // WMAP
+ // --- 
+ // --- Valeurs fixes ou par defaut
+ // --- 
+
+ //-- WMAP
  unsigned short flat = 0;
  double h100=0.71, om0=0.267804, or0=7.9e-05*0., ol0=0.73,w0=-1.;
- // Schechter
+
+ //-- Schechter HIMASS
  double h75 = h100 / 0.75;
  double nstar = 0.006*pow(h75,3.);  //
@@ -78,39 +92,45 @@
  cout<<"nstar= "<<nstar<<"  mstar="<<mstar<<"  alpha="<<alpha<<endl;
 
- // --- Arguments
- double adtx=0., atxlarg=0., dx=0.,txlarg=0.;
-   int nx=0; char unit_x = 'A';
- double adty=-1., atylarg=-1., dy=0.,tylarg=0.;
-   int ny=0; char unit_y = 'A';
- double dred=0., redlarg=0., dz=0.,tzlarg=0.;
-   int nz=0; char unit_z = 'Z';
- double redshift = 0.;
+ double hifactor = 1.;
+ double vrot = 300.; // largeur en vitesse (km/s) pour elargissement doppler
+
+ //-- CMB , Synchrotron et AGN
+ double tcmb = T_CMB_Par;
+ // a 408 MHz (Haslam) + evol index a -2.6
+ double Tsynch408=60., nuhaslam=0.408, indnu = -2.6;
+ double lflux_agn = -3.;
+
+ //-- Appareillage
+ bool ya2polar = false;
+ double facpolar = 0.5; // si on mesure les 2 polars -> 1.0
+ double Tsys=75.;
  double tobs = 6000., surftot = 400000., eta_eff  = 1.;
- // variance cosmique (default = standard SDSSII)
- double kcosm = 0.05, dkcosm = -1., pkcosm = 40000.;
  // taille du lobe d'observation en arcmin pour la frequence
  double lobewidth0 = -1., lobefreq0 = Fr_HyperFin_Par*1.e3;
- double Tsys=75.;
- // a 408 MHz (Haslam) + evol index a -2.6
- double Tsynch408=60., nuhaslam=0.408, indnu = -2.6;
+
+ //-- Variance cosmique (default = standard SDSSII)
+ double kcosm = 0.05, dkcosm = -1., pkcosm = 40000.;
+
+ // --- Pour taille du survey
+ double dx=0., dy=-1., dz=0., txlarg=0., tylarg=-1., tzlarg=0.;
+ int nx=0, ny=0, nz=0;
+ char unit_x = 'A', unit_y = 'A', unit_z = 'Z';
+ double redshift0 = 0.;
  double mhiref = -1.; // reference Mass en HI (def integ schechter)
- double hifactor = 1.;
- double vrot = 300.; // largeur en vitesse (km/s) pour elargissement doppler
- bool ya2polar = false;
- double facpolar = 0.5; // si on mesure les 2 polars -> 1.0
- double lflux_agn = -3.;
-
+
+ // --- 
  // --- Decodage arguments
+ // --- 
  char c;
   while((c = getopt(narg,arg,"h2x:y:z:N:S:O:M:F:V:U:L:A:K:")) != -1) {
   switch (c) {
   case 'x' :
-    sscanf(optarg,"%lf,%lf,%c",&adtx,&atxlarg,&unit_x);
+    sscanf(optarg,"%lf,%lf,%c",&dx,&txlarg,&unit_x);
     break;
   case 'y' :
-    sscanf(optarg,"%lf,%lf,%c",&adty,&atylarg,&unit_y);
+    sscanf(optarg,"%lf,%lf,%c",&dy,&tylarg,&unit_y);
     break;
   case 'z' :
-    sscanf(optarg,"%lf,%lf,%c",&dred,&redlarg,&unit_z);
+    sscanf(optarg,"%lf,%lf,%c",&dz,&tzlarg,&unit_z);
     break;
   case 'O' :
@@ -153,150 +173,200 @@
   }
  } 
- if(optind>=narg) {usage(); return-1;}
- sscanf(arg[optind],"%lf",&redshift);
- if(redshift<=0.) {cout<<"Redshift "<<redshift<<" should be >0"<<endl; return -2;}
-
+ if(optind>=narg) {usage(); return -1;}
+ sscanf(arg[optind],"%lf",&redshift0);
+ if(redshift0<=0.) {cout<<"Redshift "<<redshift0<<" should be >0"<<endl; return -2;}
+
+ // --- 
  // --- Initialisation de la Cosmologie
- cout<<"\n>>>>\n>>>> Cosmologie generale\n>>>>"<<endl;
- cout<<"h100="<<h100<<" Om0="<<om0<<" Or0="<<or0<<" Or0="
-     <<or0<<" Ol0="<<ol0<<" w0="<<w0<<" flat="<<flat<<endl;
- cout<<"--- Cosmology for z = "<<redshift<<endl;
- CosmoCalc univ(flat,true,2.*redshift);
- double perc=0.01,dzinc=redshift/100.,dzmax=dzinc*10.; unsigned short glorder=4;
+ // --- 
+ CosmoCalc univ(flat,true,2.*redshift0);
+ double perc=0.01,dzinc=redshift0/100.,dzmax=dzinc*10.; unsigned short glorder=4;
  univ.SetInteg(perc,dzinc,dzmax,glorder);
  univ.SetDynParam(h100,om0,or0,ol0,w0);
+
+ GrowthFactor growth(om0,ol0);
+
+ // --- 
+ // --- Mise en forme dans les unites appropriees
+ // --- 
+ // ATTENTION: le cube de simulation est en Mpc avec des pixels de taille comobile fixe
+ cout<<"\n>>>>\n>>>> Geometrie\n>>>>"<<endl;
+ if(dy<=0. || tylarg<=0.) {dy=dx; tylarg=txlarg; unit_y=unit_x;}
+ cout<<"X values: resolution="<<dx<<" largeur="<<txlarg<<" unite="<<unit_x<<endl;
+ if(unit_x == 'A') {
+   nx = int(txlarg*60./dx+0.5);
+   dx = min2rad(dx)*univ.Dtrcom(redshift0);
+   txlarg = dx*nx;
+ } else if(unit_x == 'M') {
+   nx = int(txlarg/dx+0.5);
+   txlarg = dx*nx;
+ } else {
+   cout<<"Unknown unit_x = "<<unit_x<<endl; return -2;
+ }
+ cout<<"Y values: resolution="<<dy<<" largeur="<<tylarg<<" unite="<<unit_y<<endl;
+ if(unit_y == 'A') {
+   ny = int(tylarg*60./dy+0.5);
+   dy = min2rad(dy)*univ.Dtrcom(redshift0);
+   tylarg = dy*ny;
+ } else if(unit_y == 'M') {
+   ny = int(tylarg/dy+0.5);
+   tylarg = dy*ny;
+ } else {
+   cout<<"Unknown unit_y = "<<unit_y<<endl; return -2;
+ }
+ cout<<"Z values: resolution="<<dz<<" largeur="<<tzlarg<<" unite="<<unit_z<<endl;
+ if(unit_z == 'Z') {
+   nz = int(tzlarg/dz+0.5);
+   dz = dz*univ.Dhubble()/univ.E(redshift0);
+   tzlarg = dz*nz;
+ } else if(unit_z == 'M') {
+   nz = int(tzlarg/dz+0.5);
+   tzlarg = dz*nz;
+ } else if(unit_z == 'F') { // unite en MHz
+   nz = int(tzlarg/dz+0.5);
+   dz = DzFrDNu(dz,Fr_HyperFin_Par*1.e3,redshift0);  //dzred
+   dz = dz*univ.Dhubble()/univ.E(redshift0);
+   tzlarg = dz*nz;
+ } else {
+   cout<<"Unknown unit_z = "<<unit_z<<endl; return -2;
+ }
+
+ // --- 
+ // --- Calcul des valeurs au centre du cube et aux faces limites av/ar
+ // --- 
+ cout<<"\n>>>>\n>>>> Cosmologie generale\n>>>>"<<endl;
+ double adtx[3], adty[3], atxlarg[3], atylarg[3];
+ double loscom[3], redshift[3], unplusz[3], dred[3], growthfac[3], rhocz[3];
+ double dang[3], dtrcom[3], dlum[3], dloscom[3], dlosdz[3];
+ double nuhiz[3], lambdahiz[3], dnuhiz[3];
+ double angsol_pix[3], angsol_tot[3];
+
+ redshift[0] = redshift0;
+ loscom[0] = univ.Dloscom(redshift0);
+ loscom[1] = loscom[0]-tzlarg/2.;
+ loscom[2] = loscom[0]+tzlarg/2.;
+ //if(loscom[1]<=0.) {cout<<"Lower distance limit "<<loscom[1]<<" should be >0"<<endl; return -3;}
+ for(int i=0;i<3;i++) {
+   double l = loscom[i]; if(l<=0.) l = dz/2.;
+   redshift[i]  = ZFrLos(l,univ);
+   unplusz[i]   = 1. + redshift[i];
+   growthfac[i] = growth(redshift[i]);
+   rhocz[i]     = univ.Rhoc(redshift[i])*GCm3toMsolMpc3_Cst;;
+   dang[i]      = univ.Dang(redshift[i]);
+   dtrcom[i]    = univ.Dtrcom(redshift[i]);
+   dlum[i]      = univ.Dlum(redshift[i]);
+   dloscom[i]   = univ.Dloscom(redshift[i]);
+   dlosdz[i]    = univ.Dhubble()/univ.E(redshift[i]);
+   dred[i]      = dz/dlosdz[i];
+   adtx[i]      = dx/dtrcom[i];
+   atxlarg[i]   = adtx[i]*nx;
+   adty[i]      = dy/dtrcom[i];
+   atylarg[i]   = adty[i]*ny;
+   nuhiz[i]     = Fr_HyperFin_Par / unplusz[i];  // GHz
+   lambdahiz[i] = SpeedOfLight_Cst*1000./(nuhiz[i]*1.e9);  // m
+   dnuhiz[i]    = DNuFrDz(dred[i],Fr_HyperFin_Par,redshift[i]);  // GHz
+   angsol_pix[i] = AngSol(adtx[i]/2.,adty[i]/2.,M_PI/2.);
+   angsol_tot[i] = AngSol(atxlarg[i]/2.,atylarg[i]/2.,M_PI/2.);
+ }
+ 
+
+ cout<<"--- Cosmology for z = "<<0.<<endl;
  univ.Print(0.);
- univ.Print(redshift);
- GrowthFactor growth(om0,ol0);
- double growthfac = growth(redshift);
- cout<<"Facteur de croissance lineaire = "<<growthfac
-     <<" ^2 , ( 1/(1+z)="<<1./(1.+redshift)<<" )"<<endl;
  double rhoc0 = univ.Rhoc(0.)*GCm3toMsolMpc3_Cst;
- double rhocz = univ.Rhoc(redshift)*GCm3toMsolMpc3_Cst;
- cout<<"Rho_c a z=0: "<<rhoc0<<", a z="<<redshift<<": "<<rhocz<<" Msol/Mpc^3"<<endl;
-
- double dang    = univ.Dang(redshift);
- double dtrcom  = univ.Dtrcom(redshift);
- double dlum    = univ.Dlum(redshift);
- double dloscom = univ.Dloscom(redshift);
- double dlosdz  = univ.Dhubble()/univ.E(redshift);
- cout<<"dang="<<dang<<" dlum="<<dlum<<" dtrcom="<<dtrcom
-     <<" dloscom="<<dloscom<<" dlosdz="<<dlosdz<<" Mpc"<<endl;
-
- cout<<"\n1\" -> "<<dang*sec2rad(1.)<<" Mpc = "<<dtrcom*sec2rad(1.)<<" Mpc com"<<endl;
- cout<<"1\' -> "<<dang*min2rad(1.)<<" Mpc = "<<dtrcom*min2rad(1.)<<" Mpc com"<<endl;
- cout<<"1d -> "<<dang*deg2rad(1.)<<" Mpc = "<<dtrcom*deg2rad(1.)<<" Mpc com"<<endl;
-
- cout<<"dz=1 -> "<<dlosdz<<" Mpc com"<<endl;
-
- cout<<"1 Mpc los com -> dz = "<<1./dlosdz<<endl;
- cout<<"1 Mpc transv com -> "<<rad2sec(1./dtrcom)<<"\" = "
-     <<rad2min(1./dtrcom)<<" \' = "<<rad2deg(1./dtrcom)<<" d"<<endl;
-
- // --- Mise en forme dans les unites appropriees
- cout<<"\n>>>>\n>>>> Geometrie\n>>>>"<<endl;
- if(adty<=0. || atylarg<=0.) {adty=adtx; atylarg=atxlarg; unit_y=unit_x;}
- cout<<"X values: resolution="<<adtx<<" largeur="<<atxlarg<<" unite="<<unit_x<<endl;
- if(unit_x == 'A') {
-   nx = int(atxlarg*60./adtx+0.5);
-   adtx = min2rad(adtx); atxlarg = deg2rad(atxlarg);
-   dx = adtx*dtrcom; txlarg = dx*nx;
- } else if(unit_x == 'M') {
-   nx = int(atxlarg/adtx+0.5);
-   dx = adtx; txlarg = atxlarg;
-   adtx = dx/dtrcom; atxlarg = adtx*nx;
- } else {
-   cout<<"Unknown unit_x = "<<unit_x<<endl;
- }
- cout<<"Y values: resolution="<<adty<<" largeur="<<atylarg<<" unite="<<unit_y<<endl;
- if(unit_y == 'A') {
-   ny = int(atylarg*60./adty+0.5);
-   adty = min2rad(adty); atylarg = deg2rad(atylarg);
-   dy = adty*dtrcom; tylarg = dy*ny;
- } else if(unit_y == 'M') {
-   ny = int(atylarg/adty+0.5);
-   dy = adty; tylarg = atylarg;
-   adty = dy/dtrcom; atylarg = adty*ny;
- } else {
-   cout<<"Unknown unit_y = "<<unit_y<<endl;
- }
- cout<<"Z values: resolution="<<dred<<" largeur="<<redlarg<<" unite="<<unit_z<<endl;
- if(unit_z == 'Z') {
-   nz = int(redlarg/dred+0.5);
-   dz = dred*dlosdz; tzlarg = dz*nz;
- } else if(unit_z == 'M') {
-   nz = int(redlarg/dred+0.5);
-   dz = dred; tzlarg = redlarg;
-   dred = dz/dlosdz; redlarg = dred*nz;
- } else if(unit_z == 'F') {
-   nz = int(redlarg/dred+0.5);
-   dred = dred/(Fr_HyperFin_Par*1.e3)*pow(1.+redshift,2.); redlarg = dred*nz;
-   dz = dred*dlosdz; tzlarg = dz*nz;
- } else {
-   cout<<"Unknown unit_z = "<<unit_z<<endl;
- }
-
+
+ for(int i=0;i<3;i++) {
+   cout<<"\n--- Cosmology for z = "<<redshift[i]<<endl;
+   univ.Print(redshift[i]);
+ }
+
+ cout<<endl;
+ cout<<"Facteur de croissance lineaire = "<<growthfac[0]
+     <<" in ["<<growthfac[1]<<","<<growthfac[2]<<"]"<<endl;
+ cout<<"                       1/(1+z) = "<<1./(1.+redshift[0])
+     <<" in ["<<1./(1.+redshift[1])<<","<<1./(1.+redshift[2])<<"]"<<endl;
+ cout<<"Facteur de croissance lineaire^2 = "<<growthfac[0]*growthfac[0]
+     <<" in ["<<growthfac[1]*growthfac[1]<<","<<growthfac[2]*growthfac[2]<<"]"<<endl;
+
+ cout<<"Rho_c (z=0) =  "<<rhoc0<<", a z="<<0<<": "<<rhoc0<<" Msol/Mpc^3"<<endl;
+ cout<<"Rho_c a z = "<<rhocz[0]
+     <<" Msol/Mpc^3 in ["<<rhocz[1]<<","<<rhocz[2]<<"]"<<endl;
+
+ cout<<endl;
+ cout<<"dang= "<<dang[0]<<" Mpc in ["<<dang[1]<<","<<dang[2]<<"]"<<endl;
+ cout<<"dtrcom= "<<dtrcom[0]<<" Mpc com in ["<<dtrcom[1]<<","<<dtrcom[2]<<"]"<<endl;
+ cout<<"dlum= "<<dlum[0]<<" Mpc in ["<<dlum[1]<<","<<dlum[2]<<"]"<<endl;
+ cout<<"dloscom= "<<dloscom[0]<<" Mpc com in ["<<dloscom[1]<<","<<dloscom[2]<<"]"<<endl;
+ cout<<"dz=1 -> dlosdz= "<<dlosdz[0]<<" Mpc com in ["<<dlosdz[1]<<","<<dlosdz[2]<<"]"<<endl;
+ cout<<"1 Mpc los com -> dz = "<<1./dlosdz[0]<<" in ["<<1./dlosdz[1]<<","<<1./dlosdz[2]<<"]"<<endl;
+
+ cout<<endl;
+ for(int i=0;i<3;i++) {
+   cout<<"...Redshift="<<redshift[i]<<endl;
+   cout<<"1\" -> "<<dang[i]*sec2rad(1.)<<" Mpc = "<<dtrcom[i]*sec2rad(1.)<<" Mpc com"<<endl;
+   cout<<"1\' -> "<<dang[i]*min2rad(1.)<<" Mpc = "<<dtrcom[i]*min2rad(1.)<<" Mpc com"<<endl;
+   cout<<"1d -> "<<dang[i]*deg2rad(1.)<<" Mpc = "<<dtrcom[i]*deg2rad(1.)<<" Mpc com"<<endl;
+   cout<<"1 Mpc transv com -> "<<rad2sec(1./dtrcom[i])<<"\" = "
+       <<rad2min(1./dtrcom[i])<<" \' = "<<rad2deg(1./dtrcom[i])<<" d"<<endl;
+   cout<<"dz=1 -> dlosdz= "<<dlosdz[i]<<" Mpc com"<<endl;
+   cout<<"1 Mpc los com -> dz = "<<1./dlosdz[0]<<endl;
+ }
+
+ // --- 
+ // --- Cosmolographie Transverse
+ // --- 
+ cout<<"\n>>>>\n>>>> Cosmologie & Geometrie transverse\n>>>>"<<endl;
+
+ cout<<"dx = "<<dx<<", txlarg = "<<txlarg<<" Mpc (com), nx="<<nx<<endl;
+ cout<<"adtx = "<<adtx[0]<<" rd in ["<<adtx[1]<<","<<adtx[2]<<"]"<<endl;
+ cout<<"     = "<<rad2min(adtx[0])<<"\' in ["<<rad2min(adtx[1])<<","<<rad2min(adtx[2])<<"]"<<endl;
+ cout<<"atxlarg = "<<atxlarg[0]<<" rd in ["<<atxlarg[1]<<","<<atxlarg[2]<<"]"<<endl;
+ cout<<"          "<<rad2deg(atxlarg[0])<<" d in ["<<rad2deg(atxlarg[1])<<","<<rad2deg(atxlarg[2])<<"]"<<endl;
+
+ if(fabs(dx-dy)>1.e-20 && fabs(txlarg-tylarg)>1.e-20) {
+   cout<<"\ndy = "<<dy<<", tylarg = "<<tylarg<<" Mpc (com), ny="<<ny<<endl;
+   cout<<"adty = "<<adty[0]<<" rd in ["<<adty[1]<<","<<adty[2]<<"]"<<endl;
+   cout<<"     = "<<rad2min(adty[0])<<"\' in ["<<rad2min(adty[1])<<","<<rad2min(adty[2])<<"]"<<endl;
+   cout<<"atylarg = "<<atylarg[0]<<" rd in ["<<atylarg[1]<<","<<atylarg[2]<<"]"<<endl;
+   cout<<"          "<<rad2deg(atylarg[0])<<" d in ["<<rad2deg(atylarg[1])<<","<<rad2deg(atylarg[2])<<"]"<<endl;
+ }
+
+ // --- 
+ // --- Cosmolographie Line of sight
+ // --- 
+ cout<<"\n>>>>\n>>>> Cosmologie & Geometrie ligne de visee\n>>>>"<<endl;
+ cout<<"dz = "<<dz<<", tzlarg = "<<tzlarg<<" Mpc (com), nz="<<nz<<endl;
+ cout<<"Redshift = "<<redshift[0]<<" in ["<<redshift[1]<<","<<redshift[2]<<"]"<<endl;
+ cout<<"dred = "<<dred[0]<<" in ["<<dred[1]<<","<<dred[2]<<"]"<<endl;
+ cout<<"nu HI = "<<nuhiz[0]<<" GHz in ["<<nuhiz[1]<<","<<nuhiz[2]<<"]"<<endl;
+ cout<<"lambda HI = "<<lambdahiz[0]<<" m in ["<<lambdahiz[1]<<","<<lambdahiz[2]<<"]"<<endl;
+ cout<<"dnu HI= "<<dnuhiz[0]*1e3<<" MHz in ["<<dnuhiz[1]*1e3<<","<<dnuhiz[2]*1e3<<"]"<<endl;
+
+ // --- 
+ // --- Volume
+ // --- 
+ cout<<"\n>>>>\n>>>> Volumes\n>>>>"<<endl;
  double Npix = (double)nx*(double)ny*(double)nz;
- double redlim[2] = {redshift-redlarg/2.,redshift+redlarg/2.};
- if(redlim[0]<=0.)
-   {cout<<"Lower redshift limit "<<redlim[0]<<" should be >0"<<endl; return -3;}
- double dtrlim[2]  = {univ.Dtrcom(redlim[0]),univ.Dtrcom(redlim[1])};
- double loslim[2]  = {univ.Dloscom(redlim[0]), univ.Dloscom(redlim[1])};
- double dlumlim[2] = {univ.Dlum(redlim[0]),univ.Dlum(redlim[1])};
-
- cout<<"---- Line of Sight: Redshift = "<<redshift<<endl
-     <<"dred = "<<dred<<"  redlarg = "<<redlarg<<endl
-     <<"  dz = "<<dz<<" Mpc  redlarg = "<<tzlarg<<" Mpc com, nz = "<<nz<<" pix"<<endl;
- cout<<"---- Transverse X:"<<endl
-     <<"adtx = "<<rad2min(adtx)<<"\',  atxlarg = "<<rad2deg(atxlarg)<<" d"<<endl
-     <<"  dx = "<<dx<<" Mpc,  txlarg = "<<txlarg<<" Mpc com, nx = "<<nx<<" pix"<<endl;
- cout<<"---- Transverse Y:"<<endl
-     <<"adty = "<<rad2min(adty)<<"\',  atylarg = "<<rad2deg(atylarg)<<" d"<<endl
-     <<"  dy = "<<dy<<" Mpc,  tylarg = "<<tylarg<<" Mpc com, ny = "<<ny<<" pix"<<endl;
- cout<<"---- Npix total = "<<Npix<<" -> "<<Npix*sizeof(double)/1.e6<<" Mo"<<endl;
- cout<<"     Volume pixel = "<<dx*dy*dz<<" Mpc^3"<<endl;
- cout<<"     Volume total = "<<Npix*dx*dy*dz<<" Mpc^3"<<endl;
-
- // --- Cosmolographie Transverse
- cout<<"\n>>>>\n>>>> Cosmologie & Geometrie transverse\n>>>>"<<endl;
- cout<<"dang comoving = "<<dtrcom<<" Mpc (com) var_in_z ["
-                         <<dtrlim[0]<<","<<dtrlim[1]<<"]"<<endl;
-
- cout<<"... dx = "<<dx<<" Mpc (com), with angle "<<adtx*dtrcom<<endl
-     <<"       with angle var_in_z ["<<adtx*dtrlim[0]<<","<<adtx*dtrlim[1]<<"]"<<endl;
- cout<<"... largx = "<<txlarg<<" Mpc (com), with angle "<<atxlarg*dtrcom<<endl
-     <<"          with angle var_in_z ["<<atxlarg*dtrlim[0]<<","<<atxlarg*dtrlim[1]<<"]"<<endl;
-
- cout<<"... dy = "<<dy<<" Mpc (com), with angle "<<adty*dtrcom<<endl
-     <<"       with angle var_in_z ["<<adty*dtrlim[0]<<","<<adty*dtrlim[1]<<"]"<<endl;
- cout<<"... largy = "<<tylarg<<" Mpc (com), with angle "<<atylarg*dtrcom<<endl
-     <<"          with angle var_in_z ["<<atylarg*dtrlim[0]<<","<<atylarg*dtrlim[1]<<"]"<<endl;
-
- // --- Cosmolographie Line of sight
- cout<<"\n>>>>\n>>>> Cosmologie & Geometrie ligne de visee\n>>>>"<<endl;
- cout<<"los comoving distance = "<<dloscom<<" Mpc (com) in ["
-     <<loslim[0]<<","<<loslim[1]<<"]"<<endl
-     <<"                                    diff = "
-     <<loslim[1]-loslim[0]<<" Mpc"<<endl;
-
- cout<<"...dz = "<<dz<<" Mpc (com), with redshift approx "<<dred*dlosdz<<endl;
- cout<<"...tzlarg = "<<tzlarg<<" Mpc (com), with redshift approx "<<redlarg*dlosdz<<endl;
-
- // --- Solid Angle & Volume
- cout<<"\n>>>>\n>>>> Angles solides et Volumes\n>>>>"<<endl;
- cout<<"--- Solid angle"<<endl;
- double angsol = AngSol(adtx/2.,adty/2.,M_PI/2.);
- cout<<"Elementary solid angle = "<<angsol<<" sr = "<<angsol/(4.*M_PI)<<" *4Pi sr"<<endl;
- double angsoltot = AngSol(atxlarg/2.,atylarg/2.,M_PI/2.);
- cout<<"Total solid angle = "<<angsoltot<<" sr = "<<angsoltot/(4.*M_PI)<<" *4Pi sr"<<endl;
-
- cout<<"\n--- Volume"<<endl;
- double dvol = dx*dy*dz;
- cout<<"Pixel volume comoving = "<<dvol<<" Mpc^3"<<endl;
- double vol = univ.Vol4Pi(redlim[0],redlim[1])/(4.*M_PI)*angsoltot;
- cout<<"Volume comoving = "<<vol<<" Mpc^3 = "<<vol/1.e9<<" Gpc^3"<<endl
-     <<"Pixel volume comoving = vol/Npix = "<<vol/Npix<<" Mpc^3"<<endl;
-
- // --- Fourier space: k = omega = 2*Pi*Nu
+ double vol_pixel = dx*dy*dz;
+ double vol_survey = vol_pixel*Npix;
+ cout<<"Npix total = "<<Npix<<" -> "<<Npix*sizeof(double)/1.e6<<" Mo"<<endl;
+ cout<<"Volume pixel = "<<vol_pixel<<" Mpc^3 com"<<endl;
+ cout<<"Volume total = "<<vol_survey<<" Mpc^3 com = "<<vol_survey/1.e9<<" Gpc^3"<<endl;
+
+ double vol = univ.Vol4Pi(redshift[1],redshift[2])/(4.*M_PI)*angsol_tot[0];
+ cout<<"Calcul avec angsol et redshift: vol = "<<vol<<" Mpc^3 = "<<vol/1.e9<<" Gpc^3"<<endl
+     <<"       -> pixel volume comoving = vol/Npix = "<<vol/Npix<<" Mpc^3"<<endl;
+
+ // --- 
+ // --- Angles solides
+ // --- 
+ cout<<"\n>>>>\n>>>> Angles solides\n>>>>"<<endl;
+ cout<<"Pixel solid angle = "<<angsol_pix[0]<<" sr ("<<angsol_pix[0]/(4.*M_PI)<<" *4Pi)"
+     <<" in ["<<angsol_pix[1]<<","<<angsol_pix[2]<<"]"<<endl;
+ cout<<"Total solid angle = "<<angsol_tot[0]<<" sr ("<<angsol_tot[0]/(4.*M_PI)<<" *4Pi)"
+     <<" in ["<<angsol_tot[1]<<","<<angsol_tot[2]<<"]"<<endl;
+
+ // --- 
+ // --- Fourier space: k = omega = 2*Pi*Nu = 2*Pi*C/Lambda
+ // --- 
  cout<<"\n>>>>\n>>>> Geometrie dans l'espace de Fourier\n>>>>"<<endl;
  cout<<"Array size: nx = "<<nx<<",  ny = "<<ny<<",  nz = "<<nz<<endl;
@@ -304,19 +374,23 @@
  double dk_y = 2.*M_PI/(nx*dy), knyq_y = M_PI/dy;
  double dk_z = 2.*M_PI/(nz*dz), knyq_z = M_PI/dz;
- cout<<"Resolution: dk_x = "<<dk_x<<" Mpc^-1  (2Pi/dk_x="<<2.*M_PI/dk_x<<" Mpc)"<<endl
-     <<"            dk_y = "<<dk_y<<" Mpc^-1  (2Pi/dk_y="<<2.*M_PI/dk_y<<" Mpc)"<<endl;
- cout<<"Nyquist:    kx = "<<knyq_x<<" Mpc^-1  (2Pi/knyq_x="<<2.*M_PI/knyq_x<<" Mpc)"<<endl
-     <<"            ky = "<<knyq_y<<" Mpc^-1  (2Pi/knyq_y="<<2.*M_PI/knyq_y<<" Mpc)"<<endl;
- cout<<"Resolution: dk_z = "<<dk_z<<" Mpc^-1  (2Pi/dk_z="<<2.*M_PI/dk_z<<" Mpc)"<<endl;
- cout<<"Nyquist:    kz = "<<knyq_z<<" Mpc^-1  (2Pi/knyq_z="<<2.*M_PI/knyq_z<<" Mpc)"<<endl;
-
+ cout<<"Transverse:"<<endl
+     <<"  Resolution: dk_x = "<<dk_x<<" Mpc^-1  (2Pi/dk_x="<<2.*M_PI/dk_x<<" Mpc)"<<endl
+     <<"              dk_y = "<<dk_y<<" Mpc^-1  (2Pi/dk_y="<<2.*M_PI/dk_y<<" Mpc)"<<endl
+     <<"  Nyquist:    kx = "<<knyq_x<<" Mpc^-1  (2Pi/knyq_x="<<2.*M_PI/knyq_x<<" Mpc)"<<endl
+     <<"              ky = "<<knyq_y<<" Mpc^-1  (2Pi/knyq_y="<<2.*M_PI/knyq_y<<" Mpc)"<<endl;
+ cout<<"Line of sight:"<<endl
+     <<"  Resolution: dk_z = "<<dk_z<<" Mpc^-1  (2Pi/dk_z="<<2.*M_PI/dk_z<<" Mpc)"<<endl
+     <<"  Nyquist:    kz = "<<knyq_z<<" Mpc^-1  (2Pi/knyq_z="<<2.*M_PI/knyq_z<<" Mpc)"<<endl;
+
+ // --- 
  // --- Variance cosmique
+ // --- 
  //                      cosmique                    poisson
  // (sigma/P)^2 = 2*(2Pi)^3 / (4Pi k^2 dk Vsurvey) * [(1+n*P)/(n*P)]^2
  // nombre de mode = 1/2 * Vsurvey/(2Pi)^3 * 4Pi*k^2*dk
  if(kcosm>0. && pkcosm>0.) {
-   double pk = pkcosm*pow(growthfac,2.);
+   double pk = pkcosm*pow(growthfac[0],2.);
    cout<<"\n>>>>\n>>>> variance cosmique pour k="<<kcosm<<" Mpc^-1, pk(z=0)="
-       <<pkcosm<<", pk(z="<<redshift<<")="<<pk<<"\n>>>>"<<endl;
+       <<pkcosm<<", pk(z="<<redshift[0]<<")="<<pk<<"\n>>>>"<<endl;
    for(int i=0;i<3;i++) {  // la correction de variance du au bruit de poisson
      double v = 1.1; if(i==1) v=1.5; if(i==2) v=2.0;
@@ -324,9 +398,11 @@
      cout<<"  pour "<<ngal<<" gal/Mpc^3 on multiplie par "<<v<<" sigma/P"<<endl;
    }
+
+   cout<<endl;
    vector<double> dk; if(dkcosm>0.) dk.push_back(dkcosm);
    dk.push_back(dk_x); dk.push_back(dk_y); dk.push_back(dk_z);
    for(int i=0;i<(int)dk.size();i++) { // la variance cosmique pure
-     double vcosm = sqrt( 2.*pow(2.*M_PI,3.)/(4.*M_PI*pow(kcosm,2.)*dk[i]*vol) );
-     double nmode = 0.5*vol/pow(2.*M_PI,3.) * 4.*M_PI*pow(kcosm,2.)*dk[i];
+     double vcosm = sqrt( 2.*pow(2.*M_PI,3.)/(4.*M_PI*pow(kcosm,2.)*dk[i]*vol_survey) );
+     double nmode = 0.5*vol_survey/pow(2.*M_PI,3.) * 4.*M_PI*pow(kcosm,2.)*dk[i];
      cout<<"  pour dk = "<<dk[i]<<" Mpc^-1:  sigma/P = "<<vcosm
          <<" , Nmode = "<<nmode<<endl;
@@ -334,5 +410,7 @@
  }
 
+ // --- 
  // --- Masse de HI
+ // --- 
  cout<<"\n>>>>\n>>>> Mass HI\n>>>>"<<endl;
  Schechter sch(nstar,mstar,alpha);
@@ -345,10 +423,11 @@
  cout<<"Mass density: "<<masshimpc3<<" Msol/Mpc^3"<<endl;
 
- double masshipix = masshimpc3*dvol;
- double masshitot = masshimpc3*vol;
+ double masshipix = masshimpc3*vol_pixel;
+ double masshitot = masshimpc3*vol_survey;
  cout<<"Pixel mass = "<<masshipix<<" Msol"<<endl
      <<"Total mass in survey = "<<masshitot<<" Msol"<<endl;
- cout<<"OmegaHI a z=0: "<<masshimpc3/rhoc0
-     <<", a z="<<redshift<<": "<<masshimpc3/rhocz<<endl;
+ cout<<"OmegaHI a z=0: "<<masshimpc3/rhoc0<<endl;
+ for(int i=0;i<3;i++)
+   cout<<"        a z="<<redshift[i]<<": "<<masshimpc3/rhocz[i]<<endl;
  if(mhiref<=0.)  mhiref = masshipix;
 
@@ -358,55 +437,75 @@
  for(double x=lnx1; x<lnx2-0.5; x+=1.) {
    double n = IntegrateFuncLog(sch,x,lnx2,0.001,dlnx,10.*dlnx,6);
-   cout<<"  m>"<<x<<" Msol: "<<n<<" /Mpc^3, "<<n*dvol<<" /pixel, "
-       <<n*vol<<" in survey"<<endl;
+   cout<<"  m>"<<x<<" Msol: "<<n<<" /Mpc^3, "<<n*vol_pixel<<" /pixel, "
+       <<n*vol_survey<<" in survey"<<endl;
  }
  sch.SetOutValue(1);
 
-
+ // --- 
  // --- Survey values
+ // --- 
  cout<<"\n>>>>\n>>>> Observations\n>>>>"<<endl;
  double surfeff = surftot * eta_eff;
- double unplusz = 1.+redshift;
- double nuhiz = Fr_HyperFin_Par / unplusz;  // GHz
- // dnu = NuHi/(1.+z0-dz/2) - NuHi/(1.+z0+dz/2)
- //     = NuHi*dz/(1.+z0)^2 * 1/[1-(dz/(2*(1+z0)))^2]
- //    ~= NuHi*dz/(1.+z0)^2
- double dnuhiz = Fr_HyperFin_Par *dred/(unplusz*unplusz)
-               / (1.- pow(dred/.2/unplusz,2.));
- cout<<"      surf="<<surftot<<" m^2, eta="<<eta_eff<<"  surf_eff="<<surfeff<<" m^2, tobs="<<tobs<<" s"<<endl
-     <<"      nu="<<nuhiz<<" GHz, dnu="<<dnuhiz*1.e3<<" Mhz"<<endl;
- cout<<"dang lumi = "<<dlum<<" in ["<<dlumlim[0]<<","<<dlumlim[1]<<"] Mpc"<<endl;
-
- double nlobes = 1.;
+ cout<<"surf_tot="<<surftot<<" m^2, eta="<<eta_eff<<"  surf_eff="<<surfeff<<" m^2, tobs="<<tobs<<" s"<<endl;
+
+ // Angles solides pour un telescope plein
+ double angSEq[4], angEq[4];
+ for(int i=0;i<4;i++) {
+   double nu =Fr_HyperFin_Par;
+   if(i<3) nu = nuhiz[i];
+   angSEq[i] = AngsolEqTelescope(nu,surftot);
+   angEq[i] = 2.*FrAngSol(angSEq[i]);
+ }
+ cout<<"\nFor a "<<surftot<<" m^2 telescope:"<<endl
+     <<"    equivalent Omega = "<<angSEq[0]<<" sr in ["<<angSEq[1]<<","<<angSEq[2]<<"]"<<endl
+     <<"    angular diameter = "<<angEq[0]<<" rd = "<<rad2min(angEq[0])
+     <<"\' in ["<<angEq[2]<<","<<angEq[2]<<"]"<<endl;
+ cout<<"At z=0: equivalent Omega = "<<angSEq[3]<<" sr"<<endl
+     <<"        angular diameter = "<<angEq[3]<<" rd = "<<rad2min(angEq[3])<<"\'"<<endl;
+
+ // Pour une observation ou le lobe est + petit que le pixel de simulation
+ // La taille angulaire du lobe change avec la frequence donc avec le redshift
+ // La taille du lobe "lobewidth" est donnee pour une frequence de reference "lobefreq0"
+ double nlobes[3] = {1.,1.,1.};
  if(lobewidth0>0.) {
-   double lobewidth = lobewidth0;   // ArcMin
-   if(lobefreq0<=0.) lobefreq0 = nuhiz*1.e3; // MHz
-   // La taille angulaire du lobe change avec la frequence donc avec le redshift
-   lobewidth *= lobefreq0/(nuhiz*1.e3);
-   cout<<"\n--- Lobe: width="<<lobewidth0<<" pour "<<lobefreq0<<" MHz"<<endl
-       <<"          changed to "<<lobewidth<<" pour "<<nuhiz*1.e3<<" MHz"<<endl;
-   double slobe = lobewidth/2.35482; // sigma du lobe en arcmin
-   double lobecyl = sqrt(8.)*slobe; // diametre du lobe cylindrique equiv en arcmin
-   double lobearea = M_PI*lobecyl*lobecyl/4.;  // en arcmin^2 (hypothese lobe gaussien)
-   nlobes = rad2min(adtx)*rad2min(adty)/lobearea;
-   cout<<"Beam FWHM = "<<lobewidth<<"\' -> sigma = "<<slobe<<"\' -> "
-       <<" Dcyl = "<<lobecyl<<"\' -> area = "<<lobearea<<" arcmin^2"<<endl;
-   cout<<"Number of beams in one transversal pixel = "<<nlobes<<endl;
- }
-
- // --- Power emitted by HI
- cout<<"\n--- Power from HI for M = "<<mhiref<<" Msol at "<<nuhiz<<" GHz"<<endl;
- cout<<"flux factor = "<<hifactor<<" at redshift = "<<redshift<<endl;
-
- double fhi = hifactor*Msol2FluxHI(mhiref,dlum);
- cout<<"FluxHI("<<dlum<<" Mpc) all polar:"<<endl
-     <<"  Flux= "<<fhi<<" W/m^2 = "<<fhi/Jansky2Watt_cst<<" Jy.Hz"<<endl
-     <<"      in ["<<hifactor*Msol2FluxHI(mhiref,dlumlim[0])
-     <<","<<hifactor*Msol2FluxHI(mhiref,dlumlim[1])<<"] W/m^2"<<endl;
- double sfhi = fhi / (dnuhiz*1e9) / Jansky2Watt_cst;
- cout<<"If spread over pixel depth ("<<dnuhiz<<" GHz), flux density = "<<sfhi*1.e6<<" mu_Jy"<<endl;
-
+   if(lobefreq0<=0.) lobefreq0 = nuhiz[0]*1.e3; // MHz
+   cout<<"\n--- Lobe: width="<<lobewidth0<<"\' pour "<<lobefreq0<<" MHz"<<endl;
+   double lobewidth[3], slobe[3], lobecyl[3], lobearea[3];
+   for(int i=0;i<3;i++) {
+     lobewidth[i] = lobewidth0*lobefreq0/(nuhiz[i]*1.e3); // arcmin
+     slobe[i] = lobewidth[i]/2.35482; // sigma du lobe en arcmin
+     lobecyl[i] = sqrt(8.)*slobe[i]; // diametre du lobe cylindrique equiv en arcmin
+     lobearea[i] = M_PI*lobecyl[i]*lobecyl[i]/4.; // en arcmin^2 (hypothese lobe gaussien)
+     nlobes[i] = rad2min(adtx[i])*rad2min(adty[i])/lobearea[i];
+   }
+   cout<<"Lobe width changed to "<<lobewidth[0]<<"\' pour "<<nuhiz[0]*1.e3<<" MHz"
+       <<" in ["<<lobewidth[1]<<","<<lobewidth[2]<<"]"<<endl;
+   cout<<"Lobe sigma "<<slobe[0]<<"\' in ["<<slobe[1]<<","<<slobe[2]<<"]"<<endl;
+   cout<<"Lobe cylindrique diametre "<<lobecyl[0]<<"\' in ["<<lobecyl[1]<<","<<lobecyl[2]<<"]"<<endl;
+   cout<<"Lobe cylindrique area "<<lobearea[0]<<"\'^2 in ["<<lobearea[1]<<","<<lobearea[2]<<"]"<<endl;
+   cout<<"Number of beams in one transversal pixel "<<nlobes[0]<<" in ["<<nlobes[1]<<","<<nlobes[2]<<"]"<<endl;
+ }
+
+ // --- 
  // --- Signal analysis
- cout<<"\n--- Signal analysis"<<endl;
+ // --- 
+ // --- Temperature d'antenne Ta et temperature de brillance Tb
+ // La puissance d'une source de brillance I non polarisee est:
+ // P = I * S * Omega * dNu
+ // La puissance recue pour une seule polarisation est:
+ // P = 1/2 * I * S * Omega * dNu
+ // La puissance recue pour un telescope (plein) est
+ //    en remplacant Omega = lambda^2/S
+ // P = 1/2 * I * lambda^2 * dNu
+ // En appliquant la loi de Rayleigh: I = 2*k*Tb/lambda^2
+ //   on obtient
+ // P = 1/2 * 2*k*Tb * dNu = k * Tb * dNu
+ // La temperature d'antenne est definie comme
+ // P = k * Ta * dNu
+ // Donc pour un ciel de temperature de brillance Tb
+ //   et pour une antenne qui mesure une seule polarisation
+ // on a: Ta = Tb
+
+ cout<<"\n>>>>\n>>>> Signal Analysis\n>>>>"<<endl;
  cout<<"Facteur polar = "<<facpolar<<endl;
 
@@ -417,59 +516,143 @@
  planck.SetSpectraUnit(PlanckSpectra::ANGSFLUX); // radiance W/m^2/Sr/Hz
 
- // Signal
- double psig_2polar = fhi * surfeff;
- double tsig_2polar = psig_2polar / k_Boltzman_Cst / (dnuhiz*1e9);
- double ssig_2polar = psig_2polar / surfeff / (dnuhiz*1e9) / Jansky2Watt_cst;
- double psig = facpolar * psig_2polar;
- double tsig = facpolar * tsig_2polar;
- double ssig = facpolar * ssig_2polar;
- cout<<"\nSignal("<<mhiref<<" Msol):"<<endl
-     <<"     P="<<psig<<" W"<<endl
-     <<"     flux density = "<<ssig*1.e6<<" mu_Jy  (for Dnu="<<dnuhiz<<" GHz)"<<endl
-     <<"                   ("<<ssig_2polar<<" mu_Jy for 2 polars)"<<endl
-     <<"     Antenna temperature: tsig="<<tsig<<" K"<<endl;
+ // --- 
+ // --- Signal HI
+ // --- 
+ // Power emitted by HI
+ cout<<"--- Power from HI for M = "<<mhiref<<" Msol"<<endl;
+ cout<<"Flux factor = "<<hifactor<<" at redshift = "<<redshift[0]<<endl;
+ cout<<"Luminosite = "<<hifactor*Msol2LumiHI(mhiref)<<" W"<<endl;
+
+ double fhi_ref[3], sfhi_ref[3];
+ for(int i=0;i<3;i++) {
+   fhi_ref[i] = hifactor*Msol2FluxHI(mhiref,dlum[i]);
+   sfhi_ref[i] = fhi_ref[i] / (dnuhiz[i]*1e9) / Jansky2Watt_cst;
+ }
+ cout<<"FluxHI("<<dlum[0]<<" Mpc) all polar: "<<fhi_ref[0]<<" W/m^2 = "
+     <<fhi_ref[0]/Jansky2Watt_cst<<" Jy.Hz"
+     <<" in ["<<fhi_ref[1]/Jansky2Watt_cst<<","<<fhi_ref[2]/Jansky2Watt_cst<<"]"<<endl;
+ cout<<"If spread over pixel depth ("<<dnuhiz[0]<<" GHz):"<<endl
+     <<"  flux density = "<<sfhi_ref[0]*1.e6<<" mu_Jy"
+     <<" in ["<<sfhi_ref[1]<<","<<sfhi_ref[2]<<"]"<<endl;
+
+ // Signal HI
+ double psig_2polar[3], tasig_2polar[3], ssig_2polar[3], isig_2polar[3], tsig_2polar[3];
+ double psig[3], tasig[3], ssig[3], isig[3], tsig[3];
+ double doplarge[3], dzvrot[3];
+ 
+ for(int i=0;i<3;i++) {
+   psig_2polar[i] = fhi_ref[i] * surfeff;
+   tasig_2polar[i] = psig_2polar[i] / k_Boltzman_Cst / (dnuhiz[i]*1e9);
+   ssig_2polar[i] = psig_2polar[i] / surfeff / (dnuhiz[i]*1e9) / Jansky2Watt_cst;
+   isig_2polar[i] = ssig_2polar[i] / angsol_pix[i];
+   tsig_2polar[i] = isig_2polar[i]*Jansky2Watt_cst
+                    / (2.*pow(nuhiz[i]*1e9/(SpeedOfLight_Cst*1000.),2.)*k_Boltzman_Cst);
+   psig[i] = facpolar * psig_2polar[i];
+   tasig[i] = facpolar * tasig_2polar[i];
+   ssig[i] = facpolar * ssig_2polar[i];
+   isig[i] = facpolar * isig_2polar[i];
+   tsig[i] = facpolar * tsig_2polar[i];
+   doplarge[i] = LargeurDoppler(vrot,nuhiz[i]);
+   dzvrot[i] = DzFrV(vrot,redshift[i]);
+ }
+ cout<<"\n--- Signal HI("<<mhiref<<" Msol) for Dnu="<<dnuhiz[0]<<" GHz :"<<endl
+     <<" Observation:"<<endl
+     <<"    Power="<<psig[0]<<" W in ["<<psig[1]<<","<<psig[2]<<"]"<<endl
+     <<"    Flux density = "<<ssig[0]*1.e6<<" mu_Jy in ["<<ssig[1]*1.e6<<","<<ssig[2]*1.e6<<"]"<<endl
+     <<"    Intensity = "<<isig[0]<<" Jy/sr in ["<<isig[1]<<","<<isig[2]<<"]"<<endl
+     <<"    Antenna temperature = "<<tasig[0]<<" K in ["<<tasig[1]<<","<<tasig[2]<<"]"<<endl
+     <<"    Brightness temperature = "<<tsig[0]<<" K in ["<<tsig[1]<<","<<tsig[2]<<"]"<<endl
+     <<" 2 polars:"<<endl
+     <<"    Power="<<psig_2polar[0]<<" W in ["<<psig_2polar[1]<<","<<psig_2polar[2]<<"]"<<endl
+     <<"    Flux density = "<<ssig_2polar[0]*1.e6<<" mu_Jy in ["<<ssig_2polar[1]*1.e6<<","<<ssig_2polar[2]*1.e6<<"]"<<endl
+     <<"    Intensity = "<<isig_2polar[0]<<" Jy/sr in ["<<isig_2polar[1]<<","<<isig_2polar[2]<<"]"<<endl
+     <<"    Antenna temperature = "<<tasig_2polar[0]<<" K in ["<<tasig_2polar[1]<<","<<tasig_2polar[2]<<"]"<<endl
+     <<"    Brightness temperature = "<<tsig_2polar[0]<<" K in ["<<tsig_2polar[1]<<","<<tsig_2polar[2]<<"]"<<endl;
 
  // Elargissement doppler de la raie a 21cm: dNu = vrot/C * Nu(21cm) / (1+z)
- double doplarge = vrot / SpeedOfLight_Cst * nuhiz;
- double dzvrot = vrot / SpeedOfLight_Cst * unplusz;
- cout<<"     Doppler width="<<doplarge*1.e3<<" MHz  for rotation width of "<<vrot<<" km/s"<<endl
-     <<"                 dx= "<<dzvrot<<" a z="<<redshift<<endl;
- if(doplarge>dnuhiz)
-   cout<<"Warning: doppler width "<<doplarge<<" GHz > "<<dnuhiz<<" GHz redshift bin width"<<endl;
-
- // Synchrotron  (T en -2.7  -> Flux en -0.7  dans l'approximation Rayleigh)
- double tsynch = Tsynch408;
-        if(fabs(indnu)>1.e-50) tsynch *= pow(nuhiz/nuhaslam,indnu);
- planck.SetTemperature(tsynch);
- double psynch_2polar = planck(nuhiz*1.e+9) * surfeff * angsol * (dnuhiz*1e9);
- double ssynch_2polar = psynch_2polar / surfeff / (dnuhiz*1e9) / Jansky2Watt_cst;
- double psynch = facpolar * psynch_2polar;
- double ssynch = facpolar * ssynch_2polar;
- cout<<"\nSynchrotron: T="<<Tsynch408<<" K ("<<nuhaslam<<" GHz), "
-     <<tsynch<<" K ("<<nuhiz<<" GHz)"<<endl
-     <<"             P="<<psynch<<" W for pixel"<<endl
-     <<"             flux density = "<<ssynch<<" Jy for pixel solid angle"<<endl;
-
- // CMB
- double tcmb = T_CMB_Par;
+ cout<<"    Doppler for rotation width of "<<vrot<<" km/s"<<endl
+     <<"            width="<<doplarge[0]*1.e3<<" MHz  in ["<<doplarge[1]*1.e3<<","<<doplarge[2]*1.e3<<"]"<<endl
+     <<"            dzvrot= "<<dzvrot[0]<<" in ["<<dzvrot[1]<<","<<dzvrot[2]<<"]"<<endl;
+ if(doplarge[0]>dnuhiz[0])
+   cout<<"Warning: doppler width "<<doplarge[0]<<" GHz > "<<dnuhiz[0]<<" GHz redshift bin width"<<endl;
+
+ // --- 
+ // --- Synchrotron  (T en -2.7  -> Flux en -0.7  dans l'approximation Rayleigh)
+ // --- 
+ double tsynch[3];
+ double psynch_2polar[3], tasynch_2polar[3], ssynch_2polar[3], isynch_2polar[3];
+ double psynch[3], tasynch[3], ssynch[3], isynch[3];
+
+ for(int i=0;i<3;i++) {
+   tsynch[i] = Tsynch408;
+   if(fabs(indnu)>1.e-50) tsynch[i] *= pow(nuhiz[i]/nuhaslam,indnu);
+   planck.SetTemperature(tsynch[i]);
+   psynch_2polar[i] = planck(nuhiz[i]*1.e+9) * surfeff * angsol_pix[i] * (dnuhiz[i]*1e9);
+   tasynch_2polar[i] = psynch_2polar[i] / k_Boltzman_Cst / (dnuhiz[i]*1e9);
+   ssynch_2polar[i] = psynch_2polar[i] / surfeff / (dnuhiz[i]*1e9) / Jansky2Watt_cst;
+   isynch_2polar[i] = ssynch_2polar[i] / angsol_pix[i];
+   psynch[i] = facpolar * psynch_2polar[i];
+   tasynch[i] = facpolar * tasynch_2polar[i];
+   ssynch[i] = facpolar * ssynch_2polar[i];
+   isynch[i] = ssynch[i] / angsol_pix[i];
+ }
+ cout<<"\n--- Synchrotron: T="<<Tsynch408<<" K ("<<nuhaslam<<" GHz), "<<endl
+     <<"    tsynch="<<tsynch[0]<<" K ("<<nuhiz[0]<<" GHz) in ["<<tsynch[1]<<","<<tsynch[2]<<"]"<<endl
+     <<" Observation:"<<endl
+     <<"    Power="<<psynch[0]<<" W for pixel in ["<<psynch[1]<<","<<psynch[2]<<"]"<<endl
+     <<"    Flux density = "<<ssynch[0]<<" Jy for pixel solid angle in ["<<ssynch[1]<<","<<ssynch[2]<<"]"<<endl
+     <<"    Intensity = "<<isynch[0]<<" Jy/sr in ["<<isynch[1]<<","<<isynch[2]<<"]"<<endl
+     <<"    Antenna temperature = "<<tasynch[0]<<" K in ["<<tasynch[1]<<","<<tasynch[2]<<"]"<<endl
+     <<" 2 polars:"<<endl
+     <<"    Power="<<psynch_2polar[0]<<" W for pixel in ["<<psynch_2polar[1]<<","<<psynch_2polar[2]<<"]"<<endl
+     <<"    Flux density = "<<ssynch_2polar[0]<<" Jy for pixel solid angle in ["<<ssynch_2polar[1]<<","<<ssynch_2polar[2]<<"]"<<endl
+     <<"    Intensity = "<<isynch_2polar[0]<<" Jy/sr in ["<<isynch_2polar[1]<<","<<isynch_2polar[2]<<"]"<<endl
+     <<"    Antenna temperature = "<<tasynch_2polar[0]<<" K in ["<<tasynch_2polar[1]<<","<<tasynch_2polar[2]<<"]"<<endl;
+
+ // --- 
+ // --- CMB
+ // --- 
  planck.SetTemperature(tcmb);
- double pcmb_2polar = planck(nuhiz*1.e+9) * surfeff * angsol * (dnuhiz*1e9);
- double scmb_2polar = pcmb_2polar / surfeff / (dnuhiz*1.e+9) / Jansky2Watt_cst;
- double pcmb = facpolar * pcmb_2polar;
- double scmb = facpolar * scmb_2polar;
- cout<<"\nCMB: T="<<tcmb<<" K"<<endl
-     <<"     P="<<pcmb<<" W for pixel"<<endl
-     <<"     flux density = "<<scmb<<" Jy for pixel solid angle"<<endl;
-
- // AGN
+ double pcmb_2polar[3], tacmb_2polar[3], scmb_2polar[3], icmb_2polar[3];
+ double pcmb[3], tacmb[3], scmb[3], icmb[3];
+
+ for(int i=0;i<3;i++) {
+   pcmb_2polar[i] = planck(nuhiz[i]*1.e+9) * surfeff * angsol_pix[i] * (dnuhiz[i]*1e9);
+   tacmb_2polar[i] = pcmb_2polar[i] / k_Boltzman_Cst / (dnuhiz[i]*1e9);
+   scmb_2polar[i] = pcmb_2polar[i] / surfeff / (dnuhiz[i]*1e9) / Jansky2Watt_cst;
+   icmb_2polar[i] = scmb_2polar[i] / angsol_pix[i];
+   pcmb[i] = facpolar * pcmb_2polar[i];
+   tacmb[i] = facpolar * tacmb_2polar[i];
+   scmb[i] = facpolar * scmb_2polar[i];
+   icmb[i] = scmb[i] / angsol_pix[i];
+ }
+ cout<<"\n--- CMB: T="<<tcmb<<" K"<<endl
+     <<" Observation:"<<endl
+     <<"    Power="<<pcmb[0]<<" W for pixel in ["<<pcmb[1]<<","<<pcmb[2]<<"]"<<endl
+     <<"    Flux density = "<<scmb[0]<<" Jy for pixel solid angle in ["<<scmb[1]<<","<<scmb[2]<<"]"<<endl
+     <<"    Intensity = "<<icmb[0]<<" Jy/sr in ["<<icmb[1]<<","<<icmb[2]<<"]"<<endl
+     <<"    Antenna temperature = "<<tacmb[0]<<" K in ["<<tacmb[1]<<","<<tacmb[2]<<"]"<<endl
+     <<" 2 polars:"<<endl
+     <<"    Power="<<pcmb_2polar[0]<<" W for pixel in ["<<pcmb_2polar[1]<<","<<pcmb_2polar[2]<<"]"<<endl
+     <<"    Flux density = "<<scmb_2polar[0]<<" Jy for pixel solid angle in ["<<scmb_2polar[1]<<","<<scmb_2polar[2]<<"]"<<endl
+     <<"    Intensity = "<<icmb_2polar[0]<<" Jy/sr in ["<<icmb_2polar[1]<<","<<icmb_2polar[2]<<"]"<<endl
+     <<"    Antenna temperature = "<<tacmb_2polar[0]<<" K in ["<<tacmb_2polar[1]<<","<<tacmb_2polar[2]<<"]"<<endl;
+
+ // --- 
+ // --- AGN
+ // --- 
  double flux_agn = pow(10.,lflux_agn);
- double mass_agn = FluxHI2Msol(flux_agn*Jansky2Watt_cst,dlum);
- cout<<"\nAGN: log10(S_agn)="<<lflux_agn<<" -> S_agn="
-     <<flux_agn<<" Jy -> "<<mass_agn<<" equiv. Msol/Hz"<<endl;
- double flux_agn_pix = flux_agn*(dnuhiz*1e9);
- double mass_agn_pix = FluxHI2Msol(flux_agn_pix*Jansky2Watt_cst,dlum);
- double lmass_agn_pix = log10(mass_agn_pix);
- cout<<"...pixel: f="<<flux_agn_pix<<" 10^-26 W/m^2"
-     <<" -> "<<mass_agn_pix<<" Msol -> log10 = "<<lmass_agn_pix<<endl;
+ double mass_agn[3], flux_agn_pix[3], mass_agn_pix[3], lmass_agn_pix[3];
+ for(int i=0;i<3;i++) {
+   mass_agn[i] = FluxHI2Msol(flux_agn*Jansky2Watt_cst,dlum[i]);
+   flux_agn_pix[i] = flux_agn*(dnuhiz[i]*1e9);
+   mass_agn_pix[i] = FluxHI2Msol(flux_agn_pix[i]*Jansky2Watt_cst,dlum[i]);
+   lmass_agn_pix[i] = log10(mass_agn_pix[i]);
+ }
+ cout<<"\n--- AGN: log10(S_agn)="<<lflux_agn<<"   S_agn="<<flux_agn<<" Jy :"<<endl
+     <<"  mass_agn = "<<mass_agn[0]<<" equiv. Msol/Hz in ["<<mass_agn[1]<<","<<mass_agn[2]<<"]"<<endl
+     <<"  flux_agn_pix = "<<flux_agn_pix[0]<<" 10^-26 W/m^2 in ["<<flux_agn_pix[1]<<","<<flux_agn_pix[2]<<"]"<<endl
+     <<"  mass_agn_pix = "<<mass_agn_pix[0]<<" Msol in ["<<mass_agn_pix[1]<<","<<mass_agn_pix[2]<<"]"<<endl
+     <<"  log10(mass_agn_pix) = "<<lmass_agn_pix[0]<<"  in ["<<lmass_agn_pix[1]<<","<<lmass_agn_pix[2]<<"]"<<endl;
 
  // =====================================================================
@@ -541,7 +724,9 @@
  // =====================================================================
 
- cout<<"\n---\n--- Noise analysis \n---"<<endl;
- double psys = k_Boltzman_Cst * Tsys * (dnuhiz*1.e+9);
- cout<<"Noise: T="<<Tsys<<" K, P="<<psys<<" W  (for Dnu="<<dnuhiz<<" GHz)"<<endl;
+ cout<<"\n>>>>\n>>>> Noise analysis\n>>>>"<<endl;
+ double psys[3];
+ for(int i=0;i<3;i++) psys[i] = k_Boltzman_Cst * Tsys * (dnuhiz[i]*1.e+9);
+ cout<<"Noise: T="<<Tsys<<" K"<<endl
+     <<"       P="<<psys[0]<<" W in ["<<psys[1]<<","<<psys[2]<<"]"<<endl;
 
  cout<<"...Computation assume that noise dominate the signal."<<endl;
@@ -549,5 +734,4 @@
    cout<<"...Assuming 2 polarisations measurements with 2 different electronics."<<endl;
 
- double slim,slim_nl,SsN,SsN_nl,smass,smass_nl;
 
  //---
@@ -566,24 +750,123 @@
    } else continue;
 
-   slim = 2. * k_Boltzman_Cst * Tsys / surfeff
-               / sqrt(fac*(dnuhiz*1.e+9)*tobs) /Jansky2Watt_cst;
-   if(ya2polar) slim /= sqrt(2.);
-   SsN = ssig_2polar / slim;
-   smass = mhiref / ssig_2polar * slim;
+   double slim[3], SsN[3], smass[3], pkbruit[3];
+   for(int i=0;i<3;i++) {
+     slim[i] = 2. * k_Boltzman_Cst * Tsys / surfeff
+               / sqrt(fac*(dnuhiz[i]*1.e+9)*tobs) /Jansky2Watt_cst;
+     if(ya2polar) slim[i] /= sqrt(2.);
+     SsN[i] = ssig_2polar[i] / slim[i];  // independant de  angsol_pix*surfeff
+     smass[i] = mhiref / ssig_2polar[i] * slim[i];
+     pkbruit[i] = pow(smass[i]/mhiref,2.)*vol_pixel;
+   }
    cout<<"for 1 lobe:"<<endl
-       <<"   Slim    = "<<slim*1.e6<<" mu_Jy"<<endl
-       <<"   S/N     = "<<SsN<<endl
-       <<"   Mass HI = "<<smass<<" Msol"<<endl;
-
-   slim_nl = slim * sqrt(nlobes);
-   SsN_nl = ssig_2polar / slim_nl;
-   smass_nl = mhiref / ssig_2polar * slim_nl;
-   cout<<"for "<<nlobes<<" lobes:"<<endl
-       <<"   Flux    = "<<slim_nl*1.e6<<" mu_Jy"<<endl
-       <<"   S/N     = "<<SsN_nl<<endl
-       <<"   Mass HI = "<<smass_nl<<" Msol"<<endl;
+       <<"   Slim    = "<<slim[0]*1.e6<<" mu_Jy in ["<<slim[1]*1.e6<<","<<slim[2]*1.e6<<"]"<<endl
+       <<"   S/N     = "<<SsN[0]<<" in ["<<SsN[1]<<","<<SsN[2]<<"]"<<endl
+       <<"   Mass HI = "<<smass[0]<<" Msol in ["<<smass[1]<<","<<smass[2]<<"]"<<endl
+       <<"   Pk      = "<<pkbruit[0]<<" Mpc^3 in ["<<pkbruit[1]<<","<<pkbruit[2]<<"]"<<endl;
+
+   if(fabs(nlobes[0]-1.)>1e-6) {
+     double slim_nl[3], SsN_nl[3], smass_nl[3], pkbruit_nl[3];
+     for(int i=0;i<3;i++) {
+       slim_nl[i] = slim[i] * sqrt(nlobes[i]);
+       SsN_nl[i] = ssig_2polar[i] / slim_nl[i];
+       smass_nl[i] = mhiref / ssig_2polar[i] * slim_nl[i];
+       pkbruit_nl[i] = pow(smass_nl[i]/mhiref,2.)*vol_pixel;
+     }
+     cout<<"for "<<nlobes[0]<<" lobes[i] in ["<<nlobes[1]<<","<<nlobes[2]<<"] :"<<endl
+       <<"   Slim    = "<<slim_nl[0]*1.e6<<" mu_Jy in ["<<slim_nl[1]*1.e6<<","<<slim_nl[2]*1.e6<<"]"<<endl
+       <<"   S/N     = "<<SsN_nl[0]<<" in ["<<SsN_nl[1]<<","<<SsN_nl[2]<<"]"<<endl
+       <<"   Mass HI = "<<smass_nl[0]<<" Msol in ["<<smass_nl[1]<<","<<smass_nl[2]<<"]"<<endl
+       <<"   Pk      = "<<pkbruit_nl[0]<<" Mpc^3 in ["<<pkbruit_nl[1]<<","<<pkbruit_nl[2]<<"]"<<endl;
+   }
 
  }
 
  return 0;
+ }
+
+
+//-------------------------------------------------------------------------------------------
+double LargeurDoppler(double v, double nu)
+// largeur doppler pour une vitesse v en km/s et une frequence nu
+{
+ return v / SpeedOfLight_Cst * nu;
 }
+
+double DzFrV(double v, double zred)
+// largeur en redshift pour une vitesse v en km/s au redshift zred
+{
+  return v / SpeedOfLight_Cst * (1. + zred);
+}
+
+double DNuFrDz(double dzred,double nu_at_0,double zred)
+// Largeur DNu pour une largeur en redshift "dzred" au redshift "zred"
+//    pour la frequence "nu_at_0" a z=0
+// nu =  NuHi(z=0)/(1.+z0)
+// dnu = NuHi(z=0)/(1.+z0-dz/2) - NuHi/(1.+z0+dz/2)
+//     = NuHi(z=0)*dz/[ (1+z0)^2 - (dz/2)^2 ]
+//     = NuHi(z=0)*dz/(1.+z0)^2 / [ 1 - [dz/(1+z0)/2)]^2 ]
+//     = NuHi(z=0)*dz/(1.+z0)^2 / [1 - dz/(1+z0)/2] / [1 + dz/(1+z0)/2]
+//    ~= NuHi(z=0)*dz/(1.+z0)^2   (approx. pour dz<<z0 a l'ordre (dz/z0)^2)
+{
+  double zp1 = 1.+zred;
+  return nu_at_0*dzred/(zp1*zp1)/(1.-dzred/zp1/2.)/(1.+dzred/zp1/2.);
+}
+
+double DzFrDNu(double dnu_at_0,double nu_at_0,double zred)
+// Largeur en redshift au redshift "zred" pour une largeur
+// en frequence "dnu_at_0" a la frequence "nu_at_0" a z=0
+{
+  if(dnu_at_0<=0.) return 0.;
+  double zp1 = 1.+zred;
+  double dnusnu0 = dnu_at_0/nu_at_0;
+  return 2./dnusnu0 * (sqrt(1.+(dnusnu0*zp1)*(dnusnu0*zp1)) - 1.);
+}
+double DzFrDNuApprox(double dnu_at_0,double nu_at_0,double zred)
+// idem DzFrDNu mais on utilise l'approximation: dnu=NuHi(z=0)*dz/(1.+z0)^2
+{
+  double zp1 = 1.+zred;
+  return dnu_at_0/nu_at_0 *(zp1*zp1);
+}
+
+double ZFrLos(double loscom,CosmoCalc& univ)
+// Recherche du redshift correspondant a une distance comobile
+// le long de la ligne de visee egale a "loscom" Mpc
+// et pour un univers "univ"
+{
+  double dz = univ.ZMax()/10.; if(dz<=0.) dz = 0.1;
+  double zmin=0., zmax=0.;
+  while(univ.Dloscom(zmax)<loscom) zmax += dz;
+  if(zmax==0.) return 0.;
+  for(int i=0; i<6; i++) {
+    zmin=zmax-dz; if(zmin<0.) zmin=0.;
+    dz /= 10.;
+    for(double z=zmin; z<zmax+dz; z+=dz) {
+      double d = univ.Dloscom(z);
+      if(d<loscom) continue;
+      zmax = z;
+      //cout<<"ZFrLos: z="<<zmax<<" d="<<d<<" / "<<loscom<<endl;
+      break;
+    }
+  }
+  return zmax;
+}
+
+double AngsolEqTelescope(double nu /* GHz */,double telsurf /* m^2 */)
+/*
+Calcul de l'angle solide (sr) equivalent pour un telescope
+de surface totale "telsurf" (m^2) a la frequence "nu" (GHz)
+- Soit D(t) la figure de diffraction du telescope telle que D(t=0)=1
+       (t = angle depuis l'axe optique)
+  telescope circulaire de diametre D:
+      D(t) = [2J1(Pi*D*t/l)/(Pi*D*t/l)]
+  telescope rectangulaire axb:
+      D(t) = [sin(Pi*a*t/l)/(Pi*a*t/l)]*[sin(Pi*b*t/l)/(Pi*b*t/l)]
+- On cherche l'angle solide equivalent (par ex d'un cylindre de hauteur 1)
+  Int[ D(t)^2 dOmega ] =  Int[ D(t)^2 2Pi t dt ] = Lambda^2/S
+- En conclusion, pour un ciel d'intensite uniforme I, on a:
+  P = I * S * Omega * dNu = I * S * (Lambda^2/S) * dNu
+*/
+{
+  double lambda = SpeedOfLight_Cst*1000./(nu*1.e9);
+  return lambda*lambda / telsurf;
+}
Index: /trunk/Cosmo/SimLSS/genefluct3d.cc
===================================================================
--- /trunk/Cosmo/SimLSS/genefluct3d.cc	(revision 3364)
+++ /trunk/Cosmo/SimLSS/genefluct3d.cc	(revision 3365)
@@ -1208,4 +1208,7 @@
 
 double GeneFluct3D::TurnFluct2MeanNumber(double val_by_mpc3)
+// ATTENTION: la gestion des pixels<0 proposee ici induit une perte de variance
+// sur la carte, le spectre Pk reconstruit sera plus faible!
+// L'effet sera d'autant plus grand que le nombre de pixels<0 sera grand.
 {
  if(lp_>0) cout<<"--- TurnFluct2MeanNumber : "<<val_by_mpc3<<" quantity (gal or mass)/Mpc^3"<<endl;
Index: /trunk/Cosmo/SimLSS/geneutils.cc
===================================================================
--- /trunk/Cosmo/SimLSS/geneutils.cc	(revision 3364)
+++ /trunk/Cosmo/SimLSS/geneutils.cc	(revision 3365)
@@ -278,30 +278,17 @@
 //               dtheta in [0,Pi]
 // Return: l'angle solide en steradian
-// Approx pour theta petit: PI theta^2
+// Approx pour theta petit: PI * theta^2
 {
   return   2.*M_PI * (1.-cos(dtheta));
 }
 
-//-------------------------------------------------------------------
-unsigned long PoissRandLimit(double mu,double mumax)
-{
-  double pp,ppi,x;
-  unsigned long n;
-
-  if(mu>=mumax) {
-    pp = sqrt(mu);
-    while( (x=pp*NorRand()) < -mu );
-    return (unsigned long)(mu+x+0.5);
-  }
-
-  ppi = pp = exp(-mu);
-  x = drand01();
-  n = 0;
-  while (x > ppi) {
-    n++;
-    pp = mu*pp/(double)n;
-    ppi += pp;
-  }
-  return n;
+double FrAngSol(double angsol)
+// Retourne la demi-ouverture "dtheta" d'une calotte spherique d'angle solide "angsol"
+// Input: angle solide de la calotte spherique en steradians
+// Return: demi-ouverture de la calotte spherique en radians
+{
+  angsol = 1. - angsol/(2.*M_PI);
+  if(angsol<-1. || angsol>1.) return -1.;
+  return acos(angsol);
 }
 
Index: /trunk/Cosmo/SimLSS/geneutils.h
===================================================================
--- /trunk/Cosmo/SimLSS/geneutils.h	(revision 3364)
+++ /trunk/Cosmo/SimLSS/geneutils.h	(revision 3365)
@@ -86,7 +86,5 @@
 double AngSol(double dtheta,double dphi,double theta0=M_PI/2.);
 double AngSol(double dtheta);
-
-//----------------------------------------------------
-unsigned long PoissRandLimit(double mu,double mumax=10.);
+double FrAngSol(double angsol);
 
 //----------------------------------------------------
Index: /trunk/Cosmo/SimLSS/schechter.cc
===================================================================
--- /trunk/Cosmo/SimLSS/schechter.cc	(revision 3364)
+++ /trunk/Cosmo/SimLSS/schechter.cc	(revision 3365)
@@ -429,4 +429,13 @@
 //******************* Le Flux a 21cm ********************//
 ///////////////////////////////////////////////////////////
+double Msol2LumiHI(double m)
+// Input:
+//    m : masse de HI en "Msol"
+// Return:
+//    la luminosite en W
+// L(m) =  2.393e+18* m(en masse solaire) en W
+{
+  return 2.393e+18 * m;
+}
 
 double Msol2FluxHI(double m,double d)
Index: /trunk/Cosmo/SimLSS/schechter.h
===================================================================
--- /trunk/Cosmo/SimLSS/schechter.h	(revision 3364)
+++ /trunk/Cosmo/SimLSS/schechter.h	(revision 3365)
@@ -93,4 +93,5 @@
 
 //-----------------------------------------------------------------------------------
+double Msol2LumiHI(double m);
 double Msol2FluxHI(double m,double d);
 double FluxHI2Msol(double f,double d);
