Index: trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc	(revision 2125)
+++ trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc	(revision 2128)
@@ -86,4 +86,5 @@
 #include "MPedestalCam.h"
 #include "MPedestalPix.h"
+#include "MBlindPixels.h"
 
 ClassImp(MPadSchweizer);
@@ -101,4 +102,6 @@
   fHSigmaPixTheta = NULL;
   fHDiffPixTheta  = NULL;
+  fHBlindPixIdTheta = NULL;
+  fHBlindPixNTheta  = NULL;
 
   fHSigmaPedestal = NULL;
@@ -125,15 +128,22 @@
 // fHSigmaPixTheta 3D-hiostogram (Theta, pixel, sigma)
 // fHDiffPixTheta  3D-histogram  (Theta, pixel, sigma^2-sigmabar^2)
-//
-//
-void MPadSchweizer::SetHistograms(TH2D *hist2, TH3D *hist3, TH3D *hist3Diff)
+// fHBlindPixIdTheta 2D-histogram  (Theta, blind pixel Id)
+// fHBlindPixNTheta  2D-histogram  (Theta, no.of blind pixels )
+//
+//
+void MPadSchweizer::SetHistograms(TH2D *hist2, TH3D *hist3, TH3D *hist3Diff,
+                                  TH2D *hist2Pix, TH2D *hist2PixN)
 {
     fHSigmaTheta    = hist2;
     fHSigmaPixTheta = hist3;
     fHDiffPixTheta  = hist3Diff;
+    fHBlindPixIdTheta = hist2Pix;
+    fHBlindPixNTheta  = hist2PixN;
 
     fHSigmaTheta->SetDirectory(NULL);
     fHSigmaPixTheta->SetDirectory(NULL);
     fHDiffPixTheta->SetDirectory(NULL);
+    fHBlindPixIdTheta->SetDirectory(NULL);
+    fHBlindPixNTheta->SetDirectory(NULL);
 
     Print();
@@ -171,5 +181,6 @@
 Bool_t MPadSchweizer::PreProcess(MParList *pList)
 {
-  if ( !fHSigmaTheta  || !fHSigmaPixTheta  || !fHDiffPixTheta)
+  if ( !fHSigmaTheta  || !fHSigmaPixTheta  || !fHDiffPixTheta  ||
+       !fHBlindPixIdTheta  ||  !fHBlindPixNTheta)
   { 
        *fLog << err << "At least one of the histograms needed for the padding is not defined ... aborting." << endl;
@@ -190,5 +201,5 @@
        return kFALSE;
      }
-  
+
    fCam = (MGeomCam*)pList->FindObject("MGeomCam");
    if (!fCam)
@@ -211,4 +222,11 @@
        return kFALSE;
      }
+
+   fBlinds = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
+   if (!fBlinds)
+     {
+       *fLog << err << "MBlindPixels not found... aborting." << endl;
+       return kFALSE;
+     }
    
 
@@ -296,4 +314,81 @@
   //-------------------------------------------
   // for the current theta, 
+  // generate blind pixels according to the histograms 
+  //          fHBlindPixNTheta and fHBlindPixIDTheta
+  //
+
+
+  Int_t binPix = fHBlindPixNTheta->GetXaxis()->FindBin(theta);
+
+  if ( binPix < 1  ||  binPix > fHBlindPixNTheta->GetNbinsX() )
+  {
+    //*fLog << "MPadSchweizer::Process(); binNumber out of range : theta, binPix = "
+    //      << theta << ",  " << binPix << ";  Skip event " << endl;
+    // event cannot be padded; skip event
+
+    rc = 2;
+    fErrors[rc]++;
+    return kCONTINUE;
+  }
+
+  // numBlind is the number of blind pixels in this event
+  TH1D *nblind;
+  UInt_t numBlind;
+
+  nblind = fHBlindPixNTheta->ProjectionY("", binPix, binPix, "");
+  if ( nblind->GetEntries() == 0.0 )
+  {
+    *fLog << "MPadSchweizer::Process(); projection for Theta bin " 
+          << binPix << " has no entries; Skip event " << endl;
+    // event cannot be padded; skip event
+    delete nblind;
+
+    rc = 7;
+    fErrors[rc]++;
+    return kCONTINUE;
+  }
+  else
+  {
+    numBlind = (Int_t) (nblind->GetRandom()+0.5);
+
+    //*fLog << "numBlind = " << numBlind << endl;
+  }
+  delete nblind;
+
+
+  // throw the Id of numBlind different pixels in this event
+  TH1D *hblind;
+  UInt_t idBlind;
+  UInt_t listId[npix];
+  UInt_t nlist = 0;
+  Bool_t equal;
+
+  hblind = fHBlindPixIdTheta->ProjectionY("", binPix, binPix, "");
+  if ( hblind->GetEntries() > 0.0 )
+    for (UInt_t i=0; i<numBlind; i++)
+    {
+      while(1)
+      {
+        idBlind = (Int_t) (hblind->GetRandom()+0.5);
+        equal = kFALSE;
+        for (UInt_t j=0; j<nlist; j++)
+          if (idBlind == listId[j])
+	  { 
+            equal = kTRUE;
+            break;
+	  }
+        if (!equal) break;
+      }
+      listId[nlist] = idBlind;
+      nlist++;
+
+      fBlinds->SetPixelBlind(idBlind);
+      //*fLog << "idBlind = " << idBlind << endl;
+    }
+  delete hblind;
+
+
+  //-------------------------------------------
+  // for the current theta, 
   // generate a sigmabar according to the histogram fHSigmaTheta
   //
@@ -301,13 +396,22 @@
   Int_t binNumber = fHSigmaTheta->GetXaxis()->FindBin(theta);
 
+  if (binPix != binNumber)
+  {
+    cout << "The binnings of the 2 histograms are not identical; aborting"
+         << endl;
+    return kERROR;
+  }
+
   TH1D *hsigma;
 
-  if ( binNumber < 1  ||  binNumber > fHSigmaTheta->GetNbinsX() )
+  hsigma = fHSigmaTheta->ProjectionY("", binNumber, binNumber, "");
+  if ( hsigma->GetEntries() == 0.0 )
   {
-    //*fLog << "MPadSchweizer::Process(); binNumber out of range : theta, binNumber = "
-    //      << theta << ",  " << binNumber << ";  Skip event " << endl;
+    *fLog << "MPadSchweizer::Process(); projection for Theta bin " 
+          << binNumber << " has no entries; Skip event " << endl;
     // event cannot be padded; skip event
-
-    rc = 2;
+    delete hsigma;
+
+    rc = 3;
     fErrors[rc]++;
     return kCONTINUE;
@@ -315,25 +419,9 @@
   else
   {
-    hsigma = fHSigmaTheta->ProjectionY("", binNumber, binNumber, "");
-    if ( hsigma->GetEntries() == 0.0 )
-    {
-      *fLog << "MPadSchweizer::Process(); projection for Theta bin " 
-            << binNumber << " has no entries; Skip event " << endl;
-      // event cannot be padded; skip event
-      delete hsigma;
-
-      rc = 3;
-      fErrors[rc]++;
-      return kCONTINUE;
-    }
-    else
-    {
-      sigmabar = hsigma->GetRandom();
-
-      //*fLog << "Theta, bin number = " << theta << ",  " << binNumber 
-      //      << ",  sigmabar = " << sigmabar << endl;
-    }
-    delete hsigma;
-  }
+    sigmabar = hsigma->GetRandom();
+     //*fLog << "Theta, bin number = " << theta << ",  " << binNumber      //      << ",  sigmabar = " << sigmabar << endl
+  }
+  delete hsigma;
+
   const Double_t sigmabar2 = sigmabar*sigmabar;
 
@@ -644,4 +732,8 @@
           << "%) Evts skipped due to: No data for generating Sigma" << endl;
 
+    *fLog << " " << setw(7) << fErrors[7] << " (" << setw(3) 
+          << (int)(fErrors[7]*100/GetNumExecutions()) 
+          << "%) Evts skipped due to: No data for generating Blind pixels" << endl;
+
     *fLog << " " << fErrors[0] << " (" 
           << (int)(fErrors[0]*100/GetNumExecutions()) 
Index: trunk/MagicSoft/Mars/manalysis/MPadSchweizer.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPadSchweizer.h	(revision 2125)
+++ trunk/MagicSoft/Mars/manalysis/MPadSchweizer.h	(revision 2128)
@@ -20,4 +20,5 @@
 class MSigmabar;
 class MParList;
+class MBlindPixels;
 
 class MPadSchweizer : public MTask
@@ -29,4 +30,5 @@
     MMcEvt         *fMcEvt;
     MPedestalCam   *fPed;
+    MBlindPixels   *fBlinds;
 
     Int_t          fPadFlag;
@@ -34,7 +36,9 @@
     Int_t          fGroup;
 
-    Int_t          fErrors[7];
+    Int_t          fErrors[8];
 
     // plots used for the padding
+    TH2D           *fHBlindPixIdTheta; // 2D-histogram (blind pixel Id vs. Theta)
+    TH2D           *fHBlindPixNTheta; // 2D-histogram (no.of blind pixels vs. Theta)
     TH2D           *fHSigmaTheta;    // 2D-histogram (sigmabar vs. Theta)
     TH3D           *fHSigmaPixTheta; // 3D-histogram (Theta, pixel, sigma)
@@ -53,5 +57,6 @@
     ~MPadSchweizer();
 
-    void SetHistograms(TH2D *hist2, TH3D *hist3, TH3D *hist3Diff);
+    void SetHistograms(TH2D *hist2, TH3D *hist3, TH3D *hist3Diff,
+                       TH2D *hist2Pix, TH2D *hist2PixN);
 
     Bool_t PreProcess(MParList *pList);
