Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2678)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2679)
@@ -4,4 +4,16 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2003/12/12: Markus Gaug / Michele Doro
+
+   * manalysis/MCalibrationCam.[h,cc]
+   * manalysis/MCalibrationPix.[h,cc]
+   * manalysis/MCalibrationBlindPix.[h,cc]
+   * manalysis/MCalibrationConfig.[h,cc]
+     - bug found transforming the number of photons from the blind pixel 
+	to the inner pixel. The previous results were wrong by a factor 2
+     - PIN Diode formally included
+     - Code better documented in MCalibrationCam
+
 
  2003/12/15: Thomas Bretz
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc	(revision 2678)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc	(revision 2679)
@@ -413,12 +413,7 @@
     {
       if (blindpixel.FitCharge())
-	{
-	  if (!fCalibrations->CalcNrPhotInnerPixel())
-	    *fLog << err << dbginf << "Could not calculate Number of photons from the blind pixel " << endl;
-	}
+	    *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
       else
-	{
 	  *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
-	}
 
       if (!blindpixel.FitTime())
@@ -426,7 +421,6 @@
 
       blindpixel.Draw();
-
     }
-
+  
   *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
 
@@ -450,4 +444,7 @@
       
     }
+
+  if (!fCalibrations->CalcNumPhotInsidePlexiglass())
+    *fLog << err << dbginf << "Could not calculate the number of photons from the blind pixel " << endl;
 
   fCalibrations->SetReadyToSave();
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2678)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2679)
@@ -25,13 +25,16 @@
 
 /////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MCalibrationCam                                                         //
-//                                                                         //
-// Hold the Calibration information for all pixels in the camera           //
-//                                                                         //
-// The Classes MCalibrationPix's are stored in a TClonesArray              //
-// The Class MCalibrationBlindPix and the MCalibrationPINDiode             // 
-//           are stored in separate pointers                               //
-//                                                                         //
+//                                                               
+// 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"
@@ -56,11 +59,18 @@
 //
 // Default constructor. 
-// Creates a TClonesArray of MHCalibrationPix objects, initialized to 0 entries
-// Creates an MCalibrationBlindPix and an MCalibrationPINDiode
+//
+// 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)
-    : fMeanNrPhotAvailable(kFALSE),
-      fMeanNrPhotInnerPix(-1.),
-      fMeanNrPhotInnerPixErr(-1.),
+    : fNumPhotInsidePlexiglassAvailable(kFALSE),
+      fMeanPhotInsidePlexiglass(-1.),
+      fMeanPhotErrInsidePlexiglass(-1.),
+      fNumPhotOutsidePlexiglassAvailable(kFALSE),
+      fMeanPhotOutsidePlexiglass(-1.),
+      fMeanPhotErrOutsidePlexiglass(-1.),
       fOffsets(NULL),
       fSlopes(NULL),
@@ -77,6 +87,8 @@
 // --------------------------------------------------------------------------
 //
-// Delete the TClonesArray or MCalibrationPix's
+// Delete the TClonesArray of MCalibrationPix containers
 // Delete the MCalibrationPINDiode and the MCalibrationBlindPix
+//
+// Delete the histograms if they exist
 //
 MCalibrationCam::~MCalibrationCam()
@@ -99,299 +111,11 @@
 }
 
