Index: trunk/MagicSoft/Mars/manalysis/MPad.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPad.cc	(revision 4584)
+++ trunk/MagicSoft/Mars/manalysis/MPad.cc	(revision 4841)
@@ -67,5 +67,4 @@
 
 #include "MBinning.h"
-#include "MSigmabar.h"
 #include "MPointingPos.h"
 #include "MLog.h"
@@ -82,11 +81,11 @@
 #include "MPedPhotPix.h"
 
-#include "MBlindPixels.h"
+#include "MBadPixelsCam.h"
+#include "MBadPixelsPix.h"
 
 #include "MRead.h"
 #include "MFilterList.h"
 #include "MTaskList.h"
-#include "MBlindPixelCalc.h"
-#include "MHBlindPixels.h"
+#include "MHBadPixels.h"
 #include "MFillH.h"
 #include "MHSigmaTheta.h"
@@ -124,15 +123,9 @@
   fHgOFF = NULL;
 
-  fHBlindPixIdThetaMC  = NULL;
-  fHBlindPixIdThetaON  = NULL;
-  fHBlindPixIdThetaOFF = NULL;
-
-  fHBlindPixNThetaMC   = NULL;
-  fHBlindPixNThetaON   = NULL;
-  fHBlindPixNThetaOFF  = NULL;
-
   fHSigmaPedestal = NULL;
   fHPhotons       = NULL;
   fHNSB           = NULL;
+
+  fNamePedPhotCam = "MPedPhotCamFromData";
 }
 
@@ -150,6 +143,4 @@
   delete fHSigmaPixTheta;
   delete fHDiffPixTheta;
-  delete fHBlindPixNTheta;
-  delete fHBlindPixIdTheta;
 
   delete fHSigmaPedestal;
