Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2698)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2699)
@@ -4,4 +4,15 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2003/12/17: Abelardo Moralejo
+
+   * manalysis/MExtractSignal.cc
+     - put SetNumPixelUsedFADCSlices into the ReInit, otherwise they 
+       are not accessible for MCalibrationCalc
+
+   * manalysis/MCalibration*
+   * mhist/MHCalibration*
+     - many small changes, mostly cosmetic
+
+
  2003/12/17: Abelardo Moralejo
 
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.cc	(revision 2698)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.cc	(revision 2699)
@@ -45,5 +45,17 @@
 //
 MCalibrationBlindPix::MCalibrationBlindPix(const char *name, const char *title)
-    : fHist(NULL)
+    : fHist(NULL),
+      fLambda(-1.),
+      fMu0   (-1.),
+      fMu1   (-1.),
+      fSigma0(-1.),
+      fSigma1(-1.),
+      fErrLambda(-1.),
+      fErrMu0   (-1.),
+      fErrMu1   (-1.),
+      fErrSigma0(-1.),
+      fErrSigma1(-1.),
+      fTime     (-1.),
+      fErrTime  (-1.)
 {
 
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc	(revision 2698)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc	(revision 2699)
@@ -1,3 +1,3 @@
-/* ======================================================================== *\
+ /* ======================================================================== *\
 !
 ! *
@@ -279,6 +279,6 @@
 	MExtractedSignalPix &sig =  (*fSignals)[pixid];
         MPedestalPix        &ped =  (*fPedestals)[pixid];
-        Float_t pedrms = ped.GetPedestalRms();
-	Float_t sumhi  = sig.GetExtractedSignalHiGain();
+        Float_t pedrms     = ped.GetPedestalRms();
+	Float_t sumhi      = sig.GetExtractedSignalHiGain();
         
 	if (sumhi < 15.*pedrms )   // cut at 3.5 sigma
@@ -320,9 +320,9 @@
 
 	    if (!blindpixel.FillCharge(sumhi)) 
-	      *fLog << warn << 
+	      *fLog << err << 
 		"Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
 
 	    if (!blindpixel.FillTime((int)mtime)) 
-	      *fLog << warn << 
+	      *fLog << err << 
 		"Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
 	    
@@ -412,11 +412,7 @@
   if (TESTBIT(fFlags,kUseBlindPixelFit))
     {
-      if (blindpixel.FitCharge())
-	    *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
-      else
-	  *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
-
-      if (!blindpixel.FitTime())
-        *fLog << warn << "Could not the Times of the blind pixel " << endl;
+
+      if (!blindpixel.FitCharge())
+        *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
 
       blindpixel.Draw();
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.h	(revision 2698)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.h	(revision 2699)
@@ -47,10 +47,5 @@
    
 
-  enum
-    {
-      kUseTimeFits = 1,
-      kUseBlindPixelFit = 2,
-      kUsePinDiodeFit = 3
-    };
+  enum  { kUseTimeFits, kUseBlindPixelFit, kUsePinDiodeFit };
 
 public:
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2698)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2699)
@@ -232,4 +232,5 @@
 void MCalibrationCam::Print(Option_t *o) const
 {
+
     *fLog << all << GetDescriptor() << ":" << endl;
     int id = 0;
@@ -243,5 +244,5 @@
     {
 
-      if (pix->GetCharge() >= 0.)
+      if (pix->GetCharge() >= 0.) 
 	{
 	  *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
@@ -321,6 +322,9 @@
       break;
     case 15:
-      val = ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge())*
-	    ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge());
+      if ((*this)[idx].GetCharge() != 0.)
+        val = ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge())*
+              ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge());
+      else
+        val = -1.;
       break;
     case 11:
@@ -337,15 +341,8 @@
       break;
     case 14:
-      if ((fMeanPhotInsidePlexiglass > 0. ) && ((*this)[idx].GetCharge() != -1.))
-	{
-	  if (idx < 397)
-	    val = fMeanPhotInsidePlexiglass / (*this)[idx].GetCharge();
-	  else 
-	    val = fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea / (*this)[idx].GetCharge();
-	} 
-      else
-	{
-	  val = -1.;
-	}
+      if (idx < 397)
+        val = (*this)[idx].GetMeanConversionBlindPixelMethod();
+      else 
+        val = (*this)[idx].GetMeanConversionBlindPixelMethod()*gkCalibrationOutervsInnerPixelArea;
       break;
     default:
@@ -398,9 +395,12 @@
   fNumPhotInsidePlexiglassAvailable = kTRUE;
 
+  *fLog << endl;
+  *fLog << mean << " Mean number of Photons for an Inner Pixel: " << fMeanPhotInsidePlexiglass << endl;
+  *fLog << endl;
+
   TIter Next(fPixels);
   MCalibrationPix *pix;
   while ((pix=(MCalibrationPix*)Next()))
     {
-      
       if((pix->GetCharge() > 0.) && (fMeanPhotInsidePlexiglass > 0.))
 	pix->SetConversionBlindPixelMethod(fMeanPhotInsidePlexiglass/pix->GetCharge(), 0., 0.);
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc	(revision 2698)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc	(revision 2699)
@@ -112,5 +112,5 @@
     fHist->SetLowerFitRange(1.5*fPedRms);
   else
-    *fLog << warn << "Cannot set lower fit range to suppress cosmics: Pedestals not available" << endl;
+    *fLog << warn << "Cannot set lower fit range: Pedestals not available" << endl;
 
   if (fHist->UseLoGain())
@@ -145,34 +145,39 @@
   if ((fPed > 0.)  && (fPedRms > 0.))
     {
+      
+      Float_t pedrmssquare = fPedRms*fPedRms;
+      Float_t sigmasquare  = fSigmaCharge*fSigmaCharge;
 
       if (fHiGainSaturation)
 	{
-	  
-	  Float_t nsb = TMath::Sqrt(fPedRms*fPedRms - fElectronicPedRms*fElectronicPedRms);
+          
+          Float_t logainrmssquare = fElectronicPedRms*fElectronicPedRms;
+          Float_t nsbsquare       = pedrmssquare - logainrmssquare;
 	  //	  Float_t logainrms = fElectronicPedRms + (TMath::Sqrt(fPedRms*fPedRms - fElectronicPedRms*fElectronicPedRms));
 
-	  if (nsb > 0.)
-	    {
-	      Float_t logainrms = (TMath::Sqrt(nsb*nsb + 100.*fElectronicPedRms*fElectronicPedRms));
-	      fRSigmaSquare = (fSigmaCharge*fSigmaCharge) - (logainrms*logainrms);
-	    }
-	  else
-	    fRSigmaSquare =  fSigmaCharge*fSigmaCharge - (100.*fElectronicPedRms*fElectronicPedRms);
-	}
-      else
-	fRSigmaSquare = (fSigmaCharge*fSigmaCharge) - (fPedRms*fPedRms);
-
-    if (fRSigmaSquare > 0. )
-      {
-       fPheFFactorMethod         =  fFactor * fCharge*fCharge / fRSigmaSquare;
+	  if (nsbsquare > 0.)
+	      logainrmssquare = nsbsquare/100. + logainrmssquare;
+
+          fRSigmaSquare = sigmasquare - logainrmssquare;
+
+          if (fRSigmaSquare > 0.)
+            fPheFFactorMethod = fFactor*(fCharge*fCharge/100.) / fRSigmaSquare;
+
+	}
+      else  /* if (fHiGainSaturation) */
+        {
+          fRSigmaSquare = sigmasquare - pedrmssquare;
+          fPheFFactorMethod   =  fFactor * fCharge*fCharge / fRSigmaSquare;
+        }
+      
+
+      if (fCharge > 0.)
        fConversionFFactorMethod  =  fPheFFactorMethod /  fCharge ;
-      }
-    else
-      {
+
+      else  
 	*fLog << warn << "Cannot apply F-Factor method: Reduced Sigmas are smaller than 0 in pixel: " 
 	      << fPixId << endl;
-      }
-
-    }
+
+    } /*   if ((fPed > 0.)  && (fPedRms > 0.)) */
 
   return kTRUE;
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h	(revision 2698)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h	(revision 2699)
@@ -68,5 +68,5 @@
   Float_t GetTimeChiSquare()  const    { return fTimeChiSquare;  }    
   
