Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2641)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2642)
@@ -14,4 +14,9 @@
    * mhist/MHCalibrationPixel:
 	- store Hi Gain vs. Lo Gain values to extract the conversion factor
+
+   * manalysis/MCalibrationPix:
+   * manalysis/MCalibrationCam:
+	- separate Hi Gain and Lo Gain
+	- include return of PIN Diode measurement
 
  2003/12/11: Thomas Bretz
Index: trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- trunk/MagicSoft/Mars/macros/calibration.C	(revision 2641)
+++ trunk/MagicSoft/Mars/macros/calibration.C	(revision 2642)
@@ -120,6 +120,6 @@
 
     tlist2.AddToList(&read2);
+    tlist2.AddToList(&sigsig);
     tlist2.AddToList(&calcalc);
-    tlist2.AddToList(&sigsig);
 
     MHCamEvent hist2;
@@ -129,4 +129,7 @@
     tlist2.AddToList(&fill2);
 
+    MStatusDisplay *d2 = new MStatusDisplay;
+    d2->SetUpdateTime(3000);
+
     //
     // Create and setup the eventloop
@@ -134,4 +137,5 @@
     MEvtLoop evtloop2;
     evtloop2.SetParList(&plist2);
+    evtloop2.SetDisplay(d2);
 
     //
@@ -174,5 +178,5 @@
     MHCamera disp14  (geomcam, "MCalibrationCam;photons", "Nr. of Photons (Blind Pixel Method)");
     MHCamera disp15  (geomcam, "MCalibrationCam;convphot", "Conversion Factor (Blind Pixel Method)");
-    MHCamera disp16  (geomcam, "MCalibrationCam;sigma/charge", "Sigma per Charge");
+    MHCamera disp16  (geomcam, "MCalibrationCam;sigma/charge", "Sigma^2 per Charge^2");
 
     disp1.SetCamContent(*cam, 0);
@@ -186,10 +190,10 @@
 
     disp6.SetCamContent(*cam, 5);
-    disp6.SetCamError(*cam,6);
+    disp6.SetCamError(*cam, 6);
     disp7.SetCamContent(*cam, 6);
     disp8.SetCamContent(*cam, 7);
 
     disp9.SetCamContent(*cam, 8);
-    disp9.SetCamError(*cam,9);
+    disp9.SetCamError(*cam, 9);
     disp10.SetCamContent(*cam, 9);
 
@@ -211,6 +215,6 @@
     disp7.SetYTitle("\\Delta T [FADC slices]");
     disp8.SetYTitle("P [au]");
-    disp9.SetYTitle("P [FADC counts/ slice ]");
-    disp10.SetYTitle("RMS_{P} [FADC counts / slice ]");
+    disp9.SetYTitle("P [Total FADC counts ]");
+    disp10.SetYTitle("RMS_{P} [Total FADC counts ]");
     disp11.SetYTitle("\\sigma^2_{Q} - RMS^2_{P} [FADC counts^2]");
     disp12.SetYTitle("Nr Phe's");
@@ -218,13 +222,12 @@
     disp14.SetYTitle("Nr Photons");
     disp15.SetYTitle("Conversion Factor [Ph/FADC count]");
-    disp16.SetYTitle("Sigma per Charge [1]");
-
-
-    MStatusDisplay *d2 = new MStatusDisplay;
+    disp16.SetYTitle("Sigma^2 per Charge^2 [1]");
+
+    MStatusDisplay *d3 = new MStatusDisplay;
  
     // Set update time to 1s
-    d2->SetUpdateTime(1000);
-
-    TCanvas *c1 = &d2->AddTab("Fitted Charges"); 
+    d3->SetUpdateTime(1000);
+
+    TCanvas *c1 = &d3->AddTab("Fitted Charges"); 
     c1->Divide(2, 2);
 
