Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationHiLoCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationHiLoCam.cc	(revision 7188)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationHiLoCam.cc	(revision 7189)
@@ -81,26 +81,4 @@
 /////////////////////////////////////////////////////////////////////////////
 #include "MHCalibrationHiLoCam.h"
-#include "MHCalibrationPix.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "MParList.h"
-
-#include "MCalibrationHiLoCam.h"
-#include "MCalibrationCam.h"
-#include "MCalibrationPix.h"
-
-#include "MExtractedSignalCam.h"
-#include "MExtractedSignalPix.h"
-#include "MArrivalTimeCam.h"
-#include "MArrivalTimePix.h"
-
-#include "MGeomCam.h"
-#include "MGeomPix.h"
-
-#include "MBadPixelsIntensityCam.h"
-#include "MBadPixelsCam.h"
-#include "MBadPixelsPix.h"
 
 #include <TOrdCollection.h>
@@ -114,4 +92,30 @@
 #include <TLegend.h>
 #include <TGraph.h>
+#include <TProfile.h>
+
+#include "MHCalibrationHiLoPix.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MCalibrationHiLoCam.h"
+#include "MCalibrationHiLoPix.h"
+#include "MCalibrationCam.h"
+#include "MCalibrationIntensityCam.h"
+#include "MCalibrationPix.h"
+
+#include "MExtractedSignalCam.h"
+#include "MExtractedSignalPix.h"
+#include "MArrivalTimeCam.h"
+#include "MArrivalTimePix.h"
+
+#include "MGeomCam.h"
+#include "MGeomPix.h"
+
+#include "MBadPixelsIntensityCam.h"
+#include "MBadPixelsCam.h"
+#include "MBadPixelsPix.h"
 
 ClassImp(MHCalibrationHiLoCam);
@@ -123,8 +127,17 @@
 const Axis_t  MHCalibrationHiLoCam::fgLast     = 29.9;
 const Float_t MHCalibrationHiLoCam::fgProbLimit = 0.;
+const Int_t   MHCalibrationHiLoCam::fgHivsLoNbins = 90;
+const Axis_t  MHCalibrationHiLoCam::fgHivsLoFirst = 95.;
+const Axis_t  MHCalibrationHiLoCam::fgHivsLoLast  = 995.;
+const Axis_t  MHCalibrationHiLoCam::fgLowerFitLimitProfile = 480.;
+const Axis_t  MHCalibrationHiLoCam::fgUpperFitLimitProfile = 680.;
 const TString MHCalibrationHiLoCam::gsHistName  = "HiLo";
 const TString MHCalibrationHiLoCam::gsHistTitle = "HiGain vs. LoGain";
 const TString MHCalibrationHiLoCam::gsHistXTitle = "Amplification Ratio [1]";
 const TString MHCalibrationHiLoCam::gsHistYTitle = "Nr. events";
+const TString MHCalibrationHiLoCam::gsHivsLoHistName   = "HivsLo";
+const TString MHCalibrationHiLoCam::gsHivsLoHistTitle  = "High-gain vs. Low-gain Charge";
+const TString MHCalibrationHiLoCam::gsHivsLoHistXTitle = "Q High-Gain [FADC counts]";
+const TString MHCalibrationHiLoCam::gsHivsLoHistYTitle = "Q Low-Gain [FADC counts]";
 
 // --------------------------------------------------------------------------
@@ -146,5 +159,7 @@
 //
 MHCalibrationHiLoCam::MHCalibrationHiLoCam(const char *name, const char *title) 
