Index: trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc	(revision 1772)
+++ trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc	(revision 1809)
@@ -1,3 +1,2 @@
-
 /* ======================================================================== *\
 !
@@ -102,4 +101,8 @@
   fHDiffPixTheta  = fHist3Diff;
 
+  fHSigmaTheta->SetDirectory(NULL);
+  fHSigmaPixTheta->SetDirectory(NULL);
+  fHDiffPixTheta->SetDirectory(NULL);
+
   Print();
 }
@@ -239,4 +242,8 @@
    fHDiffPixTh->SetZTitle("Sigma^2-Sigmabar^2");
 
+   //--------------------------------------------------------------------
+
+   memset(fErrors, 0, sizeof(fErrors));
+
    return kTRUE;
 }
@@ -251,17 +258,26 @@
   //*fLog << "Entry MPadSchweizer::Process();" << endl;
 
+  Int_t rc;
+
   const UInt_t npix = fEvt->GetNumPixels();
+
+  Double_t SigbarOld;
+
+  //*fLog << "before padding : " << endl;
+  //SigbarOld = fSigmabar->Calc(*fCam, *fPed, *fEvt);
+  //fSigmabar->Print("");
+
 
   //$$$$$$$$$$$$$$$$$$$$$$$$$$
   // to simulate the situation that before the padding the NSB and 
   // electronic noise are zero : set Sigma = 0 for all pixels
-  for (UInt_t i=0; i<npix; i++) 
-  {   
-    MCerPhotPix &pix = fEvt->operator[](i);      
-    Int_t j = pix.GetPixId();
-
-    MPedestalPix &ppix = fPed->operator[](j);
-    ppix.SetMeanRms(0.0);
-  }
+  //for (UInt_t i=0; i<npix; i++) 
+  //{   
+  //  MCerPhotPix &pix = fEvt->operator[](i);      
+  //  Int_t j = pix.GetPixId();
+
+  //  MPedestalPix &ppix = fPed->operator[](j);
+  //  ppix.SetMeanRms(0.0);
+  //}
   //$$$$$$$$$$$$$$$$$$$$$$$$$$
 
@@ -269,14 +285,17 @@
   // Calculate average sigma of the event
   //
-  Double_t SigbarOld = fSigmabar->Calc(*fCam, *fPed, *fEvt);
+  SigbarOld = fSigmabar->Calc(*fCam, *fPed, *fEvt);
   //fSigmabar->Print("");
 
-  //if (SigbarOld > 0.0)
-  //{
+  if (SigbarOld > 0.0)
+  {
     //*fLog << "MPadSchweizer::Process(); Sigmabar of event to be padded is > 0 : "
     //      << SigbarOld << ". Stop event loop " << endl;
     // input data should have Sigmabar = 0; stop event loop
-    // return kFALSE; 
-  //}
+  
+    rc = 1;
+    fErrors[rc]++;
+    return kCONTINUE; 
+  }
 
   Double_t Theta  = kRad2Deg*fMcEvt->GetTelescopeTheta();
@@ -296,4 +315,7 @@
           << Theta << ",  " << binNumber << ";  Skip event " << endl;
     // event cannot be padded; skip event
+
+    rc = 2;
+    fErrors[rc]++;
     return kCONTINUE;
   }
@@ -308,4 +330,7 @@
       // event cannot be padded; skip event
       delete fHSigma;
+
+      rc = 3;
+      fErrors[rc]++;
       return kCONTINUE;
     }
@@ -331,4 +356,7 @@
     *fLog << "MPadSchweizer::Process(); target Sigmabar is less than SigbarOld : "
           << Sigmabar << ",  " << SigbarOld << ",   Skip event" << endl;
+
+    rc = 4;
+    fErrors[rc]++;
     return kCONTINUE;     
   }
@@ -426,5 +454,8 @@
               << binTheta << "  and pixel bin " << binPixel  
               << " has no entries;  aborting " << endl;
-        return kERROR;
+
+        rc = 5;
+        fErrors[rc]++;
+        return kCONTINUE;     
       }
 
@@ -465,5 +496,8 @@
               << binTheta << "  and pixel bin " << binPixel  
               << " has no entries;  aborting " << endl;
-        return kERROR;
+
+        rc = 6;
+        fErrors[rc]++;
+        return kCONTINUE;     
       }
 
@@ -553,5 +587,7 @@
 
   // Calculate Sigmabar again and crosscheck
+
   Double_t SigbarNew = fSigmabar->Calc(*fCam, *fPed, *fEvt);
+  //*fLog << "after padding : " << endl;
   //fSigmabar->Print("");
 
@@ -585,4 +621,7 @@
   //*fLog << "Exit MPadSchweizer::Process();" << endl;
 
+  rc = 0;
+  fErrors[rc]++;
+
   return kTRUE;
 
@@ -594,4 +633,42 @@
 Bool_t MPadSchweizer::PostProcess()
 {
+    if (GetNumExecutions() != 0)
+    {
+
+    *fLog << inf << endl;
+    *fLog << GetDescriptor() << " execution statistics:" << endl;
+    *fLog << dec << setfill(' ');
+    *fLog << " " << setw(7) << fErrors[1] << " (" << setw(3) 
+          << (int)(fErrors[1]*100/GetNumExecutions()) 
+          << "%) Evts skipped due to: Sigmabar_old > 0" << endl;
+
+    *fLog << " " << setw(7) << fErrors[2] << " (" << setw(3) 
+          << (int)(fErrors[2]*100/GetNumExecutions()) 
+          << "%) Evts skipped due to: Zenith angle out of range" << endl;
+
+    *fLog << " " << setw(7) << fErrors[3] << " (" << setw(3) 
+          << (int)(fErrors[3]*100/GetNumExecutions()) 
+          << "%) Evts skipped due to: No data for generating Sigmabar" << endl;
+
+    *fLog << " " << setw(7) << fErrors[4] << " (" << setw(3) 
+          << (int)(fErrors[4]*100/GetNumExecutions()) 
+          << "%) Evts skipped due to: Target sigma <= Sigmabar_old" << endl;
+
+    *fLog << " " << setw(7) << fErrors[5] << " (" << setw(3) 
+          << (int)(fErrors[5]*100/GetNumExecutions()) 
+          << "%) Evts skipped due to: No data for generating Sigma^2-Sigmabar^2" << endl;
+
+    *fLog << " " << setw(7) << fErrors[6] << " (" << setw(3) 
+          << (int)(fErrors[6]*100/GetNumExecutions()) 
+          << "%) Evts skipped due to: No data for generating Sigma" << endl;
+
+    *fLog << " " << fErrors[0] << " (" 
+          << (int)(fErrors[0]*100/GetNumExecutions()) 
+          << "%) Evts survived the padding!" << endl;
+    *fLog << endl;
+
+    }
+
+    //---------------------------------------------------------------
     TCanvas &c = *(MH::MakeDefCanvas("PadSchweizer", "", 900, 1200)); 
     c.Divide(3, 4);
@@ -600,19 +677,22 @@
 
     c.cd(1);
+    fHSigmaTheta->SetDirectory(NULL);
     fHSigmaTheta->SetTitle("2D : Sigmabar, \\Theta (reference sample)");
-    fHSigmaTheta->DrawClone();     
+    fHSigmaTheta->DrawCopy();     
     fHSigmaTheta->SetBit(kCanDelete);     
 
       //c.cd(1);
-      //fHSigmaPixTheta->DrawClone();     
+      //fHSigmaPixTheta->DrawCopy();     
       //fHSigmaPixTheta->SetBit(kCanDelete);     
 
     c.cd(4);
-    fHSigbarTheta->DrawClone();     
+    fHSigbarTheta->SetDirectory(NULL);
+    fHSigbarTheta->DrawCopy();     
     fHSigbarTheta->SetBit(kCanDelete);     
 
 
     c.cd(7);
-    fHNSB->DrawClone();
+    fHNSB->SetDirectory(NULL);
+    fHNSB->DrawCopy();
     fHNSB->SetBit(kCanDelete);    
 
@@ -625,21 +705,20 @@
     c.cd(2);
     l = (TH2D*) ((TH3*)fHDiffPixTh)->Project3D("zx");
-
+    l->SetDirectory(NULL);
     l->SetTitle("Sigma^2-Sigmabar^2 vs. \\Theta (all pixels)");
     l->SetXTitle("\\Theta [\\circ]");
     l->SetYTitle("Sigma^2-Sigmabar^2");
 
-    *fLog << "before box" << endl;
-
-    l->Draw("box");
+    l->DrawCopy("box");
     l->SetBit(kCanDelete);;
 
     c.cd(5);
     l = (TH2D*) ((TH3*)fHDiffPixTh)->Project3D("zy");
+    l->SetDirectory(NULL);
     l->SetTitle("Sigma^2-Sigmabar^2 vs. pixel number (all \\Theta)");
     l->SetXTitle("pixel");
     l->SetYTitle("Sigma^2-Sigmabar^2");
 
-    l->Draw("box");
+    l->DrawCopy("box");
     l->SetBit(kCanDelete);;
 
@@ -655,18 +734,20 @@
     c.cd(3);
     k = (TH2D*) ((TH3*)fHSigPixTh)->Project3D("zx");
+    k->SetDirectory(NULL);
     k->SetTitle("Sigma vs. \\Theta (all pixels)");
     k->SetXTitle("\\Theta [\\circ]");
     k->SetYTitle("Sigma");
 
-    k->Draw("box");
+    k->DrawCopy("box");
     k->SetBit(kCanDelete);
 
     c.cd(6);
     k = (TH2D*) ((TH3*)fHSigPixTh)->Project3D("zy");
+    k->SetDirectory(NULL);
     k->SetTitle("Sigma vs. pixel number (all \\Theta)");
     k->SetXTitle("pixel");
     k->SetYTitle("Sigma");
 
-    k->Draw("box");
+    k->DrawCopy("box");
     k->SetBit(kCanDelete);;
 
@@ -677,9 +758,11 @@
 
     c.cd(10);
-    fHSigmaPedestal->DrawClone();
+    fHSigmaPedestal->SetDirectory(NULL);
+    fHSigmaPedestal->DrawCopy();
     fHSigmaPedestal->SetBit(kCanDelete);    
 
     c.cd(11);
-    fHPhotons->DrawClone();
+    fHPhotons->SetDirectory(NULL);
+    fHPhotons->DrawCopy();
     fHPhotons->SetBit(kCanDelete);    
 