@@ -252,5 +255,5 @@
 
 
-    TCanvas *c12 = &d2->AddTab("Fit Prob."); 
+    TCanvas *c12 = &d3->AddTab("Fit Prob."); 
     c12->Divide(1, 2);
 
@@ -265,5 +268,5 @@
     obj->Draw();
 
-    TCanvas *c2 = &d2->AddTab("Fitted Times");
+    TCanvas *c2 = &d3->AddTab("Fitted Times");
     c2->Divide(3, 2);
 
@@ -295,5 +298,5 @@
     obj->Draw();
 
-    TCanvas *c3 = &d2->AddTab("Pedestals");
+    TCanvas *c3 = &d3->AddTab("Pedestals");
     c3->Divide(2, 2);
 
@@ -316,5 +319,5 @@
     obj->Draw();
 
-    TCanvas *c4 = &d2->AddTab("Reduced Charges");
+    TCanvas *c4 = &d3->AddTab("Reduced Charges");
     c4->Divide(2,2);
 
@@ -337,5 +340,5 @@
     obj->Draw();
 
-    TCanvas *c5 = &d2->AddTab("F-Factor Method");
+    TCanvas *c5 = &d3->AddTab("F-Factor Method");
     c5->Divide(2, 2);
 
@@ -358,5 +361,5 @@
     obj->Draw();
 
-    TCanvas *c6 = &d2->AddTab("Blind Pixel Method");
+    TCanvas *c6 = &d3->AddTab("Blind Pixel Method");
     c6->Divide(2, 2);
 
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.cc	(revision 2641)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.cc	(revision 2642)
@@ -78,4 +78,5 @@
 Bool_t MCalibrationBlindPix::FitCharge() 
 {
+
   if (!fHist->FitSinglePhe())
     return kFALSE;
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.h	(revision 2641)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.h	(revision 2642)
@@ -55,5 +55,5 @@
   Bool_t FillRChargevsTime(Float_t rq, Int_t t) { return fHist->FillBlindPixelChargevsN(rq,t); }    
   
-  Bool_t IsValid()                { return fLambda > 0. || fErrLambda > 0.; }
+  Bool_t IsFitOK()                              { return fHist->IsFitOK(); }
   
   Bool_t FitCharge();
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc	(revision 2641)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc	(revision 2642)
@@ -220,6 +220,8 @@
     }
 
-    fNumHiGainSamples =  fRunHeader->GetNumSamplesHiGain();
-    fNumLoGainSamples =  fRunHeader->GetNumSamplesLoGain();
+    //    fNumHiGainSamples =  fRunHeader->GetNumSamplesHiGain();
+    //    fNumLoGainSamples =  fRunHeader->GetNumSamplesLoGain();
+    fNumHiGainSamples =  6;
+    fNumLoGainSamples =  6;
 
     //
@@ -281,5 +283,5 @@
         Float_t pedrms = ped.GetPedestalRms();
         
-	if ((float)sum < ((pedes*fNumHiGainSamples)+(30.*pedrms)) )
+	if ((float)sum < ((pedes*fNumHiGainSamples)+(2.*fNumHiGainSamples*pedrms)) )
            cosmicpix++;
      }
@@ -305,5 +307,6 @@
 	MExtractedSignalPix &sig =  (*fSignals)[pixid];
 
-	Float_t sum    = sig.GetExtractedSignal();
+	Float_t sumhi  = sig.GetExtractedSignalHiGain();
+	Float_t sumlo  = sig.GetExtractedSignalLoGain();
 	Bool_t  logain = sig.IsLoGainUsed();
 
@@ -322,7 +325,7 @@
           case gkCalibrationBlindPixelId:
 
-	    if (!blindpixel.FillCharge(sum)) 
+	    if (!blindpixel.FillCharge(sumhi)) 
 	      *fLog << warn << 
-		"Overflow or Underflow occurred filling Blind Pixel sum = " << sum << endl;
+		"Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
 
 	    if (!blindpixel.FillTime((int)mid)) 
