Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc	(revision 5117)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc	(revision 5431)
@@ -106,5 +106,5 @@
         if (!fPedPhotCam)
         {
-            *fLog << err << "MPedPhotCam not found... aborting." << endl;
+	  *fLog << err << fNamePedPhotContainer << "[MPedPhotCam] not found... aborting." << endl;
             return kFALSE;
         }
@@ -117,4 +117,8 @@
         }
     }
+
+    *fLog << inf << "Name of MPedPhotCam container : " << fNamePedPhotContainer
+          << endl;
+
     return kTRUE;
 }
@@ -257,4 +261,5 @@
         fPedPhotCam->ReCalc(*fGeomCam, fBadPixels);
     }
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.h	(revision 5117)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.h	(revision 5431)
@@ -37,2 +37,6 @@
 
 #endif
+
+
+
+
Index: trunk/MagicSoft/Mars/mbadpixels/MHBadPixels.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MHBadPixels.cc	(revision 5117)
+++ trunk/MagicSoft/Mars/mbadpixels/MHBadPixels.cc	(revision 5431)
@@ -35,4 +35,5 @@
 #include "MBadPixelsCam.h"
 #include "MGeomCam.h"
+#include "MPedPhotCam.h"
 #include "MParList.h"
 #include "MBinning.h"
@@ -47,24 +48,55 @@
 // -------------------------------------------------------------------------
 //
-//  Default Constructor.
+//  Constructor.
 //
 MHBadPixels::MHBadPixels(const char *name, const char *title)
-    : fNamePedPhotCam("MPedPhotCam")
 {
     fName  = name  ? name  : "MHBadPixels";
     fTitle = title ? title : "Histogram for Bad Pixels vs. Theta";
 
-    fBadId.SetName("2D-IdBadPixels");
-    fBadId.SetTitle("2D-IdBadPixels");
-    fBadId.SetDirectory(NULL);
-    fBadId.SetXTitle("\\Theta [\\circ]");
-    fBadId.SetYTitle("pixel Id");
-
-    fBadN.SetName("2D-NBadPixels");
-    fBadN.SetTitle("2D-NBadPixels");
-    fBadN.SetDirectory(NULL);
-    fBadN.SetXTitle("\\Theta [\\circ]");
-    fBadN.SetYTitle("number of bad pixels");
-
+    fBadId = new TH2D;
+    fBadId->SetName("2D-IdBadPixels");
+    fBadId->SetTitle("2D-IdBadPixels");
+    fBadId->SetDirectory(NULL);
+    fBadId->UseCurrentStyle();
+    fBadId->SetXTitle("\\Theta [\\circ]");
+    fBadId->SetYTitle("pixel Id");
+    fBadId->SetTitleOffset(1.2, "Y");
+
+    fBadN = new TH2D;
+    fBadN->SetName("2D-NBadPixels");
+    fBadN->SetTitle("2D-NBadPixels");
+    fBadN->SetDirectory(NULL);
+    fBadN->UseCurrentStyle();
+    fBadN->SetXTitle("\\Theta [\\circ]");
+    fBadN->SetYTitle("number of bad pixels");
+    fBadN->SetTitleOffset(1.2, "Y");
+
+    // define default binnings
+    fBinsTheta = new MBinning;
+    fBinsTheta->SetEdgesCos(10,  0.0,  90.0);    // theta
+
+    fBinsPix = new MBinning;
+    fBinsPix->SetEdges(578, -0.5, 577.5);    // pixel id
+
+    SetBinning(fBadId, fBinsTheta, fBinsPix);
+    SetBinning(fBadN,  fBinsTheta, fBinsPix);
+
+    //-----------------------------------------
+    fNamePedPhotCam = "MPedPhotCamFromData";
+}
+
+
+// -------------------------------------------------------------------------
+//
+//  Destructor.
+//
+MHBadPixels::~MHBadPixels()
+{
+  delete fBadId;
+  delete fBadN;
+
+  delete fBinsTheta;
+  delete fBinsPix;
 }
 
@@ -75,10 +107,12 @@
 Bool_t MHBadPixels::SetupFill(const MParList *plist)
 {
-    MGeomCam *fCam = (MGeomCam*)plist->FindObject(AddSerialNumber("MGeomCam"));
+    fCam = (MGeomCam*)plist->FindObject(AddSerialNumber("MGeomCam"));
     if (!fCam)    
     {
-        *fLog << err << "MGeomCam not found... aborting." << endl;
-        return kFALSE;
-    }
+        *fLog << err << "MHBadPixels::SetupFill; MGeomCam not found... aborting." << endl;
+        return kFALSE;
+    }
+    *fLog << "MHBadPixels::SetupFill; fCam = " << fCam << endl;
+
     fPointPos = (MPointingPos*)plist->FindObject("MPointingPos");
     if (!fPointPos)
@@ -87,23 +121,44 @@
         return kFALSE;
     }
+    
+    fPedPhot = (MPedPhotCam*)plist->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
+    if (!fPedPhot)
+    {
+        *fLog << err << AddSerialNumber(fNamePedPhotCam) 
+              << "[MPedPhotCam] not found... aborting." << endl;
+        return kFALSE;
+    }
+    fPedPhot->InitSize(fCam->GetNumPixels());
+
 
     //----------------------------------------------------
+    *fLog << inf << "Name of MPedPhotCam container : " << fNamePedPhotCam
+          << endl;
+
+
+    //----------------------------------------------------
+    // redefine the binnings
+    
     // Get Theta Binning