-  : fArrTimes(NULL)
+  : fArrTimes(NULL), fHivsLoResults("Results","Fit Results high-gain vs. low-gain",
+				    200,-10.,10.,200,0.,20.),
+    fUsedLoGainSlices(0)
 {
 
@@ -163,5 +178,22 @@
   SetHistYTitle(gsHistYTitle.Data());
 
+  SetHivsLoNbins(fgHivsLoNbins);
+  SetHivsLoFirst(fgHivsLoFirst);
+  SetHivsLoLast (fgHivsLoLast );
+
+  SetLowerFitLimitProfile();
+  SetUpperFitLimitProfile();
+
+  SetHivsLoHistName  (gsHivsLoHistName  .Data());
+  SetHivsLoHistTitle (gsHivsLoHistTitle .Data());
+  SetHivsLoHistXTitle(gsHivsLoHistXTitle.Data());
+  SetHivsLoHistYTitle(gsHivsLoHistYTitle.Data());
+
   SetOscillations(kFALSE);
+  
+  fHivsLoResults.GetXaxis()->SetTitle("Offset per FADC slices [FADC cnts]");
+  fHivsLoResults.GetYaxis()->SetTitle("Gains ratio [1]");
+  fHivsLoResults.SetDirectory(0);
+
 }
 
@@ -254,4 +286,6 @@
   }
 
+  fUsedLoGainSlices = signal->GetNumUsedLoGainFADCSlices();
+
   fArrTimes = (MArrivalTimeCam*)pList->FindObject("MArrivalTimeCam");
   if (!fArrTimes)
@@ -282,4 +316,250 @@
   return kTRUE;
 }
