Index: trunk/MagicSoft/Mars/mtemp/MFindStars.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/MFindStars.cc	(revision 4053)
+++ trunk/MagicSoft/Mars/mtemp/MFindStars.cc	(revision 4054)
@@ -66,28 +66,4 @@
 const Float_t sqrt3 = sqrt(3.);
 
-Bool_t HandleInput()
-{
-    TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
-    while (1)
-    {
-        //
-        // While reading the input process gui events asynchronously
-        //
-        timer.TurnOn();
-        cout << "Type 'q' to exit, <return> to go on: " << endl;
-        char q;
-        cin >> q;
-        TString input = q;
-        timer.TurnOff();
-
-        if (input=="q\n")
-            return kFALSE;
-
-        if (input=="\n")
-            return kTRUE;
-    };
-}
-
-
 //______________________________________________________________________________
 //
@@ -440,4 +416,11 @@
 Bool_t MFindStars::DCPedestalCalc(Float_t &ped, Float_t &rms)
 {
+  //-------------------------------------------------------------
+  // save pointer to the MINUIT object for optimizing the supercuts
+  // because it will be overwritten
+  // when fitting the alpha distribution in MHFindSignificance
+  TMinuit *savePointer = gMinuit;
+  //-------------------------------------------------------------
+
    UInt_t numPixels = fGeomCam->GetNumPixels();
 
@@ -470,7 +453,4 @@
    
    dchist.Fit("func","QR0");
-   // Remove the comments if you want to go through the file
-   // event-by-event:
-   //   HandleInput();
 
    UInt_t aproxnumdegrees = 6*(bin-dchist.GetMaximumBin());
@@ -485,5 +465,22 @@
    minbin=minbin<1?1:minbin;
    Axis_t maxbin = ped+numsigmas*rms/dchist.GetBinWidth(1);
+
    *fLog << dbg << " Number of pixels with dc under " << numsigmas << " sigmas = " << dchist.Integral((int)minbin,(int)maxbin) << endl;
+
+   //Check results from the fit are consistent
+   if (TMath::Abs(ped-maxprobdc) > rmsguess || rms > rmsguess)
+     {
+       *fLog << warn << GetName() << " Pedestal DC fit give non consistent results." << endl;
+       *fLog << warn << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
+       *fLog << warn << " ped " << ped << " rms " << rms << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
+       ped = maxprobdc;
+       rms = rmsguess/1.175; // FWHM=2.35*rms
+     }
+   
+   //=================================================================
+   // reset gMinuit to the MINUIT object for optimizing the supercuts
+   gMinuit = savePointer;
+   //-------------------------------------------
+
    return kTRUE;
 }
@@ -621,4 +618,7 @@
     meanSqY /= sumCharge;
 
+    //Substract pedestal from sumCharge
+    sumCharge -= usedPx*fPedestalDC;
+
     Float_t rmsX = TMath::Sqrt(meanSqX - meanX*meanX);
     Float_t rmsY = TMath::Sqrt(meanSqY - meanY*meanY);
@@ -714,8 +714,8 @@
 	Float_t pixXpos  = (*fGeomCam)[pix].GetX();
 	Float_t pixYpos  = (*fGeomCam)[pix].GetY();
-        Float_t starXpos = star->GetMeanXCalc();
-        Float_t starYpos = star->GetMeanYCalc();
-        
-	Float_t starSize = 3*star->GetSigmaMajorAxisCalc();
+        Float_t starXpos = star->GetMeanX();
+        Float_t starYpos = star->GetMeanY();
+        
+	Float_t starSize = 3*star->GetSigmaMajorAxis();
         
 	Float_t dist = sqrt((pixXpos-starXpos)*(pixXpos-starXpos)+