@@ -330,27 +333,29 @@
 		"Overflow or Underflow occurred filling Blind Pixel time = " << (int)mid << endl;
 	    
-	    if (!blindpixel.FillRChargevsTime(sum,fEvents))
+	    if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
 	      *fLog << warn << 
 		"Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
             
           case gkCalibrationPINDiodeId:
-            if (!pindiode.FillCharge(sum)) 
+            if (!pindiode.FillCharge(sumhi)) 
               *fLog << warn << 
-                "Overflow or Underflow occurred filling HCharge: means = " << sum << endl;
+                "Overflow or Underflow occurred filling HCharge: means = " << sumhi << endl;
             if (!pindiode.FillTime((int)mid)) 
               *fLog << warn << 
                 "Overflow or Underflow occurred filling HTime: time = " << (int)mid << endl;
-            if (!pindiode.FillRChargevsTime(sum,fEvents))
+            if (!pindiode.FillRChargevsTime(sumhi,fEvents))
               *fLog << warn << 
                 "Overflow or Underflow occurred filling HChargevsN: eventnr = " << fEvents << endl;
 
           default:
+
+	    pix.SetChargesInGraph(sumhi,sumlo);
 
 	    if (logain)
 	      {
 		
-		if (!pix.FillChargeLoGain(sum))
+		if (!pix.FillChargeLoGain(sumlo))
 		  *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid 
-			<< " signal = " << sum << endl;
+			<< " signal = " << sumlo << endl;
 
 		if (!pix.FillTimeLoGain((int)mid)) 
@@ -361,14 +366,14 @@
 		// Fill the reduced charge into the control histo for better visibility
 		//
-		if (!pix.FillRChargevsTimeLoGain(sum,fEvents))
+		if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
 		  *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: " 
-			<< pixid << " signal = " << sum  << " event Nr: " << fEvents << endl;
+			<< pixid << " signal = " << sumlo  << " event Nr: " << fEvents << endl;
 		
 	      }
 	    else
 	      {
-		if (!pix.FillChargeHiGain(sum))
+		if (!pix.FillChargeHiGain(sumhi))
 		  *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid 
-			<< " signal = " << sum << endl;
+			<< " signal = " << sumhi << endl;
 		
 		if (!pix.FillTimeHiGain((int)mid)) 
@@ -376,7 +381,7 @@
 			<< pixid << " time = " << (int)mid << endl;
 		
-		if (!pix.FillRChargevsTimeHiGain(sum,fEvents))
+		if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
 		  *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: " 
-			<< pixid << " signal = " << sum  << " event Nr: " << fEvents << endl;
+			<< pixid << " signal = " << sumhi  << " event Nr: " << fEvents << endl;
 	      }
 	    
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2641)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2642)
@@ -13,4 +13,5 @@
 ! * in supporting documentation. It is provided "as is" without express
 ! * or implied warranty.
+
 ! *
 !
@@ -372,5 +373,5 @@
 	  *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
 		<< " Reduced Charge: " << pix->GetCharge() << " +- " 
-		<< pix->GetSigmaCharge() << " Reduced Sigma: " << pix->GetRSigma() << endl;
+		<< pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
 	  id++;
 	}
@@ -392,5 +393,5 @@
 	  *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
 		<< " Reduced Charge: " << pix->GetCharge() << " +- " 
-		<< pix->GetSigmaCharge() << " Reduced Sigma: " << pix->GetRSigma() << endl;
+		<< pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
 	  id++;
 	}
@@ -437,8 +438,9 @@
       break;
     case 10:
-      val = (*this)[idx].GetRSigma();
+      val = TMath::Sqrt((*this)[idx].GetRSigmaSquare());
       break;
     case 15:
-      val = (*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge();
+      val = ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge())*
+	    ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge());
       break;
     case 11:
@@ -482,5 +484,5 @@
 Bool_t MCalibrationCam::CalcNrPhotInnerPixel()
 {
-  if (!fBlindPixel->IsValid())
+  if (!fBlindPixel->IsFitOK())
     return kFALSE;
   
@@ -561,2 +563,17 @@
   return kTRUE;
 }
+
+
+Bool_t MCalibrationCam::GetConversionFactorPINDiode(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
+{
+
+  return kTRUE;
+
+}
+
+Bool_t MCalibrationCam::GetConversionFactorCombined(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
+{
+
+  return kTRUE;
+
+}
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCam.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCam.h	(revision 2641)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCam.h	(revision 2642)
@@ -91,4 +91,6 @@
   Bool_t GetConversionFactorFFactor(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma);
   Bool_t GetConversionFactorBlindPixel(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma);
+  Bool_t GetConversionFactorPINDiode(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma);
+  Bool_t GetConversionFactorCombined(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma);
   
   ClassDef(MCalibrationCam, 1)	// Storage Container for all calibration information of the camera
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc	(revision 2641)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc	(revision 2642)
@@ -50,5 +50,5 @@
       fSigmaCharge(-1.),
       fErrSigmaCharge(-1.),
-      fRSigma(-1.),
+      fRSigmaSquare(-1.),
       fChargeProb(-1.),
       fPed(-1.),
@@ -61,5 +61,5 @@
       fConversionFFactorMethod(-1.),
       fHiGainSaturation(kFALSE),
-      fLoGainPedRms(4.)
+      fElectronicPedRms(3.67)
 {
 
@@ -140,12 +140,20 @@
 
       if (fHiGainSaturation)
-	fRSigma = (fSigmaCharge*fSigmaCharge) - (fLoGainPedRms*fLoGainPedRms);
+	{
+
+	  Float_t logainrms = fElectronicPedRms + (TMath::Sqrt(fPedRms*fPedRms - fElectronicPedRms*fElectronicPedRms));
+	  if (logainrms > 0.)
+	    fRSigmaSquare = (fSigmaCharge*fSigmaCharge) - (logainrms*logainrms);
+	  else
+	    fRSigmaSquare =  fSigmaCharge*fSigmaCharge;
+
+	}
       else
-	fRSigma = (fSigmaCharge*fSigmaCharge) - (fPedRms*fPedRms);
-
-    if (fRSigma > 0. )
+	fRSigmaSquare = (fSigmaCharge*fSigmaCharge) - (fPedRms*fPedRms);
+
+    if (fRSigmaSquare > 0. )
       {
-       fPheFFactorMethod =  fFactor * fCharge*fCharge / fRSigma;
-       fConversionFFactorMethod = fPheFFactorMethod /   fCharge ;
+       fPheFFactorMethod         =  fFactor * fCharge*fCharge / fRSigmaSquare;
+       fConversionFFactorMethod  =  fPheFFactorMethod /   fCharge ;
       }
     else
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h	(revision 2641)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h	(revision 2642)
@@ -18,5 +18,5 @@
   Float_t fSigmaCharge;         // The sigma of the mean charge after the fit
   Float_t fErrSigmaCharge;      // The error of the sigma of the mean charge after the fit
-  Float_t fRSigma;              // The reduced squares of sigmas after the fit
+  Float_t fRSigmaSquare;        // The reduced squares of sigmas after the fit
   Float_t fChargeProb;          // The probability of the fit function 
 
@@ -34,5 +34,5 @@
   Bool_t fHiGainSaturation;     // Is Lo-Gain used at all?
 
-  Float_t fLoGainPedRms;
+  Float_t fElectronicPedRms;
 
   MHCalibrationPixel *fHist;    //! Pointer to the histograms performing the fits, etc.  
@@ -46,5 +46,5 @@
 
   Float_t GetCharge()         const    { return fCharge;         }
-  Float_t GetRSigma()         const    { return fRSigma;         }
+  Float_t GetRSigmaSquare()   const    { return fRSigmaSquare;   }
     
   Float_t GetErrCharge()      const    { return fErrCharge;      }
@@ -62,4 +62,6 @@
   void SetPedestal(Float_t ped, Float_t pedrms);
   void SetHiGainSaturation()                 { fHiGainSaturation = kTRUE; fHist->SetUseLoGain(); } 
+
+  void   SetChargesInGraph(Float_t qhi,Float_t qlo) { fHist->SetPointInGraph(qhi,qlo); }
 
   Bool_t FillChargeHiGain(Float_t q)   { return fHist->FillChargeHiGain(q); }
Index: trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc	(revision 2641)
+++ trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc	(revision 2642)
@@ -246,5 +246,5 @@
 
 
-    fSignals->SetNumUsedFADCSlices(fNumHiGainSamples);
+    fSignals->SetNumUsedFADCSlices(fNumHiGainSamples,fNumLoGainSamples);
     fSignals->SetReadyToSave();
 
Index: trunk/MagicSoft/Mars/manalysis/MExtractedSignalCam.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MExtractedSignalCam.h	(revision 2641)
+++ trunk/MagicSoft/Mars/manalysis/MExtractedSignalCam.h	(revision 2642)
@@ -32,5 +32,5 @@
     Byte_t GetNumUsedHiGainFADCSlices()    { return fNumUsedHiGainFADCSlices; }
     Byte_t GetNumUsedLoGainFADCSlices()    { return fNumUsedLoGainFADCSlices; }
-    SetNumUsedHiGainFADCSlices(Byte_t numh, Byte_t numl)   
+    void   SetNumUsedHiGainFADCSlices(Byte_t numh, Byte_t numl)   
                                            { 
 					     fNumUsedHiGainFADCSlices = numh;
Index: trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.h	(revision 2641)
+++ trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.h	(revision 2642)
@@ -39,4 +39,5 @@
   TF1 *fSinglePheFit;
   TF1 *fTimeGausFit;  
+  TF1 *fSinglePhePedFit;
 
   Axis_t  fBlindPixelChargefirst;
@@ -55,5 +56,5 @@
   
   BlindPixelFitFunc fgSinglePheFitFunc;     // In the beginning, 
-  Int_t     fgSinglePheFitNPar;     // we want to be flexible using different functions
+  Int_t     fgSinglePheFitNPar;             // we want to be flexible using different functions
 
   Double_t  fLambda; 
@@ -78,4 +79,7 @@
   Double_t  fSigmaTimeErr; 
   
+  Double_t fLambdaCheck;
+  Double_t fLambdaCheckErr;
+
 public:
 
@@ -88,19 +92,21 @@
   Bool_t FillBlindPixelChargevsN(Stat_t rq, Int_t t) { return fHBlindPixelChargevsN->Fill(t,rq) > -1;  }  
   
-  const Double_t GetLambda()   const { return fLambda; }
-  const Double_t GetMu0()     const { return fMu0; }
-  const Double_t GetMu1()     const { return fMu1; }
-  const Double_t GetSigma0()   const { return fSigma0; }
-  const Double_t GetSigma1()   const { return fSigma1; }
+  const Double_t GetLambda()         const { return fLambda; }
+  const Double_t GetLambdaCheck()    const { return fLambdaCheck; }
+  const Double_t GetMu0()            const { return fMu0; }
+  const Double_t GetMu1()            const { return fMu1; }
+  const Double_t GetSigma0()         const { return fSigma0; }
+  const Double_t GetSigma1()         const { return fSigma1; }
 
-  const Double_t GetLambdaErr() const { return fLambdaErr; }
-  const Double_t GetMu0Err()   const { return fMu0Err; }
-  const Double_t GetMu1Err()   const { return fMu1Err; }
-  const Double_t GetSigma0Err() const { return fSigma0Err; }
-  const Double_t GetSigma1Err() const { return fSigma1Err; }
+  const Double_t GetLambdaErr()      const { return fLambdaErr; }
+  const Double_t GetLambdaCheckErr() const { return fLambdaCheckErr; }
+  const Double_t GetMu0Err()         const { return fMu0Err; }
+  const Double_t GetMu1Err()         const { return fMu1Err; }
+  const Double_t GetSigma0Err()      const { return fSigma0Err; }
+  const Double_t GetSigma1Err()      const { return fSigma1Err; }
 
-  const Double_t GetChiSquare() const { return fChisquare; }
-  const Double_t GetProb()    const { return fProb;      }  
-  const Int_t    GetNdf()     const { return fNdf;       }   
+  const Double_t GetChiSquare()      const { return fChisquare; }
+  const Double_t GetProb()           const { return fProb;      }  
+  const Int_t    GetNdf()            const { return fNdf;       }   
 
   const Double_t GetMeanTime()      const { return fMeanTime; }
@@ -118,5 +124,5 @@
                            Double_t sigma1);
   
-  Bool_t FitSinglePhe(Axis_t rmin=0, Axis_t rmax=0, Option_t *opt="R0+");
+  Bool_t FitSinglePhe(Axis_t rmin=0, Axis_t rmax=0, Option_t *opt="RL0+");
   Bool_t FitTime(Axis_t rmin=0., Axis_t rmax=0.,Option_t *opt="R0+");
 
@@ -126,4 +132,6 @@
   void Draw(Option_t *option="");
 
+  Bool_t IsFitOK() { return fFitOK; }
+
   ClassDef(MHCalibrationBlindPixel, 1) 
 };
Index: trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.cc	(revision 2641)
+++ trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.cc	(revision 2642)
@@ -40,4 +40,6 @@
 
 #include <TFitter.h>
+#include <TGraph.h>
+#include <TAxis.h>
 
 #include <TF1.h>
@@ -62,4 +64,8 @@
 MHCalibrationPixel::MHCalibrationPixel(const char *name, const char *title)
       : fPixId(-1),
+	fHiGainvsLoGain(NULL),
+	fTotalEntries(0),
+	fHiGains(NULL),
+	fLoGains(NULL),
         fChargeGausFit(NULL), 
 	fTimeGausFit(NULL), 
@@ -141,4 +147,7 @@
     fHChargevsNLoGain->SetDirectory(NULL);
 
+    fHiGains = new TArrayF();
+    fLoGains = new TArrayF();
+
 }
 
@@ -153,4 +162,10 @@
   delete fHTimeLoGain;
   delete fHChargevsNLoGain;
+
+  if (fHiGainvsLoGain)
+    delete fHiGainvsLoGain;
+
+  delete fHiGains;
+  delete fLoGains;
 
   if (fChargeGausFit)
@@ -232,5 +247,5 @@
   fChargeLastHiGain     = 9999.5;
 
-  fHChargeLoGain->GetXaxis()->SetRangeUser(0.,fChargeLastLoGain);
+  fHChargeHiGain->GetXaxis()->SetRangeUser(0.,fChargeLastHiGain);
 
  for (Int_t i = fHChargeLoGain->FindBin(fChargeFirstLoGain); 
@@ -280,4 +295,15 @@
 }
 
+void MHCalibrationPixel::SetPointInGraph(Float_t qhi,Float_t qlo)
+{
+
+  fHiGains->Set(++fTotalEntries);
+  fLoGains->Set(fTotalEntries);
+
+  fHiGains->AddAt(qhi,fTotalEntries-1);
+  fLoGains->AddAt(qlo,fTotalEntries-1);
+
+}
+
 
 // -------------------------------------------------------------------------
@@ -338,4 +364,17 @@
 void MHCalibrationPixel::Draw(Option_t *opt) 
 {
+
+  if (!fHiGainvsLoGain)
+    {
+
+    // Create TGraph, we set the points later, get hold of the number of points with fTotalEntries
+    fHiGainvsLoGain = new TGraph(fTotalEntries,fHiGains->GetArray(),fLoGains->GetArray());
+    fHiGainvsLoGain->SetName("HiGainvsLoGain");
+    fHiGainvsLoGain->SetTitle("Plot the High Gain vs. Low Gain");
+    fHiGainvsLoGain->GetXaxis()->Set(300,0.,1500.);
+    fHiGainvsLoGain->GetYaxis()->Set(400,0.,2000.);
+    fHiGainvsLoGain->SetMarkerStyle(7);
+
+    }
 
     gStyle->SetOptFit(0);
@@ -374,4 +413,12 @@
 	    fChargeGausFit->DrawCopy("same");
 	  }
+	c->Modified();
+	c->Update();
+
+	c->cd(3);
+	gROOT->SetSelectedPad(NULL);
+	fHiGainvsLoGain->DrawClone("Apq")->SetBit(kCanDelete);
+	gPad->Modified();
+	gPad->Update();
 
 	c->cd(4);
@@ -393,7 +440,20 @@
 	gPad->SetLogy(1);
 	gPad->SetTicks();
+
 	fHChargeLoGain->DrawCopy(opt);
+	c->Modified();
+	c->Update();
+    
 	c->cd(3);
 	DrawLegend();
+
+	c->cd(4);
+	
+	gROOT->SetSelectedPad(NULL);
+	fHiGainvsLoGain->DrawClone("Apq")->SetBit(kCanDelete);
+	gPad->Modified();
+	gPad->Update();
+
+
       }	
 
