Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 2922)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 2932)
@@ -56,94 +56,73 @@
 MHCalibrationPixel::MHCalibrationPixel(const char *name, const char *title)
       : fPixId(-1),
-	fTotalEntries(0),
-        fHChargeHiGain(NULL),  
-        fHTimeHiGain(NULL), 
-        fHChargevsNHiGain(NULL),
-        fHChargeLoGain(NULL),  
-        fHTimeLoGain(NULL),    
-        fHChargevsNLoGain(NULL),
-        fChargeGausFit(NULL), 
+        fChargeNbinsHiGain(2100),
+        fChargeNbinsLoGain(1010),
+        fTimeNbins(32),
+        fChargevsNbins(1000),
+        fTimeFirst(-0.25),
+        fTimeLast(15.75),
+	fHivsLoGain(NULL),
+        fChargeGausFit(NULL),
 	fTimeGausFit(NULL), 
-	fHivsLoGain(NULL),
-	fFitLegend(NULL),
-	fChargeFirstHiGain(-100.5),
-	fChargeLastHiGain(1999.5),
-	fChargeNbinsHiGain(2100),
-	fChargeFirstLoGain(-100.5),
-	fChargeLastLoGain(9999.5),
-	fChargeNbinsLoGain(1010),
-        fChargeChisquare(-1.),
-        fChargeProb(-1.),
-        fChargeNdf(-1),
-        fTimeChisquare(-1.),
-        fTimeProb(-1.),
-        fTimeNdf(-1),
-        fTimeMean(-1.),
-        fTimeSigma(-1.),
-        fTimeLowerFitRangeHiGain(0),
-        fTimeUpperFitRangeHiGain(0),
-        fTimeLowerFitRangeLoGain(0),
-        fTimeUpperFitRangeLoGain(0),
-	fOffset(0.),
-	fSlope(0.)
+	fFitLegend(NULL)
 { 
 
     fName  = name  ? name  : "MHCalibrationPixel";
     fTitle = title ? title : "Fill the accumulated charges and times of all events and perform fits";
+
+    fChargeFirstHiGain = -100.5;
+    fChargeLastHiGain  = 1999.5;
+    fChargeFirstLoGain = -100.5;
+    fChargeLastLoGain  = 9999.5;
 
     // Create a large number of bins, later we will rebin
     fHChargeHiGain = new TH1F("HChargeHiGain","Distribution of Summed FADC Hi Gain Slices Pixel ",
 			      fChargeNbinsHiGain,fChargeFirstHiGain,fChargeLastHiGain);
-    fHChargeHiGain->SetXTitle("Sum FADC Slices (Hi Gain)");
-    fHChargeHiGain->SetYTitle("Nr. of events");
-    fHChargeHiGain->Sumw2();
-
-    fHChargeHiGain->SetDirectory(NULL);
-
     fHChargeLoGain = new TH1F("HChargeLoGain","Distribution of Summed FADC Lo Gain Slices Pixel ",
 			      fChargeNbinsLoGain,fChargeFirstLoGain,fChargeLastLoGain);
+
     fHChargeLoGain->SetXTitle("Sum FADC Slices (Lo Gain)");
+    fHChargeHiGain->SetXTitle("Sum FADC Slices (Hi Gain)");
+
     fHChargeLoGain->SetYTitle("Nr. of events");
+    fHChargeHiGain->SetYTitle("Nr. of events");
+
+    fHChargeHiGain->Sumw2();
     fHChargeLoGain->Sumw2();
 
+    fHTimeHiGain = new TH1F("HTimeHiGain","Distribution of Mean Arrival Hi Gain Times Pixel ",
+			    fTimeNbins,fTimeFirst,fTimeLast);
+    fHTimeLoGain = new TH1F("HTimeLoGain","Distribution of Mean Arrival Lo Gain Times Pixel ",
+			    fTimeNbins,fTimeFirst,fTimeLast);
+
+    fHTimeHiGain->SetXTitle("Mean Arrival Times [Hi Gain FADC slice nr]");
+    fHTimeLoGain->SetXTitle("Mean Arrival Times [Lo Gain FADC slice nr]");
+
+    fHTimeHiGain->SetYTitle("Nr. of events");
+    fHTimeLoGain->SetYTitle("Nr. of events");
+
+    // We define a reasonable number and later enlarge it if necessary
+    fHChargevsNHiGain = new TH1I("HChargevsNHiGain","Sum of Hi Gain Charges vs. Event Number Pixel ",
+				 fChargevsNbins,-0.5,(Axis_t)fChargevsNbins - 0.5);
+    fHChargevsNLoGain = new TH1I("HChargevsNLoGain","Sum of Lo Gain Charges vs. Event Number Pixel ",
+				 fChargevsNbins,-0.5,(Axis_t)fChargevsNbins - 0.5);
+
+    fHChargevsNHiGain->SetXTitle("Event Nr.");
+    fHChargevsNLoGain->SetXTitle("Event Nr.");
+
+    fHChargevsNHiGain->SetYTitle("Sum of Hi Gain FADC slices");
+    fHChargevsNLoGain->SetYTitle("Sum of Lo Gain FADC slices");
+
+    fHChargeHiGain->SetDirectory(NULL);
     fHChargeLoGain->SetDirectory(NULL);
-
-    Axis_t tfirst = -0.5;
-    Axis_t tlast  = 15.5;
-    Int_t  ntbins = 32;
-
-    fHTimeHiGain = new TH1F("HTimeHiGain","Distribution of Mean Arrival Hi Gain Times Pixel ",
-			    ntbins,tfirst,tlast);
-    fHTimeHiGain->SetXTitle("Mean Arrival Times [Hi Gain FADC slice nr]");
-    fHTimeHiGain->SetYTitle("Nr. of events");
     fHTimeHiGain->SetDirectory(NULL);
-
-    fHTimeLoGain = new TH1F("HTimeLoGain","Distribution of Mean Arrival Lo Gain Times Pixel ",
-			    ntbins,tfirst,tlast);
-    fHTimeLoGain->SetXTitle("Mean Arrival Times [Lo Gain FADC slice nr]");
-    fHTimeLoGain->SetYTitle("Nr. of events");
     fHTimeLoGain->SetDirectory(NULL);
-
-    // We define a reasonable number and later enlarge it if necessary
-    Int_t  nqbins = 20000;
-    Axis_t nfirst = -0.5;
-    Axis_t nlast  = (Axis_t)nqbins - 0.5;
-
-    fHChargevsNHiGain = new TH1I("HChargevsNHiGain","Sum of Hi Gain Charges vs. Event Number Pixel ",
-				 nqbins,nfirst,nlast);
-    fHChargevsNHiGain->SetXTitle("Event Nr.");
-    fHChargevsNHiGain->SetYTitle("Sum of Hi Gain FADC slices");
-
     fHChargevsNHiGain->SetDirectory(NULL);
-
-    fHChargevsNLoGain = new TH1I("HChargevsNLoGain","Sum of Lo Gain Charges vs. Event Number Pixel ",
-				 nqbins,nfirst,nlast);
-    fHChargevsNLoGain->SetXTitle("Event Nr.");
-    fHChargevsNLoGain->SetYTitle("Sum of Lo Gain FADC slices");
-
     fHChargevsNLoGain->SetDirectory(NULL);
 
     fHiGains = new TArrayF();
     fLoGains = new TArrayF();
+
+    Clear();
 
 }