@@ -386,9 +377,6 @@
 Bool_t MPad::MergeONOFFMC(
    TH2D& sigthmc,  TH3D& diffpixthmc,  TH3D& sigmapixthmc,
-   TH2D& blindidthmc,  TH2D& blindnthmc,
    TH2D& sigthon,  TH3D& diffpixthon,  TH3D& sigmapixthon,
-   TH2D& blindidthon,  TH2D& blindnthon,
-   TH2D& sigthoff, TH3D& diffpixthoff, TH3D& sigmapixthoff,
-   TH2D& blindidthoff, TH2D& blindnthoff)
+   TH2D& sigthoff, TH3D& diffpixthoff, TH3D& sigmapixthoff)
 {
   //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
@@ -439,13 +427,4 @@
   *fLog << "after booking fHSigmaPixTheta" << endl;
 
-  fHBlindPixNTheta = new TH2D( (const TH2D&) blindnthon );
-  fHBlindPixNTheta->SetNameTitle("2D-ThetaBlindN", "2D-ThetaBlindN (target)");
-
-  *fLog << "after booking fHBlindPixNTheta" << endl;
-
-  fHBlindPixIdTheta = new TH2D( (const TH2D&) blindidthon );
-  fHBlindPixIdTheta->SetNameTitle("2D-ThetaBlindId", "2D-ThetaBlindId (target)");
-
-  *fLog << "after booking fHBlindPixIdTheta" << endl;
   *fLog << all << "Histograms for the merged padding plots were booked" 
         << endl;
@@ -460,26 +439,4 @@
 
   //*fLog << all << "addresses of SigmaTheta padding plots were copied" 
-  //      << endl;
-
-  //--------------------------
-  fHBlindPixNThetaMC = &blindnthmc;
-  fHBlindPixNThetaMC->SetNameTitle("2D-ThetaBlindNMC", "2D-ThetaBlindNMC (orig.)");
-  fHBlindPixNThetaON = &blindnthon;
-  fHBlindPixNThetaON->SetNameTitle("2D-ThetaBlindNON", "2D-ThetaBlindNON (orig.)");
-  fHBlindPixNThetaOFF = &blindnthoff;
-  fHBlindPixNThetaOFF->SetNameTitle("2D-ThetaBlindNOFF", "2D-ThetaBlindNOFF (orig.)");
-
-  //*fLog << all << "addresses of BlindPixTheta padding plots were copied" 
-  //      << endl;
-
-  //--------------------------
-  fHBlindPixIdThetaMC = &blindidthmc;
-  fHBlindPixIdThetaMC->SetNameTitle("2D-ThetaBlindIdMC", "2D-ThetaBlindIdMC (orig.)");
-  fHBlindPixIdThetaON = &blindidthon;
-  fHBlindPixIdThetaON->SetNameTitle("2D-ThetaBlindIdON", "2D-ThetaBlindIdON (orig.)");
-  fHBlindPixIdThetaOFF = &blindidthoff;
-  fHBlindPixIdThetaOFF->SetNameTitle("2D-ThetaBlindIdOFF", "2D-ThetaBlindIdOFF (orig.)");
-
-  //*fLog << all << "addresses of BlindPixIdTheta padding plots were copied" 
   //      << endl;
 
@@ -713,7 +670,4 @@
   //               (they are calculated as 
   //               averages of the ON and OFF distributions)
-  //        fHBlindPixNTheta, fHBlindPixIdTheta
-  //               (they are calculated as 
-  //               the sum of the ON and OFF distributions)
   // (fHDiffPixTheta will be used in the padding of MC events)
 
@@ -739,6 +693,4 @@
     TH2D *histOFF;
 
-    TH1D *hist1;
-    TH1D *hist1OFF;
 
     // weights for ON and OFF distrubtions when
@@ -812,58 +764,4 @@
     delete hist;
     delete histOFF;
-
-
-    //------------------------------------------------------------------
-    // define target distribution  'number of blind pixels per event'
-    ay = blindnthon.GetYaxis();
-    Int_t nbinsn = ay->GetNbins();
-
-    hist1    = fHBlindPixNThetaON->ProjectionY("", j, j, "");
-    hist1->SetName("dummy");
-    hist1OFF = fHBlindPixNThetaOFF->ProjectionY("", j, j, "");
-
-    normON  = hist1->Integral();
-    normOFF = hist1OFF->Integral();
-    if (normON  != 0.0) hist1->Scale(1.0/normON);
-    if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
-
-    // sum of ON and OFF distributions
-    hist1->Add(hist1OFF, 1.0); 
-    Stat_t sum1 = hist1->Integral();
-    if (sum1 != 0.0) hist1->Scale( 1.0/sum1 );
-
-    for (Int_t k=1; k<=nbinsn; k++)
-      {
-        Double_t cont = hist1->GetBinContent(k);
-        fHBlindPixNTheta->SetBinContent(j, k, cont);  
-      }
-
-    delete hist1;
-    delete hist1OFF;
-
-    //------------------------------------------------------------------
-    // define target distribution  'id of blind pixel'
-    ay = blindidthon.GetYaxis();
-    Int_t nbinsid = ay->GetNbins();
-
-    hist1    = fHBlindPixIdThetaON->ProjectionY("", j, j, "");
-    hist1->SetName("dummy");
-    hist1OFF = fHBlindPixIdThetaOFF->ProjectionY("", j, j, "");
-
-    // divide by the number of events (from fHBlindPixNTheta)
-    if (normON  != 0.0) hist1->Scale(1.0/normON);
-    if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
-
-    // sum of ON and OFF distributions
-    hist1->Add(hist1OFF, 1.0); 
-
-    for (Int_t k=1; k<=nbinsid; k++)
-      {
-        Double_t cont = hist1->GetBinContent(k);
-        fHBlindPixIdTheta->SetBinContent(j, k, cont);  
-      }
-
-    delete hist1;
-    delete hist1OFF;
   }
   //............   end of new loop over Theta bins   ....................
@@ -887,12 +785,4 @@
   fHSigmaPixThetaON->SetDirectory(NULL);
   fHSigmaPixThetaOFF->SetDirectory(NULL);
-
-  fHBlindPixIdThetaMC->SetDirectory(NULL);
-  fHBlindPixIdThetaON->SetDirectory(NULL);
-  fHBlindPixIdThetaOFF->SetDirectory(NULL);
-
-  fHBlindPixNThetaMC->SetDirectory(NULL);
-  fHBlindPixNThetaON->SetDirectory(NULL);
-  fHBlindPixNThetaOFF->SetDirectory(NULL);
 
   fHgMC->SetDirectory(NULL);
