Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3657)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3658)
@@ -25,4 +25,5 @@
 
    * mcalib/MCalibrationChargeCalc.[h,cc]
+   * mcalib/MCalibrationChargeCam.cc
      - holds also pointers to MExtractedSignalPINDiode and 
        MExtractedSignalBlindPixel and does the checks inside the task 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3657)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3658)
@@ -1039,5 +1039,5 @@
 
   Float_t flux    = pindiode.GetMeanFluxOutsidePlexiglass();
-  Float_t fluxerr = pindiode.GetMeanFluxErrOutsidePlexiglass();
+  Float_t fluxerr = pindiode.GetMeanFluxOutsidePlexiglassErr();
 
   TIter Next(fPixels);
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.cc	(revision 3657)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.cc	(revision 3658)
@@ -24,12 +24,14 @@
 
 /////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MCalibrationChargePINDiode                                                            //
-//                                                                         //
-// This is the storage container to hold informations about the pedestal   //
-// (offset) value of one Pixel (PMT).                                      //
-//                                                                         //
+//                                     
+// MCalibrationChargePINDiode       
+//                                  
+// Storage container of the fit results of the PIN Diode signal 
+// (from MHCalibrationChargePINDiode). The PIN Diode is not yet working, so 
+// is the documentation for the moment.
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MCalibrationChargePINDiode.h"
+#include "MCalibrationChargePix.h"
 
 #include "MLog.h"
@@ -40,10 +42,6 @@
 using namespace std;
 
-const Float_t MCalibrationChargePINDiode::fgChargeLimit        = 3.;
-const Float_t MCalibrationChargePINDiode::fgChargeErrLimit     = 0.;    
-const Float_t MCalibrationChargePINDiode::fgChargeRelErrLimit  = 1.; 
-
-const Float_t MCalibrationChargePINDiode::fgConvPhotons        = -1.; 
-const Float_t MCalibrationChargePINDiode::fgConvPhotonsErr     = -1.; 
+const Float_t MCalibrationChargePINDiode::fgChargeToPhotons    = -1.; 
+const Float_t MCalibrationChargePINDiode::fgChargeToPhotonsErr = -1.; 
 //
 // Area of Inner Pixel w.r.t. PIN Diode (which is 1 cm2)
@@ -84,4 +82,12 @@
 // Default Constructor. 
 //
+// Sets:
+// - fCalibFlags to 0
+// - fChargeToPhotons to fgChargeToPhotons
+// - fChargeToPhotonsVar to fgChargeToPhotonsErr*fgChargeToPhotonsErr
+// 
+// Calls:
+// - Clear()
+//
 MCalibrationChargePINDiode::MCalibrationChargePINDiode(const char *name, const char *title)
     : fCalibFlags(0)
@@ -91,44 +97,45 @@
   fTitle = title ? title : "Container of the fit results of MHCalibrationChargePINDiode";
 
+  SetChargeToPhotons();
+  SetChargeToPhotonsErr();
+
   Clear();
 
-  SetChargeLimit();
-  SetChargeErrLimit();
-  SetChargeRelErrLimit();
-
-  SetConvPhotons();
-  SetConvPhotonsErr();
-
-  SetOscillating          ( kFALSE );
-  SetExcluded             ( kFALSE );
 }
 
 // ------------------------------------------------------------------------
 //
-// Invalidate values
+// Sets:
+// - all flags to kFALSE
+// - all variables to -1.
+//
+// Calls: 
+// - MCalibrationPix::Clear()
 //
 void MCalibrationChargePINDiode::Clear(Option_t *o)
 {
 
+  SetOscillating        ( kFALSE );
   SetChargeFitValid     ( kFALSE );
   SetTimeFitValid       ( kFALSE );
     
-  fPed                              =  -1.;
-  fPedRms                           =  -1.;
-
-  fRmsChargeMean                    =  -1.;
-  fRmsChargeMeanErr                 =  -1.;
-  fRmsChargeSigma                   =  -1.;  
-  fRmsChargeSigmaErr                =  -1.;
-
-  fAbsTimeMean                      =  -1.;
-  fAbsTimeRms                       =  -1.;
-
-  fConvertedPhotons                 =  -1.;
-  fConvertedPhotonsErr              =  -1.;
-
-  fMeanFluxOutsidePlexiglass        =  -1.;  
-  fMeanFluxErrOutsidePlexiglass     =  -1.;
-
+  fPed                          =  -1.;
+  fPedRms                       =  -1.;
+
+  fRmsChargeMean                =  -1.;
+  fRmsChargeMeanErr             =  -1.;
+  fRmsChargeSigma               =  -1.;  
+  fRmsChargeSigmaErr            =  -1.;
+
+  fAbsTimeMean                  =  -1.;
+  fAbsTimeRms                   =  -1.;
+
+  fConvPhotons                  =  -1.;
+  fConvPhotonsVar               =  -1.;
+
+  fMeanFluxOutsidePlexiglass    =  -1.;  
+  fMeanFluxOutsidePlexiglassVar =  -1.;
+
+  MCalibrationPix::Clear();
 }
 
