Index: trunk/MagicSoft/Mars/mhist/MHBlindPixels.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHBlindPixels.cc	(revision 2117)
+++ trunk/MagicSoft/Mars/mhist/MHBlindPixels.cc	(revision 2128)
@@ -1,2 +1,3 @@
+
 /* ======================================================================== *\
 !
@@ -32,5 +33,12 @@
 #include <TCanvas.h>
 
+#include "MMcEvt.hxx"
 #include "MBlindPixels.h"
+#include "MPedestalCam.h"
+#include "MParList.h"
+#include "MBinning.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
 
 ClassImp(MHBlindPixels);
@@ -41,20 +49,65 @@
 //
 MHBlindPixels::MHBlindPixels(const char *name, const char *title)
-    : fHist(fName, fTitle, 577, -.5, 577-.5)
 {
     fName  = name  ? name  : "MHBlindPixels";
-    fTitle = title ? title : "Histogram for Blind Pixels";
+    fTitle = title ? title : "Histogram for Blind Pixels vs. Theta";
 
     //  - we initialize the histogram
-    //  - we have to give diferent names for the diferent histograms because
+    //  - we have to give different names for the different histograms because
     //    root don't allow us to have diferent histograms with the same name
 
-    fHist.SetName("1D-BlindPixels");
-    fHist.SetTitle(fTitle);
+    fBlindId.SetName("2D-IdBlindPixels");
+    fBlindId.SetTitle("2D-IdBlindPixels");
+    fBlindId.SetDirectory(NULL);
+    fBlindId.SetXTitle("\\Theta [\\circ]");
+    fBlindId.SetYTitle("pixel Id");
 
-    fHist.SetDirectory(NULL);
+    fBlindN.SetName("2D-NBlindPixels");
+    fBlindN.SetTitle("2D-NBlindPixels");
+    fBlindN.SetDirectory(NULL);
+    fBlindN.SetXTitle("\\Theta [\\circ]");
+    fBlindN.SetYTitle("number of blind pixels");
+}
 
-    fHist.SetXTitle("Id");
-    fHist.SetYTitle("Counts");
+// --------------------------------------------------------------------------
+//
+// Set the binnings and prepare the filling of the histogram
+//
+Bool_t MHBlindPixels::SetupFill(const MParList *plist)
+{
+    fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
+    if (!fMcEvt)
+    {
+        *fLog << err << "MMcEvt not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fPed = (MPedestalCam*)plist->FindObject("MPedestalCam");
+    if (!fPed)
+    {
+        *fLog << err << "MPedestalCam not found... aborting." << endl;
+        return kFALSE;
+    }
+
+
+    // Get Theta Binning
+    MBinning* binstheta  = (MBinning*)plist->FindObject("BinningTheta", "MBinning");
+    if (!binstheta)
+    {
+        *fLog << err << "Object 'BinningTheta' [MBinning] not found... aborting" << endl;
+        return kFALSE;
+    }
+
+    // Get binning for pixel number
+    const UInt_t npix1 = fPed->GetSize()+1;
+
+    MBinning binspix("BinningPixel");
+    binspix.SetEdges(npix1, -0.5, npix1-0.5);
+
+    // Set binnings in histograms
+    SetBinning(&fBlindId, binstheta, &binspix);
+    SetBinning(&fBlindN,  binstheta, &binspix);
+
+    return kTRUE;
 }
 
@@ -68,5 +121,33 @@
     pad->SetBorderMode(0);
 
-    fHist.Draw(option);
+    pad->Divide(2,2);
+
+    TH1D *h;
+
+    pad->cd(1);
+    fBlindId.Draw(option);
+
+    pad->cd(2);
+    fBlindN.Draw(option);
+
+    pad->cd(3);
+    gPad->SetBorderMode(0);
+    h = ((TH2*)&fBlindId)->ProjectionY("ProjY-pixId", -1, 9999, "");
+    h->SetDirectory(NULL);
+    h->SetTitle("Distribution of blind pixel Id");
+    h->SetXTitle("Id of blind pixel");
+    h->SetYTitle("No. of events");
+    h->Draw(option);
+    h->SetBit(kCanDelete);
+
+    pad->cd(4);
+    gPad->SetBorderMode(0);
+    h = ((TH2*)&fBlindN)->ProjectionY("ProjY-pixN", -1, 9999, "");
+    h->SetDirectory(NULL);
+    h->SetTitle("Distribution of no.of blind pixels");
+    h->SetXTitle("No. of blind pixels");
+    h->SetYTitle("No. of events");
+    h->Draw(option);
+    h->SetBit(kCanDelete);
 
     pad->Modified();
@@ -79,11 +160,33 @@
         return kFALSE;
 
+    Double_t theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
     const MBlindPixels &bp = *(MBlindPixels*)par;
 
     // FIXME: Slow.
-    for (int i=0; i<577; i++)
+    const UInt_t npix = fPed->GetSize();
+
+    UInt_t nb = 0;
+    for (UInt_t i=0; i<npix; i++)
+    {
         if (bp.IsBlind(i))
-            fHist.Fill(i, w);
+	{
+          fBlindId.Fill(theta, i, w);
+          nb++;
+	}   
+    }
+    fBlindN.Fill(theta, nb, w);
 
     return kTRUE;
 }
+
+
+
+
+
+
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mhist/MHBlindPixels.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHBlindPixels.h	(revision 2117)
+++ trunk/MagicSoft/Mars/mhist/MHBlindPixels.h	(revision 2128)
@@ -5,26 +5,42 @@
 #include "MH.h"
 #endif
-#ifndef ROOT_TH1
-#include <TH1.h>
+#ifndef ROOT_TH2
+#include <TH2.h>
 #endif
+
+class MPedestalCam;
+class MMcEvt;
+class MParList;
+
 
 class MHBlindPixels : public MH
 {
 private:
-    TH1D fHist; //
+    MPedestalCam  *fPed;      //!
+    MMcEvt        *fMcEvt;    //!
+
+    TH2D          fBlindId; // 2D-histogram : pixel Id vs. Theta
+    TH2D          fBlindN;  // 2D-histogram : no.of blind pixels vs. Theta
 
 public:
     MHBlindPixels(const char *name=NULL, const char *title=NULL);
 
-    const TH1D *GetHist()       { return &fHist; }
-    const TH1D *GetHist() const { return &fHist; }
+    const TH2D *GetBlindId()       { return &fBlindId; }
+    const TH2D *GetBlindId() const { return &fBlindId; }
 
-    TH1 *GetHistByName(const TString name) { return &fHist; }
+    const TH2D *GetBlindN()       { return &fBlindN; }
+    const TH2D *GetBlindN() const { return &fBlindN; }
+
+    TH2 *GetBlinIdByName(const TString name) { return &fBlindId; }
+    TH2 *GetBlinNByName(const TString name) { return &fBlindN; }
 
     void Draw(Option_t* option = "");
+    Bool_t SetupFill(const MParList *plist);
     Bool_t Fill(const MParContainer *par, const Stat_t w=1);
 
-    ClassDef(MHBlindPixels, 1)  // Histogram of blind pixels
+    ClassDef(MHBlindPixels, 1)  // Histogram of blind pixel Id vs. Theta
 };
 
 #endif
+
+
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 2117)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 2128)
@@ -788,8 +788,9 @@
     // Calculate normalization factors
     //
-    const int    nbins   = thsh.GetNbinsX();
-    const double frombin = thsh.GetBinLowEdge(1);
-    const double tobin   = thsh.GetBinLowEdge(nbins+1);
-    const double dbin    = thsh.GetBinWidth(1);
+    //const int    nbins   = thsh.GetNbinsX();
+    //const double frombin = thsh.GetBinLowEdge(1);
+    //const double tobin   = thsh.GetBinLowEdge(nbins+1);
+    //const double dbin    = thsh.GetBinWidth(1);
+
     const Int_t  nrows   = fM.GetNrows();
     const Int_t  ncols   = fM.GetNcols();
@@ -798,10 +799,16 @@
     // set up the real histogram (distribution before)
     //
-    TH1F hth("th", "Distribution before reduction", nbins, frombin, tobin);
+    //TH1F hth("th", "Distribution before reduction", nbins, frombin, tobin);
+    TH1F hth;
+    hth.SetNameTitle("th", "Distribution before reduction");
+    SetBinning(&hth, &thsh);
     hth.SetDirectory(NULL);
     for (Int_t j=0; j<nrows; j++)
         hth.Fill(fM(j, refcolumn));
 
-    TH1F hthd("thd", "Correction factors", nbins, frombin, tobin);
+    //TH1F hthd("thd", "Correction factors", nbins, frombin, tobin);
+    TH1F hthd;
+    hthd.SetNameTitle("thd", "Correction factors");
+    SetBinning(&hthd, &thsh);
     hthd.SetDirectory(NULL);
     hthd.Divide((TH1F*)&thsh, &hth, 1, 1);
@@ -840,6 +847,6 @@
     TVector v(fM.GetNrows());
     v = TMatrixColumn(fM, refcolumn);
-    v += -frombin;
-    v *= 1/dbin;
+    //v += -frombin;
+    //v *= 1/dbin;
 
     //
@@ -850,6 +857,6 @@
     for (ir=0; ir<nrows; ir++)
     {
-        const Int_t indref = (Int_t)v(ind[ir]);
-
+        // const Int_t indref = (Int_t)v(ind[ir]);
+        const Int_t indref = hthd.FindBin(v(ind[ir])) - 1;
         cumulweight[indref] += hthd.GetBinContent(indref+1);
         if (cumulweight[indref]<=0.5)
Index: trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc	(revision 2117)
+++ trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc	(revision 2128)
@@ -100,5 +100,5 @@
 
     MBinning binspix("BinningPixel");
-    binspix.SetEdges(577, -0.5, 577.5);
+    binspix.SetEdges(578, -0.5, 577.5);
 
     SetBinning(&fSigmaTheta,    &binst, &binsb);
@@ -169,8 +169,8 @@
 
     // Get binning for pixel number
-    const UInt_t npix = fPed->GetSize();
+    const UInt_t npix1 = fPed->GetSize()+1;
 
     MBinning binspix("BinningPixel");
-    binspix.SetEdges(npix, -0.5, 0.5+npix);
+    binspix.SetEdges(npix1, -0.5, npix1-0.5);
 
     // Set binnings in histograms