@@ -1001,7 +891,5 @@
 Bool_t MPad::MergeONMC(
    TH2D& sigthmc,  TH3D& diffpixthmc,  TH3D& sigmapixthmc,
-   TH2D& blindidthmc,  TH2D& blindnthmc,
-   TH2D& sigthon,  TH3D& diffpixthon,  TH3D& sigmapixthon,
-   TH2D& blindidthon,  TH2D& blindnthon)
+   TH2D& sigthon,  TH3D& diffpixthon,  TH3D& sigmapixthon)
 {
   *fLog << all << "----------------------------------------------------------------------------------" << endl;
@@ -1017,10 +905,4 @@
   fHSigmaPixTheta = new TH3D( (TH3D&) sigmapixthon );
   fHSigmaPixTheta->SetNameTitle("3D-ThetaPixSigma", "3D-ThetaPixSigma (target)");
-
-  fHBlindPixNTheta = new TH2D( (TH2D&) blindnthon );
-  fHBlindPixNTheta->SetNameTitle("2D-ThetaBlindN", "2D-ThetaBlindN (target)");
-
-  fHBlindPixIdTheta = new TH2D( (TH2D&) blindidthon );
-  fHBlindPixIdTheta->SetNameTitle("2D-ThetaBlindId", "2D-ThetaBlindId (target)");
 
   //--------------------------
@@ -1029,16 +911,4 @@
   fHSigmaThetaON = &sigthon;
   fHSigmaThetaON->SetNameTitle("2D-ThetaSigmabarON", "2D-ThetaSigmabarON (orig.)");
-
-  //--------------------------
-  fHBlindPixNThetaMC = &blindnthmc;
-  fHBlindPixNThetaMC->SetNameTitle("2D-ThetaBlindNMC", "2D-ThetaBlindNMC (orig.)");
-  fHBlindPixNThetaON = &blindnthon;
-  fHBlindPixNThetaON->SetNameTitle("2D-ThetaBlindNON", "2D-ThetaBlindNON (orig.)");
-
-  //--------------------------
-  fHBlindPixIdThetaMC = &blindidthmc;
-  fHBlindPixIdThetaMC->SetNameTitle("2D-ThetaBlindIdMC", "2D-ThetaBlindIdMC (orig.)");
-  fHBlindPixIdThetaON = &blindidthon;
-  fHBlindPixIdThetaON->SetNameTitle("2D-ThetaBlindIdON", "2D-ThetaBlindIdON (orig.)");
 
   //--------------------------
@@ -1166,7 +1036,4 @@
   //               (they are calculated as 
   //               averages of the ON and MCdistributions)
-  //        fHBlindPixNTheta, fHBlindPixIdTheta
-  //               (they are calculated as 
-  //               the sum of the ON and MC distributions)
   // (fHDiffPixTheta will be used in the padding of MC events)
 
@@ -1191,6 +1058,4 @@
     TH2D *histMC;
 
-    TH1D *hist1;
-    TH1D *hist1MC;
 
     // weights for ON and MC distrubtions when
@@ -1264,58 +1129,5 @@
     delete hist;
     delete histMC;
-
-
     //------------------------------------------------------------------
-    // define target distribution  'number of blind pixels per event'
-    ay = blindnthon.GetYaxis();
-    Int_t nbinsn = ay->GetNbins();
-
-    hist1    = fHBlindPixNThetaON->ProjectionY("", j, j, "");
-    hist1->SetName("dummy");
-    hist1MC  = fHBlindPixNThetaMC->ProjectionY("", j, j, "");
-
-    normON  = hist1->Integral();
-    normMC  = hist1MC->Integral();
-    if (normON  != 0.0) hist1->Scale(1.0/normON);
-    if (normMC  != 0.0) hist1MC->Scale(1.0/normMC);
-
-    // sum of ON and MC distributions
-    hist1->Add(hist1MC, 1.0); 
-    Stat_t sum1 = hist1->Integral();
-    if (sum1 != 0.0) hist1->Scale( 1.0/sum1 );
-
-    for (Int_t k=1; k<=nbinsn; k++)
-      {
-        Double_t cont = hist1->GetBinContent(k);
-        fHBlindPixNTheta->SetBinContent(j, k, cont);  
-      }
-
-    delete hist1;
-    delete hist1MC;
-
-    //------------------------------------------------------------------
-    // define target distribution  'id of blind pixel'
-    ay = blindidthon.GetYaxis();
-    Int_t nbinsid = ay->GetNbins();
-
-    hist1    = fHBlindPixIdThetaON->ProjectionY("", j, j, "");
-    hist1->SetName("dummy");
-    hist1MC = fHBlindPixIdThetaMC->ProjectionY("", j, j, "");
-
-    // divide by the number of events (from fHBlindPixNTheta)
-    if (normON  != 0.0) hist1->Scale(1.0/normON);
-    if (normMC  != 0.0) hist1MC->Scale(1.0/normMC);
-
-    // sum of ON and MC distributions
-    hist1->Add(hist1MC, 1.0); 
-
-    for (Int_t k=1; k<=nbinsid; k++)
-      {
-        Double_t cont = hist1->GetBinContent(k);
-        fHBlindPixIdTheta->SetBinContent(j, k, cont);  
-      }
-
-    delete hist1;
-    delete hist1MC;
   }
   //............   end of new loop over Theta bins   ....................