-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();
-}
-
-
-// --------------------------------------------------------------------------
-//
-// This function return the size of the FILLED MCalibrationCam
-// It is NOT the size of the array fPixels !!!
-// Note that with every call to AddPixels, GetSize() might change
-//
-Int_t MCalibrationCam::GetSize() const
-{
-
-  //
-  // Here we get the number of "filled" fPixels!!
-  //
-  return fPixels->GetEntriesFast();
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th pixel (pixel number)
-//
-MCalibrationPix &MCalibrationCam::operator[](Int_t i)
-{
-    return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th pixel (pixel number)
-//
-MCalibrationPix &MCalibrationCam::operator[](Int_t i) const
-{
-    return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Return a pointer to the pixel with the requested idx. 
-// NULL if it doesn't exist. 
-//
-MCalibrationPix *MCalibrationCam::GetCalibrationPix(Int_t idx) const
-{
-   if (idx<0)
-     return NULL;
-
-  if (!CheckBounds(idx))
-    return NULL;
-  
-  return (MCalibrationPix*)fPixels->At(idx);
-}
-
-
-
-// --------------------------------------------------------------------------
-//
-// Check if position i is inside bounds
-//
-Bool_t MCalibrationCam::CheckBounds(Int_t i) const 
-{
-    return i < fPixels->GetEntriesFast();
-} 
-
-Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const 
-{
-  if (!CheckBounds(idx))
-    return kFALSE;
-
-  return kTRUE;
-}
-
-Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const 
-{
-  return ((*this)[idx].GetCharge() > 0. && (*this)[idx].GetErrCharge() > 0.);
-}
-
-
-
-void MCalibrationCam::Clear(Option_t *o)
-{
-    fPixels->ForEach(TObject, Clear)();
-}
-
-//
-// Perform the fits of the charges 
-// If i=-1, then all pixels will be fitted
-// Otherwise only the one with index i
-// 
-// The number of succesful fits is returned
-//
-UShort_t MCalibrationCam::FitCharge(Int_t i)
-{
-
-  UShort_t nsuccess = 0;
-
-  // invalidate i if it exceeds the number of entries in fPixels
-  if (i > fPixels->GetEntriesFast())      
-    {
-      *fLog << warn << "Tried to fit pixel out of allowed range " << endl;
-      return 0;
-    }
-  
-  if (i == -1)    // loop over all events
-    {
-
-      TIter Next(fPixels);
-      MCalibrationPix *pix;
-      while ((pix=(MCalibrationPix*)Next()))
-        {
-          if (pix->FitCharge())
-            nsuccess++;
-        }
-    }
-  else                  // fit only the pixel with index i
-    {
-      if((*this)[i].FitCharge())
-        nsuccess++;
-    }
-  
-  return nsuccess;
-  
-}
-
-//
-// Perform the fits of the charges of all pixels 
-// plus the blind pixel and the PIN Diode
-// 
-// The number of succesful fits is returned
-//
-UShort_t MCalibrationCam::FitAllCharge()
-{
-
-  // FIXME: Once the blind pixel is fully working, 
-  //        there must be some penalty in case the
-  //        fit does not succeed
-  //
-  UShort_t nsuccess = 0;
-
-  TIter Next(fPixels);
-  MCalibrationPix *pix;
-  while ((pix=(MCalibrationPix*)Next()))
-    {
-      if (pix->FitCharge())
-        nsuccess++;
-    }
-  
-  if (fBlindPixel->FitCharge())
-        nsuccess++;
-
-  if (fPINDiode->FitCharge())
-        nsuccess++;
-
-  return nsuccess;
-
-}
-
-
-
-//
-// Perform the fits of the arrival times
-// If i=-1, then all pixels will be fitted
-// Otherwise only the one with index i
-// 
-// The number of succesful fits is returned
-//
-UShort_t MCalibrationCam::FitTime(Int_t i)
-{
-
-  UShort_t nsuccess = 0;
-
-  // invalidate i if it exceeds the number of entries in fPixels
-  if (i > fPixels->GetEntriesFast())      
-    {
-      *fLog << warn << "Tried to fit pixel out of allowed range " << endl;
-      return 0;
-    }
-  
-  if (i == -1)                // loop over all events
-    {
-
-      TIter Next(fPixels);
-      MCalibrationPix *pix;
-      while ((pix=(MCalibrationPix*)Next()))
-        {
-         if (pix->FitTime())
-            nsuccess++;
-        }
-    }
-  else                     // fit only the pixel with index i
-    {
-      if((*this)[i].FitTime())
-        nsuccess++;
-    }
-  
-  return nsuccess;
-
-}
-
-
-//
-// Perform the fits of the times of all pixels 
-// plus the blind pixel and the PIN Diode
-// 
-// The number of succesful fits is returned
-//
-UShort_t MCalibrationCam::FitAllTime()
-{
-
-  // FIXME: Once the blind pixel is fully working, 
-  //        there must be some penalty in case the
-  //        fit does not succeed
-  //
-  UShort_t nsuccess = 0;
-
-  TIter Next(fPixels);
-  MCalibrationPix *pix;
-  while ((pix=(MCalibrationPix*)Next()))
-    {
-      if (pix->FitTime())
-        nsuccess++;
-    }
-  
-  if (fBlindPixel->FitTime())
-        nsuccess++;
-
-  if (fPINDiode->FitTime())
-       nsuccess++;
-
-  return nsuccess;
-
-}
-
-
-
-void MCalibrationCam::CutEdges()
-{
-
-  fBlindPixel->GetHist()->CutAllEdges();
-
-  TIter Next(fPixels);
-  MCalibrationPix *pix;
-  while ((pix=(MCalibrationPix*)Next()))
-    {
-      pix->GetHist()->CutAllEdges();
-    }
-
-  return;
-}
-
-// ---------------------------------------------------------------------
+// -------------------------------------------------------------------
 //
 // This function simply allocates memory via the ROOT command:
 // (TObject**) TStorage::ReAlloc(fCont, newSize * sizeof(TObject*),
-//                                       fSize * sizeof(TObject*));
+//                                      fSize * sizeof(TObject*));
 // newSize corresponds to size in our case
-// fSize is the old size (in most cases: 0)
+// fSize is the old size (in most cases: 1)
 //
 void MCalibrationCam::InitSize(Int_t size)
@@ -404,10 +128,104 @@
     return;
   
-  //
-  // It is important to use Expand and NOT ExpandCreate, because 
-  // we want to keep all pixel not used with a NULL pointer.
-  //
   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
+{
+    return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Return a pointer to the pixel with the requested idx. 
+// NULL if it doesn't exist. 
+//
+MCalibrationPix *MCalibrationCam::GetCalibrationPix(Int_t idx) const
+{
+   if (idx<0)
+     return NULL;
+
+  if (!CheckBounds(idx))
+    return NULL;
+  
+  return (MCalibrationPix*)fPixels->At(idx);
+}
+
+
+
+
+Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const 
+{
+  if (!CheckBounds(idx))
+    return kFALSE;
+
+  return kTRUE;
+}
+
+Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const 
+{
+  return ((*this)[idx].GetCharge() > 0. && (*this)[idx].GetErrCharge() > 0.);
+}
+
+
+
+void MCalibrationCam::Clear(Option_t *o)
+{
+    fPixels->ForEach(TObject, Clear)();
+}
+
+void MCalibrationCam::CutEdges()
+{
+
+  fBlindPixel->GetHist()->CutAllEdges();
+
+  TIter Next(fPixels);
+  MCalibrationPix *pix;
+  while ((pix=(MCalibrationPix*)Next()))
+    {
+      pix->GetHist()->CutAllEdges();
+    }
+
+  return;
 }
   
@@ -514,15 +332,15 @@
     case 13:
       if (idx < 397)
-	val = (double)fMeanNrPhotInnerPix;
+	val = (double)fMeanPhotInsidePlexiglass;
       else
-	val = (double)fMeanNrPhotInnerPix*gkCalibrationOuterPixelArea;
+	val = (double)fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
       break;
     case 14:
-      if ((fMeanNrPhotInnerPix > 0. ) && ((*this)[idx].GetCharge() != -1.))
+      if ((fMeanPhotInsidePlexiglass > 0. ) && ((*this)[idx].GetCharge() != -1.))
 	{
 	  if (idx < 397)
-	    val = fMeanNrPhotInnerPix / (*this)[idx].GetCharge();
+	    val = fMeanPhotInsidePlexiglass / (*this)[idx].GetCharge();
 	  else 
-	    val = fMeanNrPhotInnerPix*gkCalibrationOuterPixelArea / (*this)[idx].GetCharge();
+	    val = fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea / (*this)[idx].GetCharge();
 	} 
       else
@@ -544,5 +362,5 @@
 }
 
-Bool_t MCalibrationCam::CalcNrPhotInnerPixel()
+Bool_t MCalibrationCam::CalcNumPhotInsidePlexiglass()
 {
 
@@ -556,27 +374,27 @@
     {
     case kECGreen:
-      fMeanNrPhotInnerPix = (mean / gkCalibrationBlindPixelQEGreen) // real photons
+      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEGreen)     // real photons
                             *TMath::Power(10,gkCalibrationBlindPixelAttGreen) // correct for absorption 
-                            / gkCalibrationBlindPixelArea;          // correct for area
+                            * gkCalibrationInnerPixelArea;                    // correct for area
       break;
     case kECBlue:
-      fMeanNrPhotInnerPix = (mean / gkCalibrationBlindPixelQEBlue )
+      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEBlue )
                             *TMath::Power(10,gkCalibrationBlindPixelAttBlue)
-                            / gkCalibrationBlindPixelArea;
+                            * gkCalibrationInnerPixelArea;
       break;
     case kECUV:
-      fMeanNrPhotInnerPix = (mean / gkCalibrationBlindPixelQEUV )
+      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQEUV )
                             *TMath::Power(10,gkCalibrationBlindPixelAttUV)
-                            / gkCalibrationBlindPixelArea;
+                            * gkCalibrationInnerPixelArea;
       break;
     case kECCT1:
     default:
-      fMeanNrPhotInnerPix = (mean / gkCalibrationBlindPixelQECT1 )
+      fMeanPhotInsidePlexiglass = (mean / gkCalibrationBlindPixelQECT1 )
                             *TMath::Power(10,gkCalibrationBlindPixelAttCT1)
-                            / gkCalibrationBlindPixelArea;
-      break;
-    }
-
-  fMeanNrPhotAvailable = kTRUE;
+                            * gkCalibrationInnerPixelArea;
+      break;
+    }
+
+  fNumPhotInsidePlexiglassAvailable = kTRUE;
 
   TIter Next(fPixels);