- Float_t GetPed()            const    { return fPed;            }
+  Float_t GetPed()            const    { return fPed;            }
   Float_t GetPedRms()         const    { return fPedRms;         }    
 
@@ -109,14 +109,14 @@
   void   SetChargesInGraph(Float_t qhi,Float_t qlo) { fHist->SetPointInGraph(qhi,qlo); }
 
-  Bool_t FillChargeHiGain(Float_t q)   { return fHist->FillChargeHiGain(q); }
-  Bool_t FillTimeHiGain(Int_t t)       { return fHist->FillTimeHiGain(t); }  
-  Bool_t FillRChargevsTimeHiGain(Float_t rq, Int_t t) { return fHist->FillChargevsNHiGain(rq,t); }    
+  Bool_t FillChargeHiGain(Float_t q)                   { return fHist->FillChargeHiGain(q); }
+  Bool_t FillTimeHiGain(Int_t t)                       { return fHist->FillTimeHiGain(t); }  
+  Bool_t FillRChargevsTimeHiGain(Float_t rq, Int_t t)  { return fHist->FillChargevsNHiGain(rq,t); }    
 
-  Bool_t FillChargeLoGain(Float_t q)   { return fHist->FillChargeLoGain(q); }
-  Bool_t FillTimeLoGain(Int_t t)       { return fHist->FillTimeLoGain(t); }  
-  Bool_t FillRChargevsTimeLoGain(Float_t rq, Int_t t) { return fHist->FillChargevsNLoGain(rq,t); }    
+  Bool_t FillChargeLoGain(Float_t q)                   { return fHist->FillChargeLoGain(q); }
+  Bool_t FillTimeLoGain(Int_t t)                       { return fHist->FillTimeLoGain(t); }  
+  Bool_t FillRChargevsTimeLoGain(Float_t rq, Int_t t)  { return fHist->FillChargevsNLoGain(rq,t); }    
   