@@ -1336,10 +1148,4 @@
   fHSigmaPixThetaMC->SetDirectory(NULL);
   fHSigmaPixThetaON->SetDirectory(NULL);
-
-  fHBlindPixIdThetaMC->SetDirectory(NULL);
-  fHBlindPixIdThetaON->SetDirectory(NULL);
-
-  fHBlindPixNThetaMC->SetDirectory(NULL);
-  fHBlindPixNThetaON->SetDirectory(NULL);
 
   fHgMC->SetDirectory(NULL);
@@ -1594,134 +1400,4 @@
 
     //------------------------------------
-      /*
-      fHBlindPixIdTheta = 
-      (TH2D*) gROOT->FindObject("2D-ThetaBlindId");
-      if (!fHBlindPixIdTheta)
-	{
-          *fLog << all 
-                << "MPad : Object '2D-ThetaBlindId' not found on root file" 
-                << endl;
-          return kFALSE;
-	}
-      */
-      fHBlindPixIdTheta = new TH2D;
-      fHBlindPixIdTheta->Read("2D-ThetaBlindId");
-      *fLog << all 
-            << "MPad : Object '2D-ThetaBlindId' was read in" << endl;
-
-      /*
-      fHBlindPixIdThetaMC = 
-      (TH2D*) gROOT->FindObject("2D-ThetaBlindIdMC");
-      if (!fHBlindPixIdThetaMC)
-	{
-          *fLog << all 
-                << "MPad : Object '2D-ThetaBlindIdMC' not found on root file" 
-                << endl;
-          return kFALSE;
-	}
-      */
-      fHBlindPixIdThetaMC = new TH2D;
-      fHBlindPixIdThetaMC->Read("2D-ThetaBlindIdMC");
-      *fLog << all 
-            << "MPad : Object '2D-ThetaBlindIdMC' was read in" << endl;
-
-      /*
-      fHBlindPixIdThetaON = 
-      (TH2D*) gROOT->FindObject("2D-ThetaBlindIdON");
-      if (!fHBlindPixIdThetaON)
-	{
-          *fLog << all 
-                << "MPad : Object '2D-ThetaBlindIdON' not found on root file" 
-                << endl;
-          return kFALSE;
-	}
-      */
-      fHBlindPixIdThetaON = new TH2D;
-      fHBlindPixIdThetaON->Read("2D-ThetaBlindIdON");
-      *fLog << all 
-            << "MPad : Object '2D-ThetaBlindIdON' was read in" << endl;
-
-      /*
-      fHBlindPixIdThetaOFF = 
-      (TH2D*) gROOT->FindObject("2D-ThetaBlindIdOFF");
-      if (!fHBlindPixIdThetaOFF)
-	{
-          *fLog << all 
-                << "MPad : Object '2D-ThetaBlindIdOFF' not found on root file" 
-                << endl;
-          return kFALSE;
-	}
-      */
-      fHBlindPixIdThetaOFF = new TH2D;
-      fHBlindPixIdThetaOFF->Read("2D-ThetaBlindIdOFF");
-      *fLog << all 
-            << "MPad : Object '2D-ThetaBlindIdOFF' was read in" << endl;
-
-    //------------------------------------
-      /*
-      fHBlindPixNTheta = 
-      (TH2D*) gROOT->FindObject("2D-ThetaBlindN");
-      if (!fHBlindPixNTheta)
-	{
-          *fLog << all 
-                << "MPad : Object '2D-ThetaBlindN' not found on root file" 
-                << endl;
-          return kFALSE;
-	}
-      */
-      fHBlindPixNTheta = new TH2D;
-      fHBlindPixNTheta->Read("2D-ThetaBlindN");
-      *fLog << all 
-            << "MPad : Object '2D-ThetaBlindN' was read in" << endl;
-
-      /*
-      fHBlindPixNThetaMC = 
-      (TH2D*) gROOT->FindObject("2D-ThetaBlindNMC");
-      if (!fHBlindPixNThetaMC)
-	{
-          *fLog << all 
-                << "MPad : Object '2D-ThetaBlindNMC' not found on root file" 
-                << endl;
-          return kFALSE;
-	}
-      */
-      fHBlindPixNThetaMC = new TH2D;
-      fHBlindPixNThetaMC->Read("2D-ThetaBlindNMC");
-      *fLog << all 
-            << "MPad : Object '2D-ThetaBlindNMC' was read in" << endl;
-
-      /*
-      fHBlindPixNThetaON = 
-      (TH2D*) gROOT->FindObject("2D-ThetaBlindNON");
-      if (!fHBlindPixNThetaON)
-	{
-          *fLog << all 
-                << "MPad : Object '2D-ThetaBlindNON' not found on root file" 
-                << endl;
-          return kFALSE;
-	}
-      */
-      fHBlindPixNThetaON = new TH2D;
-      fHBlindPixNThetaON->Read("2D-ThetaBlindNON");
-      *fLog << all 
-            << "MPad : Object '2D-ThetaBlindNON' was read in" << endl;
-
-      /*
-      fHBlindPixNThetaOFF = 
-      (TH2D*) gROOT->FindObject("2D-ThetaBlindNOFF");
-      if (!fHBlindPixNThetaOFF)
-	{
-          *fLog << all 
-                << "MPad : Object '2D-ThetaBlindNOFF' not found on root file" 
-                << endl;
-          return kFALSE;
-	}
-      */
-      fHBlindPixNThetaOFF = new TH2D;
-      fHBlindPixNThetaOFF->Read("2D-ThetaBlindNOFF");
-      *fLog << all 
-            << "MPad : Object '2D-ThetaBlindNOFF' was read in" << endl;
-
-    //------------------------------------
 
   return kTRUE;