-    MBinning* binstheta  = (MBinning*)plist->FindObject("BinningTheta", "MBinning");
+    const MBinning* binstheta  = (MBinning*)plist->FindObject("BinningTheta", "MBinning");
     if (!binstheta)
     {
-        *fLog << err << "BinningTheta [MBinning] not found... aborting" << endl;
-        return kFALSE;
-    }
-
-    // Get binning for pixel number
-    const UInt_t npix1 = fCam->GetNumPixels()+1;
-
+        *fLog << err << "Object 'BinningTheta' [MBinning] not found... use default binning." << endl;
+        binstheta = fBinsTheta;
+    }
+
+    // Define binning for pixel number
+    const UInt_t npix1 = fPedPhot->GetSize()+1;
+    //*fLog << "MHBadPixels::SetupFill(); npix1 = " << npix1 << endl;
     MBinning binspix("BinningPixel");
     binspix.SetEdges(npix1, -0.5, npix1-0.5);
 
     // Set binnings in histograms
-    SetBinning(&fBadId, binstheta, &binspix);
-    SetBinning(&fBadN,  binstheta, &binspix);
+    SetBinning(fBadId, binstheta, &binspix);
+    SetBinning(fBadN,  binstheta, &binspix);
+
+    *fLog << "MHBadPixels::SetupFill(); binnings were set" << endl;
+    
+
 
     return kTRUE;
@@ -122,18 +177,21 @@
     Double_t theta = fPointPos->GetZd();
 
-    const MBadPixelsCam *badpixels = (MBadPixelsCam*)par;
-
-    const UInt_t entries = badpixels->GetSize();
-
+    const MBadPixelsCam *fBadPixels = (MBadPixelsCam*)par;
+
+    const UInt_t entries = fPedPhot->GetSize(); 
     UInt_t nb = 0;
     for (UInt_t i=0; i<entries; i++)
     {
-        if ( (*badpixels)[i].IsUnsuitable() )
-        {
-            fBadId.Fill(theta, i, w);
-            nb++;
-        }
-    }
-    fBadN.Fill(theta, nb, w);
+      //*fLog << "MHBadPixels::Fill; i = " << i << endl;
+
+      if ( (*fBadPixels)[i].IsUnsuitable() )
+      {
+	//*fLog << "MHBadPixels::Fill; (UnSuitable) " << endl;
+
+          fBadId->Fill(theta, i, w);
+          nb++;
+      }   
+    }
+    fBadN->Fill(theta, nb, w);
 
     return kTRUE;
@@ -154,16 +212,17 @@
 
     pad->cd(1);
-    fBadId.Draw(option);
+    fBadId->Draw(option);
 
     pad->cd(2);
-    fBadN.Draw(option);
+    fBadN->Draw(option);
 
     pad->cd(3);
     gPad->SetBorderMode(0);
-    h = ((TH2*)&fBadId)->ProjectionY("ProjY-pixId", -1, 9999, "");
+    h = ((TH2*)fBadId)->ProjectionY("ProjY-pixId", -1, 9999, "");
     h->SetDirectory(NULL);
     h->SetTitle("Distribution of bad pixel Id");
     h->SetXTitle("Id of bad pixel");
     h->SetYTitle("No. of events");
+    h->SetTitleOffset(1.2, "Y");
     h->Draw(option);
     h->SetBit(kCanDelete);
@@ -171,9 +230,10 @@
     pad->cd(4);
     gPad->SetBorderMode(0);
-    h = ((TH2*)&fBadN)->ProjectionY("ProjY-pixN", -1, 9999, "");
+    h = ((TH2*)fBadN)->ProjectionY("ProjY-pixN", -1, 9999, "");
     h->SetDirectory(NULL);
     h->SetTitle("Distribution of no.of bad pixels");
     h->SetXTitle("No. of bad pixels");
     h->SetYTitle("No. of events");
+    h->SetTitleOffset(1.2, "Y");
     h->Draw(option);
     h->SetBit(kCanDelete);
@@ -182,2 +242,14 @@
     pad->Update();
 }
+//==========================================================================
+
+
+
+
+
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mbadpixels/MHBadPixels.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MHBadPixels.h	(revision 5117)
+++ trunk/MagicSoft/Mars/mbadpixels/MHBadPixels.h	(revision 5431)
@@ -18,21 +18,28 @@
 private:
     MGeomCam      *fCam;      //!
+    MPedPhotCam   *fPedPhot;  //!
     MPointingPos  *fPointPos; //!
 
     TString  fNamePedPhotCam; //! name of the 'MPedPhotCam' container
+    MBinning *fBinsTheta;     //!
+    MBinning *fBinsPix;       //!
 
-    TH2D          fBadId; // 2D-histogram : pixel Id vs. Theta
-    TH2D          fBadN;  // 2D-histogram : no.of bad pixels vs. Theta
+    TH2D          *fBadId; // 2D-histogram : pixel Id vs. Theta
+    TH2D          *fBadN;  // 2D-histogram : no.of bad pixels vs. Theta
 
 public:
     MHBadPixels(const char *name=NULL, const char *title=NULL);
+    ~MHBadPixels();
 
     void SetNamePedPhotCam(const char *name)  { fNamePedPhotCam = name; }
 
-    const TH2D *GetBadId()       { return &fBadId; }
-    const TH2D *GetBadId() const { return &fBadId; }
+    const TH2D *GetBadId()       { return fBadId; }
+    const TH2D *GetBadId() const { return fBadId; }
 
-    const TH2D *GetBadN()       { return &fBadN; }
-    const TH2D *GetBadN() const { return &fBadN; }
+    const TH2D *GetBadN()       { return fBadN; }
+    const TH2D *GetBadN() const { return fBadN; }
+
+    TH2 *GetBadIdByName(const TString name) { return fBadId; }
+    TH2 *GetBadNByName(const TString name)  { return fBadN; }
 
     void Draw(Option_t* option = "");