-  Bool_t IsValid()            const    { return fCharge >=0 || fErrCharge >= 0; }
-  Int_t  GetPixId()           const    { return fPixId;   }
+  Bool_t IsValid()                               const  { return fCharge >= 3.*GetPedRms() || fErrCharge >= 0; }
+  Int_t  GetPixId()                              const  { return fPixId;   }
   void   DefinePixId(Int_t i);
   
Index: trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc	(revision 2698)
+++ trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc	(revision 2699)
@@ -127,4 +127,8 @@
     fSignals->InitSize(cam->GetNumPixels());    
 
+
+    fSignals->SetNumUsedFADCSlices(fNumHiGainSamples,fFirst,fFirst+fNumHiGainSamples-1,
+				   fNumLoGainSamples,fFirst,fFirst+fNumLoGainSamples-1);
+
     return kTRUE;
 }
@@ -182,6 +186,6 @@
 
 	ptr   = pixel.GetLoGainSamples();
-        first = ptr + fFirst;
-        last  = ptr + fFirst + fNumLoGainSamples;
+        first = ptr + fFirst + 1;
+        last  = ptr + fFirst + fNumLoGainSamples +1;
 	Byte_t maxlo  = 0;
 	Byte_t midlo  = 0;
@@ -222,6 +226,5 @@
       } /* while (pixel.Next()) */
 