@@ -1740,14 +1416,4 @@
 
   TFile outfile(namefileout, "RECREATE");
-
-  fHBlindPixNTheta->Write();
-  fHBlindPixNThetaMC->Write();
-  fHBlindPixNThetaON->Write();
-  fHBlindPixNThetaOFF->Write();
-
-  fHBlindPixIdTheta->Write();
-  fHBlindPixIdThetaMC->Write();
-  fHBlindPixIdThetaON->Write();
-  fHBlindPixIdThetaOFF->Write();
 
   fHSigmaThetaMC->Write();
@@ -1801,6 +1467,4 @@
   if ( !fHSigmaThetaMC     || !fHSigmaThetaON     || !fHSigmaThetaOFF      ||  
        !fHDiffPixThetaMC   || !fHDiffPixThetaON   || !fHDiffPixThetaOFF    ||
-       !fHBlindPixIdThetaMC|| !fHBlindPixIdThetaON|| !fHBlindPixIdThetaOFF ||
-       !fHBlindPixNThetaMC || !fHBlindPixNThetaON || !fHBlindPixNThetaOFF  ||
        !fHgMC              || !fHgON              || !fHgOFF                 )
   { 
@@ -1819,11 +1483,12 @@
     }
   
-   fPed = (MPedPhotCam*)pList->FindObject("MPedPhotCam");
-   if (!fPed)
-     {
-       *fLog << err << "MPad : MPedPhotCam not found... aborting." 
-             << endl;
-       return kFALSE;
-     }
+    fPed = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
+    if (!fPed)
+    {
+        *fLog << err << AddSerialNumber(fNamePedPhotCam) 
+              << "[MPedPhotCam] not found... aborting." << endl;
+        return kFALSE;
+    }
+
 
    fCam = (MGeomCam*)pList->FindObject("MGeomCam");
@@ -1844,18 +1509,13 @@
      }
 
-   fSigmabar = (MSigmabar*)pList->FindCreateObj("MSigmabar");
-   if (!fSigmabar)
+
+   fBad = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
+   if (!fBad)
      {
-       *fLog << err << "MPad : MSigmabar not found... aborting." << endl;
-       return kFALSE;
+       *fLog << inf 
+             << "MPad : MBadPixelsCam container not present... continue." 
+             << endl;
      }
 
