Index: trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.cc	(revision 2632)
+++ trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.cc	(revision 2641)
@@ -62,5 +62,10 @@
 //
 MHCalibrationBlindPixel::MHCalibrationBlindPixel(const char *name, const char *title)
-    : fSinglePheFit(NULL), fTimeGausFit(NULL)
+  : fSinglePheFit(NULL), fTimeGausFit(NULL), fSinglePhePedFit(NULL),
+    fLambda(0.), fMu0(0.), fMu1(0.), fSigma0(0.), fSigma1(0.),
+    fLambdaErr(0.), fMu0Err(0.), fMu1Err(0.), fSigma0Err(0.), fSigma1Err(0.),    
+    fChisquare(0.), fProb(0.),  fNdf(0),
+    fMeanTime(0.),  fMeanTimeErr(0.), fSigmaTime(0.), fSigmaTimeErr(0.),
+    fLambdaCheck(0.), fLambdaCheckErr(0.)
 {
 
@@ -77,5 +82,5 @@
     fHBlindPixelCharge->SetXTitle("Sum FADC Slices");
     fHBlindPixelCharge->SetYTitle("Nr. of events");
-    fHBlindPixelCharge->Sumw2();
+    //    fHBlindPixelCharge->Sumw2();
 
     fErrBlindPixelChargefirst = 0.;
@@ -120,4 +125,6 @@
   if (fSinglePheFit)
     delete fSinglePheFit;
+  if (fSinglePhePedFit)
+    delete fSinglePhePedFit;
   if (fTimeGausFit)
     delete fTimeGausFit;
@@ -155,4 +162,8 @@
   fFitLegend->AddText(line1);
 
+  const TString line6 =
+  Form("Mean #lambda (check) = %2.2f #pm %2.2f",GetLambdaCheck(),GetLambdaCheckErr());
+  fFitLegend->AddText(line6);
+
   const TString line2 = 
   Form("Pedestal: #mu_{0} = %2.2f #pm %2.2f",GetMu0(),GetMu0Err());
@@ -215,5 +226,5 @@
       {
         if (fFitOK)
-          fSinglePheFit->SetLineColor(kGreen);          
+	  fSinglePheFit->SetLineColor(kGreen);          
         else
           fSinglePheFit->SetLineColor(kRed);
@@ -222,5 +233,12 @@
         c->Modified();
         c->Update();
+
+	if (fSinglePhePedFit)
+	  {
+	    fSinglePhePedFit->SetLineColor(kBlue);
+	    fSinglePhePedFit->DrawCopy("same");
+	  }
       }
+
 
     c->cd(2);
@@ -311,9 +329,9 @@
   // otherwise the fit goes gaga because of high number of dimensions ...
   //
-  const Stat_t   entries      = fHBlindPixelCharge->GetSumOfWeights();
-  const Double_t lambda_guess = 0.2;
+  const Stat_t   entries      = fHBlindPixelCharge->GetEntries();
+  const Double_t lambda_guess = 0.5;
   const Double_t mu_0_guess = fHBlindPixelCharge->GetBinCenter(fHBlindPixelCharge->GetMaximumBin());
-  const Double_t si_0_guess = mu_0_guess/5.;
-  const Double_t mu_1_guess = mu_0_guess + 50.;
+  const Double_t si_0_guess = 20.;
+  const Double_t mu_1_guess = mu_0_guess + 100.;
   const Double_t si_1_guess = si_0_guess + si_0_guess;
 
@@ -321,10 +339,10 @@
   fSinglePheFit->SetParameters(lambda_guess,mu_0_guess,mu_1_guess,si_0_guess,si_1_guess,entries);
   fSinglePheFit->SetParNames("#lambda","#mu_0","#mu_1","#sigma_0","#sigma_1","area");
-  fSinglePheFit->SetParLimits(0,0.,5.);
+  fSinglePheFit->SetParLimits(0,0.,3.);
   fSinglePheFit->SetParLimits(1,rmin,rmax);
   fSinglePheFit->SetParLimits(2,rmin,rmax);
   fSinglePheFit->SetParLimits(3,1.0,rmax-rmin);
   fSinglePheFit->SetParLimits(4,1.7,rmax-rmin);
-  fSinglePheFit->SetParLimits(5,0.,2.5*entries);
+  fSinglePheFit->SetParLimits(5,0.,1.5*entries);
   //
   // Normalize the histogram to facilitate faster fitting of the area
@@ -355,4 +373,5 @@
 
   fHBlindPixelCharge->Fit(fSinglePheFit,opt);
+  fHBlindPixelCharge->Fit(fSinglePheFit,opt);
 
   fLambda = fSinglePheFit->GetParameter(0);
@@ -372,4 +391,17 @@
   fNdf       = fSinglePheFit->GetNDF();
 
+  // Perform the cross-check fitting only the pedestal:
+  fSinglePhePedFit = new TF1("GausPed","gaus",rmin,fMu0);
+  fHBlindPixelCharge->Fit(fSinglePhePedFit,opt);
+
+  Double_t pedarea = fSinglePhePedFit->GetParameter(0)*gkSq2Pi*fSinglePhePedFit->GetParameter(2);
+  cout << "Parameter0: " << fSinglePhePedFit->GetParameter(0) << endl;
+  cout << "Parameter2: " << fSinglePhePedFit->GetParameter(2) << endl;
+  cout << "Pedarea: " << pedarea << endl;
+  cout << "entries: " << entries << endl;
+  fLambdaCheck     = TMath::Log((double)entries/pedarea);
+  fLambdaCheckErr  = fSinglePhePedFit->GetParError(0)/fSinglePhePedFit->GetParameter(0)
+                     + fSinglePhePedFit->GetParError(2)/fSinglePhePedFit->GetParameter(2);
+
   *fLog << "Results of the Blind Pixel Fit: " << endl;
   *fLog << "Chisquare: " << fChisquare << endl;
@@ -380,5 +412,6 @@
   //
   // The fit result is accepted under condition
-  // The Probability is greater than gkProbLimit (default 0.01 == 99%)
+  // The fit result is accepted under condition
+  // The Probability is greater than gkProbLimit (default 0.001 == 99.7%)
   //
   if (fProb < gkProbLimit) 
