Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 1681)
+++ trunk/MagicSoft/Mars/Changelog	(revision 1682)
@@ -1,3 +1,46 @@
                                                                -*-*- END -*-*-
+ 2002/12/09: Robert Wagner
+
+    * manalysis/MSigmabar.[cc,h]:
+      - added
+
+    * manalysis/MSigmabarCalc.[cc,h]:
+      - added
+
+    * manalysis/MSigmabarParam.[cc,h]:
+      - added
+      - preliminary version for CT1 test
+
+    * manalysis/MApplyPadding.[cc,h]:
+      - added
+
+    * mhist/MHSigmabarTheta.[cc,h]:
+      - added
+
+    * mhist/MHSigmabarPixel.[cc,h]:
+      - added
+      - preliminary version for CT1 test
+
+    * mtemp/MObservatoryLocation.[cc,h]:
+      - added
+
+    * mtemp/MVPObject.[cc,h]:
+      - added
+
+    * mtemp/MVPPlotter.[cc,h]:
+      - added
+
+    * mtemp/MVPTime.[cc,h]:
+      - added
+	
+    * mtemp/TempIncl.h, mtemp/TempLinkDef.h, mtemp/Makefile:
+      - added above mentioned classes
+
+    * mhist/HistLinkDef.h, mhist/Histfile:
+      - added above mentioned classes
+
+    * manalysis/AnalysisLinkDef.h, manalysis/Makefile:
+      - added above mentioned classes
+
  2002/11/25: Thomas Bretz
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 1681)
+++ trunk/MagicSoft/Mars/NEWS	(revision 1682)
@@ -8,5 +8,10 @@
      root of pixel area) according to Wolfgang's suggestion.
 
-
+   - added Sigmabar treatment (calculation and basic histogramming)
+
+   - added basic routines to apply padding
+
+   - added first implementation of MARS-based source visibility plotter
+     (needs to be linked against slalib, preliminary version)
 
  *** Version 0.8 (2002/11/18)
Index: trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1681)
+++ trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1682)
@@ -41,3 +41,8 @@
 #pragma link C++ class MPedCalcPedRun+;
 
+#pragma link C++ class MSigmabar+;
+#pragma link C++ class MSigmabarCalc+;
+#pragma link C++ class MSigmabarParam+;
+#pragma link C++ class MApplyPadding+;
+
 #endif