-   fBlindPix = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
-   if (!fBlindPix)
-     {
-       *fLog << err << "MPad : MBlindPixels not found... aborting." 
-             << endl;
-       return kFALSE;
-     }
    
    if (fType !="ON"  &&  fType !="OFF"  &&  fType !="MC")
@@ -1905,6 +1565,5 @@
 // input for the padding : 
 //  - the matrices fHgON, fHgOFF, fHgMC
-//  - the original distributions fHBlindPixNTheta, fHBlindPixIdTheta
-//                               fHSigmaTheta, fHDiffPixTheta
+//  - the original distributions fHSigmaTheta, fHDiffPixTheta
 //
 
@@ -1963,15 +1622,15 @@
   //
 
-  fSigmabar->Calc(*fCam, *fPed, *fEvt);
   //*fLog << all << "MPad::Process(); before padding : " << endl;
-  //fSigmabar->Print("");
 
   // inner sigmabar/sqrt(area)
-  Double_t sigbarInnerold_phot = fSigmabar->GetSigmabarInner();
+  Double_t ratioinn = fCam->GetPixRatio(0);
+  Double_t sigbarInnerold_phot = (fPed->GetArea(0)).GetRms() * sqrt(ratioinn);
   Double_t sigbarInnerold  = sigbarInnerold_phot * fPEperPhoton;
   Double_t sigbarInnerold2 = sigbarInnerold*sigbarInnerold;
 
   // outer sigmabar/sqrt(area)
-  Double_t sigbarOuterold_phot = fSigmabar->GetSigmabarOuter();
+  Double_t ratioout = fCam->GetPixRatio(500);
+  Double_t sigbarOuterold_phot = (fPed->GetArea(1)).GetRms() * sqrt(ratioout);
   Double_t sigbarOuterold  = sigbarOuterold_phot * fPEperPhoton;
   Double_t sigbarOuterold2 = sigbarOuterold*sigbarOuterold;
@@ -1981,10 +1640,10 @@
   //*fLog << all << "theta = " << theta << endl;
 
