Index: trunk/MagicSoft/Mars/mtemp/mmpi/SupercutsONOFFClasses/MHFindSignificanceONOFF.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mmpi/SupercutsONOFFClasses/MHFindSignificanceONOFF.cc	(revision 5327)
+++ trunk/MagicSoft/Mars/mtemp/mmpi/SupercutsONOFFClasses/MHFindSignificanceONOFF.cc	(revision 5329)
@@ -1047,6 +1047,10 @@
       // count bins with zero entry
       if (content <= 0.0)
-        fNzeroOFF++;
-     
+	{
+	  fNzeroOFF++;
+	  // The error of the bin is set to a huge number, 
+	  // so that it does not have any weight in the fit
+	  fHistOFF->SetBinError(i, dummy); 
+	}
       // set minimum error
       if (content < 9.0)
@@ -1151,5 +1155,20 @@
 
   fConstantBackg = kFALSE;
-  if ( fNzeroOFF > 0  ||  (Double_t)fMlowOFF>0.05*(Double_t)fMbinsOFF ) 
+
+  // Condition for disabling the fitting procedure and 
+  // assuming a constant background (before Nov 2004)
+
+  // if ( fNzeroOFF > 0  ||  (Double_t)fMlowOFF>0.05*(Double_t)fMbinsOFF )
+
+
+  // Condition for disabling the fitting procedure and 
+  // assuming a constant background (After Nov 01 2004)
+  // I softened the condition to allow the fit also in situations 
+  // where the reduction of the background is such that very 
+  // few events survived; which is 
+  // Specially frequent with Random Forest at high Sizes)
+
+   if ( (Double_t)fNzeroOFF > 0.1*(Double_t)fMbinsOFF ||  
+       (Double_t)fMlowOFF > 0.2*(Double_t)fMbinsOFF )
   {
     *fLog << "MHFindSignificanceONOFF::FitPolynomialOFF; polynomial fit not possible,  fNzeroOFF, fMlowOFF, fMbinsOFF = "
@@ -1182,5 +1201,5 @@
     Double_t val, err;
     val = mean;
-    err = sqrt( mean / (Double_t)fMbinsOFF );
+    err = rms; // sqrt( mean / (Double_t)fMbinsOFF );
 
     fPolyOFF->SetParameter(0, val);
@@ -1553,6 +1572,11 @@
       // count bins with zero entry
       if (content <= 0.0)
-        fNzero++;
-     
+	{
+	  fNzero++;
+	  // The error of the bin is set to a huge number, 
+	  // so that it does not have any weight in the fit
+	  fHistOFF->SetBinError(i, dummy); 
+	}
+
       // set minimum error
       if (content < 9.0)
@@ -1657,5 +1681,21 @@
 
   fConstantBackg = kFALSE;
-  if ( fNzero > 0  ||  (Double_t)fMlow>0.05*(Double_t)fMbins ) 
+
+  // Condition for disabling the fitting procedure and 
+  // assuming a constant background (before Nov 2004)
+
+  // if ( fNzero > 0  ||  (Double_t)fMlow>0.05*(Double_t)fMbins )
+
+
+  // Condition for disabling the fitting procedure and 
+  // assuming a constant background (After Nov 01 2004)
+  // I softened the condition to allow the fit also in situations 
+  // where the reduction of the background is such that very 
+  // few events survived; which is 
+  // Specially frequent with Random Forest at high Sizes)
+
+  if ( (Double_t)fNzero > 0.1*(Double_t)fMbins ||  
+       (Double_t)fMlow > 0.2*(Double_t)fMbins )
+
   {
     *fLog << "MHFindSignificanceONOFF::FitPolynomial; polynomial fit not possible,  fNzero, fMlow, fMbins = "
@@ -1688,5 +1728,5 @@
     Double_t val, err;
     val = mean;
-    err = sqrt( mean / (Double_t)fMbins );
+    err = rms; // sqrt( mean / (Double_t)fMbins );
 
     fPoly->SetParameter(0, val);
