Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3320)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3321)
@@ -6,4 +6,10 @@
  
  2004/02/25: Markus Gaug
+
+  * mcalib/MCalibrationQECam.[h,cc]
+  * mcalib/MCalibrationQEPix.[h,cc]
+    - two new classes to hold the quantum efficieny information of the 
+      calibration
+
 
   * msignal/MArrivalTimeCalc.[h,cc]
Index: trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- trunk/MagicSoft/Mars/macros/calibration.C	(revision 3320)
+++ trunk/MagicSoft/Mars/macros/calibration.C	(revision 3321)
@@ -71,4 +71,5 @@
     MGeomCamMagic              geomcam;
     MExtractedSignalCam        sigcam;
+    MArrivalTimeCam            timecam;
     MCalibrationChargeCam      calcam;
     MCalibrationChargePINDiode pindiode;   
@@ -90,4 +91,5 @@
     plist.AddToList(&geomcam);
     plist.AddToList(&sigcam);
+    plist.AddToList(&timecam);
     plist.AddToList(&calcam);
     plist.AddToList(&histtime);
@@ -107,5 +109,5 @@
     MGeomApply             geomapl;
     
-    MFillH filltime("MHCalibrationRelTimeCam", "MArrivalTime");
+    MFillH filltime( "MHCalibrationRelTimeCam"    , "MArrivalTimeCam");
     MFillH fillpin  ("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
     MFillH fillblind("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel");
@@ -148,12 +150,12 @@
     // Create and setup the eventloop
     //
-    MEvtLoop evtloop2;
-    evtloop2.SetParList(&plist);
-    evtloop2.SetDisplay(display);
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+    evtloop.SetDisplay(display);
     
     //
     // Execute second analysis
     //
-    if (!evtloop2.Eventloop())
+    if (!evtloop.Eventloop())
         return;
 
@@ -173,4 +175,5 @@
     histblind.DrawClone("all");
     histcharge[5].DrawClone("time");
+    histtime[5].DrawClone("fourierevents");
 
     // Create histograms to display
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationQECam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationQECam.cc	(revision 3321)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationQECam.cc	(revision 3321)
@@ -0,0 +1,236 @@
+/* ======================================================================== *\
+!
+! *
+! * 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   02/2004 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                               
+// MCalibrationQECam                                               
+//                                                               
+// Hold the calibrated QE information of the camera:
+//                                                               
+// 1) MCalibrationQECam initializes a TClonesArray whose elements are 
+//    pointers to MCalibrationQEPix Containers
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationQECam.h"
+
+#include <TClonesArray.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MCalibrationQEPix.h"
+
+ClassImp(MCalibrationQECam);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+// Creates a TClonesArray of MCalibrationPix containers, initialized to 1 entry
+// Later, a call to MCalibrationQECam::InitSize(Int_t size) has to be performed
+//
+// Creates an MCalibrationBlindPix container 
+//
+MCalibrationQECam::MCalibrationQECam(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MCalibrationQECam";
+    fTitle = title ? title : "Storage container for the calibrated Quantrum Efficiency of the camera";
+
+    fPixels     = new TClonesArray("MCalibrationQEPix",1);
+
+    Clear();
+}
+
+// --------------------------------------------------------------------------
+//
+MCalibrationQECam::~MCalibrationQECam()
+{
+
+  //
+  // delete fPixels should delete all Objects stored inside
+  // 
+  delete fPixels;
+
+}
+
+// -------------------------------------------------------------------
+//
+void MCalibrationQECam::InitSize(const UInt_t i)
+{
+  fPixels->ExpandCreate(i);
+}
+
+// --------------------------------------------------------------------------
+//
+// 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 MCalibrationQECam::GetSize() const
+{
+  return fPixels->GetEntriesFast();
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+MCalibrationQEPix &MCalibrationQECam::operator[](UInt_t i)
+{
+  return *static_cast<MCalibrationQEPix*>(fPixels->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+const MCalibrationQEPix &MCalibrationQECam::operator[](UInt_t i) const
+{
+  return *static_cast<MCalibrationQEPix*>(fPixels->UncheckedAt(i));
+}
+
+
+// --------------------------------------
+//
+void MCalibrationQECam::Clear(Option_t *o)
+{
+
+  fPixels->ForEach(TObject, Clear)();
+
+  return;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Print first the well fitted pixels 
+// and then the ones which are not FitValid
+//
+void MCalibrationQECam::Print(Option_t *o) const
+{
+
+  *fLog << all << GetDescriptor() << ":" << endl;
+  int id = 0;
+  
+  TIter Next(fPixels);
+  MCalibrationQEPix *pix;
+  while ((pix=(MCalibrationQEPix*)Next()))
+    {
+      
+      if (!pix->IsExcluded() && pix->IsQEValid()) 
+	{
+	    *fLog << all << "Pix " << pix->GetPixId() 
+		<< ":  QE: "                   << pix->GetQE(kCT1)        << " +- " << pix->GetQEErr(kCT1) 
+		<< endl;
+          id++;
+	}
+    }
+  
+  *fLog << all << id << " succesful pixels :-))" << endl;
+  id = 0;
+  
+  *fLog << all << endl;
+  *fLog << all << "Pixels with errors:" << endl;
+  *fLog << all << endl;
+  
+  TIter Next2(fPixels);
+    while ((pix=(MCalibrationQEPix*)Next2()))
+      {
+        
+        if (!pix->IsExcluded() && !pix->IsQEValid())
+          {
+	    *fLog << all << "Pix " << pix->GetPixId() 
+		<< ":  QE: "                   << pix->GetQE(kCT1)        << " +- " << pix->GetQEErr(kCT1) 
+		<< endl;
+            id++;
+          }
+      }
+    *fLog << all << id << " pixels with errors :-((" << endl;
+
+    
+  *fLog << all << endl;
+  *fLog << all << "Excluded pixels:" << endl;
+  *fLog << all << endl;
+  
+  id = 0;
+
+  TIter Next4(fPixels);
+  while ((pix=(MCalibrationQEPix*)Next4()))
+  {
+      if (pix->IsExcluded())
+      {
+	  *fLog << all << pix->GetPixId() << endl;
+	  id++;
+      }
+  }
+  *fLog << all << id << " Excluded pixels " << endl;
+}
+
+//
+Bool_t MCalibrationQECam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
+{
+
+  if (idx > GetSize())
+    return kFALSE;
+
+  switch (type)
+    {
+    case 0:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetQE(kCT1);
+      break;
+    case 1:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetQEErr(kCT1);
+      break;
+    default:
+      return kFALSE;
+    }
+  return val!=-1.;
+}
+
+// --------------------------------------------------------------------------
+//
+// What MHCamera needs in order to draw an individual pixel in the camera
+//
+void MCalibrationQECam::DrawPixelContent(Int_t idx) const
+{
+    return;
+}
+
+
+
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationQECam.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationQECam.h	(revision 3321)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationQECam.h	(revision 3321)
@@ -0,0 +1,52 @@
+#ifndef MARS_MCalibrationQECam
+#define MARS_MCalibrationQECam
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+#ifndef MARS_MCamEvent
+#include "MCamEvent.h"
+#endif
+
+class TClonesArray;
+
+class MCalibrationQEPix;
+class MCalibrationQECam : public MParContainer, public MCamEvent
+{
+private:
+  
+  Int_t fNumPixels;
+  TClonesArray *fPixels;                                        //-> Array of MCalibrationPix with fit results
+  
+public:
+
+  MCalibrationQECam(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationQECam();
+  
+  void Clear(    Option_t *o="" );
+  void InitSize( const UInt_t i );
+
+  // Getters
+  Int_t  GetSize()               const;
+  UInt_t GetNumPixels()          const { return fNumPixels; }
+
+  // Others
+  MCalibrationQEPix &operator[](UInt_t i);
+  const MCalibrationQEPix &operator[](UInt_t i) const;
+  
+  // Prints
+  void Print(Option_t *o="") const;
+  
+  // Others
+  Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
+  void DrawPixelContent(Int_t num) const;    
+
+  ClassDef(MCalibrationQECam, 1)	// Container for calibration information of the camera
+};
+
+#endif
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationQEPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationQEPix.cc	(revision 3321)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationQEPix.cc	(revision 3321)
@@ -0,0 +1,268 @@
+/* ======================================================================== *\
+!
+! *
+! * 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   02/2004 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MCalibrationChargePix                                                         //
+//                                                                         //
+// Storage container of the calibrated Quantrum Efficiency of one pixel 
+// For the moment, only a fixed average QE is stored:
+//
+// - Average QE: (email David Paneque, 14.2.04):
+//
+//  The conversion factor that comes purely from QE folded to a Cherenkov
+//  spectrum has to be multiplied by:
+//  * Plexiglass window -->> 0.96 X 0.96
+//  * PMT photoelectron collection efficiency -->> 0.9
+//  * Light guides efficiency -->> 0.94
+//
+//  Concerning the light guides effiency estimation... Daniel Ferenc 
+//  is preparing some work (simulations) to estimate it. Yet so far, he has 
+//  been busy with other stuff, and this work is still UNfinished.
+//
+//  The estimation I did comes from:
+//  1) Reflectivity of light guide walls is 85 % (aluminum)
+//  2) At ZERO degree light incidence, 37% of the light hits such walls 
+//    (0.15X37%= 5.6% of light lost)
+//  3) When increasing the light incidence angle, more and more light hits 
+//     the walls.
+//
+//  However, the loses due to larger amount of photons hitting the walls is more 
+//  or less counteracted by the fact that more and more photon trajectories cross 
+//  the PMT photocathode twice, increasing the effective sensitivity of the PMT.
+//
+//  Jurgen Gebauer did some quick measurements about this issue. I attach a 
+//  plot. You can see that the angular dependence is (more or less) in agreement 
+//  with a CosTheta function (below 20-25 degrees),
+//  which is the variation of teh entrance window cross section. So, in 
+//  first approximation, no loses when increasing light incidence angle; 
+//  and therefore, the factor 0.94.
+//
+//  So, summarizing... I would propose the following conversion factors 
+//  (while working with CT1 cal box) in order to get the final number of photons 
+//  from the detected measured size in ADC counts.
+// 
+//  Nph = ADC * FmethodConversionFactor / ConvPhe-PhFactor
+// 
+//  FmethodConversionFactor ; measured for individual pmts
+// 
+//  ConvPhe-PhFactor = 0.98 * 0.23 * 0.90 * 0.94 * 0.96 * 0.96 = 0.18
+// 
+//  I would not apply any smearing of this factor (which we have in nature), 
+//  since we might be applying it to PMTs in the totally wrong direction.
+// 
+// 
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationQEPix.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MCalibrationQEPix);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor: 
+//
+MCalibrationQEPix::MCalibrationQEPix(const char *name, const char *title)
+    : fPixId(-1)
+{
+
+  fName  = name  ? name  : "MCalibrationQEPix";
+  fTitle = title ? title : "Container of the calibrated quantum efficiency ";
+
+  Clear();
+
+}
+
+// ------------------------------------------------------------------------
+//
+// Invalidate values
+//
+void MCalibrationQEPix::Clear(Option_t *o)
+{
+
+  SetExcluded               ( kFALSE );
+  SetQEValid                ( kFALSE );
+
+  fQEGreen      =  -1.;
+  fQEBlue       =  -1.;
+  fQEUV         =  -1.;
+  fQECT1        =  -1.;
+  
+  fQEGreenErr   =  -1.;
+  fQEBlueErr    =  -1.;
+  fQEUVErr      =  -1.;
+  fQECT1Err     =  -1.;
+ 
+}
+
+
+void MCalibrationQEPix::SetQE( const Float_t qe, const PulserColor_t col )
+{
+
+  switch (col)
+  {
+      case kGREEN:
+	  fQEGreen = qe;
+	  break;
+      case kBLUE:
+	  fQEBlue = qe;
+	  break;
+      case kUV:
+	  fQEUV = qe;
+	  break;
+      case kCT1:
+	  fQECT1 = qe;
+	  break;
+      default:
+	  fQECT1 = qe;
+	  break;
+  }
+}
+
+void MCalibrationQEPix::SetQEErr( const Float_t qeerr, const PulserColor_t col )
+{
+
+  switch (col)
+  {
+      case kGREEN:
+	  fQEGreenErr = qeerr;
+	  break;
+      case kBLUE:
+	  fQEBlueErr  = qeerr;
+	  break;
+      case kUV:
+	  fQEUVErr    = qeerr;
+	  break;
+      case kCT1:
+	  fQECT1Err   = qeerr;
+	  break;
+      default:
+	  fQECT1Err  = qeerr;
+	  break;
+  }
+}
+
+
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationQEPix::SetExcluded(Bool_t b )
+{ 
+    b ?  SETBIT(fFlags, kExcluded) : CLRBIT(fFlags, kExcluded); 
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationQEPix::SetQEValid(Bool_t b )    
+{ 
+  b ?  SETBIT(fFlags, kQEValid) : CLRBIT(fFlags, kQEValid); 
+}
+
+
+Int_t MCalibrationQEPix::GetPixId()  const
+{
+    return fPixId;
+}
+
+Float_t MCalibrationQEPix::GetQE(const PulserColor_t col )  const
+{
+
+  switch (col)
+  {
+      case kGREEN:
+	  return fQEGreen;
+	  break;
+      case kBLUE:
+	  return fQEBlue;
+	  break;
+      case kUV:
+	  return fQEUV;
+	  break;
+      case kCT1:
+	  return fQECT1;
+	  break;
+      default:
+	  return fQECT1;
+	  break;
+  }
+}
+
+Float_t MCalibrationQEPix::GetQEErr(const PulserColor_t col )  const
+{
+
+  switch (col)
+  {
+      case kGREEN:
+	  return fQEGreenErr;
+	  break;
+      case kBLUE:
+	  return fQEBlueErr;
+	  break;
+      case kUV:
+	  return fQEUVErr;
+	  break;
+      case kCT1:
+	  return fQECT1Err;
+	  break;
+      default:
+	  return fQECT1Err;
+	  break;
+  }
+}
+
+
+Bool_t MCalibrationQEPix::IsExcluded()            const
+{ 
+   return TESTBIT(fFlags,kExcluded);  
+}
+
+
+Bool_t MCalibrationQEPix::IsQEValid()         const 
+{
+  return TESTBIT(fFlags, kQEValid);  
+}
+
+
+//
+// The check return kTRUE if:
+//
+// 1) Pixel has a fitted charge greater than fQELimit*PedRMS
+// 2) Pixel has a fit error greater than fQEErrLimit
+// 3) Pixel has a fitted charge greater its fQERelErrLimit times its charge error
+// 4) Pixel has a charge sigma bigger than its Pedestal RMS
+// 
+Bool_t MCalibrationQEPix::CheckQEValidity()
+{
+ 
+  SetQEValid();
+  return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationQEPix.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationQEPix.h	(revision 3321)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationQEPix.h	(revision 3321)
@@ -0,0 +1,59 @@
+#ifndef MARS_MCalibrationQEPix
+#define MARS_MCalibrationQEPix
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MCalibrationQEPix : public MParContainer
+{
+private:
+
+  Int_t fPixId;
+
+  Float_t fQEGreen;
+  Float_t fQEBlue;
+  Float_t fQEUV;
+  Float_t fQECT1;
+  
+  Float_t fQEGreenErr;
+  Float_t fQEBlueErr;
+  Float_t fQEUVErr;
+  Float_t fQECT1Err;   
+  
+  Byte_t fFlags;
+
+  enum { kExcluded, kQEValid };
+
+public:
+
+  MCalibrationQEPix(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationQEPix() {}
+  
+  void Clear(Option_t *o="");
+
+  // Setters
+  void SetQE   ( const Float_t qe   , const PulserColor_t col );
+  void SetQEErr( const Float_t qeerr, const PulserColor_t col );
+
+  void SetExcluded            (  const Bool_t b = kTRUE );
+  void SetQEValid             (  const Bool_t b = kTRUE );
+
+  // Getters
+  Float_t GetQE   ( const PulserColor_t col )  const;
+  Float_t GetQEErr( const PulserColor_t col )  const;
+  Int_t   GetPixId()          const;
+
+  Bool_t IsExcluded()         const;
+  Bool_t IsQEValid()          const;
+
+  void   SetPixId(const Int_t i)     { fPixId = i; }
+
+  // Miscellaneous
+  Bool_t CheckQEValidity();
+
+  ClassDef(MCalibrationQEPix, 1)	// Container for calibrated Quantrum Efficieny of one pixel
+};
+
+#endif
+