@@ -585,6 +403,6 @@
     {
       
-      if((pix->GetCharge() > 0.) && (fMeanNrPhotInnerPix > 0.))
-	pix->SetConversionBlindPixelMethod(fMeanNrPhotInnerPix/pix->GetCharge(), 0., 0.);
+      if((pix->GetCharge() > 0.) && (fMeanPhotInsidePlexiglass > 0.))
+	pix->SetConversionBlindPixelMethod(fMeanPhotInsidePlexiglass/pix->GetCharge(), 0., 0.);
     }
   return kTRUE;
@@ -592,4 +410,49 @@
 
 
+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)
 {
@@ -598,6 +461,6 @@
     return kFALSE;
 
-  if (!fMeanNrPhotAvailable)
-    if (!CalcNrPhotInnerPixel())
+  if (!fNumPhotInsidePlexiglassAvailable)
+    if (!CalcNumPhotInsidePlexiglass())
       return kFALSE;
 
@@ -666,2 +529,45 @@
 
 }
+
+
+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/manalysis/MCalibrationCam.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCam.h	(revision 2678)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCam.h	(revision 2679)
@@ -44,35 +44,38 @@
   
   Int_t fNumPixels;
-  TClonesArray *fPixels;             //! FIXME: Change TClonesArray away from a pointer?
+  TClonesArray *fPixels;                      // Array of MCalibrationPix with fit results
   
