Index: trunk/MagicSoft/Mars/manalysis/MApplyPadding.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MApplyPadding.cc	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MApplyPadding.cc	(revision 1951)
@@ -78,5 +78,5 @@
 // Default constructor. 
 //
-MApplyPadding::MApplyPadding(const char *name, const char *title) : fRunType(0), fGroup(0), fUseHistogram(kTRUE), fFixedSigmabar(0.0)
+MApplyPadding::MApplyPadding(const char *name, const char *title) : fRunType(0), fGroup(0), fUseHistogram(kTRUE), fFixedSigmabar(0.0), fRnd(0)
 {
   fName  = name  ? name  : "MApplyPadding";
@@ -87,20 +87,10 @@
 // --------------------------------------------------------------------------
 //
-// Destructor. 
-//
-MApplyPadding::~MApplyPadding()
-{
-  //nothing yet
-}
-
-// --------------------------------------------------------------------------
-//
 // You can provide a TH1D* histogram containing the target Sigmabar in
 // bins of theta. Be sure to use the same binning as for the analysis
 //
-Bool_t MApplyPadding::SetDefiningHistogram(TH1D *histo)
+void MApplyPadding::SetDefiningHistogram(TH1D *histo)
 {
   fHSigmabarMax = histo;
-  return kTRUE;
 }
 
@@ -113,6 +103,4 @@
 Bool_t MApplyPadding::PreProcess(MParList *pList)
 {
-  fRnd = new TRandom3(0);
-
   fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
   if (!fMcEvt)
@@ -163,18 +151,9 @@
    if ((!fUseHistogram) && (fHSigmabarMax==NULL)) {
      
-     fHSigmabarMax = new TH1D();
+     fHSigmabarMax = new TH1D;
      fHSigmabarMax->SetNameTitle("fHSigmabarMax","Sigmabarmax for this analysis");
-     TAxis &x = *fHSigmabarMax->GetXaxis();
-#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
-     TString xtitle = x.GetTitle();
-#endif
-     fHSigmabarMax->SetBins(binstheta->GetNumBins(), 0, 1);
-     // Set the binning of the current histogram to the binning
-     // in one of the two given histograms
-     x.Set(binstheta->GetNumBins(), binstheta->GetEdges());
-#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
-     x.SetTitle(xtitle);
-#endif
-     
+
+     MH::SetBinning(fHSigmabarMax, binstheta);
+
      // -------------------------------------------------
      // read in SigmabarParams
@@ -229,15 +208,14 @@
 
   // Get sigmabar which we have to pad to
-  Double_t otherSig;
+  Double_t otherSig = fFixedSigmabar;
   if (fUseHistogram) {
-    Int_t binNumber = fHSigmabarMax->GetXaxis()->FindBin(fMcEvt->GetTheta()*kRad2Deg);
+    Int_t binNumber = fHSigmabarMax->GetXaxis()->FindBin(fMcEvt->GetTelescopeTheta()*kRad2Deg);
     otherSig = fHSigmabarMax->GetBinContent(binNumber);
-  } else {
-    otherSig = fFixedSigmabar;
   }
 
   // Determine quadratic difference other-mine
-  Double_t quadraticDiff = otherSig*otherSig - mySig*mySig;
-
+  const Double_t quadraticDiff = otherSig*otherSig - mySig*mySig;
+
+  // crosscheck, should never happen
   if (quadraticDiff < 0) {
     *fLog << err << dbginf << "Event has higher Sigmabar="<<mySig<<" than Sigmabarmax="<<otherSig << " ...Skipping this event" <<endl;
@@ -248,6 +226,4 @@
   
   // Pad if quadratic difference > 0 
-  if (quadraticDiff > 0) {    
-
    MPedestalCam newPed;
    newPed.InitSize(fPed->GetSize());
@@ -257,10 +233,10 @@
 
    for (UInt_t i=0; i<npix; i++) {
-     MCerPhotPix pix = fEvt->operator[](i);      
+     MCerPhotPix &pix = (*fEvt)[i];
      if (!pix.IsPixelUsed())
        continue;
      pix.SetNumPhotons(pix.GetNumPhotons() +
 		       sqrt(quadraticDiff)*
-		       fRnd->Gaus(0.0, 1.0)/
+		       fRnd.Gaus(0.0, 1.0)/
 		       fCam->GetPixRatio(pix.GetPixId())
 		       );
@@ -268,8 +244,6 @@
      Double_t error = pix.GetErrorPhot();
      pix.SetErrorPhot(sqrt(error*error + quadraticDiff));
-     MPedestalPix ppix = fPed->operator[](i);
-     MPedestalPix npix;
-     npix.SetSigma(sqrt(ppix.GetSigma()*ppix.GetSigma() + quadraticDiff));
-     newPed[i]=npix;
+     MPedestalPix &ppix = (*fPed)[i];
+     newPed[i].SetSigma(sqrt(ppix.GetSigma()*ppix.GetSigma() + quadraticDiff));
     } //for
    // Calculate Sigmabar again and crosscheck
@@ -278,11 +252,4 @@
    // fTest->Fill(otherSig,mySig);
    return kTRUE;
-  } //if 
-  return kFALSE;
-}
-
-Bool_t MApplyPadding::PostProcess()
-{
-  //  fTest->DrawClone();
-  return kTRUE;
-}
+}
+
Index: trunk/MagicSoft/Mars/manalysis/MApplyPadding.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MApplyPadding.h	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MApplyPadding.h	(revision 1951)
@@ -24,5 +24,5 @@
     MCerPhotEvt *fEvt; 
     MSigmabar *fSigmabar;
-    TRandom3 *fRnd;
+    TRandom3 fRnd;
     Int_t fRunType;
     Int_t fGroup;
@@ -37,9 +37,7 @@
 public:
     MApplyPadding(const char *name=NULL, const char *title=NULL);
-    ~MApplyPadding();
 
     Bool_t PreProcess(MParList *pList);
     Bool_t Process();
-    Bool_t PostProcess();
     
     void SetRunType(Int_t runtype) { fRunType =  runtype; }
@@ -47,5 +45,5 @@
     void SetDatabaseFile(char *filename) { fDatabaseFilename = filename; }
     void SetTargetLevel(Double_t sigmabar) { fFixedSigmabar = sigmabar; fUseHistogram=kFALSE; }
-    Bool_t SetDefiningHistogram(TH1D *histo);
+    void SetDefiningHistogram(TH1D *histo);
 
     ClassDef(MApplyPadding, 1)    // task for applying padding
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h	(revision 1951)
@@ -15,4 +15,5 @@
     Bool_t  fIsCore;      // the pixel is a Core pixel          --> kTRUE
 
+    UShort_t fRing;       // NT: number of analyzed rings around the core pixels
     Float_t fPhot;        // The number of Cerenkov photons
     Float_t fErrPhot;     // the error of fPhot
@@ -31,6 +32,10 @@
 
     Bool_t  IsPixelUsed() const      { return fIsUsed;   }
-    void    SetPixelUnused()         { fIsUsed = kFALSE; }
-    void    SetPixelUsed()           { fIsUsed = kTRUE;  }
+    void    SetPixelUnused()         { fIsUsed = kFALSE; fRing=0; }
+    void    SetPixelUsed()           { fIsUsed = kTRUE;  fRing=1;  }
+
+    void    SetRing(Short_t r)       { fRing = r; fIsUsed = (r>0); }
+
+    Short_t GetRing() const          { return fRing;}
 
     void    SetPixelCore()           { fIsCore = kTRUE; }
Index: trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc	(revision 1951)
@@ -145,5 +145,5 @@
    if (!fPed)
      {
-       *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
+       *fLog << err << "MPedestalCam not found... aborting." << endl;
        return kFALSE;
      }
@@ -152,5 +152,5 @@
    if (!fCam)
      {
-       *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
+       *fLog << err << "MGeomCam not found (no geometry information available)... aborting." << endl;
        return kFALSE;
      }
@@ -159,5 +159,5 @@
    if (!fEvt)
      {
-       *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
+       *fLog << err << "MCerPhotEvt not found... aborting." << endl;
        return kFALSE;
      }
@@ -166,29 +166,29 @@
    if (!fSigmabar)
      {
-       *fLog << dbginf << "MSigmabar not found... aborting." << endl;
+       *fLog << err << "MSigmabar not found... aborting." << endl;
        return kFALSE;
      }
    
    // Get Theta Binning  
-   MBinning* binstheta  = (MBinning*)pList->FindObject("BinningTheta");
+   MBinning* binstheta = (MBinning*)pList->FindObject("BinningTheta");
    if (!binstheta)
      {
-       *fLog << err << dbginf << "BinningTheta not found... aborting." << endl;
+       *fLog << err << "BinningTheta not found... aborting." << endl;
        return kFALSE;      
      }
 
    // Get Sigma Binning  
-   MBinning* binssigma  = (MBinning*)pList->FindObject("BinningSigmabar");
+   MBinning* binssigma = (MBinning*)pList->FindObject("BinningSigmabar");
    if (!binssigma)
      {
-       *fLog << err << dbginf << "BinningSigmabar not found... aborting." << endl;
+       *fLog << err << "BinningSigmabar not found... aborting." << endl;
        return kFALSE;      
      }
 
    // Get binning for (sigma^2-sigmabar^2)  
-   MBinning* binsdiff  = (MBinning*)pList->FindObject("BinningDiffsigma2");
+   MBinning* binsdiff = (MBinning*)pList->FindObject("BinningDiffsigma2");
    if (!binsdiff)
      {
-       *fLog << err << dbginf << "BinningDiffsigma2 not found... aborting." << endl;
+       *fLog << err << "BinningDiffsigma2 not found... aborting." << endl;
        return kFALSE;      
      }
Index: trunk/MagicSoft/Mars/manalysis/MPadding.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPadding.cc	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MPadding.cc	(revision 1951)
@@ -16,6 +16,7 @@
 !
 !
-!   Author(s): Robert Wagner   <mailto:magicsoft@rwagner.de> 10/2002
-!              Wolfgang Wittek <mailto:wittek@mppmu.mpg.de>  01/2003
+!   Author(s): Robert Wagner, 10/2002   <mailto:magicsoft@rwagner.de>
+!   Author(s): Wolfgang Wittek, 01/2003 <mailto:wittek@mppmu.mpg.de>
+!   Author(s): Thomas Bretz, 04/2003    <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2003
@@ -61,4 +62,6 @@
 //  missing. It is not the FINAL MAGIC VERSION.                            //
 //                                                                         //
+//  For random numbers gRandom is used.                                    //
+//                                                                         //
 /////////////////////////////////////////////////////////////////////////////
 #include "MPadding.h"
@@ -66,20 +69,29 @@
 #include <stdio.h>
 
-#include "TH1.h"
-#include "TH2.h"
-#include "TH3.h"
-#include "TProfile.h"
-#include "TRandom.h"
-#include "TCanvas.h"
-
+#include <TH1.h>
+#include <TH2.h>
+#include <TH3.h>
+#include <TRandom.h>
+#include <TCanvas.h>
+#include <TProfile.h>
+
+#include "MH.h"
 #include "MBinning.h"
+
 #include "MSigmabar.h"
+
 #include "MMcEvt.hxx"
+
+#include "MParList.h"
+
 #include "MLog.h"
 #include "MLogManip.h"
-#include "MParList.h"
+
 #include "MGeomCam.h"
+
+#include "MCerPhotEvt.h"
 #include "MCerPhotPix.h"
-#include "MCerPhotEvt.h"
+
+#include "MPedestalCam.h"
 #include "MPedestalPix.h"
 
@@ -90,14 +102,37 @@
 // Default constructor. 
 //
-MPadding::MPadding(const char *name, const char *title) : fRunType(0), fGroup(0), fFixedSigmabar(0.0)
-{
-  fName  = name  ? name  : "MPadding";
-  fTitle = title ? title : "Task for the padding";
-
-  fFixedSigmabar = 0.0;
-  fHSigmabarMax  = NULL;
-  fHSigmaTheta   = NULL;
-
-  Print();
+MPadding::MPadding(const char *name, const char *title)
+    : fRunType(0), fGroup(0), fFixedSigmabar(0), fHSigMaxAllocated(kFALSE), fHSigmabarMax(NULL), fHSigmaTheta(NULL)
+{
+    fName  = name  ? name  : "MPadding";
+    fTitle = title ? title : "Task for the padding";
+
+    //--------------------------------------------------------------------
+    // plot pedestal sigmas for testing purposes
+    fHSigmaPedestal = new TH2D("SigPed", "Padded vs orig. sigma",
+                               100, 0.0, 5.0, 100, 0.0, 5.0);
+   fHSigmaPedestal->SetXTitle("Orig. Pedestal sigma");
+   fHSigmaPedestal->SetYTitle("Padded Pedestal sigma");
+
+   // plot no.of photons (before vs. after padding) for testing purposes
+   fHPhotons = new TH2D("Photons", "Photons after vs.before padding",
+                        100, -10.0, 90.0, 100, -10, 90);
+   fHPhotons->SetXTitle("No.of photons before padding");
+   fHPhotons->SetYTitle("No.of photons after padding");
+
+   // plot of added NSB
+   fHNSB = new TH1D("NSB", "Distribution of added NSB", 100, -10.0, 10.0);
+   fHNSB->SetXTitle("No.of added NSB photons");
+   fHNSB->SetYTitle("No.of pixels");
+
+   fHSigmaOld = new TH2D;
+   fHSigmaOld->SetNameTitle("fHSigmaOld", "Sigma before padding");
+   fHSigmaOld->SetXTitle("Theta");
+   fHSigmaOld->SetYTitle("Sigma");
+
+   fHSigmaNew = new TH2D;
+   fHSigmaNew->SetNameTitle("fHSigmaNew", "Sigma after padding");
+   fHSigmaNew->SetXTitle("Theta");
+   fHSigmaNew->SetYTitle("Sigma");
 }
 
@@ -108,5 +143,11 @@
 MPadding::~MPadding()
 {
-  //nothing yet
+   delete fHSigmaPedestal;
+   delete fHPhotons;
+   delete fHNSB;
+   delete fHSigmaOld;
+   delete fHSigmaNew;
+   if (fHSigMaxAllocated && fHSigmabarMax)
+       delete fHSigmabarMax;
 }
 
@@ -119,12 +160,18 @@
 Bool_t MPadding::SetDefiningHistogram(TH1D *histo)
 {
-  fHSigmabarMax  = histo;
-
-  fFixedSigmabar = 0.0;
-  fHSigmaTheta   = NULL;
-
-  *fLog << "MPadding::SetDefiningHistogram" << endl;
-
-  return kTRUE;
+    if (fHSigmabarMax)
+    {
+        *fLog << warn << "MPadding - SigmabarMax already set.";
+        return kFALSE;
+    }
+
+    fHSigmabarMax  = histo;
+
+    fFixedSigmabar = 0;
+    fHSigmaTheta   = NULL;
+
+    *fLog << inf << "MPadding - Use Defining Histogram.";
+
+    return kTRUE;
 }
 
@@ -136,12 +183,23 @@
 Bool_t MPadding::SetSigmaThetaHist(TH2D *histo)
 {
-  fHSigmaTheta   = histo;
-
-  fFixedSigmabar = 0.0;
-  fHSigmabarMax  = NULL;
-
-  *fLog << "MPadding::SetSigmaThetaHist" << endl;
-
-  return kTRUE;
+    if (fHSigmaTheta)
+    {
+        *fLog << warn << "MPadding - SigmaTheta already set.";
+        return kFALSE;
+    }
+
+    fHSigmaTheta   = histo;
+
+    fFixedSigmabar = 0;
+    if (fHSigMaxAllocated)
+    {
+        fHSigMaxAllocated = kFALSE;
+        delete fHSigmabarMax;
+    }
+    fHSigmabarMax  = NULL;
+
+    *fLog << inf << "MPadding - Use Sigma Theta Histogram.";
+
+    return kTRUE;
 }
 
@@ -151,11 +209,16 @@
 void MPadding::SetTargetLevel(Double_t sigmabar)
 {
-  fFixedSigmabar = sigmabar;
-
-  fHSigmabarMax  = NULL;
-  fHSigmaTheta   = NULL;
-
-  *fLog << "MPadding::SetTargetLevel; use fixed sigmabar : fFixedSigmabar = " 
-        << fFixedSigmabar << endl;
+    fFixedSigmabar = sigmabar;
+
+    fHSigmaTheta   = NULL;
+    if (fHSigMaxAllocated)
+    {
+        fHSigMaxAllocated = kFALSE;
+        delete fHSigmabarMax;
+    }
+    fHSigmabarMax = NULL;
+
+    *fLog << inf << "MPadding - Use fixed sigmabar: fFixedSigmabar = ";
+    *fLog << fFixedSigmabar << endl;
 }
 
@@ -167,10 +230,8 @@
 Bool_t MPadding::PreProcess(MParList *pList)
 {
-  fRnd = new TRandom3(0);
-
   fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
   if (!fMcEvt)
     {
-       *fLog << err << dbginf << "MPadding::PreProcess : MMcEvt not found... aborting." << endl;
+       *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
        return kFALSE;
      }
@@ -179,5 +240,5 @@
    if (!fPed)
      {
-       *fLog << dbginf << "MPadding::PreProcess : MPedestalCam not found... aborting." << endl;
+       *fLog << err << dbginf << "MPedestalCam not found... aborting." << endl;
        return kFALSE;
      }
@@ -186,5 +247,5 @@
    if (!fCam)
      {
-       *fLog << dbginf << "MPadding::PreProcess : MGeomCam not found (no geometry information available)... aborting." << endl;
+       *fLog << err << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
        return kFALSE;
      }
@@ -193,5 +254,5 @@
    if (!fEvt)
      {
-       *fLog << dbginf << "MPadding::PreProcess : MCerPhotEvt not found... aborting." << endl;
+       *fLog << err << dbginf << "MCerPhotEvt not found... aborting." << endl;
        return kFALSE;
      }
@@ -200,5 +261,5 @@
    if (!fSigmabar)
      {
-       *fLog << dbginf << "MPadding::PreProcess : MSigmabar not found... aborting." << endl;
+       *fLog << err << dbginf << "MSigmabar not found... aborting." << endl;
        return kFALSE;
      }
@@ -208,5 +269,5 @@
    if (!binstheta)
      {
-       *fLog << err << dbginf << "MPadding::PreProcess : BinningTheta not found... aborting." << endl;
+       *fLog << err << dbginf << "BinningTheta not found... aborting." << endl;
        return kFALSE;      
      }
@@ -216,38 +277,10 @@
    if (!binssigma)
      {
-       *fLog << err << dbginf << "MPadding::PreProcess : BinningSigmabar not found... aborting." << endl;
+       *fLog << err << dbginf << "BinningSigmabar not found... aborting." << endl;
        return kFALSE;      
      }
 
-   //--------------------------------------------------------------------
-   // plot pedestal sigmas for testing purposes
-   fHSigmaPedestal = new TH2D("SigPed","padded vs orig. sigma", 
-                     100, 0.0, 5.0, 100, 0.0, 5.0);
-   fHSigmaPedestal->SetXTitle("orig. Pedestal sigma");
-   fHSigmaPedestal->SetYTitle("padded Pedestal sigma");
-
-   // plot no.of photons (before vs. after padding) for testing purposes
-   fHPhotons = new TH2D("Photons","Photons after vs.before padding", 
-                        100, -10.0, 90.0, 100, -10, 90);
-   fHPhotons->SetXTitle("no.of photons before padding");
-   fHPhotons->SetYTitle("no.of photons after padding");
-
-   // plot of added NSB
-   fHNSB = new TH1D("NSB","Distribution of added NSB", 100, -10.0, 10.0);
-   fHNSB->SetXTitle("no.of added NSB photons");
-   fHNSB->SetYTitle("no.of pixels");
-
-   fHSigmaOld = new TH2D();
-   fHSigmaOld->SetNameTitle("fHSigmaOld","Sigma before padding");
    MH::SetBinning(fHSigmaOld, binstheta, binssigma);
-   fHSigmaOld->SetXTitle("Theta");
-   fHSigmaOld->SetYTitle("Sigma");
-
-   fHSigmaNew = new TH2D();
-   fHSigmaNew->SetNameTitle("fHSigmaNew","Sigma after padding");
    MH::SetBinning(fHSigmaNew, binstheta, binssigma);
-   fHSigmaNew->SetXTitle("Theta");
-   fHSigmaNew->SetYTitle("Sigma");
-
 
    //************************************************************************
@@ -256,21 +289,17 @@
    // provided)
    //
-   if ( (fFixedSigmabar==0.0)   && (fHSigmabarMax==NULL) 
-        && (fHSigmaTheta==NULL) ) 
+   if (fFixedSigmabar==0 && !fHSigmabarMax && !fHSigmaTheta)
    {
-        *fLog << "MPadding::PreProcess() : fFixedSigmabar, fHSigmabarMax = " 
-          <<  fFixedSigmabar << ",  " << fHSigmabarMax << endl;
-     *fLog << "          create fSigmabarMax histogram" << endl;
-
-     fHSigmabarMax = new TH1D();
-     fHSigmabarMax->SetNameTitle("fHSigmabarMax","Sigmabarmax for this analysis");
-     TAxis &x = *fHSigmabarMax->GetXaxis();
-     fHSigmabarMax->SetBins(binstheta->GetNumBins(), 0, 1);
-     // Set the binning of the current histogram to the binning
-     // in one of the two given histograms
-     x.Set(binstheta->GetNumBins(), binstheta->GetEdges());
-     x.SetTitle("Theta");
-     TAxis &y = *fHSigmabarMax->GetYaxis();     
-     y.SetTitle("SigmabarMax");
+       *fLog << inf << "MPadding - Creating fSigmabarMax histogram: ";
+       *fLog << "fFixedSigmabar=" << fFixedSigmabar << ", ";
+       *fLog << "fHSigmabarMax = " << fHSigmabarMax << endl;
+
+       // FIXME: Not deleted
+     fHSigmabarMax = new TH1D;
+     fHSigmabarMax->SetNameTitle("fHSigmabarMax", "Sigmabarmax for this analysis");
+
+     fHSigMaxAllocated = kTRUE;
+
+     MH::SetBinning(fHSigmabarMax, binstheta);
 
      // -------------------------------------------------
@@ -279,27 +308,35 @@
      // -------------------------------------------------
      
-     FILE *f;
-     if( !(f =fopen(fDatabaseFilename, "r")) ) {
-       *fLog << err << dbginf << "Database file " << fDatabaseFilename 
-             << "was not found... (specify with MPadding::SetDatabaseFile) aborting." << endl;
-       return kFALSE;  
-     }
-     char line[80];    
-     Float_t sigmabarMin, sigmabarMax, thetaMin, thetaMax, ra, dec2;
-     Int_t type, group, mjd, nr;
+     FILE *f=fopen(fDatabaseFilename, "r");
+     if(!f) {
+         *fLog << err << dbginf << "Database file '" << fDatabaseFilename;
+         *fLog << "' was not found (specified by MPadding::SetDatabaseFile) ...aborting." << endl;
+         return kFALSE;
+     }
+
+     TAxis &axe = *fHSigmabarMax->GetXaxis();
+
+     char line[80];
      while ( fgets(line, sizeof(line), f) != NULL) {
-       if ((line[0]!='#')) {	
-	 sscanf(line,"%d %d %f %f %d %d %f %f %f %f",
-                &type, &group, &ra, &dec2, &mjd, &nr, 
-                &sigmabarMin,&sigmabarMax,&thetaMin,&thetaMax);
-	 if ((group==fGroup)||(type==1)) //selected ON group or OFF         
-	   {    
-	     // find out which bin(s) we have to look at
-	     for (Int_t i=fHSigmabarMax->GetXaxis()->FindBin(thetaMin); 
-	       i<fHSigmabarMax->GetXaxis()->FindBin(thetaMax)+1; i++) 
-	     if (sigmabarMax > fHSigmabarMax->GetBinContent(i)) 
-	       fHSigmabarMax->SetBinContent(i, sigmabarMax);	  
-	   }
-       }
+         if (line[0]=='#')
+             continue;
+
+         Float_t sigmabarMin, sigmabarMax, thetaMin, thetaMax, ra, dec2;
+         Int_t type, group, mjd, nr;
+
+         sscanf(line,"%d %d %f %f %d %d %f %f %f %f",
+                &type, &group, &ra, &dec2, &mjd, &nr,
+                &sigmabarMin, &sigmabarMax, &thetaMin, &thetaMax);
+
+         if (group!=fGroup && type!=1) //selected ON group or OFF
+             continue;
+
+         const Int_t from = axe.FindFixBin(thetaMin);
+         const Int_t to   = axe.FindFixBin(thetaMax);
+
+         // find out which bin(s) we have to look at
+         for (Int_t i=from; i<to+1; i++)
+             if (sigmabarMax > fHSigmabarMax->GetBinContent(i))
+                 fHSigmabarMax->SetBinContent(i, sigmabarMax);
      }//while
   
@@ -307,6 +344,117 @@
    //************************************************************************
 
+   if (!fHSigmabarMax && !fHSigmaTheta && fFixedSigmabar==0)
+   {
+       *fLog << err << "ERROR: Sigmabar for padding not defined... aborting." << endl;
+       return kFALSE;
+   }
+
    return kTRUE;
 }
+
+Double_t MPadding::CalcOtherSig(const Double_t mySig, const Double_t theta) const
+{
+  //
+  // Get sigmabar which we have to pad to
+  //
+  const TAxis   &axe     = *fHSigmabarMax->GetXaxis();
+  const Int_t    binnum  =  axe.FindFixBin(theta);
+  const Bool_t   inrange =  theta>=axe.GetXmin() && theta<=axe.GetXmax();
+
+  if ((fHSigmabarMax || fHSigmaTheta) && !inrange)
+  {
+      *fLog << err << dbginf;
+      *fLog << "Theta of current event is beyond the limits, Theta = ";
+      *fLog << theta << " ...skipping." <<endl;
+      return -1;
+  }
+
+
+  //
+  // get target sigma for the current Theta from the histogram fHSigmabarMax
+  //
+  if (fHSigmabarMax != NULL) 
+      return fHSigmabarMax->GetBinContent(binnum);
+
+  //
+  // for the current Theta, 
+  // generate a sigma according to the histogram fHSigmaTheta
+  //
+  if (fHSigmaTheta != NULL)
+  {
+      Double_t otherSig = -1;
+
+      TH1D* fHSigma = fHSigmaTheta->ProjectionY("", binnum, binnum, "");
+
+      if (fHSigma->GetEntries()>0)
+          otherSig = fHSigma->GetRandom();
+
+      delete fHSigma;
+
+      return otherSig;
+  }
+
+  //
+  // use a fixed target sigma
+  //
+  return fFixedSigmabar;
+}
+
+// --------------------------------------------------------------------------
+//
+// Do the padding  (mySig ==> otherSig)
+// 
+Bool_t MPadding::Padding(const Double_t quadraticDiff, const Double_t theta)
+{
+   const UInt_t npix = fEvt->GetNumPixels();
+
+   // pad only pixels   - which are used (before image cleaning)
+   //                   - and for which the no.of photons is != 0.0
+   //
+   for (UInt_t i=0; i<npix; i++) 
+   {   
+     MCerPhotPix &pix = (*fEvt)[i];
+     if ( !pix.IsPixelUsed() )
+       continue;
+/*
+     if ( pix.GetNumPhotons() == 0)
+     {
+       *fLog << "MPadding::Process(); no.of photons is 0 for used pixel" 
+             << endl;
+       continue;
+     }
+*/
+     const Double_t area = fCam->GetPixRatio(pix.GetPixId());
+
+     // add additional NSB to the number of photons
+     const Double_t NSB = sqrt(quadraticDiff*area) * gRandom->Gaus(0, 1);
+     const Double_t oldphotons = pix.GetNumPhotons();
+     const Double_t newphotons = oldphotons + NSB;
+     pix.SetNumPhotons(	newphotons );
+
+     fHNSB->Fill( NSB/sqrt(area) );
+     fHPhotons->Fill( newphotons/sqrt(area), oldphotons/sqrt(area) );
+
+     // error: add sigma of padded noise quadratically
+     const Double_t olderror = pix.GetErrorPhot();
+     const Double_t newerror = sqrt( olderror*olderror + quadraticDiff*area );
+     pix.SetErrorPhot( newerror );
+
+     MPedestalPix &ppix = (*fPed)[i];
+
+     ppix.SetMeanRms(0);
+
+     const Double_t oldsigma = ppix.GetMeanRms();
+     const Double_t newsigma = sqrt( oldsigma*oldsigma + quadraticDiff*area );
+     ppix.SetMeanRms( newsigma );
+
+     fHSigmaPedestal->Fill( oldsigma, newsigma );
+     fHSigmaOld->Fill( theta, oldsigma );
+     fHSigmaNew->Fill( theta, newsigma );
+   } //for
+
+   return kTRUE;
+}
+
 
 // --------------------------------------------------------------------------
@@ -321,249 +469,84 @@
 Bool_t MPadding::Process()
 {
-  //-------------------------------------------
-  // Calculate sigmabar of event
-  //
-  Double_t mySig = fSigmabar->Calc(*fCam, *fPed, *fEvt);
-  //fSigmabar->Print("");
-
-  //$$$$$$$$$$$$$$$$$$$$$$$$$$
-  mySig = 0.0;
-  //$$$$$$$$$$$$$$$$$$$$$$$$$$
-
-
-  // Get sigmabar which we have to pad to
-  //
-  Double_t otherSig;
-  Double_t Theta  = kRad2Deg*fMcEvt->GetTelescopeTheta();
-
-  // *fLog << "Theta = " << Theta << endl;
-
-  //-------------------------------------------
-  // get target sigma for the current Theta from the histogram fHSigmabarMax
-  //
-
-  if (fHSigmabarMax != NULL) 
-  {
-    Int_t binNumber = fHSigmabarMax->GetXaxis()->FindBin(Theta);
-    if (binNumber < 1  || binNumber > fHSigmabarMax->GetNbinsX())
-    {
-      *fLog << err << dbginf 
-            << "Theta of current event is beyond the limits, Theta = "  
-            << kRad2Deg*fMcEvt->GetTelescopeTheta()
-            << "   ...Skipping this event" <<endl;
-      return kCONTINUE;
-    }
-    else
-    {
-      otherSig = fHSigmabarMax->GetBinContent(binNumber);
-
-      //*fLog << "Theta, binNumber, otherSig = " 
-      //      << kRad2Deg*fMcEvt->GetTelescopeTheta() << ",  "
-      //      << binNumber << ",  " << otherSig << endl; 
-    }
-  } 
-
-  //-------------------------------------------
-  // for the current Theta, 
-  // generate a sigma according to the histogram fHSigmaTheta
-  //
-  else if (fHSigmaTheta != NULL) 
-  {
-    Int_t binNumber = fHSigmaTheta->GetXaxis()->FindBin(Theta);
-
-    if ( binNumber < 1  ||  binNumber > fHSigmaTheta->GetNbinsX() )
-    {
-      //      *fLog << "MPadding::Process(); binNumber out of range, binNumber = "
-      //      << binNumber << ",  Skip event " << endl;
-      return kCONTINUE;
-    }
-    else
-    {
-      TH1D* fHSigma = 
-            fHSigmaTheta->ProjectionY("", binNumber, binNumber, "");
-      if ( fHSigma->GetEntries() == 0.0 )
-      {
-        //*fLog << "MPadding::Process(); projection for Theta bin " << binNumber
-        //      << " has no entries,  Skip event" << endl;
+    const Double_t theta = kRad2Deg*fMcEvt->GetTelescopeTheta();
+
+    //
+    // Calculate sigmabar of event
+    //
+    Double_t mySig = fSigmabar->Calc(*fCam, *fPed, *fEvt);
+
+    //$$$$$$$$$$$$$$$$$$$$$$$$$$
+    mySig = 0.0;  // FIXME?
+    //$$$$$$$$$$$$$$$$$$$$$$$$$$
+
+    const Double_t otherSig = CalcOtherSig(mySig, theta);
+
+    // Skip event if target sigma is zero
+    if (otherSig<=0)
         return kCONTINUE;
-      }
-      else
-      {
-        otherSig = fHSigma->GetRandom(); 
-
-        //*fLog << "Theta, bin number = " << Theta << ",  " << binNumber 
-        //      << ",  otherSig = " << otherSig << endl;
-      }
-      delete fHSigma;
-    }
-  } 
-
-  //-------------------------------------------
-  // use a fixed target sigma
-  //
-  else if (fFixedSigmabar != 0.0) 
-  {
-    otherSig = fFixedSigmabar;
-  }
-
-  //-------------------------------------------
-  else
-  {
-    *fLog << "MPadding::Process(); sigmabar for padding not defined" << endl;
-    return kFALSE;
-  }
-
-  //-------------------------------------------
-  //
-
-  //*fLog << "MPadding::Process(); mySig, otherSig = " << mySig << ",  "
-  //      << otherSig << endl;
-
-  // Skip event if target sigma is zero
-  if (otherSig == 0.0)
-  {
-    return kCONTINUE;     
-  }
-
-  // Determine quadratic difference other-mine
-  Double_t quadraticDiff = otherSig*otherSig - mySig*mySig;
-
-  if (quadraticDiff < 0) {
-    *fLog << err << dbginf << "Event has higher Sigmabar=" << mySig
-          <<" than Sigmabarmax=" << otherSig << "; Theta =" 
-          << kRad2Deg*fMcEvt->GetTelescopeTheta()
-          << "   ...Skipping this event" <<endl;
-    return kCONTINUE; //skip
-  }
-
-  if (quadraticDiff == 0) return kTRUE; //no padding necessary.
-  
-
-  //-------------------------------------------
-  // quadratic difference is > 0, do the padding; 
-  //
-  Padding(quadraticDiff);
-
-  // Calculate Sigmabar again and crosscheck
-  mySig = fSigmabar->Calc(*fCam, *fPed, *fEvt);
-
-  //fSigmabar->Print("");
-
-  return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Do the padding  (mySig ==> otherSig)
-// 
-Bool_t MPadding::Padding(Double_t quadraticDiff)
-{
-   const UInt_t npix = fEvt->GetNumPixels();
-
-   // pad only pixels   - which are used (before image cleaning)
-   //                   - and for which the no.of photons is != 0.0
-   //
-   for (UInt_t i=0; i<npix; i++) 
-   {   
-     MCerPhotPix &pix = fEvt->operator[](i);      
-     if ( !pix.IsPixelUsed() )
-       continue;
-
-     if ( pix.GetNumPhotons() == 0.0)
-     {
-       *fLog << "MPadding::Process(); no.of photons is 0 for used pixel" 
-             << endl;
-       continue;
-     }
-
-     Int_t j = pix.GetPixId();
-     Double_t Area = fCam->GetPixRatio(j);
-
-     // add additional NSB to the number of photons
-     Double_t oldphotons = pix.GetNumPhotons();
-     Double_t NSB = sqrt(quadraticDiff*Area) * fRnd->Gaus(0.0, 1.0);
-     Double_t newphotons = oldphotons + NSB;
-     pix.SetNumPhotons(	newphotons );
-
-     fHNSB->Fill( NSB/sqrt(Area) );
-     fHPhotons->Fill( newphotons/sqrt(Area), oldphotons/sqrt(Area) );
-
-
-     // error: add sigma of padded noise quadratically
-     Double_t olderror = pix.GetErrorPhot();
-     Double_t newerror = sqrt(  olderror*olderror + quadraticDiff*Area );
-     pix.SetErrorPhot( newerror );
-
-
-     MPedestalPix &ppix = fPed->operator[](j);
-
-     //$$$$$$$$$$$$$$$$$$$$$$$$$$
-     ppix.SetMeanRms(0.0);
-     //$$$$$$$$$$$$$$$$$$$$$$$$$$
-
-     Double_t oldsigma = ppix.GetMeanRms();
-     Double_t newsigma = sqrt(  oldsigma*oldsigma + quadraticDiff*Area );
-     ppix.SetMeanRms( newsigma );
-
-     fHSigmaPedestal->Fill( oldsigma, newsigma );
-     fHSigmaOld->Fill( kRad2Deg*fMcEvt->GetTelescopeTheta(), oldsigma );
-     fHSigmaNew->Fill( kRad2Deg*fMcEvt->GetTelescopeTheta(), newsigma );
-   } //for
-
-   return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
+
+    // Determine quadratic difference other-mine
+    const Double_t quadraticDiff = otherSig*otherSig - mySig*mySig;
+
+    if (quadraticDiff < 0) {
+        *fLog << err << "ERROR - MPadding: Event has higher Sigmabar=" << mySig;
+        *fLog << " than Sigmabarmax=" << otherSig << " @ Theta =" << theta;
+        *fLog << " ...skipping." << endl;
+        return kCONTINUE; //skip
+    }
+
+    if (quadraticDiff == 0)
+        return kTRUE; //no padding necessary.
+
+    //
+    // quadratic difference is > 0, do the padding;
+    //
+    Padding(quadraticDiff, theta);
+
+    // Calculate Sigmabar again and crosscheck
+    //mySig = fSigmabar->Calc(*fCam, *fPed, *fEvt);
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Draws some histograms if IsGraphicalOutputEnabled
 //
 Bool_t MPadding::PostProcess()
 {
-    TCanvas &c = *(MH::MakeDefCanvas("Padding", "", 600, 900)); 
+    if (!IsGraphicalOutputEnabled())
+        return kTRUE;
+
+    TCanvas &c = *MH::MakeDefCanvas("Padding", "", 600, 900);
     c.Divide(2,3);
     gROOT->SetSelectedPad(NULL);
 
-
     if (fHSigmabarMax != NULL)
     {
-      c.cd(1);
-      fHSigmabarMax->DrawClone();     
-      fHSigmabarMax->SetBit(kCanDelete);     
+        c.cd(1);
+        fHSigmabarMax->DrawClone();
     }
     else if (fHSigmaTheta != NULL)
     {
-      c.cd(1);
-      fHSigmaTheta->DrawClone();     
-      fHSigmaTheta->SetBit(kCanDelete);     
+        c.cd(1);
+        fHSigmaTheta->DrawClone();
     }
 
     c.cd(3);
     fHSigmaPedestal->DrawClone();
-    fHSigmaPedestal->SetBit(kCanDelete);    
 
     c.cd(5);
     fHPhotons->DrawClone();
-    fHPhotons->SetBit(kCanDelete);    
 
     c.cd(2);
     fHNSB->DrawClone();
-    fHNSB->SetBit(kCanDelete);    
 
     c.cd(4);
     fHSigmaOld->DrawClone();     
-    fHSigmaOld->SetBit(kCanDelete);     
 
     c.cd(6);
     fHSigmaNew->DrawClone();     
-    fHSigmaNew->SetBit(kCanDelete);     
-
-
-  return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-
-
-
-
-
-
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/manalysis/MPadding.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPadding.h	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MPadding.h	(revision 1951)
@@ -6,15 +6,6 @@
 #endif
 
-#ifndef MARS_MH
-#include "MH.h"
-#endif
-
-#include "TRandom3.h"
-#include "TH1.h"
-#include "TH2.h"
-#include "TH3.h"
-#include "TProfile.h"
-
-
+class TH1D;
+class TH2D;
 class MGeomCam;
 class MCerPhotEvt;
@@ -28,34 +19,27 @@
 {
 private:
-    MGeomCam *fCam; 
-    MCerPhotEvt    *fEvt; 
-    MSigmabar      *fSigmabar;
-    MMcEvt         *fMcEvt;
-    MPedestalCam   *fPed;
+    MGeomCam     *fCam;
+    MCerPhotEvt  *fEvt;
+    MSigmabar    *fSigmabar;
+    MMcEvt       *fMcEvt;
+    MPedestalCam *fPed;
 
-    TRandom3       *fRnd;
+    Int_t     fRunType;
+    Int_t     fGroup;
 
-    Int_t          fRunType;
-    Int_t          fGroup;
+    TString   fDatabaseFilename; // data file used for generating fHSigmabarMax histogram
+    Double_t  fFixedSigmabar;    // fixed sigmabar value
 
-    TH1D           *fHSigmabarMax;   // histogram (sigmabarmax vs. Theta)
-    char           *fDatabaseFilename; // data file used for generating
-                                     //   fHSigmabarMax histogram
+    Bool_t    fHSigMaxAllocated; // flag whether MPadding allocated it
+    TH1D     *fHSigmabarMax;     // histogram (sigmabarmax vs. Theta)
+    TH2D     *fHSigmaTheta;      // 2D-histogram (sigmabar vs. Theta)
+    TH2D     *fHSigmaPedestal;   //-> for testing: plot of padded vs orig. pedestal sigmas
+    TH2D     *fHPhotons;         //-> for testing: no.of photons after versus before padding
+    TH2D     *fHSigmaOld;        //-> histogram (sigma vs. Theta) before padding
+    TH2D     *fHSigmaNew;        //-> histogram (sigma vs. Theta) after padding
+    TH1D     *fHNSB;             //-> histogram of added NSB
 
-    TH2D           *fHSigmaTheta;    // 2D-histogram (sigmabar vs. Theta)
-
-    Double_t       fFixedSigmabar;   // fixed sigmabar value
-
-    TH2D           *fHSigmaPedestal; // for testing : plot of padded vs
-                                     //               orig. pedestal sigmas
-    TH2D           *fHPhotons;       // for testing : no.of photons after
-                                     //               versus before padding
-    TH2D           *fHSigmaOld;      // histogram (sigma vs. Theta)
-                                     // before padding
-
-    TH2D           *fHSigmaNew   ;   // histogram (sigma vs. Theta)
-                                     // after padding
-    TH1D           *fHNSB;           // histogram of added NSB
-
+    Double_t CalcOtherSig(const Double_t mySig, const Double_t theta) const;
+    Bool_t   Padding(Double_t quadDiff, const Double_t theta);
 
 public:
@@ -67,6 +51,4 @@
     Bool_t PostProcess();
     
-    Bool_t Padding(Double_t quadDiff);
-
     void SetRunType(Int_t runtype) { fRunType =  runtype; }
     void SetGroup(Int_t group)     { fGroup   =  group; }
@@ -79,5 +61,5 @@
     void SetTargetLevel(Double_t sigmabar);
 
-    ClassDef(MPadding, 1)    // task for the padding
+    ClassDef(MPadding, 0)   // task for the padding
 }; 
 
Index: trunk/MagicSoft/Mars/manalysis/MParameters.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MParameters.h	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MParameters.h	(revision 1951)
@@ -31,6 +31,68 @@
     Int_t GetVal() const { return fVal; }
 
-    ClassDef(MParameterI, 1) // Container to hold a generalized parameters (double)
+    ClassDef(MParameterI, 1) // Container to hold a generalized parameters (integer)
 };
+/*
+class MParameters : public MParContainer
+{
+private:
+    TObjArray fList;
+    TObjArray fNames;
 
+public:
+    MParameters(const char *name=NULL, const char *title=NULL)
+    {
+        fName  = name  ? name  : "MParameters";
+        fTitle = title ? title : "Additional temporary parameters";
+
+        SetReadyToSave();
+    }
+
+    MParamaterI &AddInteger(const TString name, const TString title, Int_t val=0)
+    {
+        MParameterI &p = *new MParameterI(name, title);
+        p.SetValue(val);
+
+        fList.Add(&p);
+
+        TNamed &n = *new TNamed(name, title);
+        fNames.Add(&n);
+
+        return p;
+    }
+
+    MParameterD &AddDouble(const TString name, const TString title, Double_t val=0)
+    {
+        MParameterD &p = *new MParameterD(name, title);
+        p.SetValue(val);
+
+        fList.Add(&p);
+
+        TNamed &n = *new TNamed(name, title);
+        fNames.Add(&n);
+
+        return p;
+    }
+
+    const TObjArray &GetList()
+    {
+        fList.SetNames(&fNames);
+        return fList;
+    }
+
+    MParameterD *GetParameterD(const TString &name)
+    {
+        fList.SetNames(&fNames);
+        return (MParamaterD*)fList.FindObject(name);
+    }
+
+    MParameterI *GetParameterI(const TString &name)
+    {
+        fList.SetNames(&fNames);
+        return (MParameterI*)fList.FindObject(name);
+    }
+
+    ClassDef(MParameters, 1) // List to hold generalized parameters (MParameterD/I)
+    }
+    */
 #endif
Index: trunk/MagicSoft/Mars/manalysis/MPointingCorr.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPointingCorr.h	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MPointingCorr.h	(revision 1951)
@@ -18,5 +18,4 @@
 class MParameterD;
 
-
 class MPointingCorr : public MTask
 {
@@ -27,5 +26,5 @@
     MParameterD  *fHourAngle;
 
-    Float_t      fMm2Deg;
+    Float_t       fMm2Deg;
 
 public:
Index: trunk/MagicSoft/Mars/manalysis/MSigmabar.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabar.cc	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabar.cc	(revision 1951)
@@ -16,6 +16,7 @@
 !
 !
-!   Author(s): Robert Wagner   10/2002 <mailto:magicsoft@rwagner.de>
-!              Wolfgang Wittek 01/2003 <mailto:wittek@mppmu.mpg.de>
+!   Author(s): Robert Wagner, 10/2002 <mailto:magicsoft@rwagner.de>
+!   Author(s): Wolfgang Wittek, 01/2003 <mailto:wittek@mppmu.mpg.de>
+!   Author(s): Thomas Bretz, 04/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2003
@@ -40,11 +41,15 @@
 #include "MLog.h"
 #include "MLogManip.h"
+
 #include "MParList.h"
+
 #include "MGeomCam.h"
+#include "MGeomPix.h"
+
+#include "MCerPhotEvt.h"
+#include "MCerPhotPix.h"
+
 #include "MPedestalCam.h"
 #include "MPedestalPix.h"
-#include "MGeomPix.h"
-#include "MCerPhotEvt.h"
-#include "MCerPhotPix.h"
 
 ClassImp(MSigmabar);
@@ -52,11 +57,8 @@
 // --------------------------------------------------------------------------
 //
-MSigmabar::MSigmabar(const char *name, const char *title)
+MSigmabar::MSigmabar(const char *name, const char *title) : fCalcPixNum(kTRUE)
 {
     fName  = name  ? name  : "MSigmabar";
     fTitle = title ? title : "Storage container for Sigmabar";
-    
-
-    fCalcPixNum=kTRUE;
 }
 
@@ -66,4 +68,17 @@
 {
   // do nothing special.
+}
+
+void MSigmabar::Reset()
+{
+    fSigmabar      = -1;
+    fInnerPixels   = -1;
+    fOuterPixels   = -1;
+    fSigmabarInner = -1;
+    fSigmabarOuter = -1;
+
+    memset(fSigmabarSector, 0, sizeof(fSigmabarSector));
+    memset(fSigmabarInnerSector, 0, sizeof(fSigmabarInnerSector));
+    memset(fSigmabarOuterSector, 0, sizeof(fSigmabarOuterSector));
 }
 
@@ -81,110 +96,99 @@
                         const MCerPhotEvt &evt)
 {
-  fSigmabar      = 0.0;
-  fSigmabarInner = 0.0;
-  fSigmabarOuter = 0.0;
-
-
-  Float_t innerSquaredSum[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
-  Float_t outerSquaredSum[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
-  Int_t innerPixels[6]       = {0,0,0,0,0,0};
-  Int_t outerPixels[6]       = {0,0,0,0,0,0};
-
-  // sum up sigma**2 for each sector, separately for inner and outer region;
-  // all pixels are renormalized to the area of pixel 0
-  //
-  // consider all pixels with Cherenkov photon information
-  // and require "Used"
-  //
-
-  const UInt_t npix = evt.GetNumPixels();
-
-  for (UInt_t i=0; i<npix; i++)
-  {
-      MCerPhotPix &cerpix = evt.operator[](i);
-      if (!cerpix.IsPixelUsed())
-        continue;
-  
-      if ( cerpix.GetNumPhotons() == 0 )
-      {
-        *fLog << "MSigmabar::Calc(); no.of photons is 0 for used pixel" 
-              << endl;
-        continue;
-      }
-
-      Int_t j = cerpix.GetPixId();
-      Double_t area = geom.GetPixRatio(j);
-
-      const MGeomPix    &gpix = geom[j];
-      const MPedestalPix &pix =  ped[j]; 
-
-      //angle = 6.0*atan2(gpix.GetX(),gpix.GetY()) / (2.0*TMath::Pi()) - 0.5;
-      //if (angle<0.0) angle+=6.0;
-
-      Float_t angle = atan2(gpix.GetY(),gpix.GetX())*6 / (TMath::Pi()*2);
-      if (angle<0) angle+=6;
-
-      Int_t currentSector=(Int_t)angle;
-       
-      // count only those pixels which have a sigma != 0.0 
-      Float_t sigma = pix.GetMeanRms();
-
-      if ( sigma != 0.0 )
-      {  
+    Int_t innerPixels[6];
+    Int_t outerPixels[6];
+    Float_t innerSquaredSum[6];
+    Float_t outerSquaredSum[6];
+
+    memset(innerPixels, 0, sizeof(innerPixels));
+    memset(outerPixels, 0, sizeof(outerPixels));
+    memset(outerSquaredSum, 0, sizeof(outerSquaredSum));
+    memset(outerSquaredSum, 0, sizeof(outerSquaredSum));
+
+    //
+    // sum up sigma^2 for each sector, separately for inner and outer region;
+    // all pixels are renormalized to the area of pixel 0
+    //
+    // consider all pixels with Cherenkov photon information
+    // and require "Used"
+    //
+
+    const UInt_t npix = evt.GetNumPixels();
+
+    for (UInt_t i=0; i<npix; i++)
+    {
+        MCerPhotPix &cerpix = evt.operator[](i);
+        if (!cerpix.IsPixelUsed())
+            continue;
+        /*
+         if ( cerpix.GetNumPhotons() == 0 )
+         {
+         *fLog << "MSigmabar::Calc(); no.of photons is 0 for used pixel"
+         << endl;
+         continue;
+         }
+         */
+        const Int_t id = cerpix.GetPixId();
+        const Double_t area = geom.GetPixRatio(id);
+
+        const MGeomPix    &gpix = geom[id];
+        const MPedestalPix &pix =  ped[id];
+
+        Int_t sector = (Int_t)(atan2(gpix.GetY(),gpix.GetX())*6 / (TMath::Pi()*2));
+        if (sector<0)
+            sector+=6;
+
+        // count only those pixels which have a sigma != 0.0
+        const Float_t sigma = pix.GetMeanRms();
+
+        if ( sigma <= 0 )
+            continue;
+
         if (area < 1.5)
         {
-          innerPixels[currentSector]++;
-          innerSquaredSum[currentSector]+= sigma*sigma / area;
+            innerPixels[sector]++;
+            innerSquaredSum[sector]+= sigma*sigma / area;
         }
         else
         {
-          outerPixels[currentSector]++;
-          outerSquaredSum[currentSector]+= sigma*sigma / area;
+            outerPixels[sector]++;
+            outerSquaredSum[sector]+= sigma*sigma / area;
         }
-      }
-  }
- 
-  fSigmabarInner=0; fInnerPixels=0;
-  fSigmabarOuter=0; fOuterPixels=0;
-  for (UInt_t i=0; i<6; i++) {
-    fSigmabarInner += innerSquaredSum[i];
-    fInnerPixels   += innerPixels[i];
-    fSigmabarOuter += outerSquaredSum[i];
-    fOuterPixels   += outerPixels[i];
-  }
-
-
-  // this is the sqrt of the average sigma**2;
+    }
+
+    fInnerPixels   = 0;
+    fOuterPixels   = 0;
+    fSigmabarInner = 0;
+    fSigmabarOuter = 0;
+    for (UInt_t i=0; i<6; i++) {
+        fSigmabarInner += innerSquaredSum[i];
+        fInnerPixels   += innerPixels[i];
+        fSigmabarOuter += outerSquaredSum[i];
+        fOuterPixels   += outerPixels[i];
+    }
+
+    //
+    // this is the sqrt of the average sigma^2;
+    //
+    fSigmabar=fInnerPixels+fOuterPixels<=0?0:sqrt((fSigmabarInner+fSigmabarOuter)/(fInnerPixels+fOuterPixels));
+
+    if (fInnerPixels > 0) fSigmabarInner /= fInnerPixels;
+    if (fOuterPixels > 0) fSigmabarOuter /= fOuterPixels;
+
   //
-  if ( (fInnerPixels+fOuterPixels) > 0)
-    fSigmabar=sqrt(   (fSigmabarInner + fSigmabarOuter)
-                    / (fInnerPixels   + fOuterPixels) ); 
-
-  if (fInnerPixels > 0) fSigmabarInner /= fInnerPixels;
-  if (fOuterPixels > 0) fSigmabarOuter /= fOuterPixels;
- 
-  // this is the sqrt of the average sigma**2
+  // this is the sqrt of the average sigma^2
   // for the inner and outer pixels respectively
   //
   fSigmabarInner = sqrt( fSigmabarInner );
   fSigmabarOuter = sqrt( fSigmabarOuter );
-  
 
   for (UInt_t i=0; i<6; i++) {
-    fSigmabarSector[i]         = 0.0;
-    fSigmabarInnerSector[i]    = 0.0;
-    fSigmabarOuterSector[i]    = 0.0;
-
-    if ( (innerPixels[i]+outerPixels[i]) > 0)
-      fSigmabarSector[i] = sqrt(  (innerSquaredSum[i] + outerSquaredSum[i])
-                                / (innerPixels[i]     + outerPixels[i]    ) );
-    if ( innerPixels[i] > 0)
-      fSigmabarInnerSector[i] = innerSquaredSum[i] / innerPixels[i];
-    if ( outerPixels[i] > 0)
-      fSigmabarOuterSector[i] = outerSquaredSum[i] / outerPixels[i];
-
-
-    fSigmabarInnerSector[i] = sqrt( fSigmabarInnerSector[i] );
-    fSigmabarOuterSector[i] = sqrt( fSigmabarOuterSector[i] );
+      fSigmabarSector[i] = innerPixels[i]+outerPixels[i]<=0?0:sqrt((innerSquaredSum[i]+outerSquaredSum[i])/(innerPixels[i]+outerPixels[i]));
+
+      const Double_t is = innerPixels[i]<=0?0:innerSquaredSum[i]/innerPixels[i];
+      const Double_t os = outerPixels[i]<=0?0:outerSquaredSum[i]/outerPixels[i];
+
+      fSigmabarInnerSector[i] = sqrt( is );
+      fSigmabarOuterSector[i] = sqrt( os );
   }
     
@@ -196,5 +200,5 @@
 void MSigmabar::Print(Option_t *) const
 {
-  *fLog << endl;
+  *fLog << all << endl;
   *fLog << "Total number of inner pixels is " << fInnerPixels << endl;
   *fLog << "Total number of outer pixels is " << fOuterPixels << endl;
@@ -203,5 +207,6 @@
   *fLog << "Sigmabar     Overall : " << fSigmabar << "   ";
   *fLog << " Sectors: ";
-  for (Int_t i=0;i<6;i++) *fLog << fSigmabarSector[i] << ", ";
+  for (Int_t i=0;i<6;i++)
+      *fLog << fSigmabarSector[i] << ", ";
   *fLog << endl;
 
@@ -209,5 +214,6 @@
   *fLog << "Sigmabar     Inner   : " << fSigmabarInner << "   ";
   *fLog << " Sectors: ";
-  for (Int_t i=0;i<6;i++) *fLog << fSigmabarInnerSector[i] << ", ";
+  for (Int_t i=0;i<6;i++)
+      *fLog << fSigmabarInnerSector[i] << ", ";
   *fLog << endl;
 
@@ -215,11 +221,7 @@
   *fLog << "Sigmabar     Outer   : " << fSigmabarOuter << "   ";
   *fLog << " Sectors: ";
-  for (Int_t i=0;i<6;i++) *fLog << fSigmabarOuterSector[i] << ", ";
-  *fLog << endl;
-
-}
-// --------------------------------------------------------------------------
-
-
-
-
+  for (Int_t i=0;i<6;i++)
+      *fLog << fSigmabarOuterSector[i] << ", ";
+  *fLog << endl;
+
+}
Index: trunk/MagicSoft/Mars/manalysis/MSigmabar.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabar.h	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabar.h	(revision 1951)
@@ -6,17 +6,8 @@
 #endif
 
-#ifndef MARS_MParList
-#include "MParList.h"
-#endif
-
-#ifndef MARS_MGeomCam
-#include "MGeomCam.h"
-#endif
-
-#ifndef MARS_MPedestalCam
-#include "MPedestalCam.h"
-#endif
-
+class MGeomCam;
+class MParList;
 class MCerPhotEvt;
+class MPedestalCam;
 
 class MSigmabar : public MParContainer
@@ -31,6 +22,6 @@
     Float_t fSigmabarOuterSector[6];
 
-    UInt_t  fInnerPixels;       // Overall number of inner pixels
-    UInt_t  fOuterPixels;       // Overall number of outer pixels
+    Int_t  fInnerPixels;       // Overall number of inner pixels
+    Int_t  fOuterPixels;       // Overall number of outer pixels
 
     Bool_t  fCalcPixNum;
@@ -41,4 +32,6 @@
     ~MSigmabar();
     
+    void Reset();
+
     void Print(Option_t *) const;
  
Index: trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.cc	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.cc	(revision 1951)
@@ -16,5 +16,6 @@
 !
 !
-!   Author(s): Robert Wagner <rwagner@mppmu.mpg.de> 10/2002
+!   Author(s): Robert Wagner, 10/2002 <rwagner@mppmu.mpg.de>
+!   Author(s): Thomas Bretz, 4/2003 <tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2003
@@ -39,8 +40,11 @@
 
 #include "MParList.h"
+
 #include "MGeomCam.h"
 #include "MPedestalCam.h"
+
 #include "MSigmabar.h"
 #include "MSigmabarParam.h"
+
 #include "MMcEvt.hxx"
 
@@ -53,8 +57,8 @@
 MSigmabarCalc::MSigmabarCalc(const char *name, const char *title)
 {
-  fName  = name  ? name  : "MSigmabarCalc";
-  fTitle = title ? title : "Task to calculate Sigmabar";
+    fName  = name  ? name  : "MSigmabarCalc";
+    fTitle = title ? title : "Task to calculate Sigmabar";
 
-  Reset();
+    Reset();
 }
 
@@ -74,5 +78,5 @@
     if (!fCam)
     {
-        *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
+        *fLog << err << "MGeomCam not found (no geometry information available)... aborting." << endl;
         return kFALSE;
     }
@@ -81,5 +85,5 @@
     if (!fPed)
     {
-        *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
+        *fLog << err << "MPedestalCam not found... aborting." << endl;
         return kFALSE;
     }
@@ -88,5 +92,5 @@
     if (!fSig)
     {
-        *fLog << dbginf << "MSigmabar not found... aborting." << endl;
+        *fLog << err << "MSigmabar not found... aborting." << endl;
         return kFALSE;
     }
@@ -95,5 +99,5 @@
     if (!fSigParam)
     {
-        *fLog << dbginf << "MSigmabarParam not found... aborting." << endl;
+        *fLog << err << "MSigmabarParam not found... aborting." << endl;
         return kFALSE;
     }
@@ -102,13 +106,13 @@
     if (!fRun)
     {
-        *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
+        *fLog << err << "MRawRunHeader not found... aborting." << endl;
         return kFALSE;
     }
     
+    // This is needed for determining min/max Theta
     fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
-    // This is needed for determining min/max Theta
     if (!fMcEvt)
       {
-	*fLog << err << dbginf << "MHSigmabaCalc : MMcEvt not found... aborting." << endl;
+	*fLog << err << "MMcEvt not found... aborting." << endl;
 	return kFALSE;
       }
@@ -117,5 +121,5 @@
     if (!fEvt)
       {
-	*fLog << err << dbginf << "MHSigmabarCalc : MCerPhotEvt not found... aborting." << endl;
+	*fLog << err << "MCerPhotEvt not found... aborting." << endl;
 	return kFALSE;
       }
@@ -133,13 +137,15 @@
 Bool_t MSigmabarCalc::Process()
 {
-  Float_t rc = fSig->Calc(*fCam, *fPed, *fEvt);    
-  fSigmabarMax = TMath::Max((Double_t)rc, fSigmabarMax);
-  fSigmabarMin = TMath::Min((Double_t)rc, fSigmabarMin);
+    const Double_t rc = fSig->Calc(*fCam, *fPed, *fEvt);
 
-  if (fMcEvt->GetTelescopeTheta()*kRad2Deg < 120)
-    fThetaMax    = TMath::Max(fMcEvt->GetTelescopeTheta()*kRad2Deg, fThetaMax);
-  fThetaMin    = TMath::Min(fMcEvt->GetTelescopeTheta()*kRad2Deg, fThetaMin);
+    fSigmabarMax = TMath::Max(rc, fSigmabarMax);
+    fSigmabarMin = TMath::Min(rc, fSigmabarMin);
 
-  return kTRUE;
+    const Double_t theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
+
+    fThetaMax = TMath::Max(theta, fThetaMax);
+    fThetaMin = TMath::Min(theta, fThetaMin);
+
+    return kTRUE;
 }
 
@@ -151,19 +157,18 @@
 Bool_t MSigmabarCalc::ReInit(MParList *pList)
 {
-   
-  fSigParam->SetParams(1, fSigmabarMin, fSigmabarMax, fThetaMin, fThetaMax); 
-  fSigParam->SetRunNumber(fRun->GetRunNumber());
- 
-  Reset();
-  
-  return kTRUE;
+    fSigParam->SetParams(1, fSigmabarMin, fSigmabarMax, fThetaMin, fThetaMax);
+    fSigParam->SetRunNumber(fRun->GetRunNumber());
+
+    Reset();
+
+    return kTRUE;
 }
 
 void MSigmabarCalc::Reset()
 {
-  fThetaMin = 200;    //there must be a function which gives me the hightest
-  fThetaMax = 0;     // value allowed for a certain type!
-  fSigmabarMin = 200;
-  fSigmabarMax = 0;
+    fThetaMin = 200;    // there must be a function which gives me the hightest
+    fThetaMax = 0;      // value allowed for a certain type!
+    fSigmabarMin = 200;
+    fSigmabarMax = 0;
 }
 
Index: trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.h	(revision 1950)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.h	(revision 1951)
@@ -33,15 +33,17 @@
 {
 private:
-    MGeomCam      *fCam;  
-    MPedestalCam  *fPed;  
-    MRawRunHeader *fRun;
-    MSigmabar    *fSig;
+    MMcEvt         *fMcEvt;
+    MCerPhotEvt    *fEvt;
+    MGeomCam       *fCam;
+    MPedestalCam   *fPed;
+    MRawRunHeader  *fRun;
+    MSigmabar      *fSig;
+    MSigmabarParam *fSigParam;
+
     Double_t fSigmabarMin; // Parametrization
     Double_t fSigmabarMax;
     Double_t fThetaMin;
     Double_t fThetaMax;
-    MSigmabarParam *fSigParam;
-    MMcEvt *fMcEvt;
-    MCerPhotEvt *fEvt;
+
     void Reset();
 
@@ -54,5 +56,5 @@
     Bool_t Process();
 
-    ClassDef(MSigmabarCalc, 2)    // task for calculating sigmabar
+    ClassDef(MSigmabarCalc, 0) // task for calculating sigmabar
 }; 
 
Index: trunk/MagicSoft/Mars/mhist/MHSigmaPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmaPixel.cc	(revision 1950)
+++ trunk/MagicSoft/Mars/mhist/MHSigmaPixel.cc	(revision 1951)
@@ -17,5 +17,6 @@
 !
 !   Author(s): Robert Wagner 10/2002 <mailto:magicsoft@rwagner.de>
-!   Copyright: MAGIC Software Development, 2000-2002
+!
+!   Copyright: MAGIC Software Development, 2000-2003
 !
 !
@@ -79,23 +80,25 @@
   if (!fPedestalCam)
     {
-      *fLog << err << dbginf << "MHSigmaPixel: MPedestalCam not found... aborting." << endl;
+      *fLog << err << "MPedestalCam not found... aborting." << endl;
       return kFALSE;
     }
   
   MBinning* binssigma = (MBinning*)plist->FindObject("BinningSigma");
-  MBinning* binspixel = new MBinning();
-  binspixel->SetEdges(fPedestalCam->GetSize(), -0.5, -0.5+fPedestalCam->GetSize());
-  
   if (!binssigma)
     {
-      *fLog << err << dbginf << "MHSigmaPixel: BinningSigma not found... aborting." << endl;
+      *fLog << err << "BinningSigma [MBinning] not found... aborting." << endl;
       return kFALSE;      
-   }
+    }
 
-   SetBinning(&fHist, binspixel, binssigma);
+  const Int_t n = fPedestalCam->GetSize();
 
-   fHist.Sumw2(); 
+  MBinning binspixel;
+  binspixel.SetEdges(n, -0.5, -0.5+n);
 
-   return kTRUE;
+  SetBinning(&fHist, &binspixel, binssigma);
+
+  fHist.Sumw2();
+
+  return kTRUE;
 }
 
@@ -106,9 +109,9 @@
 Bool_t MHSigmaPixel::Fill(const MParContainer *par)
 {
-  MPedestalCam &ped = *(MPedestalCam*)par;
+    const MPedestalCam &ped = *(MPedestalCam*)par;
     for (Int_t i=0;i<(ped.GetSize());i++)
     {
-      const MPedestalPix pix = ped[i];       
-      fHist.Fill(i, pix.GetSigma());
+        const MPedestalPix pix = ped[i];
+        fHist.Fill(i, pix.GetSigma());
     }
     return kTRUE;
Index: trunk/MagicSoft/Mars/mhist/MHSigmaPixel.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmaPixel.h	(revision 1950)
+++ trunk/MagicSoft/Mars/mhist/MHSigmaPixel.h	(revision 1951)
@@ -19,5 +19,6 @@
 {
 private:
-    MPedestalCam *fPedestalCam;
+    MPedestalCam *fPedestalCam; //!
+
     TH2D fHist;
 
Index: trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc	(revision 1950)
+++ trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc	(revision 1951)
@@ -96,5 +96,5 @@
   if (!fMcEvt)
     {
-       *fLog << err << dbginf << "MHSigmaTheta::SetupFill : MMcEvt not found... aborting." << endl;
+       *fLog << err << "MMcEvt not found... aborting." << endl;
        return kFALSE;
      }
@@ -103,5 +103,5 @@
    if (!fPed)
      {
-       *fLog << dbginf << "MHSigmaTheta::SetupFill : MPedestalCam not found... aborting." << endl;
+       *fLog << err << "MPedestalCam not found... aborting." << endl;
        return kFALSE;
      }
@@ -110,5 +110,5 @@
    if (!fCam)
      {
-       *fLog << dbginf << "MHSigmaTheta::SetupFill : MGeomCam not found (no geometry information available)... aborting." << endl;
+       *fLog << err << "MGeomCam not found (no geometry information available)... aborting." << endl;
        return kFALSE;
      }
@@ -117,5 +117,5 @@
    if (!fEvt)
      {
-       *fLog << dbginf << "MHSigmaTheta::SetupFill : MCerPhotEvt not found... aborting." << endl;
+       *fLog << err << "MCerPhotEvt not found... aborting." << endl;
        return kFALSE;
      }
@@ -124,5 +124,5 @@
    if (!fSigmabar)
      {
-       *fLog << dbginf << "MHSigmaTheta::SetupFill : MSigmabar not found... aborting." << endl;
+       *fLog << err << "MSigmabar not found... aborting." << endl;
        return kFALSE;
      }
@@ -132,13 +132,13 @@
    if (!binstheta)
      {
-       *fLog << err << dbginf << "MHSigmaTheta::SetupFill : BinningTheta not found... aborting." << endl;
+       *fLog << err << "BinningTheta [MBinning] not found... aborting." << endl;
        return kFALSE;      
      }
 
    // Get Sigmabar binning  
-   MBinning* binssigma  = (MBinning*)plist->FindObject("BinningSigmabar");
+   MBinning* binssigma = (MBinning*)plist->FindObject("BinningSigmabar");
    if (!binssigma)
      {
-       *fLog << err << dbginf << "MHSigmaTheta::SetupFill : BinningSigmabar not found... aborting." << endl;
+       *fLog << err << "BinningSigmabar [MBinning] not found... aborting." << endl;
        return kFALSE;      
      }
@@ -148,5 +148,5 @@
    if (!binsdiff)
      {
-       *fLog << err << dbginf << "MHSigmaTheta::SetupFill : BinningDiffsigma2 not found... aborting." << endl;
+       *fLog << err << "BinningDiffsigma2 [MBinning] not found... aborting." << endl;
        return kFALSE;      
      }
@@ -154,14 +154,14 @@
 
    // Set binnings in histograms
-   SetBinning(&fSigmaTheta,    binstheta, binssigma);
+   SetBinning(&fSigmaTheta, binstheta, binssigma);
 
    // Get binning for pixel number
-   UInt_t npix = fPed->GetSize();
+   const UInt_t npix = fPed->GetSize();
+
    MBinning binspix("BinningPixel");
-   MBinning* binspixel = &binspix;
-   binspixel->SetEdges(npix, -0.5, ((float)npix)-0.5 ); 
-
-   SetBinning(&fSigmaPixTheta, binstheta, binspixel, binssigma);
-   SetBinning(&fDiffPixTheta,  binstheta, binspixel, binsdiff);
+   binspix.SetEdges(npix, -0.5, -0.5+npix );
+
+   SetBinning(&fSigmaPixTheta, binstheta, &binspix, binssigma);
+   SetBinning(&fDiffPixTheta,  binstheta, &binspix, binsdiff);
 
    return kTRUE;
@@ -176,9 +176,8 @@
   //*fLog << "entry Fill" << endl;
 
-    Double_t Theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
+    Double_t theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
     Double_t mySig = fSigmabar->Calc(*fCam, *fPed, *fEvt);
-    fSigmaTheta.Fill(Theta, mySig);
-
-    //*fLog << "Theta, mySig = " << Theta << ",  " << mySig << endl;
+
+    fSigmaTheta.Fill(theta, mySig);
 
     const UInt_t npix = fEvt->GetNumPixels();
@@ -189,29 +188,20 @@
         continue;
 
+      /*
       if (cerpix.GetNumPhotons() == 0)
         continue;
-
-      Int_t j = cerpix.GetPixId();
-      const MPedestalPix pix = fPed->operator[](j);
-
-      Double_t Sigma = pix.GetMeanRms();
-      Double_t Area  = fCam->GetPixRatio(j);
-
-      fSigmaPixTheta.Fill(Theta, (Double_t)j, Sigma);
-
-      Double_t Diff = Sigma*Sigma/Area - mySig*mySig;
-      fDiffPixTheta.Fill (Theta, (Double_t)j, Diff);
+        */
+
+      const Int_t id = cerpix.GetPixId();
+      const MPedestalPix &pix = (*fPed)[id];
+
+      const Double_t sigma = pix.GetMeanRms();
+      const Double_t area  = fCam->GetPixRatio(id);
+
+      fSigmaPixTheta.Fill(theta, (Double_t)id, sigma);
+
+      const Double_t diff = sigma*sigma/area - mySig*mySig;
+      fDiffPixTheta.Fill(theta, (Double_t)id, diff);
     }
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-//  Plot the results
-//
-Bool_t MHSigmaTheta::Finalize()
-{
-    DrawClone();
 
     return kTRUE;
@@ -329,6 +319,5 @@
 {
     if (!gPad)
-        MakeDefCanvas("SigmaTheta", "Sigmabar vs. Theta",
-                       600, 600);
+        MakeDefCanvas("SigmaTheta", "Sigmabar vs. Theta", 600, 600);
 
     TH1D *h;
@@ -358,6 +347,4 @@
     fSigmaTheta.DrawCopy(opt);
 
-
-
     gPad->Modified();
     gPad->Update();
Index: trunk/MagicSoft/Mars/mhist/MHSigmaTheta.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmaTheta.h	(revision 1950)
+++ trunk/MagicSoft/Mars/mhist/MHSigmaTheta.h	(revision 1951)
@@ -14,8 +14,4 @@
 #endif
 
-#ifndef ROOT_TProfile2D
-#include "TProfile2D.h"
-#endif
-
 class MGeomCam;
 class MCerPhotEvt;
@@ -30,15 +26,13 @@
 {
 private:
-    const MGeomCam *fCam; 
-    MPedestalCam   *fPed;
-    MCerPhotEvt    *fEvt; 
-    MSigmabar      *fSigmabar;
-    MMcEvt         *fMcEvt;
+    const MGeomCam *fCam;        //!
+    MPedestalCam   *fPed;        //!
+    MCerPhotEvt    *fEvt;        //!
+    MSigmabar      *fSigmabar;   //!
+    MMcEvt         *fMcEvt;      //!
  
-    TH2D           fSigmaTheta;   // 2D-distribution sigmabar versus Theta;
-                                  // sigmabar is the average pedestasl sigma
-                                  // in an event
-    TH3D           fSigmaPixTheta;// 3D-distr.:Theta, pixel, pedestal sigma
-    TH3D           fDiffPixTheta; // 3D-distr.:Theta, pixel, sigma^2-sigmabar^2
+    TH2D fSigmaTheta;    // 2D-distribution sigmabar versus Theta; sigmabar is the average pedestasl sigma in an event
+    TH3D fSigmaPixTheta; // 3D-distr.:Theta, pixel, pedestal sigma
+    TH3D fDiffPixTheta;  // 3D-distr.:Theta, pixel, sigma^2-sigmabar^2
 
 
@@ -46,7 +40,6 @@
     MHSigmaTheta(const char *name=NULL, const char *title=NULL);
 
-    virtual Bool_t SetupFill(const MParList *plist);
-    virtual Bool_t Fill(const MParContainer *par);
-    virtual Bool_t Finalize();
+    Bool_t SetupFill(const MParList *plist);
+    Bool_t Fill(const MParContainer *par);
 
     const TH2D *GetSigmaTheta() { return &fSigmaTheta; }
Index: trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.cc	(revision 1950)
+++ trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.cc	(revision 1951)
@@ -76,5 +76,5 @@
    if (!fMcEvt)
    {
-       *fLog << err << dbginf << "MHSigmabarTheta : MMcEvt not found... aborting." << endl;
+       *fLog << err << "MMcEvt not found... aborting." << endl;
        return kFALSE;
    }
@@ -83,13 +83,18 @@
    if (!fSigmabar)
    {
-       *fLog << err << dbginf << "MHSigmabarTheta : MSigmabar not found... aborting." << endl;
+       *fLog << err << "MSigmabar not found... aborting." << endl;
        return kFALSE;
    }
 
+   MBinning* binstheta  = (MBinning*)plist->FindObject("BinningTheta");
+   if (!binstheta)
+   {
+       *fLog << err << "BinningTheta [MBinning] not found... aborting." << endl;
+       return kFALSE;      
+   }
    MBinning* binssigmabar = (MBinning*)plist->FindObject("BinningSigmabar");
-   MBinning* binstheta  = (MBinning*)plist->FindObject("BinningTheta");
-   if (!binssigmabar || !binstheta)
+   if (!binssigmabar)
    {
-       *fLog << err << dbginf << "MHSigmabarTheta : At least one MBinning not found... aborting." << endl;
+       *fLog << err << "BinningSigmabar [MBinning] not found... aborting." << endl;
        return kFALSE;      
    }
Index: trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.h	(revision 1950)
+++ trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.h	(revision 1951)
@@ -19,6 +19,6 @@
 {
 private:
-    MMcEvt    *fMcEvt;
-    MSigmabar *fSigmabar;
+    MMcEvt    *fMcEvt;        //!
+    MSigmabar *fSigmabar;     //!
 
     TH2D fHist;
Index: trunk/MagicSoft/Mars/mhist/MHStarMap.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHStarMap.cc	(revision 1950)
+++ trunk/MagicSoft/Mars/mhist/MHStarMap.cc	(revision 1951)
@@ -156,6 +156,5 @@
     const float sind = sqrt(1.0-cosd*cosd);
 
-
-    float t = h.GetMeanY() - m*h.GetMeanX();
+    const float t = h.GetMeanY() - m*h.GetMeanX();
 
     if (!fUseMmScale)
@@ -163,15 +162,16 @@
 
     // get step size ds along the main axis of the ellipse
-    TAxis &axe = *fStarMap->GetXaxis();
+    const TAxis &axe = *fStarMap->GetXaxis();
     const int   N    = axe.GetNbins();
-    const float xmin = axe.GetBinLowEdge(1);
-    const float xmax = axe.GetBinLowEdge(N+1);
+    const float xmin = axe.GetXmin();
+    const float xmax = axe.GetXmax();
+    // FIXME: Fixed number?
     const float ds   = (xmax-xmin) / 200.0;
 
     if (m>-1 && m<1)
     {
-        float dx = ds * cosd;
-        float  x = xmin + dx/2.0;
-        int   N1 = (int) ((xmax-xmin)/dx+1.0);
+        const float dx = ds * cosd;
+        const float  x = xmin + dx/2.0;
+        const int   N1 = (int) ((xmax-xmin)/dx+1.0);
 
         for (int i=0; i<N1; i++)
@@ -184,12 +184,12 @@
     else
     {
-        TAxis &axe = *fStarMap->GetYaxis();
+        const TAxis &axe = *fStarMap->GetYaxis();
         const int   M    = axe.GetNbins();
-        const float ymin = axe.GetBinLowEdge(1);
-        const float ymax = axe.GetBinLowEdge(M+1);
-
-        float dy = ds * sind;
-        float  y = ymin + dy/2.0;
-        int   M1 = (int) ((ymax-ymin)/dy+1.0);
+        const float ymin = axe.GetXmin();
+        const float ymax = axe.GetXmax();
+
+        const float dy = ds * sind;
+        const float  y = ymin + dy/2.0;
+        const int   M1 = (int) ((ymax-ymin)/dy+1.0);
 
         for (int i=0; i<M1; i++)
