Index: /trunk/MagicSoft/Mars/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/Makefile	(revision 2733)
+++ /trunk/MagicSoft/Mars/Makefile	(revision 2734)
@@ -42,4 +42,5 @@
           mhist \
           manalysis \
+	  mcalib \
           mfileio \
           mreflector \
Index: /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2733)
+++ /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2734)
@@ -10,6 +10,4 @@
 #pragma link C++ class MCerPhotAnal2+;
 #pragma link C++ class MCerPhotCalc+;
-
-#pragma link C++ class MCalibrate+;
 
 #pragma link C++ class MCameraData+;
@@ -69,10 +67,4 @@
 #pragma link C++ class MFiltercutsCalc+;
 
-#pragma link C++ class MCalibrationPix+;
-#pragma link C++ class MCalibrationBlindPix+;
-#pragma link C++ class MCalibrationPINDiode+;
-#pragma link C++ class MCalibrationCam+;
-#pragma link C++ class MCalibrationCalc+;
-
 #pragma link C++ class MPedestalWorkaround+;
 
Index: unk/MagicSoft/Mars/manalysis/MCalibrate.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrate.cc	(revision 2733)
+++ 	(revision )
@@ -1,171 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Javier Lopez 12/2003 <mailto:jlopez@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//
-//   MCalibrate
-//
-//   This task takes the integrated charge from MExtractedSignal and apply
-//   the calibration constants from MCalibraitionCam to the charge. Then
-//   stores number of photons obtained in MCerPhotEvt.
-//
-//   Input Containers:
-//    MExtractedSingal
-//    MCalibrationCam
-//
-//   Output Containers:
-//    MCerPhotEvt
-//
-//////////////////////////////////////////////////////////////////////////////
-#include "MCalibrate.h"
-#include "MCalibrationConfig.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "MParList.h"
-#include "MH.h"
-
-#include "MGeomCam.h"
-
-#include "MCalibrationCam.h"
-#include "MCalibrationPix.h"
-
-#include "MExtractedSignalCam.h"
-#include "MExtractedSignalPix.h"
-
-#include "MCerPhotEvt.h"
-
-#include "MTime.h"
-#include "TMath.h"
-
-ClassImp(MCalibrate);
-
-using namespace std;
-// --------------------------------------------------------------------------
-//
-// Default constructor. 
-//
-MCalibrate::MCalibrate(const char *name, const char *title)
-{
-    fName  = name  ? name  : "MCalibrate";
-    fTitle = title ? title : "Task to calculate the number of photons in one event";
-}
-
-// --------------------------------------------------------------------------
-//
-// The PreProcess searches for the following input containers:
-//  - MGeomCam
-//  - MCalibrationCam
-//  - MExtractedSignalCam
-//
-// The following output containers are also searched and created if
-// they were not found:
-//
-//  - MCerPhotEvt
-//
-Int_t MCalibrate::PreProcess(MParList *pList)
-{
-    fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
-    if (!fSignals)
-    {
-        *fLog << err << "MExtractedSignalCam not found ... aborting" << endl;
-        return kFALSE;
-    }
-
-    fCalibrations = (MCalibrationCam*)pList->FindObject("MCalibrationCam");
-    if (!fCalibrations)
-    {
-        *fLog << err << "MCalibrationCam not found ... aborting." << endl;
-        return kFALSE;
-    }
-
-    fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
-    if (!fCerPhotEvt)
-        return kFALSE;
-    
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-//
-Int_t MCalibrate::Process()
-{
-  /*
-    if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
-    {
-        // FIXME: MExtractedSignal must be of variable size -
-        //        like MCerPhotEvt - because we must be able
-        //        to reduce size by zero supression
-        //        For the moment this check could be done in ReInit...
-        *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
-        return kFALSE;
-    }
-  */
-
-    const UInt_t imaxnumpix = fSignals->GetSize();
-    
-    for (UInt_t pixidx=0; pixidx<imaxnumpix; pixidx++)
-    {
-	const MCalibrationPix &pix = (*fCalibrations)[pixidx];
-
-        if (!pix.IsBlindPixelMethodValid())
-            continue;
-
-        MExtractedSignalPix &sig =  (*fSignals)[pixidx];
-
-        Float_t signal;
-        Float_t signalErr = 0.;
-
-        if (sig.IsLoGainUsed())
-        {
-            signal    = sig.GetExtractedSignalLoGain()*pix.GetConversionHiLo();
-            signalErr = signal*pix.GetConversionHiLoError();
-        }
-        else
-        {
-            signal = sig.GetExtractedSignalHiGain();
-        }
-
-        //      Float_t calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
-        const Float_t calibrationConversionFactor      = pix.GetMeanConversionBlindPixelMethod();
-        const Float_t calibrationConversionFactorError = pix.GetErrorConversionBlindPixelMethod();
-
-        const Float_t nphot = signal*calibrationConversionFactor;
-        Float_t nphotErr    = signal*calibrationConversionFactorError
-                             *signal*calibrationConversionFactorError;
-        nphotErr += signalErr*calibrationConversionFactor
-                   *signalErr*calibrationConversionFactor;
-
-        nphotErr  = TMath::Sqrt(nphotErr);
-
-        fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
-    }
-
-    fCerPhotEvt->FixSize();
-    fCerPhotEvt->SetReadyToSave();
-
-    return kTRUE;
-}
Index: unk/MagicSoft/Mars/manalysis/MCalibrate.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrate.h	(revision 2733)
+++ 	(revision )
@@ -1,47 +1,0 @@
-#ifndef MARS_MCalibrate
-#define MARS_MCalibrate
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MCalibrate                                                              //
-//                                                                         //
-// Integrates the desired ADC time slices of one pixel and apply           //
-// calibration constants                                                   //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-#ifndef ROOT_TArrayF
-#include <TArrayF.h>
-#endif
-
-#ifndef MARS_MTask
-#include "MTask.h"
-#endif
-
-class MGeomCam;
-class MCalibrationCam;
-class MExtractedSignalCam;
-class MCerPhotEvt;
-
-class MCalibrate : public MTask
-{
-private:
-    MCalibrationCam     *fCalibrations; // Calibration constants 
-    MExtractedSignalCam *fSignals;      // Integrated charge in FADCs counts
-    MCerPhotEvt         *fCerPhotEvt; // Cerenkov Photon Event used for calculation
-
-    Float_t fConversionHiLo;
-    
-    Int_t PreProcess(MParList *pList);
-    Int_t Process();
-
-public:
-
-    MCalibrate(const char *name=NULL, const char *title=NULL);
-
-    void SetConversionHiLo(Float_t conv) { fConversionHiLo = conv; }
-    
-    ClassDef(MCalibrate, 0)   // Task to calculate cerenkov photons using calibration constants
-};
- 
-
-#endif
Index: unk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.cc	(revision 2733)
+++ 	(revision )
@@ -1,124 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MCalibrationBlindPix                                                    //
-//                                                                         //
-// This is the storage container to hold informations about the calibration//
-// blind pixel                                                             //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-#include "MCalibrationBlindPix.h"
-#include "MHCalibrationBlindPixel.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MCalibrationBlindPix);
-
-using namespace std;
-// --------------------------------------------------------------------------
-//
-// Default Constructor. 
-//
-MCalibrationBlindPix::MCalibrationBlindPix(const char *name, const char *title)
-    : 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.)
-{
-
-  fName  = name  ? name  : "MCalibrationBlindPix";
-  fTitle = title ? title : "Container of the MHCalibrationBlindPixel and the fit results";
-
-  fHist = new MHCalibrationBlindPixel();
-  
-  if (!fHist)
-    *fLog << err << dbginf << "Could not create MHCalibrationBlindPixel " << endl;
-
-  fLambda    = fMu0    = fMu1    = fSigma0    = fSigma1    = 0;
-  fErrLambda = fErrMu0 = fErrMu1 = fErrSigma0 = fErrSigma1 = 0;
-  
-  fTime = fErrTime = 0;
-}
-
-MCalibrationBlindPix::~MCalibrationBlindPix() 
-{
-  delete fHist;
-}
-
-// ------------------------------------------------------------------------
-//
-// Invalidate values
-//
-void MCalibrationBlindPix::Clear(Option_t *o)
-{
-  fHist->Reset();
-}
-
-Bool_t MCalibrationBlindPix::FitCharge() 
-{
-
-  if (!fHist->FitSinglePhe())
-    return kFALSE;
-  
-  fLambda = fHist->GetLambda();
-  fMu0    = fHist->GetMu0();
-  fMu1    = fHist->GetMu1();
-  fSigma0 = fHist->GetSigma0();
-  fSigma1 = fHist->GetSigma1();
-
-  fErrLambda = fHist->GetLambdaErr();
-  fErrMu0    = fHist->GetMu0Err();
-  fErrMu1    = fHist->GetMu1Err();
-  fErrSigma0 = fHist->GetSigma0Err();
-  fErrSigma1 = fHist->GetSigma1Err();
-
-  return kTRUE;
-}
-
-
-
-Bool_t MCalibrationBlindPix::FitTime() 
-{
-
-  if(!fHist->FitTime())
-    return kFALSE;
-
-  fTime    = fHist->GetMeanTime();
-  fErrTime = fHist->GetMeanTimeErr();
-  
-  return kTRUE;
-
-}
Index: unk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.h	(revision 2733)
+++ 	(revision )
@@ -1,69 +1,0 @@
-#ifndef MARS_MCalibrationBlindPix
-#define MARS_MCalibrationBlindPix
-
-#ifndef MARS_MParContainer
-#include "MParContainer.h"
-#endif
-
-#include "MHCalibrationBlindPixel.h"
-
-class MCalibrationBlindPix : public MParContainer
-{
-private:
-
-  Float_t fLambda;           // The mean charge after the fit
-  Float_t fMu0;              // The position of the pedestal-peak
-  Float_t fMu1;              // The position of the first phe-peak
-  Float_t fSigma0;           // The width of the pedestal-peak
-  Float_t fSigma1;           // The width of the first phe-peak  
-
-  Float_t fErrLambda;        // The error of the mean charge after the fit
-  Float_t fErrMu0;           // The error of the position of the pedestal-peak
-  Float_t fErrMu1;           // The error of the position of the first phe-peak
-  Float_t fErrSigma0;        // The error of the width of the pedestal-peak
-  Float_t fErrSigma1;        // The error of the width of the first phe-peak  
-  
-  Float_t fTime;                // The mean arrival time after the fit  
-  Float_t fErrTime;             // The error of the mean arrival time after the fit
-  
-  MHCalibrationBlindPixel *fHist; // Pointer to the histograms performing the fits, etc.  
-  
-public:
-
-  MCalibrationBlindPix(const char *name=NULL, const char *title=NULL);
-  ~MCalibrationBlindPix();
-  
-  void Clear(Option_t *o="");
-  
-  Float_t GetLambda()    const    { return fLambda;  }
-  Float_t GetMu0()       const    { return fMu0;  }
-  Float_t GetMu1()       const    { return fMu1;  }
-  Float_t GetSigma0()    const    { return fSigma0;  }
-  Float_t GetSigma1()    const    { return fSigma1;  }
-
-  Float_t GetErrLambda() const    { return fErrLambda;  }
-  Float_t GetErrMu0()    const    { return fErrMu0;  }
-  Float_t GetErrMu1()    const    { return fErrMu1;  }
-  Float_t GetErrSigma0() const    { return fErrSigma0;  }
-  Float_t GetErrSigma1() const    { return fErrSigma1;  }
-
-  Float_t GetTime()      const    { return fTime;         }
-  Float_t GetErrTime()   const    { return fErrTime;      }
-  
-  Bool_t FillCharge(Float_t q)    { return fHist->FillBlindPixelCharge(q); }
-  Bool_t FillTime(Int_t t)        { return fHist->FillBlindPixelTime(t); }  
-  Bool_t FillRChargevsTime(Float_t rq, Int_t t) { return fHist->FillBlindPixelChargevsN(rq,t); }    
-  
-  Bool_t IsFitOK()                              { return fHist->IsFitOK(); }
-  
-  Bool_t FitCharge();
-  Bool_t FitTime();
-  
-  virtual void Draw(Option_t *opt="")         { fHist->Draw(opt); }
-  MHCalibrationBlindPixel *GetHist()  const  { return fHist;  }
-  
-  ClassDef(MCalibrationBlindPix, 1)	// Storage Container for Calibration information of one pixel
-};
-
-#endif
-
Index: unk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc	(revision 2733)
+++ 	(revision )
@@ -1,453 +1,0 @@
- /* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug  09/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//   MCalibrationCalc                                                       //
-//                                                                          //
-//   This is a task which calculates the number of photons from the FADC    //
-//   time slices. At the moment it integrates simply the FADC values.       //
-//                                                                          //
-//  Input Containers:                                                       //
-//   MRawEvtData                                                            //
-//                                                                          //
-//  Output Containers:                                                      //
-//   MCalibrationCam                                                        //
-//                                                                          //
-//                                                                          //
-//  The class MCalibrationCam hold one entry of type MCalibrationPix for    //
-//  every pixel. It is filled in the following way:                         //
-//  PreParocess: MalibrationCam::InitSize(577) is called which allocates    //
-//               memory in an TClonesArray of type MCalibrationPix and      //
-//               all pointers to NULL.                                      //
-//                                                                          //
-//  Process:     The NULL pointer is tested on every pixel via              //
-//               MalibrationCam::IsPixelUsed(npix).                         //
-//                                                                          //
-//               In case, IsPixelUsed returns NULL,                         //
-//               MalibrationCam::AddPixel(npix) is invoked which creates a  //
-//               new MCalibrationPix(npix) in the npix's entry              //
-//               of the TClonesArray.                                       //
-//                                                                          //
-//               Every MCalibrationPix holds a histogram class,             //
-//               MHCalibrationPixel which itself hold histograms of type:   //
-//               HCharge(npix) (distribution of summed FADC time slice entries) 
-//               HTime(npix) (distribution of position of maximum)              
-//               HChargevsN(npix) (distribution of charges vs. event number.
-//                                                                          
-// PostProcess:  All histograms HCharge(npix) are fitted to a Gaussian      
-//               All histograms HTime(npix) are fitted to a Gaussian        
-//               The histogram HBlindPixelCharge (blind pixel) is fitted to a single     
-//                   PhE fit                                                
-//               The histogram HBlindPixelTime (blind pixel) is fitted to a Gaussian   
-//               The histograms of the PIN Diode are fitted to Gaussians    
-//                                                                          
-//               Fits can be excluded via the commands:                     
-//               MalibrationCam::SetSkipTimeFits()   (skip all time fits)   
-//               MalibrationCam::SetSkipBlindPixelFits()  (skip all blind pixel fits) 
-//               MalibrationCam::SetSkipPinDiodeFits()  (skip all PIN Diode fits) 
-//                                                                          
-//////////////////////////////////////////////////////////////////////////////
-
-#include "MCalibrationCalc.h"
-#include "MCalibrationConfig.h"
-#include "MCalibrationFits.h"
-
-#include "MCalibrationCam.h"
-#include "MCalibrationPix.h"
-#include "MCalibrationBlindPix.h"
-#include "MCalibrationPINDiode.h"
-
-#include "MPedestalCam.h"
-#include "MPedestalPix.h"
-
-#include "MGeomCam.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "MParList.h"
-#include "MH.h"
-
-#include "MRawRunHeader.h"
-#include "MRawEvtData.h"       // MRawEvtData::GetNumPixels
-#include "MRawEvtPixelIter.h"
-
-#include "MExtractedSignalCam.h"
-#include "MExtractedSignalPix.h"
-
-#include "MTime.h"
-#include "TMath.h"
-
-ClassImp(MCalibrationCalc);
-
-using namespace std;
-// --------------------------------------------------------------------------
-//
-// Default constructor. b is the number of slices before the maximum slice,
-// a the number of slices behind the maximum slice which is taken as signal.
-//
-MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
-    : fColor(kEBlue)
-{
-
-    fName  = name  ? name  : "MCalibrationCalc";
-    fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
-
-    AddToBranchList("MRawEvtData.fHiGainPixId");
-    AddToBranchList("MRawEvtData.fLoGainPixId");
-    AddToBranchList("MRawEvtData.fHiGainFadcSamples");
-    AddToBranchList("MRawEvtData.fLoGainFadcSamples");
-
-    SETBIT(fFlags, kUseTimeFits);
-    SETBIT(fFlags, kUseBlindPixelFit);
-    SETBIT(fFlags, kUsePinDiodeFit);
-
-}
-
-// --------------------------------------------------------------------------
-//
-// The PreProcess searches for the following input containers:
-//  - MRawEvtData
-//  - MPedestalCam
-//
-// The following output containers are also searched and created if
-// they were not found:
-//
-//  - MHCalibrationBlindPixel
-//  - MCalibrationCam
-//  - MTime
-//
-Int_t MCalibrationCalc::PreProcess(MParList *pList)
-{
-
-    fHistOverFlow = 0;
-    fEvents       = 0;
-    fCosmics      = 0;
-
-    fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
-    if (!fRawEvt)
-    {
-        *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
-    if (!runheader)
-        *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
-    else
-        if (runheader->GetRunType() == kRTMonteCarlo)
-        {
-            return kTRUE;
-        }
-
-    fCalibrations = (MCalibrationCam*)pList->FindCreateObj("MCalibrationCam");
-    if (!fCalibrations)
-      {
-        *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;        
-        return kFALSE;
-      }
-
-
-    switch (fColor)
-      {
-      case kEBlue:
-        fCalibrations->SetColor(MCalibrationCam::kECBlue);
-	break;        
-      case kEGreen:
-        fCalibrations->SetColor(MCalibrationCam::kECGreen);      
-	break;
-      case kEUV:
-        fCalibrations->SetColor(MCalibrationCam::kECUV);            
-	break;
-      case kECT1:
-        fCalibrations->SetColor(MCalibrationCam::kECCT1);            
-	break;
-      default:
-        fCalibrations->SetColor(MCalibrationCam::kECCT1); 
-      }
-
-    fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
-    if (!fPedestals)
-      {
-        *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
-        return kFALSE;
-      }
-
-
-    fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
-    if (!fSignals)
-      {
-        *fLog << err << dbginf << "Cannot find MExtractedSignalCam ... aborting" << endl;
-        return kFALSE;
-      }
-    
-    return kTRUE;
-}
-
-
-// --------------------------------------------------------------------------
-//
-// The ReInit searches for the following input containers:
-//  - MRawRunHeader
-//
-Bool_t MCalibrationCalc::ReInit(MParList *pList )
-{
- 
-    fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
-    if (!fRunHeader)
-    {
-        *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
-        return kFALSE;
-    }
-
-
-    MGeomCam *cam = (MGeomCam*)pList->FindObject("MGeomCam");
-    if (!cam)
-    {
-        *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
-        return kFALSE;
-    }
-
-
-    fNumHiGainSamples =  fSignals->GetNumUsedHiGainFADCSlices();
-    fNumLoGainSamples =  fSignals->GetNumUsedLoGainFADCSlices();
-
-    fCalibrations->InitSize(cam->GetNumPixels());    
-
-    for (UInt_t i=0;i<cam->GetNumPixels();i++)
-      {
-        MCalibrationPix &pix = (*fCalibrations)[i];
-        pix.DefinePixId(i);
-      }
-    
-    return kTRUE;
- 
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Calculate the integral of the FADC time slices and store them as a new
-// pixel in the MCerPhotEvt container.
-//
-Int_t MCalibrationCalc::Process()
-{
-
-    Int_t cosmicpix = 0;
-
-    MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
-    MCalibrationPINDiode &pindiode   = *(fCalibrations->GetPINDiode());
-
-    MRawEvtPixelIter pixel(fRawEvt);
-
-    //
-    // Create a first loop to sort out the cosmics ...
-    // 
-    // This is a very primitive check for the number of cosmicpixs
-    // The cut will be applied in the fit, but for the blind pixel,
-    // we need to remove this event
-    //
-    // FIXME: In the future need a much more sophisticated one!!!
-    //
-
-    while (pixel.Next())
-      {
-	
-	const UInt_t pixid = pixel.GetPixelId();
-	
-	MExtractedSignalPix &sig =  (*fSignals)[pixid];
-        MPedestalPix        &ped =  (*fPedestals)[pixid];
-        Float_t pedrms     = ped.GetPedestalRms();
-	Float_t sumhi      = sig.GetExtractedSignalHiGain();
-        
-	if (sumhi < 15.*pedrms )   // cut at 3.5 sigma
-	  cosmicpix++;
-     }
-
-    if (cosmicpix > 100.)
-      {
-	fCosmics++;
-	return kCONTINUE;
-      }
-
-    pixel.Reset();
-    fEvents++;
-
-    //
-    // Create a second loop to do fill the calibration histograms
-    // 
-
-    while (pixel.Next())
-      {
-
-	const UInt_t pixid = pixel.GetPixelId();
-	
-	MExtractedSignalPix &sig =  (*fSignals)[pixid];
-        
-	Float_t sumhi  = sig.GetExtractedSignalHiGain();
-	Float_t sumlo  = sig.GetExtractedSignalLoGain();
-	Float_t mtime  = sig.GetMeanArrivalTime();
-
-	MCalibrationPix &pix = (*fCalibrations)[pixid];
-
-        switch(pixid)
-          {
-            
-          case gkCalibrationBlindPixelId:
-
-	    if (!blindpixel.FillCharge(sumhi)) 
-	      *fLog << err << 
-		"Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
-
-	    if (!blindpixel.FillTime((int)mtime)) 
-	      *fLog << err << 
-		"Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
-	    
-	    if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
-	      *fLog << warn << 
-		"Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
-            
-          case gkCalibrationPINDiodeId:
-            if (!pindiode.FillCharge(sumhi)) 
-              *fLog << warn << 
-                "Overflow or Underflow occurred filling HCharge: means = " << sumhi << endl;
-            if (!pindiode.FillTime((int)mtime)) 
-              *fLog << warn << 
-                "Overflow or Underflow occurred filling HTime: time = " << mtime << endl;
-            if (!pindiode.FillRChargevsTime(sumhi,fEvents))
-              *fLog << warn << 
-                "Overflow or Underflow occurred filling HChargevsN: eventnr = " << fEvents << endl;
-	    break;
-
-          default:
-
-	    pix.SetChargesInGraph(sumhi,sumlo);
-
-	    if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
-	      *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: " 
-		    << pixid << " signal = " << sumlo  << " event Nr: " << fEvents << endl;
-		
-	    if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
-	      *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: " 
-		    << pixid << " signal = " << sumhi  << " event Nr: " << fEvents << endl;
-
-	    if (sig.IsLoGainUsed())
-	      {
-		
-		if (!pix.FillChargeLoGain(sumlo))
-		  *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid 
-			<< " signal = " << sumlo << endl;
-
-		if (!pix.FillTimeLoGain((int)mtime)) 
-		  *fLog << warn << "Could not fill Lo Gain Time of pixel: " 
-			<< pixid << " time = " << mtime << endl;
-		
-	      }
-	    else
-	      {
-		if (!pix.FillChargeHiGain(sumhi))
-		  *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid 
-			<< " signal = " << sumhi << endl;
-		
-		if (!pix.FillTimeHiGain((int)mtime)) 
-		  *fLog << warn << "Could not fill Hi Gain Time of pixel: " 
-			<< pixid << " time = " << mtime << endl;
-		
-	      }
-	    break;
-	    
-          } /* switch(pixid) */
-
-      } /* while (pixel.Next()) */
-
-    return kTRUE;
-}
-
-Int_t MCalibrationCalc::PostProcess()
-{
-
-
-  *fLog << inf << endl;
-  *fLog << GetDescriptor() << " Cut Histogram Edges" << endl;
-
-  //
-  // Cut edges to make fits and viewing of the hists easier  
-  //
-  fCalibrations->CutEdges();
-
-  //
-  // Get pointer to blind pixel
-  //
-  MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
-
-  *fLog << GetDescriptor() << " Fitting the Blind Pixel" << endl;
-
-  // 
-  // Fit the blind pixel
-  //
-  if (TESTBIT(fFlags,kUseBlindPixelFit))
-    {
-
-      if (!blindpixel.FitCharge())
-        *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
-
-      blindpixel.Draw();
-    }
-  
-  *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
-
-  //
-  // loop over the pedestal events and check if we have calibration
-  //
-  for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
-    {
-
-      MCalibrationPix &pix = (*fCalibrations)[pixid];
-
-      const Float_t ped    = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
-      const Float_t prms   = (*fPedestals)[pixid].GetPedestalRms() * TMath::Sqrt((float)fNumHiGainSamples);
-
-      pix.SetPedestal(ped,prms);
-
-      pix.FitCharge();
-
-      if (TESTBIT(fFlags,kUseTimeFits))
-        pix.FitTime();
-      
-    }
-
-  if (!fCalibrations->CalcNumPhotInsidePlexiglass())
-    *fLog << err << dbginf << "Could not calculate the number of photons from the blind pixel " << endl;
-
-  fCalibrations->SetReadyToSave();
-  
-  if (GetNumExecutions()==0)
-    return kTRUE;
-  
-  *fLog << endl;
-  *fLog << dec << setfill(' ') << fCosmics << " Events presumably cosmics" << endl;
-
-  return kTRUE;
-}
Index: unk/MagicSoft/Mars/manalysis/MCalibrationCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.h	(revision 2733)
+++ 	(revision )
@@ -1,83 +1,0 @@
-#ifndef MARS_MCalibrationCalc
-#define MARS_MCalibrationCalc
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MCalibrationCalc                                                   //
-//                                                                         //
-// Integrates the time slices of the all pixels of a calibration event     //
-// and substract the pedestal value                                        //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef MARS_MTask
-#include "MTask.h"
-#endif
-
-class MRawEvtData;
-class MRawRunHeader;
-
-class MPedestalCam;
-class MCalibrationCam;
-class MExtractedSignalCam;
-
-class MTime;
-
-class MCalibrationCalc : public MTask
-{
-private:
-
-  MPedestalCam             *fPedestals;    // Pedestals of all pixels in the camera
-  MCalibrationCam          *fCalibrations; // Calibration events of all pixels in the camera
-  MExtractedSignalCam      *fSignals;      // Calibration events of all pixels in the camera
-
-  MRawEvtData              *fRawEvt;       // raw event data (time slices)
-  MRawRunHeader            *fRunHeader;    // RunHeader information
-
-  MTime                    *fEvtTime;      // Time of the event
-
-  Int_t fEvents;                           // Number of events  
-  Int_t fHistOverFlow;                     // Number of events with saturated Low Gain
-  Int_t fCosmics;                          // Number of events due to supposed cosmics
-
-  Byte_t fNumHiGainSamples; 
-  Byte_t fNumLoGainSamples; 
-
-  Byte_t fFlags;                           // Flag for the fits used
-   
-  Float_t fConversionHiLo;
-  
-  enum  { kUseTimeFits, kUseBlindPixelFit, kUsePinDiodeFit };
-
-public:
-  
-  enum PulserColor_t  { kEGreen, kEBlue, kEUV, kECT1 };
-
-private:
-
-  PulserColor_t  fColor;
-  
-  Bool_t ReInit(MParList *pList); 
-  Int_t PreProcess(MParList *pList);
-  Int_t Process();
-  Int_t PostProcess();
-  
-public:
-
-  MCalibrationCalc(const char *name=NULL, const char *title=NULL);
-
-  void SetSkipTimeFits(Bool_t b=kTRUE)
-      {b ? CLRBIT(fFlags, kUseTimeFits) : SETBIT(fFlags, kUseTimeFits);}
-  void SetSkipBlindPixelFit(Bool_t b=kTRUE)
-      {b ? CLRBIT(fFlags, kUseBlindPixelFit) : SETBIT(fFlags, kUseBlindPixelFit);}
-  void SetSkipPinDiodeFit(Bool_t b=kTRUE)
-      {b ? CLRBIT(fFlags, kUsePinDiodeFit) : SETBIT(fFlags, kUsePinDiodeFit);}
-
-  void SetPulserColor(PulserColor_t color)    { fColor = color; }
-
-  void SetConversionHiLo(Float_t conv)         { fConversionHiLo = conv; }
-  
-  ClassDef(MCalibrationCalc, 1)   // Task to fill the Calibration Containers from raw data
-};
-
-#endif
Index: unk/MagicSoft/Mars/manalysis/MCalibrationCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2733)
+++ 	(revision )
@@ -1,625 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-
-! *
-!
-!
-!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                               
-// MCalibrationCam                                               
-//                                                               
-// Hold the whole Calibration results of the camera:
-//                                                               
-// 1) MCalibrationCam initializes a TClonesArray whose elements are 
-//    pointers to MCalibrationPix Containers
-// 2) It initializes a pointer to an MCalibrationBlindPix container
-// 3) It initializes a pointer to an MCalibrationPINDiode container
-//
-// 4)  
-// 
-/////////////////////////////////////////////////////////////////////////////
-#include "MCalibrationCam.h"
-#include "MCalibrationPix.h"
-#include "MHCalibrationPixel.h"
-#include "MCalibrationBlindPix.h"
-#include "MCalibrationConfig.h"
-
-#include <TClonesArray.h>
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "TCanvas.h"
-
-#include "MGeomCam.h"
-
-ClassImp(MCalibrationCam);
-
-using namespace std;
-// --------------------------------------------------------------------------
-//
-// Default constructor. 
-//
-// Creates a TClonesArray of MCalibrationPix containers, initialized to 1 entry
-// Later, a call to MCalibrationCam::InitSize(Int_t size) has to be performed
-//
-// Creates an MCalibrationBlindPix container 
-// Creates an MCalibrationPINDiode container
-//
-MCalibrationCam::MCalibrationCam(const char *name, const char *title)
-    : fNumPhotInsidePlexiglassAvailable(kFALSE),
-      fMeanPhotInsidePlexiglass(-1.),
-      fMeanPhotErrInsidePlexiglass(-1.),
-      fNumPhotOutsidePlexiglassAvailable(kFALSE),
-      fMeanPhotOutsidePlexiglass(-1.),
-      fMeanPhotErrOutsidePlexiglass(-1.),
-      fOffsets(NULL),
-      fSlopes(NULL),
-      fOffvsSlope(NULL)
-{
-    fName  = name  ? name  : "MCalibrationCam";
-    fTitle = title ? title : "Storage container for the Calibration Information in the camera";
-
-    fPixels     = new TClonesArray("MCalibrationPix",1);
-    fBlindPixel = new MCalibrationBlindPix();
-    fPINDiode   = new MCalibrationPINDiode();
-}
-
-// --------------------------------------------------------------------------
-//
-// Delete the TClonesArray of MCalibrationPix containers
-// Delete the MCalibrationPINDiode and the MCalibrationBlindPix
-//
-// Delete the histograms if they exist
-//
-MCalibrationCam::~MCalibrationCam()
-{
-
-  //
-  // delete fPixels should delete all Objects stored inside
-  // 
-  delete fPixels;
-  delete fBlindPixel;
-  delete fPINDiode;
-
-  if (fOffsets)
-    delete fOffsets;
-  if (fSlopes)
-    delete fSlopes;
-  if (fOffvsSlope)
-    delete fOffvsSlope;
-
-}
-
-// -------------------------------------------------------------------
-//
-// This function simply allocates memory via the ROOT command:
-// (TObject**) TStorage::ReAlloc(fCont, newSize * sizeof(TObject*),
-//                                      fSize * sizeof(TObject*));
-// newSize corresponds to size in our case
-// fSize is the old size (in most cases: 1)
-//
-void MCalibrationCam::InitSize(Int_t size)
-{
-  
-  //
-  // check if we have already initialized to size
-  //
-  if (CheckBounds(size))
-    return;
-  
-  fPixels->ExpandCreate(size);
-
-}
-
-// --------------------------------------------------------------------------
-//
-// This function returns the current size of the TClonesArray 
-// independently if the MCalibrationPix is filled with values or not.
-//
-// It is the size of the array fPixels.
-//
-Int_t MCalibrationCam::GetSize() const
-{
-  return fPixels->GetEntriesFast();
-}
-
-// --------------------------------------------------------------------------
-//
-// Check if position i is inside the current bounds of the TClonesArray
-//
-Bool_t MCalibrationCam::CheckBounds(Int_t i) const 
-{
-    return i < fPixels->GetEntriesFast();
-} 
-
-
-// --------------------------------------------------------------------------
-//
-// Get i-th pixel (pixel number)
-//
-MCalibrationPix &MCalibrationCam::operator[](Int_t i)
-{
-
-  if (!CheckBounds(i))
-    return *static_cast<MCalibrationPix*>(NULL);
-
-  return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th pixel (pixel number)
-//
-MCalibrationPix &MCalibrationCam::operator[](Int_t i) const
-{
-
-  if (!CheckBounds(i))
-    return *static_cast<MCalibrationPix*>(NULL);
-
-  return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Return true if pixel is inside bounds of the TClonesArray fPixels
-//
-Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const 
-{
-  if (!CheckBounds(idx))
-    return kFALSE;
-
-  return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Return true if pixel has already been fitted once (independent of the result)
-//
-Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const 
-{
-
-  if (!CheckBounds(idx))
-    return kFALSE;
-
-  return (*this)[idx].IsFitted();
-}
-
-
-// --------------------------------------
-//
-void MCalibrationCam::Clear(Option_t *o)
-{
-    fPixels->ForEach(TObject, Clear)();
-}
-
-// --------------------------------------------------------------------------
-//
-// Sets the user ranges of all histograms such that 
-// empty bins at the edges are not used. Additionally, it rebins the 
-// histograms such that in total, 50 bins are used.
-//
-void MCalibrationCam::CutEdges()
-{
-
-  fBlindPixel->GetHist()->CutAllEdges();
-  fPINDiode->GetHist()->CutAllEdges();
-
-  TIter Next(fPixels);
-  MCalibrationPix *pix;
-  while ((pix=(MCalibrationPix*)Next()))
-    {
-      pix->GetHist()->CutAllEdges();
-    }
-
-  return;
-}
-  
-// --------------------------------------------------------------------------
-//
-// Print first the well fitted pixels 
-// and then the ones which are not FitValid
-//
-void MCalibrationCam::Print(Option_t *o) const
-{
-
-  *fLog << all << GetDescriptor() << ":" << endl;
-  int id = 0;
-  
-  *fLog << "Succesfully calibrated pixels:" << endl;
-  *fLog << endl;
-
-  TIter Next(fPixels);
-  MCalibrationPix *pix;
-  while ((pix=(MCalibrationPix*)Next()))
-    {
-      
-      if (pix->IsFitValid()) 
-	{
-	  *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
-		<< " Reduced Charge: " << pix->GetCharge() << " +- " 
-		<< pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
-	  id++;
-	}
-    }
-  
-  *fLog << id << " succesful pixels :-))" << endl;
-  id = 0;
-  
-  *fLog << endl;
-  *fLog << "Pixels with errors:" << endl;
-  *fLog << endl;
-  
-  TIter Next2(fPixels);
-    while ((pix=(MCalibrationPix*)Next2()))
-      {
-        
-        if (!pix->IsFitValid())
-          {
-            *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
-                  << " Reduced Charge: " << pix->GetCharge() << " +- " 
-		<< pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
-            id++;
-          }
-      }
-    *fLog << id << " pixels with errors :-((" << endl;
-    
-}
-
-// The types are as follows:
-// 
-// 0: Fitted Charge
-// 1: Error of fitted Charge
-// 2: Sigma of fitted Charge
-// 3: Error of Sigma of fitted Charge
-// 4: Returned probability of Gauss fit to Charge distribution
-// 5: Mean arrival time
-// 6: Sigma of the arrival time
-// 7: Chi-square of the Gauss fit to the arrival times
-// 8: Pedestal
-// 9: Pedestal RMS
-// 10: Reduced Sigma Square
-// 11: Number of Photo-electrons after the F-Factor method
-// 12: Error on the Number of Photo-electrons after the F-Factor method
-// 13: Mean conversion factor after the F-Factor method
-// 14: Error on the conversion factor after the F-Factor method
-// 15: Number of Photons after the Blind Pixel method
-// 16: Mean conversion factor after the Blind Pixel method
-//
-Bool_t MCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
-{
-
-  if (idx > GetSize())
-    return kFALSE;
-
-  switch (type)
-    {
-    case 0:
-      val = (*this)[idx].GetCharge();
-      break;
-    case 1:
-      val = (*this)[idx].GetErrCharge();
-      break;
-    case 2:
-      val = (*this)[idx].GetSigmaCharge();
-      break;
-    case 3:
-      val = (*this)[idx].GetErrSigmaCharge();
-      break;
-    case 4:
-      val = (*this)[idx].GetChargeProb();
-      break;
-    case 5:
-      val = (*this)[idx].GetTime();
-      break;
-    case 6:
-      val = (*this)[idx].GetSigmaTime();
-      break;
-    case 7:
-      val = (*this)[idx].GetTimeChiSquare();
-      break;
-    case 8:
-      val = (*this)[idx].GetPed();
-      break;
-    case 9:
-      val = (*this)[idx].GetPedRms();
-      break;
-    case 10:
-      if ((*this)[idx].GetRSigmaSquare() > 0.)
-	val = TMath::Sqrt((*this)[idx].GetRSigmaSquare());
-      else
-	val = -1.;
-      break;
-    case 11:
-      val = (*this)[idx].GetPheFFactorMethod();
-      break;
-    case 12:
-      val = (*this)[idx].GetPheFFactorMethodError();
-      break;
-    case 13:
-      val = (*this)[idx].GetMeanConversionFFactorMethod();
-      break;
-    case 14:
-      val = (*this)[idx].GetErrorConversionFFactorMethod();
-      break;
-    case 15:
-      if (idx < 397)
-	val = (double)fMeanPhotInsidePlexiglass;
-      else
-	val = (double)fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
-      break;
-    case 16:
-      if (idx < 397)
-        val = (*this)[idx].GetMeanConversionBlindPixelMethod();
-      else 
-        val = (*this)[idx].GetMeanConversionBlindPixelMethod()*gkCalibrationOutervsInnerPixelArea;
-      break;
-    case 17:
-      if ((*this)[idx].GetCharge() != 0.)
-        val = ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge())*
-              ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge());
-      else
-        val = -1.;
-      break;
-    default:
-      return kFALSE;
-    }
-  return val>=0;
-}
-
-// --------------------------------------------------------------------------
-//
-// What MHCamera needs in order to draw an individual pixel in the camera
-//
-void MCalibrationCam::DrawPixelContent(Int_t idx) const
-{
-  (*this)[idx].Draw();
-}
-
-
-// --------------------------------------------------------------------------
-//
-
-//
-Bool_t MCalibrationCam::CalcNumPhotInsidePlexiglass()
-{
-
-  if (!fBlindPixel->IsFitOK())
-    return kFALSE;
-  
-  const Float_t mean = fBlindPixel->GetLambda();
-  const Float_t merr = fBlindPixel->GetErrLambda();
-  
-  switch (fColor)
-    {
-    case kECGreen:
-      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEGreen)     // real photons
-                            *TMath::Power(10,gkCalibrationBlindPixelAttGreen) // correct for absorption 
-                            * gkCalibrationInnerPixelArea;                    // correct for area
-      break;
-    case kECBlue:
-      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEBlue )
-                            *TMath::Power(10,gkCalibrationBlindPixelAttBlue)
-                            * gkCalibrationInnerPixelArea;
-      break;
-    case kECUV:
-      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEUV )
-                            *TMath::Power(10,gkCalibrationBlindPixelAttUV)
-                            * gkCalibrationInnerPixelArea;
-      break;
-    case kECCT1:
-    default:
-      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQECT1 )
-                            *TMath::Power(10,gkCalibrationBlindPixelAttCT1)
-                            * gkCalibrationInnerPixelArea;
-      break;
-    }
-
-  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.))
-        {
-
-          Float_t conversion      = fMeanPhotInsidePlexiglass/pix->GetCharge();
-          Float_t conversionerr   = 0.;
-          Float_t conversionsigma = 0.;
-          pix->SetConversionBlindPixelMethod(conversion, conversionerr, conversionsigma);
-
-          if (conversionerr/conversion < 0.1) 
-            pix->SetBlindPixelMethodValid();
-        }
-    }
-  return kTRUE;
-}
-
-
-Bool_t MCalibrationCam::CalcNumPhotOutsidePlexiglass()
-{
-
-  if (!fPINDiode->IsFitOK())
-    return kFALSE;
-  
-  const Float_t mean = fPINDiode->GetMean();
-  const Float_t merr = fPINDiode->GetMeanError();
-  
-  switch (fColor)
-    {
-    case kECGreen:
-      fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEGreen)   // real photons
-                            * gkCalibrationInnerPixelvsPINDiodeArea;        // correct for area
-      break;
-    case kECBlue:
-      fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEBlue )
-                            * gkCalibrationInnerPixelvsPINDiodeArea;
-      break;
-    case kECUV:
-      fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEUV )
-                            * gkCalibrationInnerPixelvsPINDiodeArea;
-      break;
-    case kECCT1:
-    default:
-      fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQECT1 )
-                            * gkCalibrationInnerPixelvsPINDiodeArea;
-      break;
-    }
-
-  fNumPhotOutsidePlexiglassAvailable = kTRUE;
-
-  TIter Next(fPixels);
-  MCalibrationPix *pix;
-  while ((pix=(MCalibrationPix*)Next()))
-    {
-      
-      if((pix->GetCharge() > 0.) && (fMeanPhotInsidePlexiglass > 0.))
-	pix->SetConversionPINDiodeMethod(fMeanPhotOutsidePlexiglass/pix->GetCharge(), 0., 0.);
-    }
-  return kTRUE;
-}
-
-
-
-Bool_t MCalibrationCam::GetConversionFactorBlindPixel(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
-{
-  
-  if (ipx < 0 || !IsPixelFitted(ipx))
-    return kFALSE;
-
-  if (!fNumPhotInsidePlexiglassAvailable)
-    if (!CalcNumPhotInsidePlexiglass())
-      return kFALSE;
-
-  mean  = (*this)[ipx].GetMeanConversionBlindPixelMethod();
-  err   = (*this)[ipx].GetErrorConversionBlindPixelMethod();
-  sigma = (*this)[ipx].GetSigmaConversionBlindPixelMethod();
-
-  return kTRUE;
-}
-
-
-Bool_t MCalibrationCam::GetConversionFactorFFactor(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
-{
-  
-  if (ipx < 0 || !IsPixelFitted(ipx))
-    return kFALSE;
-
-  Float_t conv = (*this)[ipx].GetMeanConversionFFactorMethod();
-
-  if (conv < 0.)
-    return kFALSE;
-
-  mean  = conv;
-  err   = (*this)[ipx].GetErrorConversionFFactorMethod();
-  sigma = (*this)[ipx].GetSigmaConversionFFactorMethod();
-
-  return kTRUE;
-}
-
-
-//-----------------------------------------------------------------------------------
-//
-// Calculates the conversion factor between the integral of FADCs slices 
-// (as defined in the signal extractor MExtractSignal.cc)
-// and the number of photons reaching the plexiglass for one Inner Pixel 
-//
-// FIXME: The PINDiode is still not working and so is the code 
-//
-Bool_t MCalibrationCam::GetConversionFactorPINDiode(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
-{
-
-  if (ipx < 0 || !IsPixelFitted(ipx))
-    return kFALSE;
-
-  return kFALSE;
-
-}
-
-//-----------------------------------------------------------------------------------
-//
-// Calculates the best combination of the three used methods possible 
-// between the integral of FADCs slices 
-// (as defined in the signal extractor MExtractSignal.cc)
-// and the number of photons reaching one Inner Pixel. 
-// The procedure is not yet defined.
-//
-// FIXME: The PINDiode is still not working and so is the code 
-//
-Bool_t MCalibrationCam::GetConversionFactorCombined(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
-{
-
-  if (ipx < 0 || !IsPixelFitted(ipx))
-    return kFALSE;
-
-  return kFALSE;
-
-}
-
-
-void MCalibrationCam::DrawHiLoFits()
-{
-
-  if (!fOffsets)
-    fOffsets = new TH1D("pp","Offsets of the HiGain LoGain Fit",100,-600.,400.);
-  if (!fSlopes)
-    fSlopes  = new TH1D("mm","Slopes of the HiGain LoGain Fit",100,-2.,2.);
-  if (!fOffvsSlope)
-    fOffvsSlope = new TH2D("aa","Slopes vs Offsets of the HiGain LoGain Fit",100,-600.,400.,100,-2.,2.);
-
-  TIter Next(fPixels);
-  MCalibrationPix *pix;
-  MHCalibrationPixel *hist;
-  while ((pix=(MCalibrationPix*)Next()))
-    {
-      hist = pix->GetHist();
-      hist->FitHiGainvsLoGain();
-      fOffsets->Fill(hist->GetOffset(),1.);
-      fSlopes->Fill(hist->GetSlope(),1.);
-      fOffvsSlope->Fill(hist->GetOffset(),hist->GetSlope(),1.);
-    }
-
-   TCanvas *c1 = new TCanvas();
-
-   c1->Divide(1,3);
-   c1->cd(1);
-   fOffsets->Draw();
-   gPad->Modified();
-   gPad->Update();
-
-   c1->cd(2);
-  fSlopes->Draw();
-  gPad->Modified();
-  gPad->Update();
-
-  c1->cd(3);
-  fOffvsSlope->Draw("col1");
-  gPad->Modified();
-  gPad->Update();
-}
-
Index: unk/MagicSoft/Mars/manalysis/MCalibrationCam.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationCam.h	(revision 2733)
+++ 	(revision )
@@ -1,135 +1,0 @@
-#ifndef MARS_MCalibrationCam
-#define MARS_MCalibrationCam
-
-#ifndef MARS_MCamEvent
-#include "MCamEvent.h"
-#endif
-
-#ifndef MARS_MCalibrationPix
-#include "MCalibrationPix.h"
-#endif
-
-#ifndef MARS_MCalibrationBlindPix
-#include "MCalibrationBlindPix.h"
-#endif
-
-#ifndef MARS_MCalibrationPINDiode
-#include "MCalibrationPINDiode.h"
-#endif
-
-#ifndef ROOT_TClonesArray
-#include <TClonesArray.h>
-#endif
-
-#ifndef ROOT_TH1F
-#include <TH1F.h>
-#endif
-
-#ifndef ROOT_TH1D
-#include <TH1D.h>
-#endif
-
-#ifndef ROOT_TH2D
-#include <TH2D.h>
-#endif
-
-class MGeomCam;
-class MCalibrationPix;
-class MCalibrationBlindPix;
-class MCalibrationPINDiode;
-
-class MCalibrationCam : public MCamEvent
-{
-private:
-  
-  Int_t fNumPixels;
-  TClonesArray *fPixels;                      // Array of MCalibrationPix with fit results
-  
-  MCalibrationBlindPix *fBlindPixel;          // Pointer to the Blind Pixel with fit results
-  MCalibrationPINDiode *fPINDiode;            // Pointer to the PIN Diode with fit results    
-
-  Bool_t  fNumPhotInsidePlexiglassAvailable;  // TRUE: Blind Pixel could have been fitted well 
-  Float_t fMeanPhotInsidePlexiglass;          //  The mean number of photons in an INNER PIXEL inside the plexiglass
-  Float_t fMeanPhotErrInsidePlexiglass;       //  The uncertainty about the number of photons in an INNER PIXEL  
-
-  Bool_t  fNumPhotOutsidePlexiglassAvailable; // TRUE: PIN Diode could have been fitted well 
-  Float_t fMeanPhotOutsidePlexiglass;         //  The mean number of photons in an INNER PIXEL outside the plexiglass
-  Float_t fMeanPhotErrOutsidePlexiglass;      //  The uncertainty about the number of photons in an INNER PIXEL  
-
-  TH1F* fHChargeAllPixels;                     //! 
-  TH1F* fHChargeErrAllPixels;                  //! 
-  TH1F* fHChargeSigmaAllPixels;                //! 
-  TH1F* fHChargeProbAllPixels;                 //! 
-
-  TH1F* fHTimeAllPixels;                       //! 
-  TH1F* fHTimeSigmaAllPixels;                  //! 
-  TH1F* fHTimeProbAllPixels;                   //! 
-
-  TH1F* fHPedAllPixels;                        //! 
-  TH1F* fHPedRMSAllPixels;                     //! 
-  TH1F* fHSigmaPerChargeAllPixels;             //! 
-  TH1F* fHPhEAllPixels;                        //! 
-
-  TH1F* fHConvPhEperFADCAllPixels;             //! 
-  TH1F* fHConvPhperFADCAllPixels;              //! 
-
-  TH1D* fOffsets;                              //! 
-  TH1D* fSlopes;                               //! 
-  
-  TH2D* fOffvsSlope;                           //! 
-
-public:
-  
-  enum CalibrationColor_t { kECGreen, kECBlue, kECUV, kECCT1 };
-
-private:
-
-  CalibrationColor_t fColor;  
-  
-public:
-
-  MCalibrationCam(const char *name=NULL, const char *title=NULL);
-  ~MCalibrationCam();
-  
-  void Clear(Option_t *o="");
-  
-  void InitSize(const Int_t i);
-  Int_t GetSize() const;
-
-  UInt_t GetNumPixels() const { return fNumPixels; }
-
-  Bool_t IsPixelUsed(Int_t idx)      const;
-  Bool_t IsPixelFitted(Int_t idx)    const;
-  
-  MCalibrationPix &operator[](Int_t i);
-  MCalibrationPix &operator[](Int_t i) const;
-  
-  Bool_t CheckBounds(Int_t i) const;
-
-  void Print(Option_t *o="") const;
-  
-  void CutEdges();
-  
-  Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
-  void   DrawPixelContent(Int_t num) const;    
-  
-  MCalibrationBlindPix *GetBlindPixel()              const { return fBlindPixel;  }
-  MCalibrationPINDiode *GetPINDiode()                const { return fPINDiode;    }
-
-  void SetColor(CalibrationColor_t color)    { fColor = color; }
-
-  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);
-
-  Bool_t CalcNumPhotInsidePlexiglass();
-  Bool_t CalcNumPhotOutsidePlexiglass();
-
-  void DrawHiLoFits();
-
-  ClassDef(MCalibrationCam, 1)	// Storage Container for all calibration information of the camera
-};
-
-#endif
-
Index: unk/MagicSoft/Mars/manalysis/MCalibrationConfig.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationConfig.h	(revision 2733)
+++ 	(revision )
@@ -1,96 +1,0 @@
-#ifndef MARS_MCalibrationConfig
-#define MARS_MCalibrationConfig
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         
-// MCalibrationConfig                                                      
-//
-// Contains all configuration data of the Calibration          
-//                                                             
-// This file is only TEMPORARY. It values will go into the DATABASE 
-//
-/////////////////////////////////////////////////////////////////////////////
-
-
-// The highest value of the High Gain in the linear regime
-const Byte_t gkSaturationLimit = 250;
-
-// The conversion factor between High Gain and Low Gain
-const Float_t gkConversionHiLo      = 10.;
-const Float_t gkConversionHiLoError = 2.5;
-
-// The penalty constant to produce overflow in the histogram 
-const ULong_t gkLoGainOverFlow = 99999999;
-
-// ----- BLIND PIXEL ----------------------//
-
-// Pixel ID of the Calibration Blind Pixel
-const UShort_t gkCalibrationBlindPixelId = 559;
-
-// Average QE of Blind Pixel (three colours)
-const Float_t gkCalibrationBlindPixelQEGreen = 0.154;
-const Float_t gkCalibrationBlindPixelQEBlue  = 0.226;
-const Float_t gkCalibrationBlindPixelQEUV    = 0.247;
-const Float_t gkCalibrationBlindPixelQECT1   = 0.247;
-
-// Attenuation factor Blind Pixel (three colours)
-const Float_t gkCalibrationBlindPixelAttGreen = 1.97;
-const Float_t gkCalibrationBlindPixelAttBlue  = 1.96;
-const Float_t gkCalibrationBlindPixelAttUV    = 1.95;
-const Float_t gkCalibrationBlindPixelAttCT1   = 1.95;
-
-//
-// Area of Inner Pixel w.r.t. Blind Pixel (which is 1 sq. cm)
-//
-// Hexagone of diagonal axis b = 3.5 cm
-//             straight axis a = 3.0 cm +- 2% 
-// Area =  sqrt(3)*a*a/2 = 7.79 sq.cm +- 4% = 7.8 +- 0.3 sq.cm
-//
-const Float_t gkCalibrationInnerPixelArea      = 7.8;
-const Float_t gkCalibrationInnerPixelAreaError = 0.3;
-//
-// Area of Outer Pixel w.r.t. Inner Pixel
-//
-// Hexagone of diagonal axis b = 7.0 cm
-//             straight axis a = 6.0 cm +- 1% 
-// Area = sqrt(3)*a*a/2 = 
-//
-const Float_t gkCalibrationOutervsInnerPixelArea      = 4.00;
-const Float_t gkCalibrationOutervsInnerPixelAreaError = 0.00;
-
-// ----- PIN DIODE ------------------------//
-
-// Pixel ID of the Calibration PIN Diode
-const UShort_t gkCalibrationPINDiodeId = 9999;
-
-//
-// Area of Inner Pixel w.r.t. PIN Diode (which is 1 cm²)
-//
-// Hexagone of diagonal axis b = 3.5 cm
-//             straight axis a = 3.0 cm +- 2% 
-// Area =  sqrt(3)*a*a/2 = 7.79 sq.cm +- 4% = 7.8 +- 0.3 sq.cm
-//
-// Distance of PIN Diode to pulser D1:   1.5  +- 0.3 m
-// Distance of Inner Pixel to pulser D2: 18.0 +- 0.5 m
-//
-//
-//                A(Inner Pixel)    D1*D1
-// conversion C = -------------- * ------ = 0.054
-//                A(PIN Diode)      D2*D2
-//
-// Delta C / C  = sqrt((Delta A(IP)/A(IP))² + 4 * ( (Delta D1/D1)² + (Delta D2/D2)² )
-// Delta C / C  = 0.4
-// 
-// C = 0.05 +- 0.02
-//
-const Float_t gkCalibrationInnerPixelvsPINDiodeArea      = 0.05;
-const Float_t gkCalibrationInnerPixelvsPINDiodeAreaError = 0.02;
-
-// Average QE of the PIN Diode
-const Float_t gkCalibrationPINDiodeQEGreen = -1.0;
-const Float_t gkCalibrationPINDiodeQEBlue  = -1.0;
-const Float_t gkCalibrationPINDiodeQEUV    = -1.0;
-const Float_t gkCalibrationPINDiodeQECT1   = -1.0;
-
-
-#endif /* MARS_MCalibrationConfig */
Index: unk/MagicSoft/Mars/manalysis/MCalibrationFits.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationFits.h	(revision 2733)
+++ 	(revision )
@@ -1,310 +1,0 @@
-#ifndef MARS_MCalibrationFits
-#define MARS_MCalibrationFits
-
-#ifndef ROOT_TMath
-#include <TMath.h>
-#endif
-
-#define GIMMEABREAK     10000000000.0
-
-inline Double_t gfKto5(Double_t *x, Double_t *par)
-{
-
-  Double_t lambda = par[0];  
-  
-  Double_t sum = 0.;
-  Double_t arg = 0.;
-
-  Double_t mu0 = par[1];
-  Double_t mu1 = par[2];
-
-  if (mu1 < mu0)
-    return GIMMEABREAK;
-
-  Double_t sigma0 = par[3];
-  Double_t sigma1 = par[4];
-
-  if (sigma1 < sigma0)
-    return GIMMEABREAK;
-
-
-  Double_t mu2 = (2.*mu1)-mu0;  
-  Double_t mu3 = (3.*mu1)-(2.*mu0);
-  Double_t mu4 = (4.*mu1)-(3.*mu0);
-  Double_t mu5 = (5.*mu1)-(4.*mu0);
-
-  Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));  
-  Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
-  Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
-  Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
-
-  Double_t lambda2 = lambda*lambda;
-  Double_t lambda3 = lambda2*lambda;
-  Double_t lambda4 = lambda3*lambda;
-  Double_t lambda5 = lambda4*lambda;
-
-  // k=0:
-  arg = (x[0] - mu0)/sigma0;
-  sum = TMath::Exp(-0.5*arg*arg)/sigma0;
-  
-  // k=1:
-  arg = (x[0] - mu1)/sigma1;
-  sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
-  
-  // k=2:
-  arg = (x[0] - mu2)/sigma2;
-  sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
-
-  // k=3:
-  arg = (x[0] - mu3)/sigma3;
-  sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
-
-  // k=4:
-  arg = (x[0] - mu4)/sigma4;
-  sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
-  
-  // k=5:
-  arg = (x[0] - mu5)/sigma5;
-  sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
-
-  return par[5]*sum;
-
-};
-
-inline Double_t gfKto6(Double_t *x, Double_t *par)
-{
-
-  Double_t lambda = par[0];  
-  
-  Double_t sum = 0.;
-  Double_t arg = 0.;
-
-  Double_t mu0 = par[1];
-  Double_t mu1 = par[2];
-
-  if (mu1 < mu0)
-    return GIMMEABREAK;
-
-  Double_t sigma0 = par[3];
-  Double_t sigma1 = par[4];
-
-  if (sigma1 < sigma0)
-    return GIMMEABREAK;
-
-
-  Double_t mu2 = (2.*mu1)-mu0;  
-  Double_t mu3 = (3.*mu1)-(2.*mu0);
-  Double_t mu4 = (4.*mu1)-(3.*mu0);
-  Double_t mu5 = (5.*mu1)-(4.*mu0);
-  Double_t mu6 = (6.*mu1)-(5.*mu0);
-
-  Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));  
-  Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
-  Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
-  Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
-  Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
-
-  Double_t lambda2 = lambda*lambda;
-  Double_t lambda3 = lambda2*lambda;
-  Double_t lambda4 = lambda3*lambda;
-  Double_t lambda5 = lambda4*lambda;
-  Double_t lambda6 = lambda5*lambda;
-  
-  // k=0:
-  arg = (x[0] - mu0)/sigma0;
-  sum = TMath::Exp(-0.5*arg*arg)/sigma0;
-  
-  // k=1:
-  arg = (x[0] - mu1)/sigma1;
-  sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
-  
-  // k=2:
-  arg = (x[0] - mu2)/sigma2;
-  sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
-
-  // k=3:
-  arg = (x[0] - mu3)/sigma3;
-  sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
-
-  // k=4:
-  arg = (x[0] - mu4)/sigma4;
-  sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
-  
-  // k=5:
-  arg = (x[0] - mu5)/sigma5;
-  sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
-
-  // k=6:
-  arg = (x[0] - mu6)/sigma6;
-  sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
-  
-  return par[5]*sum;
-
-};
-
-inline Double_t gfKto7(Double_t *x, Double_t *par)
-{
-
-  Double_t lambda = par[0];  
-  
-  Double_t sum = 0.;
-  Double_t arg = 0.;
-
-  Double_t mu0 = par[1];
-  Double_t mu1 = par[2];
-
-  if (mu1 < mu0)
-    return GIMMEABREAK;
-
-  Double_t sigma0 = par[3];
-  Double_t sigma1 = par[4];
-
-  if (sigma1 < sigma0)
-    return GIMMEABREAK;
-
-
-  Double_t mu2 = (2.*mu1)-mu0;  
-  Double_t mu3 = (3.*mu1)-(2.*mu0);
-  Double_t mu4 = (4.*mu1)-(3.*mu0);
-  Double_t mu5 = (5.*mu1)-(4.*mu0);
-  Double_t mu6 = (6.*mu1)-(5.*mu0);
-  Double_t mu7 = (7.*mu1)-(6.*mu0);
-  
-  Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));  
-  Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
-  Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
-  Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
-  Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
-  Double_t sigma7 = TMath::Sqrt((7.*sigma1*sigma1) - (6.*sigma0*sigma0));
-
-  Double_t lambda2 = lambda*lambda;
-  Double_t lambda3 = lambda2*lambda;
-  Double_t lambda4 = lambda3*lambda;
-  Double_t lambda5 = lambda4*lambda;
-  Double_t lambda6 = lambda5*lambda;
-  Double_t lambda7 = lambda6*lambda;
-  
-  // k=0:
-  arg = (x[0] - mu0)/sigma0;
-  sum = TMath::Exp(-0.5*arg*arg)/sigma0;
-  
-  // k=1:
-  arg = (x[0] - mu1)/sigma1;
-  sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
-  
-  // k=2:
-  arg = (x[0] - mu2)/sigma2;
-  sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
-
-  // k=3:
-  arg = (x[0] - mu3)/sigma3;
-  sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
-
-  // k=4:
-  arg = (x[0] - mu4)/sigma4;
-  sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
-  
-  // k=5:
-  arg = (x[0] - mu5)/sigma5;
-  sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
-
-  // k=6:
-  arg = (x[0] - mu6)/sigma6;
-  sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
-  
-  // k=7:
-  arg = (x[0] - mu7)/sigma7;
-  sum += 0.000198412698413*lambda7*TMath::Exp(-0.5*arg*arg)/sigma7;
-  
-  return par[5]*sum;
-
-};
-
-
-inline Double_t gfKto8(Double_t *x, Double_t *par)
-{
-
-  Double_t lambda = par[0];  
-  
-  Double_t sum = 0.;
-  Double_t arg = 0.;
-
-  Double_t mu0 = par[1];
-  Double_t mu1 = par[2];
-
-  if (mu1 < mu0)
-    return GIMMEABREAK;
-
-  Double_t sigma0 = par[3];
-  Double_t sigma1 = par[4];
-
-  if (sigma1 < sigma0)
-    return GIMMEABREAK;
-
-
-  Double_t mu2 = (2.*mu1)-mu0;  
-  Double_t mu3 = (3.*mu1)-(2.*mu0);
-  Double_t mu4 = (4.*mu1)-(3.*mu0);
-  Double_t mu5 = (5.*mu1)-(4.*mu0);
-  Double_t mu6 = (6.*mu1)-(5.*mu0);
-  Double_t mu7 = (7.*mu1)-(6.*mu0);
-  Double_t mu8 = (8.*mu1)-(7.*mu0);    
-  
-  Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));  
-  Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
-  Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
-  Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
-  Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
-  Double_t sigma7 = TMath::Sqrt((7.*sigma1*sigma1) - (6.*sigma0*sigma0));
-  Double_t sigma8 = TMath::Sqrt((8.*sigma1*sigma1) - (7.*sigma0*sigma0));          
-
-  Double_t lambda2 = lambda*lambda;
-  Double_t lambda3 = lambda2*lambda;
-  Double_t lambda4 = lambda3*lambda;
-  Double_t lambda5 = lambda4*lambda;
-  Double_t lambda6 = lambda5*lambda;
-  Double_t lambda7 = lambda6*lambda;
-  Double_t lambda8 = lambda7*lambda;
-  
-  // k=0:
-  arg = (x[0] - mu0)/sigma0;
-  sum = TMath::Exp(-0.5*arg*arg)/sigma0;
-  
-  // k=1:
-  arg = (x[0] - mu1)/sigma1;
-  sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
-  
-  // k=2:
-  arg = (x[0] - mu2)/sigma2;
-  sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
-
-  // k=3:
-  arg = (x[0] - mu3)/sigma3;
-  sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
-
-  // k=4:
-  arg = (x[0] - mu4)/sigma4;
-  sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
-  
-  // k=5:
-  arg = (x[0] - mu5)/sigma5;
-  sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
-
-  // k=6:
-  arg = (x[0] - mu6)/sigma6;
-  sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
-  
-  // k=7:
-  arg = (x[0] - mu7)/sigma7;
-  sum += 0.000198412698413*lambda7*TMath::Exp(-0.5*arg*arg)/sigma7;
-  
-  // k=8:
-  arg = (x[0] - mu8)/sigma8;
-  sum += 0.000024801587315*lambda8*TMath::Exp(-0.5*arg*arg)/sigma7;
-  
-  return par[5]*sum;
-
-};
-
-#endif  /* MARS_MCalibrationFits */
-
Index: unk/MagicSoft/Mars/manalysis/MCalibrationPINDiode.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationPINDiode.cc	(revision 2733)
+++ 	(revision )
@@ -1,102 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MCalibrationPINDiode                                                            //
-//                                                                         //
-// This is the storage container to hold informations about the pedestal   //
-// (offset) value of one Pixel (PMT).                                      //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-#include "MCalibrationPINDiode.h"
-
-#include "MLog.h"
-
-ClassImp(MCalibrationPINDiode);
-
-using namespace std;
-// --------------------------------------------------------------------------
-//
-// Default Constructor. 
-//
-MCalibrationPINDiode::MCalibrationPINDiode(const char *name, const char *title)
-  : fHist(NULL),
-    fCharge(-1.),
-    fErrCharge(-1.),
-    fPed(-1.),
-    fPedRms(-1.),
-    fSigmaCharge(-1.),
-    fErrSigmaCharge(-1.),
-    fTime(-1.),
-    fErrTime(-1.)
-{
-
-  fName  = name  ? name  : "MCalibrationPINDiode";
-  fTitle = title ? title : "Container of the MHCalibrationPINDiode and the fit results";
-
-  fHist = new MHCalibrationPINDiode();
-
-}
-
-MCalibrationPINDiode::~MCalibrationPINDiode() 
-{
-  delete fHist;
-}
-
-// ------------------------------------------------------------------------
-//
-// Invalidate values
-//
-void MCalibrationPINDiode::Clear(Option_t *o)
-{
-  fHist->Reset();
-}
-
-Bool_t MCalibrationPINDiode::FitCharge() 
-{
-  if(!fHist->FitChargeHiGain())
-    return kFALSE;
-
-  fCharge         = fHist->GetChargeMean();
-  fErrCharge      = fHist->GetChargeMeanErr(); 
-  fSigmaCharge    = fHist->GetChargeSigma();
-  fErrSigmaCharge = fHist->GetChargeSigmaErr();
-
-  return kTRUE;
-  
-}
-
-Bool_t MCalibrationPINDiode::FitTime() 
-{
-
-  if(!fHist->FitTimeHiGain())
-    return kFALSE;
-
-  fTime    = fHist->GetTime();
-  fErrTime = fHist->GetErrTime();
-  
-  return kTRUE;
-
-}
Index: unk/MagicSoft/Mars/manalysis/MCalibrationPINDiode.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationPINDiode.h	(revision 2733)
+++ 	(revision )
@@ -1,53 +1,0 @@
-#ifndef MARS_MCalibrationPINDiode
-#define MARS_MCalibrationPINDiode
-
-#ifndef MARS_MParContainer
-#include "MParContainer.h"
-#endif
-
-#include "MHCalibrationPINDiode.h"
-
-class MCalibrationPINDiode : public MParContainer
-{
-private:
-
-  MHCalibrationPINDiode *fHist; // Pointer to the histograms performing the fits, etc.  
-  
-  Float_t fCharge;                // The mean charge after the fit
-  Float_t fErrCharge;             // The error of mean charge after the fit
-  Float_t fPed;              // The mean pedestal (from MPedestalPix)
-  Float_t fPedRms;           // The pedestal  RMS (from MPedestalPix)
-  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 fTime;                // The mean arrival time after the fit  
-  Float_t fErrTime;             // The error of the mean arrival time after the fit
-  
-public:
-
-  MCalibrationPINDiode(const char *name=NULL, const char *title=NULL);
-  ~MCalibrationPINDiode();
-  
-  void Clear(Option_t *o="");
-  
-  void SetPed(Float_t ped)          { fPed      = ped;      } 
-  void SetPedRms(Float_t pedrms)    { fPedRms   = pedrms; }
-
-  Float_t GetMean()           const { return fCharge; }
-  Float_t GetMeanError()      const { return fErrCharge; }
-
-  Bool_t IsFitOK() const            { return fCharge > 0 && fErrCharge > 0; }
-
-  Bool_t FillCharge(Float_t q)      { return fHist->FillChargeHiGain(q); }
-  Bool_t FillTime(Int_t t)          { return fHist->FillTimeHiGain(t); }  
-  Bool_t FillRChargevsTime(Float_t rq, Int_t t) { return fHist->FillChargevsNHiGain(rq,t); }    
-  
-  Bool_t FitCharge();
-  Bool_t FitTime();
-  
-  MHCalibrationPINDiode *GetHist()  const  { return fHist;  }
-  
-  ClassDef(MCalibrationPINDiode, 1)	// Storage Container for Calibration information of one pixel
-};
-
-#endif   /* MARS_MCalibrationPINDiode */
-
Index: unk/MagicSoft/Mars/manalysis/MCalibrationPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc	(revision 2733)
+++ 	(revision )
@@ -1,436 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MCalibrationPix                                                         //
-//                                                                         //
-// This is the storage container to hold informations about the pedestal   //
-// (offset) value of one Pixel (PMT).                                      //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-#include "MCalibrationPix.h"
-#include "MCalibrationConfig.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MCalibrationPix);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor. 
-//
-MCalibrationPix::MCalibrationPix(const char *name, const char *title)
-    : fPixId(-1),
-      fCharge(-1.),
-      fErrCharge(-1.),
-      fSigmaCharge(-1.),
-      fErrSigmaCharge(-1.),
-      fRSigmaSquare(-1.),
-      fChargeProb(-1.),
-      fPed(-1.),
-      fPedRms(-1.),
-      fErrPedRms(0.),
-      fElectronicPedRms(1.5),
-      fErrElectronicPedRms(0.3),
-      fTime(-1.),
-      fSigmaTime(-1.),
-      fTimeChiSquare(-1.),
-      fFactor(1.3),
-      fPheFFactorMethod(-1.),
-      fConversionFFactorMethod(-1.),
-      fConversionBlindPixelMethod(-1.),
-      fConversionPINDiodeMethod(-1.),
-      fConversionErrorFFactorMethod(-1.),
-      fConversionErrorBlindPixelMethod(-1.),
-      fConversionErrorPINDiodeMethod(-1.),
-      fConversionSigmaFFactorMethod(-1.),
-      fConversionSigmaBlindPixelMethod(-1.),
-      fConversionSigmaPINDiodeMethod(-1.),
-      fHiGainSaturation(kFALSE),
-      fFitValid(kFALSE),        
-      fFitted(kFALSE), 
-      fBlindPixelMethodValid(kFALSE),
-      fFFactorMethodValid(kFALSE),
-      fPINDiodeMethodValid(kFALSE)
-{
-
-  fName  = name  ? name  : "MCalibrationPixel";
-  fTitle = title ? title : "Container of the MHCalibrationPixels and the fit results";
-
-  //
-  // At the moment, we don't have a database, yet, 
-  // so we get it from the configuration file
-  //
-  fConversionHiLo      = gkConversionHiLo;
-  fConversionHiLoError = gkConversionHiLoError;  
-
-  fHist = new MHCalibrationPixel("MHCalibrationPixel","Calibration Histograms Pixel ");
-
-}
-
-MCalibrationPix::~MCalibrationPix() 
-{
-  delete fHist;
-}
-
-
-void MCalibrationPix::DefinePixId(Int_t i)
-{
-  
-  fPixId = i;
-  fHist->ChangeHistId(i);
-  
-}
-
-
-// ------------------------------------------------------------------------
-//
-// Invalidate values
-//
-void MCalibrationPix::Clear(Option_t *o)
-{
-  fHist->Reset();
-}
-
-
-// --------------------------------------------------------------------------
-//
-// 1) Return if the charge distribution is already succesfully fitted  
-// 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid 
-//    possible remaining cosmics to spoil the fit.
-// 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
-// 4) Fit the histograms with a Gaussian
-// 5) In case of failure print out the fit results
-// 6) Retrieve the results and store them in this class
-// 7) Calculate the number of photo-electrons after the F-Factor method
-// 8) Calculate the errors of the F-Factor method
-//
-// The fit is declared valid (fFitValid = kTRUE), if:
-//
-// 1) Pixel has a fitted charge greater than 3*PedRMS
-// 2) Pixel has a fit error greater than 0.
-// 3) Pixel has a fit Probability greater than 0.0001 
-// 4) Pixel has a charge sigma bigger than its Pedestal RMS
-// 5) If FitTimes is used, 
-//    the mean arrival time is at least 1.0 slices from the used edge slices 
-// 
-// The conversion factor after the F-Factor method is declared valid, if:
-//
-// 1) fFitValid is kTRUE
-// 2) Conversion Factor is bigger than 0.
-// 3) The error of the conversion factor is smaller than 10%
-//
-Bool_t MCalibrationPix::FitCharge() 
-{
-
-  //
-  // 1) Return if the charge distribution is already succesfully fitted  
-  //
-  if (fHist->IsFitOK())
-    return kTRUE;
-
-  //
-  // 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid 
-  //    possible remaining cosmics to spoil the fit.
-  //
-  if (fPed && fPedRms)
-    fHist->SetLowerFitRange(1.5*fPedRms);
-  else
-    *fLog << warn << "Cannot set lower fit range: Pedestals not available" << endl;
-
-  //
-  // 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
-  //
-  if (fHist->UseLoGain())
-    {
-
-      SetHiGainSaturation();
-      
-      //
-      // 4) Fit the Lo Gain histograms with a Gaussian
-      //
-      if(!fHist->FitChargeLoGain())
-	{
-	  *fLog << warn << "Could not fit Lo Gain charges of pixel " << fPixId << endl;
-          //          
-          // 5) In case of failure print out the fit results
-          //
-	  fHist->PrintChargeFitResult();
-	}
-    }
-  else 
-    {
-      //
-      // 4) Fit the Hi Gain histograms with a Gaussian
-      //
-      if(!fHist->FitChargeHiGain())
-	{
-	  *fLog << warn << "Could not fit Hi Gain charges of pixel " << fPixId << endl;
-          //          
-          // 5) In case of failure print out the fit results
-          //
-	  fHist->PrintChargeFitResult();
-	}
-    }
-  
-
-  //
-  // 6) Retrieve the results and store them in this class
-  //
-  fCharge         = fHist->GetChargeMean();
-  fErrCharge      = fHist->GetChargeMeanErr(); 
-  fSigmaCharge    = fHist->GetChargeSigma();
-  fErrSigmaCharge = fHist->GetChargeSigmaErr();
-  fChargeProb     = fHist->GetChargeProb();
-
-  if (fCharge <= 0.)
-    {
-      *fLog << warn << "Cannot apply calibration: Mean Fitted Charges are smaller than 0 in pixel " 
-            << fPixId << endl;
-      return kFALSE;
-    }
-
-  if (fErrCharge > 0.) 
-    fFitted = kTRUE;
-
-
-  if (fHiGainSaturation)
-    {
-      if ( (fCharge     > 0.3*GetPedRms()) &&
-          (fErrCharge  > 0.)              &&
-          (fHist->IsFitOK())              &&
-          (fSigmaCharge > fPedRms/fConversionHiLo)   &&
-          (fTime > fHist->GetTimeLowerFitRange()+1.) &&
-          (fTime < fHist->GetTimeUpperFitRange()-1.) )
-        fFitValid =  kTRUE;
-    }
-  else
-    {
-      if ( (fCharge > 3.*GetPedRms()) &&
-           (fErrCharge  > 0.)        &&
-           (fHist->IsFitOK())        &&
-           (fSigmaCharge > fPedRms)  &&
-           (fTime > fHist->GetTimeLowerFitRange()+1.) &&
-           (fTime < fHist->GetTimeUpperFitRange()-1.) )
-        fFitValid =  kTRUE;
-    }
-  
-  //
-  // 7) Calculate the number of photo-electrons after the F-Factor method
-  // 8) Calculate the errors of the F-Factor method
-  //
-  if ((fPed > 0.)  && (fPedRms > 0.))
-    {
-      
-      //
-      // Square all variables in order to avoid applications of square root
-      //
-      // First the relative error squares
-      //
-      const Float_t chargeSquare              =       fCharge*   fCharge;
-      const Float_t chargeSquareRelErrSquare  = 4.*fErrCharge*fErrCharge / chargeSquare;
-
-      const Float_t fFactorRelErrSquare       = fFactorError * fFactorError / (fFactor * fFactor);
-      //
-      // Now the absolute error squares
-      //
-      const Float_t sigmaSquare               =       fSigmaCharge*   fSigmaCharge;
-      const Float_t sigmaSquareErrSquare      = 4.*fErrSigmaCharge*fErrSigmaCharge * sigmaSquare;
-
-      const Float_t elecRmsSquare             =       fElectronicPedRms*   fElectronicPedRms;
-      const Float_t elecRmsSquareErrSquare    = 4.*fErrElectronicPedRms*fErrElectronicPedRms * elecRmsSquare;
-
-      Float_t pedRmsSquare                    =       fPedRms*   fPedRms;
-      Float_t pedRmsSquareErrSquare           = 4.*fErrPedRms*fErrPedRms * pedRmsSquare;
-
-      if (fHiGainSaturation)
-	{
-          
-          //
-          // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it 
-          // from the Hi Gain: 
-          //
-          // We extract the pure NSB contribution:
-          //
-          Float_t nsbSquare             =  pedRmsSquare          - elecRmsSquare;
-          Float_t nsbSquareRelErrSquare = (pedRmsSquareErrSquare + elecRmsSquareErrSquare)
-                                          / (nsbSquare * nsbSquare) ;
-
-	  if (nsbSquare < 0.)
-            nsbSquare = 0.;
-          
-          //
-          // Now, we divide the NSB by the conversion factor and 
-          // add it quadratically to the electronic noise
-          //
-          const Float_t conversionSquare             =    fConversionHiLo     *fConversionHiLo;
-          const Float_t conversionSquareRelErrSquare = 4.*fConversionHiLoError*fConversionHiLoError/conversionSquare;
-
-          //
-          // Calculate the new "Pedestal RMS"
-          //
-          const Float_t convertedNsbSquare          =  nsbSquare             / conversionSquare;
-          const Float_t convertedNsbSquareErrSquare = (nsbSquareRelErrSquare + conversionSquareRelErrSquare)
-                                                      * convertedNsbSquare * convertedNsbSquare;
-
-          pedRmsSquare           = convertedNsbSquare           + elecRmsSquare;
-          pedRmsSquareErrSquare  = convertedNsbSquareErrSquare  + elecRmsSquareErrSquare;
-          
-	}    /* if (fHiGainSaturation) */
-      
-      //
-      // Calculate the reduced sigmas
-      //
-      fRSigmaSquare = sigmaSquare - pedRmsSquare;
-      if (fRSigmaSquare <= 0.)
-        {
-          *fLog << warn << "Cannot apply F-Factor calibration: Reduced Sigma smaller than 0 in pixel " 
-                << fPixId << endl;
-          if (fHiGainSaturation)
-            ApplyLoGainConversion();
-          return kFALSE;
-        }
-
-      const Float_t rSigmaSquareRelErrSquare = (sigmaSquareErrSquare + pedRmsSquareErrSquare)
-        / (fRSigmaSquare * fRSigmaSquare) ;
-  
-      //
-      // Calculate the number of phe's from the F-Factor method
-      // (independent on Hi Gain or Lo Gain)
-      //
-      fPheFFactorMethod = fFactor * chargeSquare / fRSigmaSquare;
-
-      const Float_t pheFFactorRelErrSquare =  fFactorRelErrSquare
-                                            + chargeSquareRelErrSquare
-                                            + rSigmaSquareRelErrSquare ;
-          
-      fPheFFactorMethodError        =  TMath::Sqrt(pheFFactorRelErrSquare) * fPheFFactorMethod;
-
-      //
-      // Calculate the conversion factors 
-      //
-      if (fHiGainSaturation)
-        ApplyLoGainConversion();
-      
-      const Float_t chargeRelErrSquare = fErrCharge*fErrCharge / (fCharge * fCharge);
-      
-      fConversionFFactorMethod        =  fPheFFactorMethod / fCharge ;
-      fConversionErrorFFactorMethod   =  ( pheFFactorRelErrSquare + chargeRelErrSquare )
-                                         * fConversionFFactorMethod * fConversionFFactorMethod;
-      
-      if ( IsFitValid()                     &&
-           (fConversionFFactorMethod > 0.) &&
-           (fConversionErrorFFactorMethod/fConversionFFactorMethod < 0.1) )
-        fFFactorMethodValid = kTRUE;
-      
-      
-    } /*   if ((fPed > 0.)  && (fPedRms > 0.)) */
-
-  return kTRUE;
-  
-}
-
-
-void MCalibrationPix::ApplyLoGainConversion()
-{
-  
-  const Float_t chargeRelErrSquare     =   fErrCharge*fErrCharge
-                                         /(   fCharge *  fCharge);
-  const Float_t sigmaRelErrSquare      =   fErrSigmaCharge*fErrSigmaCharge
-                                         /(   fSigmaCharge *  fSigmaCharge);
-  const Float_t conversionRelErrSquare =   fConversionHiLoError*fConversionHiLoError 
-                                         /(fConversionHiLo    * fConversionHiLo);
-  
-  fCharge         *= fConversionHiLo;
-  fErrCharge       = TMath::Sqrt(chargeRelErrSquare + conversionRelErrSquare) * fCharge;
-  
-  fSigmaCharge    *= fConversionHiLo;
-  fErrSigmaCharge =  TMath::Sqrt(sigmaRelErrSquare + conversionRelErrSquare) * fSigmaCharge;
-  
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Set the pedestals from outside
-//
-void MCalibrationPix::SetPedestal(Float_t ped, Float_t pedrms)
-{
-
-  fPed    = ped;    
-  fPedRms = pedrms;
-  
-}
-
-// --------------------------------------------------------------------------
-//
-// 1) Fit the arrival times
-// 2) Retrieve the results
-// 3) Note that because of the low number of bins, the NDf is sometimes 0, so 
-//    Root does not give a reasonable Probability, the Chisquare is more significant
-//
-// This fit has to be done AFTER the Charges fit, 
-// otherwise only the Hi Gain will be fitted, even if there are no entries
-//
-// 
-Bool_t MCalibrationPix::FitTime() 
-{
-
-  //
-  // Fit the Low Gain
-  //
-  if (fHiGainSaturation)
-    {
-      if(!fHist->FitTimeLoGain())
-	{
-	  *fLog << warn << "Could not fit Lo Gain times of pixel " << fPixId << endl;
-	  fHist->PrintTimeFitResult();
-	  return kFALSE;
-	}
-    }
-
-  //
-  // Fit the High Gain
-  //
-  else
-    {
-      if(!fHist->FitTimeHiGain())
-	{
-	  *fLog << warn << "Could not fit Hi Gain times of pixel " << fPixId << endl;
-	  fHist->PrintTimeFitResult();
-	  return kFALSE;
-	}
-    }
-    
-  fTime          = fHist->GetTimeMean();
-  fSigmaTime     = fHist->GetTimeSigma();
-  fTimeChiSquare = fHist->GetTimeChiSquare();
-
-  return kTRUE;
-}
-
Index: unk/MagicSoft/Mars/manalysis/MCalibrationPix.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h	(revision 2733)
+++ 	(revision )
@@ -1,172 +1,0 @@
-#ifndef MARS_MCalibrationPix
-#define MARS_MCalibrationPix
-
-#ifndef MARS_MParContainer
-#include "MParContainer.h"
-#endif
-
-#include "MHCalibrationPixel.h"
-
-class MCalibrationPix : public MParContainer
-{
-private:
-
-  Int_t   fPixId;                        // the pixel Id
-  
-  Float_t fCharge;                       // The mean reduced charge after the fit
-  Float_t fErrCharge;                    // The error of reduced mean charge after the fit
-  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 fRSigmaSquare;                 // The reduced squares of sigmas after the fit
-  Float_t fChargeProb;                   // The probability of the fit function 
-
-  Float_t fPed;                          // The mean pedestal (from MPedestalPix)
-  Float_t fPedRms;                       // The pedestal  RMS (from MPedestalPix)
-  Float_t fErrPedRms;                    // The error of the pedestal  RMS (from MPedestalPix)  
-  Float_t fElectronicPedRms;             // The pure electronic component of the RMS
-  Float_t fErrElectronicPedRms;          // The error of the pure electronic component of the RMS
-
-  Float_t fTime;                         // The mean arrival time after the fit  
-  Float_t fSigmaTime;                    // The error of the mean arrival time after the fit
-  Float_t fTimeChiSquare;                // The probability of the fit function 
-  
-  Float_t fFactor;                       // The laboratory F-factor
-  Float_t fFactorError;                  // The laboratory F-factor Error
-  Float_t fPheFFactorMethod;             // The number of Phe's calculated (F-factor method)
-  Float_t fPheFFactorMethodError;        // The error on the number of Phe's calculated (F-factor method)
-
-  Float_t fConversionFFactorMethod;      // The conversion factor to Phe's (F-factor method)
-  Float_t fConversionBlindPixelMethod;   // The conversion factor to Ph's (Blind Pixel method)
-  Float_t fConversionPINDiodeMethod;     // The conversion factor to Ph's (PIN Diode method)
-
-  Float_t fConversionErrorFFactorMethod;    // The error of the conversion factor to Phe's (F-factor method)
-  Float_t fConversionErrorBlindPixelMethod; // The error of the conversion factor to Ph's (Blind Pixel method)
-  Float_t fConversionErrorPINDiodeMethod;   // The error of the conversion factor to Ph's (PIN Diode method)
-
-  Float_t fConversionSigmaFFactorMethod;    // The sigma of conversion factor to Ph's (F-factor method)
-  Float_t fConversionSigmaBlindPixelMethod; // The conversion factor to Ph's (Blind Pixel method)
-  Float_t fConversionSigmaPINDiodeMethod;   // The conversion factor to Phd's (PIN Diode method)
-
-  Float_t fConversionHiLo;                  // The conversion factor between Hi Gain and Lo Gain  
-  Float_t fConversionHiLoError;             // The error of the conversion factor between Hi Gain and Lo Gain  
-  
-  Bool_t  fHiGainSaturation;                // Is Lo-Gain used at all?
-
-  Bool_t  fFitValid;        
-  Bool_t  fFitted; 
-  Bool_t  fBlindPixelMethodValid;
-  Bool_t  fFFactorMethodValid;
-  Bool_t  fPINDiodeMethodValid;
-  
-  MHCalibrationPixel *fHist;    //! Pointer to the histograms performing the fits, etc.  
-  
-public:
-
-  MCalibrationPix(const char *name=NULL, const char *title=NULL);
-  ~MCalibrationPix();
-  
-  void Clear(Option_t *o="");
-
-  // Getter
-  Bool_t IsFitValid()              const { return fFitValid;  }
-  Bool_t IsFitted()                const { return fFitted;  }
-  Bool_t IsBlindPixelMethodValid() const { return fBlindPixelMethodValid;  }
-  Bool_t IsFFactorMethodValid()    const { return fFFactorMethodValid;  }
-  Bool_t IsPINDiodeMethodValid()   const { return fPINDiodeMethodValid;  }
-
-  Float_t GetCharge()              const { return fCharge;         }
-  Float_t GetRSigmaSquare()        const { return fRSigmaSquare;   }
-    
-  Float_t GetErrCharge()           const { return fErrCharge;      }
-  Float_t GetChargeProb()          const { return fChargeProb;     }    
-  
-  Float_t GetSigmaCharge()         const { return fSigmaCharge;    }
-  Float_t GetErrSigmaCharge()      const { return fErrSigmaCharge; }
-  Float_t GetTime()                const { return fTime;           }
-  Float_t GetSigmaTime()           const { return fSigmaTime;      }
-  Float_t GetTimeChiSquare()       const { return fTimeChiSquare;  }    
-
-  Float_t GetConversionHiLo()                 const  { return fConversionHiLo;        }
-  Float_t GetConversionHiLoError()            const  { return fConversionHiLoError;   }
-
-  Float_t GetMeanConversionBlindPixelMethod()  const { return fConversionBlindPixelMethod ; }
-  Float_t GetErrorConversionBlindPixelMethod() const { return fConversionErrorBlindPixelMethod ; }
-  Float_t GetSigmaConversionBlindPixelMethod() const { return fConversionSigmaBlindPixelMethod ; }
-
-  Float_t GetMeanConversionFFactorMethod()     const { return fConversionFFactorMethod ;       }
-  Float_t GetErrorConversionFFactorMethod()    const { return fConversionErrorFFactorMethod ;  }
-  Float_t GetSigmaConversionFFactorMethod()    const { return fConversionSigmaFFactorMethod ;  }
-
-  Float_t GetPheFFactorMethod()                const { return fPheFFactorMethod;               }
-  Float_t GetPheFFactorMethodError()           const { return fPheFFactorMethodError;          }
-
-  Float_t GetMeanConversionPINDiodeMethod()    const { return fConversionPINDiodeMethod ;      }
-  Float_t GetErrorConversionPINDiodeMethod()   const { return fConversionErrorPINDiodeMethod ; }
-  Float_t GetSigmaConversionPINDiodeMethod()   const { return fConversionSigmaPINDiodeMethod ; }
-
-  // FIXME: Remove this from stored data members
-  Float_t GetPed()    const { return fPed;    }
-  Float_t GetPedRms() const { return fPedRms; }
-
-  // Setter
-  void SetPedestal(Float_t ped, Float_t pedrms);
-  void SetHiGainSaturation()             { fHiGainSaturation = kTRUE; fHist->SetUseLoGain(); }
-
-  void SetConversionHiLo(Float_t c)      { fConversionHiLo      = c;    }
-  void SetConversionHiLoError(Float_t e) { fConversionHiLoError = e;    }
-
-  void SetConversionFFactorMethod(Float_t c, Float_t err, Float_t sig)
-  {
-      fConversionFFactorMethod = c;
-      fConversionErrorFFactorMethod = err;
-      fConversionSigmaFFactorMethod = sig;
-  }
-  void SetConversionBlindPixelMethod(Float_t c, Float_t err, Float_t sig)
-  {
-      fConversionBlindPixelMethod = c;
-      fConversionErrorBlindPixelMethod = err;
-      fConversionSigmaBlindPixelMethod = sig;
-  }
-
-  void SetConversionPINDiodeMethod(Float_t c, Float_t err, Float_t sig)
-  {
-      fConversionPINDiodeMethod = c ;
-      fConversionErrorPINDiodeMethod = err;
-      fConversionSigmaPINDiodeMethod = sig;
-  }
-
-  void SetFitValid()                            { fFitValid = kTRUE;  }
-  void SetFitted()                              { fFitted = kTRUE;  }
-  void SetBlindPixelMethodValid(Bool_t b=kTRUE) { fBlindPixelMethodValid = b;  }
-  void SetFFactorMethodValid(Bool_t b=kTRUE)    { fFFactorMethodValid = b;  }
-  void SetPINDiodeMethodValid(Bool_t b=kTRUE)   { fPINDiodeMethodValid = b;  }
-
-  // Unknown
-  void   ApplyLoGainConversion();
-
-  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 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); }    
-  
-  // FIXME: Not necessary -> pixidx (not id anyhow!) == index in array!
-  //        Only needed n histograms which have to move to an MH-class anyhow!
-  Int_t  GetPixId()                              const  { return fPixId;   }
-  void   DefinePixId(Int_t i);
-  
-  Bool_t FitCharge();
-  Bool_t FitTime();
-  
-  MHCalibrationPixel *GetHist() const   { return fHist;     }
-  void Draw(Option_t *opt="")           { fHist->Draw(opt); }
-  
-  ClassDef(MCalibrationPix, 1)	// Storage Container for Calibration information of one pixel
-};
-
-#endif
-
Index: /trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/Makefile	(revision 2733)
+++ /trunk/MagicSoft/Mars/manalysis/Makefile	(revision 2734)
@@ -53,5 +53,4 @@
            MCerPhotAnal2.cc \
 	   MCerPhotCalc.cc \