@@ -426,4 +486,6 @@
 	    
 	    fTimeGausFit->DrawCopy("same");
+	    c->Modified();
+	    c->Update();
 	  }
       }
@@ -445,4 +507,7 @@
 	gPad->SetLogy(1);
 	fHTimeLoGain->DrawCopy(opt);	
+	c->Modified();
+	c->Update();
+    
       }
     c->Modified();
@@ -459,4 +524,5 @@
     c->Update();
 
+
 }
 
@@ -616,17 +682,11 @@
   fHChargeHiGain->Fit(fChargeGausFit,option);
   
-  Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.5*fChargeGausFit->GetParameter(2);
+  Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.0*fChargeGausFit->GetParameter(2);
   
   rmin = (rtry < rmin ? rmin : rtry);
-  rmax = fChargeGausFit->GetParameter(1) + 2.5*fChargeGausFit->GetParameter(2);
+  rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
   fChargeGausFit->SetRange(rmin,rmax);  
 
   fHChargeHiGain->Fit(fChargeGausFit,option);
-
-  //  rmin = fChargeGausFit->GetParameter(1) - 2.5*fChargeGausFit->GetParameter(2);
-  //  rmax = fChargeGausFit->GetParameter(1) + 2.5*fChargeGausFit->GetParameter(2);
-  //  fChargeGausFit->SetRange(rmin,rmax);  
-
-  // fHChargeHiGain->Fit(fChargeGausFit,option);
 
   fChargeChisquare = fChargeGausFit->GetChisquare();
