Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4400)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4401)
@@ -38,4 +38,11 @@
     - use variable histogram range depending on whether amplitude
       or integral has been extracted
+
+  * mcalib/MCalibrationChargeBlindCam.[h,cc]
+  * mcalib/MHCalibrationChargeBlindCam.[h,cc]
+  * mcalib/Makefile
+  * mcalib/CalibLinkDef.h
+    - two new classes for the treatment of various blind pixels in the 
+      camera
 
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindCam.cc	(revision 4401)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindCam.cc	(revision 4401)
@@ -0,0 +1,239 @@
+/* ======================================================================== *\
+!
+! *
+! * 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   07/2004 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                               
+// MCalibrationChargeBlindCam                                               
+//                                                               
+// Base class for Blind Pixels Calibration results. 
+//
+// Contains TClonesArrays for the following objects:
+// - fBlindPixels:    Array of classes derived from MCalibrationChargeBlindPix, one entry 
+//                    per blind pixel. 
+//
+// All TClonesArrays have to enlarged by the corresponding calls to (e.g. in MGeomApply): 
+// - InitSize()
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationChargeBlindCam.h"
+#include "MCalibrationChargeBlindPix.h"
+
+#include "MCalibrationCam.h"
+#include "MCalibrationPix.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include <TClonesArray.h>
+
+ClassImp(MCalibrationChargeBlindCam);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+// Set the following pointer to NULL:
+// - fBlindPixels
+//
+// Initializes:
+// - fPulserColor to kNONE 
+//
+// Creates a TClonesArray of MCalibrationChargeBlindPix containers for the TClonesArray's: 
+// - fBlindPixels
+// all initialized to 1 entry
+//
+// Later, a call to InitSize() 
+// has to be performed in order to get the dimension correctly.
+//
+MCalibrationChargeBlindCam::MCalibrationChargeBlindCam(const char *name, const char *title)
+    : fPulserColor(MCalibrationCam::kNONE), 
+      fBlindPixels(NULL), 
+      fValid(kFALSE)
+{
+  fName  = name  ? name  : "MCalibrationChargeBlindCam";
+  fTitle = title ? title : "Container for the Calibration Information of the blind pixels in the camera";
+
+  fBlindPixels = new TClonesArray("MCalibrationChargeBlindPix",1);
+}
+
+// --------------------------------------------------------------------------
+//
+// Deletes the following TClonesArray's of MCalibrationPix containers (if exist):
+// - fBlindPixels
+//
+MCalibrationChargeBlindCam::~MCalibrationChargeBlindCam()
+{
+
+  //
+  // delete fBlindPixels should delete all Objects stored inside
+  // 
+  delete fBlindPixels;
+
+}
+
+// --------------------------------------
+//
+// Calls the ForEach macro for the TClonesArray fBlindPixels with the argument Clear()
+// 
+void MCalibrationChargeBlindCam::Clear(Option_t *o)
+{
+
+  fBlindPixels->ForEach(TObject, Clear)();
+
+  return;
+}
+
+// -----------------------------------------------------
+//
+// own copy function to do the initialization correctly
+//
+void MCalibrationChargeBlindCam::Copy(TObject& object) const
+{
+  
+  MCalibrationChargeBlindCam &calib = (MCalibrationChargeBlindCam&)object;
+  
+  MParContainer::Copy(calib);
+  
+  calib.fPulserColor          = fPulserColor;
+  
+  const Int_t n3 = GetSize();
+  if (n3 != 0)
+    {
+      calib.InitSize(n3);
+      for (int i=0; i<n3; i++)
+        (*this)[i].Copy(calib[i]);
+    }
+  
+}
+
+// -------------------------------------------------------------------
+//
+// Calls TClonesArray::ExpandCreate() for fBlindPixels
+//
+void MCalibrationChargeBlindCam::InitSize(const UInt_t i)
+{
+  fBlindPixels->ExpandCreate(i);
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Get i-th blind pixel (pixel number)
+//
+MCalibrationChargeBlindPix &MCalibrationChargeBlindCam::operator[](UInt_t i)
+{
+  return *static_cast<MCalibrationChargeBlindPix*>(fBlindPixels->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+const MCalibrationChargeBlindPix &MCalibrationChargeBlindCam::operator[](UInt_t i) const
+{
+  return *static_cast<MCalibrationChargeBlindPix*>(fBlindPixels->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the current size of the TClonesArray fBlindPixels 
+// independently if the MCalibrationChargeBlindPix is filled with values or not.
+//
+const Int_t MCalibrationChargeBlindCam::GetSize() const
+{
+  return fBlindPixels->GetEntriesFast();
+}
+
+// --------------------------------------------------------------------------
+//
+// Print first the results of the pixels 
+// and then the ones which are not FitValid
+//
+void MCalibrationChargeBlindCam::Print(Option_t *o) const
+{
+
+  *fLog << all << GetDescriptor() << ":" << endl;
+  int id = 0;
+  
+  *fLog << all << "Calibrated Blind pixels:" << endl;
+  *fLog << all << endl;
+
+  TIter Next(fBlindPixels);
+  MCalibrationChargeBlindPix *pix;
+  while ((pix=(MCalibrationChargeBlindPix*)Next()))
+    {
+      
+      if (pix->IsSinglePheFitOK()) 
+	{                            
+
+          *fLog << all 
+                << Form("%s%3i","BlindPixel: ",pix->GetPixId())
+                << Form("%s%4.2f%s%4.2f","  Lambda: ",pix->GetLambda(),"+-",pix->GetLambdaErr())
+		<< Form("%s%4.2f%s%4.2f","  Mu0: ",pix->GetMu0(),"+-",pix->GetMu0Err())
+		<< Form("%s%4.2f%s%4.2f","  Mu1: ",pix->GetMu1(),"+-",pix->GetMu1Err()) 
+		<< Form("%s%4.2f%s%4.2f","  Sigma0: ",pix->GetSigma0(),"+-",pix->GetSigma0Err())
+		<< Form("%s%4.2f%s%4.2f","  Sigma1: ",pix->GetSigma1(),"+-",pix->GetSigma1Err())
+		<< endl;
+	  *fLog << all
+                << " Pedestal Fit OK? :" << pix->IsPedestalFitOK() 
+		<< Form("%s%4.2f%s%4.2f","  Lambda (Check): " ,pix->GetLambdaCheck(),"+-",pix->GetLambdaCheckErr()) << endl;
+	  *fLog << all
+                << " Flux available? :" << pix->IsFluxInsidePlexiglassAvailable() 
+		<< Form("%s%4.2f%s%4.2f","  Flux: " ,pix->GetFluxInsidePlexiglass(),"+-",pix->GetFluxInsidePlexiglassErr())
+		<< endl;
+          id++;
+	}
+    }
+  *fLog << all << id << " blind pixels OK" << endl;
+  id = 0;
+  
+  TIter Next2(fBlindPixels);
+  while ((pix=(MCalibrationChargeBlindPix*)Next2()))
+    {
+      
+      if (!pix->IsSinglePheFitOK()) 
+	{                            
+
+          *fLog << all 
+                << Form("%s%3i","BlindPixel: ",pix->GetPixId())
+                << Form("%s%4.2f%s%4.2f","  Lambda: ",pix->GetLambda(),"+-",pix->GetLambdaErr())
+		<< Form("%s%4.2f%s%4.2f","  Mu0: ",pix->GetMu0(),"+-",pix->GetMu0Err())
+		<< Form("%s%4.2f%s%4.2f","  Mu1: ",pix->GetMu1(),"+-",pix->GetMu1Err()) 
+		<< Form("%s%4.2f%s%4.2f","  Sigma0: ",pix->GetSigma0(),"+-",pix->GetSigma0Err())
+		<< Form("%s%4.2f%s%4.2f","  Sigma1: ",pix->GetSigma1(),"+-",pix->GetSigma1Err())
+		<< endl;
+	  *fLog << all
+                << " Pedestal Fit OK? :" << pix->IsPedestalFitOK() 
+		<< Form("%s%4.2f%s%4.2f","  Lambda (Check): " ,pix->GetLambdaCheck(),"+-",pix->GetLambdaCheckErr()) << endl;
+	  *fLog << all
+                << " Flux available? :" << pix->IsFluxInsidePlexiglassAvailable() 
+		<< Form("%s%4.2f%s%4.2f","  Flux: " ,pix->GetFluxInsidePlexiglass(),"+-",pix->GetFluxInsidePlexiglassErr())
+		<< endl;
+          id++;
+	}
+    }
+  *fLog << all << id << " blind pixels NOT OK" << endl;
+  
+}
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindCam.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindCam.h	(revision 4401)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindCam.h	(revision 4401)
@@ -0,0 +1,49 @@
+#ifndef MARS_MCalibrationChargeBlindCam
+#define MARS_MCalibrationChargeBlindCam
+
+#ifndef MARS_MCalibrationCam
+#include "MCalibrationCam.h"
+#endif
+
+class MCalibrationChargeBlindPix;
+class TClonesArray;
+class MCalibrationChargeBlindCam : public MParContainer
+{
+private:
+
+  MCalibrationCam::PulserColor_t fPulserColor;  // Colour of the pulsed LEDs
+
+  TClonesArray *fBlindPixels;                   //-> Array of MCalibrationChargeBlindPix
+
+  Bool_t fValid;
+
+public:
+  MCalibrationChargeBlindCam(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationChargeBlindCam();
+  
+  void   Clear ( Option_t *o="" );
+  void   Copy ( TObject& obj ) const;
+
+  // Getters
+  const Int_t                          GetSize()        const;
+  const MCalibrationCam::PulserColor_t GetColor() const { return fPulserColor; }
+
+        MCalibrationChargeBlindPix &operator[] ( UInt_t i );
+  const MCalibrationChargeBlindPix &operator[] ( UInt_t i ) const;
+
+  Bool_t IsValid() const { return fValid; }
+
+  // Setters
+  void  SetColor ( const MCalibrationCam::PulserColor_t col )  { fPulserColor = col; }
+  void  SetValid () { fValid = kTRUE; }
+
+  // Inits
+  void  InitSize( const UInt_t i);
+  
+  // Prints
+  void   Print(Option_t *o="") const;
+
+  ClassDef(MCalibrationChargeBlindCam, 1) // Container Blind Pixel Calibration Results Camera
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindCam.cc	(revision 4401)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindCam.cc	(revision 4401)
@@ -0,0 +1,296 @@
+/* ======================================================================== *\
+!
+! *
+! * 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
+!
+!
+\* ======================================================================== */
+/////////////////////////////////////////////////////////////////////////////
+//                                                               
+// MHCalibrationChargeBlindCam                                               
+//
+// Histogram class for blind pixels in the camera. Incorporates the TObjArray's:
+// - fBlindPixelsArray (for calibrated High Gains per pixel)
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MHCalibrationChargeBlindCam.h"
+#include "MHCalibrationChargeBlindPix.h"
+
+#include <TVirtualPad.h>
+#include <TCanvas.h>
+#include <TPad.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MCalibrationChargeBlindPix.h"
+#include "MCalibrationChargeBlindCam.h"
+
+#include "MExtractedSignalBlindPixel.h"
+
+#include "MParList.h"
+
+#include "MRawRunHeader.h"
+
+ClassImp(MHCalibrationChargeBlindCam);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. 
+//
+// Sets:
+// - all pointers to NULL
+//
+// Initializes and sets owner of:
+// - fBlindPixelsArray
+//
+MHCalibrationChargeBlindCam::MHCalibrationChargeBlindCam(const char *name, const char *title)
+    :  fCam(NULL), fRunHeader(NULL)
+{
+
+  fBlindPixelsArray = new TObjArray;
+  fBlindPixelsArray->SetOwner();
+}
+
+// --------------------------------------------------------------------------
+//
+// Deletes the TClonesArray of:
+// - fBlindPixelsArray
+//
+MHCalibrationChargeBlindCam::~MHCalibrationChargeBlindCam()
+{
+  delete fBlindPixelsArray;
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th High Gain pixel (pixel number)
+//
+MHCalibrationChargeBlindPix &MHCalibrationChargeBlindCam::operator[](UInt_t i)
+{
+  return *static_cast<MHCalibrationChargeBlindPix*>(fBlindPixelsArray->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th High Gain pixel (pixel number)
+//
+const MHCalibrationChargeBlindPix &MHCalibrationChargeBlindCam::operator[](UInt_t i) const
+{
+  return *static_cast<MHCalibrationChargeBlindPix*>(fBlindPixelsArray->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Our own clone function is necessary since root 3.01/06 or Mars 0.4
+// I don't know the reason. 
+//
+// Creates new MHCalibrationChargeBlindCam
+// Deletes the TObjArray's and Clones them individually
+//
+TObject *MHCalibrationChargeBlindCam::Clone(const char *) const
+{
+
+  const Int_t nhi   = fBlindPixelsArray->GetEntries();
+  
+  //
+  // FIXME, this might be done faster and more elegant, by direct copy.
+  //
+  MHCalibrationChargeBlindCam *cam = new MHCalibrationChargeBlindCam();
+
+  cam->fBlindPixelsArray->Expand(nhi);
+
+  for (int i=0; i<nhi; i++)
+    (*cam->fBlindPixelsArray)[i] = (*fBlindPixelsArray)[i]->Clone();
+
+  return cam;
+}
+
+// --------------------------------------------------------------------------
+//
+// Gets the pointers to:
+// - MRunHeader
+// - MExtractedSignalBlindPix
+//
+// Calls Delete-Function of:
+// - MHCalibrationChargeBlindCam::fBlindPixelsArray
+//
+Bool_t MHCalibrationChargeBlindCam::SetupFill(const MParList *pList)
+{
+  
+  fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+  if (!fRunHeader)
+  {
+    *fLog << warn << GetDescriptor() 
+          << ": MRawRunHeader not found... will not store run numbers." << endl;
+    return kFALSE;
+  }
+
+  fSignal  = (MExtractedSignalBlindPixel*)pList->FindObject("MExtractedSignalBlindPixel");
+  if (!fSignal)
+    {
+      *fLog << err << "MExtractedSignalBlindPixel not found... aborting " << endl;
+      return kFALSE;
+    }
+
+  fBlindPixelsArray->Delete();
+
+  return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Initializes, if empty to MExtractedSignalCam::GetSize() for:
+// - MHCalibrationChargeBlindCam::fBlindPixelsArray
+//
+// Calls InitializeHists() for every entry in:
+// - MHCalibrationChargeBlindCam::fBlindPixelsArray
+//
+// Retrieves the run numbers from MRawRunHeader and stores them in fRunNumbers
+//
+Bool_t MHCalibrationChargeBlindCam::ReInit(MParList *pList)
+{
+
+  const Int_t nblindpixels  = fSignal->GetNumBlindPixels();
+
+  Int_t runnr = 0;
+
+  if (fRunHeader)
+    runnr = fRunHeader->GetRunNumber();
+
+  fCam = (MCalibrationChargeBlindCam*)pList->FindCreateObj("MCalibrationChargeBlindCam");
+  if (!fCam)
+    {
+	*fLog << err << "Cannot find nor create MCalibrationChargeBlindCam ... abort." << endl;
+	return kFALSE;
+    }
+
+  fCam->InitSize(nblindpixels);
+
+  const Int_t samples = fSignal->GetNumFADCSamples();
+  const Int_t integ   = fSignal->IsExtractionType( MExtractBlindPixel::kIntegral );
+
+  if (fBlindPixelsArray->GetEntries()==0)
+  {
+
+      fBlindPixelsArray->Expand(nblindpixels);
+
+      for (Int_t i=0; i<nblindpixels; i++)
+	{
+	  (*fBlindPixelsArray)[i] = new MHCalibrationChargeBlindPix;
+	  (*this)[i].ChangeHistId(i);
+	  if (integ)
+	    {
+	      (*this)[i].SetLast( samples * integ * 
+				  ((*this)[i].GetLast()+0.5) - 0.5 );
+	      (*this)[i].SetSinglePheCut( samples * integ *
+					  (*this)[i].GetSinglePheCut() );
+	    }
+	  (*this)[i].InitBins();
+	  TH1F *h = (*this)[i].GetHGausHist();
+	  h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
+	  (*this)[i].SetupFill(pList);
+	  (*this)[i].SetCalibrationChargeBlindPix(&(*fCam)[i]);
+      }
+  }
+
+  for (Int_t i=0; i<nblindpixels; i++)
+    {
+      TH1F *h = (*this)[i].GetHGausHist();
+      h->SetTitle( Form("%s%i%s", h->GetTitle(),runnr," "));
+    }
+
+  return kTRUE;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// Retrieves from MExtractedSignalBlindPixel:
+// - number of blind pixels
+//
+// For all TObjArray's, the following steps are performed: 
+//
+// 1) Test size and return kFALSE if not matching
+// 2) 
+//
+Bool_t MHCalibrationChargeBlindCam::Fill(const MParContainer *par, const Stat_t w)
+{
+
+  const Int_t nblindpixels  = fSignal->GetNumBlindPixels();
+  
+  if (GetSize() != nblindpixels)
+    {
+      gLog << err << "ERROR - Size mismatch... abort." << endl;
+      return kFALSE;
+    }
+  
+  for (Int_t i=0; i<nblindpixels; i++)
+    (*this)[i].Fill(par,w);
+
+  return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calls the Finalize() function of the blind pixels
+//
+Bool_t MHCalibrationChargeBlindCam::Finalize()
+{
+
+  for (Int_t i=0; i<GetSize(); i++)
+    if (!(*this)[i].Finalize())
+      return kFALSE;
+
+  return kTRUE;
+}
+
+
+
+// -----------------------------------------------------------------------------
+// 
+// Default draw:
+//
+// Displays the averaged areas, both High Gain and Low Gain 
+//
+// Calls the Draw of the fAverageHiGainAreas and fAverageLoGainAreas objects with options
+//
+void MHCalibrationChargeBlindCam::Draw(const Option_t *opt)
+{
+
+  const Int_t size = fBlindPixelsArray->GetEntries();
+  if (size == 0)
+    return;
+  
+  TString option(opt);
+  option.ToLower();
+
+  TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);  
+  pad->SetBorderMode(0);
+  pad->Divide(size/2+1,size/2+1);
+
+  for (Int_t i=0; i<size;i++) 
+    {
+      pad->cd(i+1);
+      (*this)[i].Draw(option);
+    }
+}
Index: trunk/MagicSoft/Mars/mcalib/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mcalib/Makefile	(revision 4400)
+++ trunk/MagicSoft/Mars/mcalib/Makefile	(revision 4401)
@@ -45,7 +45,9 @@
            MCalibrationChargeCam.cc \
            MCalibrationChargePix.cc  \
+           MCalibrationChargeBlindCam.cc  \
            MCalibrationChargeBlindPix.cc  \
            MCalibrationChargePINDiode.cc  \
            MHCalibrationChargeBlindPix.cc \
+           MHCalibrationChargeBlindCam.cc \
            MHCalibrationChargePix.cc \
            MHCalibrationCam.cc \