-	   MCalibrate.cc \
            MBlindPixels.cc \
            MBlindPixelCalc.cc \
@@ -76,9 +75,4 @@
            MCT1PadONOFF.cc  \
            MPadONOFF.cc  \
-           MCalibrationCalc.cc \
-           MCalibrationPix.cc  \
-           MCalibrationBlindPix.cc  \
-           MCalibrationPINDiode.cc  \
-           MCalibrationCam.cc \
            MPedestalWorkaround.cc \
            MExtractedSignalCam.cc \
Index: /trunk/MagicSoft/Mars/mcalib/CalibIncl.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/CalibIncl.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/CalibIncl.h	(revision 2734)
@@ -0,0 +1,3 @@
+#ifndef __CINT__
+
+#endif // __CINT__
Index: /trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 2734)
@@ -0,0 +1,19 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class MCalibrate+;
+
+#pragma link C++ class MCalibrationPix+;
+#pragma link C++ class MCalibrationBlindPix+;
+#pragma link C++ class MCalibrationPINDiode+;
+#pragma link C++ class MCalibrationCam+;
+#pragma link C++ class MCalibrationCalc+;
+
+#pragma link C++ class MHCalibrationBlindPixel+;
+#pragma link C++ class MHCalibrationPINDiode+;
+#pragma link C++ class MHCalibrationPixel+;
+
+#endif
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrate.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 2734)
@@ -0,0 +1,170 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Javier Lopez 12/2003 <mailto:jlopez@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//   MCalibrate
+//
+//   This task takes the integrated charge from MExtractedSignal and apply
+//   the calibration constants from MCalibraitionCam to the charge. Then
+//   stores number of photons obtained in MCerPhotEvt.
+//
+//   Input Containers:
+//    MExtractedSingal
+//    MCalibrationCam
+//
+//   Output Containers:
+//    MCerPhotEvt
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MCalibrate.h"
+#include "MCalibrationConfig.h"
+
+#include <TMath.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MH.h"
+
+#include "MGeomCam.h"
+
+#include "MCalibrationCam.h"
+#include "MCalibrationPix.h"
+
+#include "MExtractedSignalCam.h"
+#include "MExtractedSignalPix.h"
+
+#include "MCerPhotEvt.h"
+
+ClassImp(MCalibrate);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+MCalibrate::MCalibrate(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MCalibrate";
+    fTitle = title ? title : "Task to calculate the number of photons in one event";
+}
+
+// --------------------------------------------------------------------------
+//
+// The PreProcess searches for the following input containers:
+//  - MGeomCam
+//  - MCalibrationCam
+//  - MExtractedSignalCam
+//
+// The following output containers are also searched and created if
+// they were not found:
+//
+//  - MCerPhotEvt
+//
+Int_t MCalibrate::PreProcess(MParList *pList)
+{
+    fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
+    if (!fSignals)
+    {
+        *fLog << err << "MExtractedSignalCam not found ... aborting" << endl;
+        return kFALSE;
+    }
+
+    fCalibrations = (MCalibrationCam*)pList->FindObject("MCalibrationCam");
+    if (!fCalibrations)
+    {
+        *fLog << err << "MCalibrationCam not found ... aborting." << endl;
+        return kFALSE;
+    }
+
+    fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
+    if (!fCerPhotEvt)
+        return kFALSE;
+    
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//
+Int_t MCalibrate::Process()
+{
+  /*
+    if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
+    {
+        // FIXME: MExtractedSignal must be of variable size -
+        //        like MCerPhotEvt - because we must be able
+        //        to reduce size by zero supression
+        //        For the moment this check could be done in ReInit...
+        *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
+        return kFALSE;
+    }
+  */
+
+    const UInt_t imaxnumpix = fSignals->GetSize();
+    
+    for (UInt_t pixidx=0; pixidx<imaxnumpix; pixidx++)
+    {
+	const MCalibrationPix &pix = (*fCalibrations)[pixidx];
+
+        if (!pix.IsBlindPixelMethodValid())
+            continue;
+
+        MExtractedSignalPix &sig =  (*fSignals)[pixidx];
+
+        Float_t signal;
+        Float_t signalErr = 0.;
+
+        if (sig.IsLoGainUsed())
+        {
+            signal    = sig.GetExtractedSignalLoGain()*pix.GetConversionHiLo();
+            signalErr = signal*pix.GetConversionHiLoError();
+        }
+        else
+        {
+            signal = sig.GetExtractedSignalHiGain();
+        }
+
+        //      Float_t calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
+        const Float_t calibrationConversionFactor      = pix.GetMeanConversionBlindPixelMethod();
+        const Float_t calibrationConversionFactorError = pix.GetErrorConversionBlindPixelMethod();
+
+        const Float_t nphot = signal*calibrationConversionFactor;
+        Float_t nphotErr    = signal*calibrationConversionFactorError
+                             *signal*calibrationConversionFactorError;
+        nphotErr += signalErr*calibrationConversionFactor
+                   *signalErr*calibrationConversionFactor;
+
+        nphotErr  = TMath::Sqrt(nphotErr);
+
+        fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
+    }
+
+    fCerPhotEvt->FixSize();
+    fCerPhotEvt->SetReadyToSave();
+
+    return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrate.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrate.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrate.h	(revision 2734)
@@ -0,0 +1,47 @@
+#ifndef MARS_MCalibrate
+#define MARS_MCalibrate
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MCalibrate                                                              //
+//                                                                         //
+// Integrates the desired ADC time slices of one pixel and apply           //
+// calibration constants                                                   //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#ifndef ROOT_TArrayF
+#include <TArrayF.h>
+#endif
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MGeomCam;
+class MCalibrationCam;
+class MExtractedSignalCam;
+class MCerPhotEvt;
+
+class MCalibrate : public MTask
+{
+private:
+    MCalibrationCam     *fCalibrations; // Calibration constants 
+    MExtractedSignalCam *fSignals;      // Integrated charge in FADCs counts
+    MCerPhotEvt         *fCerPhotEvt; // Cerenkov Photon Event used for calculation
+
+    Float_t fConversionHiLo;
+    
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+
+public:
+
+    MCalibrate(const char *name=NULL, const char *title=NULL);
+
+    void SetConversionHiLo(Float_t conv) { fConversionHiLo = conv; }
+    
+    ClassDef(MCalibrate, 0)   // Task to calculate cerenkov photons using calibration constants
+};
+ 
+
+#endif
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.cc	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.cc	(revision 2734)
@@ -0,0 +1,124 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MCalibrationBlindPix                                                    //
+//                                                                         //
+// This is the storage container to hold informations about the calibration//
+// blind pixel                                                             //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationBlindPix.h"
+#include "MHCalibrationBlindPixel.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MCalibrationBlindPix);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default Constructor. 
+//
+MCalibrationBlindPix::MCalibrationBlindPix(const char *name, const char *title)
+    : 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.)
+{
+
+  fName  = name  ? name  : "MCalibrationBlindPix";
+  fTitle = title ? title : "Container of the MHCalibrationBlindPixel and the fit results";
+
+  fHist = new MHCalibrationBlindPixel();
+  
+  if (!fHist)
+    *fLog << err << dbginf << "Could not create MHCalibrationBlindPixel " << endl;
+
+  fLambda    = fMu0    = fMu1    = fSigma0    = fSigma1    = 0;
+  fErrLambda = fErrMu0 = fErrMu1 = fErrSigma0 = fErrSigma1 = 0;
+  
+  fTime = fErrTime = 0;
+}
+
+MCalibrationBlindPix::~MCalibrationBlindPix() 
+{
+  delete fHist;
+}
+
+// ------------------------------------------------------------------------
+//
+// Invalidate values
+//
+void MCalibrationBlindPix::Clear(Option_t *o)
+{
+  fHist->Reset();
+}
+
+Bool_t MCalibrationBlindPix::FitCharge() 
+{
+
+  if (!fHist->FitSinglePhe())
+    return kFALSE;
+  
+  fLambda = fHist->GetLambda();
+  fMu0    = fHist->GetMu0();
+  fMu1    = fHist->GetMu1();
+  fSigma0 = fHist->GetSigma0();
+  fSigma1 = fHist->GetSigma1();
+
+  fErrLambda = fHist->GetLambdaErr();
+  fErrMu0    = fHist->GetMu0Err();
+  fErrMu1    = fHist->GetMu1Err();
+  fErrSigma0 = fHist->GetSigma0Err();
+  fErrSigma1 = fHist->GetSigma1Err();
+
+  return kTRUE;
+}
+
+
+
+Bool_t MCalibrationBlindPix::FitTime() 
+{
+
+  if(!fHist->FitTime())
+    return kFALSE;
+
+  fTime    = fHist->GetMeanTime();
+  fErrTime = fHist->GetMeanTimeErr();
+  
+  return kTRUE;
+
+}
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.h	(revision 2734)
@@ -0,0 +1,69 @@
+#ifndef MARS_MCalibrationBlindPix
+#define MARS_MCalibrationBlindPix
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#include "MHCalibrationBlindPixel.h"
+
+class MCalibrationBlindPix : public MParContainer
+{
+private:
+
+  Float_t fLambda;           // The mean charge after the fit
+  Float_t fMu0;              // The position of the pedestal-peak
+  Float_t fMu1;              // The position of the first phe-peak
+  Float_t fSigma0;           // The width of the pedestal-peak
+  Float_t fSigma1;           // The width of the first phe-peak  
+
+  Float_t fErrLambda;        // The error of the mean charge after the fit
+  Float_t fErrMu0;           // The error of the position of the pedestal-peak
+  Float_t fErrMu1;           // The error of the position of the first phe-peak
+  Float_t fErrSigma0;        // The error of the width of the pedestal-peak
+  Float_t fErrSigma1;        // The error of the width of the first phe-peak  
+  
+  Float_t fTime;                // The mean arrival time after the fit  
+  Float_t fErrTime;             // The error of the mean arrival time after the fit
+  
+  MHCalibrationBlindPixel *fHist; // Pointer to the histograms performing the fits, etc.  
+  
+public:
+
+  MCalibrationBlindPix(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationBlindPix();
+  
+  void Clear(Option_t *o="");
+  
+  Float_t GetLambda()    const    { return fLambda;  }
+  Float_t GetMu0()       const    { return fMu0;  }
+  Float_t GetMu1()       const    { return fMu1;  }
+  Float_t GetSigma0()    const    { return fSigma0;  }
+  Float_t GetSigma1()    const    { return fSigma1;  }
+
+  Float_t GetErrLambda() const    { return fErrLambda;  }
+  Float_t GetErrMu0()    const    { return fErrMu0;  }
+  Float_t GetErrMu1()    const    { return fErrMu1;  }
+  Float_t GetErrSigma0() const    { return fErrSigma0;  }
+  Float_t GetErrSigma1() const    { return fErrSigma1;  }
+
+  Float_t GetTime()      const    { return fTime;         }
+  Float_t GetErrTime()   const    { return fErrTime;      }
+  
+  Bool_t FillCharge(Float_t q)    { return fHist->FillBlindPixelCharge(q); }
+  Bool_t FillTime(Int_t t)        { return fHist->FillBlindPixelTime(t); }  
+  Bool_t FillRChargevsTime(Float_t rq, Int_t t) { return fHist->FillBlindPixelChargevsN(rq,t); }    
+  
+  Bool_t IsFitOK()                              { return fHist->IsFitOK(); }
+  
+  Bool_t FitCharge();
+  Bool_t FitTime();
+  
+  virtual void Draw(Option_t *opt="")         { fHist->Draw(opt); }
+  MHCalibrationBlindPixel *GetHist()  const  { return fHist;  }
+  
+  ClassDef(MCalibrationBlindPix, 1)	// Storage Container for Calibration information of one pixel
+};
+
+#endif
+
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 2734)
@@ -0,0 +1,453 @@
+ /* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug  09/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//   MCalibrationCalc                                                       //
+//                                                                          //
+//   This is a task which calculates the number of photons from the FADC    //
+//   time slices. At the moment it integrates simply the FADC values.       //
+//                                                                          //
+//  Input Containers:                                                       //
+//   MRawEvtData                                                            //
+//                                                                          //
+//  Output Containers:                                                      //
+//   MCalibrationCam                                                        //
+//                                                                          //
+//                                                                          //
+//  The class MCalibrationCam hold one entry of type MCalibrationPix for    //
+//  every pixel. It is filled in the following way:                         //
+//  PreParocess: MalibrationCam::InitSize(577) is called which allocates    //
+//               memory in an TClonesArray of type MCalibrationPix and      //
+//               all pointers to NULL.                                      //
+//                                                                          //
+//  Process:     The NULL pointer is tested on every pixel via              //
+//               MalibrationCam::IsPixelUsed(npix).                         //
+//                                                                          //
+//               In case, IsPixelUsed returns NULL,                         //
+//               MalibrationCam::AddPixel(npix) is invoked which creates a  //
+//               new MCalibrationPix(npix) in the npix's entry              //
+//               of the TClonesArray.                                       //
+//                                                                          //
+//               Every MCalibrationPix holds a histogram class,             //
+//               MHCalibrationPixel which itself hold histograms of type:   //
+//               HCharge(npix) (distribution of summed FADC time slice entries) 
+//               HTime(npix) (distribution of position of maximum)              
+//               HChargevsN(npix) (distribution of charges vs. event number.
+//                                                                          
+// PostProcess:  All histograms HCharge(npix) are fitted to a Gaussian      
+//               All histograms HTime(npix) are fitted to a Gaussian        
+//               The histogram HBlindPixelCharge (blind pixel) is fitted to a single     
+//                   PhE fit                                                
+//               The histogram HBlindPixelTime (blind pixel) is fitted to a Gaussian   
+//               The histograms of the PIN Diode are fitted to Gaussians    
+//                                                                          
+//               Fits can be excluded via the commands:                     
+//               MalibrationCam::SetSkipTimeFits()   (skip all time fits)   
+//               MalibrationCam::SetSkipBlindPixelFits()  (skip all blind pixel fits) 
+//               MalibrationCam::SetSkipPinDiodeFits()  (skip all PIN Diode fits) 
+//                                                                          
+//////////////////////////////////////////////////////////////////////////////
+
+#include "MCalibrationCalc.h"
+#include "MCalibrationConfig.h"
+#include "MCalibrationFits.h"
+
+#include "MCalibrationCam.h"
+#include "MCalibrationPix.h"
+#include "MCalibrationBlindPix.h"
+#include "MCalibrationPINDiode.h"
+
+#include "MPedestalCam.h"
+#include "MPedestalPix.h"
+
+#include "MGeomCam.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MH.h"
+
+#include "MRawRunHeader.h"
+#include "MRawEvtData.h"       // MRawEvtData::GetNumPixels
+#include "MRawEvtPixelIter.h"
+
+#include "MExtractedSignalCam.h"
+#include "MExtractedSignalPix.h"
+
+#include "MTime.h"
+#include "TMath.h"
+
+ClassImp(MCalibrationCalc);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default constructor. b is the number of slices before the maximum slice,
+// a the number of slices behind the maximum slice which is taken as signal.
+//
+MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
+    : fColor(kEBlue)
+{
+
+    fName  = name  ? name  : "MCalibrationCalc";
+    fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
+
+    AddToBranchList("MRawEvtData.fHiGainPixId");
+    AddToBranchList("MRawEvtData.fLoGainPixId");
+    AddToBranchList("MRawEvtData.fHiGainFadcSamples");
+    AddToBranchList("MRawEvtData.fLoGainFadcSamples");
+
+    SETBIT(fFlags, kUseTimeFits);
+    SETBIT(fFlags, kUseBlindPixelFit);
+    SETBIT(fFlags, kUsePinDiodeFit);
+
+}
+
+// --------------------------------------------------------------------------
+//
+// The PreProcess searches for the following input containers:
+//  - MRawEvtData
+//  - MPedestalCam
+//
+// The following output containers are also searched and created if
+// they were not found:
+//
+//  - MHCalibrationBlindPixel
+//  - MCalibrationCam
+//  - MTime
+//
+Int_t MCalibrationCalc::PreProcess(MParList *pList)
+{
+
+    fHistOverFlow = 0;
+    fEvents       = 0;
+    fCosmics      = 0;
+
+    fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
+    if (!fRawEvt)
+    {
+        *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!runheader)
+        *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
+    else
+        if (runheader->GetRunType() == kRTMonteCarlo)
+        {
+            return kTRUE;
+        }
+
+    fCalibrations = (MCalibrationCam*)pList->FindCreateObj("MCalibrationCam");
+    if (!fCalibrations)
+      {
+        *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;        
+        return kFALSE;
+      }
+
+
+    switch (fColor)
+      {
+      case kEBlue:
+        fCalibrations->SetColor(MCalibrationCam::kECBlue);
+	break;        
+      case kEGreen:
+        fCalibrations->SetColor(MCalibrationCam::kECGreen);      
+	break;
+      case kEUV:
+        fCalibrations->SetColor(MCalibrationCam::kECUV);            
+	break;
+      case kECT1:
+        fCalibrations->SetColor(MCalibrationCam::kECCT1);            
+	break;
+      default:
+        fCalibrations->SetColor(MCalibrationCam::kECCT1); 
+      }
+
+    fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
+    if (!fPedestals)
+      {
+        *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
+        return kFALSE;
+      }
+
+
+    fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
+    if (!fSignals)
+      {
+        *fLog << err << dbginf << "Cannot find MExtractedSignalCam ... aborting" << endl;
+        return kFALSE;
+      }
+    
+    return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// The ReInit searches for the following input containers:
+//  - MRawRunHeader
+//
+Bool_t MCalibrationCalc::ReInit(MParList *pList )
+{
+ 
+    fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!fRunHeader)
+    {
+        *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+
+
+    MGeomCam *cam = (MGeomCam*)pList->FindObject("MGeomCam");
+    if (!cam)
+    {
+        *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
+        return kFALSE;
+    }
+
+
+    fNumHiGainSamples =  fSignals->GetNumUsedHiGainFADCSlices();
+    fNumLoGainSamples =  fSignals->GetNumUsedLoGainFADCSlices();
+
+    fCalibrations->InitSize(cam->GetNumPixels());    
+
+    for (UInt_t i=0;i<cam->GetNumPixels();i++)
+      {
+        MCalibrationPix &pix = (*fCalibrations)[i];
+        pix.DefinePixId(i);
+      }
+    
+    return kTRUE;
+ 
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Calculate the integral of the FADC time slices and store them as a new
+// pixel in the MCerPhotEvt container.
+//
+Int_t MCalibrationCalc::Process()
+{
+
+    Int_t cosmicpix = 0;
+
+    MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
+    MCalibrationPINDiode &pindiode   = *(fCalibrations->GetPINDiode());
+
+    MRawEvtPixelIter pixel(fRawEvt);
+
+    //
+    // Create a first loop to sort out the cosmics ...
+    // 
+    // This is a very primitive check for the number of cosmicpixs
+    // The cut will be applied in the fit, but for the blind pixel,
+    // we need to remove this event
+    //
+    // FIXME: In the future need a much more sophisticated one!!!
+    //
+
+    while (pixel.Next())
+      {
+	
+	const UInt_t pixid = pixel.GetPixelId();
+	
+	MExtractedSignalPix &sig =  (*fSignals)[pixid];
+        MPedestalPix        &ped =  (*fPedestals)[pixid];
+        Float_t pedrms     = ped.GetPedestalRms();
+	Float_t sumhi      = sig.GetExtractedSignalHiGain();
+        
+	if (sumhi < 15.*pedrms )   // cut at 3.5 sigma
+	  cosmicpix++;
+     }
+
+    if (cosmicpix > 100.)
+      {
+	fCosmics++;
+	return kCONTINUE;
+      }
+
+    pixel.Reset();
+    fEvents++;
+
+    //
+    // Create a second loop to do fill the calibration histograms
+    // 
+
+    while (pixel.Next())
+      {
+
+	const UInt_t pixid = pixel.GetPixelId();
+	
+	MExtractedSignalPix &sig =  (*fSignals)[pixid];
+        
+	Float_t sumhi  = sig.GetExtractedSignalHiGain();
+	Float_t sumlo  = sig.GetExtractedSignalLoGain();
+	Float_t mtime  = sig.GetMeanArrivalTime();
+
+	MCalibrationPix &pix = (*fCalibrations)[pixid];
+
+        switch(pixid)
+          {
+            
+          case gkCalibrationBlindPixelId:
+
+	    if (!blindpixel.FillCharge(sumhi)) 
+	      *fLog << err << 
+		"Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
+
+	    if (!blindpixel.FillTime((int)mtime)) 
+	      *fLog << err << 
+		"Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
+	    
+	    if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
+	      *fLog << warn << 
+		"Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
+            
+          case gkCalibrationPINDiodeId:
+            if (!pindiode.FillCharge(sumhi)) 
+              *fLog << warn << 
+                "Overflow or Underflow occurred filling HCharge: means = " << sumhi << endl;
+            if (!pindiode.FillTime((int)mtime)) 
+              *fLog << warn << 
+                "Overflow or Underflow occurred filling HTime: time = " << mtime << endl;
+            if (!pindiode.FillRChargevsTime(sumhi,fEvents))
+              *fLog << warn << 
+                "Overflow or Underflow occurred filling HChargevsN: eventnr = " << fEvents << endl;
+	    break;
+
+          default:
+
+	    pix.SetChargesInGraph(sumhi,sumlo);
+
+	    if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
+	      *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: " 
+		    << pixid << " signal = " << sumlo  << " event Nr: " << fEvents << endl;
+		
+	    if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
+	      *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: " 
+		    << pixid << " signal = " << sumhi  << " event Nr: " << fEvents << endl;
+
+	    if (sig.IsLoGainUsed())
+	      {
+		
+		if (!pix.FillChargeLoGain(sumlo))
+		  *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid 
+			<< " signal = " << sumlo << endl;
+
+		if (!pix.FillTimeLoGain((int)mtime)) 
+		  *fLog << warn << "Could not fill Lo Gain Time of pixel: " 
+			<< pixid << " time = " << mtime << endl;
+		
+	      }
+	    else
+	      {
+		if (!pix.FillChargeHiGain(sumhi))
+		  *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid 
+			<< " signal = " << sumhi << endl;
+		
+		if (!pix.FillTimeHiGain((int)mtime)) 
+		  *fLog << warn << "Could not fill Hi Gain Time of pixel: " 
+			<< pixid << " time = " << mtime << endl;
+		
+	      }
+	    break;
+	    
+          } /* switch(pixid) */
+
+      } /* while (pixel.Next()) */
+
+    return kTRUE;
+}
+
+Int_t MCalibrationCalc::PostProcess()
+{
+
+
+  *fLog << inf << endl;
+  *fLog << GetDescriptor() << " Cut Histogram Edges" << endl;
+
+  //
+  // Cut edges to make fits and viewing of the hists easier  
+  //
+  fCalibrations->CutEdges();
+
+  //
+  // Get pointer to blind pixel
+  //
+  MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
+
+  *fLog << GetDescriptor() << " Fitting the Blind Pixel" << endl;
+
+  // 
+  // Fit the blind pixel
+  //
+  if (TESTBIT(fFlags,kUseBlindPixelFit))
+    {
+
+      if (!blindpixel.FitCharge())
+        *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
+
+      blindpixel.Draw();
+    }
+  
+  *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
+
+  //
+  // loop over the pedestal events and check if we have calibration
+  //
+  for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
+    {
+
+      MCalibrationPix &pix = (*fCalibrations)[pixid];
+
+      const Float_t ped    = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
+      const Float_t prms   = (*fPedestals)[pixid].GetPedestalRms() * TMath::Sqrt((float)fNumHiGainSamples);
+
+      pix.SetPedestal(ped,prms);
+
+      pix.FitCharge();
+
+      if (TESTBIT(fFlags,kUseTimeFits))
+        pix.FitTime();
+      
+    }
+
+  if (!fCalibrations->CalcNumPhotInsidePlexiglass())
+    *fLog << err << dbginf << "Could not calculate the number of photons from the blind pixel " << endl;
+
+  fCalibrations->SetReadyToSave();
+  
+  if (GetNumExecutions()==0)
+    return kTRUE;
+  
+  *fLog << endl;
+  *fLog << dec << setfill(' ') << fCosmics << " Events presumably cosmics" << endl;
+
+  return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h	(revision 2734)
@@ -0,0 +1,83 @@
+#ifndef MARS_MCalibrationCalc
+#define MARS_MCalibrationCalc
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MCalibrationCalc                                                   //
+//                                                                         //
+// Integrates the time slices of the all pixels of a calibration event     //
+// and substract the pedestal value                                        //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MRawEvtData;
+class MRawRunHeader;
+
+class MPedestalCam;
+class MCalibrationCam;
+class MExtractedSignalCam;
+
+class MTime;
+
+class MCalibrationCalc : public MTask
+{
+private:
+
+  MPedestalCam             *fPedestals;    // Pedestals of all pixels in the camera
+  MCalibrationCam          *fCalibrations; // Calibration events of all pixels in the camera
+  MExtractedSignalCam      *fSignals;      // Calibration events of all pixels in the camera
+
+  MRawEvtData              *fRawEvt;       // raw event data (time slices)
+  MRawRunHeader            *fRunHeader;    // RunHeader information
+
+  MTime                    *fEvtTime;      // Time of the event
+
+  Int_t fEvents;                           // Number of events  
+  Int_t fHistOverFlow;                     // Number of events with saturated Low Gain
+  Int_t fCosmics;                          // Number of events due to supposed cosmics
+
+  Byte_t fNumHiGainSamples; 
+  Byte_t fNumLoGainSamples; 
+
+  Byte_t fFlags;                           // Flag for the fits used
+   
+  Float_t fConversionHiLo;
+  
+  enum  { kUseTimeFits, kUseBlindPixelFit, kUsePinDiodeFit };
+
+public:
+  
+  enum PulserColor_t  { kEGreen, kEBlue, kEUV, kECT1 };
+
+private:
+
+  PulserColor_t  fColor;
+  
+  Bool_t ReInit(MParList *pList); 
+  Int_t PreProcess(MParList *pList);
+  Int_t Process();
+  Int_t PostProcess();
+  
+public:
+
+  MCalibrationCalc(const char *name=NULL, const char *title=NULL);
+
+  void SetSkipTimeFits(Bool_t b=kTRUE)
+      {b ? CLRBIT(fFlags, kUseTimeFits) : SETBIT(fFlags, kUseTimeFits);}
+  void SetSkipBlindPixelFit(Bool_t b=kTRUE)
+      {b ? CLRBIT(fFlags, kUseBlindPixelFit) : SETBIT(fFlags, kUseBlindPixelFit);}
+  void SetSkipPinDiodeFit(Bool_t b=kTRUE)
+      {b ? CLRBIT(fFlags, kUsePinDiodeFit) : SETBIT(fFlags, kUsePinDiodeFit);}
+
+  void SetPulserColor(PulserColor_t color)    { fColor = color; }
+
+  void SetConversionHiLo(Float_t conv)         { fConversionHiLo = conv; }
+  
+  ClassDef(MCalibrationCalc, 1)   // Task to fill the Calibration Containers from raw data
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 2734)
@@ -0,0 +1,625 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+
+! *
+!
+!
+!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                               
+// MCalibrationCam                                               
+//                                                               
+// Hold the whole Calibration results of the camera:
+//                                                               
+// 1) MCalibrationCam initializes a TClonesArray whose elements are 
+//    pointers to MCalibrationPix Containers
+// 2) It initializes a pointer to an MCalibrationBlindPix container
+// 3) It initializes a pointer to an MCalibrationPINDiode container
+//
+// 4)  
+// 
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationCam.h"
+#include "MCalibrationPix.h"
+#include "MHCalibrationPixel.h"
+#include "MCalibrationBlindPix.h"
+#include "MCalibrationConfig.h"
+
+#include <TClonesArray.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "TCanvas.h"
+
+#include "MGeomCam.h"
+
+ClassImp(MCalibrationCam);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+// Creates a TClonesArray of MCalibrationPix containers, initialized to 1 entry
+// Later, a call to MCalibrationCam::InitSize(Int_t size) has to be performed
+//
+// Creates an MCalibrationBlindPix container 
+// Creates an MCalibrationPINDiode container
+//
+MCalibrationCam::MCalibrationCam(const char *name, const char *title)
+    : fNumPhotInsidePlexiglassAvailable(kFALSE),
+      fMeanPhotInsidePlexiglass(-1.),
+      fMeanPhotErrInsidePlexiglass(-1.),
+      fNumPhotOutsidePlexiglassAvailable(kFALSE),
+      fMeanPhotOutsidePlexiglass(-1.),
+      fMeanPhotErrOutsidePlexiglass(-1.),
+      fOffsets(NULL),
+      fSlopes(NULL),
+      fOffvsSlope(NULL)
+{
+    fName  = name  ? name  : "MCalibrationCam";
+    fTitle = title ? title : "Storage container for the Calibration Information in the camera";
+
+    fPixels     = new TClonesArray("MCalibrationPix",1);
+    fBlindPixel = new MCalibrationBlindPix();
+    fPINDiode   = new MCalibrationPINDiode();
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the TClonesArray of MCalibrationPix containers
+// Delete the MCalibrationPINDiode and the MCalibrationBlindPix
+//
+// Delete the histograms if they exist
+//
+MCalibrationCam::~MCalibrationCam()
+{
+
+  //
+  // delete fPixels should delete all Objects stored inside
+  // 
+  delete fPixels;
+  delete fBlindPixel;
+  delete fPINDiode;
+
+  if (fOffsets)
+    delete fOffsets;
+  if (fSlopes)
+    delete fSlopes;
+  if (fOffvsSlope)
+    delete fOffvsSlope;
+
+}
+
+// -------------------------------------------------------------------
+//
+// This function simply allocates memory via the ROOT command:
+// (TObject**) TStorage::ReAlloc(fCont, newSize * sizeof(TObject*),
+//                                      fSize * sizeof(TObject*));
+// newSize corresponds to size in our case
+// fSize is the old size (in most cases: 1)
+//
+void MCalibrationCam::InitSize(Int_t size)
+{
+  
+  //
+  // check if we have already initialized to size
+  //
+  if (CheckBounds(size))
+    return;
+  
+  fPixels->ExpandCreate(size);
+
+}
+
+// --------------------------------------------------------------------------
+//
+// This function returns the current size of the TClonesArray 
+// independently if the MCalibrationPix is filled with values or not.
+//
+// It is the size of the array fPixels.
+//
+Int_t MCalibrationCam::GetSize() const
+{
+  return fPixels->GetEntriesFast();
+}
+
+// --------------------------------------------------------------------------
+//
+// Check if position i is inside the current bounds of the TClonesArray
+//
+Bool_t MCalibrationCam::CheckBounds(Int_t i) const 
+{
+    return i < fPixels->GetEntriesFast();
+} 
+
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+MCalibrationPix &MCalibrationCam::operator[](Int_t i)
+{
+
+  if (!CheckBounds(i))
+    return *static_cast<MCalibrationPix*>(NULL);
+
+  return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+MCalibrationPix &MCalibrationCam::operator[](Int_t i) const
+{
+
+  if (!CheckBounds(i))
+    return *static_cast<MCalibrationPix*>(NULL);
+
+  return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Return true if pixel is inside bounds of the TClonesArray fPixels
+//
+Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const 
+{
+  if (!CheckBounds(idx))
+    return kFALSE;
+
+  return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Return true if pixel has already been fitted once (independent of the result)
+//
+Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const 
+{
+
+  if (!CheckBounds(idx))
+    return kFALSE;
+
+  return (*this)[idx].IsFitted();
+}
+
+
+// --------------------------------------
+//
+void MCalibrationCam::Clear(Option_t *o)
+{
+    fPixels->ForEach(TObject, Clear)();
+}
+
+// --------------------------------------------------------------------------
+//
+// Sets the user ranges of all histograms such that 
+// empty bins at the edges are not used. Additionally, it rebins the 
+// histograms such that in total, 50 bins are used.
+//
+void MCalibrationCam::CutEdges()
+{
+
+  fBlindPixel->GetHist()->CutAllEdges();
+  fPINDiode->GetHist()->CutAllEdges();
+
+  TIter Next(fPixels);
+  MCalibrationPix *pix;
+  while ((pix=(MCalibrationPix*)Next()))
+    {
+      pix->GetHist()->CutAllEdges();
+    }
+
+  return;
+}
+  
+// --------------------------------------------------------------------------
+//
+// Print first the well fitted pixels 
+// and then the ones which are not FitValid
+//
+void MCalibrationCam::Print(Option_t *o) const
+{
+
+  *fLog << all << GetDescriptor() << ":" << endl;
+  int id = 0;
+  
+  *fLog << "Succesfully calibrated pixels:" << endl;
+  *fLog << endl;
+
+  TIter Next(fPixels);
+  MCalibrationPix *pix;
+  while ((pix=(MCalibrationPix*)Next()))
+    {
+      
+      if (pix->IsFitValid()) 
+	{
+	  *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
+		<< " Reduced Charge: " << pix->GetCharge() << " +- " 
+		<< pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
+	  id++;
+	}
+    }
+  
+  *fLog << id << " succesful pixels :-))" << endl;
+  id = 0;
+  
+  *fLog << endl;
+  *fLog << "Pixels with errors:" << endl;
+  *fLog << endl;
+  
+  TIter Next2(fPixels);
+    while ((pix=(MCalibrationPix*)Next2()))
+      {
+        
+        if (!pix->IsFitValid())
+          {
+            *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
+                  << " Reduced Charge: " << pix->GetCharge() << " +- " 
+		<< pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
+            id++;
+          }
+      }
+    *fLog << id << " pixels with errors :-((" << endl;
+    
+}
+
+// The types are as follows:
+// 
+// 0: Fitted Charge
+// 1: Error of fitted Charge
+// 2: Sigma of fitted Charge
+// 3: Error of Sigma of fitted Charge
+// 4: Returned probability of Gauss fit to Charge distribution
+// 5: Mean arrival time
+// 6: Sigma of the arrival time
+// 7: Chi-square of the Gauss fit to the arrival times
+// 8: Pedestal
+// 9: Pedestal RMS
+// 10: Reduced Sigma Square
+// 11: Number of Photo-electrons after the F-Factor method
+// 12: Error on the Number of Photo-electrons after the F-Factor method
+// 13: Mean conversion factor after the F-Factor method
+// 14: Error on the conversion factor after the F-Factor method
+// 15: Number of Photons after the Blind Pixel method
+// 16: Mean conversion factor after the Blind Pixel method
+//
+Bool_t MCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
+{
+
+  if (idx > GetSize())
+    return kFALSE;
+
+  switch (type)
+    {
+    case 0:
+      val = (*this)[idx].GetCharge();
+      break;
+    case 1:
+      val = (*this)[idx].GetErrCharge();
+      break;
+    case 2:
+      val = (*this)[idx].GetSigmaCharge();
+      break;
+    case 3:
+      val = (*this)[idx].GetErrSigmaCharge();
+      break;
+    case 4:
+      val = (*this)[idx].GetChargeProb();
+      break;
+    case 5:
+      val = (*this)[idx].GetTime();
+      break;
+    case 6:
+      val = (*this)[idx].GetSigmaTime();
+      break;
+    case 7:
+      val = (*this)[idx].GetTimeChiSquare();
+      break;
+    case 8:
+      val = (*this)[idx].GetPed();
+      break;
+    case 9:
+      val = (*this)[idx].GetPedRms();
+      break;
+    case 10:
+      if ((*this)[idx].GetRSigmaSquare() > 0.)
+	val = TMath::Sqrt((*this)[idx].GetRSigmaSquare());
+      else
+	val = -1.;
+      break;
+    case 11:
+      val = (*this)[idx].GetPheFFactorMethod();
+      break;
+    case 12:
+      val = (*this)[idx].GetPheFFactorMethodError();
+      break;
+    case 13:
+      val = (*this)[idx].GetMeanConversionFFactorMethod();
+      break;
+    case 14:
+      val = (*this)[idx].GetErrorConversionFFactorMethod();
+      break;
+    case 15:
+      if (idx < 397)
+	val = (double)fMeanPhotInsidePlexiglass;
+      else
+	val = (double)fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
+      break;
+    case 16:
+      if (idx < 397)
+        val = (*this)[idx].GetMeanConversionBlindPixelMethod();
+      else 
+        val = (*this)[idx].GetMeanConversionBlindPixelMethod()*gkCalibrationOutervsInnerPixelArea;
+      break;
+    case 17:
+      if ((*this)[idx].GetCharge() != 0.)
+        val = ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge())*
+              ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge());
+      else
+        val = -1.;
+      break;
+    default:
+      return kFALSE;
+    }
+  return val>=0;
+}
+
+// --------------------------------------------------------------------------
+//
+// What MHCamera needs in order to draw an individual pixel in the camera
+//
+void MCalibrationCam::DrawPixelContent(Int_t idx) const
+{
+  (*this)[idx].Draw();
+}
+
+
+// --------------------------------------------------------------------------
+//
+
+//
+Bool_t MCalibrationCam::CalcNumPhotInsidePlexiglass()
+{
+
+  if (!fBlindPixel->IsFitOK())
+    return kFALSE;
+  
+  const Float_t mean = fBlindPixel->GetLambda();
+  const Float_t merr = fBlindPixel->GetErrLambda();
+  
+  switch (fColor)
+    {
+    case kECGreen:
+      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEGreen)     // real photons
+                            *TMath::Power(10,gkCalibrationBlindPixelAttGreen) // correct for absorption 
+                            * gkCalibrationInnerPixelArea;                    // correct for area
+      break;
+    case kECBlue:
+      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEBlue )
+                            *TMath::Power(10,gkCalibrationBlindPixelAttBlue)
+                            * gkCalibrationInnerPixelArea;
+      break;
+    case kECUV:
+      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEUV )
+                            *TMath::Power(10,gkCalibrationBlindPixelAttUV)
+                            * gkCalibrationInnerPixelArea;
+      break;
+    case kECCT1:
+    default:
+      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQECT1 )
+                            *TMath::Power(10,gkCalibrationBlindPixelAttCT1)
+                            * gkCalibrationInnerPixelArea;
+      break;
+    }
+
+  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.))
+        {
+
+          Float_t conversion      = fMeanPhotInsidePlexiglass/pix->GetCharge();
+          Float_t conversionerr   = 0.;
+          Float_t conversionsigma = 0.;
+          pix->SetConversionBlindPixelMethod(conversion, conversionerr, conversionsigma);
+
+          if (conversionerr/conversion < 0.1) 
+            pix->SetBlindPixelMethodValid();
+        }
+    }
+  return kTRUE;
+}
+
+
+Bool_t MCalibrationCam::CalcNumPhotOutsidePlexiglass()
+{
+
+  if (!fPINDiode->IsFitOK())
+    return kFALSE;
+  
+  const Float_t mean = fPINDiode->GetMean();
+  const Float_t merr = fPINDiode->GetMeanError();
+  
+  switch (fColor)
+    {
+    case kECGreen:
+      fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEGreen)   // real photons
+                            * gkCalibrationInnerPixelvsPINDiodeArea;        // correct for area
+      break;
+    case kECBlue:
+      fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEBlue )
+                            * gkCalibrationInnerPixelvsPINDiodeArea;
+      break;
+    case kECUV:
+      fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQEUV )
+                            * gkCalibrationInnerPixelvsPINDiodeArea;
+      break;
+    case kECCT1:
+    default:
+      fMeanPhotOutsidePlexiglass = (mean / gkCalibrationPINDiodeQECT1 )
+                            * gkCalibrationInnerPixelvsPINDiodeArea;
+      break;
+    }
+
+  fNumPhotOutsidePlexiglassAvailable = kTRUE;
+
+  TIter Next(fPixels);
+  MCalibrationPix *pix;
+  while ((pix=(MCalibrationPix*)Next()))
+    {
+      
+      if((pix->GetCharge() > 0.) && (fMeanPhotInsidePlexiglass > 0.))
+	pix->SetConversionPINDiodeMethod(fMeanPhotOutsidePlexiglass/pix->GetCharge(), 0., 0.);
+    }
+  return kTRUE;
+}
+
+
+
+Bool_t MCalibrationCam::GetConversionFactorBlindPixel(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
+{
+  
+  if (ipx < 0 || !IsPixelFitted(ipx))
+    return kFALSE;
+
+  if (!fNumPhotInsidePlexiglassAvailable)
+    if (!CalcNumPhotInsidePlexiglass())
+      return kFALSE;
+
+  mean  = (*this)[ipx].GetMeanConversionBlindPixelMethod();
+  err   = (*this)[ipx].GetErrorConversionBlindPixelMethod();
+  sigma = (*this)[ipx].GetSigmaConversionBlindPixelMethod();
+
+  return kTRUE;
+}
+
+
+Bool_t MCalibrationCam::GetConversionFactorFFactor(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
+{
+  
+  if (ipx < 0 || !IsPixelFitted(ipx))
+    return kFALSE;
+
+  Float_t conv = (*this)[ipx].GetMeanConversionFFactorMethod();
+
+  if (conv < 0.)
+    return kFALSE;
+
+  mean  = conv;
+  err   = (*this)[ipx].GetErrorConversionFFactorMethod();
+  sigma = (*this)[ipx].GetSigmaConversionFFactorMethod();
+
+  return kTRUE;
+}
+
+
+//-----------------------------------------------------------------------------------
+//
+// Calculates the conversion factor between the integral of FADCs slices 
+// (as defined in the signal extractor MExtractSignal.cc)
+// and the number of photons reaching the plexiglass for one Inner Pixel 
+//
+// FIXME: The PINDiode is still not working and so is the code 
+//
+Bool_t MCalibrationCam::GetConversionFactorPINDiode(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
+{
+
+  if (ipx < 0 || !IsPixelFitted(ipx))
+    return kFALSE;
+
+  return kFALSE;
+
+}
+
+//-----------------------------------------------------------------------------------
+//
+// Calculates the best combination of the three used methods possible 
+// between the integral of FADCs slices 
+// (as defined in the signal extractor MExtractSignal.cc)
+// and the number of photons reaching one Inner Pixel. 
+// The procedure is not yet defined.
+//
+// FIXME: The PINDiode is still not working and so is the code 
+//
+Bool_t MCalibrationCam::GetConversionFactorCombined(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
+{
+
+  if (ipx < 0 || !IsPixelFitted(ipx))
+    return kFALSE;
+
+  return kFALSE;
+
+}
+
+
+void MCalibrationCam::DrawHiLoFits()
+{
+
+  if (!fOffsets)
+    fOffsets = new TH1D("pp","Offsets of the HiGain LoGain Fit",100,-600.,400.);
+  if (!fSlopes)
+    fSlopes  = new TH1D("mm","Slopes of the HiGain LoGain Fit",100,-2.,2.);
+  if (!fOffvsSlope)
+    fOffvsSlope = new TH2D("aa","Slopes vs Offsets of the HiGain LoGain Fit",100,-600.,400.,100,-2.,2.);
+
+  TIter Next(fPixels);
+  MCalibrationPix *pix;
+  MHCalibrationPixel *hist;
+  while ((pix=(MCalibrationPix*)Next()))
+    {
+      hist = pix->GetHist();
+      hist->FitHiGainvsLoGain();
+      fOffsets->Fill(hist->GetOffset(),1.);
+      fSlopes->Fill(hist->GetSlope(),1.);
+      fOffvsSlope->Fill(hist->GetOffset(),hist->GetSlope(),1.);
+    }
+
+   TCanvas *c1 = new TCanvas();
+
+   c1->Divide(1,3);
+   c1->cd(1);
+   fOffsets->Draw();
+   gPad->Modified();
+   gPad->Update();
+
+   c1->cd(2);
+  fSlopes->Draw();
+  gPad->Modified();
+  gPad->Update();
+
+  c1->cd(3);
+  fOffvsSlope->Draw("col1");
+  gPad->Modified();
+  gPad->Update();
+}
+
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.h	(revision 2734)
@@ -0,0 +1,135 @@
+#ifndef MARS_MCalibrationCam
+#define MARS_MCalibrationCam
+
+#ifndef MARS_MCamEvent
+#include "MCamEvent.h"
+#endif
+
+#ifndef MARS_MCalibrationPix
+#include "MCalibrationPix.h"
+#endif
+
+#ifndef MARS_MCalibrationBlindPix
+#include "MCalibrationBlindPix.h"
+#endif
+
+#ifndef MARS_MCalibrationPINDiode
+#include "MCalibrationPINDiode.h"
+#endif
+
+#ifndef ROOT_TClonesArray
+#include <TClonesArray.h>
+#endif
+
+#ifndef ROOT_TH1F
+#include <TH1F.h>
+#endif
+
+#ifndef ROOT_TH1D
+#include <TH1D.h>
+#endif
+
+#ifndef ROOT_TH2D
+#include <TH2D.h>
+#endif
+
+class MGeomCam;
+class MCalibrationPix;
+class MCalibrationBlindPix;
+class MCalibrationPINDiode;
+
+class MCalibrationCam : public MCamEvent
+{
+private:
+  
+  Int_t fNumPixels;
+  TClonesArray *fPixels;                      // Array of MCalibrationPix with fit results
+  
+  MCalibrationBlindPix *fBlindPixel;          // Pointer to the Blind Pixel with fit results
+  MCalibrationPINDiode *fPINDiode;            // Pointer to the PIN Diode with fit results    
+
+  Bool_t  fNumPhotInsidePlexiglassAvailable;  // TRUE: Blind Pixel could have been fitted well 
+  Float_t fMeanPhotInsidePlexiglass;          //  The mean number of photons in an INNER PIXEL inside the plexiglass
+  Float_t fMeanPhotErrInsidePlexiglass;       //  The uncertainty about the number of photons in an INNER PIXEL  
+
+  Bool_t  fNumPhotOutsidePlexiglassAvailable; // TRUE: PIN Diode could have been fitted well 
+  Float_t fMeanPhotOutsidePlexiglass;         //  The mean number of photons in an INNER PIXEL outside the plexiglass
+  Float_t fMeanPhotErrOutsidePlexiglass;      //  The uncertainty about the number of photons in an INNER PIXEL  
+
+  TH1F* fHChargeAllPixels;                     //! 
+  TH1F* fHChargeErrAllPixels;                  //! 
+  TH1F* fHChargeSigmaAllPixels;                //! 
+  TH1F* fHChargeProbAllPixels;                 //! 
+
+  TH1F* fHTimeAllPixels;                       //! 
+  TH1F* fHTimeSigmaAllPixels;                  //! 
+  TH1F* fHTimeProbAllPixels;                   //! 
+
+  TH1F* fHPedAllPixels;                        //! 
+  TH1F* fHPedRMSAllPixels;                     //! 
+  TH1F* fHSigmaPerChargeAllPixels;             //! 
+  TH1F* fHPhEAllPixels;                        //! 
+
+  TH1F* fHConvPhEperFADCAllPixels;             //! 
+  TH1F* fHConvPhperFADCAllPixels;              //! 
+
+  TH1D* fOffsets;                              //! 
+  TH1D* fSlopes;                               //! 
+  
+  TH2D* fOffvsSlope;                           //! 
+
+public:
+  
+  enum CalibrationColor_t { kECGreen, kECBlue, kECUV, kECCT1 };
+
+private:
+
+  CalibrationColor_t fColor;  
+  
+public:
+
+  MCalibrationCam(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationCam();
+  
+  void Clear(Option_t *o="");
+  
+  void InitSize(const Int_t i);
+  Int_t GetSize() const;
+
+  UInt_t GetNumPixels() const { return fNumPixels; }
+
+  Bool_t IsPixelUsed(Int_t idx)      const;
+  Bool_t IsPixelFitted(Int_t idx)    const;
+  
+  MCalibrationPix &operator[](Int_t i);
+  MCalibrationPix &operator[](Int_t i) const;
+  
+  Bool_t CheckBounds(Int_t i) const;
+
+  void Print(Option_t *o="") const;
+  
+  void CutEdges();
+  
+  Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
+  void   DrawPixelContent(Int_t num) const;    
+  
+  MCalibrationBlindPix *GetBlindPixel()              const { return fBlindPixel;  }
+  MCalibrationPINDiode *GetPINDiode()                const { return fPINDiode;    }
+
+  void SetColor(CalibrationColor_t color)    { fColor = color; }
+
+  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);
+
+  Bool_t CalcNumPhotInsidePlexiglass();
+  Bool_t CalcNumPhotOutsidePlexiglass();
+
+  void DrawHiLoFits();
+
+  ClassDef(MCalibrationCam, 1)	// Storage Container for all calibration information of the camera
+};
+
+#endif
+
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationConfig.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationConfig.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationConfig.h	(revision 2734)
@@ -0,0 +1,96 @@
+#ifndef MARS_MCalibrationConfig
+#define MARS_MCalibrationConfig
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         
+// MCalibrationConfig                                                      
+//
+// Contains all configuration data of the Calibration          
+//                                                             
+// This file is only TEMPORARY. It values will go into the DATABASE 
+//
+/////////////////////////////////////////////////////////////////////////////
+
+
+// The highest value of the High Gain in the linear regime
+const Byte_t gkSaturationLimit = 250;
+
+// The conversion factor between High Gain and Low Gain
+const Float_t gkConversionHiLo      = 10.;
+const Float_t gkConversionHiLoError = 2.5;
+
+// The penalty constant to produce overflow in the histogram 
+const ULong_t gkLoGainOverFlow = 99999999;
+
+// ----- BLIND PIXEL ----------------------//
+
+// Pixel ID of the Calibration Blind Pixel
+const UShort_t gkCalibrationBlindPixelId = 559;
+
+// Average QE of Blind Pixel (three colours)
+const Float_t gkCalibrationBlindPixelQEGreen = 0.154;
+const Float_t gkCalibrationBlindPixelQEBlue  = 0.226;
+const Float_t gkCalibrationBlindPixelQEUV    = 0.247;
+const Float_t gkCalibrationBlindPixelQECT1   = 0.247;
+
+// Attenuation factor Blind Pixel (three colours)
+const Float_t gkCalibrationBlindPixelAttGreen = 1.97;
+const Float_t gkCalibrationBlindPixelAttBlue  = 1.96;
+const Float_t gkCalibrationBlindPixelAttUV    = 1.95;
+const Float_t gkCalibrationBlindPixelAttCT1   = 1.95;
+
+//
+// Area of Inner Pixel w.r.t. Blind Pixel (which is 1 sq. cm)
+//
+// Hexagone of diagonal axis b = 3.5 cm
+//             straight axis a = 3.0 cm +- 2% 
+// Area =  sqrt(3)*a*a/2 = 7.79 sq.cm +- 4% = 7.8 +- 0.3 sq.cm
+//
+const Float_t gkCalibrationInnerPixelArea      = 7.8;
+const Float_t gkCalibrationInnerPixelAreaError = 0.3;
+//
+// Area of Outer Pixel w.r.t. Inner Pixel
+//
+// Hexagone of diagonal axis b = 7.0 cm
+//             straight axis a = 6.0 cm +- 1% 
+// Area = sqrt(3)*a*a/2 = 
+//
+const Float_t gkCalibrationOutervsInnerPixelArea      = 4.00;
+const Float_t gkCalibrationOutervsInnerPixelAreaError = 0.00;
+
+// ----- PIN DIODE ------------------------//
+
+// Pixel ID of the Calibration PIN Diode
+const UShort_t gkCalibrationPINDiodeId = 9999;
+
+//
+// Area of Inner Pixel w.r.t. PIN Diode (which is 1 cm²)
+//
+// Hexagone of diagonal axis b = 3.5 cm
+//             straight axis a = 3.0 cm +- 2% 
+// Area =  sqrt(3)*a*a/2 = 7.79 sq.cm +- 4% = 7.8 +- 0.3 sq.cm
+//
+// Distance of PIN Diode to pulser D1:   1.5  +- 0.3 m
+// Distance of Inner Pixel to pulser D2: 18.0 +- 0.5 m
+//
+//
+//                A(Inner Pixel)    D1*D1
+// conversion C = -------------- * ------ = 0.054
+//                A(PIN Diode)      D2*D2
+//
+// Delta C / C  = sqrt((Delta A(IP)/A(IP))² + 4 * ( (Delta D1/D1)² + (Delta D2/D2)² )
+// Delta C / C  = 0.4
+// 
+// C = 0.05 +- 0.02
+//
+const Float_t gkCalibrationInnerPixelvsPINDiodeArea      = 0.05;
+const Float_t gkCalibrationInnerPixelvsPINDiodeAreaError = 0.02;
+
+// Average QE of the PIN Diode
+const Float_t gkCalibrationPINDiodeQEGreen = -1.0;
+const Float_t gkCalibrationPINDiodeQEBlue  = -1.0;
+const Float_t gkCalibrationPINDiodeQEUV    = -1.0;
+const Float_t gkCalibrationPINDiodeQECT1   = -1.0;
+
+
+#endif /* MARS_MCalibrationConfig */
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationFits.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationFits.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationFits.h	(revision 2734)
@@ -0,0 +1,310 @@
+#ifndef MARS_MCalibrationFits
+#define MARS_MCalibrationFits
+
+#ifndef ROOT_TMath
+#include <TMath.h>
+#endif
+
+#define GIMMEABREAK     10000000000.0
+
+inline Double_t gfKto5(Double_t *x, Double_t *par)
+{
+
+  Double_t lambda = par[0];  
+  
+  Double_t sum = 0.;
+  Double_t arg = 0.;
+
+  Double_t mu0 = par[1];
+  Double_t mu1 = par[2];
+
+  if (mu1 < mu0)
+    return GIMMEABREAK;
+
+  Double_t sigma0 = par[3];
+  Double_t sigma1 = par[4];
+
+  if (sigma1 < sigma0)
+    return GIMMEABREAK;
+
+
+  Double_t mu2 = (2.*mu1)-mu0;  
+  Double_t mu3 = (3.*mu1)-(2.*mu0);
+  Double_t mu4 = (4.*mu1)-(3.*mu0);
+  Double_t mu5 = (5.*mu1)-(4.*mu0);
+
+  Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));  
+  Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
+  Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
+  Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
+
+  Double_t lambda2 = lambda*lambda;
+  Double_t lambda3 = lambda2*lambda;
+  Double_t lambda4 = lambda3*lambda;
+  Double_t lambda5 = lambda4*lambda;
+
+  // k=0:
+  arg = (x[0] - mu0)/sigma0;
+  sum = TMath::Exp(-0.5*arg*arg)/sigma0;
+  
+  // k=1:
+  arg = (x[0] - mu1)/sigma1;
+  sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
+  
+  // k=2:
+  arg = (x[0] - mu2)/sigma2;
+  sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
+
+  // k=3:
+  arg = (x[0] - mu3)/sigma3;
+  sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
+
+  // k=4:
+  arg = (x[0] - mu4)/sigma4;
+  sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
+  
+  // k=5:
+  arg = (x[0] - mu5)/sigma5;
+  sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
+
+  return par[5]*sum;
+
+};
+
+inline Double_t gfKto6(Double_t *x, Double_t *par)
+{
+
+  Double_t lambda = par[0];  
+  
+  Double_t sum = 0.;
+  Double_t arg = 0.;
+
+  Double_t mu0 = par[1];
+  Double_t mu1 = par[2];
+
+  if (mu1 < mu0)
+    return GIMMEABREAK;
+
+  Double_t sigma0 = par[3];
+  Double_t sigma1 = par[4];
+
+  if (sigma1 < sigma0)
+    return GIMMEABREAK;
+
+
+  Double_t mu2 = (2.*mu1)-mu0;  
+  Double_t mu3 = (3.*mu1)-(2.*mu0);
+  Double_t mu4 = (4.*mu1)-(3.*mu0);
+  Double_t mu5 = (5.*mu1)-(4.*mu0);
+  Double_t mu6 = (6.*mu1)-(5.*mu0);
+
+  Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));  
+  Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
+  Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
+  Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
+  Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
+
+  Double_t lambda2 = lambda*lambda;
+  Double_t lambda3 = lambda2*lambda;
+  Double_t lambda4 = lambda3*lambda;
+  Double_t lambda5 = lambda4*lambda;
+  Double_t lambda6 = lambda5*lambda;
+  
+  // k=0:
+  arg = (x[0] - mu0)/sigma0;
+  sum = TMath::Exp(-0.5*arg*arg)/sigma0;
+  
+  // k=1:
+  arg = (x[0] - mu1)/sigma1;
+  sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
+  
+  // k=2:
+  arg = (x[0] - mu2)/sigma2;
+  sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
+
+  // k=3:
+  arg = (x[0] - mu3)/sigma3;
+  sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
+
+  // k=4:
+  arg = (x[0] - mu4)/sigma4;
+  sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
+  
+  // k=5:
+  arg = (x[0] - mu5)/sigma5;
+  sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
+
+  // k=6:
+  arg = (x[0] - mu6)/sigma6;
+  sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
+  
+  return par[5]*sum;
+
+};
+
+inline Double_t gfKto7(Double_t *x, Double_t *par)
+{
+
+  Double_t lambda = par[0];  
+  
+  Double_t sum = 0.;
+  Double_t arg = 0.;
+
+  Double_t mu0 = par[1];
+  Double_t mu1 = par[2];
+
+  if (mu1 < mu0)
+    return GIMMEABREAK;
+
+  Double_t sigma0 = par[3];
+  Double_t sigma1 = par[4];
+
+  if (sigma1 < sigma0)
+    return GIMMEABREAK;
+
+
+  Double_t mu2 = (2.*mu1)-mu0;  
+  Double_t mu3 = (3.*mu1)-(2.*mu0);
+  Double_t mu4 = (4.*mu1)-(3.*mu0);
+  Double_t mu5 = (5.*mu1)-(4.*mu0);
+  Double_t mu6 = (6.*mu1)-(5.*mu0);
+  Double_t mu7 = (7.*mu1)-(6.*mu0);
+  
+  Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));  
+  Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
+  Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
+  Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
+  Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
+  Double_t sigma7 = TMath::Sqrt((7.*sigma1*sigma1) - (6.*sigma0*sigma0));
+
+  Double_t lambda2 = lambda*lambda;
+  Double_t lambda3 = lambda2*lambda;
+  Double_t lambda4 = lambda3*lambda;
+  Double_t lambda5 = lambda4*lambda;
+  Double_t lambda6 = lambda5*lambda;
+  Double_t lambda7 = lambda6*lambda;
+  
+  // k=0:
+  arg = (x[0] - mu0)/sigma0;
+  sum = TMath::Exp(-0.5*arg*arg)/sigma0;
+  
+  // k=1:
+  arg = (x[0] - mu1)/sigma1;
+  sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
+  
+  // k=2:
+  arg = (x[0] - mu2)/sigma2;
+  sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
+
+  // k=3:
+  arg = (x[0] - mu3)/sigma3;
+  sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
+
+  // k=4:
+  arg = (x[0] - mu4)/sigma4;
+  sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
+  
+  // k=5:
+  arg = (x[0] - mu5)/sigma5;
+  sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
+
+  // k=6:
+  arg = (x[0] - mu6)/sigma6;
+  sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
+  
+  // k=7:
+  arg = (x[0] - mu7)/sigma7;
+  sum += 0.000198412698413*lambda7*TMath::Exp(-0.5*arg*arg)/sigma7;
+  
+  return par[5]*sum;
+
+};
+
+
+inline Double_t gfKto8(Double_t *x, Double_t *par)
+{
+
+  Double_t lambda = par[0];  
+  
+  Double_t sum = 0.;
+  Double_t arg = 0.;
+
+  Double_t mu0 = par[1];
+  Double_t mu1 = par[2];
+
+  if (mu1 < mu0)
+    return GIMMEABREAK;
+
+  Double_t sigma0 = par[3];
+  Double_t sigma1 = par[4];
+
+  if (sigma1 < sigma0)
+    return GIMMEABREAK;
+
+
+  Double_t mu2 = (2.*mu1)-mu0;  
+  Double_t mu3 = (3.*mu1)-(2.*mu0);
+  Double_t mu4 = (4.*mu1)-(3.*mu0);
+  Double_t mu5 = (5.*mu1)-(4.*mu0);
+  Double_t mu6 = (6.*mu1)-(5.*mu0);
+  Double_t mu7 = (7.*mu1)-(6.*mu0);
+  Double_t mu8 = (8.*mu1)-(7.*mu0);    
+  
+  Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));  
+  Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
+  Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
+  Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
+  Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
+  Double_t sigma7 = TMath::Sqrt((7.*sigma1*sigma1) - (6.*sigma0*sigma0));
+  Double_t sigma8 = TMath::Sqrt((8.*sigma1*sigma1) - (7.*sigma0*sigma0));          
+
+  Double_t lambda2 = lambda*lambda;
+  Double_t lambda3 = lambda2*lambda;
+  Double_t lambda4 = lambda3*lambda;
+  Double_t lambda5 = lambda4*lambda;
+  Double_t lambda6 = lambda5*lambda;
+  Double_t lambda7 = lambda6*lambda;
+  Double_t lambda8 = lambda7*lambda;
+  
+  // k=0:
+  arg = (x[0] - mu0)/sigma0;
+  sum = TMath::Exp(-0.5*arg*arg)/sigma0;
+  
+  // k=1:
+  arg = (x[0] - mu1)/sigma1;
+  sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
+  
+  // k=2:
+  arg = (x[0] - mu2)/sigma2;
+  sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
+
+  // k=3:
+  arg = (x[0] - mu3)/sigma3;
+  sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
+
+  // k=4:
+  arg = (x[0] - mu4)/sigma4;
+  sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
+  
+  // k=5:
+  arg = (x[0] - mu5)/sigma5;
+  sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
+
+  // k=6:
+  arg = (x[0] - mu6)/sigma6;
+  sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
+  
+  // k=7:
+  arg = (x[0] - mu7)/sigma7;
+  sum += 0.000198412698413*lambda7*TMath::Exp(-0.5*arg*arg)/sigma7;
+  
+  // k=8:
+  arg = (x[0] - mu8)/sigma8;
+  sum += 0.000024801587315*lambda8*TMath::Exp(-0.5*arg*arg)/sigma7;
+  
+  return par[5]*sum;
+
+};
+
+#endif  /* MARS_MCalibrationFits */
+
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.cc	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.cc	(revision 2734)
@@ -0,0 +1,102 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MCalibrationPINDiode                                                            //
+//                                                                         //
+// This is the storage container to hold informations about the pedestal   //
+// (offset) value of one Pixel (PMT).                                      //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationPINDiode.h"
+
+#include "MLog.h"
+
+ClassImp(MCalibrationPINDiode);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default Constructor. 
+//
+MCalibrationPINDiode::MCalibrationPINDiode(const char *name, const char *title)
+  : fHist(NULL),
+    fCharge(-1.),
+    fErrCharge(-1.),
+    fPed(-1.),
+    fPedRms(-1.),
+    fSigmaCharge(-1.),
+    fErrSigmaCharge(-1.),
+    fTime(-1.),
+    fErrTime(-1.)
+{
+
+  fName  = name  ? name  : "MCalibrationPINDiode";
+  fTitle = title ? title : "Container of the MHCalibrationPINDiode and the fit results";
+
+  fHist = new MHCalibrationPINDiode();
+
+}
+
+MCalibrationPINDiode::~MCalibrationPINDiode() 
+{
+  delete fHist;
+}
+
+// ------------------------------------------------------------------------
+//
+// Invalidate values
+//
+void MCalibrationPINDiode::Clear(Option_t *o)
+{
+  fHist->Reset();
+}
+
+Bool_t MCalibrationPINDiode::FitCharge() 
+{
+  if(!fHist->FitChargeHiGain())
+    return kFALSE;
+
+  fCharge         = fHist->GetChargeMean();
+  fErrCharge      = fHist->GetChargeMeanErr(); 
+  fSigmaCharge    = fHist->GetChargeSigma();
+  fErrSigmaCharge = fHist->GetChargeSigmaErr();
+
+  return kTRUE;
+  
+}
+
+Bool_t MCalibrationPINDiode::FitTime() 
+{
+
+  if(!fHist->FitTimeHiGain())
+    return kFALSE;
+
+  fTime    = fHist->GetTime();
+  fErrTime = fHist->GetErrTime();
+  
+  return kTRUE;
+
+}
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h	(revision 2734)
@@ -0,0 +1,53 @@
+#ifndef MARS_MCalibrationPINDiode
+#define MARS_MCalibrationPINDiode
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#include "MHCalibrationPINDiode.h"
+
+class MCalibrationPINDiode : public MParContainer
+{
+private:
+
+  MHCalibrationPINDiode *fHist; // Pointer to the histograms performing the fits, etc.  
+  
+  Float_t fCharge;                // The mean charge after the fit
+  Float_t fErrCharge;             // The error of mean charge after the fit
+  Float_t fPed;              // The mean pedestal (from MPedestalPix)
+  Float_t fPedRms;           // The pedestal  RMS (from MPedestalPix)
+  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 fTime;                // The mean arrival time after the fit  
+  Float_t fErrTime;             // The error of the mean arrival time after the fit
+  
+public:
+
+  MCalibrationPINDiode(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationPINDiode();
+  
+  void Clear(Option_t *o="");
+  
+  void SetPed(Float_t ped)          { fPed      = ped;      } 
+  void SetPedRms(Float_t pedrms)    { fPedRms   = pedrms; }
+
+  Float_t GetMean()           const { return fCharge; }
+  Float_t GetMeanError()      const { return fErrCharge; }
+
+  Bool_t IsFitOK() const            { return fCharge > 0 && fErrCharge > 0; }
+
+  Bool_t FillCharge(Float_t q)      { return fHist->FillChargeHiGain(q); }
+  Bool_t FillTime(Int_t t)          { return fHist->FillTimeHiGain(t); }  
+  Bool_t FillRChargevsTime(Float_t rq, Int_t t) { return fHist->FillChargevsNHiGain(rq,t); }    
+  
+  Bool_t FitCharge();
+  Bool_t FitTime();
+  
+  MHCalibrationPINDiode *GetHist()  const  { return fHist;  }
+  
+  ClassDef(MCalibrationPINDiode, 1)	// Storage Container for Calibration information of one pixel
+};
+
+#endif   /* MARS_MCalibrationPINDiode */
+
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc	(revision 2734)
@@ -0,0 +1,436 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MCalibrationPix                                                         //
+//                                                                         //
+// This is the storage container to hold informations about the pedestal   //
+// (offset) value of one Pixel (PMT).                                      //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationPix.h"
+#include "MCalibrationConfig.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MCalibrationPix);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. 
+//
+MCalibrationPix::MCalibrationPix(const char *name, const char *title)
+    : fPixId(-1),
+      fCharge(-1.),
+      fErrCharge(-1.),
+      fSigmaCharge(-1.),
+      fErrSigmaCharge(-1.),
+      fRSigmaSquare(-1.),
+      fChargeProb(-1.),
+      fPed(-1.),
+      fPedRms(-1.),
+      fErrPedRms(0.),
+      fElectronicPedRms(1.5),
+      fErrElectronicPedRms(0.3),
+      fTime(-1.),
+      fSigmaTime(-1.),
+      fTimeChiSquare(-1.),
+      fFactor(1.3),
+      fPheFFactorMethod(-1.),
+      fConversionFFactorMethod(-1.),
+      fConversionBlindPixelMethod(-1.),
+      fConversionPINDiodeMethod(-1.),
+      fConversionErrorFFactorMethod(-1.),
+      fConversionErrorBlindPixelMethod(-1.),
+      fConversionErrorPINDiodeMethod(-1.),
+      fConversionSigmaFFactorMethod(-1.),
+      fConversionSigmaBlindPixelMethod(-1.),
+      fConversionSigmaPINDiodeMethod(-1.),
+      fHiGainSaturation(kFALSE),
+      fFitValid(kFALSE),        
+      fFitted(kFALSE), 
+      fBlindPixelMethodValid(kFALSE),
+      fFFactorMethodValid(kFALSE),
+      fPINDiodeMethodValid(kFALSE)
+{
+
+  fName  = name  ? name  : "MCalibrationPixel";
+  fTitle = title ? title : "Container of the MHCalibrationPixels and the fit results";
+
+  //
+  // At the moment, we don't have a database, yet, 
+  // so we get it from the configuration file
+  //
+  fConversionHiLo      = gkConversionHiLo;
+  fConversionHiLoError = gkConversionHiLoError;  
+
+  fHist = new MHCalibrationPixel("MHCalibrationPixel","Calibration Histograms Pixel ");
+
+}
+
+MCalibrationPix::~MCalibrationPix() 
+{
+  delete fHist;
+}
+
+
+void MCalibrationPix::DefinePixId(Int_t i)
+{
+  
+  fPixId = i;
+  fHist->ChangeHistId(i);
+  
+}
+
+
+// ------------------------------------------------------------------------
+//
+// Invalidate values
+//
+void MCalibrationPix::Clear(Option_t *o)
+{
+  fHist->Reset();
+}
+
+
+// --------------------------------------------------------------------------
+//
+// 1) Return if the charge distribution is already succesfully fitted  
+// 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid 
+//    possible remaining cosmics to spoil the fit.
+// 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
+// 4) Fit the histograms with a Gaussian
+// 5) In case of failure print out the fit results
+// 6) Retrieve the results and store them in this class
+// 7) Calculate the number of photo-electrons after the F-Factor method
+// 8) Calculate the errors of the F-Factor method
+//
+// The fit is declared valid (fFitValid = kTRUE), if:
+//
+// 1) Pixel has a fitted charge greater than 3*PedRMS
+// 2) Pixel has a fit error greater than 0.
+// 3) Pixel has a fit Probability greater than 0.0001 
+// 4) Pixel has a charge sigma bigger than its Pedestal RMS
+// 5) If FitTimes is used, 
+//    the mean arrival time is at least 1.0 slices from the used edge slices 
+// 
+// The conversion factor after the F-Factor method is declared valid, if:
+//
+// 1) fFitValid is kTRUE
+// 2) Conversion Factor is bigger than 0.
+// 3) The error of the conversion factor is smaller than 10%
+//
+Bool_t MCalibrationPix::FitCharge() 
+{
+
+  //
+  // 1) Return if the charge distribution is already succesfully fitted  
+  //
+  if (fHist->IsFitOK())
+    return kTRUE;
+
+  //
+  // 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid 
+  //    possible remaining cosmics to spoil the fit.
+  //
+  if (fPed && fPedRms)
+    fHist->SetLowerFitRange(1.5*fPedRms);
+  else
+    *fLog << warn << "Cannot set lower fit range: Pedestals not available" << endl;
+
+  //
+  // 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
+  //
+  if (fHist->UseLoGain())
+    {
+
+      SetHiGainSaturation();
+      
+      //
+      // 4) Fit the Lo Gain histograms with a Gaussian
+      //
+      if(!fHist->FitChargeLoGain())
+	{
+	  *fLog << warn << "Could not fit Lo Gain charges of pixel " << fPixId << endl;
+          //          
+          // 5) In case of failure print out the fit results
+          //
+	  fHist->PrintChargeFitResult();
+	}
+    }
+  else 
+    {
+      //
+      // 4) Fit the Hi Gain histograms with a Gaussian
+      //
+      if(!fHist->FitChargeHiGain())
+	{
+	  *fLog << warn << "Could not fit Hi Gain charges of pixel " << fPixId << endl;
+          //          
+          // 5) In case of failure print out the fit results
+          //
+	  fHist->PrintChargeFitResult();
+	}
+    }
+  
+
+  //
+  // 6) Retrieve the results and store them in this class
+  //
+  fCharge         = fHist->GetChargeMean();
+  fErrCharge      = fHist->GetChargeMeanErr(); 
+  fSigmaCharge    = fHist->GetChargeSigma();
+  fErrSigmaCharge = fHist->GetChargeSigmaErr();
+  fChargeProb     = fHist->GetChargeProb();
+
+  if (fCharge <= 0.)
+    {
+      *fLog << warn << "Cannot apply calibration: Mean Fitted Charges are smaller than 0 in pixel " 
+            << fPixId << endl;
+      return kFALSE;
+    }
+
+  if (fErrCharge > 0.) 
+    fFitted = kTRUE;
+
+
+  if (fHiGainSaturation)
+    {
+      if ( (fCharge     > 0.3*GetPedRms()) &&
+          (fErrCharge  > 0.)              &&
+          (fHist->IsFitOK())              &&
+          (fSigmaCharge > fPedRms/fConversionHiLo)   &&
+          (fTime > fHist->GetTimeLowerFitRange()+1.) &&
+          (fTime < fHist->GetTimeUpperFitRange()-1.) )
+        fFitValid =  kTRUE;
+    }
+  else
+    {
+      if ( (fCharge > 3.*GetPedRms()) &&
+           (fErrCharge  > 0.)        &&
+           (fHist->IsFitOK())        &&
+           (fSigmaCharge > fPedRms)  &&
+           (fTime > fHist->GetTimeLowerFitRange()+1.) &&
+           (fTime < fHist->GetTimeUpperFitRange()-1.) )
+        fFitValid =  kTRUE;
+    }
+  
+  //
+  // 7) Calculate the number of photo-electrons after the F-Factor method
+  // 8) Calculate the errors of the F-Factor method
+  //
+  if ((fPed > 0.)  && (fPedRms > 0.))
+    {
+      
+      //
+      // Square all variables in order to avoid applications of square root
+      //
+      // First the relative error squares
+      //
+      const Float_t chargeSquare              =       fCharge*   fCharge;
+      const Float_t chargeSquareRelErrSquare  = 4.*fErrCharge*fErrCharge / chargeSquare;
+
+      const Float_t fFactorRelErrSquare       = fFactorError * fFactorError / (fFactor * fFactor);
+      //
+      // Now the absolute error squares
+      //
+      const Float_t sigmaSquare               =       fSigmaCharge*   fSigmaCharge;
+      const Float_t sigmaSquareErrSquare      = 4.*fErrSigmaCharge*fErrSigmaCharge * sigmaSquare;
+
+      const Float_t elecRmsSquare             =       fElectronicPedRms*   fElectronicPedRms;
+      const Float_t elecRmsSquareErrSquare    = 4.*fErrElectronicPedRms*fErrElectronicPedRms * elecRmsSquare;
+
+      Float_t pedRmsSquare                    =       fPedRms*   fPedRms;
+      Float_t pedRmsSquareErrSquare           = 4.*fErrPedRms*fErrPedRms * pedRmsSquare;
+
+      if (fHiGainSaturation)
+	{
+          
+          //
+          // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it 
+          // from the Hi Gain: 
+          //
+          // We extract the pure NSB contribution:
+          //
+          Float_t nsbSquare             =  pedRmsSquare          - elecRmsSquare;
+          Float_t nsbSquareRelErrSquare = (pedRmsSquareErrSquare + elecRmsSquareErrSquare)
+                                          / (nsbSquare * nsbSquare) ;
+
+	  if (nsbSquare < 0.)
+            nsbSquare = 0.;
+          
+          //
+          // Now, we divide the NSB by the conversion factor and 
+          // add it quadratically to the electronic noise
+          //
+          const Float_t conversionSquare             =    fConversionHiLo     *fConversionHiLo;
+          const Float_t conversionSquareRelErrSquare = 4.*fConversionHiLoError*fConversionHiLoError/conversionSquare;
+
+          //
+          // Calculate the new "Pedestal RMS"
+          //
+          const Float_t convertedNsbSquare          =  nsbSquare             / conversionSquare;
+          const Float_t convertedNsbSquareErrSquare = (nsbSquareRelErrSquare + conversionSquareRelErrSquare)
+                                                      * convertedNsbSquare * convertedNsbSquare;
+
+          pedRmsSquare           = convertedNsbSquare           + elecRmsSquare;
+          pedRmsSquareErrSquare  = convertedNsbSquareErrSquare  + elecRmsSquareErrSquare;
+          
+	}    /* if (fHiGainSaturation) */
+      
+      //
+      // Calculate the reduced sigmas
+      //
+      fRSigmaSquare = sigmaSquare - pedRmsSquare;
+      if (fRSigmaSquare <= 0.)
+        {
+          *fLog << warn << "Cannot apply F-Factor calibration: Reduced Sigma smaller than 0 in pixel " 
+                << fPixId << endl;
+          if (fHiGainSaturation)
+            ApplyLoGainConversion();
+          return kFALSE;
+        }
+
+      const Float_t rSigmaSquareRelErrSquare = (sigmaSquareErrSquare + pedRmsSquareErrSquare)
+        / (fRSigmaSquare * fRSigmaSquare) ;
+  
+      //
+      // Calculate the number of phe's from the F-Factor method
+      // (independent on Hi Gain or Lo Gain)
+      //
+      fPheFFactorMethod = fFactor * chargeSquare / fRSigmaSquare;
+
+      const Float_t pheFFactorRelErrSquare =  fFactorRelErrSquare
+                                            + chargeSquareRelErrSquare
+                                            + rSigmaSquareRelErrSquare ;
+          
+      fPheFFactorMethodError        =  TMath::Sqrt(pheFFactorRelErrSquare) * fPheFFactorMethod;
+
+      //
+      // Calculate the conversion factors 
+      //
+      if (fHiGainSaturation)
+        ApplyLoGainConversion();
+      
+      const Float_t chargeRelErrSquare = fErrCharge*fErrCharge / (fCharge * fCharge);
+      
+      fConversionFFactorMethod        =  fPheFFactorMethod / fCharge ;
+      fConversionErrorFFactorMethod   =  ( pheFFactorRelErrSquare + chargeRelErrSquare )
+                                         * fConversionFFactorMethod * fConversionFFactorMethod;
+      
+      if ( IsFitValid()                     &&
+           (fConversionFFactorMethod > 0.) &&
+           (fConversionErrorFFactorMethod/fConversionFFactorMethod < 0.1) )
+        fFFactorMethodValid = kTRUE;
+      
+      
+    } /*   if ((fPed > 0.)  && (fPedRms > 0.)) */
+
+  return kTRUE;
+  
+}
+
+
+void MCalibrationPix::ApplyLoGainConversion()
+{
+  
+  const Float_t chargeRelErrSquare     =   fErrCharge*fErrCharge
+                                         /(   fCharge *  fCharge);
+  const Float_t sigmaRelErrSquare      =   fErrSigmaCharge*fErrSigmaCharge
+                                         /(   fSigmaCharge *  fSigmaCharge);
+  const Float_t conversionRelErrSquare =   fConversionHiLoError*fConversionHiLoError 
+                                         /(fConversionHiLo    * fConversionHiLo);
+  
+  fCharge         *= fConversionHiLo;
+  fErrCharge       = TMath::Sqrt(chargeRelErrSquare + conversionRelErrSquare) * fCharge;
+  
+  fSigmaCharge    *= fConversionHiLo;
+  fErrSigmaCharge =  TMath::Sqrt(sigmaRelErrSquare + conversionRelErrSquare) * fSigmaCharge;
+  
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Set the pedestals from outside
+//
+void MCalibrationPix::SetPedestal(Float_t ped, Float_t pedrms)
+{
+
+  fPed    = ped;    
+  fPedRms = pedrms;
+  
+}
+
+// --------------------------------------------------------------------------
+//
+// 1) Fit the arrival times
+// 2) Retrieve the results
+// 3) Note that because of the low number of bins, the NDf is sometimes 0, so 
+//    Root does not give a reasonable Probability, the Chisquare is more significant
+//
+// This fit has to be done AFTER the Charges fit, 
+// otherwise only the Hi Gain will be fitted, even if there are no entries
+//
+// 
+Bool_t MCalibrationPix::FitTime() 
+{
+
+  //
+  // Fit the Low Gain
+  //
+  if (fHiGainSaturation)
+    {
+      if(!fHist->FitTimeLoGain())
+	{
+	  *fLog << warn << "Could not fit Lo Gain times of pixel " << fPixId << endl;
+	  fHist->PrintTimeFitResult();
+	  return kFALSE;
+	}
+    }
+
+  //
+  // Fit the High Gain
+  //
+  else
+    {
+      if(!fHist->FitTimeHiGain())
+	{
+	  *fLog << warn << "Could not fit Hi Gain times of pixel " << fPixId << endl;
+	  fHist->PrintTimeFitResult();
+	  return kFALSE;
+	}
+    }
+    
+  fTime          = fHist->GetTimeMean();
+  fSigmaTime     = fHist->GetTimeSigma();
+  fTimeChiSquare = fHist->GetTimeChiSquare();
+
+  return kTRUE;
+}
+
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h	(revision 2734)
@@ -0,0 +1,172 @@
+#ifndef MARS_MCalibrationPix
+#define MARS_MCalibrationPix
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#include "MHCalibrationPixel.h"
+
+class MCalibrationPix : public MParContainer
+{
+private:
+
+  Int_t   fPixId;                        // the pixel Id
+  
+  Float_t fCharge;                       // The mean reduced charge after the fit
+  Float_t fErrCharge;                    // The error of reduced mean charge after the fit
+  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 fRSigmaSquare;                 // The reduced squares of sigmas after the fit
+  Float_t fChargeProb;                   // The probability of the fit function 
+
+  Float_t fPed;                          // The mean pedestal (from MPedestalPix)
+  Float_t fPedRms;                       // The pedestal  RMS (from MPedestalPix)
+  Float_t fErrPedRms;                    // The error of the pedestal  RMS (from MPedestalPix)  
+  Float_t fElectronicPedRms;             // The pure electronic component of the RMS
+  Float_t fErrElectronicPedRms;          // The error of the pure electronic component of the RMS
+
+  Float_t fTime;                         // The mean arrival time after the fit  
+  Float_t fSigmaTime;                    // The error of the mean arrival time after the fit
+  Float_t fTimeChiSquare;                // The probability of the fit function 
+  
+  Float_t fFactor;                       // The laboratory F-factor
+  Float_t fFactorError;                  // The laboratory F-factor Error
+  Float_t fPheFFactorMethod;             // The number of Phe's calculated (F-factor method)
+  Float_t fPheFFactorMethodError;        // The error on the number of Phe's calculated (F-factor method)
+
+  Float_t fConversionFFactorMethod;      // The conversion factor to Phe's (F-factor method)
+  Float_t fConversionBlindPixelMethod;   // The conversion factor to Ph's (Blind Pixel method)
+  Float_t fConversionPINDiodeMethod;     // The conversion factor to Ph's (PIN Diode method)
+
+  Float_t fConversionErrorFFactorMethod;    // The error of the conversion factor to Phe's (F-factor method)
+  Float_t fConversionErrorBlindPixelMethod; // The error of the conversion factor to Ph's (Blind Pixel method)
+  Float_t fConversionErrorPINDiodeMethod;   // The error of the conversion factor to Ph's (PIN Diode method)
+
+  Float_t fConversionSigmaFFactorMethod;    // The sigma of conversion factor to Ph's (F-factor method)
+  Float_t fConversionSigmaBlindPixelMethod; // The conversion factor to Ph's (Blind Pixel method)
+  Float_t fConversionSigmaPINDiodeMethod;   // The conversion factor to Phd's (PIN Diode method)
+
+  Float_t fConversionHiLo;                  // The conversion factor between Hi Gain and Lo Gain  
+  Float_t fConversionHiLoError;             // The error of the conversion factor between Hi Gain and Lo Gain  
+  
+  Bool_t  fHiGainSaturation;                // Is Lo-Gain used at all?
+
+  Bool_t  fFitValid;        
+  Bool_t  fFitted; 
+  Bool_t  fBlindPixelMethodValid;
+  Bool_t  fFFactorMethodValid;
+  Bool_t  fPINDiodeMethodValid;
+  
+  MHCalibrationPixel *fHist;    //! Pointer to the histograms performing the fits, etc.  
+  
+public:
+
+  MCalibrationPix(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationPix();
+  
+  void Clear(Option_t *o="");
+
+  // Getter
+  Bool_t IsFitValid()              const { return fFitValid;  }
+  Bool_t IsFitted()                const { return fFitted;  }
+  Bool_t IsBlindPixelMethodValid() const { return fBlindPixelMethodValid;  }
+  Bool_t IsFFactorMethodValid()    const { return fFFactorMethodValid;  }
+  Bool_t IsPINDiodeMethodValid()   const { return fPINDiodeMethodValid;  }
+
+  Float_t GetCharge()              const { return fCharge;         }
+  Float_t GetRSigmaSquare()        const { return fRSigmaSquare;   }
+    
+  Float_t GetErrCharge()           const { return fErrCharge;      }
+  Float_t GetChargeProb()          const { return fChargeProb;     }    
+  
+  Float_t GetSigmaCharge()         const { return fSigmaCharge;    }
+  Float_t GetErrSigmaCharge()      const { return fErrSigmaCharge; }
+  Float_t GetTime()                const { return fTime;           }
+  Float_t GetSigmaTime()           const { return fSigmaTime;      }
+  Float_t GetTimeChiSquare()       const { return fTimeChiSquare;  }    
+
+  Float_t GetConversionHiLo()                 const  { return fConversionHiLo;        }
+  Float_t GetConversionHiLoError()            const  { return fConversionHiLoError;   }
+
+  Float_t GetMeanConversionBlindPixelMethod()  const { return fConversionBlindPixelMethod ; }
+  Float_t GetErrorConversionBlindPixelMethod() const { return fConversionErrorBlindPixelMethod ; }
+  Float_t GetSigmaConversionBlindPixelMethod() const { return fConversionSigmaBlindPixelMethod ; }
+
+  Float_t GetMeanConversionFFactorMethod()     const { return fConversionFFactorMethod ;       }
+  Float_t GetErrorConversionFFactorMethod()    const { return fConversionErrorFFactorMethod ;  }
+  Float_t GetSigmaConversionFFactorMethod()    const { return fConversionSigmaFFactorMethod ;  }
+
+  Float_t GetPheFFactorMethod()                const { return fPheFFactorMethod;               }
+  Float_t GetPheFFactorMethodError()           const { return fPheFFactorMethodError;          }
+
+  Float_t GetMeanConversionPINDiodeMethod()    const { return fConversionPINDiodeMethod ;      }
+  Float_t GetErrorConversionPINDiodeMethod()   const { return fConversionErrorPINDiodeMethod ; }
+  Float_t GetSigmaConversionPINDiodeMethod()   const { return fConversionSigmaPINDiodeMethod ; }
+
+  // FIXME: Remove this from stored data members
+  Float_t GetPed()    const { return fPed;    }
+  Float_t GetPedRms() const { return fPedRms; }
+
+  // Setter
+  void SetPedestal(Float_t ped, Float_t pedrms);
+  void SetHiGainSaturation()             { fHiGainSaturation = kTRUE; fHist->SetUseLoGain(); }
+
+  void SetConversionHiLo(Float_t c)      { fConversionHiLo      = c;    }
+  void SetConversionHiLoError(Float_t e) { fConversionHiLoError = e;    }
+
+  void SetConversionFFactorMethod(Float_t c, Float_t err, Float_t sig)
+  {
+      fConversionFFactorMethod = c;
+      fConversionErrorFFactorMethod = err;
+      fConversionSigmaFFactorMethod = sig;
+  }
+  void SetConversionBlindPixelMethod(Float_t c, Float_t err, Float_t sig)
+  {
+      fConversionBlindPixelMethod = c;
+      fConversionErrorBlindPixelMethod = err;
+      fConversionSigmaBlindPixelMethod = sig;
+  }
+
+  void SetConversionPINDiodeMethod(Float_t c, Float_t err, Float_t sig)
+  {
+      fConversionPINDiodeMethod = c ;
+      fConversionErrorPINDiodeMethod = err;
+      fConversionSigmaPINDiodeMethod = sig;
+  }
+
+  void SetFitValid()                            { fFitValid = kTRUE;  }
+  void SetFitted()                              { fFitted = kTRUE;  }
+  void SetBlindPixelMethodValid(Bool_t b=kTRUE) { fBlindPixelMethodValid = b;  }
+  void SetFFactorMethodValid(Bool_t b=kTRUE)    { fFFactorMethodValid = b;  }
+  void SetPINDiodeMethodValid(Bool_t b=kTRUE)   { fPINDiodeMethodValid = b;  }
+
+  // Unknown
+  void   ApplyLoGainConversion();
+
+  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 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); }    
+  
+  // FIXME: Not necessary -> pixidx (not id anyhow!) == index in array!
+  //        Only needed n histograms which have to move to an MH-class anyhow!
+  Int_t  GetPixId()                              const  { return fPixId;   }
+  void   DefinePixId(Int_t i);
+  
+  Bool_t FitCharge();
+  Bool_t FitTime();
+  
+  MHCalibrationPixel *GetHist() const   { return fHist;     }
+  void Draw(Option_t *opt="")           { fHist->Draw(opt); }
+  
+  ClassDef(MCalibrationPix, 1)	// Storage Container for Calibration information of one pixel
+};
+
+#endif
+
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc	(revision 2734)
@@ -0,0 +1,484 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug 11/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//  MHCalibrationBlindPixel                                                 //
+//                                                                          //
+//  Performs all the necessary fits to extract the mean number of photons   //
+//              out of the derived light flux                               //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+#include "MHCalibrationBlindPixel.h"
+#include "MHCalibrationConfig.h"
+#include "MCalibrationFits.h"
+
+#include <TStyle.h>
+#include <TMath.h>
+#include <TPad.h>
+
+#include <TMinuit.h>
+#include <TFitter.h>
+
+#include <TF1.h>
+#include <TH2.h>
+#include <TCanvas.h>
+#include <TPaveText.h>
+#include <TRandom.h>
+
+#include "MBinning.h"
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MHCalibrationBlindPixel);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default Constructor. 
+//
+MHCalibrationBlindPixel::MHCalibrationBlindPixel(const char *name, const char *title)
+  : 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.)
+{
+
+    fName  = name  ? name  : "MHCalibrationBlindPixel";
+    fTitle = title ? title : "Fill the accumulated charges and times all Blind Pixel events and perform fits";
+
+    // Create a large number of bins, later we will rebin
+    fBlindPixelChargefirst = -1000.;
+    fBlindPixelChargelast  = gkStartBlindPixelBinNr;
+    fBlindPixelChargenbins = gkStartBlindPixelBinNr+(int)fBlindPixelChargefirst;
+
+    fHBlindPixelCharge = new TH1F("HBlindPixelCharge","Distribution of Summed FADC Slices",
+				  fBlindPixelChargenbins,fBlindPixelChargefirst,fBlindPixelChargelast);
+    fHBlindPixelCharge->SetXTitle("Sum FADC Slices");
+    fHBlindPixelCharge->SetYTitle("Nr. of events");
+    fHBlindPixelCharge->Sumw2();
+
+    Axis_t tfirst = -0.5;
+    Axis_t tlast  = 15.5;
+    Int_t nbins   = 16;
+
+    fHBlindPixelTime = new TH1I("HBlindPixelTime","Distribution of Mean Arrival Times",nbins,tfirst,tlast);
+    fHBlindPixelTime->SetXTitle("Mean Arrival Times [FADC slice nr]");
+    fHBlindPixelTime->SetYTitle("Nr. of events");
+    fHBlindPixelTime->Sumw2();
+
+    // We define a reasonable number and later enlarge it if necessary
+    nbins = 20000;
+    Axis_t nfirst = -0.5;
+    Axis_t nlast  = (Axis_t)nbins - 0.5;
+
+    fHBlindPixelChargevsN = new TH1I("HBlindPixelChargevsN","Sum of Charges vs. Event Number",nbins,nfirst,nlast);
+    fHBlindPixelChargevsN->SetXTitle("Event Nr.");
+    fHBlindPixelChargevsN->SetYTitle("Sum of FADC slices");
+
+    fgSinglePheFitFunc = &gfKto8;
+    fgSinglePheFitNPar = 5;
+}
+
+MHCalibrationBlindPixel::~MHCalibrationBlindPixel()
+{
+
+  delete fHBlindPixelCharge;
+  delete fHBlindPixelTime;
+
+  if (fSinglePheFit)
+    delete fSinglePheFit;
+  if (fSinglePhePedFit)
+    delete fSinglePhePedFit;
+  if (fTimeGausFit)
+    delete fTimeGausFit;
+}
+
+
+
+void MHCalibrationBlindPixel::ResetBin(Int_t i)
+{
+    fHBlindPixelCharge->SetBinContent (i, 1.e-20);
+    fHBlindPixelTime->SetBinContent(i, 1.e-20);
+}
+
+
+// -------------------------------------------------------------------------
+//
+// Draw a legend with the fit results
+//
+void MHCalibrationBlindPixel::DrawLegend()
+{
+
+  fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
+
+  if (fFitOK) 
+      fFitLegend->SetFillColor(80);
+  else
+      fFitLegend->SetFillColor(2);    
+  
+  fFitLegend->SetLabel("Results of the single PhE Fit (to k=6):");
+  fFitLegend->SetTextSize(0.05);
+
+  const TString line1 = 
+  Form("Mean: #lambda = %2.2f #pm %2.2f",GetLambda(),GetLambdaErr());
+  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());
+  fFitLegend->AddText(line2);
+
+  const TString line3 =
+  Form("Width Pedestal: #sigma_{0} = %2.2f #pm %2.2f",GetSigma0(),GetSigma0Err());
+  fFitLegend->AddText(line3);
+
+  const TString line4 =
+  Form("1^{st} Phe-peak: #mu_{1} = %2.2f #pm %2.2f",GetMu1(),GetMu1Err());
+  fFitLegend->AddText(line4);
+
+  const TString line5 =
+  Form("Width 1^{st} Phe-peak: #sigma_{1} = %2.2f #pm %2.2f",GetSigma1(),GetSigma1Err());
+  fFitLegend->AddText(line5);
+
+  const TString line7 =
+  Form("#chi^{2} / N_{dof}: %4.2f / %3i",GetChiSquare(),GetNdf());
+  fFitLegend->AddText(line7);
+
+  const TString line8 =
+  Form("Probability: %4.2f ",GetProb());
+  fFitLegend->AddText(line8);
+
+  if (fFitOK)
+    fFitLegend->AddText("Result of the Fit: OK");
+  else
+    fFitLegend->AddText("Result of the Fit: NOT OK");
+
+  fFitLegend->SetBit(kCanDelete);
+  fFitLegend->Draw();
+
+}
+
+
+// -------------------------------------------------------------------------
+//
+// Draw the histogram
+//
+void MHCalibrationBlindPixel::Draw(Option_t *opt) 
+{
+
+    gStyle->SetOptFit(0);
+    gStyle->SetOptStat(1111111);
+
+    TCanvas *c = MakeDefCanvas(this,550,700);
+
+    c->Divide(2,2);
+
+    gROOT->SetSelectedPad(NULL);
+
+    c->cd(1);
+    gPad->SetLogy(1);
+    gPad->SetTicks();
+
+    fHBlindPixelCharge->DrawCopy(opt);
+    
+    if (fSinglePheFit)
+      {
+        if (fFitOK)
+	  fSinglePheFit->SetLineColor(kGreen);          
+        else
+          fSinglePheFit->SetLineColor(kRed);
+
+        fSinglePheFit->DrawCopy("same");
+        c->Modified();
+        c->Update();
+
+	if (fSinglePhePedFit)
+	  {
+	    fSinglePhePedFit->SetLineColor(kBlue);
+	    fSinglePhePedFit->DrawCopy("same");
+	  }
+      }
+
+
+    c->cd(2);
+    DrawLegend();
+    c->Modified();
+    c->Update();
+
+    c->cd(3);
+    gPad->SetLogy(1);
+    gPad->SetBorderMode(0);
+    fHBlindPixelTime->DrawCopy(opt);
+
+    if (fHBlindPixelTime->GetFunction("GausTime"))
+      {
+        TF1 *tfit = fHBlindPixelTime->GetFunction("GausTime");
+        if (tfit->GetProb() < 0.01)
+          tfit->SetLineColor(kRed);
+        else
+          tfit->SetLineColor(kGreen);
+
+        tfit->DrawCopy("same");
+        c->Modified();
+        c->Update();
+      }
+    
+    c->cd(4);
+
+    fHBlindPixelChargevsN->DrawCopy(opt);
+
+    c->Modified();
+    c->Update();
+}
+
+
+
+Bool_t MHCalibrationBlindPixel::SimulateSinglePhe(Double_t lambda, Double_t mu0, Double_t mu1, Double_t sigma0, Double_t sigma1) 
+{
+  gRandom->SetSeed();
+
+  if (fHBlindPixelCharge->GetIntegral() != 0)
+    {
+      *fLog << err << "Histogram " << fHBlindPixelCharge->GetTitle() << " is already filled. " << endl;
+      *fLog << err << "Create new class MHCalibrationBlindPixel for simulation! " << endl;
+      return kFALSE;
+    }
+  
+  TF1 *simulateSinglePhe = new TF1("simulateSinglePhe",fgSinglePheFitFunc,
+                                   fBlindPixelChargefirst,fBlindPixelChargelast,fgSinglePheFitNPar);
+  
+  simulateSinglePhe->SetParameters(lambda,mu0,mu1,sigma0,sigma1);
+  simulateSinglePhe->SetParNames("#lambda","#mu_0","#mu_1","#sigma_0","#sigma_1");
+  simulateSinglePhe->SetNpx(fBlindPixelChargenbins);  
+
+  for (Int_t i=0;i<10000; i++) 
+    {
+      fHBlindPixelCharge->Fill(simulateSinglePhe->GetRandom());
+    }
+  
+  return kTRUE;
+}
+
+
+void MHCalibrationBlindPixel::ChangeFitFunc(BlindPixelFitFunc fitfunc, Int_t par)
+{
+  
+  fgSinglePheFitFunc = fitfunc;
+  fgSinglePheFitNPar = par;
+
+}
+
+
+
+Bool_t MHCalibrationBlindPixel::FitSinglePhe(Axis_t rmin, Axis_t rmax, Option_t *opt) 
+{
+
+  if (fSinglePheFit)
+    return kFALSE;
+
+
+  //
+  // Get the fitting ranges
+  //
+  rmin = (rmin != 0.) ? rmin : fBlindPixelChargefirst;
+  rmax = (rmax != 0.) ? rmax : fBlindPixelChargelast;
+
+  //
+  // First guesses for the fit (should be as close to reality as possible, 
+  // otherwise the fit goes gaga because of high number of dimensions ...
+  //
+  const Stat_t   entries      = fHBlindPixelCharge->Integral();
+  const Double_t lambda_guess = 0.5;
+  const Double_t mu_0_guess = fHBlindPixelCharge->GetBinCenter(fHBlindPixelCharge->GetMaximumBin());
+  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;
+
+  fSinglePheFit = new TF1("SinglePheFit",fgSinglePheFitFunc,rmin,rmax,fgSinglePheFitNPar+1);
+  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.,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.,1.5*entries);
+  //
+  // Normalize the histogram to facilitate faster fitting of the area
+  // For speed reasons, FKto8 is normalized to Sqrt(2 pi).
+  // Therefore also normalize the histogram to that value 
+  //
+  // ROOT gives us another nice example of user-unfriendly behavior:
+  // Although the normalization of the function fSinglePhe and the 
+  // Histogram fHBlindPixelCharge agree (!!), the fit does not normalize correctly INTERNALLY
+  // in the fitting procedure !!!
+  // 
+  // This has to do with the fact that the internal function histogramming 
+  // uses 100 bins and does not adapt to the binning of the fitted histogram, unlike PAW does
+  // (very important if you use Sumw2, see e.g. ROOTTALK: Mon May 26 1997 - 09:56:03 MEST)
+  // 
+  // So, WE have to adapt to that internal flaw of ROOT:
+  //
+  //  const Int_t  npx     = fSinglePheFit->GetNpx();
+  //  const Int_t  bins    = fHBlindPixelCharge->GetXaxis()->GetLast()-fHBlindPixelCharge->GetXaxis()->GetFirst();
+  //  fHBlindPixelCharge->Scale(gkSq2Pi*(float)bins/npx/entries);
+
+  // 
+  // we need this, otherwise, ROOT does not calculate the area correctly
+  // don't ask me why it does not behave correctly, it's one of the nasty
+  // mysteries of ROOT which takes you a whole day to find out :-)
+  //
+  //  fSinglePheFit->SetNpx(fChargenbins);  
+
+  fHBlindPixelCharge->Fit(fSinglePheFit,opt);
+  fHBlindPixelCharge->Fit(fSinglePheFit,opt);
+
+  fLambda = fSinglePheFit->GetParameter(0);
+  fMu0    = fSinglePheFit->GetParameter(1);
+  fMu1    = fSinglePheFit->GetParameter(2);
+  fSigma0 = fSinglePheFit->GetParameter(3);
+  fSigma1 = fSinglePheFit->GetParameter(4);
+  
+  fLambdaErr = fSinglePheFit->GetParError(0);
+  fMu0Err    = fSinglePheFit->GetParError(1);
+  fMu1Err    = fSinglePheFit->GetParError(2);
+  fSigma0Err = fSinglePheFit->GetParError(3);
+  fSigma1Err = fSinglePheFit->GetParError(4);
+
+  fProb      = fSinglePheFit->GetProb();
+  fChisquare = fSinglePheFit->GetChisquare();
+  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;
+  *fLog << "DoF: " << fNdf << endl;
+  *fLog << "Probability: " << fProb << endl;
+  *fLog << "Integral: " << fSinglePheFit->Integral(rmin,rmax);
+
+  //
+  // The fit result is accepted under condition
+  // The fit result is accepted under condition
+  // The Probability is greater than gkProbLimit (default 0.001 == 99.7%)
+  //
+  if (fProb < gkProbLimit) 
+    {
+      *fLog << warn << "Prob: " << fProb << " is smaller than the allowed value: " << gkProbLimit << endl;
+      fFitOK = kFALSE;
+      return kFALSE;
+    }
+  
+  
+  fFitOK = kTRUE;
+    
+  return kTRUE;
+}
+
+ 
+void MHCalibrationBlindPixel::CutAllEdges()
+{
+
+  Int_t nbins = 50;
+
+  CutEdges(fHBlindPixelCharge,nbins);
+
+  fBlindPixelChargefirst = fHBlindPixelCharge->GetBinLowEdge(fHBlindPixelCharge->GetXaxis()->GetFirst());
+  fBlindPixelChargelast  = fHBlindPixelCharge->GetBinLowEdge(fHBlindPixelCharge->GetXaxis()->GetLast())+fHBlindPixelCharge->GetBinWidth(0);
+  fBlindPixelChargenbins = nbins;
+
+  CutEdges(fHBlindPixelChargevsN,0);
+
+}
+
+Bool_t MHCalibrationBlindPixel::FitTime(Axis_t rmin, Axis_t rmax, Option_t *opt) 
+{
+  
+  if (fTimeGausFit)
+    return kFALSE;
+
+  rmin = (rmin != 0.) ? rmin : 4.;
+  rmax = (rmax != 0.) ? rmax : 9.;
+
+  const Stat_t   entries     = fHBlindPixelTime->Integral();
+  const Double_t mu_guess    = fHBlindPixelTime->GetBinCenter(fHBlindPixelTime->GetMaximumBin());
+  const Double_t sigma_guess = (rmax - rmin)/2.;
+  const Double_t area_guess  = entries/gkSq2Pi;
+
+  fTimeGausFit = new TF1("GausTime","gaus",rmin,rmax);  
+  fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
+  fTimeGausFit->SetParNames("Area","#mu","#sigma");
+  fTimeGausFit->SetParLimits(0,0.,entries);
+  fTimeGausFit->SetParLimits(1,rmin,rmax);
+  fTimeGausFit->SetParLimits(2,0.,rmax-rmin);
+
+  fHBlindPixelTime->Fit(fTimeGausFit,opt);
+
+  rmin = fTimeGausFit->GetParameter(1) - 2.*fTimeGausFit->GetParameter(2);
+  rmax = fTimeGausFit->GetParameter(1) + 2.*fTimeGausFit->GetParameter(2);
+  fTimeGausFit->SetRange(rmin,rmax);  
+
+  fHBlindPixelTime->Fit(fTimeGausFit,opt);
+
+
+  fMeanTime     = fTimeGausFit->GetParameter(2);
+  fSigmaTime    = fTimeGausFit->GetParameter(3);
+  fMeanTimeErr  = fTimeGausFit->GetParError(2);
+  fSigmaTimeErr = fTimeGausFit->GetParError(3);
+
+  Float_t prob = fTimeGausFit->GetProb();
+
+  *fLog << "Results of the Times Fit: " << endl;
+  *fLog << "Chisquare: "   << fTimeGausFit->GetChisquare() << endl;
+  *fLog << "Ndf: "         << fTimeGausFit->GetNDF() << endl;
+  *fLog << "Probability: " << prob << endl;
+
+  if (prob < gkProbLimit) 
+    {
+      *fLog << warn << "Fit of the Arrival times failed ! " << endl;
+      return kFALSE;
+    }
+  
+  return kTRUE;
+
+}
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.h	(revision 2734)
@@ -0,0 +1,130 @@
+#ifndef MARS_MHCalibrationBlindPixel
+#define MARS_MHCalibrationBlindPixel
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+#ifndef MARS_MHCalibrationConfig
+#include "MHCalibrationConfig.h"
+#endif
+
+#ifndef ROOT_TH1
+#include "TH1.h"
+#endif
+
+#ifndef ROOT_TH1F
+#include "TH1F.h"
+#endif
+
+#ifndef ROOT_TF1
+#include "TF1.h"
+#endif
+
+#ifndef ROOT_TPaveText
+#include "TPaveText.h"
+#endif
+
+class TMath;
+class MParList;
+class MHCalibrationBlindPixel : public MH
+{
+private:
+
+  TH1F* fHBlindPixelCharge;        //-> Histogram with the single Phe spectrum
+  TH1I* fHBlindPixelTime;          //-> Variance of summed FADC slices
+  TH1I* fHBlindPixelChargevsN;     //-> Summed Charge vs. Event Nr. 
+  
+  TF1 *fSinglePheFit;
+  TF1 *fTimeGausFit;  
+  TF1 *fSinglePhePedFit;
+
+  Axis_t  fBlindPixelChargefirst;
+  Axis_t  fBlindPixelChargelast;
+  Int_t   fBlindPixelChargenbins;
+  
+  void ResetBin(Int_t i);
+  void DrawLegend();
+
+  TPaveText *fFitLegend;
+  Bool_t fFitOK;  
+  
+  BlindPixelFitFunc fgSinglePheFitFunc;     // In the beginning, 
+  Int_t     fgSinglePheFitNPar;             // we want to be flexible using different functions
+
+  Double_t  fLambda; 
+  Double_t  fMu0; 
+  Double_t  fMu1; 
+  Double_t  fSigma0; 
+  Double_t  fSigma1; 
+
+  Double_t  fLambdaErr; 
+  Double_t  fMu0Err; 
+  Double_t  fMu1Err; 
+  Double_t  fSigma0Err; 
+  Double_t  fSigma1Err; 
+
+  Double_t  fChisquare; 
+  Double_t  fProb;      
+  Int_t     fNdf;       
+
+  Double_t  fMeanTime; 
+  Double_t  fMeanTimeErr; 
+  Double_t  fSigmaTime; 
+  Double_t  fSigmaTimeErr; 
+  
+  Double_t fLambdaCheck;
+  Double_t fLambdaCheckErr;
+
+public:
+
+  MHCalibrationBlindPixel(const char *name=NULL, const char *title=NULL);
+  ~MHCalibrationBlindPixel();
+
+  Bool_t FillBlindPixelCharge(Float_t q)             { return fHBlindPixelCharge->Fill(q) > -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;  }  
+  
+  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 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 GetMeanTime()      const { return fMeanTime; }
+  const Double_t GetMeanTimeErr()    const { return fMeanTimeErr; }
+  const Double_t GetSigmaTime()      const { return fSigmaTime; }
+  const Double_t GetSigmaTimeErr()    const { return fSigmaTimeErr; }
+
+  Bool_t SimulateSinglePhe(Double_t lambda,
+                           Double_t mu0,
+                           Double_t mu1,
+                           Double_t sigma0,
+                           Double_t sigma1);
+  
+  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+");
+
+  void ChangeFitFunc(BlindPixelFitFunc fitfunc, Int_t par=5);
+
+  void CutAllEdges();
+  void Draw(Option_t *option="");
+
+  Bool_t IsFitOK() { return fFitOK; }
+
+  ClassDef(MHCalibrationBlindPixel, 1) 
+};
+
+#endif  /* MARS_MHCalibrationBlindPixel */
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationConfig.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationConfig.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationConfig.h	(revision 2734)
@@ -0,0 +1,28 @@
+#ifndef MARS_MHCalibrationConfig
+#define MARS_MHCalibrationConfig
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MHCalibrationConfig                                                     //
+//                                                                         //
+// Contains all configuration data of the Calibration                      //
+//                       i                                                  //
+/////////////////////////////////////////////////////////////////////////////
+
+
+// Global rejection criteria for the acceptance of a fit: Prob=0.01 == 99% Probability
+const Float_t gkProbLimit = 0.001;
+
+// Starting number of bins for the histo:
+const Int_t gkStartBlindPixelBinNr = 10000;
+
+// Starting number of bins for the histo: (maximum by hardware: 4080)
+const Int_t gkStartPINDiodeBinNr = 4000;
+
+// Square root of 2 pi:
+const Float_t gkSq2Pi = 2.506628274631;
+
+// typedef to the fitting functions for the blind pixel
+typedef Double_t (*BlindPixelFitFunc)(Double_t *, Double_t *);
+
+#endif /* MARS_MHCalibrationBlindPixelConfig */
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.cc	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.cc	(revision 2734)
@@ -0,0 +1,111 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug 11/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//  MHCalibrationPINDiode                                                 //
+//                                                                          //
+//  Performs all the necessary fits to extract the mean number of photons   //
+//              out of the derived light flux                               //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+#include "MHCalibrationPINDiode.h"
+#include "MHCalibrationConfig.h"
+
+#include <TStyle.h>
+#include <TMath.h>
+
+#include <TMinuit.h>
+#include <TFitter.h>
+
+#include <TF1.h>
+#include <TH2.h>
+#include <TCanvas.h>
+#include <TPaveText.h>
+#include <TRandom.h>
+
+#include "MBinning.h"
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MHCalibrationPINDiode);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default Constructor. 
+//
+MHCalibrationPINDiode::MHCalibrationPINDiode(const char *name, const char *title)
+    : fVarGausFit(NULL)
+{
+
+    fName  = name  ? name  : "MHCalibrationPINDiode";
+    fTitle = title ? title : "Fill the accumulated charges and times all PINDiode events and perform fits";
+
+    // Create a large number of bins, later we will rebin
+    fChargeFirstHiGain = -1000.;
+    fChargeLastHiGain  = gkStartPINDiodeBinNr;
+    fChargeNbinsHiGain = gkStartPINDiodeBinNr;
+
+    fHPCharge = new TH1I("HPCharge","Distribution of Summed FADC Slices",
+			 fChargeNbinsHiGain,fChargeFirstHiGain,fChargeLastHiGain);
+    fHPCharge->SetXTitle("Sum FADC Slices");
+    fHPCharge->SetYTitle("Nr. of events");
+    fHPCharge->Sumw2();
+
+    fErrChargeFirst = 0.;
+    fErrChargeLast  = gkStartPINDiodeBinNr;
+    fErrChargeNbins = gkStartPINDiodeBinNr;
+
+    fHErrCharge = new TH1F("HErrCharge","Distribution of Variances of Summed FADC Slices",fErrChargeNbins,fErrChargeFirst,fErrChargeLast);
+    fHErrCharge->SetXTitle("Variance Summed FADC Slices");
+    fHErrCharge->SetYTitle("Nr. of events");
+    fHErrCharge->Sumw2();
+
+    Int_t tfirst = 0;
+    Int_t tlast  = 31;
+    Int_t nbins   = 32;
+
+    fHPTime = new TH1I("HPTime","Distribution of Mean Arrival Times",nbins,tfirst,tlast);
+    fHPTime->SetXTitle("Mean Arrival Times [FADC slice nr]");
+    fHPTime->SetYTitle("Nr. of events");
+    fHPTime->Sumw2();
+
+}
+
+MHCalibrationPINDiode::~MHCalibrationPINDiode()
+{
+
+  delete fHPCharge;
+  delete fHErrCharge;
+  
+  if (fVarGausFit)
+    delete fVarGausFit;
+  
+  delete fHPTime;
+
+}
+
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.h	(revision 2734)
@@ -0,0 +1,51 @@
+#ifndef MARS_MHCalibrationPINDiode
+#define MARS_MHCalibrationPINDiode
+
+#ifndef MARS_MHCalibrationPixel
+#include "MHCalibrationPixel.h"
+#endif
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+#ifndef ROOT_TH1
+#include "TH1.h"
+#endif
+
+#ifndef ROOT_TH1F
+#include "TH1F.h"
+#endif
+
+#ifndef ROOT_TF1
+#include "TF1.h"
+#endif
+
+class MHCalibrationPINDiode : public MHCalibrationPixel
+{
+private:
+
+  TH1I* fHPCharge;             //-> Histogram containing the summed 32 PINDiode slices
+  TH1F* fHErrCharge;           //-> Variance of summed FADC slices
+  TH1I* fHPTime;             //-> Histogram with time evolution of summed charges
+  
+  
+  TF1 *fVarGausFit;
+  
+  Float_t  fErrChargeFirst;
+  Float_t  fErrChargeLast;
+  UShort_t fErrChargeNbins;
+
+public:
+
+  MHCalibrationPINDiode(const char *name=NULL, const char *title=NULL);
+  ~MHCalibrationPINDiode();
+
+  const Double_t GetTime()      const { return fVarGausFit->GetParameter(2); }
+  const Double_t GetErrTime()    const { return fVarGausFit->GetParameter(3); }
+
+  ClassDef(MHCalibrationPINDiode, 0) 
+};
+
+#endif
+
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 2734)
@@ -0,0 +1,897 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug 11/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//  MHCalibrationPixel                                                 //
+//                                                                          //
+//  Performs all the necessary fits to extract the mean number of photons   //
+//              out of the derived light flux                               //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "MHCalibrationPixel.h"
+#include "MHCalibrationConfig.h"
+#include "MCalibrationFits.h"
+
+#include <TStyle.h>
+#include <TMath.h>
+
+#include <TFitter.h>
+#include <TGraph.h>
+#include <TAxis.h>
+
+#include <TF1.h>
+#include <TH2.h>
+#include <TProfile.h>
+#include <TCanvas.h>
+#include <TPad.h>
+#include <TPaveText.h>
+
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MHCalibrationPixel);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. 
+//
+MHCalibrationPixel::MHCalibrationPixel(const char *name, const char *title)
+      : fPixId(-1),
+	fTotalEntries(0),
+	fHiGains(NULL),
+	fLoGains(NULL),
+        fChargeGausFit(NULL), 
+	fTimeGausFit(NULL), 
+	fHivsLoGain(NULL),
+	fFitLegend(NULL),
+	fLowerFitRange(-2000.),
+	fChargeFirstHiGain(-2000.5),
+	fChargeLastHiGain(9999.5),
+	fChargeNbinsHiGain(12000),
+	fChargeFirstLoGain(-2000.5),
+	fChargeLastLoGain(9999.5),
+	fChargeNbinsLoGain(1200),
+        fFitOK(kFALSE),
+        fChargeChisquare(-1.),
+        fChargeProb(-1.),
+        fChargeNdf(-1),
+        fTimeChisquare(-1.),
+        fTimeProb(-1.),
+        fTimeNdf(-1),
+        fTimeMean(-1.),
+        fTimeSigma(-1.),
+        fTimeLowerFitRange(3.),
+        fTimeUpperFitRange(9.),
+	fUseLoGain(kFALSE),
+	fOffset(0.),
+	fSlope(0.)
+{ 
+
+    fName  = name  ? name  : "MHCalibrationPixel";
+    fTitle = title ? title : "Fill the accumulated charges and times of all events and perform fits";
+
+    // 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)");
+    fHChargeLoGain->SetYTitle("Nr. of events");
+    fHChargeLoGain->Sumw2();
+
+    fHChargeLoGain->SetDirectory(NULL);
+
+    Axis_t tfirst = -0.5;
+    Axis_t tlast  = 15.5;
+    Int_t  ntbins = 16;
+
+    fHTimeHiGain = new TH1I("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->Sumw2();
+
+    fHTimeHiGain->SetDirectory(NULL);
+
+    fHTimeLoGain = new TH1I("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->Sumw2();
+
+    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();
+
+}
+
+MHCalibrationPixel::~MHCalibrationPixel()
+{
+
+  delete fHChargeHiGain;
+  delete fHTimeHiGain;
+  delete fHChargevsNHiGain;
+
+  delete fHChargeLoGain;
+  delete fHTimeLoGain;
+  delete fHChargevsNLoGain;
+
+  delete fHiGains;
+  delete fLoGains;
+
+  if (fChargeGausFit)
+    delete fChargeGausFit;
+  if (fTimeGausFit)
+    delete fTimeGausFit;
+  if (fFitLegend)
+    delete fFitLegend;
+  if (fHivsLoGain)
+    delete fHivsLoGain;
+
+
+}
+
+
+void MHCalibrationPixel::ChangeHistId(Int_t id)
+{
+
+  fPixId = id;
+
+  //
+  // Names Hi gain Histograms
+  //
+  TString nameQHiGain = TString(fHChargeHiGain->GetName());
+  nameQHiGain += id;
+  fHChargeHiGain->SetName(nameQHiGain.Data());
+
+  TString nameTHiGain = TString(fHTimeHiGain->GetName());
+  nameTHiGain += id;
+  fHTimeHiGain->SetName(nameTHiGain.Data());
+
+  TString nameQvsNHiGain  = TString(fHChargevsNHiGain->GetName());
+  nameQvsNHiGain += id;
+  fHChargevsNHiGain->SetName(nameQvsNHiGain.Data());
+
+  //
+  // Title Hi gain Histograms
+  //
+  TString titleQHiGain = TString(fHChargeHiGain->GetTitle());
+  titleQHiGain += id;
+  fHChargeHiGain->SetTitle(titleQHiGain.Data());
+
+  TString titleTHiGain = TString(fHTimeHiGain->GetTitle());
+  titleTHiGain += id;
+  fHTimeHiGain->SetTitle(titleTHiGain.Data());
+
+  TString titleQvsNHiGain  = TString(fHChargevsNHiGain->GetTitle());
+  titleQvsNHiGain += id;
+  fHChargevsNHiGain->SetTitle(titleQvsNHiGain.Data());
+
+  //
+  // Names Low Gain Histograms
+  //
+  TString nameQLoGain = TString(fHChargeLoGain->GetName());
+  nameQLoGain += id;
+  fHChargeLoGain->SetName(nameQLoGain.Data());
+
+  TString nameTLoGain = TString(fHTimeLoGain->GetName());
+  nameTLoGain += id;
+  fHTimeLoGain->SetName(nameTLoGain.Data());
+
+  TString nameQvsNLoGain  = TString(fHChargevsNLoGain->GetName());
+  nameQvsNLoGain += id;
+  fHChargevsNLoGain->SetName(nameQvsNLoGain.Data());
+
+  //
+  // Titles Low Gain Histograms
+  //
+  TString titleQLoGain = TString(fHChargeLoGain->GetTitle());
+  titleQLoGain += id;
+  fHChargeLoGain->SetTitle(titleQLoGain.Data());
+
+  TString titleTLoGain = TString(fHTimeLoGain->GetTitle());
+  titleTLoGain += id;
+  fHTimeLoGain->SetTitle(titleTLoGain.Data());
+
+  TString titleQvsNLoGain  = TString(fHChargevsNLoGain->GetTitle());
+  titleQvsNLoGain += id;
+  fHChargevsNLoGain->SetTitle(titleQvsNLoGain.Data());
+}
+
+
+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);
+  
+  fChargeLastHiGain     = 9999.5;
+
+  fHChargeHiGain->GetXaxis()->SetRangeUser(0.,fChargeLastHiGain);
+
+ 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);
+  
+  fChargeLastLoGain     = 9999.5;
+
+  fHChargeLoGain->GetXaxis()->SetRangeUser(0.,fChargeLastLoGain);
+
+  return;
+}
+
+
+// -------------------------------------------------------------------------
+//
+// Set the binnings and prepare the filling of the histograms
+//
+Bool_t MHCalibrationPixel::SetupFill(const MParList *plist)
+{
+
+  fHChargeHiGain->Reset();
+  fHTimeHiGain->Reset();
+  fHChargeLoGain->Reset();
+  fHTimeLoGain->Reset();
+
+  return kTRUE;
+}
+
+
+Bool_t MHCalibrationPixel::UseLoGain()
+{
+
+  if (fHChargeHiGain->Integral() > fHChargeLoGain->Integral())
+    {
+      fUseLoGain = kFALSE;
+      return kFALSE;
+    }
+  else
+    {
+      fUseLoGain = kTRUE;
+      return kTRUE;
+    }
+}
+
+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);
+
+}
+
+
+// -------------------------------------------------------------------------
+//
+// Draw a legend with the fit results
+//
+void MHCalibrationPixel::DrawLegend()
+{
+
+  fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
+
+  if (fFitOK) 
+      fFitLegend->SetFillColor(80);
+  else
+      fFitLegend->SetFillColor(2);    
+  
+  fFitLegend->SetLabel("Results of the Gauss Fit:");
+  fFitLegend->SetTextSize(0.05);
+
+  const TString line1 = 
+    Form("Mean: Q_{#mu} = %2.2f #pm %2.2f",fChargeMean,fChargeMeanErr);
+
+  fFitLegend->AddText(line1);
+
+
+  const TString line4 =
+    Form("Sigma: #sigma_{Q} = %2.2f #pm %2.2f",fChargeSigma,fChargeSigmaErr);
+
+  fFitLegend->AddText(line4);
+
+
+  const TString line7 =
+    Form("#chi^{2} / N_{dof}: %4.2f / %3i",fChargeChisquare,fChargeNdf);
+
+  fFitLegend->AddText(line7);
+
+
+  const TString line8 =
+    Form("Probability: %4.3f ",fChargeProb);
+
+  fFitLegend->AddText(line8);
+
+  if (fFitOK)
+    fFitLegend->AddText("Result of the Fit: OK");
+  else
+    fFitLegend->AddText("Result of the Fit: NOT OK");
+
+  fFitLegend->SetBit(kCanDelete);
+  fFitLegend->Draw();
+
+}
+
+
+// -------------------------------------------------------------------------
+//
+// Draw the histogram
+//
+void MHCalibrationPixel::Draw(Option_t *opt) 
+{
+
+  if (!fHivsLoGain)
+    FitHiGainvsLoGain();
+      
+  gStyle->SetOptFit(0);
+  gStyle->SetOptStat(1111111);
+  
+  TCanvas *c = MakeDefCanvas(this,600,900); 
+  
+  gROOT->SetSelectedPad(NULL);
+  
+  c->Divide(2,4);
+  
+  c->cd(1);
+  gPad->SetBorderMode(0);
+  gPad->SetTicks();
+
+  if (fHChargeHiGain->Integral() > 0)
+    gPad->SetLogy(1);
+  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(6);
+        gPad->SetTicks();
+	gPad->SetLogy(0);
+	fHTimeLoGain->DrawCopy(opt);
+	c->Modified();
+	c->Update();
+	
+	if (fTimeGausFit)
+	  {
+	    if (fTimeChisquare > 20.) 
+	      fTimeGausFit->SetLineColor(kRed);
+	    else
+	      fTimeGausFit->SetLineColor(kGreen);
+	    
+	    fTimeGausFit->DrawCopy("same");
+	    c->Modified();
+	    c->Update();
+	  }
+      }
+    else
+      {  
+	if (fTimeGausFit)
+	  {
+	    if (fTimeChisquare > 20.) 
+	      fTimeGausFit->SetLineColor(kRed);
+	    else
+	      fTimeGausFit->SetLineColor(kGreen);
+	    
+	    fTimeGausFit->DrawCopy("same");
+	    c->Modified();
+	    c->Update();
+	  }
+
+	c->cd(6);
+        gPad->SetTicks();
+	gPad->SetLogy(0);
+	fHTimeLoGain->DrawCopy(opt);	
+	c->Modified();
+	c->Update();
+    
+      }
+    c->Modified();
+    c->Update();
+    
+    c->cd(7);
+    gPad->SetTicks();
+    fHChargevsNHiGain->DrawCopy(opt);
+    c->Modified();
+    c->Update();
+
+    c->cd(8);
+    gPad->SetTicks();
+    fHChargevsNLoGain->DrawCopy(opt);
+    c->Modified();
+    c->Update();
+
+
+}
+
+void MHCalibrationPixel::FitHiGainvsLoGain()
+{
+
+  if (fHivsLoGain)
+    return;
+
+  gStyle->SetOptFit();
+
+  fHivsLoGain = new TProfile("HiGainvsLoGain","Plot the High Gain vs. Low Gain",100,0.,1000.,0.,1000.);
+  fHivsLoGain->GetXaxis()->SetTitle("Sum of Charges High Gain");
+  fHivsLoGain->GetYaxis()->SetTitle("Sum of Charges Low Gain");
+
+  TString titleHiLoGain  = TString(fHivsLoGain->GetName());
+  titleHiLoGain += fPixId;
+  fHivsLoGain->SetName(titleHiLoGain.Data());
+
+  
+  for (Int_t i=0;i<fTotalEntries;i++)
+    fHivsLoGain->Fill(fHiGains->At(i),fLoGains->At(i),1);
+  
+  fHivsLoGain->Fit("pol1","rq","",fHivsLoGain->GetMean()-2.5*fHivsLoGain->GetRMS(),fHivsLoGain->GetMean()+2.*fHivsLoGain->GetRMS());
+  
+  fOffset = fHivsLoGain->GetFunction("pol1")->GetParameter(0);
+  fSlope  = fHivsLoGain->GetFunction("pol1")->GetParameter(1);
+  
+}
+
+
+Bool_t MHCalibrationPixel::FitTimeHiGain(Axis_t rmin, Axis_t rmax, Option_t *option)
+{
+
+  if (fTimeGausFit)
+    return kFALSE;
+
+  rmin = (rmin != 0.) ? rmin : fTimeLowerFitRange;
+  rmax = (rmax != 0.) ? rmax : fTimeUpperFitRange;
+
+  const Stat_t entries       = fHTimeHiGain->Integral();
+  const Double_t mu_guess    = fHTimeHiGain->GetBinCenter(fHTimeHiGain->GetMaximumBin());
+  const Double_t sigma_guess = (rmax - rmin)/2.;
+  const Double_t area_guess  = entries/gkSq2Pi;
+
+  TString name = TString("GausTime");
+  name += fPixId;
+  fTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);  
+
+  if (!fTimeGausFit) 
+    {
+    *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
+    return kFALSE;
+    }
+
+  fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
+  fTimeGausFit->SetParNames("Area","#mu","#sigma");
+  fTimeGausFit->SetParLimits(0,0.,entries);
+  fTimeGausFit->SetParLimits(1,rmin,rmax);
+  fTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
+  fTimeGausFit->SetRange(rmin,rmax);
+
+  fHTimeHiGain->Fit(fTimeGausFit,option);
+
+  rmin = fTimeGausFit->GetParameter(1) - 3.*fTimeGausFit->GetParameter(2);
+  rmax = fTimeGausFit->GetParameter(1) + 3.*fTimeGausFit->GetParameter(2);
+  fTimeGausFit->SetRange(rmin,rmax);  
+
+  fHTimeHiGain->Fit(fTimeGausFit,option);
+
+  fTimeChisquare = fTimeGausFit->GetChisquare();
+  fTimeNdf       = fTimeGausFit->GetNDF();
+  fTimeProb      = fTimeGausFit->GetProb();
+
+  fTimeMean      = fTimeGausFit->GetParameter(1);
+  fTimeSigma     = fTimeGausFit->GetParameter(2);
+
+  if (fTimeChisquare > 20.)  // Cannot use Probability because Ndf is sometimes < 1
+    {
+      *fLog << warn << "Fit of the Arrival times failed ! " << endl;
+      return kFALSE;
+    }
+  
+  return kTRUE;
+
+}
+
+Bool_t MHCalibrationPixel::FitTimeLoGain(Axis_t rmin, Axis_t rmax, Option_t *option)
+{
+
+  if (fTimeGausFit)
+    return kFALSE;
+
+  rmin = (rmin != 0.) ? rmin : fTimeLowerFitRange;
+  rmax = (rmax != 0.) ? rmax : fTimeUpperFitRange;
+
+  const Stat_t   entries     = fHTimeLoGain->Integral();
+  const Double_t mu_guess    = fHTimeLoGain->GetBinCenter(fHTimeLoGain->GetMaximumBin());
+  const Double_t sigma_guess = (rmax - rmin)/2.;
+  const Double_t area_guess  = entries/gkSq2Pi;
+
+  TString name = TString("GausTime");
+  name += fPixId;
+  fTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);  
+
+  if (!fTimeGausFit) 
+    {
+    *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
+    return kFALSE;
+    }
+
+  fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
+  fTimeGausFit->SetParNames("Area","#mu","#sigma");
+  fTimeGausFit->SetParLimits(0,0.,entries);
+  fTimeGausFit->SetParLimits(1,rmin,rmax);
+  fTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
+  fTimeGausFit->SetRange(rmin,rmax);
+
+  fHTimeLoGain->Fit(fTimeGausFit,option);
+
+  rmin = fTimeGausFit->GetParameter(1) - 3.*fTimeGausFit->GetParameter(2);
+  rmax = fTimeGausFit->GetParameter(1) + 3.*fTimeGausFit->GetParameter(2);
+  fTimeGausFit->SetRange(rmin,rmax);  
+
+  fHTimeLoGain->Fit(fTimeGausFit,option);
+
+  fTimeChisquare = fTimeGausFit->GetChisquare();
+  fTimeNdf       = fTimeGausFit->GetNDF();
+  fTimeProb      = fTimeGausFit->GetProb();
+
+  fTimeMean      = fTimeGausFit->GetParameter(1);
+  fTimeSigma     = fTimeGausFit->GetParameter(2);
+
+  if (fTimeChisquare > 20.)  // Cannot use Probability because Ndf is sometimes < 1
+    {
+      *fLog << warn << "Fit of the Arrival times failed ! " << endl;
+      return kFALSE;
+    }
+  
+  return kTRUE;
+
+}
+
+Bool_t MHCalibrationPixel::FitChargeHiGain(Option_t *option)
+{
+
+  if (fChargeGausFit)
+    return kFALSE;
+
+  //
+  // Get the fitting ranges
+  //
+  Axis_t rmin = (fLowerFitRange != 0.) ? fLowerFitRange : fChargeFirstHiGain;
+  Axis_t rmax = 0.;
+
+  //
+  // First guesses for the fit (should be as close to reality as possible, 
+  // otherwise the fit goes gaga because of high number of dimensions ...
+  //
+  const Stat_t   entries    = fHChargeHiGain->Integral();
+  const Double_t area_guess = entries/gkSq2Pi;
+  const Double_t mu_guess   = fHChargeHiGain->GetBinCenter(fHChargeHiGain->GetMaximumBin());
+  const Double_t sigma_guess = mu_guess/15.;
+
+  TString name = TString("ChargeGausFit");
+  name += fPixId;
+
+  fChargeGausFit = new TF1(name.Data(),"gaus",rmin,fChargeLastHiGain);
+
+  if (!fChargeGausFit) 
+    {
+    *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
+    return kFALSE;
+    }
+  
+  fChargeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
+  fChargeGausFit->SetParNames("Area","#mu","#sigma");
+  fChargeGausFit->SetParLimits(0,0.,entries);
+  fChargeGausFit->SetParLimits(1,rmin,fChargeLastHiGain);
+  fChargeGausFit->SetParLimits(2,0.,fChargeLastHiGain-rmin);
+  fChargeGausFit->SetRange(rmin,fChargeLastHiGain);
+
+  fHChargeHiGain->Fit(fChargeGausFit,option);
+  
+  Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.0*fChargeGausFit->GetParameter(2);
+  
+  rmin = (rtry < rmin ? rmin : rtry);
+  rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
+  fChargeGausFit->SetRange(rmin,rmax);  
+
+  fHChargeHiGain->Fit(fChargeGausFit,option);
+
+  fChargeChisquare = fChargeGausFit->GetChisquare();
+  fChargeNdf       = fChargeGausFit->GetNDF();
+  fChargeProb      = fChargeGausFit->GetProb();
+  fChargeMean      = fChargeGausFit->GetParameter(1);
+  fChargeMeanErr   = fChargeGausFit->GetParError(1);
+  fChargeSigma     = fChargeGausFit->GetParameter(2);
+  fChargeSigmaErr  = fChargeGausFit->GetParError(2);
+
+  //
+  // The fit result is accepted under condition
+  // The Probability is greater than gkProbLimit (default 0.001 == 99.9%)
+  //
+  if (fChargeProb < gkProbLimit) 
+    {
+      *fLog << warn << "Prob: " << fChargeProb 
+            << " is smaller than the allowed value: " << gkProbLimit << endl;
+      fFitOK = kFALSE;
+      return kFALSE;
+    }
+  
+  fFitOK = kTRUE;
+  return kTRUE;
+}
+
+
+Bool_t MHCalibrationPixel::FitChargeLoGain(Option_t *option)
+{
+
+  if (fChargeGausFit)
+    return kFALSE;
+
+  //
+  // Get the fitting ranges
+  //
+  Axis_t rmin = (fLowerFitRange != 0.) ? fLowerFitRange : fChargeFirstLoGain;
+  Axis_t rmax = 0.;
+
+  //
+  // First guesses for the fit (should be as close to reality as possible, 
+  // otherwise the fit goes gaga because of high number of dimensions ...
+  //
+  const Stat_t   entries    = fHChargeLoGain->Integral();
+  const Double_t area_guess = entries/gkSq2Pi;
+  const Double_t mu_guess   = fHChargeLoGain->GetBinCenter(fHChargeLoGain->GetMaximumBin());
+  const Double_t sigma_guess = mu_guess/15.;
+
+  TString name = TString("ChargeGausFit");
+  name += fPixId;
+
+  fChargeGausFit = new TF1(name.Data(),"gaus",rmin,fChargeLastLoGain);
+
+  if (!fChargeGausFit) 
+    {
+    *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
+    return kFALSE;
+    }
+  
+  fChargeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
+  fChargeGausFit->SetParNames("Area","#mu","#sigma");
+  fChargeGausFit->SetParLimits(0,0.,entries);
+  fChargeGausFit->SetParLimits(1,rmin,fChargeLastLoGain);
+  fChargeGausFit->SetParLimits(2,0.,fChargeLastLoGain-rmin);
+  fChargeGausFit->SetRange(rmin,fChargeLastLoGain);
+
+  fHChargeLoGain->Fit(fChargeGausFit,option);
+  
+  Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.*fChargeGausFit->GetParameter(2);
+  
+  rmin = (rtry < rmin ? rmin : rtry);
+  rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
+  fChargeGausFit->SetRange(rmin,rmax);  
+
+  fHChargeLoGain->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);  
+
+  // fHChargeLoGain->Fit(fChargeGausFit,option);
+
+  fChargeChisquare = fChargeGausFit->GetChisquare();
+  fChargeNdf       = fChargeGausFit->GetNDF();
+  fChargeProb      = fChargeGausFit->GetProb();
+  fChargeMean      = fChargeGausFit->GetParameter(1);
+  fChargeMeanErr   = fChargeGausFit->GetParError(1);
+  fChargeSigma     = fChargeGausFit->GetParameter(2);
+  fChargeSigmaErr  = fChargeGausFit->GetParError(2);
+
+  //
+  // The fit result is accepted under condition
+  // The Probability is greater than gkProbLimit (default 0.01 == 99%)
+  //
+  if (fChargeProb < gkProbLimit) 
+    {
+      *fLog << warn << "Prob: " << fChargeProb << " is smaller than the allowed value: " << gkProbLimit << endl;
+      fFitOK = kFALSE;
+      return kFALSE;
+    }
+  
+  
+  fFitOK = kTRUE;
+    
+  return kTRUE;
+}
+
+ 
+void MHCalibrationPixel::CutAllEdges()
+{
+
+  Int_t nbins = 30;
+
+  CutEdges(fHChargeHiGain,nbins);
+
+  fChargeFirstHiGain = fHChargeHiGain->GetBinLowEdge(fHChargeHiGain->GetXaxis()->GetFirst());
+  fChargeLastHiGain  = fHChargeHiGain->GetBinLowEdge(fHChargeHiGain->GetXaxis()->GetLast())
+                      +fHChargeHiGain->GetBinWidth(0);
+  fChargeNbinsHiGain = nbins;
+
+  CutEdges(fHChargeLoGain,nbins);
+
+  fChargeFirstLoGain = fHChargeLoGain->GetBinLowEdge(fHChargeLoGain->GetXaxis()->GetFirst());
+  fChargeLastLoGain  = fHChargeLoGain->GetBinLowEdge(fHChargeLoGain->GetXaxis()->GetLast())
+                      +fHChargeLoGain->GetBinWidth(0);
+  fChargeNbinsLoGain = nbins;
+
+  CutEdges(fHChargevsNHiGain,0);
+  CutEdges(fHChargevsNLoGain,0);
+
+}
+
+void MHCalibrationPixel::PrintChargeFitResult()
+{
+  
+  *fLog << "Results of the Summed Charges Fit: "                      << endl;
+  *fLog << "Chisquare: "        << fChargeChisquare                   << endl;
+  *fLog << "DoF: "              << fChargeNdf                         << endl;
+  *fLog << "Probability: "      << fChargeProb                        << endl;
+  *fLog                                                               << endl;
+  
+}
+
+void MHCalibrationPixel::PrintTimeFitResult()
+{
+
+  *fLog << "Results of the Time Slices Fit: "                        << endl;
+  *fLog << "Chisquare: "   << fTimeChisquare                         << endl;
+  *fLog << "Ndf: "         << fTimeNdf                               << endl;
+  *fLog << "Probability: " << fTimeProb                              << endl;
+  *fLog                                                              << endl;
+
+}
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h	(revision 2734)
@@ -0,0 +1,174 @@
+#ifndef MARS_MHCalibrationPixel
+#define MARS_MHCalibrationPixel
+
+#ifndef ROOT_TH1
+#include "TH1.h"
+#endif
+
+#ifndef ROOT_TH1
+#include "TH1F.h"
+#endif
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+#ifndef ROOT_TF1
+#include "TF1.h"
+#endif
+
+#ifndef ROOT_TProfile
+#include "TProfile.h"
+#endif
+
+#ifndef ROOT_TArrayF
+#include "TArrayF.h"
+#endif
+
+class TPaveText;
+class TMath;
+class MParList;
+
+class MHCalibrationPixel : public MH
+{
+
+private:
+
+  Int_t fPixId;                  // Pixel Nr
+  Int_t fTotalEntries;           // Number of entries
+
+  TArrayF *fHiGains;
+  TArrayF *fLoGains;
+
+protected:
+
+  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 Low Gain
+  TH1I* fHTimeLoGain;            // Mean arrival time in number of FADC sice
+  TH1I* fHChargevsNLoGain;       // Summed Charge vs. Event Nr. 
+
+  TF1* fChargeGausFit;
+  TF1* fTimeGausFit;
+  
+  TProfile* fHivsLoGain;
+
+  TPaveText *fFitLegend;  
+  
+  Axis_t  fLowerFitRange;
+  Axis_t  fChargeFirstHiGain;
+  Axis_t  fChargeLastHiGain;
+  Int_t   fChargeNbinsHiGain;
+
+  Axis_t  fChargeFirstLoGain;
+  Axis_t  fChargeLastLoGain;
+  Int_t   fChargeNbinsLoGain;
+
+  Bool_t fFitOK;
+
+  Double_t fChargeChisquare;
+  Double_t fChargeProb;
+  Int_t    fChargeNdf;
+
+  Double_t fChargeMean;
+  Double_t fChargeMeanErr;
+  Double_t fChargeSigma;
+  Double_t fChargeSigmaErr;
+  
+  Double_t fTimeChisquare;
+  Double_t fTimeProb;
+  Int_t    fTimeNdf;
+
+  Double_t fTimeMean;
+  Double_t fTimeSigma;
+
+  Stat_t   fTimeLowerFitRange;
+  Stat_t   fTimeUpperFitRange;
+  
+  Bool_t fUseLoGain;
+
+  Double_t fOffset;
+  Double_t fSlope;
+  
+  virtual void DrawLegend();
+  
+public:
+
+  MHCalibrationPixel(const char *name=NULL, const char *title=NULL);
+  ~MHCalibrationPixel();
+
+  void ChangeHistId(Int_t i);
+  
+  Bool_t SetupFill(const MParList *pList);
+  Bool_t Fill(const MParContainer *, const Stat_t w=1) { return kTRUE; }
+
+  void   SetPointInGraph(Float_t qhi, Float_t qlo);
+  void   FitHiGainvsLoGain();
+
+  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; }
+  Bool_t UseLoGain();
+
+  const TH1F *GetHCharge()                 { return fHChargeHiGain;    }
+  const TH1F *GetHCharge() const           { return fHChargeHiGain;    }
+
+  const Double_t GetChargeMean()     const { return fChargeMean;    }
+  const Double_t GetChargeMeanErr()  const { return fChargeMeanErr; }
+  const Double_t GetChargeSigma()    const { return fChargeSigma;   }
+  const Double_t GetChargeSigmaErr() const { return fChargeSigmaErr; }
+  const Double_t GetArea()           const { return fChargeGausFit->GetParameter(0); }
+  const Double_t GetAreaErr()        const { return fChargeGausFit->GetParError(0);  }
+
+  const Double_t GetChargeChiSquare() const { return fChargeChisquare; }
+  const Double_t GetChargeProb()      const { return fChargeProb;      }  
+  const Int_t    GetChargeNdf()       const { return fChargeNdf;       }   
+
+  const Double_t GetTimeMean()        const { return fTimeMean;  }
+  const Double_t GetTimeSigma()       const { return fTimeSigma; }
+
+  const Stat_t   GetTimeLowerFitRange()  const { return fTimeLowerFitRange;  }
+  const Stat_t   GetTimeUpperFitRange()  const { return fTimeUpperFitRange;  }
+  
+  const Double_t GetTimeChiSquare()   const { return fTimeChisquare; }
+  const Double_t GetTimeProb()        const { return fTimeProb;      }
+  const Int_t    GetTimeNdf()         const { return fTimeNdf;       }   
+  
+  const TH1I *GetHTime()                    { return fHTimeHiGain; }
+  const TH1I *GetHTime()              const { return fHTimeHiGain; }
+  
+  const TH1I *GetHChargevsN()               { return fHChargevsNHiGain; }
+  const TH1I *GetHChargevsN()         const { return fHChargevsNHiGain; }
+
+  Double_t GetOffset()  { return fOffset; }
+  Double_t GetSlope()   { return fSlope;  }
+  
+  Bool_t FitChargeHiGain(Option_t *option="RQ0");  
+  Bool_t FitTimeHiGain(Axis_t rmin=0, Axis_t rmax=0, Option_t *option="RQ0");    
+
+  Bool_t FitChargeLoGain(Option_t *option="RQ0");  
+  Bool_t FitTimeLoGain(Axis_t rmin=0, Axis_t rmax=0, Option_t *option="RQ0");    
+
+  virtual void Draw(Option_t *option="");
+  virtual void CutAllEdges();
+  virtual void Reset();
+
+  void SetLowerFitRange(Axis_t min)                {  fLowerFitRange = min; }
+
+  void PrintChargeFitResult();
+  void PrintTimeFitResult();  
+
+  Bool_t IsFitOK()                           {  return fFitOK;          }
+  
+  ClassDef(MHCalibrationPixel, 1) 
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mcalib/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/Makefile	(revision 2734)
+++ /trunk/MagicSoft/Mars/mcalib/Makefile	(revision 2734)
@@ -0,0 +1,61 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+include ../Makefile.conf.$(OSTYPE)
+include ../Makefile.conf.general
+
+#
+# Handling name of the Root Dictionary Files
+#
+CINT  = Calib
+
+#
+# Library name to creatre
+#
+LIB   = mcalib.a
+
+#
+#  connect the include files defined in the config.mk file
+#
+INCLUDES = -I. -I../mbase -I../mhist -I../mgui -I../mgeom -I../manalysis \
+	   -I../mraw
+# mhist: MBinning MH 
+# mgui:  MCamEvent (McalibrationCam)
+# mgeom: MGeomCam (McalibrationCam - necessary?)
+# manalysis: MExtractedSignal, MCerPhotEvt (move to mcalib?)
+# mraw: MRawRunHeader, MRawEvtHeader, MRawEvtPixelIter (3xMCalibrationCalc)
+
+
+#------------------------------------------------------------------------------
+
+.SUFFIXES: .c .cc .cxx .h .hxx .o 
+
+SRCFILES = MCalibrate.cc \
+	   MCalibrationCalc.cc \
+           MCalibrationPix.cc  \
+           MCalibrationBlindPix.cc  \
+           MCalibrationPINDiode.cc  \
+           MCalibrationCam.cc \
+           MHCalibrationBlindPixel.cc \
+           MHCalibrationPINDiode.cc \
+           MHCalibrationPixel.cc
+
+SRCS    = $(SRCFILES)
+HEADERS = $(SRCFILES:.cc=.h)
+OBJS    = $(SRCFILES:.cc=.o) 
+
+############################################################
+
+all: $(LIB)
+
+include ../Makefile.rules
+
+clean:	rmcint rmobjs rmcore rmlib
+
+mrproper:	clean rmbak
+
+# @endcode
Index: /trunk/MagicSoft/Mars/mhist/HistLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 2733)
+++ /trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 2734)
@@ -52,18 +52,5 @@
 #pragma link C++ class MHPixVsTime+;
 