@@ -697,8 +757,8 @@
   fHChargeLoGain->Fit(fChargeGausFit,option);
   
-  Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.5*fChargeGausFit->GetParameter(2);
+  Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.*fChargeGausFit->GetParameter(2);
   
   rmin = (rtry < rmin ? rmin : rtry);
-  rmax = fChargeGausFit->GetParameter(1) + 2.5*fChargeGausFit->GetParameter(2);
+  rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
   fChargeGausFit->SetRange(rmin,rmax);  
 
Index: trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.h	(revision 2641)
+++ trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.h	(revision 2642)
@@ -18,4 +18,12 @@
 #endif
 
+#ifndef ROOT_TGraph
+#include "TGraph.h"
+#endif
+
+#ifndef ROOT_TArrayF
+#include "TArrayF.h"
+#endif
+
 class TPaveText;
 class TMath;
@@ -27,16 +35,21 @@
 private:
 
-  Int_t fPixId;           //-> Pixel Nr
-  
+  Int_t fPixId;                  // Pixel Nr
+  TGraph *fHiGainvsLoGain;       // Plot the HiGain vs. the LoGain
+  Int_t fTotalEntries;           // Number of entries
+
+  TArrayF *fHiGains;
+  TArrayF *fLoGains;
+
 protected:
 