@@ -171,6 +150,74 @@
   if (fHivsLoGain)
     delete fHivsLoGain;
-
-}
+}
+
+
+void MHCalibrationPixel::Clear(Option_t *o)
+{
+  
+  fTotalEntries            = 0;
+
+  fChargeFirstHiGain       = -100.5;
+  fChargeLastHiGain        = 1999.5;
+  fChargeFirstLoGain       = -100.5;
+  fChargeLastLoGain        = 9999.5;
+
+  fChargeChisquare         = -1.;
+  fChargeProb              = -1.;
+  fChargeNdf               = -1;
+  fTimeChisquare           = -1.;
+  fTimeProb                = -1.;
+  fTimeNdf                 = -1;
+  fTimeMean                = -1.;
+  fTimeSigma               = -1.;
+
+  fTimeLowerFitRangeHiGain = 0;
+  fTimeUpperFitRangeHiGain = 0;
+  fTimeLowerFitRangeLoGain = 0;
+  fTimeUpperFitRangeLoGain = 0;
+
+  fOffset = 0.;
+  fSlope  = 0;
+
+  if (fChargeGausFit)
+    delete fChargeGausFit;
+  if (fTimeGausFit)
+    delete fTimeGausFit;
+  if (fFitLegend)
+    delete fFitLegend;
+  if (fHivsLoGain)
+    delete fHivsLoGain;
+  if (fHPSD)
+    delete fHPSD;
+
+  return;
+}
+
+
+void MHCalibrationPixel::Reset()
+{
+  
+  Clear();
+  
+  fHChargeHiGain->Reset();
+  fHChargeLoGain->Reset();
+  fHTimeHiGain->Reset();
+  fHTimeLoGain->Reset();
+  fHChargevsNHiGain->Reset();
+  fHChargevsNLoGain->Reset();
+
+  fHChargeHiGain->SetName("HChargeHiGain");
+  fHChargeLoGain->SetName("HChargeLoGain");
+  fHTimeHiGain->SetName("HTimeHiGain");
+  fHTimeLoGain->SetName("HTimeLoGain");
+  fHChargevsNHiGain->SetName("HChargevsNHiGain");
+  fHChargevsNLoGain->SetName("HChargevsNLoGain");
+
+  fHiGains->Reset();
+  fLoGains->Reset();
+
+}
+
+
 
 Bool_t MHCalibrationPixel::IsEmpty() const
