Index: /trunk/Cosmo/RadioBeam/calcpk2.cc
===================================================================
--- /trunk/Cosmo/RadioBeam/calcpk2.cc	(revision 3985)
+++ /trunk/Cosmo/RadioBeam/calcpk2.cc	(revision 3986)
@@ -7,5 +7,5 @@
     R. Ansari , C. Magneville - Juin 2010 
 
-Usage: calcpk2 [-t -g] InMapLSS convFacLSS InMapSync convFacSync InMapRadioSource convFacRsc OutPkFile 
+Usage: calcpk2 [-t -g -mxr val] InMapLSS convFacLSS InMapSync convFacSync InMapRadioSource convFacRsc OutPkFile 
                [PixNoiseLevel] [Diameter/Four2DRespTableFile] [TargetBeamArcmin] [NSigSrcThr]
 ---------------------------------------------------------------  */
@@ -44,9 +44,10 @@
 {
   if ( (narg<6)||((narg>1)&&(strcmp(arg[1],"-h")==0)) ) {
-    cout << " Usage: [-t -g] calcpk2 InMapLSS convFacLSS InMapFgnd convFacFgnd OutPkFile \n" 
+    cout << " Usage: [-t -g -mxr val] calcpk2 InMapLSS convFacLSS InMapFgnd convFacFgnd OutPkFile \n" 
          << "        [PixNoiseLevel] [D_Dish/Four2DRespTableFile CorBeamDiam] \n"
 	 << "        [NSigSrcThr] [P2/P1] [RecMapFile] " << endl;
     if ((narg>1)&&(strcmp(arg[1],"-h")==0)) {
       cout << "-t -g : Triangular / gaussian beam shape (def=gaussian) \n" 
+	   << "-mxr val: Max beam correction factor (default=10.) \n "
 	   << "- InMapLSS: Input 3D LSS cube (PPF file name) \n "
 	   << "- convFacLSS: LSS cube conversion factor to mK (milliKelvin) \n"
@@ -78,8 +79,10 @@
     // decodage argument optionnel 
     bool fgoptarg=true;
+    double maxratio=10.;
     while (fgoptarg) {
       string fbo = arg[1];
       if (fbo=="-t")  { fggaussian=false; arg++; narg--; }
       else if (fbo=="-g")  { fggaussian=true; arg++; narg--; }
+      else if (fbo=="-mxr")  { arg++; maxratio=atof(arg[1]); arg++; narg-=2; }
       else fgoptarg=false;
     }
@@ -197,5 +200,5 @@
     Four2DResponse tbeam(typcb, DoL, DoL );
 
-    ForegroundCleaner  cleaner(*arep_p, tbeam, skycube); 
+    ForegroundCleaner  cleaner(*arep_p, tbeam, skycube, maxratio); 
     if (fgcorrbeam) {
       cout << "calcpk2[3.b] : calling cleaner.BeamCorrections() for target beam Diameter=" << tbeamDiam  
Index: /trunk/Cosmo/RadioBeam/fgndsub.cc
===================================================================
--- /trunk/Cosmo/RadioBeam/fgndsub.cc	(revision 3985)
+++ /trunk/Cosmo/RadioBeam/fgndsub.cc	(revision 3986)
@@ -14,6 +14,6 @@
 
 /* --Methode-- */
-ForegroundCleaner::ForegroundCleaner(Four2DResponse& arrep, Four2DResponse& tbeam, TArray< TF >& skycube)
-  : arrep_(arrep) , tbeam_(tbeam), skycube_(skycube)
+ForegroundCleaner::ForegroundCleaner(Four2DResponse& arrep, Four2DResponse& tbeam, TArray< TF >& skycube, double maxratio)
+  : arrep_(arrep) , tbeam_(tbeam), skycube_(skycube), maxratio_(maxratio)
 {
   double dxdeg = ThetaSizeDegre/(double)NTheta;
@@ -32,6 +32,6 @@
 {
   BeamEffect beam(arrep_);
-  beam.Correct2RefLobe(tbeam_, skycube_, dx_, dy_, freq0_, dfreq_);
-  cout << " ForegroundCleaner::BeamCorrections() done " << endl;
+  beam.Correct2RefLobe(tbeam_, skycube_, dx_, dy_, freq0_, dfreq_, maxratio_);
+  cout << " ForegroundCleaner::BeamCorrections() done Maxratio=" << maxratio_ << endl;
 }
 
Index: /trunk/Cosmo/RadioBeam/fgndsub.h
===================================================================
--- /trunk/Cosmo/RadioBeam/fgndsub.h	(revision 3985)
+++ /trunk/Cosmo/RadioBeam/fgndsub.h	(revision 3986)
@@ -25,5 +25,5 @@
 class ForegroundCleaner {
 public:
-  ForegroundCleaner(Four2DResponse& arrep, Four2DResponse& tbeam, TArray< TF >& skycube);
+  ForegroundCleaner(Four2DResponse& arrep, Four2DResponse& tbeam, TArray< TF >& skycube, double maxratio=10.);
   void BeamCorrections();
   int CleanNegatives(TF seuil=1.e-6);
@@ -37,4 +37,5 @@
   Four2DResponse& tbeam_;    // Target beam to which would be corrected using BeamCorrections()
   TArray< TF > skycube_;
+  double maxratio_;
   double dx_, dy_;   // taille des pixels (radians) de skycube
   double freq0_, dfreq_;    // 1ere frequence et bin en frequence de skycube_;
Index: /trunk/Cosmo/RadioBeam/lobe.cc
===================================================================
--- /trunk/Cosmo/RadioBeam/lobe.cc	(revision 3985)
+++ /trunk/Cosmo/RadioBeam/lobe.cc	(revision 3986)
@@ -85,5 +85,5 @@
 
 /* --Methode-- */
-void BeamEffect::Correct2RefLobe(Four2DResponse& rep, TArray< TF >& a, double dx, double dy, double f0, double df)
+void BeamEffect::Correct2RefLobe(Four2DResponse& rep, TArray< TF >& a, double dx, double dy, double f0, double df, double maxratio)
 // dx, dy en radioans, f0, df en MHz
 {
@@ -103,5 +103,5 @@
     conv.setFrequency(f0+kz*df);
     fresp_.setLambda(conv.getLambda());
-    Four2DRespRatio rratio(rep, fresp_);
+    Four2DRespRatio rratio(rep, fresp_, maxratio);
     ApplyLobeK2D(rratio, fourAmp, dkx, dky);
     ffts.FFTBackward(fourAmp, slice, true);
Index: /trunk/Cosmo/RadioBeam/lobe.h
===================================================================
--- /trunk/Cosmo/RadioBeam/lobe.h	(revision 3985)
+++ /trunk/Cosmo/RadioBeam/lobe.h	(revision 3986)
@@ -36,5 +36,5 @@
 
   // Corrige de l'effet de l'effet de lobe, pour chaque plan de frequence, pour tout ramener au lobe defini par "rep" 
-  void Correct2RefLobe(Four2DResponse& rep, TArray< TF >& a, double dx, double dy, double f0, double df);
+  void Correct2RefLobe(Four2DResponse& rep, TArray< TF >& a, double dx, double dy, double f0, double df, double maxratio=10.);
 
   // Applique l'effet de lobe "rep" dans le plan de Fourier  pour une frequence (longueur d'onde) fixee
Index: /trunk/Cosmo/RadioBeam/mdish.cc
===================================================================
--- /trunk/Cosmo/RadioBeam/mdish.cc	(revision 3985)
+++ /trunk/Cosmo/RadioBeam/mdish.cc	(revision 3986)
@@ -167,6 +167,6 @@
 // -- Four2DRespRatio : rapport de la reponse entre deux objets Four2DResponse
 //---------------------------------------------------------------
-Four2DRespRatio::Four2DRespRatio(Four2DResponse& a, Four2DResponse& b, double divzthr)
-  : Four2DResponse(0, a.D(), a.D()), a_(a), b_(b), divzthr_(divzthr)
+Four2DRespRatio::Four2DRespRatio(Four2DResponse& a, Four2DResponse& b, double maxratio)
+  : Four2DResponse(0, a.D(), a.D()), a_(a), b_(b), maxratio_(maxratio)
 {
 }
@@ -177,9 +177,11 @@
   double rb = b_.Value(kx,ky);
   if (ra<rb) {
-    if (rb>1.e-39)  return(ra/rb);  
+    if (rb>1.e-9)  return(ra/rb);  
     else return 0.;
   }
-  if (rb<divzthr_)  rb=divzthr_;
-  return (ra/rb);
+  double rval=1.;
+  if (rb<1.e-9) rval=ra/rb;
+  if (rval<maxratio_) return rval;
+  return maxratio_;
 }
 
Index: /trunk/Cosmo/RadioBeam/mdish.h
===================================================================
--- /trunk/Cosmo/RadioBeam/mdish.h	(revision 3985)
+++ /trunk/Cosmo/RadioBeam/mdish.h	(revision 3986)
@@ -90,10 +90,10 @@
 class Four2DRespRatio : public  Four2DResponse {
 public:
-  Four2DRespRatio(Four2DResponse& a, Four2DResponse& b, double divzthr=5.e-2);
+  Four2DRespRatio(Four2DResponse& a, Four2DResponse& b, double maxratio=10.);
   // Return the ratio a.Value(kx,ky) / b.Value(kx, ky) - with protection against divide by zero 
   virtual double Value(double kx, double ky); 
   Four2DResponse& a_;
   Four2DResponse& b_;
-  double divzthr_;
+  double maxratio_;
 };
 
Index: /trunk/Cosmo/RadioBeam/subtractradsrc.cmd
===================================================================
--- /trunk/Cosmo/RadioBeam/subtractradsrc.cmd	(revision 3985)
+++ /trunk/Cosmo/RadioBeam/subtractradsrc.cmd	(revision 3986)
@@ -17,4 +17,6 @@
 # 1.d/ To run SimLSS with GSM map parametersand 90x30 deg maps (DeltaFreq=500 MHz) @ z=1 [ 90deg-> phi/alpha, 30deg -> theta/delta]
 csh> ~/Objs/exe/cmvginit3df -a -1 -2 -C -G 0. -F 0 -x 600,2.9 -y 1800,2.9 -z 256,3.5 -Z 1.0 -8 1. -n 10000 -O 0,2 -o lssz100 -T 2
+
+csh> ~/Objs/exe/cmvginit3df -a -1 -2 -C -G 0. -F 0 -x 600,3.8 -y 1800,3.8 -z 256,4.2 -Z 1.5 -8 1. -n 10000 -O 0,2 -o lssz150 -T 2
 
 # 1.c/ Change the X and Z axis of the cube to adapt it to RadioBeam package convention 