@@ -158,5 +165,5 @@
 // --------------------------------------------------------------------------
 //
-// Set the Excluded Bit from outside 
+// Set the ChargeFitValid Bit from outside 
 //
 void MCalibrationChargePINDiode::SetChargeFitValid(Bool_t b )    
@@ -167,5 +174,5 @@
 // --------------------------------------------------------------------------
 //
-// Set the Excluded Bit from outside 
+// Set the TimeFitValid Bit from outside 
 //
 void MCalibrationChargePINDiode::SetTimeFitValid(Bool_t b )    
@@ -174,9 +181,32 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Set the FluxOutsidePlexiglassAvailable Bit from outside 
+//
 void MCalibrationChargePINDiode::SetFluxOutsidePlexiglassAvailable (const Bool_t b)
 {
-  b ?  SETBIT(fCalibFlags, kFluxOutsidePlexiglassAvailable) : CLRBIT(fCalibFlags, kFluxOutsidePlexiglassAvailable); 
-}
-
+  b ?  SETBIT(fCalibFlags, kFluxOutsidePlexiglassAvailable) 
+    : CLRBIT(fCalibFlags, kFluxOutsidePlexiglassAvailable); 
+}
+
+// --------------------------------------------------------------------------
+//
+// Return -1 if fMeanFluxOutsidePlexiglassVar is smaller than 0.
+// Return square root of fMeanFluxOutsidePlexiglassVar
+// 
+Float_t MCalibrationChargePINDiode::GetMeanFluxOutsidePlexiglassErr() const
+{
+  if (fMeanFluxOutsidePlexiglassVar < 0.)
+    return -1.;
+  
+  return TMath::Sqrt(fMeanFluxOutsidePlexiglassVar);
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Test bit kChargeFitValid
+//
 Bool_t MCalibrationChargePINDiode::IsChargeFitValid() const 
 {
@@ -184,4 +214,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Test bit kTimeFitValid
+//
 Bool_t MCalibrationChargePINDiode::IsTimeFitValid()   const 
 {
@@ -189,4 +223,13 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Return kFALSE if IsChargeFitValid() is kFALSE
+//
+// Calculate fMeanFluxOutsidePlexiglass with the formula:
+// - fMeanFluxOutsidePlexiglass = fConvPhotons*gkPINDiodeArea*gkFluxCameravsPINDiode 
+//                              / gkPINDiodeQE (of the corr. colour) 
+// - fMeanFluxOutsidePlexiglass = fConvPhotons*gkPINDiodeArea*gkFluxCameravsPINDiode 
+//
 Bool_t MCalibrationChargePINDiode::CalcFluxOutsidePlexiglass()
 {
@@ -196,12 +239,12 @@
   
   // Start calculation of number of photons per mm^2 on the camera
-  fMeanFluxOutsidePlexiglass  = fConvertedPhotons * gkPINDiodeArea;
+  fMeanFluxOutsidePlexiglass  = fConvPhotons * gkPINDiodeArea;
   // Correct for the distance between camera and PIN Diode and for different areas.
   fMeanFluxOutsidePlexiglass *= gkFluxCameravsPINDiode;
 
   // Start calculation of number of photons relative Variance (!!)
-  fMeanFluxErrOutsidePlexiglass  = fConvertedPhotonsErr * fConvertedPhotonsErr 
-                                 / fConvertedPhotons    / fConvertedPhotons    ;
-  fMeanFluxErrOutsidePlexiglass += gkFluxCameravsPINDiodeErr*gkFluxCameravsPINDiodeErr
+  fMeanFluxOutsidePlexiglassVar  = fConvPhotonsVar
+                                 / ( fConvPhotons * fConvPhotons  )  ;
+  fMeanFluxOutsidePlexiglassVar += gkFluxCameravsPINDiodeErr*gkFluxCameravsPINDiodeErr
                                  / gkFluxCameravsPINDiode/gkFluxCameravsPINDiode;
   
@@ -210,15 +253,15 @@
     case kGREEN:
       fMeanFluxOutsidePlexiglass    /= gkPINDiodeQEGreen;
-      fMeanFluxErrOutsidePlexiglass += gkPINDiodeQEGreenErr*gkPINDiodeQEGreenErr
+      fMeanFluxOutsidePlexiglassVar += gkPINDiodeQEGreenErr*gkPINDiodeQEGreenErr
                                      / gkPINDiodeQEGreen/gkPINDiodeQEGreen;
       break;
     case kBLUE:
       fMeanFluxOutsidePlexiglass    /= gkPINDiodeQEBlue;
-      fMeanFluxErrOutsidePlexiglass += gkPINDiodeQEBlueErr*gkPINDiodeQEBlueErr
+      fMeanFluxOutsidePlexiglassVar += gkPINDiodeQEBlueErr*gkPINDiodeQEBlueErr
                                      / gkPINDiodeQEBlue/gkPINDiodeQEBlue;
       break; 
     case kUV:
       fMeanFluxOutsidePlexiglass    /= gkPINDiodeQEUV;
-      fMeanFluxErrOutsidePlexiglass += gkPINDiodeQEUVErr*gkPINDiodeQEUVErr
+      fMeanFluxOutsidePlexiglassVar += gkPINDiodeQEUVErr*gkPINDiodeQEUVErr
                                      / gkPINDiodeQEUV/gkPINDiodeQEUV;
       break;
@@ -226,5 +269,5 @@
     default:
       fMeanFluxOutsidePlexiglass    /= gkPINDiodeQECT1;
-      fMeanFluxErrOutsidePlexiglass += gkPINDiodeQECT1Err*gkPINDiodeQECT1Err
+      fMeanFluxOutsidePlexiglassVar += gkPINDiodeQECT1Err*gkPINDiodeQECT1Err
                                      / gkPINDiodeQECT1/gkPINDiodeQECT1;
       break;
@@ -239,20 +282,18 @@
       return kFALSE;
 
-  if (fMeanFluxErrOutsidePlexiglass < 0.)
+  if (fMeanFluxOutsidePlexiglassVar < 0.)
       return kFALSE;
 
   SetFluxOutsidePlexiglassAvailable();  
 
-  // Finish calculation of errors -> convert from relative variance to absolute error
-  fMeanFluxErrOutsidePlexiglass = TMath::Sqrt(fMeanFluxErrOutsidePlexiglass);
-  fMeanFluxErrOutsidePlexiglass *= fMeanFluxOutsidePlexiglass;
+  //
+  // Finish calculation of errors -> convert from relative variance to absolute variance
+  //
+  fMeanFluxOutsidePlexiglassVar *= fMeanFluxOutsidePlexiglass*fMeanFluxOutsidePlexiglass;
 
   *fLog << inf << " Error on Photon flux [ph/mm^2] outside Plexiglass: " 
-        << fMeanFluxErrOutsidePlexiglass << endl;
+        << GetMeanFluxOutsidePlexiglassErr() << endl;
   *fLog << inf << endl;
 
   return kTRUE;
 }
-
-
-
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.h	(revision 3657)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.h	(revision 3658)
@@ -10,9 +10,6 @@
 private:
 
-  static const Float_t fgChargeLimit;             //! Default for fChargeLimit
-  static const Float_t fgChargeErrLimit;          //! Default for fChargeErrLimit
-  static const Float_t fgChargeRelErrLimit;       //! Default for fChargeRelErrLimit
-  static const Float_t fgConvPhotons;             //! Default for fConversionChargePhotons
-  static const Float_t fgConvPhotonsErr;          //! Default for fConversionChargePhotonsErr
+  static const Float_t fgChargeToPhotons;         //! Default for fChargeToPhotons
+  static const Float_t fgChargeToPhotonsErr;      //! Default for fChargeToPhotonsVar
   static const Float_t gkPINDiodeArea;            //! PIN Diode Effective Area in mm^2  
   static const Float_t gkFluxCameravsPINDiode;    //! Flux Conversion PIN Diode - inner pixel
@@ -34,10 +31,10 @@
   Float_t fChargeErrLimit;                // Limit (in units of PedRMS) for acceptance fitted charge sigma
   Float_t fChargeRelErrLimit;             // Limit (in units of Error of fitted charge) for acceptance fitted mean  
-  Float_t fConvPhotons;                   // Mean conv. PIN Diode charge to number of incident photons
-  Float_t fConvPhotonsErr;                // Error mean conv. PIN Diode charge to nr. incident photons
-  Float_t fConvertedPhotons;              // Number photons incidident on PIN Diode
-  Float_t fConvertedPhotonsErr;           // Error on nr. photons incid. on PIN Diode
+  Float_t fChargeToPhotons;               // Mean conv. PIN Diode charge to number of incident photons
+  Float_t fChargeToPhotonsVar;            // Variance of mean conv. PIN Diode charge to nr. incident photons
+  Float_t fConvPhotons;                   // Number photons incidident on PIN Diode
+  Float_t fConvPhotonsVar;                // Error on nr. photons incid. on PIN Diode
   Float_t fMeanFluxOutsidePlexiglass;     // Mean number photons in INNER PIXEL outside plexiglass
-  Float_t fMeanFluxErrOutsidePlexiglass;  // Error on nr. photons in INNER PIXEL outside plexiglass
+  Float_t fMeanFluxOutsidePlexiglassVar;  // Error on nr. photons in INNER PIXEL outside plexiglass
   Float_t fPed;                           // Mean pedestal (from MPedestalPix)
   Float_t fPedRms;                        // Pedestal  RMS (from MPedestalPix)
@@ -60,25 +57,22 @@
   
   // Setters
-  void SetAbsTimeMean      ( const Float_t f )                     { fAbsTimeMean       = f; }
-  void SetAbsTimeRms       ( const Float_t f )                     { fAbsTimeRms        = f; }
-  void SetChargeLimit      ( const Float_t f=fgChargeLimit       ) { fChargeLimit       = f; }
-  void SetChargeErrLimit   ( const Float_t f=fgChargeErrLimit    ) { fChargeErrLimit    = f; }
-  void SetChargeRelErrLimit( const Float_t f=fgChargeRelErrLimit ) { fChargeRelErrLimit = f; }
-  void SetColor            ( const PulserColor_t color           ) { fColor = color;         }
-  void SetConvPhotons      ( const Float_t f=fgConvPhotons       ) { fConvPhotons       = f; }  
-  void SetConvPhotonsErr   ( const Float_t f=fgConvPhotonsErr    ) { fConvPhotonsErr    = f; }  
-  void SetPedestal         (       Float_t ped, Float_t pedrms   );
-  void SetRmsChargeMean    ( const Float_t f )                     { fRmsChargeMean     = f; }
-  void SetRmsChargeMeanErr ( const Float_t f )                     { fRmsChargeMeanErr  = f; }
-  void SetRmsChargeSigma   ( const Float_t f )                     { fRmsChargeSigma    = f; }
-  void SetRmsChargeSigmaErr( const Float_t f )                     { fRmsChargeSigmaErr = f; }
-  void SetOscillating      ( const Bool_t b=kTRUE );
-  void SetChargeFitValid   ( const Bool_t b=kTRUE );
-  void SetTimeFitValid     ( const Bool_t b=kTRUE );
+  void SetAbsTimeMean        ( const Float_t f )                      { fAbsTimeMean        = f;   }
+  void SetAbsTimeRms         ( const Float_t f )                      { fAbsTimeRms         = f;   }
+  void SetChargeToPhotons    ( const Float_t f=fgChargeToPhotons    ) { fChargeToPhotons    = f;   }  
+  void SetChargeToPhotonsErr ( const Float_t f=fgChargeToPhotonsErr ) { fChargeToPhotonsVar = f*f; }  
+  void SetColor              ( const PulserColor_t color            ) { fColor = color;            }
+  void SetPedestal           (       Float_t ped, Float_t pedrms    );
+  void SetRmsChargeMean      ( const Float_t f )                      { fRmsChargeMean      = f;   }
+  void SetRmsChargeMeanErr   ( const Float_t f )                      { fRmsChargeMeanErr   = f;   }
+  void SetRmsChargeSigma     ( const Float_t f )                      { fRmsChargeSigma     = f;   }
+  void SetRmsChargeSigmaErr  ( const Float_t f )                      { fRmsChargeSigmaErr  = f;   }
+  void SetOscillating        ( const Bool_t b=kTRUE );
+  void SetChargeFitValid     ( const Bool_t b=kTRUE );
+  void SetTimeFitValid       ( const Bool_t b=kTRUE );
   void SetFluxOutsidePlexiglassAvailable ( const Bool_t b = kTRUE );
 
   // Getters
   Float_t GetMeanFluxOutsidePlexiglass()    const { return fMeanFluxOutsidePlexiglass; }
-  Float_t GetMeanFluxErrOutsidePlexiglass() const { return fMeanFluxErrOutsidePlexiglass; }
+  Float_t GetMeanFluxOutsidePlexiglassErr() const;
 
   // Pedestals
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc	(revision 3657)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc	(revision 3658)
@@ -108,6 +108,4 @@
   fTitle = title ? title : "Container of the fit results of MHCalibrationChargePixs ";
 
-  Clear();
-
   //
   // At the moment, we don't have a database, yet, 
@@ -119,4 +117,5 @@
   SetPheFFactorMethodLimit();
   
+  Clear();
 }
 
@@ -124,5 +123,5 @@
 //
 // Sets:
-// - all flags to 0
+// - all flags to kFALSE
 // - all variables to -1.
 //