-  TH1F* fHChargeHiGain;              //-> Summed FADC slices
-  TH1I* fHTimeHiGain;                //-> Mean arrival time in number of FADC sice
-  TH1I* fHChargevsNHiGain;           //-> Summed Charge vs. Event Nr. 
+  TH1F* fHChargeHiGain;          // Summed FADC slices High Gain
+  TH1I* fHTimeHiGain;            // Mean arrival time in number of FADC sice
+  TH1I* fHChargevsNHiGain;       // Summed Charge vs. Event Nr. 
   
-  TH1F* fHChargeLoGain;              //-> Summed FADC slices
-  TH1I* fHTimeLoGain;                //-> Mean arrival time in number of FADC sice
-  TH1I* fHChargevsNLoGain;           //-> Summed Charge vs. Event Nr. 
-  
+  TH1F* fHChargeLoGain;          // Summed FADC slices Low Gain
+  TH1I* fHTimeLoGain;            // Mean arrival time in number of FADC sice
+  TH1I* fHChargevsNLoGain;       // Summed Charge vs. Event Nr. 
+
   TF1* fChargeGausFit;
   TF1* fTimeGausFit;
@@ -85,11 +98,13 @@
   Bool_t Fill(const MParContainer *, const Stat_t w=1) { return kTRUE; }
 
