Index: trunk/MagicSoft/Mars/mbadpixels/BadPixelsIncl.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/BadPixelsIncl.h	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/BadPixelsIncl.h	(revision 3068)
@@ -0,0 +1,3 @@
+#ifndef __CINT__
+
+#endif // __CINT__
Index: trunk/MagicSoft/Mars/mbadpixels/BadPixelsLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/BadPixelsLinkDef.h	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/BadPixelsLinkDef.h	(revision 3068)
@@ -0,0 +1,15 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class MBadPixelsPix+;
+#pragma link C++ class MBadPixelsCam+;
+
+#pragma link C++ class MBadPixelsCalc+;
+#pragma link C++ class MBadPixelsMerge+;
+
+#pragma link C++ class MMcBadPixelsSet+;
+
+#endif
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc	(revision 3068)
@@ -0,0 +1,164 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Thomas Bretz, 02/2004 <mailto:tbretz@astro.uni.wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MBadPixelsCalc
+//
+//
+// The job of the task is to determin bad pixels event-wise. This must be
+// redone for each event. This particular task is for what is explained
+// below.
+// New algorithms may enter new tasks.
+//
+//
+// Check the pedestal RMS of every pixel with respect to the mean
+// pedestal RMS of the camera (Sigmabar).
+//
+// The pixels can be set as blind if the pedestalRMS is too big or 0.
+//
+// If you don't want to use this option set the PedestalLevel<=0;
+//
+//     MBadPixelsCalc calc;
+//     calc.SetPedestalLevel(-1);
+//
+//
+//  Input Containers:
+//   [MPedPhotCam]
+//   [MGeomCam]
+//   [MSigmabar]
+//
+//  Output Containers:
+//   MBadPixles
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MBadPixelsCalc.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MGeomCam.h"
+#include "MSigmabar.h"
+
+#include "MPedPhotCam.h"
+#include "MPedPhotPix.h"
+
+#include "MBadPixelsCam.h"
+#include "MBadPixelsPix.h"
+
+ClassImp(MBadPixelsCalc);
+
+using namespace std;
+
+static const TString gsDefName  = "MBadPixelsCalc";
+static const TString gsDefTitle = "Find hot spots (star, broken pixels, etc)";
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MBadPixelsCalc::MBadPixelsCalc(const char *name, const char *title)
+    : fPedestalLevel(3)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+}
+
+// --------------------------------------------------------------------------
+//
+//
+Int_t MBadPixelsCalc::PreProcess (MParList *pList)
+{
+    fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
+    if (!fBadPixels)
+        return kFALSE;
+
+    if (fPedestalLevel>0)
+    {
+        fPedPhotCam = (MPedPhotCam*)pList->FindObject(AddSerialNumber("MPedPhotCam"));
+        if (!fPedPhotCam)
+        {
+            *fLog << err << "MPedPhotCam not found... aborting." << endl;
+            return kFALSE;
+        }
+
+        fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
+        if (!fGeomCam)
+        {
+            *fLog << err << "MGeomCam not found... aborting." << endl;
+            return kFALSE;
+        }
+
+        fSigmabar = (MSigmabar*)pList->FindObject(AddSerialNumber("MSigmabar"));
+        if (!fSigmabar)
+        {
+            *fLog << err << "MSigmabar not found... aborting." << endl;
+            return kFALSE;
+        }
+    }
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Check the pedestal RMS of every pixel with respect to the mean pedestal RMS 
+// of the camera (Sigmabar).
+//
+// The pixels can be set as blind if the pedestalRMS is too big or 0.
+//
+// If you don't want to use this option set the PedestalLevel<=0;
+//
+//     MBadPixelsCalc calc;
+//     calc.SetPedestalLevel(-1);
+//
+void MBadPixelsCalc::CheckPedestalRMS() const
+{
+    const Int_t entries = fPedPhotCam->GetSize();
+
+    const Float_t meanPedRMS = fSigmabar->GetSigmabar();
+
+    for (Int_t i=0; i<entries; i++)
+    {
+        //
+        // get pixel as entry from list
+        //
+        const Double_t nratio    = fGeomCam->GetPixRatio(i);
+        const Double_t pixPedRms = (*fPedPhotCam)[i].GetRms();
+
+        if (pixPedRms*nratio > fPedestalLevel * meanPedRMS || pixPedRms == 0)
+            (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
+    }
+}
+// --------------------------------------------------------------------------
+//
+//
+Int_t MBadPixelsCalc::Process()
+{
+    if (fPedestalLevel>0)
+        CheckPedestalRMS();
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.h	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.h	(revision 3068)
@@ -0,0 +1,41 @@
+#ifndef MARS_MBadPixelsCalc
+#define MARS_MBadPixelsCalc
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MBadPixelsCam;
+class MSigmabar;
+class MGeomCam;
+class MPedPhotCam;
+
+class MBadPixelsCalc : public MTask
+{
+private:
+    MGeomCam      *fGeomCam;    //! Input container storing the pixel sizes
+    MSigmabar     *fSigmabar;   //! Input container storing mean pedestal rms of the camera
+    MPedPhotCam   *fPedPhotCam; //! Input container storing the pedestal and pedestal rms of all pixels
+
+    MBadPixelsCam *fBadPixels;  //! Output container holding the bad pixels
+
+    Float_t fPedestalLevel;
+
+    void CheckPedestalRMS() const;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+
+public:
+    MBadPixelsCalc(const char *name=NULL, const char *title=NULL);
+
+    void SetPedestalLevel(Float_t f) { fPedestalLevel=f; }
+
+    ClassDef(MBadPixelsCalc, 1) // Task to find bad pixels (star, broken pixels, etc)
+}; 
+
+#endif
+
+
+
+
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 3068)
@@ -0,0 +1,245 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Thomas Bretz 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MBadPixelsCam                                                                                                                              //
+//
+//Storage container to store bad pixel of the camera...//
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MBadPixelsCam.h"
+
+#include <fstream>
+
+#include <TClonesArray.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MBadPixelsPix.h"
+
+ClassImp(MBadPixelsCam);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MBadPixelsCam::MBadPixelsCam(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MBadPixelsCam";
+    fTitle = title ? title : "";
+
+    fArray = new TClonesArray("MBadPixelsPix", 1);
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the array conatining the bad pixel information
+//
+MBadPixelsCam::~MBadPixelsCam()
+{
+    delete fArray;
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the size of the camera
+//
+void MBadPixelsCam::InitSize(const UInt_t i)
+{
+    fArray->ExpandCreate(i);
+}
+
+// --------------------------------------------------------------------------
+//
+// Get the size of the MBadPixelsCam
+//
+Int_t MBadPixelsCam::GetSize() const
+{
+    return fArray->GetEntriesFast();
+}
+
+// --------------------------------------------------------------------------
+//
+// Copy 'constructor'
+//
+void MBadPixelsCam::Copy(TObject &object) const
+{
+    MBadPixelsCam &cam = (MBadPixelsCam&)object;
+
+    const Int_t n = GetSize();
+    if (n==0)
+        return;
+
+    cam.InitSize(n);
+    for (int i=0; i<n; i++)
+        (*this)[i].Copy(cam[i]);
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+MBadPixelsPix &MBadPixelsCam::operator[](Int_t i)
+{
+    return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+const MBadPixelsPix &MBadPixelsCam::operator[](Int_t i) const
+{
+    return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Merge two MBadPixelsCam together, see also MBadPixelsPix::Merge
+//
+void MBadPixelsCam::Merge(const MBadPixelsCam &cam)
+{
+    const Int_t n = cam.GetSize();
+    if (n==0)
+    {
+        *fLog << warn << "MBadPixelsCam::Merge: Container empty." << endl;
+        return;
+    }
+
+    if (GetSize()==0)
+        InitSize(n);
+
+    if (n!=GetSize())
+    {
+        *fLog << warn << "MBadPixelsCam::Merge: Size mismatch... ignored." << endl;
+        return;
+    }
+
+    for (int i=0; i<n; i++)
+        (*this)[i].Merge(cam[i]);
+}
+
+// --------------------------------------------------------------------------
+//
+// Clear the contents of all bad pixels (set=0 means Ok)
+//
+void MBadPixelsCam::Clear(Option_t *o)
+{
+    fArray->ForEach(TObject, Clear)();
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the contents of all bad pixels
+//
+void MBadPixelsCam::Print(Option_t *o) const
+{
+    *fLog << all << GetDescriptor() << ":" << endl;
+    fArray->ForEach(TObject, Print)();
+}
+
+// --------------------------------------------------------------------------
+//
+// Read from an ascii file of the format:
+//    pixel1 pixel2 pixel3 pixel4
+// while pixel1,2,3,4 are the pixel indices used in the software.
+//
+// To read the pixels corresponding to a given run you can give run!=0
+// and a file of the format:
+//   1234: 17 193 292
+//   1235: 17 193 292 293
+//
+void MBadPixelsCam::AsciiRead(ifstream &fin, UInt_t run=0)
+{
+    Int_t len;
+    TString str;
+
+    while (1)
+    {
+        str.ReadLine(fin);
+        if (!fin)
+            return;
+
+        Int_t r;
+
+        const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
+        if (n!=1)
+            return;
+
+        if (run==0 || run && (UInt_t)r==run)
+            break;
+    }
+
+    str.Remove(0, len);
+
+    while (1)
+    {
+        Int_t idx;
+        const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
+        if (n!=1)
+            break;
+
+        str.Remove(0, len);
+
+        if (idx>=GetSize())
+            InitSize(idx);
+
+        (*this)[idx].SetUnsuitable();
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Write the information into an ascii file. If a run-number is given the
+// run-number will lead the line.
+//
+Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
+{
+    if (run)
+        fout << run << ":";
+
+    for (int i=0; i<GetSize(); i++)
+        if ((*this)[i].IsUnsuitable())
+            fout << " " << i;
+
+    if (run && GetSize())
+        fout << endl;
+
+    return kTRUE;
+}
+
+Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
+{
+    val = (*this)[idx].GetInfo()[0];
+    return (*this)[idx].IsOK();
+}
+
+void MBadPixelsCam::DrawPixelContent(Int_t num) const
+{
+    *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
+}
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.h	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.h	(revision 3068)
@@ -0,0 +1,47 @@
+#ifndef MARS_MBadPixelsCam
+#define MARS_MBadPixelsCam
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+#ifndef MARS_MCamEvent
+#include "MCamEvent.h"
+#endif
+
+class TClonesArray;
+class MBadPixelsPix;
+
+class MBadPixelsCam : public MParContainer, public MCamEvent
+{
+private:
+    TClonesArray *fArray; //-> 
+
+public:
+    MBadPixelsCam(const char *name=NULL, const char *title=NULL);
+    ~MBadPixelsCam();
+
+    void Clear(Option_t *o="");
+    void Print(Option_t *o="") const;
+    void Copy(TObject &object) const;
+
+    void InitSize(const UInt_t i);
+    Int_t GetSize() const;
+
+    MBadPixelsPix &operator[](Int_t i);
+    const MBadPixelsPix &operator[](Int_t i) const;
+
+    void Merge(const MBadPixelsCam &cam);
+
+    void   AsciiRead(ifstream &fin, UInt_t run);
+    void   AsciiRead(ifstream &fin) { AsciiRead(fin, 0); }
+    Bool_t AsciiWrite(ostream &out, UInt_t run) const;
+    Bool_t AsciiWrite(ostream &out) const { return AsciiWrite(out, 0); }
+
+    Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
+    void DrawPixelContent(Int_t num) const;
+
+    ClassDef(MBadPixelsCam, 1)	//Storage container to store bad pixel of the camera...
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsMerge.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsMerge.cc	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsMerge.cc	(revision 3068)
@@ -0,0 +1,101 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Thomas Bretz 02/2004 <mailto:tbretz@astro.uni.wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MBadPixelsMerge
+//
+//  Merges in ReInit two bad pixel containers together:
+//   1) The contents of the container given in the constructor is in ReInit
+//      merged into MBadPixelsCam from the parameter list (aka run-headers)
+//   2) MBadPixelsCam from the parameter list (aka run-headers) is merged
+//      into the container given in the constructor. While the contents
+//      to which 1) refers are still untouched.
+//
+//  Input Containers:
+//   MBadPixelsCam
+//
+//  Output Containers:
+//   MBadPixelsCam
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MBadPixelsMerge.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MBadPixelsCam.h"
+
+ClassImp(MBadPixelsMerge);
+
+using namespace std;
+
+const TString MBadPixelsMerge::fgDefName  = "MBadPixelsMerge";
+const TString MBadPixelsMerge::fgDefTitle = "Merge extra- and intra-loop pixels";
+
+// --------------------------------------------------------------------------
+//
+// Constructor. A copy of the given MBadPixelsCam is created. This copy
+// is - in ReInit - merged into the MBadPixelsCam which is found in the
+// parameter list. In addition the pointer is stored and all MBadPixelsCam
+// which are processed in ReInit are merged into this container.
+//
+MBadPixelsMerge::MBadPixelsMerge(MBadPixelsCam *bad, const char *name, const char *title)
+    : fDest(bad)
+{
+    fName  = name  ? name  : fgDefName.Data();
+    fTitle = title ? title : fgDefTitle.Data();
+
+    fSource = new MBadPixelsCam;
+    bad->Copy(*fSource);
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the copy of the primer MBadPixelsCam
+//
+MBadPixelsMerge::~MBadPixelsMerge()
+{
+    delete fSource;
+}
+
+// --------------------------------------------------------------------------
+//
+// 1) Get MBadPixelCam from the parameter list, if it doesn't yet exist,
+//    it will be created.
+// 2) Merge MBasPixelsCam into the primer container given in the constructor
+// 3) Merge the primer container given in the constructor into MBadPixelsCam
+//
+Bool_t MBadPixelsMerge::ReInit(MParList *pList)
+{
+    MBadPixelsCam *cam = (MBadPixelsCam*)pList->FindCreateObj("MBadPixelsCam");
+    if (!cam)
+        return kFALSE;
+
+    fDest->Merge(*cam);
+    cam->Merge(*fSource);
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsMerge.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsMerge.h	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsMerge.h	(revision 3068)
@@ -0,0 +1,29 @@
+#ifndef MARS_MBadPixelsMerge
+#define MARS_MBadPixelsMerge
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MBadPixelsCam;
+
+class MBadPixelsMerge : public MTask
+{
+private:
+    static const TString fgDefName;  //!
+    static const TString fgDefTitle; //!
+
+    MBadPixelsCam *fDest;            //!
+    MBadPixelsCam *fSource;          //->
+
+    Bool_t ReInit(MParList *pList);
+
+public:
+    MBadPixelsMerge(MBadPixelsCam *bad, const char *name=NULL, const char *title=NULL);
+    ~MBadPixelsMerge();
+
+    ClassDef(MBadPixelsMerge, 0) //Merge extra- and intra-loop pixels
+}; 
+
+#endif
+
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.cc	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.cc	(revision 3068)
@@ -0,0 +1,173 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MBadPixelsPix
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MBadPixelsPix.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MBadPixelsPix);
+
+using namespace std;
+
+const Char_t MBadPixelsPix::fgRunMask=MBadPixelsPix::kUnsuitableRun;
+
+// ------------------------------------------------------------------------
+//
+// Initialize Pixel to be Ok.
+//
+MBadPixelsPix::MBadPixelsPix(const char* name, const char* title)
+    : fInfo(0)
+{
+    fName  = name  ? name  : "MBadPixelsPix";
+    fTitle = title ? title : "Container storeing bad pixel information for a single pixel";
+}
+
+// ------------------------------------------------------------------------
+//
+// Invalidate all bits which are not run-wise. This will be called for
+// all entries in the parameter list, just before each time the task-list
+// is executed.
+//
+void MBadPixelsPix::Reset()
+{
+    fInfo[0] &= fgRunMask;
+}
+
+// ------------------------------------------------------------------------
+//
+// Invalidate values (set=0 which mean Pixel OK)
+//
+void MBadPixelsPix::Clear(Option_t *o)
+{
+    fInfo.Reset(0);
+}
+
+// ------------------------------------------------------------------------
+//
+// Merge (bitwise or) the information in pix into this pixel.
+//
+void MBadPixelsPix::Merge(const MBadPixelsPix &pix)
+{
+    const Int_t n = pix.fInfo.GetSize();
+    if (n>fInfo.GetSize())
+        fInfo.Set(n);
+
+    for (int i=0; i<n; i++)
+        fInfo[i] |= pix.fInfo[n];
+}
+
+/****************************************************************************
+           This is a collection of possible defects for later use
+ ****************************************************************************/
+
+/*
+ 1  PMT defective.
+ 2  Preamplifier defective.
+ 3  Optical link defective.
+ 4  HV cannot be set.
+ 7  HV unstable.
+ 5  HV readout defective.
+ 8  DC unstable.
+ 6  DC readout defective.
+ 9  Discriminator threshold cannot be set.
+ 10  Trigger delay cannot be set.
+ 11  Discriminator gives no output.
+ <-? 12  Pixel out of L1T.
+ 13  FADC defective.
+ 14  FADC board digital information defective.
+ */
+
+/*
+ 1  Pixel shows no signal
+ */
+
+/*
+ MCalibrationCalc - valid for the result of a calibration run:
+
+  <-  1  Pedestals not available
+  <-  2  FADC samples not available
+
+      3  Hi-Gain saturated, no LoGain available
+
+      4  Conversion Factor HiGain - LoGain not valid
+
+      5  Cannot be calibrated at all
+      6  Cannot be fitted - calibrated using Histogram Mean and RMS
+
+      7  Mean Charge smaller than PedRMS
+      8  Mean Charge smaller than Mean charge in camera minus 5 sigma
+      9  Mean Charge bigger than Mean charge in camera plus 5 sigma
+
+     10  Sigma Charge smaller than PedRMS
+
+     11  Result of F-Factor    method invalid
+     12  Result of Blind Pixel method invalid
+     13  Result of PIN-Diode   method invalid
+     14  Methods inconsistency
+
+     15  Gains oscillate
+
+  <- 16  Arrival Time not calculated
+  <- 17  Arrival Time not valid
+
+     18  Sigma  Arrival Time  bigger than  FADC window
+     19  Mean   Arrival Time  at edge of   FADC window
+     */
+
+/*
+
+Hardware defects which cannot be detected automatically by software. This might be stored at least in the data-base. I think we should wait until we implement these things...
+Preamplifier defective.
+Optical link defective.
+HV cannot be set.
+HV readout defective.
+DC readout defective.
+Discriminator threshold cannot be set.
+Trigger delay cannot be set.
+Discriminator gives no output.
+FADC defective.
+FADC board digital information defective.
+Pixel out of L1T. (this is an important information, but not necessarily a defect, is it?)
+
+In addition here are some cases which I think can be detected by software:
+- no signal
+- wrong signal
+- hv problem
+- dc problem
+- Conversion Factor HiGain - LoGain not valid (what does this mean?)
+- No calibration possible
+- No fit possible - calibrated using Histogram Mean and RMS
+- Mean Charge smaller than PedRMS
+- Sigma Charge smaller than PedRMS
+- Calib.methods inconsistency (there are in pricipal 6 combinations... do we need 6 bits?)
+- Gains oscillate (what does it mean?)
+- Sigma  Arrival Time  bigger than  FADC window (from calib)
+- Mean   Arrival Time  at edge of   FADC window (from calib)
+*/
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h	(revision 3068)
@@ -0,0 +1,53 @@
+#ifndef MARS_MBadPixelsPix
+#define MARS_MBadPixelsPix
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#ifndef ROOT_TArrayC
+#include <TArrayC.h>
+#endif
+
+class MBadPixelsPix : public MParContainer
+{
+private:
+    TArrayC fInfo;
+
+public:
+    MBadPixelsPix(const char* name=NULL, const char* title=NULL);
+
+    enum UnsuitableType_t {
+        kUnsuitableRun = BIT(1),
+        kUnsuitableEvt = BIT(2)
+    };
+
+    static const Char_t fgRunMask; // All types which are not event wise determined
+
+    void Reset();
+    void Clear(Option_t *o="");
+    void Copy(TObject &object) const
+    {
+        static_cast<MBadPixelsPix&>(object).fInfo = fInfo;
+    }
+
+    // Setter
+    void   SetUnsuitable(UnsuitableType_t typ=kUnsuitableRun) { fInfo[0] |=  typ; }
+    void   SetSuitable(UnsuitableType_t typ=kUnsuitableRun)   { fInfo[0] &= ~typ; }
+
+    // Getter
+    Bool_t IsUnsuitable(UnsuitableType_t typ=kUnsuitableRun) const { return   fInfo[0]&typ; }
+    Bool_t IsSuitable(UnsuitableType_t typ=kUnsuitableRun) const   { return !(fInfo[0]&typ); }
+
+    Bool_t IsOK() const  { return fInfo[0]==0; }
+    Bool_t IsBad() const { return fInfo[0]!=0; }
+
+    void Merge(const MBadPixelsPix &pix);
+
+    const TArrayC &GetInfo() const { return fInfo; }
+
+    ClassDef(MBadPixelsPix, 1)	// Storage Container for bad pixel information of a single pixel
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/mbadpixels/MMcBadPixelsSet.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MMcBadPixelsSet.cc	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MMcBadPixelsSet.cc	(revision 3068)
@@ -0,0 +1,147 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Oscar Blanch    12/2001 <mailto:blanch@ifae.es>
+!   Author(s): Thomas Bretz    08/2002 <mailto:tbretz@astro.uni.wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MMcBadPixelsSet
+//
+//  This task tries to identify the starfield from the
+//  MMcRunHeader container and tries to identifies it. If it is known
+//  (eg. Crab) the fixed build in pixel numbers are used as blind
+//  pixels.
+//
+//  Implemented star fields (for the MAGIC camera only):
+//   - Crab: 400, 401, 402, 437, 438, 439
+//
+//  Input Containers:
+//   -/-
+//
+//  Output Containers:
+//   MBadPixels
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MMcBadPixelsSet.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MGeomCam.h"
+#include "MMcRunHeader.hxx"
+
+#include "MBadPixelsCam.h"
+#include "MBadPixelsPix.h"
+
+ClassImp(MMcBadPixelsSet);
+
+using namespace std;
+
+static const TString gsDefName  = "MMcBadPixelsSet";
+static const TString gsDefTitle = "Set predefined star fields";
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MMcBadPixelsSet::MMcBadPixelsSet(const char *name, const char *title)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+}
+
+// --------------------------------------------------------------------------
+//
+Int_t MMcBadPixelsSet::PreProcess (MParList *pList)
+{
+    fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
+    if (!fBadPixels)
+        return kFALSE;
+
+    fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
+    if (!fGeomCam)
+    {
+        *fLog << err << dbginf << "MGeomCam not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  - Check whether pixels to disable are available. If pixels are
+//    given by the user nothing more is done.
+//  - Otherwise try to determin the blind pixels from the starfield
+//    given in MMcRunHeader.
+//
+Bool_t MMcBadPixelsSet::ReInit(MParList *pList)
+{
+    if (!fGeomCam->InheritsFrom("MGeomCamMagic"))
+    {
+        *fLog << warn << "MMcBadPixelsSet::ReInit: Warning - Starfield only implemented for Magic standard Camera... no action." << endl;
+        return kTRUE;
+    }
+
+    //
+    // Set as blind some particular pixels because of a particular
+    // Star Field of View.
+    //
+    MMcRunHeader *mcrun = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
+    if (!mcrun)
+    {
+        *fLog << warn << "MMcBadPixelsSet::ReInit: Warning - No run header available... no action." << endl;
+        return kTRUE;
+    }
+
+    Int_t rah, ram, ras;
+    Int_t ded, dem, des;
+    mcrun->GetStarFieldRa(&rah, &ram, &ras);
+    mcrun->GetStarFieldDec(&ded, &dem, &des);
+
+    if (rah!=5 || ram!=34 || ras!=32 || ded!=22 || dem!=0 || des!=55)
+    {
+        *fLog << warn << "Warning - Starfield unknown..." << endl;
+        return kTRUE;
+    }
+
+    //
+    // Case for Crab Nebula FOV
+    //
+    (*fBadPixels)[400].SetUnsuitable();
+    (*fBadPixels)[401].SetUnsuitable();
+    (*fBadPixels)[402].SetUnsuitable();
+    (*fBadPixels)[437].SetUnsuitable();
+    (*fBadPixels)[438].SetUnsuitable();
+    (*fBadPixels)[439].SetUnsuitable();
+
+    *fLog << inf;
+    *fLog << "FOV is centered at CRAB NEBULA: Setting 6 blind pixels" << endl;
+    *fLog << "to avoid bias values of analysis due to CRAB NEBULA:" << endl;
+    *fLog << "   Pixels: 400, 401, 402, 437, 438, 439" << endl;
+
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/mbadpixels/MMcBadPixelsSet.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MMcBadPixelsSet.h	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/MMcBadPixelsSet.h	(revision 3068)
@@ -0,0 +1,30 @@
+#ifndef MARS_MMcBadPixelsSet
+#define MARS_MMcBadPixelsSet
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MGeomCam;
+class MBadPixelsCam;
+
+class MMcBadPixelsSet : public MTask
+{
+private:
+    MBadPixelsCam *fBadPixels;  //!
+    MGeomCam      *fGeomCam;    //!
+
+    Int_t  PreProcess(MParList *pList);
+    Bool_t ReInit(MParList *pList);
+
+public:
+    MMcBadPixelsSet(const char *name=NULL, const char *title=NULL);
+
+    ClassDef(MMcBadPixelsSet, 1) // Task to deal with known MC star-fields
+}; 
+
+#endif
+
+
+
+
Index: trunk/MagicSoft/Mars/mbadpixels/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/Makefile	(revision 3068)
+++ trunk/MagicSoft/Mars/mbadpixels/Makefile	(revision 3068)
@@ -0,0 +1,55 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+include ../Makefile.conf.$(OSTYPE)
+include ../Makefile.conf.general
+
+#
+# Handling name of the Root Dictionary Files
+#
+CINT  = BadPixels
+
+#
+# Library name to creatre
+#
+LIB   = mbadpixels.a
+
+#
+#  connect the include files defined in the config.mk file
+#
+INCLUDES = -I. -I../mbase -I../manalysis -I../mgeom -I../mgui -I../mmc
+# MBadPixelsCalc  (manalysis): MPedPhotCam, MSigmabar
+# MBadPixelsCalc  (mgeom):     MGeomCam
+# MBadPixelsCam   (mgui):      MCamEvent
+# MMcBadPixelsSet (mmc):       MMcRunHeader
+
+
+#------------------------------------------------------------------------------
+
+.SUFFIXES: .c .cc .cxx .h .hxx .o 
+
+SRCFILES = MBadPixelsPix.cc \
+           MBadPixelsCam.cc \
+           MBadPixelsMerge.cc \
+           MBadPixelsCalc.cc \
+           MMcBadPixelsSet.cc
+
+SRCS    = $(SRCFILES)
+HEADERS = $(SRCFILES:.cc=.h)
+OBJS    = $(SRCFILES:.cc=.o) 
+
+############################################################
+
+all: $(LIB)
+
+include ../Makefile.rules
+
+clean:	rmcint rmobjs rmcore rmlib
+
+mrproper:	clean rmbak
+
+# @endcode