-    fSignals->SetNumUsedFADCSlices(fNumHiGainSamples,fFirst,fFirst+fNumHiGainSamples-1,
-				   fNumLoGainSamples,fFirst,fFirst+fNumLoGainSamples-1);
+
     fSignals->SetReadyToSave();
 
Index: trunk/MagicSoft/Mars/manalysis/MExtractedSignalCam.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MExtractedSignalCam.h	(revision 2698)
+++ trunk/MagicSoft/Mars/manalysis/MExtractedSignalCam.h	(revision 2699)
@@ -47,5 +47,5 @@
 
     void   SetNumUsedFADCSlices(Byte_t numh, Byte_t firsth, Byte_t lasth, 
-				Byte_t numl, Byte_t firstl, Byte_t lastl)   
+			Byte_t numl, Byte_t firstl, Byte_t lastl)   
                                            { 
 					     fNumUsedHiGainFADCSlices = numh;
Index: trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.cc	(revision 2698)
+++ trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.cc	(revision 2699)
@@ -82,15 +82,5 @@
     fHBlindPixelCharge->SetXTitle("Sum FADC Slices");
     fHBlindPixelCharge->SetYTitle("Nr. of events");
-    //    fHBlindPixelCharge->Sumw2();
-
-    fErrBlindPixelChargefirst = 0.;
-    fErrBlindPixelChargelast  = gkStartBlindPixelBinNr;
-    fErrBlindPixelChargenbins = gkStartBlindPixelBinNr;
-
-    fHBlindPixelErrCharge = new TH1F("HBlindPixelErrCharge","Distribution of Variances of Summed FADC Slices",
-                        fErrBlindPixelChargenbins,fErrBlindPixelChargefirst,fErrBlindPixelChargelast);
-    fHBlindPixelErrCharge->SetXTitle("Variance Summed FADC Slices");
-    fHBlindPixelErrCharge->SetYTitle("Nr. of events");
-    fHBlindPixelErrCharge->Sumw2();
+    fHBlindPixelCharge->Sumw2();
 
     Axis_t tfirst = -0.5;
@@ -121,6 +111,5 @@
   delete fHBlindPixelCharge;
   delete fHBlindPixelTime;
-  delete fHBlindPixelErrCharge;
-  
+
   if (fSinglePheFit)
     delete fSinglePheFit;
@@ -136,5 +125,4 @@
 {
     fHBlindPixelCharge->SetBinContent (i, 1.e-20);
-    fHBlindPixelErrCharge->SetBinContent  (i, 1.e-20);
     fHBlindPixelTime->SetBinContent(i, 1.e-20);
 }
@@ -279,5 +267,5 @@
   gRandom->SetSeed();
 
-  if (fHBlindPixelCharge->GetEntries() != 0)
+  if (fHBlindPixelCharge->GetIntegral() != 0)
     {
       *fLog << err << "Histogram " << fHBlindPixelCharge->GetTitle() << " is already filled. " << endl;
@@ -329,5 +317,5 @@
   // otherwise the fit goes gaga because of high number of dimensions ...
   //
-  const Stat_t   entries      = fHBlindPixelCharge->GetEntries();
+  const Stat_t   entries      = fHBlindPixelCharge->Integral();
   const Double_t lambda_guess = 0.5;
   const Double_t mu_0_guess = fHBlindPixelCharge->GetBinCenter(fHBlindPixelCharge->GetMaximumBin());
@@ -439,5 +427,5 @@
   Int_t nbins = 50;
 
-  *fLog << "New number of bins in HSinCharge: " << CutEdges(fHBlindPixelCharge,nbins) << endl;
+  CutEdges(fHBlindPixelCharge,nbins);
 
   fBlindPixelChargefirst = fHBlindPixelCharge->GetBinLowEdge(fHBlindPixelCharge->GetXaxis()->GetFirst());
@@ -445,9 +433,4 @@
   fBlindPixelChargenbins = nbins;
 
-  *fLog << "New number of bins in HErrCharge: " << CutEdges(fHBlindPixelErrCharge,30) << endl;
-  fErrBlindPixelChargefirst = fHBlindPixelErrCharge->GetBinLowEdge(fHBlindPixelErrCharge->GetXaxis()->GetFirst());
-  fErrBlindPixelChargelast  = fHBlindPixelErrCharge->GetBinLowEdge(fHBlindPixelErrCharge->GetXaxis()->GetLast())+fHBlindPixelErrCharge->GetBinWidth(0);
-  fErrBlindPixelChargenbins = nbins;
-
   CutEdges(fHBlindPixelChargevsN,0);
 
@@ -463,5 +446,5 @@
   rmax = (rmax != 0.) ? rmax : 9.;
 
-  const Stat_t   entries     = fHBlindPixelTime->GetEntries();
+  const Stat_t   entries     = fHBlindPixelTime->Integral();
   const Double_t mu_guess    = fHBlindPixelTime->GetBinCenter(fHBlindPixelTime->GetMaximumBin());
   const Double_t sigma_guess = (rmax - rmin)/2.;
Index: trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.h	(revision 2698)
+++ trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.h	(revision 2699)
@@ -33,6 +33,5 @@
 
   TH1F* fHBlindPixelCharge;        //-> Histogram with the single Phe spectrum
-  TH1F* fHBlindPixelErrCharge;     //-> Variance of summed FADC slices
-  TH1I* fHBlindPixelTime;        //-> Variance of summed FADC slices
+  TH1I* fHBlindPixelTime;          //-> Variance of summed FADC slices
   TH1I* fHBlindPixelChargevsN;     //-> Summed Charge vs. Event Nr. 
   
@@ -45,8 +44,4 @@
   Int_t   fBlindPixelChargenbins;
   
-  Axis_t fErrBlindPixelChargefirst;
-  Axis_t fErrBlindPixelChargelast;
-  Int_t  fErrBlindPixelChargenbins;
-
   void ResetBin(Int_t i);
   void DrawLegend();
@@ -88,5 +83,4 @@
 
   Bool_t FillBlindPixelCharge(Float_t q)             { return fHBlindPixelCharge->Fill(q) > -1;  }  
-  Bool_t FillErrBlindPixelCharge(Float_t errq)       { return fHBlindPixelErrCharge->Fill(errq) > -1; }
   Bool_t FillBlindPixelTime(Int_t t)                 { return fHBlindPixelTime->Fill(t) > -1;  }
   Bool_t FillBlindPixelChargevsN(Stat_t rq, Int_t t) { return fHBlindPixelChargevsN->Fill(t,rq) > -1;  }  
@@ -115,7 +109,4 @@
   const Double_t GetSigmaTimeErr()    const { return fSigmaTimeErr; }
 
-  const TH1F *GetHErrCharge() { return fHBlindPixelErrCharge; }
-  const TH1F *GetHErrCharge() const { return fHBlindPixelErrCharge; }
-  
   Bool_t SimulateSinglePhe(Double_t lambda,
                            Double_t mu0,
Index: trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.cc	(revision 2698)
+++ trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.cc	(revision 2699)
@@ -297,5 +297,5 @@
 {
 
-  if (fHChargeHiGain->GetEntries() > fHChargeLoGain->GetEntries())
+  if (fHChargeHiGain->Integral() > fHChargeLoGain->Integral())
     {
       fUseLoGain = kFALSE;
@@ -382,5 +382,4 @@
     FitHiGainvsLoGain();
       
-  
   gStyle->SetOptFit(0);
   gStyle->SetOptStat(1111111);
@@ -390,97 +389,111 @@
   gROOT->SetSelectedPad(NULL);
   
-    c->Divide(2,4);
-
-    c->cd(1);
-    gPad->SetBorderMode(0);
+  c->Divide(2,4);
+  
+  c->cd(1);
+  gPad->SetBorderMode(0);
+  gPad->SetTicks();
+
+  if (fHChargeHiGain->Integral() > 0)
     gPad->SetLogy(1);
-    gPad->SetTicks();
-
-    fHChargeHiGain->DrawCopy(opt);
-
-    c->Modified();
-    c->Update();
-
-    if (fUseLoGain)
+  else
+    gPad->SetLogy(0);
+
+  fHChargeHiGain->DrawCopy(opt);
+  
+  c->Modified();
+  c->Update();
+  
+  if (fUseLoGain)
+    {
+
+      c->cd(2);
+      gPad->SetTicks();
+
+      if (fHChargeLoGain->Integral() > 0)
+        gPad->SetLogy(1);
+      else
+        gPad->SetLogy(0);
+
+      fHChargeLoGain->DrawCopy(opt);
+      
+      if (fChargeGausFit)
+        {
+          if (fFitOK)
+            fChargeGausFit->SetLineColor(kGreen);          
+          else
+            fChargeGausFit->SetLineColor(kRed);
+          
+          fChargeGausFit->DrawCopy("same");
+        }
+      c->Modified();
+      c->Update();
+      
+      c->cd(3);
+      gROOT->SetSelectedPad(NULL);
+      gStyle->SetOptFit();
+      fHivsLoGain->Draw("prof");
+
+      gPad->Modified();
+      gPad->Update();
+      
+      c->cd(4);
+      DrawLegend();
+      
+    }
+  else
+    {
+      if (fChargeGausFit)
+        {
+          if (fFitOK)
+            fChargeGausFit->SetLineColor(kGreen);          
+          else
+            fChargeGausFit->SetLineColor(kRed);
+          
+          fChargeGausFit->DrawCopy("same");
+        }
+
+      c->cd(2);
+      gPad->SetTicks();
+
+      if (fHChargeLoGain->Integral() > 0)
+        gPad->SetLogy(1);
+      else
+        gPad->SetLogy(0);
+      
+      fHChargeLoGain->DrawCopy(opt);
+      c->Modified();
+      c->Update();
+      
+      c->cd(3);
+      DrawLegend();
+      
+      c->cd(4);
+      
+      gROOT->SetSelectedPad(NULL);
+      gStyle->SetOptFit();
+      fHivsLoGain->Draw("prof");
+      gPad->Modified();
+      gPad->Update();
+    }	
+  
+  c->Modified();
+  c->Update();
+  
+  c->cd(5);
+  gStyle->SetOptStat(1111111);
+
+  gPad->SetTicks();  
+  gPad->SetLogy(0);
+  fHTimeHiGain->DrawCopy(opt);
+  c->Modified();
+  c->Update();
+  
+  if (fUseLoGain)
       {
-	c->cd(2);
-	gPad->SetLogy(1);
-	gPad->SetTicks();
-	fHChargeLoGain->DrawCopy(opt);
-    
- 	if (fChargeGausFit)
-	  {
-	    if (fFitOK)
-	      fChargeGausFit->SetLineColor(kGreen);          
-	    else
-	      fChargeGausFit->SetLineColor(kRed);
-	    
-	    fChargeGausFit->DrawCopy("same");
-	  }
-	c->Modified();
-	c->Update();
-
-	c->cd(3);
-	gROOT->SetSelectedPad(NULL);
-	gStyle->SetOptFit();
-	fHivsLoGain->Draw("prof");
-
-
-	gPad->Modified();
-	gPad->Update();
-
-	c->cd(4);
-	DrawLegend();
-
-      }
-    else
-      {
- 	if (fChargeGausFit)
-	  {
-	    if (fFitOK)
-	      fChargeGausFit->SetLineColor(kGreen);          
-	    else
-	      fChargeGausFit->SetLineColor(kRed);
-	    
-	    fChargeGausFit->DrawCopy("same");
-	  }
-	c->cd(2);
-	gPad->SetLogy(1);
-	gPad->SetTicks();
-
-	fHChargeLoGain->DrawCopy(opt);
-	c->Modified();
-	c->Update();
-    
-	c->cd(3);
-	DrawLegend();
-
-	c->cd(4);
-	
-	gROOT->SetSelectedPad(NULL);
-	gStyle->SetOptFit();
-	fHivsLoGain->Draw("prof");
-	gPad->Modified();
-	gPad->Update();
-
-
-      }	
-
-    c->Modified();
-    c->Update();
-    
-    c->cd(5);
-    gStyle->SetOptStat(1111111);
-
-    gPad->SetLogy(1);
-    fHTimeHiGain->DrawCopy(opt);
-    c->Modified();
-    c->Update();
-
-    if (fUseLoGain)
-      {
-
+        
 	c->cd(6);
-	gPad->SetLogy(1);
+        gPad->SetTicks();
+	gPad->SetLogy(0);
 	fHTimeLoGain->DrawCopy(opt);
 	c->Modified();
@@ -514,5 +527,6 @@
 
 	c->cd(6);
-	gPad->SetLogy(1);
+        gPad->SetTicks();
+	gPad->SetLogy(0);
 	fHTimeLoGain->DrawCopy(opt);	
 	c->Modified();
@@ -524,4 +538,5 @@
     
     c->cd(7);
+    gPad->SetTicks();
     fHChargevsNHiGain->DrawCopy(opt);
     c->Modified();
@@ -529,4 +544,5 @@
 
     c->cd(8);
+    gPad->SetTicks();
     fHChargevsNLoGain->DrawCopy(opt);
     c->Modified();
@@ -573,5 +589,5 @@
   rmax = (rmax != 0.) ? rmax : 9.;
 
-  const Stat_t   entries     = fHTimeHiGain->GetEntries();
+  const Stat_t entries       = fHTimeHiGain->Integral();
   const Double_t mu_guess    = fHTimeHiGain->GetBinCenter(fHTimeHiGain->GetMaximumBin());
   const Double_t sigma_guess = (rmax - rmin)/2.;
@@ -629,5 +645,5 @@
   rmax = (rmax != 0.) ? rmax : 9.;
 
-  const Stat_t   entries     = fHTimeLoGain->GetEntries();
+  const Stat_t   entries     = fHTimeLoGain->Integral();
   const Double_t mu_guess    = fHTimeLoGain->GetBinCenter(fHTimeLoGain->GetMaximumBin());
   const Double_t sigma_guess = (rmax - rmin)/2.;
@@ -692,5 +708,5 @@
   // otherwise the fit goes gaga because of high number of dimensions ...
   //
-  const Stat_t   entries    = fHChargeHiGain->GetEntries();
+  const Stat_t   entries    = fHChargeHiGain->Integral();
   const Double_t area_guess = entries/gkSq2Pi;
   const Double_t mu_guess   = fHChargeHiGain->GetBinCenter(fHChargeHiGain->GetMaximumBin());
@@ -766,5 +782,5 @@
   // otherwise the fit goes gaga because of high number of dimensions ...
   //
-  const Stat_t   entries    = fHChargeLoGain->GetEntries();
+  const Stat_t   entries    = fHChargeLoGain->Integral();
   const Double_t area_guess = entries/gkSq2Pi;
   const Double_t mu_guess   = fHChargeLoGain->GetBinCenter(fHChargeLoGain->GetMaximumBin());
Index: trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.h	(revision 2698)
+++ trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.h	(revision 2699)
@@ -156,10 +156,10 @@
   virtual void Reset();
 
-  void SetLowerFitRange(Axis_t min)  { fLowerFitRange = min; }
+  void SetLowerFitRange(Axis_t min)                {  fLowerFitRange = min; }
 
   void PrintChargeFitResult();
   void PrintTimeFitResult();  
 
-  Bool_t IsFitOK()    { return fFitOK; }
+  Bool_t IsFitOK()                           {  return fFitOK;          }
   
   ClassDef(MHCalibrationPixel, 1) 