Index: trunk/MagicSoft/Mars/manalysis/MApplyPadding.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MApplyPadding.cc	(revision 1682)
+++ trunk/MagicSoft/Mars/manalysis/MApplyPadding.cc	(revision 1682)
@@ -0,0 +1,287 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Robert Wagner <magicsoft@rwagner.de> 10/2002
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//  MApplyPadding                                                          //
+//                                                                         //
+//  This task applies padding to a given Sigmabar target value.            //
+//  The task checks whether the data stream it is applied to has to be     //
+//  padded or not and if so, Gaussian noise with the difference in Sigma   //
+//  is produced and added to the particular event. Number of photons and   //
+//  error on this number is altered.                                       //
+//                                                                         //
+//  There are three ways to define the sigmabar value to which the events  //
+//  are padded:                                                            //
+//                                                                         //
+//  1) Set a fixed level with SetTargetLevel                               //
+//                                                                         //
+//  2) Give a TH1D* which defines the Sigmabar as function of Theta        //
+//     with SetDefiningHistogram                                           //
+//     The given histogram should have the same binning in Theta as        //
+//     is used in the analysis                                             //
+//                                                                         //
+//  3) Do nothing, then PreProcess will try to read in a (workaround!)     //
+//     propriety format ASCII database for the CT1 test.                   //
+//     the name of this file is set by SetDatabaseFile                     //
+//     Better know what you are doing or use methods 1 or 2.               //
+//                                                                         //
+//  This implementation is still PRELIMINARY and requires some workarounds //
+//  put in SPECIFICALLY FOR THE CT1 TESTS, since a database to access is   //
+//  missing. It is not the FINAL MAGIC VERSION.                            //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MApplyPadding.h"
+
+#include <stdio.h>
+
+#include "TH1.h"
+#include "TH2.h"
+#include "TRandom.h"
+
+#include "MBinning.h"
+#include "MSigmabar.h"
+#include "MMcEvt.hxx"
+#include "MLog.h"
+#include "MLogManip.h"
+#include "MParList.h"
+#include "MGeomCam.h"
+#include "MCerPhotPix.h"
+#include "MCerPhotEvt.h"
+#include "MPedestalPix.h"
+
+ClassImp(MApplyPadding);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+MApplyPadding::MApplyPadding(const char *name, const char *title) : fRunType(0), fGroup(0), fUseHistogram(kTRUE), fFixedSigmabar(0.0)
+{
+  fName  = name  ? name  : "MApplyPadding";
+  fTitle = title ? title : "Task to apply padding";
+  Print();
+}
+
+// --------------------------------------------------------------------------
+//
+// 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)
+{
+  fHSigmabarMax = histo;
+  return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+//  check if MEvtHeader exists in the Parameter list already.
+//  if not create one and add them to the list
+//
+Bool_t MApplyPadding::PreProcess(MParList *pList)
+{
+  fRnd = new TRandom3(0);
+
+  fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
+  if (!fMcEvt)
+    {
+       *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
+       return kFALSE;
+     }
+  
+   fPed = (MPedestalCam*)pList->FindObject("MPedestalCam");
+   if (!fPed)
+     {
+       *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
+       return kFALSE;
+     }
+  
+   fCam = (MGeomCam*)pList->FindObject("MGeomCam");
+   if (!fCam)
+     {
+       *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
+       return kFALSE;
+     }
+  
+   fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
+   if (!fEvt)
+     {
+       *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
+       return kFALSE;
+     }
+
+   fSigmabar = (MSigmabar*)pList->FindCreateObj("MSigmabar");
+   if (!fSigmabar)
+     {
+       *fLog << dbginf << "MSigmabar not found... aborting." << endl;
+       return kFALSE;
+     }
+   
+   // Get Theta Binning  
+   MBinning* binstheta  = (MBinning*)pList->FindObject("BinningTheta");
+   if (!binstheta)
+     {
+       *fLog << err << dbginf << "BinningTheta not found... aborting." << endl;
+       return kFALSE;      
+     }
+
+   // Create fSigmabarMax histogram
+   // (only if no fixed Sigmabar target value or a histogram have already been 
+   // provided)
+   if ((!fUseHistogram) && (fHSigmabarMax==NULL)) {
+     
+     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
+     
+     // -------------------------------------------------
+     // read in SigmabarParams
+     // workaround--proprietary file format--CT1test only BEGIN
+     // -------------------------------------------------
+     
+     FILE *f;
+     if( !(f =fopen(fDatabaseFilename, "r")) ) {
+       *fLog << err << dbginf << "Database file " << fDatabaseFilename << "was not found... (specify with MApplyPadding::SetDatabaseFile) aborting." << endl;
+       return kFALSE;  
+     }
+     char line[80];    
+     Float_t sigmabarMin, sigmabarMax, thetaMin, thetaMax, ra, dec2;
+     Int_t type, group, mjd, nr;
+     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);	  
+	   }
+       }
+     }//while
+  
+     // workaround--proprietary file format--CT1test only END
+
+     //   fHSigmabarMax->DrawClone();     
+     //   fTest = new TH2D("fTest", "Test if padding works", 201, -0.05, 2.05, 201, -0.05, 2.05);
+
+   } //!fUseHistogram
+   return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculate Sigmabar for current event
+// Then apply padding
+// 
+// 1) have current event
+// 2) get sigmabar(theta)
+// 3) pad event
+//
+Bool_t MApplyPadding::Process()
+{
+  // Calculate sigmabar of event
+  fSigmabar->Calc(*fCam, *fPed);
+  Double_t mySig = fSigmabar->GetSigmabar();
+
+  // Get sigmabar which we have to pad to
+  Double_t otherSig;
+  if (fUseHistogram) {
+    Int_t binNumber = fHSigmabarMax->GetXaxis()->FindBin(fMcEvt->GetTheta()*kRad2Deg);
+    otherSig = fHSigmabarMax->GetBinContent(binNumber);
+  } else {
+    otherSig = fFixedSigmabar;
+  }
+
+  // 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 << " ...Skipping this event" <<endl;
+    return kCONTINUE; //skip
+  }
+
+  if (quadraticDiff == 0) return kTRUE; //no padding necessary.
+  
+  // Pad if quadratic difference > 0 
+  if (quadraticDiff > 0) {    
+
+   MPedestalCam newPed;
+   newPed.InitSize(fPed->GetSize());
+
+   const UInt_t npix = fPed->GetSize(); // Total number of pixels
+   for (UInt_t i=0; i<npix; i++) {
+     MCerPhotPix pix = fEvt->operator[](i);
+     if (!pix.IsPixelUsed())
+       continue;
+     pix.SetNumPhotons(pix.GetNumPhotons() +
+		       sqrt(quadraticDiff)*
+		       fRnd->Gaus(0.0, 1.0)/
+		       fCam->GetPixRatio(pix.GetPixId())
+		       );
+     // error: add sigma of padded noise quadratically
+     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;
+    } //for
+   // Calculate Sigmabar again and crosscheck
+   fSigmabar->Calc(*fCam, newPed);
+   //mySig = fSigmabar->GetSigmabar();
+   // 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 1682)
+++ trunk/MagicSoft/Mars/manalysis/MApplyPadding.h	(revision 1682)
@@ -0,0 +1,55 @@
+#ifndef MARS_MApplyPadding
+#define MARS_MApplyPadding
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+#include "TRandom3.h"
+#include "TH1.h"
+#include "TH2.h"
+
+class MGeomCam;
+class MCerPhotEvt;
+class MPedestalCam;
+class MMcEvt;
+class MPedestalCam;
+class MSigmabar;
+class MParList;
+
+class MApplyPadding : public MTask
+{
+private:
+    const MGeomCam *fCam; 
+    MCerPhotEvt *fEvt; 
+    MSigmabar *fSigmabar;
+    TRandom3 *fRnd;
+    Int_t fRunType;
+    Int_t fGroup;
+    char *fDatabaseFilename;
+    TH1D *fHSigmabarMax;
+    MMcEvt *fMcEvt;
+    MPedestalCam *fPed;
+    TH2D *fTest;
+    Bool_t fUseHistogram;
+    Double_t fFixedSigmabar;
+
+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; }
+    void SetGroup(Int_t group)     { fGroup   =  group; }
+    void SetDatabaseFile(char *filename) { fDatabaseFilename = filename; }
+    void SetTargetLevel(Double_t sigmabar) { fFixedSigmabar = sigmabar; fUseHistogram=kFALSE; }
+    Bool_t SetDefiningHistogram(TH1D *histo);
+
+    ClassDef(MApplyPadding, 1)    // task for applying padding
+}; 
+
+#endif
+
Index: trunk/MagicSoft/Mars/manalysis/MSigmabar.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabar.cc	(revision 1682)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabar.cc	(revision 1682)
@@ -0,0 +1,150 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Robert Wagner  10/2002 <mailto:magicsoft@rwagner.de>
+!
+!   Copyright: MAGIC Software Development, 2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MSigmabar                                                               //
+//                                                                         //
+// This is the storage container to hold information about the mean sigma  //
+// (aka Sigmabar) of all pedestals                                         //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MSigmabar.h"
+
+#include <TMath.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MGeomCam.h"
+#include "MPedestalCam.h"
+#include "MGeomPix.h"
+#include "MPedestalPix.h"
+
+ClassImp(MSigmabar);
+
+MSigmabar::MSigmabar(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MSigmabar";
+    fTitle = title ? title : "Storage container for Sigmabar";
+    
+    fSigmabar = 0.0;
+    fSigmabarInner = 0.0;
+    fSigmabarOuter = 0.0;
+    fRatioA = 0.0;
+
+    fCalcPixNum=kTRUE;
+}
+
+MSigmabar::~MSigmabar()
+{
+  // do nothing special.
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Actual calculation of sigmabar. This is done for each of the six sectors
+// separately due to their possibly different HV behavior. Also inner and
+// outer pixels are treated separately
+//
+// Preliminary! Works for CT1 test, for real MAGIC crosschecks still have
+// to be done. Also implementation details will be updated, like 
+// determination of sector to which a respective pixel belongs
+//
+Bool_t MSigmabar::Calc(const MGeomCam &geom, const MPedestalCam &ped)
+{
+  const UInt_t npix = ped.GetSize();
+  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};
+  Int_t currentSector;
+  Float_t angle;
+  
+  for (UInt_t i=0; i<npix;i++)
+    {
+      const MGeomPix gpix = geom[i];
+      angle=((6*atan2(gpix.GetX(),gpix.GetY())/(2*TMath::Pi()))-0.5);
+      if (angle<0) angle+=6;
+      currentSector=(Int_t)angle;          
+      geom.GetPixRatio(i) == 1 ? innerPixels[currentSector]++ : outerPixels[currentSector]++;	
+      
+      const MPedestalPix pix = ped[i]; 
+      geom.GetPixRatio(i) == 1 ? innerSquaredSum[currentSector]+=(pix.GetSigma()*pix.GetSigma()) : outerSquaredSum[currentSector]+=((pix.GetSigma()*pix.GetSigma()) / geom.GetPixRatio(i));
+
+      // Get once and forever the ratio of areas outer/inner pixels
+      if (fRatioA && (geom.GetPixRatio(i) != 1)) fRatioA=geom.GetPixRatio(i);
+    }
+
+  // Overall Sigma
+  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];
+  }
+
+  fSigmabarInner/=fInnerPixels;
+  if (fSigmabarOuter != 0) fSigmabarOuter/=fOuterPixels; 
+  fSigmabar=sqrt(fSigmabarInner + fSigmabarOuter/( fOuterPixels==0 ? 1 : fRatioA)); 
+  fSigmabarInner=sqrt(fSigmabarInner);
+  fSigmabarOuter=sqrt(fSigmabarOuter);
+  
+  for (UInt_t i=0; i<6; i++) {
+    fSigmabarInnerSector[i]=innerSquaredSum[i]/innerPixels[i];
+    fSigmabarOuterSector[i]=outerSquaredSum[i]/( outerSquaredSum[i]==0 ? 1: outerPixels[i] );
+
+    fSigmabarSector[i]=sqrt(fSigmabarInnerSector[i] + fSigmabarOuterSector[i]*fRatioA);
+    fSigmabarInnerSector[i]=sqrt(fSigmabarInnerSector[i]);
+    fSigmabarOuterSector[i]=sqrt(fSigmabarOuterSector[i]);
+  }
+    
+  // Did all our calculations work? fOuterPixels==0 could happen, however.
+  return (fInnerPixels!=0);
+}
+
+
+void MSigmabar::Print(Option_t *) const
+{
+  *fLog << all;
+  *fLog << "Sigmabar     Overall " << fSigmabar;
+  *fLog << " Sectors: ";
+  for (Int_t i=0;i<6;i++) *fLog << fSigmabarSector[i] << " ";
+  *fLog << endl;
+  *fLog << "Sigmabar     Inner   " << fSigmabarInner;
+  *fLog << " Sectors: ";
+  for (Int_t i=0;i<6;i++) *fLog << fSigmabarInnerSector[i] << " ";
+  *fLog << endl;
+  *fLog << "Sigmabar     Outer   " << fSigmabarOuter;
+  *fLog << " Sectors: ";
+  for (Int_t i=0;i<6;i++) *fLog << fSigmabarOuterSector[i] << " ";
+  *fLog << endl;
+  *fLog << "Total number of inner pixels found is " << fInnerPixels << endl;
+  *fLog << "Total number of outer pixels found is " << fOuterPixels << endl;
+  *fLog << "Ratio of areas outer/inner pixels found is " << fRatioA << endl;
+  *fLog << endl;
+}
Index: trunk/MagicSoft/Mars/manalysis/MSigmabar.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabar.h	(revision 1682)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabar.h	(revision 1682)
@@ -0,0 +1,54 @@
+#ifndef MARS_MSigmabar
+#define MARS_MSigmabar
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#ifndef MARS_MGeomCam
+#include "MGeomCam.h"
+#endif
+
+#ifndef MARS_MPedestalCam
+#include "MPedestalCam.h"
+#endif
+
+class MSigmabar : public MParContainer
+{
+private:
+    Float_t fSigmabar; // Sigmabar (mean standard deviation) of pedestal
+    Float_t fSigmabarSector[6]; // --for the 6 sectors of the camera
+    Float_t fSigmabarInnerSector[6];
+    Float_t fSigmabarOuterSector[6];
+    Float_t fSigmabarInner; // --only for inner pixels
+    Float_t fSigmabarOuter; // --only for outer pixels  
+    UInt_t  fInnerPixels; // Overall number of inner pixels
+    UInt_t  fOuterPixels; // Overall number of outer pixels
+    Float_t fRatioA; // Ratio of areas (outer/inner pixels)
+    Bool_t fCalcPixNum;
+
+public:
+
+    MSigmabar(const char *name=NULL, const char *title=NULL);
+    ~MSigmabar();
+    
+    void Print(Option_t *) const;
+ 
+    Float_t GetSigmabar() const       { return fSigmabar;       }
+    Float_t GetSigmabarInner() const  { return fSigmabarInner;  }
+    Float_t GetSigmabarOuter() const  { return fSigmabarOuter;  }
+    Float_t GetSigmabarSector(const Int_t sector) const 
+                              { return fSigmabarSector[sector]; } 
+  
+    //   void SetSigmabar(Float_t f, Float_t i, Float_t o) 
+    //      { fSigmabar = f; fSigmabarInner = i; fSigmabarOuter = o; }
+    //    void SetSigmabarInner(Float_t f) { fSigmabarInner = f; }
+    //    void SetSigmabarOuter(Float_t f) { fSigmabarOuter = f; }   
+
+    Bool_t MSigmabar::Calc(const MGeomCam &geom, const MPedestalCam &ped);
+      
+    ClassDef(MSigmabar, 1)  // Storage Container for Sigmabar
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.cc	(revision 1682)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.cc	(revision 1682)
@@ -0,0 +1,153 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Robert Wagner <magicdev@rwagner.de> 10/2002
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//  MSigmabarCalc                                                          //
+//                                                                         //
+//  This task calculates Sigmabar using the MSigmabar container and stores //
+//  its extremal values together with the corresponding Theta values       //
+//  in MSigmabarParam. For the time being, Theta is taken from a Monte     //
+//  Carlo container. This is preliminary and to be changed ASAP.           //
+ //                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MSigmabarCalc.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MGeomCam.h"
+#include "MPedestalCam.h"
+#include "MSigmabar.h"
+#include "MSigmabarParam.h"
+#include "MMcEvt.hxx"
+
+ClassImp(MSigmabarCalc);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+MSigmabarCalc::MSigmabarCalc(const char *name, const char *title)
+{
+  fName  = name  ? name  : "MSigmabarCalc";
+  fTitle = title ? title : "Task to calculate Sigmabar";
+
+  Reset();
+}
+
+MSigmabarCalc::~MSigmabarCalc()
+{
+  // nothing special yet.
+}
+
+// --------------------------------------------------------------------------
+//
+//  check if necessary containers exists in the Parameter list already.
+//  if not create one and add them to the list
+//
+Bool_t MSigmabarCalc::PreProcess(MParList *pList)
+{
+    fCam = (MGeomCam*)pList->FindObject("MGeomCam");
+    if (!fCam)
+    {
+        *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
+        return kFALSE;
+    }
+
+    fPed = (MPedestalCam*)pList->FindObject("MPedestalCam");
+    if (!fPed)
+    {
+        *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fSig = (MSigmabar*)pList->FindCreateObj("MSigmabar");
+    if (!fSig)
+    {
+        *fLog << dbginf << "MSigmabar not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fSigParam = (MSigmabarParam*)pList->FindCreateObj("MSigmabarParam");
+    if (!fSigParam)
+    {
+        *fLog << dbginf << "MSigmabarParam not found... aborting." << endl;
+        return kFALSE;
+    }
+    
+    fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
+    // This is needed for determining min/max Theta
+    if (!fMcEvt)
+      {
+	*fLog << err << dbginf << "MHSigmabarTheta : MMcEvt not found... aborting." << endl;
+	return kFALSE;
+      }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculating a new Sigmabar is not necessary on event basis as long as
+// we deal with CT1 data. Therefore, the real calculation is done in
+// the ReInit function. Process just takes care for finding the extremal
+// values. Preliminary.
+//
+Bool_t MSigmabarCalc::Process()
+{
+  Bool_t rc = fSig->Calc(*fCam, *fPed);    
+  fSigmabarMax = TMath::Max(fSig->GetSigmabar(), fSigmabarMax);
+  fSigmabarMin = TMath::Min(fSig->GetSigmabar(), fSigmabarMin);
+
+  if (fMcEvt->GetTheta()*kRad2Deg < 90)
+    fThetaMax    = TMath::Max(fMcEvt->GetTheta()*kRad2Deg, fThetaMax);
+  fThetaMin    = TMath::Min(fMcEvt->GetTheta()*kRad2Deg, fThetaMin);
+
+  return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculates Sigmabar (for CT1 only needed at Reinit, i.e. when reading
+// a new file)
+//
+Bool_t MSigmabarCalc::ReInit(MParList *pList)
+{
+   
+  fSigParam->SetParams(1, fSigmabarMin, fSigmabarMax, fThetaMin, fThetaMax);  
+  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;
+}
+
Index: trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.h	(revision 1682)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.h	(revision 1682)
@@ -0,0 +1,54 @@
+#ifndef MARS_MSigmabarCalc
+#define MARS_MSigmabarCalc
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+#ifndef MARS_MGeomCam
+#include "MGeomCam.h"
+#endif
+
+#ifndef MARS_MMcEvt
+#include "MMcEvt.hxx"
+#endif
+
+#ifndef MARS_MPedestalCam
+#include "MPedestalCam.h"
+#endif
+
+#ifndef MARS_MSigmabar
+#include "MSigmabar.h"
+#endif
+
+#ifndef MARS_MSigmabarParam
+#include "MSigmabarParam.h"
+#endif
+
+class MSigmabarCalc : public MTask
+{
+private:
+    const MGeomCam     *fCam;  
+    const MPedestalCam *fPed;  
+    MSigmabar    *fSig;
+    Double_t fSigmabarMin; // Parametrization
+    Double_t fSigmabarMax;
+    Double_t fThetaMin;
+    Double_t fThetaMax;
+    MSigmabarParam *fSigParam;
+    MMcEvt *fMcEvt;
+    void MSigmabarCalc::Reset();
+
+public:
+    MSigmabarCalc(const char *name=NULL, const char *title=NULL);
+    ~MSigmabarCalc();
+
+    Bool_t PreProcess(MParList *pList);
+    Bool_t ReInit(MParList *pList);
+    Bool_t Process();
+
+    ClassDef(MSigmabarCalc, 2)    // task for calculating sigmabar
+}; 
+
+#endif
+
Index: trunk/MagicSoft/Mars/manalysis/MSigmabarParam.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabarParam.cc	(revision 1682)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabarParam.cc	(revision 1682)
@@ -0,0 +1,80 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Robert Wagner  10/2002 <mailto:magicsoft@rwagner.de>
+!
+!   Copyright: MAGIC Software Development, 2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MSigmabarParam                                                          //
+//                                                                         //
+// Storage Container for parameters characterizing a distribution of       //
+// events in the Sigmabar-Theta plane                                      //
+//                                                                         //
+// For CT1 tests, we just store Sigmabar_max, Sigmabar_min, Theta_max,     //
+// Theta_min. Later MJD and perhaps more than two points on the            //
+// distribution might follow.                                              //
+//                                                                         //
+//  This implementation is still PRELIMINARY and requires some workarounds //
+//  put in SPECIFICALLY FOR THE CT1 TESTS, since a database to access is   //
+//  missing. It is not the FINAL MAGIC VERSION.                            //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MSigmabarParam.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MSigmabarParam);
+
+MSigmabarParam::MSigmabarParam(const char *name, const char *title) : fSigmabarMin(0), fSigmabarMax(0), fMjdMin(0), fMjdMax(0), fThetaMin(0), fThetaMax(0), fRunNumber(0)
+{
+    fName  = name  ? name  : "MSigmabarParam";
+    fTitle = title ? title : "Storage container for characterizing a distribution of events in the Sigmabar-Theta plane";      
+}
+
+MSigmabarParam::~MSigmabarParam()
+{
+  // nothing special yet
+}
+
+void MSigmabarParam::SetRunNumber(Int_t r)
+{
+  fRunNumber = r;
+}
+
+void MSigmabarParam::SetParams(Int_t r, Double_t si, Double_t sx, Double_t ti, Double_t tx, Double_t mi, Double_t mx)
+{
+  fSigmabarMin = si;
+  fSigmabarMax = sx;
+  fThetaMin = ti;
+  fThetaMax = tx;
+  fMjdMin = mi;
+  fMjdMax = mx;
+  //fRunNumber = r;
+}
+
+void MSigmabarParam::Print()
+{
+  *fLog << endl << "Run " << fRunNumber << " | " 
+       << "Sigmabar Min, Max: " << fSigmabarMin << " " << fSigmabarMax 
+       << "| Theta Min, Max: " << fThetaMin << " " << fThetaMax << endl;
+}
Index: trunk/MagicSoft/Mars/manalysis/MSigmabarParam.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSigmabarParam.h	(revision 1682)
+++ trunk/MagicSoft/Mars/manalysis/MSigmabarParam.h	(revision 1682)
@@ -0,0 +1,42 @@
+#ifndef MARS_MSigmabarParam
+#define MARS_MSigmabarParam
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MSigmabarParam : public MParContainer
+{
+private:
+  Double_t fSigmabarMin;
+  Double_t fSigmabarMax;
+  Double_t fMjdMin;
+  Double_t fMjdMax;
+  Double_t fThetaMin;
+  Double_t fThetaMax;
+  Int_t    fRunNumber;
+
+public:
+  
+  MSigmabarParam(const char *name=NULL, const char *title=NULL);
+  ~MSigmabarParam();
+  
+  //  void Print(Option_t *) const;
+
+  void SetRunNumber(Int_t r);
+  
+  void SetParams(Int_t r, Double_t si, Double_t sx, Double_t ti, Double_t tx, Double_t mi=0, Double_t mx=0);
+
+  Double_t GetSigmabarMin() { return fSigmabarMin; }
+  Double_t GetSigmabarMax() { return fSigmabarMax; }
+  Double_t GetThetaMin() { return fThetaMin; }
+  Double_t GetThetaMax() { return fThetaMax; }
+
+  void Print();
+      
+  ClassDef(MSigmabarParam, 1)  // Storage container for characterizing a distribution of events in the Sigmabar-Theta plane
+
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1681)
+++ trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1682)
@@ -54,5 +54,9 @@
 	   MPedCalcPedRun.cc \
            MBlindPixels.cc \
-           MBlindPixelCalc.cc
+           MBlindPixelCalc.cc \
+	   MSigmabar.cc \
+	   MSigmabarParam.cc \
+	   MSigmabarCalc.cc \
+	   MApplyPadding.cc
 
 SRCS    = $(SRCFILES)
Index: trunk/MagicSoft/Mars/mhist/HistLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 1681)
+++ trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 1682)
@@ -33,4 +33,7 @@
 #pragma link C++ class MHThetabarTime+;
 #pragma link C++ class MHThetabarTheta+;
+#pragma link C++ class MHSigmabarTheta+;
+#pragma link C++ class MHSigmaPixel+;
+#pragma link C++ class MHFluxSubtraction+;
 
 #pragma link C++ class MHCompProb+;
@@ -46,5 +49,5 @@
 #pragma link C++ class MHMcEnergyImpact+;
 #pragma link C++ class MHMcCollectionArea+;
-#pragma link C++ class MHMcEnergyMigration+;
+# pragma link C++ class MHMcEnergyMigration+;
 
 #endif
Index: trunk/MagicSoft/Mars/mhist/MHSigmaPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmaPixel.cc	(revision 1682)
+++ trunk/MagicSoft/Mars/mhist/MHSigmaPixel.cc	(revision 1682)
@@ -0,0 +1,149 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Robert Wagner 10/2002 <mailto:magicsoft@rwagner.de>
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//  MHSigmaPixel                                                            //
+//                                                                          //
+//  2D-Histogram pedestal sigma vs pixel number                             //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "MHSigmaPixel.h"
+
+#include <TCanvas.h>
+
+#include <math.h>
+
+#include "MPedestalCam.h"
+#include "MPedestalPix.h"
+#include "MSigmabar.h"
+
+#include "MBinning.h"
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MHSigmaPixel);
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. It sets name and title of the histogram. 
+//
+MHSigmaPixel::MHSigmaPixel(const char *name, const char *title)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MHSigmaPixel";
+    fTitle = title ? title : "2-D histogram in sigma and pixel";
+
+    fHist.SetDirectory(NULL);
+
+    fHist.SetTitle("Sigma vs pixel #");
+    fHist.SetXTitle("pixel #");
+    fHist.SetYTitle("\\sigma");
+    fHist.SetZTitle("N");
+}
+
+// --------------------------------------------------------------------------
+//
+// Set binnings and prepare filling of the histogram. The binning for the
+// pixel axis is derived automagically from the MPedestalCam container
+// expected to be found in the MParList *plist.
+// 
+Bool_t MHSigmaPixel::SetupFill(const MParList *plist)
+{
+  fPedestalCam = (MPedestalCam*)plist->FindObject("MPedestalCam");
+  if (!fPedestalCam)
+    {
+      *fLog << err << dbginf << "MHSigmaPixel: 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;
+      return kFALSE;      
+   }
+
+   SetBinning(&fHist, binspixel, binssigma);
+
+   fHist.Sumw2(); 
+
+   return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Fill the histogram
+// 
+Bool_t MHSigmaPixel::Fill(const MParContainer *par)
+{
+  MPedestalCam &ped = *(MPedestalCam*)par;
+    for (Int_t i=0;i<(ped.GetSize());i++)
+    {
+      const MPedestalPix pix = ped[i];       
+      fHist.Fill(i, pix.GetSigma());
+    }
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw the histogram
+// 
+void MHSigmaPixel::Draw(Option_t *opt)
+{
+  //gStyle->SetOptStat(1000);
+  if (!gPad)
+    MakeDefCanvas("SigmaPixel", fTitle);
+  
+  fHist.Draw(opt);
+  
+  gPad->Modified();
+  gPad->Update();
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw copies of the histogram
+// 
+TObject *MHSigmaPixel::DrawClone(Option_t *opt) const
+{
+  //gStyle->SetOptStat(1000);
+  TCanvas &c = *MakeDefCanvas("SigmaPixel", fTitle);
+  
+  ((TH2&)fHist).DrawCopy(opt);
+  
+  c.Modified();
+  c.Update();
+  
+  return &c;
+}
+
Index: trunk/MagicSoft/Mars/mhist/MHSigmaPixel.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmaPixel.h	(revision 1682)
+++ trunk/MagicSoft/Mars/mhist/MHSigmaPixel.h	(revision 1682)
@@ -0,0 +1,46 @@
+#ifndef MARS_MHSigmaPixel
+#define MARS_MHSigmaPixel
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+#ifndef ROOT_TH2
+#include "TH2.h"
+#endif
+
+class MMcEvt;
+class MPedestalCam;
+class TH2D;
+class MParList;
+
+
+class MHSigmaPixel : public MH
+{
+private:
+    MPedestalCam *fPedestalCam;
+    TH2D fHist;
+
+public:
+    MHSigmaPixel(const char *name=NULL, const char *title=NULL);
+
+    virtual Bool_t SetupFill(const MParList *pList);
+    virtual Bool_t Fill(const MParContainer *par);
+
+    const TH2D *GetHist()       { return &fHist; }
+    const TH2D *GetHist() const { return &fHist; }
+
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
+    void Draw(Option_t *option="");
+    TObject *DrawClone(Option_t *option="") const;
+
+    ClassDef(MHSigmaPixel, 1) //2D-histogram in Sigma and Pixel number
+};
+
+#endif
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.cc	(revision 1682)
+++ trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.cc	(revision 1682)
@@ -0,0 +1,144 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Robert Wagner 10/2002 <mailto:magicsoft@rwagner.de>
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//  MHSigmabarTheta                                                         //
+//                                                                          //
+//  2D-Histogram in Sigmabar and Theta                                      //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "MHSigmabarTheta.h"
+
+#include <TCanvas.h>
+
+#include <math.h>
+
+#include "MMcEvt.hxx"
+#include "MSigmabar.h"
+
+#include "MBinning.h"
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MHSigmabarTheta);
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. It sets name and title of the histogram. 
+//
+MHSigmabarTheta::MHSigmabarTheta(const char *name, const char *title)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MHSigmabarTheta";
+    fTitle = title ? title : "3-D histogram in sigmabar and theta";
+
+    fHist.SetDirectory(NULL);
+
+    fHist.SetTitle("3D-plot of sigmabar and theta");
+    fHist.SetXTitle("\\theta [\\circ]");
+    fHist.SetYTitle("\\overline{\\sigma}");
+    fHist.SetZTitle("N");
+}
+
+// --------------------------------------------------------------------------
+//
+// Set binnings and prepare filling of the histogram
+// 
+Bool_t MHSigmabarTheta::SetupFill(const MParList *plist)
+{
+   fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
+   if (!fMcEvt)
+   {
+       *fLog << err << dbginf << "MHSigmabarTheta : MMcEvt not found... aborting." << endl;
+       return kFALSE;
+   }
+
+   fSigmabar = (MSigmabar*)plist->FindObject("MSigmabar");
+   if (!fSigmabar)
+   {
+       *fLog << err << dbginf << "MHSigmabarTheta : MSigmabar not found... aborting." << endl;
+       return kFALSE;
+   }
+
+   MBinning* binssigmabar = (MBinning*)plist->FindObject("BinningSigmabar");
+   MBinning* binstheta  = (MBinning*)plist->FindObject("BinningTheta");
+   if (!binssigmabar || !binstheta)
+   {
+       *fLog << err << dbginf << "MHSigmabarTheta : At least one MBinning not found... aborting." << endl;
+       return kFALSE;      
+   }
+
+   SetBinning(&fHist, binstheta, binssigmabar);
+
+   fHist.Sumw2(); 
+
+   return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Fill the histogram
+// 
+Bool_t MHSigmabarTheta::Fill(const MParContainer *par)
+{
+    fHist.Fill(fMcEvt->GetTheta()*kRad2Deg, fSigmabar->GetSigmabar());  
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw the histogram
+// 
+void MHSigmabarTheta::Draw(Option_t *opt)
+{
+    if (!gPad)
+        MakeDefCanvas("SigmabarTheta", fTitle);
+   
+    fHist.Draw(opt);
+    
+    gPad->Modified();
+    gPad->Update();
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw copies of the histogram
+// 
+TObject *MHSigmabarTheta::DrawClone(Option_t *opt) const
+{
+    TCanvas &c = *MakeDefCanvas("SigmabarTheta", fTitle);
+    
+    ((TH2&)fHist).DrawCopy(opt);
+
+    c.Modified();
+    c.Update();
+
+    return &c;
+}
+
Index: trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.h	(revision 1682)
+++ trunk/MagicSoft/Mars/mhist/MHSigmabarTheta.h	(revision 1682)
@@ -0,0 +1,48 @@
+#ifndef MARS_MHSigmabarTheta
+#define MARS_MHSigmabarTheta
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+#ifndef ROOT_TH2
+#include "TH2.h"
+#endif
+
+class MMcEvt;
+class MSigmabar;
+class TH2D;
+class MParList;
+
+
+class MHSigmabarTheta : public MH
+{
+private:
+    MMcEvt    *fMcEvt;
+    MSigmabar *fSigmabar;
+
+    TH2D fHist;
+
+public:
+    MHSigmabarTheta(const char *name=NULL, const char *title=NULL);
+
+    virtual Bool_t SetupFill(const MParList *pList);
+    virtual Bool_t Fill(const MParContainer *par);
+
+    const TH2D *GetHist()       { return &fHist; }
+    const TH2D *GetHist() const { return &fHist; }
+
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
+    void Draw(Option_t *option="");
+    TObject *DrawClone(Option_t *option="") const;
+
+    ClassDef(MHSigmabarTheta, 1) //3D-histogram in alpha, Energy and theta
+};
+
+#endif
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhist/Makefile	(revision 1681)
+++ trunk/MagicSoft/Mars/mhist/Makefile	(revision 1682)
@@ -63,5 +63,8 @@
            MHMcEnergyMigration.cc \
            MHGamma.cc \
-           MHFlux.cc 
+           MHFlux.cc \
+	   MHSigmaPixel.cc \
+	   MHSigmabarTheta.cc \
+	   MHFluxSubtraction.cc
  
 