+
+// --------------------------------------------------------------------------
+//
+// Retrieve:
+// - fRunHeader->GetNumSamplesHiGain();
+//
+// Initializes the High Gain Arrays:
+//
+// - For every entry in the expanded arrays: 
+//   * Initialize an MHCalibrationHiLoPix
+//   * Set Binning from  fNbins, fFirst and fLast
+//   * Set Binning of Abs Times histogram from  fAbsNbins, fAbsFirst and fAbsLast
+//   * Set Histgram names and titles from fHistName and fHistTitle
+//   * Set Abs Times Histgram names and titles from fAbsHistName and fAbsHistTitle
+//   * Set X-axis and Y-axis titles from fHistXTitle and fHistYTitle
+//   * Set X-axis and Y-axis titles of Abs Times Histogram from fAbsHistXTitle and fAbsHistYTitle
+//   * Call InitHists
+//
+//
+void MHCalibrationHiLoCam::InitHiGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
+{
+  
+  TProfile *h;
+
+  if (fHiGainArray->GetSize()==0)
+  {
+      for (Int_t i=0; i<npixels; i++)
+      {
+        fHiGainArray->AddAt(new MHCalibrationHiLoPix(Form("%sHiGainPix%04d",fHistName.Data(),i),
+                                                       Form("%s High Gain Pixel%04d",fHistTitle.Data(),i)),i);
+
+        MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)(*this)[i];
+
+        pix.SetNbins(fNbins);
+        pix.SetFirst(fFirst);
+        pix.SetLast (fLast);
+
+        pix.SetProbLimit(fProbLimit);
+
+        pix.SetHivsLoNbins(fHivsLoNbins);
+        pix.SetHivsLoFirst(fHivsLoFirst);
+        pix.SetHivsLoLast (fHivsLoLast);
+
+        InitHists(pix,(*fBadPixels)[i],i);
+
+	if (fCam)
+	  (*fCam)[i].SetPixId(i);
+
+        h = pix.GetHivsLo();
+
+        h->SetName (Form("H%sHiGainPix%04d",fHivsLoHistName.Data(),i));
+        h->SetTitle(Form("%s High Gain Pixel %04d",fHivsLoHistTitle.Data(),i));
+        h->SetXTitle(fHivsLoHistXTitle.Data());
+        h->SetYTitle(fHivsLoHistYTitle.Data());
+        h->SetDirectory(0);
+      }
+  }
+
+
+  if (fAverageHiGainAreas->GetSize()==0)
+  {
+    for (Int_t j=0; j<nareas; j++)
+      {
+        fAverageHiGainAreas->AddAt(new MHCalibrationHiLoPix(Form("%sHiGainArea%d",fHistName.Data(),j),
+                                                  Form("%s High Gain Area Idx %d",fHistTitle.Data(),j)),j);
+        
+        MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)GetAverageHiGainArea(j);
+        
+        pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
+        pix.SetFirst(fFirst);
+        pix.SetLast (fLast);
+        
+        pix.SetHivsLoNbins(fHivsLoNbins);
+        pix.SetHivsLoFirst(fHivsLoFirst);
+        pix.SetHivsLoLast (fHivsLoLast);
+
+        InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
+
+	if (fCam)
+	  fCam->GetAverageArea(j).SetPixId(j);
+
+        h =  pix.GetHivsLo();
+        
+        h->SetName (Form("H%sHiGainArea%d",fHivsLoHistName.Data(),j));
+        h->SetTitle(Form("%s averaged on event-by-event basis High Gain Area Idx %d",
+                         fHivsLoHistTitle.Data(), j));
+        h->SetXTitle(fHivsLoHistXTitle.Data());
+        h->SetYTitle(fHivsLoHistYTitle.Data());
+        h->SetDirectory(0);
+      }
+  }
+  
+  if (fAverageHiGainSectors->GetSize()==0)
+  {
+      for (Int_t j=0; j<nsectors; j++)
+        {
+	  fAverageHiGainSectors->AddAt(new MHCalibrationHiLoPix(Form("%sHiGainSector%02d",fHistName.Data(),j),
+                                                      Form("%s High Gain Sector %02d",fHistTitle.Data(),j)),j);
+
+          MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)GetAverageHiGainSector(j);
+
+          pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
+          pix.SetFirst(fFirst);
+          pix.SetLast (fLast);
+
+          pix.SetHivsLoNbins(fHivsLoNbins);
+          pix.SetHivsLoFirst(fHivsLoFirst);
+          pix.SetHivsLoLast (fHivsLoLast);
+          
+          InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
+
+	  if (fCam)
+	    fCam->GetAverageSector(j).SetPixId(j);
+
+          h =  pix.GetHivsLo();
+          
+          h->SetName (Form("H%sHiGainSector%02d",fHivsLoHistName.Data(),j));
+          h->SetTitle(Form("%s averaged on event-by-event basis High Gain Area Sector %02d",
+                           fHivsLoHistTitle.Data(),j));
+          h->SetXTitle(fHivsLoHistXTitle.Data());
+          h->SetYTitle(fHivsLoHistYTitle.Data());
+          h->SetDirectory(0);
+      }
+  }
+}
+
+//--------------------------------------------------------------------------------------
+//
+// Return, if IsLoGain() is kFALSE 
+//
+// Retrieve:
+// - fRunHeader->GetNumSamplesHiGain();
+//
+// Initializes the Low Gain Arrays:
+//
+// - For every entry in the expanded arrays: 
+//   * Initialize an MHCalibrationHiLoPix
+//   * Set Binning from  fNbins, fFirst and fLast
+//   * Set Binning of HivsLo Times histogram from  fHivsLoNbins, fHivsLoFirst and fHivsLoLast
+//   * Set Histgram names and titles from fHistName and fHistTitle
+//   * Set HivsLo Times Histgram names and titles from fHivsLoHistName and fHivsLoHistTitle
+//   * Set X-axis and Y-axis titles from fHistXTitle and fHistYTitle
+//   * Set X-axis and Y-axis titles of HivsLo Times Histogram from fHivsLoHistXTitle and fHivsLoHistYTitle
+//   * Call InitHists
+//
+void MHCalibrationHiLoCam::InitLoGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
+{
+  if (!IsLoGain())
+    return;
+
+  TProfile *h;
+
+  if (fLoGainArray->GetSize()==0 )
+    {
+      for (Int_t i=0; i<npixels; i++)
+        {
+          fLoGainArray->AddAt(new MHCalibrationHiLoPix(Form("%sLoGainPix%04d",fHistName.Data(),i),
+                                       Form("%s Low Gain Pixel %04d",fHistTitle.Data(),i)),i);
+
+          MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)(*this)(i);
+
+          pix.SetNbins(fNbins);
+          pix.SetFirst(fFirst);
+          pix.SetLast (fLast);
+          
+          pix.SetProbLimit(fProbLimit);
+
+          pix.SetHivsLoNbins(fHivsLoNbins);
+          pix.SetHivsLoFirst(fHivsLoFirst);
+          pix.SetHivsLoLast (fHivsLoLast );
+          
+          InitHists(pix,(*fBadPixels)[i],i);
+
+          h = pix.GetHivsLo();
+          
+          h->SetName (Form("H%sLoGainPix%04d",fHivsLoHistName.Data(),i));
+          h->SetTitle(Form("%s Low Gain Pixel %04d",fHivsLoHistTitle.Data(),i));
+          h->SetXTitle(fHivsLoHistXTitle.Data());
+          h->SetYTitle(fHivsLoHistYTitle.Data());
+          h->SetDirectory(0);
+      }
+  }
+
+  if (fAverageLoGainAreas->GetSize()==0)
+    {
+      for (Int_t j=0; j<nareas; j++)
+        {
+	  fAverageLoGainAreas->AddAt(new MHCalibrationHiLoPix(Form("%sLoGainArea%d",fHistName.Data(),j),
+                                       Form("%s Low Gain Area Idx %d",fHistTitle.Data(),j)),j);
+        
+          MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)GetAverageLoGainArea(j);
+          
+          pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
+          pix.SetFirst(fFirst);
+          pix.SetLast (fLast);
+          
+          pix.SetHivsLoNbins(fHivsLoNbins);
+          pix.SetHivsLoFirst(fHivsLoFirst);
+          pix.SetHivsLoLast (fHivsLoLast );
+          
+          InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
+
+          h =  pix.GetHivsLo();
+          
+          h->SetName (Form("H%sLoGainArea%02d",fHivsLoHistName.Data(),j));
+          h->SetTitle(Form("%s%s%02d",fHivsLoHistTitle.Data(),
+                           " averaged on event-by-event basis Low Gain Area Idx ",j));
+          h->SetXTitle(fHivsLoHistXTitle.Data());
+          h->SetYTitle(fHivsLoHistYTitle.Data());
+          h->SetDirectory(0);
+        }
+    }
+  
+
+  if (fAverageLoGainSectors->GetSize()==0 && IsLoGain())
+  {
+    for (Int_t j=0; j<nsectors; j++)
+      {
+        fAverageLoGainSectors->AddAt(new MHCalibrationHiLoPix(Form("%sLoGainSector%02d",fHistName.Data(),j),
+                                                        Form("%s Low Gain Sector %02d",fHistTitle.Data(),j)),j);
+        
+        MHCalibrationHiLoPix &pix = (MHCalibrationHiLoPix&)GetAverageLoGainSector(j);
+        
+        pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
+        pix.SetFirst(fFirst);
+        pix.SetLast (fLast);
+        
+        pix.SetHivsLoNbins(fHivsLoNbins);
+        pix.SetHivsLoFirst(fHivsLoFirst);
+        pix.SetHivsLoLast (fHivsLoLast);
+        
+        InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
+
+        h =  pix.GetHivsLo();
+        
+        h->SetName (Form("H%sLoGainSector%02d",fHivsLoHistName.Data(),j));
+        h->SetTitle(Form("%s%s%02d",fHivsLoHistTitle.Data(),
+                           " averaged on event-by-event basis Low Gain Area Sector ",j));
+        h->SetXTitle(fHivsLoHistXTitle.Data());
+        h->SetYTitle(fHivsLoHistYTitle.Data());
+        h->SetDirectory(0);
+      }
+  }
+}
+
+
 
 // -------------------------------------------------------------------------------