-  Bool_t FillChargeLoGain(Float_t q)             { return fHChargeLoGain->Fill(q)      > -1; }
-  Bool_t FillTimeLoGain(Int_t t)                 { return fHTimeLoGain->Fill(t)        > -1; }
-  Bool_t FillChargevsNLoGain(Float_t q, Int_t n) { return fHChargevsNLoGain->Fill(n,q) > -1; }
+  void   SetPointInGraph(Float_t qhi, Float_t qlo);
 
-  Bool_t FillChargeHiGain(Float_t q)             { return fHChargeHiGain->Fill(q)      > -1; }
-  Bool_t FillTimeHiGain(Int_t t)                 { return fHTimeHiGain->Fill(t)        > -1; }
-  Bool_t FillChargevsNHiGain(Float_t q, Int_t n) { return fHChargevsNHiGain->Fill(n,q) > -1; }
+  Bool_t FillChargeLoGain(Float_t q)             { return (fHChargeLoGain->Fill(q) > -1); }
+  Bool_t FillTimeLoGain(Int_t t)                 { return (fHTimeLoGain->Fill(t)   > -1); }
+  Bool_t FillChargevsNLoGain(Float_t q, Int_t n) { return (fHChargevsNLoGain->Fill(n,q) > -1); }
+
+  Bool_t FillChargeHiGain(Float_t q)             { return (fHChargeHiGain->Fill(q)      > -1); }
+  Bool_t FillTimeHiGain(Int_t t)                 { return (fHTimeHiGain->Fill(t)        > -1); }
+  Bool_t FillChargevsNHiGain(Float_t q, Int_t n) { return (fHChargevsNHiGain->Fill(n,q) > -1); }
 
   void   SetUseLoGain()                          { fUseLoGain = kTRUE; }
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 2641)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 2642)
@@ -125,5 +125,5 @@
     virtual void     SetCamContent(const MHCamera &d, Int_t type=0) { Reset(); AddCamContent(d, type); fEntries=d.fEntries; }
 
-    virtual void     SetCamError(const MCamEvent &event, Int_t type=0);
+    virtual void     SetCamError(const MCamEvent &evt, Int_t type=0);
 
     virtual void     CntCamContent(const MCamEvent &evt, Double_t threshold, Int_t type=0);