-  MCalibrationBlindPix *fBlindPixel; //! containing blind pixel data with fitresults
-  MCalibrationPINDiode *fPINDiode;   //! containing PIN Diode data 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  fMeanNrPhotAvailable;
-  Float_t fMeanNrPhotInnerPix;       // The mean number of photons in an inner pixel  
-  Float_t fMeanNrPhotInnerPixErr;    // The uncertainty about the number of photons in an inner pixel  
+  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  
 
-  TH1F* fHChargeAllPixels;
-  TH1F* fHChargeErrAllPixels;
-  TH1F* fHChargeSigmaAllPixels;
-  TH1F* fHChargeProbAllPixels;
+  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* fHTimeAllPixels;
-  TH1F* fHTimeSigmaAllPixels;
-  TH1F* fHTimeProbAllPixels;
+  TH1F* fHChargeAllPixels;                     //! 
+  TH1F* fHChargeErrAllPixels;                  //! 
+  TH1F* fHChargeSigmaAllPixels;                //! 
+  TH1F* fHChargeProbAllPixels;                 //! 
 
-  TH1F* fHPedAllPixels;
-  TH1F* fHPedRMSAllPixels;
+  TH1F* fHTimeAllPixels;                       //! 
+  TH1F* fHTimeSigmaAllPixels;                  //! 
+  TH1F* fHTimeProbAllPixels;                   //! 
 
-  TH1F* fHSigmaPerChargeAllPixels;
-  TH1F* fHPhEAllPixels;
+  TH1F* fHPedAllPixels;                        //! 
+  TH1F* fHPedRMSAllPixels;                     //! 
+  TH1F* fHSigmaPerChargeAllPixels;             //! 
+  TH1F* fHPhEAllPixels;                        //! 
 
-  TH1F* fHConvPhEperFADCAllPixels;
-  TH1F* fHConvPhperFADCAllPixels;
+  TH1F* fHConvPhEperFADCAllPixels;             //! 
+  TH1F* fHConvPhperFADCAllPixels;              //! 
 
-  TH1D* fOffsets;
-  TH1D* fSlopes;
+  TH1D* fOffsets;                              //! 
+  TH1D* fSlopes;                               //! 
   
-  TH2D* fOffvsSlope;
+  TH2D* fOffvsSlope;                           //! 
 
 public:
@@ -102,9 +105,4 @@
   MCalibrationPix &operator[](Int_t i) const;
   
-  UShort_t FitCharge(Int_t i=-1);
-  UShort_t FitAllCharge();
-  UShort_t FitTime(Int_t i=-1);
-  UShort_t FitAllTime();
-  
   Bool_t CheckBounds(Int_t i) const;
 
@@ -113,5 +111,4 @@
   void CutEdges();
   
-  Bool_t CalcNrPhotInnerPixel();
   Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
   void   DrawPixelContent(Int_t num) const;    
@@ -127,5 +124,8 @@
   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();
 
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationConfig.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationConfig.h	(revision 2678)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationConfig.h	(revision 2679)
@@ -3,9 +3,11 @@
 
 /////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MCalibrationConfig                                                      //
-//                                                                         //
-// Contains all configuration data of the Calibration                      //
-//                                                                         //
+//                                                                         
+// MCalibrationConfig                                                      
+//
+// Contains all configuration data of the Calibration          
+//                                                             
+// This file is only TEMPORARY. It values will go into the DATABASE 
+//
 /////////////////////////////////////////////////////////////////////////////
 
@@ -37,9 +39,22 @@
 const Float_t gkCalibrationBlindPixelAttCT1   = 1.95;
 
-// Area of Blind Pixel w.r.t. Inner Pixel
-const Float_t gkCalibrationBlindPixelArea     = 0.25;
-
+//
+// Area of Inner Pixel w.r.t. Blind Pixel (which is 1 cm²)
+//
+// Hexagone of diagonal axis b = 3.5 cm
+//             straight axis a = 3.0 cm +- 2% 
+// Area =  sqrt(3)*a²/2 = 7.79 cm² +- 4% = 7.8 +- 0.3 cm²
+//
+const Float_t gkCalibrationInnerPixelArea      = 7.8;
+const Float_t gkCalibrationInnerPixelAreaError = 0.3;
+//
 // Area of Outer Pixel w.r.t. Inner Pixel
-const Float_t gkCalibrationOuterPixelArea     = 4.00;
+//
+// Hexagone of diagonal axis b = 7.0 cm
+//             straight axis a = 6.0 cm +- 1% 
+// Area = sqrt(3)*a²/2 = 
+//
+const Float_t gkCalibrationOutervsInnerPixelArea      = 4.00;
+const Float_t gkCalibrationOutervsInnerPixelAreaError = 0.00;
 
 // ----- PIN DIODE ------------------------//
@@ -48,3 +63,33 @@
 const UShort_t gkCalibrationPINDiodeId = 9999;
 
-#endif /* MARS_MCalibrationBlindPixelConfig */
+//
+// 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²/2 = 7.79 cm² +- 4% = 7.8 +- 0.3 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²
+// conversion C = -------------- * ----- = 0.054
+//                A(PIN Diode)      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/manalysis/MCalibrationPINDiode.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationPINDiode.h	(revision 2678)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationPINDiode.h	(revision 2679)
@@ -23,7 +23,4 @@
   Float_t fErrTime;             // The error of the mean arrival time after the fit
   
-  Float_t fRCharge;               // The reduced mean charge after the fit
-  Float_t fErrRCharge;            // The error of the reduced mean charge after the fit  
-  
 public:
 
@@ -36,5 +33,8 @@
   void SetPedRms(Float_t pedrms)    { fPedRms   = pedrms; }
 
-  Bool_t IsValid() const { return fRCharge >=0 || fErrRCharge >= 0; }
+  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); }
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc	(revision 2678)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc	(revision 2679)
@@ -111,8 +111,6 @@
   if (fPed && fPedRms)
     fHist->SetLowerFitRange(1.5*fPedRms);
-
   else
     *fLog << warn << "Cannot set lower fit range to suppress cosmics: Pedestals not available" << endl;
-
 
   if (fHist->UseLoGain())
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h	(revision 2678)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h	(revision 2679)
@@ -68,5 +68,5 @@
   Float_t GetTimeChiSquare()  const    { return fTimeChiSquare;  }    
   
-  Float_t GetPed()            const    { return fPed;            }
+ Float_t GetPed()            const    { return fPed;            }
   Float_t GetPedRms()         const    { return fPedRms;         }    
 
@@ -127,5 +127,4 @@
   void Draw(Option_t *opt="")           { fHist->Draw(opt); }
   
-  
   ClassDef(MCalibrationPix, 1)	// Storage Container for Calibration information of one pixel
 };