@@ -341,9 +621,19 @@
 
       const Float_t sighi = pix.GetExtractedSignalHiGain();
+
+      //      *fLog << err << sighi << "  " << siglo << endl;
       const Float_t ratio = sighi / siglo;
       
-      MHCalibrationPix &histhi = (*this)[i];
+      MHCalibrationHiLoPix &histhi = (MHCalibrationHiLoPix&)(*this)[i];
 
       histhi.FillHist(ratio);
+      histhi.FillHivsLo(sighi,siglo);
+
+      if (IsAverageing())
+	{
+	  MHCalibrationHiLoPix &histhi = (MHCalibrationHiLoPix&)GetAverageHiGainArea(aidx);
+	  histhi.FillHivsLo(sighi,siglo);
+	}
+
       fSumareahi  [aidx]   += ratio;
       fNumareahi  [aidx]   ++;
@@ -371,5 +661,7 @@
   for (Int_t j=0; j<nareas; j++)
     {
-      MHCalibrationPix &histhi = GetAverageHiGainArea(j);
+
+      MHCalibrationHiLoPix &histhi = (MHCalibrationHiLoPix&)GetAverageHiGainArea(j);
+      
       if (IsOscillations())
 	histhi.FillHistAndArray(fNumareahi[j] == 0 ? 0. : fSumareahi[j]/fNumareahi[j]);
@@ -390,4 +682,5 @@
     {
       MHCalibrationPix &hist = GetAverageHiGainSector(j);
+
       if (IsOscillations())
 	hist.FillHistAndArray(fNumsectorhi[j] == 0 ? 0. : fSumsectorhi[j]/fNumsectorhi[j]);
@@ -397,5 +690,7 @@
       if (IsLoGain())
 	{
+
 	  MHCalibrationPix &histlo = GetAverageLoGainSector(j);
+
 	  if (IsOscillations())
 	    histlo.FillHistAndArray(fNumsectorlo[j] == 0 ? 0. : fSumsectorlo[j]/fNumsectorlo[j]);
@@ -425,10 +720,9 @@
 
   const Int_t nareas   = fAverageHiGainAreas->GetSize();
-  const Int_t nsectors = fAverageHiGainSectors->GetSize();
 
   for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
     {
       
-      MHCalibrationPix &hist = (*this)[i];
+      MHCalibrationHiLoPix &hist = (MHCalibrationHiLoPix&)(*this)[i];
 
       if (hist.IsExcluded())
@@ -436,4 +730,21 @@
       
       CheckOverflow(hist);
+
+      TProfile *h = hist.GetHivsLo();
+      h->Fit("pol1","RQ","",fLowerFitLimitProfile,fUpperFitLimitProfile);
+
+      TF1 *fit = h->GetFunction("pol1");
+
+      const Float_t gainr  = fit->GetParameter(1) > 0.001 
+	? 1./fit->GetParameter(1) 
+	: 0.;
+      const Float_t offset = fit->GetParameter(0)/fUsedLoGainSlices;
+
+      fHivsLoResults.Fill(offset,gainr);
+      
+      MCalibrationHiLoPix &pix = (MCalibrationHiLoPix&)(*fCam)[i];
+      pix.SetOffsetPerSlice(offset);
+      pix.SetGainRatio     (gainr );
+
     }
 
@@ -472,8 +783,52 @@
   {
       for (Int_t j=0; j<nareas; j++)
-          CheckOverflow(GetAverageLoGainArea(j));
-
-      for (Int_t j=0; j<nsectors; j++)
-          CheckOverflow(GetAverageLoGainSector(j));
+        {
+	  
+	  MHCalibrationHiLoPix &hist = (MHCalibrationHiLoPix&)GetAverageHiGainArea(j);
+	  //
+	  // Check histogram overflow
+	  // 
+	  CheckOverflow(hist);
+	  
+	  TProfile *h = hist.GetHivsLo();
+	  h->Fit("pol1","RQ","",fLowerFitLimitProfile,fUpperFitLimitProfile);
+
+	  TF1 *fit = h->GetFunction("pol1");
+	  
+	  const Float_t gainr  = fit->GetParameter(1) > 0.001 
+	    ? 1./fit->GetParameter(1) 
+	    : 0.;
+	  const Float_t offset = fit->GetParameter(0)/fUsedLoGainSlices;
+	  
+	  MCalibrationHiLoPix &pix = (MCalibrationHiLoPix&)fCam->GetAverageArea(0);
+	  pix.SetOffsetPerSlice(offset);
+	  pix.SetGainRatio     (gainr );
+
+        }
+      
+      for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
+        {
+	  
+          MHCalibrationHiLoPix &hist = (MHCalibrationHiLoPix&)GetAverageHiGainSector(j);      
+          //
+          // Check histogram overflow
+          // 
+          CheckOverflow(hist);
+
+	  TProfile *h = hist.GetHivsLo();
+	  h->Fit("pol1","RQ","",fLowerFitLimitProfile,fUpperFitLimitProfile);
+
+	  TF1 *fit = h->GetFunction("pol1");
+	  
+	  const Float_t gainr  = fit->GetParameter(1) > 0.001 
+	    ? 1./fit->GetParameter(1) 
+	    : 0.;
+	  const Float_t offset = fit->GetParameter(0)/fUsedLoGainSlices;
+	  
+	  MCalibrationHiLoPix &pix = (MCalibrationHiLoPix&)fCam->GetAverageSector(0);
+	  pix.SetOffsetPerSlice(offset);
+	  pix.SetGainRatio     (gainr );
+
+        }
   }
 
@@ -680,2 +1035,42 @@
 }
 
+Int_t MHCalibrationHiLoCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+
+  Bool_t rc = kFALSE;
+
+  if (MHCalibrationCam::ReadEnv(env,prefix,print))
+    rc = kTRUE;
+   
+  if (IsEnvDefined(env, prefix, "LowerFitLimitProfile", print))
+    {
+      SetLowerFitLimitProfile(GetEnvValue(env, prefix, "LowerFitLimitProfile", fLowerFitLimitProfile));
+      rc = kTRUE;
+    }
+  
+  if (IsEnvDefined(env, prefix, "UpperFitLimitProfile", print))
+    {
+      SetUpperFitLimitProfile(GetEnvValue(env, prefix, "UpperFitLimitProfile", fUpperFitLimitProfile));
+      rc = kTRUE;
+    }
+  
+  if (IsEnvDefined(env, prefix, "HivsLoNbins", print))
+    {
+      SetHivsLoNbins(GetEnvValue(env, prefix, "HivsLoNbins", fHivsLoNbins));
+      rc = kTRUE;
+    }
+  
+  if (IsEnvDefined(env, prefix, "HivsLoFirst", print))
+    {
+      SetHivsLoFirst(GetEnvValue(env, prefix, "HivsLoFirst", fHivsLoFirst));
+      rc = kTRUE;
+    }
+  
+  if (IsEnvDefined(env, prefix, "HivsLoLast", print))
+    {
+      SetHivsLoLast(GetEnvValue(env, prefix, "HivsLoLast", fHivsLoLast));
+      rc = kTRUE;
+    }
+  
+  return rc;
+}
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationHiLoCam.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationHiLoCam.h	(revision 7188)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationHiLoCam.h	(revision 7189)
@@ -14,39 +14,76 @@
 #endif
 
-class TH1F;
+#ifndef ROOT_TH2F
+#include <TH2F.h>
+#endif
 
 class MGeomCam;
 class MArrivalTimeCam;
+class MHCalibrationHiLoPix;
 
 class MHCalibrationHiLoCam : public MHCalibrationCam
 {
 private:
-  static const Int_t   fgNbins;                      //! Default number of bins        (now set to: 900   )
-  static const Axis_t  fgFirst;                      //! Default lower histogram limit (now set to: -13.5 )
-  static const Axis_t  fgLast;                       //! Default upper histogram limit (now set to:  13.5 )
-  static const Float_t fgProbLimit;                  //! The default for fProbLimit    (now set to: 0.0)  
-  
-  static const TString gsHistName;                   //! Default Histogram names
-  static const TString gsHistTitle;                  //! Default Histogram titles
-  static const TString gsHistXTitle;                 //! Default Histogram x-axis titles
-  static const TString gsHistYTitle;                 //! Default Histogram y-axis titles
+   static const Int_t   fgNbins;                //! Default number of bins        (now set to: 900   )
+   static const Axis_t  fgFirst;                //! Default lower histogram limit (now set to: -13.5 )
+   static const Axis_t  fgLast;                 //! Default upper histogram limit (now set to:  13.5 )
+   static const Float_t fgProbLimit;            //! The default for fProbLimit    (now set to: 0.0)
 
-  MArrayD fSumareahi  ;                               //
-  MArrayD fSumsectorhi;                               //
-  MArrayI fNumareahi  ;                               //
-  MArrayI fNumsectorhi;                               //
-  MArrayD fSumarealo  ;                               //
-  MArrayD fSumsectorlo;                               //
-  MArrayI fNumarealo  ;                               //
-  MArrayI fNumsectorlo;                               //
+   static const Int_t   fgHivsLoNbins;          //! Default number of bins        (now set to: 900   )
+   static const Axis_t  fgHivsLoFirst;          //! Default lower histogram limit (now set to: -13.5 )
+   static const Axis_t  fgHivsLoLast;           //! Default upper histogram limit (now set to:  13.5 )
 
-  MArrivalTimeCam *fArrTimes;                         //! Pointer to arrival times
+   static const Axis_t  fgLowerFitLimitProfile; //! Default for fLowerFitLimitProfile    (now set to: 480. )
+   static const Axis_t  fgUpperFitLimitProfile; //! Default for fUpperFitLimitProfile    (now set to: 680. )
 
-  Bool_t ReInitHists(MParList *pList);
-  Bool_t FillHists(const MParContainer *par, const Stat_t w=1);
-  Bool_t FinalizeHists();
-  void   FinalizeBadPixels();
+   static const TString gsHistName;          //! Default Histogram names
+   static const TString gsHistTitle;         //! Default Histogram titles
+   static const TString gsHistXTitle;        //! Default Histogram x-axis titles
+   static const TString gsHistYTitle;        //! Default Histogram y-axis titles
 
-  void   CheckOverflow( MHCalibrationPix &pix);
+   static const TString gsHivsLoHistName;    //! Default  names hi vs. lo profile
+   static const TString gsHivsLoHistTitle;   //! Default  titles hi vs. lo profile
+   static const TString gsHivsLoHistXTitle;  //! Default  x-axis titles hi vs. lo profile
+   static const TString gsHivsLoHistYTitle;  //! Default  y-axis titles hi vs. lo profile
+
+   TString fHivsLoHistName;                  //  names hi vs. lo profile
+   TString fHivsLoHistTitle;                 //  titles hi vs. lo profile
+   TString fHivsLoHistXTitle;                //  x-axis titles hi vs. lo profile
+   TString fHivsLoHistYTitle;                //  y-axis titles hi vs. lo profile
+
+   Int_t   fHivsLoNbins;                     // Number of HivsLo bins
+   Axis_t  fHivsLoFirst;                     // Lower histogram limit low gain
+   Axis_t  fHivsLoLast;                      // Upper histogram limit low gain
+
+   Axis_t  fLowerFitLimitProfile;            // Lower limit for hi-vs. logain fit
+   Axis_t  fUpperFitLimitProfile;            // Upper limit for hi-vs. logain fit
+
+   MArrayD fSumareahi  ;                     //
+   MArrayD fSumsectorhi;                     //
+   MArrayI fNumareahi  ;                     //
+   MArrayI fNumsectorhi;                     //
+   MArrayD fSumarealo  ;                     //
+   MArrayD fSumsectorlo;                     //
+   MArrayI fNumarealo  ;                     //
+   MArrayI fNumsectorlo;                     //
+
+   MArrivalTimeCam *fArrTimes;               //! Pointer to arrival times
+
+   TH2F    fHivsLoResults;                   // Results from pol1-fit
+
+   Float_t fUsedLoGainSlices;                // Used low-gain FADC slices
+   Bool_t ReInitHists(MParList *pList);
+   Bool_t FillHists(const MParContainer *par, const Stat_t w=1);
+   Bool_t FinalizeHists();
+   void   FinalizeBadPixels();
+
+   void   InitHiGainArrays( const Int_t npix, const Int_t nareas, const Int_t nsectors );
+   void   InitLoGainArrays( const Int_t npix, const Int_t nareas, const Int_t nsectors );
+
+   void   FinalizeHivsLo (MHCalibrationHiLoPix &hist);
+
+   void   CheckOverflow( MHCalibrationPix &pix);
+
+   Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
   
 public:
@@ -55,4 +92,18 @@
   // Clone
   TObject *Clone(const char *name="") const;
+
+  TH2F &GetHivsLoResults() { return fHivsLoResults; }
+
+  void SetHivsLoHistName   ( const char *name )  { fHivsLoHistName   = name; }
+  void SetHivsLoHistTitle  ( const char *name )  { fHivsLoHistTitle  = name; }
+  void SetHivsLoHistXTitle ( const char *name )  { fHivsLoHistXTitle = name; }
+  void SetHivsLoHistYTitle ( const char *name )  { fHivsLoHistYTitle = name; }
+
+  void SetHivsLoNbins      ( const Int_t  i=fgHivsLoNbins   ) { fHivsLoNbins   = i; }
+  void SetHivsLoFirst      ( const Axis_t f=fgHivsLoFirst   ) { fHivsLoFirst   = f; }
+  void SetHivsLoLast       ( const Axis_t f=fgHivsLoLast    ) { fHivsLoLast    = f; }
+
+  void SetLowerFitLimitProfile( const Axis_t f=fgLowerFitLimitProfile ) { fLowerFitLimitProfile = f; }
+  void SetUpperFitLimitProfile( const Axis_t f=fgUpperFitLimitProfile ) { fUpperFitLimitProfile = f; }
 
   // Draw
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc	(revision 7188)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc	(revision 7189)
@@ -464,5 +464,11 @@
 
       if (npix > fNumPixelsRequired)
-        GetAverageHiGainArea(j).FillHist(fSumhiarea[j]/npix);
+	{
+	   if (IsOscillations())
+	        GetAverageHiGainArea(j).FillHistAndArray(fSumhiarea[j]/npix);
+	   else
+	        GetAverageHiGainArea(j).FillHist(fSumhiarea[j]/npix);
+
+	}
     }
 
@@ -473,5 +479,10 @@
 
       if (npix > 0)
-        GetAverageHiGainSector(j).FillHist(fSumhisector [j]/npix);
+	{
+	   if (IsOscillations())
+	        GetAverageHiGainSector(j).FillHistAndArray(fSumhisector [j]/npix);
+	   else
+	        GetAverageHiGainSector(j).FillHist(fSumhisector [j]/npix);
+	}
     }
 
@@ -560,4 +571,5 @@
     {
       *fLog << dbginf << GetDescriptor() << ": ID " << GetName() 
+            << " "<<pix.GetPixId()
             << " Mean: "         << hist.GetMean    ()
             << " MeanErr: "      << hist.GetMeanErr ()
Index: trunk/MagicSoft/Mars/mhcalib/MHGausEvents.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHGausEvents.h	(revision 7188)
+++ trunk/MagicSoft/Mars/mhcalib/MHGausEvents.h	(revision 7189)
@@ -169,5 +169,5 @@
   void  SimulateGausEvents(const Float_t mean, const Float_t sigma, const Int_t nevts=4096);     // *MENU*
 
-  ClassDef(MHGausEvents, 3) // Base class for events with Gaussian distributed values
+  ClassDef(MHGausEvents, 4) // Base class for events with Gaussian distributed values
 };
 