-  Int_t binTheta = fHBlindPixNTheta->GetXaxis()->FindBin(theta);
-  if ( binTheta < 1  ||  binTheta > fHBlindPixNTheta->GetNbinsX() )
+  Int_t binTheta = fHSigmaThetaON->GetXaxis()->FindBin(theta);
+  if ( binTheta < 1  ||  binTheta > fHSigmaThetaON->GetNbinsX() )
   {
     *fLog << warn 
           << "MPad::Process(); binNumber out of range : theta, binTheta = "
-          << theta << ",  " << binTheta << ";  aborting " << endl;
+          << theta << ",  " << binTheta << endl;
 
     rc = 2;
@@ -2037,139 +1696,4 @@
  
   //-------------------------------------------
-  // for the current theta :
-  //     generate blind pixels according to the histograms 
-  //     fHBlindPixNTheta and fHBlindPixIDTheta
-  //
-  // ON  : add the blind pixels from the OFF data
-  // OFF : add the blind pixels from the ON data
-  // MC  : add the blind pixels from the ON and OFF data
-
-  //-----------------------------------
-  if (fType == "ON"  ||  fType == "MC")
-  {
-    // numBlind is the number of blind pixels in an event
-    TH1D *nblind;
-    UInt_t numBlind;
-
-    nblind = fHBlindPixNThetaOFF->ProjectionY("", binTheta, binTheta, "");
-    if ( nblind->Integral() == 0.0 )
-    {
-      *fLog << warn << "MPad::Process(); projection of '"
-            << fHBlindPixNThetaOFF->GetName() << "' for Theta bin " 
-            << binTheta << " has no entries; aborting " << endl;
-      // event cannot be padded; skip event
-      delete nblind;
-
-      rc = 7;
-      fErrors[rc]++;
-      return kCONTINUE;
-    }
-    else
-    {
-      numBlind = (Int_t) (nblind->GetRandom()+0.5);
-    }
-    delete nblind;
-
-
-    // throw the Id of numBlind different pixels in this event
-    if ( numBlind > 0)
-    {
-      TH1D *hblind;
-      UInt_t idBlind;
-      UInt_t listId[npix];
-      UInt_t nlist = 0;
-      Bool_t equal;
-
-      hblind = fHBlindPixIdThetaOFF->ProjectionY("", binTheta, binTheta, "");
-      if ( hblind->Integral() > 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++;
-
-          fBlindPix->SetPixelBlind(idBlind);
-          //*fLog << all << "idBlind = " << idBlind << endl;
-        }
-      fBlindPix->SetReadyToSave();
-
-      delete hblind;
-    }
-  }
-
-  //------------------------------------
-  if (fType == "OFF"  ||  fType == "MC")
-  {
-    // throw numBlind;
-    // numBlind is the number of blind pixels in an event
-    TH1D *nblind;
-    UInt_t numBlind;
-
-    nblind = fHBlindPixNThetaON->ProjectionY("", binTheta, binTheta, "");
-    if ( nblind->Integral() == 0.0 )
-    {
-      *fLog << warn << "MPad::Process(); projection of '" 
-            << fHBlindPixNThetaON->GetName() << "' for Theta bin " 
-            << binTheta << " has no entries; Skip event " << endl;
-      delete nblind;
-
-      rc = 7;
-      fErrors[rc]++;
-      return kCONTINUE;
-    }
-    else
-    {
-      numBlind = (Int_t) (nblind->GetRandom()+0.5);
-    }
-    delete nblind;
-
-
-    // throw the Id of numBlind different pixels in this event
-    if ( numBlind > 0)
-    {
-      TH1D *hblind;
-      UInt_t idBlind;
-      UInt_t listId[npix];
-      UInt_t nlist = 0;
-      Bool_t equal;
-
-      hblind = fHBlindPixIdThetaON->ProjectionY("", binTheta, binTheta, "");
-      if ( hblind->Integral() > 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++;
-
-          fBlindPix->SetPixelBlind(idBlind);
-          //*fLog << all << "idBlind = " << idBlind << endl;
-        }
-      fBlindPix->SetReadyToSave();
-
-      delete hblind;
-    }
-  }
 
   //******************************************************************
@@ -2332,5 +1856,5 @@
   // do the padding for each pixel
   //
-  // pad only pixels   - which are used and not blind (before image cleaning)
+  // pad only pixels   - which are used and not bad (before image cleaning)
   //
 
@@ -2403,10 +1927,10 @@
     MPedPhotPix &ppix = (*fPed)[j];
 
-    if ( fBlindPix != NULL  &&  fBlindPix->IsBlind(j) )
+    if ( fBad != NULL  &&  (*fBad)[j].IsUnsuitable() )
     {
-       // this should never occur, because blind pixels should have
-       // been set unused by MBlindPixelsCalc2::UnMap()
-       //*fLog << all << "MPad::Process; blind pixel found which is used, j = "
-       //       << j << "... go to next pixel." << endl;
+       // this should never occur, because bad pixels should have
+       // been set unused 
+       *fLog << all << "MPad::Process; bad pixel found which is used, j = "
+              << j << "... go to next pixel." << endl;
        continue;
     }	
@@ -2569,7 +2093,5 @@
   // Calculate sigmabar again and crosscheck
 
-  fSigmabar->Calc(*fCam, *fPed, *fEvt);
   //*fLog << all << "MPad::Process(); after padding : " << endl;
-  //fSigmabar->Print("");
 
   //*fLog << all << "Exit MPad::Process();" << endl;
@@ -2612,8 +2134,4 @@
           << (int)(fErrors[4]*100/GetNumExecutions()) 
           << "%) Evts skipped due to: Target sigma <= Sigmabar_old" << 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 << " " << setw(7) << fErrors[8] << " (" << setw(3) 
@@ -2656,24 +2174,4 @@
     fHSigmaTheta->DrawCopy();     
     fHSigmaTheta->SetBit(kCanDelete);     
-    */
-
-    //--------------------------------------------------------------------
-
-    /*
-    c.cd(7);
-    fHBlindPixNTheta->SetDirectory(NULL);
-    fHBlindPixNTheta->SetTitle("(Target) 2D : no.of blind pixels, \\Theta");
-    fHBlindPixNTheta->DrawCopy();     
-    fHBlindPixNTheta->SetBit(kCanDelete);     
-    */
-
-    //--------------------------------------------------------------------
-
-    /*
-    c.cd(10);
-    fHBlindPixIdTheta->SetDirectory(NULL);
-    fHBlindPixIdTheta->SetTitle("(Target) 2D : blind pixel Id, \\Theta");
-    fHBlindPixIdTheta->DrawCopy();     
-    fHBlindPixIdTheta->SetBit(kCanDelete);     
     */
 
