Index: trunk/MagicSoft/Mars/manalysis/MApplyPadding.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MApplyPadding.cc	(revision 1713)
+++ 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;
-}
+}
+