@@ -295,35 +342,4 @@
 
   return kTRUE;
-}
-
-
-void MHCalibrationPixel::Reset()
-{
-  
-  for (Int_t i = fHChargeHiGain->FindBin(fChargeFirstHiGain); 
-       i <= fHChargeHiGain->FindBin(fChargeLastHiGain); i++)
-    fHChargeHiGain->SetBinContent(i, 1.e-20);
-
-  for (Int_t i = 0; i < 16; i++)
-    fHTimeHiGain->SetBinContent(i, 1.e-20);
-
-  fChargeFirstHiGain    = -100.5;
-  fChargeLastHiGain     = 1999.5;
-
-  fHChargeHiGain->GetXaxis()->UnZoom();
-
- for (Int_t i = fHChargeLoGain->FindBin(fChargeFirstLoGain); 
-       i <= fHChargeLoGain->FindBin(fChargeLastLoGain); i++)
-    fHChargeLoGain->SetBinContent(i, 1.e-20);
-
-  for (Int_t i = 0; i < 16; i++)
-      fHTimeLoGain->SetBinContent(i, 1.e-20);
-  
-  fChargeFirstLoGain    = -100.5;
-  fChargeLastLoGain     = 9999.5;
-
-  fHChargeLoGain->GetXaxis()->UnZoom();
-
-  return;
 }
 
@@ -866,5 +882,4 @@
   fChargeLastHiGain  = fHChargeHiGain->GetBinLowEdge(fHChargeHiGain->GetXaxis()->GetLast())
                       +fHChargeHiGain->GetBinWidth(0);
-  fChargeNbinsHiGain = nbins;
 
   CutEdges(fHChargeLoGain,nbins);
@@ -873,5 +888,4 @@
   fChargeLastLoGain  = fHChargeLoGain->GetBinLowEdge(fHChargeLoGain->GetXaxis()->GetLast())
                       +fHChargeLoGain->GetBinWidth(0);
-  fChargeNbinsLoGain = nbins;
 
   CutEdges(fHChargevsNHiGain,0);
