Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3195)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3196)
@@ -5,4 +5,13 @@
                                                  -*-*- END OF LINE -*-*-
  2004/02/16: Markus Gaug
+
+   * mcalib/Makefile, mcalib/CalibLinkDef.h:
+     - added MExtractBlindPixel and MExtractedSignalBlindPixel
+
+   * mcalib/MExtractBlindPixel.[h,cc]
+     - new signal extractor for the Blind Pixel
+
+   * mcalib/MExtractedSignalBlindPixel.[h,cc]
+     - new container for the extracted signal of the BlindPixel
 
    * manalysis/MPedestalCam.h 
Index: /trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 3195)
+++ /trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 3196)
@@ -26,4 +26,6 @@
 #pragma link C++ class MExtractPINDiode++;
 #pragma link C++ class MExtractedSignalPINDiode++;
+#pragma link C++ class MExtractBlindPixel++;
+#pragma link C++ class MExtractedSignalBlindPixel++;
 
 #pragma link C++ class MHGausEvents++;
Index: /trunk/MagicSoft/Mars/mcalib/MExtractBlindPixel.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MExtractBlindPixel.cc	(revision 3196)
+++ /trunk/MagicSoft/Mars/mcalib/MExtractBlindPixel.cc	(revision 3196)
@@ -0,0 +1,272 @@
+/* ======================================================================== *\
+!
+! *
+! * 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
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//   MExtractBlindPixel
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MExtractBlindPixel.h"
+
+#include <fstream>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MRawEvtData.h"
+#include "MRawEvtPixelIter.h"
+
+#include "MPedestalCam.h"
+#include "MPedestalPix.h"
+
+#include "MExtractedSignalBlindPixel.h"
+
+ClassImp(MExtractBlindPixel);
+
+using namespace std;
+
+const UInt_t MExtractBlindPixel::fgBlindPixelIdx   = 559;
+const Byte_t MExtractBlindPixel::fgSaturationLimit = 254;
+const Byte_t MExtractBlindPixel::fgFirst =  3;
+const Byte_t MExtractBlindPixel::fgLast  = 14;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+MExtractBlindPixel::MExtractBlindPixel(const char *name, const char *title)
+    : fSaturationLimit(fgSaturationLimit)
+{
+  
+  fName  = name  ? name  : "MExtractBlindPixel";
+  fTitle = title ? title : "Task to extract the signal from the FADC slices";
+  
+  AddToBranchList("MRawEvtData.*");
+  
+  SetBlindPixelIdx();
+  SetSaturationLimit();
+  SetRange();
+}
+
+void MExtractBlindPixel::SetRange(Byte_t first, Byte_t last)
+{
+
+    fNumSamples = last-first+1;
+    fFirst      = first;
+    fLast       = last;
+
+    fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
+}
+
+// --------------------------------------------------------------------------
+//
+// The PreProcess searches for the following input containers:
+//  - MRawEvtData
+//  - MPedestalCam
+//
+// The following output containers are also searched and created if
+// they were not found:
+//
+//  - MExtractedBlindPixel
+//
+Int_t MExtractBlindPixel::PreProcess(MParList *pList)
+{
+    fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
+    if (!fRawEvt)
+    {
+        *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
+        return kFALSE;
+    }
+
+
+    fBlindPixel = (MExtractedSignalBlindPixel*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalBlindPixel"));
+    if (!fBlindPixel)
+        return kFALSE;
+
+    fBlindPixel->SetUsedFADCSlices(fFirst, fLast);
+
+    fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
+
+    if (!fPedestals)
+    {
+        *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
+        return kFALSE;
+    }
+
+    const MPedestalPix &ped   = (*fPedestals)[fBlindPixelIdx]; 
+
+    if (&ped)
+      {
+        fPedestal = ped.GetPedestal();
+        fPedRms   = ped.GetPedestalRms();
+      }
+    else
+      {
+        *fLog << err << " Cannot find MPedestalPix of the Blind Pixel (idx=" 
+              << fBlindPixelIdx << ")" << endl;
+        return kFALSE;
+      }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculate the integral of the FADC time slices and store them as a new
+// pixel in the MExtractedBlindPixel container.
+//
+Int_t MExtractBlindPixel::Process()
+{
+
+    MRawEvtPixelIter pixel(fRawEvt);
+
+    fBlindPixel->Clear();
+
+    pixel.Jump(fBlindPixelIdx);
+ 
+    UInt_t sat  = 0;
+    UInt_t max  = 0;
+
+    Byte_t *ptr = pixel.GetHiGainSamples();
+    
+    UInt_t sumhi = 0;
+    UInt_t sumlo = 0;
+    //
+    // We need a dedicated signal extractor for the blind pixel
+    //
+    Int_t  diff  = 0;
+    UInt_t first = fFirst;
+    UInt_t last  = fLast;
+
+    if (last > 15)
+      {
+        diff = last - 15;
+        last = 15;
+      }
+    
+    
+    Byte_t *start   = ptr + first - 1;
+    Byte_t *end     = ptr + last  - 1;
+    
+    ptr = start;
+    
+    Int_t sum = 0;
+    
+    while (ptr<=end)
+      {
+        sum += *ptr;
+
+        if (*ptr > max)
+          max = *ptr;
+
+        if (*ptr++ >= fSaturationLimit)
+          sat++;
+      }
+    
+    if (diff > 0)
+      {
+        ptr = pixel.GetLoGainSamples();
+        end = ptr + diff - 1;
+        
+        while (ptr<=end)
+          {
+
+            sum += *ptr;
+
+            if (*ptr > max)
+              max = *ptr;
+
+            if (*ptr++ >= fSaturationLimit)
+              sat++;
+
+          }
+      }
+    
+    sumhi = sum;
+    
+    ptr = pixel.GetLoGainSamples();
+    
+    start   = ptr + fFirst - 1;
+    end     = ptr + fLast  - 1;
+    
+    ptr = start;
+    
+    sum = 0;
+    
+    while (ptr<=end)
+      {
+        
+      sum += *ptr;
+    
+      if (*ptr > max)
+        max = *ptr;
+      
+      if (*ptr++ >= fSaturationLimit)
+        sat++;
+      }
+    
+    sumlo = sum;
+    
+    fBlindPixel->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples);
+    fBlindPixel->SetSaturation(sat);
+
+    if (sat)
+      *fLog << warn << "WARNING - saturation occurred in the Blind Pixel " << endl;
+
+    fBlindPixel->SetReadyToSave();
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
+void MExtractBlindPixel::StreamPrimitive(ofstream &out) const
+{
+    out << "   " << ClassName() << " " << GetUniqueName() << "(\"";
+    out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
+
+    if (fSaturationLimit!=fgSaturationLimit)
+    {
+        out << "   " << GetUniqueName() << ".SetSaturationLimit(";
+        out << (int)fSaturationLimit << ");" << endl;
+    }
+
+    const Bool_t arg2 = fNumSamples+fFirst-1 != fgLast;
+    const Bool_t arg1 = arg2 || fFirst != fgFirst;
+
+    if (!arg1)
+        return;
+
+    out << "   " << GetUniqueName() << ".SetRange(";
+    out << (int)fFirst;
+    if (arg2)
+      out << ", " << (int)(fNumSamples+fFirst-1);
+    out << ");" << endl;
+}
Index: /trunk/MagicSoft/Mars/mcalib/MExtractBlindPixel.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MExtractBlindPixel.h	(revision 3196)
+++ /trunk/MagicSoft/Mars/mcalib/MExtractBlindPixel.h	(revision 3196)
@@ -0,0 +1,66 @@
+#ifndef MARS_MExtractBlindPixel
+#define MARS_MExtractBlindPixel
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MExtractBlindPixel                                                        //
+//                                                                         //
+// 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 MExtractedSignalBlindPixel;
+class MExtractBlindPixel : public MTask
+{
+private:
+
+  static const UInt_t fgBlindPixelIdx;  
+  static const Byte_t fgSaturationLimit;
+  static const Byte_t fgFirst;
+  static const Byte_t fgLast;
+
+  MPedestalCam                *fPedestals;    // Pedestals of all pixels in the camera
+  MExtractedSignalBlindPixel  *fBlindPixel;   // Extracted signal of the Blind Pixel
+
+  MRawEvtData         *fRawEvt;       // raw event data (time slices)
+  MRawRunHeader       *fRunHeader;    // RunHeader information
+  
+  Byte_t  fFirst;
+  Byte_t  fLast;
+  Byte_t  fNumSamples;
+  Float_t fSqrtSamples;
+  Byte_t  fSaturationLimit;
+
+  UInt_t  fBlindPixelIdx;
+
+  Float_t fPedestal;
+  Float_t fPedRms;
+  
+  void   FindSignal(Byte_t *ptr, Int_t size, UInt_t &sum, UInt_t &sum2, UInt_t &sat, UInt_t &max) const;
+  
+  Int_t  PreProcess(MParList *pList);
+  Int_t  Process();
+  void   StreamPrimitive(ofstream &out) const;
+  
+public:
+
+  MExtractBlindPixel(const char *name=NULL, const char *title=NULL);
+
+  // Setters
+  void SetRange(const Byte_t first=fgFirst, const Byte_t last=fgLast);
+  void SetSaturationLimit(const Byte_t lim=fgSaturationLimit) { fSaturationLimit = lim; }
+  void SetBlindPixelIdx( const UInt_t idx=fgBlindPixelIdx  ) { fBlindPixelIdx = idx;   }  
+
+  ClassDef(MExtractBlindPixel, 0) // Task to fill the Extracted BlindPixel Containers from raw data
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mcalib/MExtractedSignalBlindPixel.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MExtractedSignalBlindPixel.cc	(revision 3196)
+++ /trunk/MagicSoft/Mars/mcalib/MExtractedSignalBlindPixel.cc	(revision 3196)
@@ -0,0 +1,104 @@
+/* ======================================================================== *\
+!
+! *
+! * 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
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MExtractedSignalBlindPixel
+//
+// This is the storage container to hold informations about the extracted signal 
+// (offset) value of the calibration PIN Diode
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MExtractedSignalBlindPixel.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MExtractedSignalBlindPixel);
+
+using namespace std;
+
+static const Float_t gkSignalInitializer = 99999.9;
+
+// ------------------------------------------------------------------------
+//
+// MExtractedSignalBlindPixel holds the extracted signal
+// of the FADC slices and its error. 
+//
+// Additionally, the number of saturated Slices are stored. 
+// 
+// Default values for the extracted signals are: 99999.9 
+//
+MExtractedSignalBlindPixel::MExtractedSignalBlindPixel(const char* name, const char* title)
+{
+
+  fName  = name  ? name  : "MExtractedSignalBlindPixel";
+  fTitle = title ? title : "Container of the Extracted Signals";
+
+  Clear();
+}
+
+// ------------------------------------------------------------------------
+//
+// Invalidate values
+//
+void MExtractedSignalBlindPixel::Clear(Option_t *o)
+{
+  fExtractedSignal          = gkSignalInitializer;
+  fExtractedSignalErr       = gkSignalInitializer;
+
+  fNumSaturated       = 0;
+}
+
+void MExtractedSignalBlindPixel::SetUsedFADCSlices(const Byte_t first, const Byte_t num)   
+{
+  fFirst          = first; 
+  fNumFADCSamples = num;
+}
+
+
+void MExtractedSignalBlindPixel::SetExtractedSignal(const Float_t sig, const Float_t sigerr)   
+{
+  fExtractedSignal      = sig; 
+  fExtractedSignalErr = sigerr;
+}
+
+
+Bool_t MExtractedSignalBlindPixel::IsValid() const
+{
+    return fExtractedSignal >= 0. || fExtractedSignalErr >= 0.;
+}
+
+void MExtractedSignalBlindPixel::SetSaturation(const Byte_t numsat)
+{
+  fNumSaturated = numsat; 
+}
+
+void MExtractedSignalBlindPixel::Print(Option_t *o) const
+{
+  *fLog << " Signal: " << fExtractedSignal
+        << " +- " << fExtractedSignalErr
+        << " Nr. Saturation: " <<  fNumSaturated
+        << endl;
+}
Index: /trunk/MagicSoft/Mars/mcalib/MExtractedSignalBlindPixel.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MExtractedSignalBlindPixel.h	(revision 3196)
+++ /trunk/MagicSoft/Mars/mcalib/MExtractedSignalBlindPixel.h	(revision 3196)
@@ -0,0 +1,41 @@
+#ifndef MARS_MExtractedSignalBlindPixel
+#define MARS_MExtractedSignalBlindPixel
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MExtractedSignalBlindPixel : public MParContainer
+{
+private:
+
+  Float_t fExtractedSignal;    // mean value of the extracted signal
+  Float_t fExtractedSignalErr; // error of the mean value of the extracted signal
+
+  Byte_t fFirst;
+  Byte_t fNumFADCSamples;
+  Byte_t fNumSaturated;
+
+public:
+    MExtractedSignalBlindPixel(const char* name=NULL, const char* title=NULL);
+
+    void Clear(Option_t *o="");
+    void Print(Option_t *o="") const;
+
+    // Setter
+    void SetExtractedSignal(const Float_t sig, const Float_t sigerr);
+    void SetSaturation(   const Byte_t numsat);
+    void SetUsedFADCSlices( const Byte_t first, const Byte_t num);
+    
+    // Getter
+    Float_t GetExtractedSignal()    const { return fExtractedSignal; }
+    Float_t GetExtractedSignalErr() const { return fExtractedSignalErr; }
+
+    Byte_t  GetNumFADCSamples()     const { return fNumFADCSamples;  }
+    
+    Bool_t IsValid() const;   
+
+    ClassDef(MExtractedSignalBlindPixel, 0)	// Storage Container for Extracted Signal of the blind pixel
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mcalib/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/Makefile	(revision 3195)
+++ /trunk/MagicSoft/Mars/mcalib/Makefile	(revision 3196)
@@ -54,4 +54,6 @@
 	   MExtractPINDiode.cc \
 	   MExtractedSignalPINDiode.cc \
+	   MExtractBlindPixel.cc \
+	   MExtractedSignalBlindPixel.cc \
 	   MHGausEvents.cc 
 