-#pragma link C++ class MHCalibrationPINDiode+;
-#pragma link C++ class MHCalibrationBlindPixel+;
-#pragma link C++ class MHCalibrationPixel+;
-
 #pragma link C++ class MHSimulatedAnnealing+;
 
 #endif
-
-
-
-
-
-
-
-
-
Index: unk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.cc	(revision 2733)
+++ 	(revision )
@@ -1,484 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug 11/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//  MHCalibrationBlindPixel                                                 //
-//                                                                          //
-//  Performs all the necessary fits to extract the mean number of photons   //
-//              out of the derived light flux                               //
-//                                                                          //
-//////////////////////////////////////////////////////////////////////////////
-#include "MHCalibrationBlindPixel.h"
-#include "MHCalibrationConfig.h"
-#include "MCalibrationFits.h"
-
-#include <TStyle.h>
-#include <TMath.h>
-#include <TPad.h>
-
-#include <TMinuit.h>
-#include <TFitter.h>
-
-#include <TF1.h>
-#include <TH2.h>
-#include <TCanvas.h>
-#include <TPaveText.h>
-#include <TRandom.h>
-
-#include "MBinning.h"
-#include "MParList.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MHCalibrationBlindPixel);
-
-using namespace std;
-// --------------------------------------------------------------------------
-//
-// Default Constructor. 
-//
-MHCalibrationBlindPixel::MHCalibrationBlindPixel(const char *name, const char *title)
-  : 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.)
-{
-
-    fName  = name  ? name  : "MHCalibrationBlindPixel";
-    fTitle = title ? title : "Fill the accumulated charges and times all Blind Pixel events and perform fits";
-
-    // Create a large number of bins, later we will rebin
-    fBlindPixelChargefirst = -1000.;
-    fBlindPixelChargelast  = gkStartBlindPixelBinNr;
-    fBlindPixelChargenbins = gkStartBlindPixelBinNr+(int)fBlindPixelChargefirst;
-
-    fHBlindPixelCharge = new TH1F("HBlindPixelCharge","Distribution of Summed FADC Slices",
-				  fBlindPixelChargenbins,fBlindPixelChargefirst,fBlindPixelChargelast);
-    fHBlindPixelCharge->SetXTitle("Sum FADC Slices");
-    fHBlindPixelCharge->SetYTitle("Nr. of events");
-    fHBlindPixelCharge->Sumw2();
-
-    Axis_t tfirst = -0.5;
-    Axis_t tlast  = 15.5;
-    Int_t nbins   = 16;
-
-    fHBlindPixelTime = new TH1I("HBlindPixelTime","Distribution of Mean Arrival Times",nbins,tfirst,tlast);
-    fHBlindPixelTime->SetXTitle("Mean Arrival Times [FADC slice nr]");
-    fHBlindPixelTime->SetYTitle("Nr. of events");
-    fHBlindPixelTime->Sumw2();
-
-    // We define a reasonable number and later enlarge it if necessary
-    nbins = 20000;
-    Axis_t nfirst = -0.5;
-    Axis_t nlast  = (Axis_t)nbins - 0.5;
-
-    fHBlindPixelChargevsN = new TH1I("HBlindPixelChargevsN","Sum of Charges vs. Event Number",nbins,nfirst,nlast);
-    fHBlindPixelChargevsN->SetXTitle("Event Nr.");
-    fHBlindPixelChargevsN->SetYTitle("Sum of FADC slices");
-
-    fgSinglePheFitFunc = &gfKto8;
-    fgSinglePheFitNPar = 5;
-}
-
-MHCalibrationBlindPixel::~MHCalibrationBlindPixel()
-{
-
-  delete fHBlindPixelCharge;
-  delete fHBlindPixelTime;
-
-  if (fSinglePheFit)
-    delete fSinglePheFit;
-  if (fSinglePhePedFit)
-    delete fSinglePhePedFit;
-  if (fTimeGausFit)
-    delete fTimeGausFit;
-}
-
-
-
-void MHCalibrationBlindPixel::ResetBin(Int_t i)
-{
-    fHBlindPixelCharge->SetBinContent (i, 1.e-20);
-    fHBlindPixelTime->SetBinContent(i, 1.e-20);
-}
-
-
-// -------------------------------------------------------------------------
-//
-// Draw a legend with the fit results
-//
-void MHCalibrationBlindPixel::DrawLegend()
-{
-
-  fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
-
-  if (fFitOK) 
-      fFitLegend->SetFillColor(80);
-  else
-      fFitLegend->SetFillColor(2);    
-  
-  fFitLegend->SetLabel("Results of the single PhE Fit (to k=6):");
-  fFitLegend->SetTextSize(0.05);
-
-  const TString line1 = 
-  Form("Mean: #lambda = %2.2f #pm %2.2f",GetLambda(),GetLambdaErr());
-  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());
-  fFitLegend->AddText(line2);
-
-  const TString line3 =
-  Form("Width Pedestal: #sigma_{0} = %2.2f #pm %2.2f",GetSigma0(),GetSigma0Err());
-  fFitLegend->AddText(line3);
-
-  const TString line4 =
-  Form("1^{st} Phe-peak: #mu_{1} = %2.2f #pm %2.2f",GetMu1(),GetMu1Err());
-  fFitLegend->AddText(line4);
-
-  const TString line5 =
-  Form("Width 1^{st} Phe-peak: #sigma_{1} = %2.2f #pm %2.2f",GetSigma1(),GetSigma1Err());
-  fFitLegend->AddText(line5);
-
-  const TString line7 =
-  Form("#chi^{2} / N_{dof}: %4.2f / %3i",GetChiSquare(),GetNdf());
-  fFitLegend->AddText(line7);
-
-  const TString line8 =
-  Form("Probability: %4.2f ",GetProb());
-  fFitLegend->AddText(line8);
-
-  if (fFitOK)
-    fFitLegend->AddText("Result of the Fit: OK");
-  else
-    fFitLegend->AddText("Result of the Fit: NOT OK");
-
-  fFitLegend->SetBit(kCanDelete);
-  fFitLegend->Draw();
-
-}
-
-
-// -------------------------------------------------------------------------
-//
-// Draw the histogram
-//
-void MHCalibrationBlindPixel::Draw(Option_t *opt) 
-{
-
-    gStyle->SetOptFit(0);
-    gStyle->SetOptStat(1111111);
-
-    TCanvas *c = MakeDefCanvas(this,550,700);
-
-    c->Divide(2,2);
-
-    gROOT->SetSelectedPad(NULL);
-
-    c->cd(1);
-    gPad->SetLogy(1);
-    gPad->SetTicks();
-
-    fHBlindPixelCharge->DrawCopy(opt);
-    
-    if (fSinglePheFit)
-      {
-        if (fFitOK)
-	  fSinglePheFit->SetLineColor(kGreen);          
-        else
-          fSinglePheFit->SetLineColor(kRed);
-
-        fSinglePheFit->DrawCopy("same");
-        c->Modified();
-        c->Update();
-
-	if (fSinglePhePedFit)
-	  {
-	    fSinglePhePedFit->SetLineColor(kBlue);
-	    fSinglePhePedFit->DrawCopy("same");
-	  }
-      }
-
-
-    c->cd(2);
-    DrawLegend();
-    c->Modified();
-    c->Update();
-
-    c->cd(3);
-    gPad->SetLogy(1);
-    gPad->SetBorderMode(0);
-    fHBlindPixelTime->DrawCopy(opt);
-
-    if (fHBlindPixelTime->GetFunction("GausTime"))
-      {
-        TF1 *tfit = fHBlindPixelTime->GetFunction("GausTime");
-        if (tfit->GetProb() < 0.01)
-          tfit->SetLineColor(kRed);
-        else
-          tfit->SetLineColor(kGreen);
-
-        tfit->DrawCopy("same");
-        c->Modified();
-        c->Update();
-      }
-    
-    c->cd(4);
-
-    fHBlindPixelChargevsN->DrawCopy(opt);
-
-    c->Modified();
-    c->Update();
-}
-
-
-
-Bool_t MHCalibrationBlindPixel::SimulateSinglePhe(Double_t lambda, Double_t mu0, Double_t mu1, Double_t sigma0, Double_t sigma1) 
-{
-  gRandom->SetSeed();
-
-  if (fHBlindPixelCharge->GetIntegral() != 0)
-    {
-      *fLog << err << "Histogram " << fHBlindPixelCharge->GetTitle() << " is already filled. " << endl;
-      *fLog << err << "Create new class MHCalibrationBlindPixel for simulation! " << endl;
-      return kFALSE;
-    }
-  
-  TF1 *simulateSinglePhe = new TF1("simulateSinglePhe",fgSinglePheFitFunc,
-                                   fBlindPixelChargefirst,fBlindPixelChargelast,fgSinglePheFitNPar);
-  
-  simulateSinglePhe->SetParameters(lambda,mu0,mu1,sigma0,sigma1);
-  simulateSinglePhe->SetParNames("#lambda","#mu_0","#mu_1","#sigma_0","#sigma_1");
-  simulateSinglePhe->SetNpx(fBlindPixelChargenbins);  
-
-  for (Int_t i=0;i<10000; i++) 
-    {
-      fHBlindPixelCharge->Fill(simulateSinglePhe->GetRandom());
-    }
-  
-  return kTRUE;
-}
-
-
-void MHCalibrationBlindPixel::ChangeFitFunc(BlindPixelFitFunc fitfunc, Int_t par)
-{
-  
-  fgSinglePheFitFunc = fitfunc;
-  fgSinglePheFitNPar = par;
-
-}
-
-
-
-Bool_t MHCalibrationBlindPixel::FitSinglePhe(Axis_t rmin, Axis_t rmax, Option_t *opt) 
-{
-
-  if (fSinglePheFit)
-    return kFALSE;
-
-
-  //
-  // Get the fitting ranges
-  //
-  rmin = (rmin != 0.) ? rmin : fBlindPixelChargefirst;
-  rmax = (rmax != 0.) ? rmax : fBlindPixelChargelast;
-
-  //
-  // First guesses for the fit (should be as close to reality as possible, 
-  // otherwise the fit goes gaga because of high number of dimensions ...
-  //
-  const Stat_t   entries      = fHBlindPixelCharge->Integral();
-  const Double_t lambda_guess = 0.5;
-  const Double_t mu_0_guess = fHBlindPixelCharge->GetBinCenter(fHBlindPixelCharge->GetMaximumBin());
-  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;
-
-  fSinglePheFit = new TF1("SinglePheFit",fgSinglePheFitFunc,rmin,rmax,fgSinglePheFitNPar+1);
-  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.,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.,1.5*entries);
-  //
-  // Normalize the histogram to facilitate faster fitting of the area
-  // For speed reasons, FKto8 is normalized to Sqrt(2 pi).
-  // Therefore also normalize the histogram to that value 
-  //
-  // ROOT gives us another nice example of user-unfriendly behavior:
-  // Although the normalization of the function fSinglePhe and the 
-  // Histogram fHBlindPixelCharge agree (!!), the fit does not normalize correctly INTERNALLY
-  // in the fitting procedure !!!
-  // 
-  // This has to do with the fact that the internal function histogramming 
-  // uses 100 bins and does not adapt to the binning of the fitted histogram, unlike PAW does
-  // (very important if you use Sumw2, see e.g. ROOTTALK: Mon May 26 1997 - 09:56:03 MEST)
-  // 
-  // So, WE have to adapt to that internal flaw of ROOT:
-  //
-  //  const Int_t  npx     = fSinglePheFit->GetNpx();
-  //  const Int_t  bins    = fHBlindPixelCharge->GetXaxis()->GetLast()-fHBlindPixelCharge->GetXaxis()->GetFirst();
-  //  fHBlindPixelCharge->Scale(gkSq2Pi*(float)bins/npx/entries);
-
-  // 
-  // we need this, otherwise, ROOT does not calculate the area correctly
-  // don't ask me why it does not behave correctly, it's one of the nasty
-  // mysteries of ROOT which takes you a whole day to find out :-)
-  //
-  //  fSinglePheFit->SetNpx(fChargenbins);  
-
-  fHBlindPixelCharge->Fit(fSinglePheFit,opt);
-  fHBlindPixelCharge->Fit(fSinglePheFit,opt);
-
-  fLambda = fSinglePheFit->GetParameter(0);
-  fMu0    = fSinglePheFit->GetParameter(1);
-  fMu1    = fSinglePheFit->GetParameter(2);
-  fSigma0 = fSinglePheFit->GetParameter(3);
-  fSigma1 = fSinglePheFit->GetParameter(4);
-  
-  fLambdaErr = fSinglePheFit->GetParError(0);
-  fMu0Err    = fSinglePheFit->GetParError(1);
-  fMu1Err    = fSinglePheFit->GetParError(2);
-  fSigma0Err = fSinglePheFit->GetParError(3);
-  fSigma1Err = fSinglePheFit->GetParError(4);
-
-  fProb      = fSinglePheFit->GetProb();
-  fChisquare = fSinglePheFit->GetChisquare();
-  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;
-  *fLog << "DoF: " << fNdf << endl;
-  *fLog << "Probability: " << fProb << endl;
-  *fLog << "Integral: " << fSinglePheFit->Integral(rmin,rmax);
-
-  //
-  // The fit result is accepted under condition
-  // The fit result is accepted under condition
-  // The Probability is greater than gkProbLimit (default 0.001 == 99.7%)
-  //
-  if (fProb < gkProbLimit) 
-    {
-      *fLog << warn << "Prob: " << fProb << " is smaller than the allowed value: " << gkProbLimit << endl;
-      fFitOK = kFALSE;
-      return kFALSE;
-    }
-  
-  
-  fFitOK = kTRUE;
-    
-  return kTRUE;
-}
-
- 
-void MHCalibrationBlindPixel::CutAllEdges()
-{
-
-  Int_t nbins = 50;
-
-  CutEdges(fHBlindPixelCharge,nbins);
-
-  fBlindPixelChargefirst = fHBlindPixelCharge->GetBinLowEdge(fHBlindPixelCharge->GetXaxis()->GetFirst());
-  fBlindPixelChargelast  = fHBlindPixelCharge->GetBinLowEdge(fHBlindPixelCharge->GetXaxis()->GetLast())+fHBlindPixelCharge->GetBinWidth(0);
-  fBlindPixelChargenbins = nbins;
-
-  CutEdges(fHBlindPixelChargevsN,0);
-
-}
-
-Bool_t MHCalibrationBlindPixel::FitTime(Axis_t rmin, Axis_t rmax, Option_t *opt) 
-{
-  
-  if (fTimeGausFit)
-    return kFALSE;
-
-  rmin = (rmin != 0.) ? rmin : 4.;
-  rmax = (rmax != 0.) ? rmax : 9.;
-
-  const Stat_t   entries     = fHBlindPixelTime->Integral();
-  const Double_t mu_guess    = fHBlindPixelTime->GetBinCenter(fHBlindPixelTime->GetMaximumBin());
-  const Double_t sigma_guess = (rmax - rmin)/2.;
-  const Double_t area_guess  = entries/gkSq2Pi;
-
-  fTimeGausFit = new TF1("GausTime","gaus",rmin,rmax);  
-  fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
-  fTimeGausFit->SetParNames("Area","#mu","#sigma");
-  fTimeGausFit->SetParLimits(0,0.,entries);
-  fTimeGausFit->SetParLimits(1,rmin,rmax);
-  fTimeGausFit->SetParLimits(2,0.,rmax-rmin);
-
-  fHBlindPixelTime->Fit(fTimeGausFit,opt);
-
-  rmin = fTimeGausFit->GetParameter(1) - 2.*fTimeGausFit->GetParameter(2);
-  rmax = fTimeGausFit->GetParameter(1) + 2.*fTimeGausFit->GetParameter(2);
-  fTimeGausFit->SetRange(rmin,rmax);  
-
-  fHBlindPixelTime->Fit(fTimeGausFit,opt);
-
-
-  fMeanTime     = fTimeGausFit->GetParameter(2);
-  fSigmaTime    = fTimeGausFit->GetParameter(3);
-  fMeanTimeErr  = fTimeGausFit->GetParError(2);
-  fSigmaTimeErr = fTimeGausFit->GetParError(3);
-
-  Float_t prob = fTimeGausFit->GetProb();
-
-  *fLog << "Results of the Times Fit: " << endl;
-  *fLog << "Chisquare: "   << fTimeGausFit->GetChisquare() << endl;
-  *fLog << "Ndf: "         << fTimeGausFit->GetNDF() << endl;
-  *fLog << "Probability: " << prob << endl;
-
-  if (prob < gkProbLimit) 
-    {
-      *fLog << warn << "Fit of the Arrival times failed ! " << endl;
-      return kFALSE;
-    }
-  
-  return kTRUE;
-
-}
Index: unk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCalibrationBlindPixel.h	(revision 2733)
+++ 	(revision )
@@ -1,130 +1,0 @@
-#ifndef MARS_MHCalibrationBlindPixel
-#define MARS_MHCalibrationBlindPixel
-
-#ifndef MARS_MH
-#include "MH.h"
-#endif
-
-#ifndef MARS_MHCalibrationConfig
-#include "MHCalibrationConfig.h"
-#endif
-
-#ifndef ROOT_TH1
-#include "TH1.h"
-#endif
-
-#ifndef ROOT_TH1F
-#include "TH1F.h"
-#endif
-
-#ifndef ROOT_TF1
-#include "TF1.h"
-#endif
-
-#ifndef ROOT_TPaveText
-#include "TPaveText.h"
-#endif
-
-class TMath;
-class MParList;
-class MHCalibrationBlindPixel : public MH
-{
-private:
-
-  TH1F* fHBlindPixelCharge;        //-> Histogram with the single Phe spectrum
-  TH1I* fHBlindPixelTime;          //-> Variance of summed FADC slices
-  TH1I* fHBlindPixelChargevsN;     //-> Summed Charge vs. Event Nr. 
-  
-  TF1 *fSinglePheFit;
-  TF1 *fTimeGausFit;  
-  TF1 *fSinglePhePedFit;
-
-  Axis_t  fBlindPixelChargefirst;
-  Axis_t  fBlindPixelChargelast;
-  Int_t   fBlindPixelChargenbins;
-  
-  void ResetBin(Int_t i);
-  void DrawLegend();
-
-  TPaveText *fFitLegend;
-  Bool_t fFitOK;  
-  
-  BlindPixelFitFunc fgSinglePheFitFunc;     // In the beginning, 
-  Int_t     fgSinglePheFitNPar;             // we want to be flexible using different functions
-
-  Double_t  fLambda; 
-  Double_t  fMu0; 
-  Double_t  fMu1; 
-  Double_t  fSigma0; 
-  Double_t  fSigma1; 
-
-  Double_t  fLambdaErr; 
-  Double_t  fMu0Err; 
-  Double_t  fMu1Err; 
-  Double_t  fSigma0Err; 
-  Double_t  fSigma1Err; 
-
-  Double_t  fChisquare; 
-  Double_t  fProb;      
-  Int_t     fNdf;       
-
-  Double_t  fMeanTime; 
-  Double_t  fMeanTimeErr; 
-  Double_t  fSigmaTime; 
-  Double_t  fSigmaTimeErr; 
-  
-  Double_t fLambdaCheck;
-  Double_t fLambdaCheckErr;
-
-public:
-
-  MHCalibrationBlindPixel(const char *name=NULL, const char *title=NULL);
-  ~MHCalibrationBlindPixel();
-
-  Bool_t FillBlindPixelCharge(Float_t q)             { return fHBlindPixelCharge->Fill(q) > -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;  }  
-  
-  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 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 GetMeanTime()      const { return fMeanTime; }
-  const Double_t GetMeanTimeErr()    const { return fMeanTimeErr; }
-  const Double_t GetSigmaTime()      const { return fSigmaTime; }
-  const Double_t GetSigmaTimeErr()    const { return fSigmaTimeErr; }
-
-  Bool_t SimulateSinglePhe(Double_t lambda,
-                           Double_t mu0,
-                           Double_t mu1,
-                           Double_t sigma0,
-                           Double_t sigma1);
-  
-  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+");
-
-  void ChangeFitFunc(BlindPixelFitFunc fitfunc, Int_t par=5);
-
-  void CutAllEdges();
-  void Draw(Option_t *option="");
-
-  Bool_t IsFitOK() { return fFitOK; }
-
-  ClassDef(MHCalibrationBlindPixel, 1) 
-};
-
-#endif  /* MARS_MHCalibrationBlindPixel */
Index: unk/MagicSoft/Mars/mhist/MHCalibrationConfig.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCalibrationConfig.h	(revision 2733)
+++ 	(revision )
@@ -1,28 +1,0 @@
-#ifndef MARS_MHCalibrationConfig
-#define MARS_MHCalibrationConfig
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MHCalibrationConfig                                                     //
-//                                                                         //
-// Contains all configuration data of the Calibration                      //
-//                       i                                                  //
-/////////////////////////////////////////////////////////////////////////////
-
-
-// Global rejection criteria for the acceptance of a fit: Prob=0.01 == 99% Probability
-const Float_t gkProbLimit = 0.001;
-
-// Starting number of bins for the histo:
-const Int_t gkStartBlindPixelBinNr = 10000;
-
-// Starting number of bins for the histo: (maximum by hardware: 4080)
-const Int_t gkStartPINDiodeBinNr = 4000;
-
-// Square root of 2 pi:
-const Float_t gkSq2Pi = 2.506628274631;
-
-// typedef to the fitting functions for the blind pixel
-typedef Double_t (*BlindPixelFitFunc)(Double_t *, Double_t *);
-
-#endif /* MARS_MHCalibrationBlindPixelConfig */
Index: unk/MagicSoft/Mars/mhist/MHCalibrationPINDiode.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCalibrationPINDiode.cc	(revision 2733)
+++ 	(revision )
@@ -1,111 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug 11/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//  MHCalibrationPINDiode                                                 //
-//                                                                          //
-//  Performs all the necessary fits to extract the mean number of photons   //
-//              out of the derived light flux                               //
-//                                                                          //
-//////////////////////////////////////////////////////////////////////////////
-#include "MHCalibrationPINDiode.h"
-#include "MHCalibrationConfig.h"
-
-#include <TStyle.h>
-#include <TMath.h>
-
-#include <TMinuit.h>
-#include <TFitter.h>
-
-#include <TF1.h>
-#include <TH2.h>
-#include <TCanvas.h>
-#include <TPaveText.h>
-#include <TRandom.h>
-
-#include "MBinning.h"
-#include "MParList.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MHCalibrationPINDiode);
-
-using namespace std;
-// --------------------------------------------------------------------------
-//
-// Default Constructor. 
-//
-MHCalibrationPINDiode::MHCalibrationPINDiode(const char *name, const char *title)
-    : fVarGausFit(NULL)
-{
-
-    fName  = name  ? name  : "MHCalibrationPINDiode";
-    fTitle = title ? title : "Fill the accumulated charges and times all PINDiode events and perform fits";
-
-    // Create a large number of bins, later we will rebin
-    fChargeFirstHiGain = -1000.;
-    fChargeLastHiGain  = gkStartPINDiodeBinNr;
-    fChargeNbinsHiGain = gkStartPINDiodeBinNr;
-
-    fHPCharge = new TH1I("HPCharge","Distribution of Summed FADC Slices",
-			 fChargeNbinsHiGain,fChargeFirstHiGain,fChargeLastHiGain);
-    fHPCharge->SetXTitle("Sum FADC Slices");
-    fHPCharge->SetYTitle("Nr. of events");
-    fHPCharge->Sumw2();
-
-    fErrChargeFirst = 0.;
-    fErrChargeLast  = gkStartPINDiodeBinNr;
-    fErrChargeNbins = gkStartPINDiodeBinNr;
-
-    fHErrCharge = new TH1F("HErrCharge","Distribution of Variances of Summed FADC Slices",fErrChargeNbins,fErrChargeFirst,fErrChargeLast);
-    fHErrCharge->SetXTitle("Variance Summed FADC Slices");
-    fHErrCharge->SetYTitle("Nr. of events");
-    fHErrCharge->Sumw2();
-
-    Int_t tfirst = 0;
-    Int_t tlast  = 31;
-    Int_t nbins   = 32;
-
-    fHPTime = new TH1I("HPTime","Distribution of Mean Arrival Times",nbins,tfirst,tlast);
-    fHPTime->SetXTitle("Mean Arrival Times [FADC slice nr]");
-    fHPTime->SetYTitle("Nr. of events");
-    fHPTime->Sumw2();
-
-}
-
-MHCalibrationPINDiode::~MHCalibrationPINDiode()
-{
-
-  delete fHPCharge;
-  delete fHErrCharge;
-  
-  if (fVarGausFit)
-    delete fVarGausFit;
-  
-  delete fHPTime;
-
-}
-
Index: unk/MagicSoft/Mars/mhist/MHCalibrationPINDiode.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCalibrationPINDiode.h	(revision 2733)
+++ 	(revision )
@@ -1,51 +1,0 @@
-#ifndef MARS_MHCalibrationPINDiode
-#define MARS_MHCalibrationPINDiode
-
-#ifndef MARS_MHCalibrationPixel
-#include "MHCalibrationPixel.h"
-#endif
-
-#ifndef MARS_MH
-#include "MH.h"
-#endif
-
-#ifndef ROOT_TH1
-#include "TH1.h"
-#endif
-
-#ifndef ROOT_TH1F
-#include "TH1F.h"
-#endif
-
-#ifndef ROOT_TF1
-#include "TF1.h"
-#endif
-
-class MHCalibrationPINDiode : public MHCalibrationPixel
-{
-private:
-
-  TH1I* fHPCharge;             //-> Histogram containing the summed 32 PINDiode slices
-  TH1F* fHErrCharge;           //-> Variance of summed FADC slices
-  TH1I* fHPTime;             //-> Histogram with time evolution of summed charges
-  
-  
-  TF1 *fVarGausFit;
-  
-  Float_t  fErrChargeFirst;
-  Float_t  fErrChargeLast;
-  UShort_t fErrChargeNbins;
-
-public:
-
-  MHCalibrationPINDiode(const char *name=NULL, const char *title=NULL);
-  ~MHCalibrationPINDiode();
-
-  const Double_t GetTime()      const { return fVarGausFit->GetParameter(2); }
-  const Double_t GetErrTime()    const { return fVarGausFit->GetParameter(3); }
-
-  ClassDef(MHCalibrationPINDiode, 0) 
-};
-
-#endif
-
Index: unk/MagicSoft/Mars/mhist/MHCalibrationPixel.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.cc	(revision 2733)
+++ 	(revision )
@@ -1,897 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug 11/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//  MHCalibrationPixel                                                 //
-//                                                                          //
-//  Performs all the necessary fits to extract the mean number of photons   //
-//              out of the derived light flux                               //
-//                                                                          //
-//////////////////////////////////////////////////////////////////////////////
-
-#include "MHCalibrationPixel.h"
-#include "MHCalibrationConfig.h"
-#include "MCalibrationFits.h"
-
-#include <TStyle.h>
-#include <TMath.h>
-
-#include <TFitter.h>
-#include <TGraph.h>
-#include <TAxis.h>
-
-#include <TF1.h>
-#include <TH2.h>
-#include <TProfile.h>
-#include <TCanvas.h>
-#include <TPad.h>
-#include <TPaveText.h>
-
-#include "MParList.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MHCalibrationPixel);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor. 
-//
-MHCalibrationPixel::MHCalibrationPixel(const char *name, const char *title)
-      : fPixId(-1),
-	fTotalEntries(0),
-	fHiGains(NULL),
-	fLoGains(NULL),
-        fChargeGausFit(NULL), 
-	fTimeGausFit(NULL), 
-	fHivsLoGain(NULL),
-	fFitLegend(NULL),
-	fLowerFitRange(-2000.),
-	fChargeFirstHiGain(-2000.5),
-	fChargeLastHiGain(9999.5),
-	fChargeNbinsHiGain(12000),
-	fChargeFirstLoGain(-2000.5),
-	fChargeLastLoGain(9999.5),
-	fChargeNbinsLoGain(1200),
-        fFitOK(kFALSE),
-        fChargeChisquare(-1.),
-        fChargeProb(-1.),
-        fChargeNdf(-1),
-        fTimeChisquare(-1.),
-        fTimeProb(-1.),
-        fTimeNdf(-1),
-        fTimeMean(-1.),
-        fTimeSigma(-1.),
-        fTimeLowerFitRange(3.),
-        fTimeUpperFitRange(9.),
-	fUseLoGain(kFALSE),
-	fOffset(0.),
-	fSlope(0.)
-{ 
-
-    fName  = name  ? name  : "MHCalibrationPixel";
-    fTitle = title ? title : "Fill the accumulated charges and times of all events and perform fits";
-
-    // 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)");
-    fHChargeLoGain->SetYTitle("Nr. of events");
-    fHChargeLoGain->Sumw2();
-
-    fHChargeLoGain->SetDirectory(NULL);
-
-    Axis_t tfirst = -0.5;
-    Axis_t tlast  = 15.5;
-    Int_t  ntbins = 16;
-
-    fHTimeHiGain = new TH1I("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->Sumw2();
-
-    fHTimeHiGain->SetDirectory(NULL);
-
-    fHTimeLoGain = new TH1I("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->Sumw2();
-
-    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();
-
-}
-
-MHCalibrationPixel::~MHCalibrationPixel()
-{
-
-  delete fHChargeHiGain;
-  delete fHTimeHiGain;
-  delete fHChargevsNHiGain;
-
-  delete fHChargeLoGain;
-  delete fHTimeLoGain;
-  delete fHChargevsNLoGain;
-
-  delete fHiGains;
-  delete fLoGains;
-
-  if (fChargeGausFit)
-    delete fChargeGausFit;
-  if (fTimeGausFit)
-    delete fTimeGausFit;
-  if (fFitLegend)
-    delete fFitLegend;
-  if (fHivsLoGain)
-    delete fHivsLoGain;
-
-
-}
-
-
-void MHCalibrationPixel::ChangeHistId(Int_t id)
-{
-
-  fPixId = id;
-
-  //
-  // Names Hi gain Histograms
-  //
-  TString nameQHiGain = TString(fHChargeHiGain->GetName());
-  nameQHiGain += id;
-  fHChargeHiGain->SetName(nameQHiGain.Data());
-
-  TString nameTHiGain = TString(fHTimeHiGain->GetName());
-  nameTHiGain += id;
-  fHTimeHiGain->SetName(nameTHiGain.Data());
-
-  TString nameQvsNHiGain  = TString(fHChargevsNHiGain->GetName());
-  nameQvsNHiGain += id;
-  fHChargevsNHiGain->SetName(nameQvsNHiGain.Data());
-
-  //
-  // Title Hi gain Histograms
-  //
-  TString titleQHiGain = TString(fHChargeHiGain->GetTitle());
-  titleQHiGain += id;
-  fHChargeHiGain->SetTitle(titleQHiGain.Data());
-
-  TString titleTHiGain = TString(fHTimeHiGain->GetTitle());
-  titleTHiGain += id;
-  fHTimeHiGain->SetTitle(titleTHiGain.Data());
-
-  TString titleQvsNHiGain  = TString(fHChargevsNHiGain->GetTitle());
-  titleQvsNHiGain += id;
-  fHChargevsNHiGain->SetTitle(titleQvsNHiGain.Data());
-
-  //
-  // Names Low Gain Histograms
-  //
-  TString nameQLoGain = TString(fHChargeLoGain->GetName());
-  nameQLoGain += id;
-  fHChargeLoGain->SetName(nameQLoGain.Data());
-
-  TString nameTLoGain = TString(fHTimeLoGain->GetName());
-  nameTLoGain += id;
-  fHTimeLoGain->SetName(nameTLoGain.Data());
-
-  TString nameQvsNLoGain  = TString(fHChargevsNLoGain->GetName());
-  nameQvsNLoGain += id;
-  fHChargevsNLoGain->SetName(nameQvsNLoGain.Data());
-
-  //
-  // Titles Low Gain Histograms
-  //
-  TString titleQLoGain = TString(fHChargeLoGain->GetTitle());
-  titleQLoGain += id;
-  fHChargeLoGain->SetTitle(titleQLoGain.Data());
-
-  TString titleTLoGain = TString(fHTimeLoGain->GetTitle());
-  titleTLoGain += id;
-  fHTimeLoGain->SetTitle(titleTLoGain.Data());
-
-  TString titleQvsNLoGain  = TString(fHChargevsNLoGain->GetTitle());
-  titleQvsNLoGain += id;
-  fHChargevsNLoGain->SetTitle(titleQvsNLoGain.Data());
-}
-
-
-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);
-  
-  fChargeLastHiGain     = 9999.5;
-
-  fHChargeHiGain->GetXaxis()->SetRangeUser(0.,fChargeLastHiGain);
-
- 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);
-  
-  fChargeLastLoGain     = 9999.5;
-
-  fHChargeLoGain->GetXaxis()->SetRangeUser(0.,fChargeLastLoGain);
-
-  return;
-}
-
-
-// -------------------------------------------------------------------------
-//
-// Set the binnings and prepare the filling of the histograms
-//
-Bool_t MHCalibrationPixel::SetupFill(const MParList *plist)
-{
-
-  fHChargeHiGain->Reset();
-  fHTimeHiGain->Reset();
-  fHChargeLoGain->Reset();
-  fHTimeLoGain->Reset();
-
-  return kTRUE;
-}
-
-
-Bool_t MHCalibrationPixel::UseLoGain()
-{
-
-  if (fHChargeHiGain->Integral() > fHChargeLoGain->Integral())
-    {
-      fUseLoGain = kFALSE;
-      return kFALSE;
-    }
-  else
-    {
-      fUseLoGain = kTRUE;
-      return kTRUE;
-    }
-}
-
-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);
-
-}
-
-
-// -------------------------------------------------------------------------
-//
-// Draw a legend with the fit results
-//
-void MHCalibrationPixel::DrawLegend()
-{
-
-  fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
-
-  if (fFitOK) 
-      fFitLegend->SetFillColor(80);
-  else
-      fFitLegend->SetFillColor(2);    
-  
-  fFitLegend->SetLabel("Results of the Gauss Fit:");
-  fFitLegend->SetTextSize(0.05);
-
-  const TString line1 = 
-    Form("Mean: Q_{#mu} = %2.2f #pm %2.2f",fChargeMean,fChargeMeanErr);
-
-  fFitLegend->AddText(line1);
-
-
-  const TString line4 =
-    Form("Sigma: #sigma_{Q} = %2.2f #pm %2.2f",fChargeSigma,fChargeSigmaErr);
-
-  fFitLegend->AddText(line4);
-
-
-  const TString line7 =
-    Form("#chi^{2} / N_{dof}: %4.2f / %3i",fChargeChisquare,fChargeNdf);
-
-  fFitLegend->AddText(line7);
-
-
-  const TString line8 =
-    Form("Probability: %4.3f ",fChargeProb);
-
-  fFitLegend->AddText(line8);
-
-  if (fFitOK)
-    fFitLegend->AddText("Result of the Fit: OK");
-  else
-    fFitLegend->AddText("Result of the Fit: NOT OK");
-
-  fFitLegend->SetBit(kCanDelete);
-  fFitLegend->Draw();
-
-}
-
-
-// -------------------------------------------------------------------------
-//
-// Draw the histogram
-//
-void MHCalibrationPixel::Draw(Option_t *opt) 
-{
-
-  if (!fHivsLoGain)
-    FitHiGainvsLoGain();
-      
-  gStyle->SetOptFit(0);
-  gStyle->SetOptStat(1111111);
-  
-  TCanvas *c = MakeDefCanvas(this,600,900); 
-  
-  gROOT->SetSelectedPad(NULL);
-  
-  c->Divide(2,4);
-  
-  c->cd(1);
-  gPad->SetBorderMode(0);
-  gPad->SetTicks();
-
-  if (fHChargeHiGain->Integral() > 0)
-    gPad->SetLogy(1);
-  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(6);
-        gPad->SetTicks();
-	gPad->SetLogy(0);
-	fHTimeLoGain->DrawCopy(opt);
-	c->Modified();
-	c->Update();
-	
-	if (fTimeGausFit)
-	  {
-	    if (fTimeChisquare > 20.) 
-	      fTimeGausFit->SetLineColor(kRed);
-	    else
-	      fTimeGausFit->SetLineColor(kGreen);
-	    
-	    fTimeGausFit->DrawCopy("same");
-	    c->Modified();
-	    c->Update();
-	  }
-      }
-    else
-      {  
-	if (fTimeGausFit)
-	  {
-	    if (fTimeChisquare > 20.) 
-	      fTimeGausFit->SetLineColor(kRed);
-	    else
-	      fTimeGausFit->SetLineColor(kGreen);
-	    
-	    fTimeGausFit->DrawCopy("same");
-	    c->Modified();
-	    c->Update();
-	  }
-
-	c->cd(6);
-        gPad->SetTicks();
-	gPad->SetLogy(0);
-	fHTimeLoGain->DrawCopy(opt);	
-	c->Modified();
-	c->Update();
-    
-      }
-    c->Modified();
-    c->Update();
-    
-    c->cd(7);
-    gPad->SetTicks();
-    fHChargevsNHiGain->DrawCopy(opt);
-    c->Modified();
-    c->Update();
-
-    c->cd(8);
-    gPad->SetTicks();
-    fHChargevsNLoGain->DrawCopy(opt);
-    c->Modified();
-    c->Update();
-
-
-}
-
-void MHCalibrationPixel::FitHiGainvsLoGain()
-{
-
-  if (fHivsLoGain)
-    return;
-
-  gStyle->SetOptFit();
-
-  fHivsLoGain = new TProfile("HiGainvsLoGain","Plot the High Gain vs. Low Gain",100,0.,1000.,0.,1000.);
-  fHivsLoGain->GetXaxis()->SetTitle("Sum of Charges High Gain");
-  fHivsLoGain->GetYaxis()->SetTitle("Sum of Charges Low Gain");
-
-  TString titleHiLoGain  = TString(fHivsLoGain->GetName());
-  titleHiLoGain += fPixId;
-  fHivsLoGain->SetName(titleHiLoGain.Data());
-
-  
-  for (Int_t i=0;i<fTotalEntries;i++)
-    fHivsLoGain->Fill(fHiGains->At(i),fLoGains->At(i),1);
-  
-  fHivsLoGain->Fit("pol1","rq","",fHivsLoGain->GetMean()-2.5*fHivsLoGain->GetRMS(),fHivsLoGain->GetMean()+2.*fHivsLoGain->GetRMS());
-  
-  fOffset = fHivsLoGain->GetFunction("pol1")->GetParameter(0);
-  fSlope  = fHivsLoGain->GetFunction("pol1")->GetParameter(1);
-  
-}
-
-
-Bool_t MHCalibrationPixel::FitTimeHiGain(Axis_t rmin, Axis_t rmax, Option_t *option)
-{
-
-  if (fTimeGausFit)
-    return kFALSE;
-
-  rmin = (rmin != 0.) ? rmin : fTimeLowerFitRange;
-  rmax = (rmax != 0.) ? rmax : fTimeUpperFitRange;
-
-  const Stat_t entries       = fHTimeHiGain->Integral();
-  const Double_t mu_guess    = fHTimeHiGain->GetBinCenter(fHTimeHiGain->GetMaximumBin());
-  const Double_t sigma_guess = (rmax - rmin)/2.;
-  const Double_t area_guess  = entries/gkSq2Pi;
-
-  TString name = TString("GausTime");
-  name += fPixId;
-  fTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);  
-
-  if (!fTimeGausFit) 
-    {
-    *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
-    return kFALSE;
-    }
-
-  fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
-  fTimeGausFit->SetParNames("Area","#mu","#sigma");
-  fTimeGausFit->SetParLimits(0,0.,entries);
-  fTimeGausFit->SetParLimits(1,rmin,rmax);
-  fTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
-  fTimeGausFit->SetRange(rmin,rmax);
-
-  fHTimeHiGain->Fit(fTimeGausFit,option);
-
-  rmin = fTimeGausFit->GetParameter(1) - 3.*fTimeGausFit->GetParameter(2);
-  rmax = fTimeGausFit->GetParameter(1) + 3.*fTimeGausFit->GetParameter(2);
-  fTimeGausFit->SetRange(rmin,rmax);  
-
-  fHTimeHiGain->Fit(fTimeGausFit,option);
-
-  fTimeChisquare = fTimeGausFit->GetChisquare();
-  fTimeNdf       = fTimeGausFit->GetNDF();
-  fTimeProb      = fTimeGausFit->GetProb();
-
-  fTimeMean      = fTimeGausFit->GetParameter(1);
-  fTimeSigma     = fTimeGausFit->GetParameter(2);
-
-  if (fTimeChisquare > 20.)  // Cannot use Probability because Ndf is sometimes < 1
-    {
-      *fLog << warn << "Fit of the Arrival times failed ! " << endl;
-      return kFALSE;
-    }
-  
-  return kTRUE;
-
-}
-
-Bool_t MHCalibrationPixel::FitTimeLoGain(Axis_t rmin, Axis_t rmax, Option_t *option)
-{
-
-  if (fTimeGausFit)
-    return kFALSE;
-
-  rmin = (rmin != 0.) ? rmin : fTimeLowerFitRange;
-  rmax = (rmax != 0.) ? rmax : fTimeUpperFitRange;
-
-  const Stat_t   entries     = fHTimeLoGain->Integral();
-  const Double_t mu_guess    = fHTimeLoGain->GetBinCenter(fHTimeLoGain->GetMaximumBin());
-  const Double_t sigma_guess = (rmax - rmin)/2.;
-  const Double_t area_guess  = entries/gkSq2Pi;
-
-  TString name = TString("GausTime");
-  name += fPixId;
-  fTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);  
-
-  if (!fTimeGausFit) 
-    {
-    *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
-    return kFALSE;
-    }
-
-  fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
-  fTimeGausFit->SetParNames("Area","#mu","#sigma");
-  fTimeGausFit->SetParLimits(0,0.,entries);
-  fTimeGausFit->SetParLimits(1,rmin,rmax);
-  fTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
-  fTimeGausFit->SetRange(rmin,rmax);
-
-  fHTimeLoGain->Fit(fTimeGausFit,option);
-
-  rmin = fTimeGausFit->GetParameter(1) - 3.*fTimeGausFit->GetParameter(2);
-  rmax = fTimeGausFit->GetParameter(1) + 3.*fTimeGausFit->GetParameter(2);
-  fTimeGausFit->SetRange(rmin,rmax);  
-
-  fHTimeLoGain->Fit(fTimeGausFit,option);
-
-  fTimeChisquare = fTimeGausFit->GetChisquare();
-  fTimeNdf       = fTimeGausFit->GetNDF();
-  fTimeProb      = fTimeGausFit->GetProb();
-
-  fTimeMean      = fTimeGausFit->GetParameter(1);
-  fTimeSigma     = fTimeGausFit->GetParameter(2);
-
-  if (fTimeChisquare > 20.)  // Cannot use Probability because Ndf is sometimes < 1
-    {
-      *fLog << warn << "Fit of the Arrival times failed ! " << endl;
-      return kFALSE;
-    }
-  
-  return kTRUE;
-
-}
-
-Bool_t MHCalibrationPixel::FitChargeHiGain(Option_t *option)
-{
-
-  if (fChargeGausFit)
-    return kFALSE;
-
-  //
-  // Get the fitting ranges
-  //
-  Axis_t rmin = (fLowerFitRange != 0.) ? fLowerFitRange : fChargeFirstHiGain;
-  Axis_t rmax = 0.;
-
-  //
-  // First guesses for the fit (should be as close to reality as possible, 
-  // otherwise the fit goes gaga because of high number of dimensions ...
-  //
-  const Stat_t   entries    = fHChargeHiGain->Integral();
-  const Double_t area_guess = entries/gkSq2Pi;
-  const Double_t mu_guess   = fHChargeHiGain->GetBinCenter(fHChargeHiGain->GetMaximumBin());
-  const Double_t sigma_guess = mu_guess/15.;
-
-  TString name = TString("ChargeGausFit");
-  name += fPixId;
-
-  fChargeGausFit = new TF1(name.Data(),"gaus",rmin,fChargeLastHiGain);
-
-  if (!fChargeGausFit) 
-    {
-    *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
-    return kFALSE;
-    }
-  
-  fChargeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
-  fChargeGausFit->SetParNames("Area","#mu","#sigma");
-  fChargeGausFit->SetParLimits(0,0.,entries);
-  fChargeGausFit->SetParLimits(1,rmin,fChargeLastHiGain);
-  fChargeGausFit->SetParLimits(2,0.,fChargeLastHiGain-rmin);
-  fChargeGausFit->SetRange(rmin,fChargeLastHiGain);
-
-  fHChargeHiGain->Fit(fChargeGausFit,option);
-  
-  Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.0*fChargeGausFit->GetParameter(2);
-  
-  rmin = (rtry < rmin ? rmin : rtry);
-  rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
-  fChargeGausFit->SetRange(rmin,rmax);  
-
-  fHChargeHiGain->Fit(fChargeGausFit,option);
-
-  fChargeChisquare = fChargeGausFit->GetChisquare();
-  fChargeNdf       = fChargeGausFit->GetNDF();
-  fChargeProb      = fChargeGausFit->GetProb();
-  fChargeMean      = fChargeGausFit->GetParameter(1);
-  fChargeMeanErr   = fChargeGausFit->GetParError(1);
-  fChargeSigma     = fChargeGausFit->GetParameter(2);
-  fChargeSigmaErr  = fChargeGausFit->GetParError(2);
-
-  //
-  // The fit result is accepted under condition
-  // The Probability is greater than gkProbLimit (default 0.001 == 99.9%)
-  //
-  if (fChargeProb < gkProbLimit) 
-    {
-      *fLog << warn << "Prob: " << fChargeProb 
-            << " is smaller than the allowed value: " << gkProbLimit << endl;
-      fFitOK = kFALSE;
-      return kFALSE;
-    }
-  
-  fFitOK = kTRUE;
-  return kTRUE;
-}
-
-
-Bool_t MHCalibrationPixel::FitChargeLoGain(Option_t *option)
-{
-
-  if (fChargeGausFit)
-    return kFALSE;
-
-  //
-  // Get the fitting ranges
-  //
-  Axis_t rmin = (fLowerFitRange != 0.) ? fLowerFitRange : fChargeFirstLoGain;
-  Axis_t rmax = 0.;
-
-  //
-  // First guesses for the fit (should be as close to reality as possible, 
-  // otherwise the fit goes gaga because of high number of dimensions ...
-  //
-  const Stat_t   entries    = fHChargeLoGain->Integral();
-  const Double_t area_guess = entries/gkSq2Pi;
-  const Double_t mu_guess   = fHChargeLoGain->GetBinCenter(fHChargeLoGain->GetMaximumBin());
-  const Double_t sigma_guess = mu_guess/15.;
-
-  TString name = TString("ChargeGausFit");
-  name += fPixId;
-
-  fChargeGausFit = new TF1(name.Data(),"gaus",rmin,fChargeLastLoGain);
-
-  if (!fChargeGausFit) 
-    {
-    *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
-    return kFALSE;
-    }
-  
-  fChargeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
-  fChargeGausFit->SetParNames("Area","#mu","#sigma");
-  fChargeGausFit->SetParLimits(0,0.,entries);
-  fChargeGausFit->SetParLimits(1,rmin,fChargeLastLoGain);
-  fChargeGausFit->SetParLimits(2,0.,fChargeLastLoGain-rmin);
-  fChargeGausFit->SetRange(rmin,fChargeLastLoGain);
-
-  fHChargeLoGain->Fit(fChargeGausFit,option);
-  
-  Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.*fChargeGausFit->GetParameter(2);
-  
-  rmin = (rtry < rmin ? rmin : rtry);
-  rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
-  fChargeGausFit->SetRange(rmin,rmax);  
-
-  fHChargeLoGain->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);  
-
-  // fHChargeLoGain->Fit(fChargeGausFit,option);
-
-  fChargeChisquare = fChargeGausFit->GetChisquare();
-  fChargeNdf       = fChargeGausFit->GetNDF();
-  fChargeProb      = fChargeGausFit->GetProb();
-  fChargeMean      = fChargeGausFit->GetParameter(1);
-  fChargeMeanErr   = fChargeGausFit->GetParError(1);
-  fChargeSigma     = fChargeGausFit->GetParameter(2);
-  fChargeSigmaErr  = fChargeGausFit->GetParError(2);
-
-  //
-  // The fit result is accepted under condition
-  // The Probability is greater than gkProbLimit (default 0.01 == 99%)
-  //
-  if (fChargeProb < gkProbLimit) 
-    {
-      *fLog << warn << "Prob: " << fChargeProb << " is smaller than the allowed value: " << gkProbLimit << endl;
-      fFitOK = kFALSE;
-      return kFALSE;
-    }
-  
-  
-  fFitOK = kTRUE;
-    
-  return kTRUE;
-}
-
- 
-void MHCalibrationPixel::CutAllEdges()
-{
-
-  Int_t nbins = 30;
-
-  CutEdges(fHChargeHiGain,nbins);
-
-  fChargeFirstHiGain = fHChargeHiGain->GetBinLowEdge(fHChargeHiGain->GetXaxis()->GetFirst());
-  fChargeLastHiGain  = fHChargeHiGain->GetBinLowEdge(fHChargeHiGain->GetXaxis()->GetLast())
-                      +fHChargeHiGain->GetBinWidth(0);
-  fChargeNbinsHiGain = nbins;
-
-  CutEdges(fHChargeLoGain,nbins);
-
-  fChargeFirstLoGain = fHChargeLoGain->GetBinLowEdge(fHChargeLoGain->GetXaxis()->GetFirst());
-  fChargeLastLoGain  = fHChargeLoGain->GetBinLowEdge(fHChargeLoGain->GetXaxis()->GetLast())
-                      +fHChargeLoGain->GetBinWidth(0);
-  fChargeNbinsLoGain = nbins;
-
-  CutEdges(fHChargevsNHiGain,0);
-  CutEdges(fHChargevsNLoGain,0);
-
-}
-
-void MHCalibrationPixel::PrintChargeFitResult()
-{
-  
-  *fLog << "Results of the Summed Charges Fit: "                      << endl;
-  *fLog << "Chisquare: "        << fChargeChisquare                   << endl;
-  *fLog << "DoF: "              << fChargeNdf                         << endl;
-  *fLog << "Probability: "      << fChargeProb                        << endl;
-  *fLog                                                               << endl;
-  
-}
-
-void MHCalibrationPixel::PrintTimeFitResult()
-{
-
-  *fLog << "Results of the Time Slices Fit: "                        << endl;
-  *fLog << "Chisquare: "   << fTimeChisquare                         << endl;
-  *fLog << "Ndf: "         << fTimeNdf                               << endl;
-  *fLog << "Probability: " << fTimeProb                              << endl;
-  *fLog                                                              << endl;
-
-}
Index: unk/MagicSoft/Mars/mhist/MHCalibrationPixel.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.h	(revision 2733)
+++ 	(revision )
@@ -1,174 +1,0 @@
-#ifndef MARS_MHCalibrationPixel
-#define MARS_MHCalibrationPixel
-
-#ifndef ROOT_TH1
-#include "TH1.h"
-#endif
-
-#ifndef ROOT_TH1
-#include "TH1F.h"
-#endif
-
-#ifndef MARS_MH
-#include "MH.h"
-#endif
-
-#ifndef ROOT_TF1
-#include "TF1.h"
-#endif
-
-#ifndef ROOT_TProfile
-#include "TProfile.h"
-#endif
-
-#ifndef ROOT_TArrayF
-#include "TArrayF.h"
-#endif
-
-class TPaveText;
-class TMath;
-class MParList;
-
-class MHCalibrationPixel : public MH
-{
-
-private:
-
-  Int_t fPixId;                  // Pixel Nr
-  Int_t fTotalEntries;           // Number of entries
-
-  TArrayF *fHiGains;
-  TArrayF *fLoGains;
-
-protected:
-
-  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 Low Gain
-  TH1I* fHTimeLoGain;            // Mean arrival time in number of FADC sice
-  TH1I* fHChargevsNLoGain;       // Summed Charge vs. Event Nr. 
-
-  TF1* fChargeGausFit;
-  TF1* fTimeGausFit;
-  
-  TProfile* fHivsLoGain;
-
-  TPaveText *fFitLegend;  
-  
-  Axis_t  fLowerFitRange;
-  Axis_t  fChargeFirstHiGain;
-  Axis_t  fChargeLastHiGain;
-  Int_t   fChargeNbinsHiGain;
-
-  Axis_t  fChargeFirstLoGain;
-  Axis_t  fChargeLastLoGain;
-  Int_t   fChargeNbinsLoGain;
-
-  Bool_t fFitOK;
-
-  Double_t fChargeChisquare;
-  Double_t fChargeProb;
-  Int_t    fChargeNdf;
-
-  Double_t fChargeMean;
-  Double_t fChargeMeanErr;
-  Double_t fChargeSigma;
-  Double_t fChargeSigmaErr;
-  
-  Double_t fTimeChisquare;
-  Double_t fTimeProb;
-  Int_t    fTimeNdf;
-
-  Double_t fTimeMean;
-  Double_t fTimeSigma;
-
-  Stat_t   fTimeLowerFitRange;
-  Stat_t   fTimeUpperFitRange;
-  
-  Bool_t fUseLoGain;
-
-  Double_t fOffset;
-  Double_t fSlope;
-  
-  virtual void DrawLegend();
-  
-public:
-
-  MHCalibrationPixel(const char *name=NULL, const char *title=NULL);
-  ~MHCalibrationPixel();
-
-  void ChangeHistId(Int_t i);
-  
-  Bool_t SetupFill(const MParList *pList);
-  Bool_t Fill(const MParContainer *, const Stat_t w=1) { return kTRUE; }
-
-  void   SetPointInGraph(Float_t qhi, Float_t qlo);
-  void   FitHiGainvsLoGain();
-
-  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; }
-  Bool_t UseLoGain();
-
-  const TH1F *GetHCharge()                 { return fHChargeHiGain;    }
-  const TH1F *GetHCharge() const           { return fHChargeHiGain;    }
-
-  const Double_t GetChargeMean()     const { return fChargeMean;    }
-  const Double_t GetChargeMeanErr()  const { return fChargeMeanErr; }
-  const Double_t GetChargeSigma()    const { return fChargeSigma;   }
-  const Double_t GetChargeSigmaErr() const { return fChargeSigmaErr; }
-  const Double_t GetArea()           const { return fChargeGausFit->GetParameter(0); }
-  const Double_t GetAreaErr()        const { return fChargeGausFit->GetParError(0);  }
-
-  const Double_t GetChargeChiSquare() const { return fChargeChisquare; }
-  const Double_t GetChargeProb()      const { return fChargeProb;      }  
-  const Int_t    GetChargeNdf()       const { return fChargeNdf;       }   
-
-  const Double_t GetTimeMean()        const { return fTimeMean;  }
-  const Double_t GetTimeSigma()       const { return fTimeSigma; }
-
-  const Stat_t   GetTimeLowerFitRange()  const { return fTimeLowerFitRange;  }
-  const Stat_t   GetTimeUpperFitRange()  const { return fTimeUpperFitRange;  }
-  
-  const Double_t GetTimeChiSquare()   const { return fTimeChisquare; }
-  const Double_t GetTimeProb()        const { return fTimeProb;      }
-  const Int_t    GetTimeNdf()         const { return fTimeNdf;       }   
-  
-  const TH1I *GetHTime()                    { return fHTimeHiGain; }
-  const TH1I *GetHTime()              const { return fHTimeHiGain; }
-  
-  const TH1I *GetHChargevsN()               { return fHChargevsNHiGain; }
-  const TH1I *GetHChargevsN()         const { return fHChargevsNHiGain; }
-
-  Double_t GetOffset()  { return fOffset; }
-  Double_t GetSlope()   { return fSlope;  }
-  
-  Bool_t FitChargeHiGain(Option_t *option="RQ0");  
-  Bool_t FitTimeHiGain(Axis_t rmin=0, Axis_t rmax=0, Option_t *option="RQ0");    
-
-  Bool_t FitChargeLoGain(Option_t *option="RQ0");  
-  Bool_t FitTimeLoGain(Axis_t rmin=0, Axis_t rmax=0, Option_t *option="RQ0");    
-
-  virtual void Draw(Option_t *option="");
-  virtual void CutAllEdges();
-  virtual void Reset();
-
-  void SetLowerFitRange(Axis_t min)                {  fLowerFitRange = min; }
-
-  void PrintChargeFitResult();
-  void PrintTimeFitResult();  
-
-  Bool_t IsFitOK()                           {  return fFitOK;          }
-  
-  ClassDef(MHCalibrationPixel, 1) 
-};
-
-#endif
Index: /trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mhist/Makefile	(revision 2733)
+++ /trunk/MagicSoft/Mars/mhist/Makefile	(revision 2734)
@@ -66,8 +66,4 @@
 	   MHCT1Supercuts.cc \
            MHCamera.cc \
-           MHCalibrationPixel.cc  \
-           MHCalibrationBlindPixel.cc \
-           MHCalibrationPINDiode.cc \
-           MHCalibrationPINDiode.cc \
            MHSupercuts.cc \
            MHSimulatedAnnealing.cc 
