Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9311)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9312)
@@ -18,4 +18,65 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2009/02/10 Thomas Bretz
+
+   * manalysis/MMcTriggerLvl2Calc.cc:
+     - removed obsolete include of MmcRunHeader
+
+   * mbase/MSpline3.[h,cc]:
+     - improved the available constructors
+     - added some comments for future use
+     - added default constructor
+     - added GetHistogram()
+
+   * mcorsika/MCorsikaRunHeader.[h,cc]:
+     - added fImpactMax
+     - added some Getters
+
+   * melectronics/MPulseShape.[h,cc]:
+     - set class version to 1 to make it storable
+     - set a title for the splines
+     - implemented Paint function
+
+   * mhbase/MH.[h,cc]:
+     - added SetPadRange
+
+   * mhist/MHCamEvent.[h,cc]:
+     - Init the geometry in ReInit thus it can work with a geometry stored in a file
+     - Make sure that histogranms already drawn properly to a pad are found in Paint
+     - added RecursiveRemove for sanity
+
+   * mmc/MMcCorsikaRunHeader.h:
+     - added SetSpectrum
+
+   * mmc/MMcEvt.hxx:
+     - added SetEvtNumber
+     - added SetPhotElfromShower
+
+   * mmc/MMcEvtBasic.[h,cc]:
+     - added operator=
+
+   * mmc/MMcRunHeader.[hxx, cxx]:
+     - set default for the versions to UShort_t(-1)
+     - added some comments 
+     - added SetNumSimulatedShowers
+     - added SetImpactMax
+
+   * mraw/MRawRunHeader.cc:
+     - suppress some information in header if not valid
+
+   * msignal/MSignalCalc.cc:
+     - if (!fPedestal) we should return kTRUE not kFALSE
+
+   * msimreflector/MMirror.[h,cc], msimreflector/MMirrorDisk.[h,cc],
+     msimreflector/MMirrorHex.[h,cc], msimreflector/MMirrorSquare.[h,cc],
+     msimreflector/MReflector.[h,cc],
+     - added Print
+     - some cosmetics in header
+     - set class version to 1 to make it storable
+
+   * mtools/MagicJam.cc:
+     - updated
+
+
 
  2009/02/10 Daniela Dorner
Index: trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/manalysis/MMcTriggerLvl2Calc.cc	(revision 9312)
@@ -45,5 +45,4 @@
 #include "MMcTrig.hxx"
 #include "MRawRunHeader.h"
-#include "MMcRunHeader.hxx"
 
 #include "MGeomCam.h"
Index: trunk/MagicSoft/Mars/mbase/MSpline3.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MSpline3.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/mbase/MSpline3.cc	(revision 9312)
@@ -38,4 +38,6 @@
 #include <TF1.h>
 
+#include "MArrayD.h"
+
 ClassImp(MSpline3);
 
@@ -48,4 +50,9 @@
 MSpline3::MSpline3(const TF1 &f, const char *opt, Double_t valbeg, Double_t valend)
     : TSpline3("MSpline3", f.GetXmin(), f.GetXmax(), &f, f.GetNpx(), opt, valbeg, valend)
+{
+}
+
+MSpline3::MSpline3(const TF1 &f, Double_t freq, const char *opt,Double_t valbeg, Double_t valend)
+    : TSpline3("MSpline3", f.GetXmin()*freq, f.GetXmax()*freq, ConvertFunc(f, freq).GetArray(), f.GetNpx(), opt, valbeg, valend)
 {
 }
@@ -105,5 +112,5 @@
 // a discrete binning is done similar to the constructor of TSpline
 //
-TGraph *MSpline3::ConvertFunc(const TF1 &f, Float_t freq) const
+MArrayD &MSpline3::ConvertFunc(const TF1 &f, Float_t freq) const
 {
     const UInt_t npx = f.GetNpx();
@@ -111,5 +118,5 @@
     // WARNING: This is a stupid workaround because the TSpline3-
     // constructor takes a pointer as input! It is not thread-safe!
-    static TGraph g;
+    static MArrayD g;
     g.Set(npx);
 
@@ -119,7 +126,59 @@
     {
         const Double_t x = f.GetXmin() + i*step;
-        g.SetPoint(i, x*freq, f.Eval(x));
+        g[i] = f.Eval(x);
     }
 
-    return &g;
+    return g;
 }
+
+// FIXME: As soon as TSpline3 allows access to fPoly we can implement
+//        a much faster evaluation of the spline, especially in
+//        special conditions like in MAnalogSignal::AddPulse
+//        This will be the case for root > 5.22/00
+
+/*
+Double_t MSpline3::EvalFast(Double_t x) const
+{
+    // Eval this spline at x
+    const Int_t klow=FindFast(x);
+    return fPoly[klow].Eval(x);
+}
+
+Int_t MSpline3::FindFast(Double_t x) const
+{
+    //
+    // If out of boundaries, extrapolate
+    // It may be badly wrong
+
+    // if (x<=fXmin)
+    //     return 0;
+    //
+    // if (x>=fXmax)
+    //     return fNp-1;
+
+    //
+    // Equidistant knots, use histogramming
+    if (fKstep)
+        return TMath::Min(Int_t((x-fXmin)/fDelta),fNp-1);
+
+    //
+    // Non equidistant knots, binary search
+    Int_t klow = 0;
+    Int_t khig = fNp-1;
+
+    Int_t khalf;
+    while (khig-klow>1)
+        if(x>fPoly[khalf=(klow+khig)/2].X())
+            klow=khalf;
+        else
+            khig=khalf;
+
+    // This could be removed, sanity check
+    //if(!(fPoly[klow].X()<=x && x<=fPoly[klow+1].X()))
+    //    Error("Eval",
+    //          "Binary search failed x(%d) = %f < %f < x(%d) = %f\n",
+    //          klow,fPoly[klow].X(),x,fPoly[klow+1].X());
+
+    return klow;
+}
+*/
Index: trunk/MagicSoft/Mars/mbase/MSpline3.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MSpline3.h	(revision 9311)
+++ trunk/MagicSoft/Mars/mbase/MSpline3.h	(revision 9312)
@@ -6,49 +6,46 @@
 #endif
 
+class MArrayD;
+
 class MSpline3 : public TSpline3
 {
 private:
-    TGraph *ConvertSpline(const TSpline &s, Float_t freq) const;
-    TGraph *ConvertGraph(const TGraph &s, Float_t freq) const;
-    TGraph *ConvertFunc(const TF1 &f, Float_t freq) const;
+    TGraph  *ConvertSpline(const TSpline &s, Float_t freq) const;
+    TGraph  *ConvertGraph(const TGraph &s, Float_t freq) const;
+    MArrayD &ConvertFunc(const TF1 &f, Float_t freq) const;
 
 public:
-   MSpline3(const TGraph &g,
-            const char *opt=0, Double_t valbeg=0, Double_t valend=0)
-        : TSpline3("MSpline3", &g, opt, valbeg, valend)
-   {
-   }
+    MSpline3() { }
 
-   MSpline3(const TGraph &g, Double_t freq,
-            const char *opt=0, Double_t valbeg=0, Double_t valend=0)
-        : TSpline3("MSpline3", ConvertGraph(g, freq), opt, valbeg, valend)
-   {
-   }
+    // None equidistant binning (evaluation a bit slower in case of many bins)
+    MSpline3(const TGraph &g,
+             const char *opt=0, Double_t valbeg=0, Double_t valend=0)
+       : TSpline3("MSpline3", &g, opt, valbeg, valend)
+    {
+    }
 
-   MSpline3(const TSpline &s, Double_t freq,
-            const char *opt=0, Double_t valbeg=0, Double_t valend=0)
-        : TSpline3("MSpline3", ConvertSpline(s, freq), opt, valbeg, valend)
-   {
-   }
-        /*
-   MSpline3(Double_t xmin, Double_t xmax,
-            const TF1 *func, Int_t n, const char *opt=0,
-            Double_t valbeg=0, Double_t valend=0)
-        : TSpline3("MSpline3", xmin, xmax, func, n, opt, valbeg, valend)
-   {
-   }*/
-   MSpline3(const TF1 &f, const char *opt=0,Double_t valbeg=0, Double_t valend=0);
+    MSpline3(const TGraph &g, Double_t freq,
+             const char *opt=0, Double_t valbeg=0, Double_t valend=0)
+       : TSpline3("MSpline3", ConvertGraph(g, freq), opt, valbeg, valend)
+    {
+    }
 
-   MSpline3(const TF1 &f, Double_t freq,
-            const char *opt=0,Double_t valbeg=0, Double_t valend=0)
-        : TSpline3("MSpline3", ConvertFunc(f, freq), opt, valbeg, valend)
-   {
-   }
+    MSpline3(const TSpline &s, Double_t freq,
+             const char *opt=0, Double_t valbeg=0, Double_t valend=0)
+       : TSpline3("MSpline3", ConvertSpline(s, freq), opt, valbeg, valend)
+    {
+    }
 
-   MSpline3(const Double_t x[], const Double_t y[], Int_t n, const char *opt=0,
-            Double_t valbeg=0, Double_t valend=0)
-        : TSpline3("MSpline3", const_cast<Double_t*>(x), const_cast<Double_t*>(y), n, opt, valbeg, valend)
-   {
-   }
+    MSpline3(const Double_t x[], const Double_t y[], Int_t n, const char *opt=0,
+             Double_t valbeg=0, Double_t valend=0)
+       : TSpline3("MSpline3", const_cast<Double_t*>(x), const_cast<Double_t*>(y), n, opt, valbeg, valend)
+    {
+    }
+
+    // Equidistant binning (evaluation a bit faster in case of many bins)
+
+    // FIXME: In principle TF1 can be evaluated histogram like which should be faster
+    MSpline3(const TF1 &f, const char *opt=0,Double_t valbeg=0, Double_t valend=0);
+    MSpline3(const TF1 &f, Double_t freq, const char *opt=0,Double_t valbeg=0, Double_t valend=0);
 
    Double_t GetXmin() const { return fXmin; }     // Minimum value of abscissa
@@ -57,4 +54,6 @@
    Int_t GetNp() const { return fNp; }
 
+   TH1 *GetHistogram() const { return fHistogram; }
+
    ClassDef(MSpline3, 1) // An extension of the TSpline3
 };
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9312)
@@ -33,4 +33,5 @@
 // ----------------
 //  + UInt_t fParticleID
+//  + Float_t fImpactMax
 //
 ////////////////////////////////////////////////////////////////////////////
@@ -148,5 +149,5 @@
     fParticleID = TMath::Nint(g[1]);
 
-    //fImpactMax = g[86];
+    fImpactMax = g[86];
 
     fZdMin = g[79];                // lower edge of theta in °
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9311)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9312)
@@ -16,26 +16,26 @@
 
 private:
-    UInt_t    fRunNumber;         // Run number
-    UInt_t    fParticleID;        // Particle ID (see MMcEvtBasic or CORSIKA manual)
-    UInt_t    fNumEvents;         // Number of events
-    MTime     fRunStart;          // Date of begin (yymmdd)
-    Float_t   fProgramVersion;    // Version of program
+    UInt_t   fRunNumber;              // Run number
+    UInt_t   fParticleID;             // Particle ID (see MMcEvtBasic or CORSIKA manual)
+    UInt_t   fNumEvents;              // Number of events
+    MTime    fRunStart;               // Date of begin (yymmdd)
+    Float_t  fProgramVersion;         // Version of program
 
-    Byte_t    fNumObsLevel;       // Number of observation levels
-    Float_t   fObsLevel[10];      // Observation levels [cm]
+    Byte_t   fNumObsLevel;            // Number of observation levels
+    Float_t  fObsLevel[10];           // Observation levels [cm]
 
-    Float_t   fSlopeSpectrum;     // Slope of energy spectrum
-    Float_t   fEnergyMin;         // Lower limit of energy range
-    Float_t   fEnergyMax;         // Upper limit of energy range
+    Float_t  fImpactMax;              // [cm] Maximum simulated impact
 
-    Float_t  fZdMin;                     // [rad] Zenith distance
-    Float_t  fZdMax;                     // [rad] Zenith distance
-    Float_t  fAzMin;                     // [rad] Azimuth (north=0; west=90)
-    Float_t  fAzMax;                     // [rad] Azimuth (north=0; west=90)
+    Float_t  fSlopeSpectrum;          // Slope of energy spectrum
+    Float_t  fEnergyMin;              // Lower limit of energy range
+    Float_t  fEnergyMax;              // Upper limit of energy range
 
-    Float_t fWavelengthMin;      // [nm] Wavelength bandwidth lo edge
-    Float_t fWavelengthMax;      // [nm] Wavelength bandwidth up edge
+    Float_t  fZdMin;                  // [rad] Zenith distance
+    Float_t  fZdMax;                  // [rad] Zenith distance
+    Float_t  fAzMin;                  // [rad] Azimuth (north=0; west=90)
+    Float_t  fAzMax;                  // [rad] Azimuth (north=0; west=90)
 
-    //Float_t  fImpactMax;              // [cm] Maximum simulated impact
+    Float_t fWavelengthMin;           // [nm] Wavelength bandwidth lo edge
+    Float_t fWavelengthMax;           // [nm] Wavelength bandwidth up edge
 
     Float_t fViewConeInnerAngle;      // [deg]
@@ -48,4 +48,6 @@
     Bool_t HasViewCone() const { return fViewConeOuterAngle>0; }
 
+    UInt_t GetParticleID() const { return fParticleID; }
+
     Float_t GetZdMin() const { return fZdMin; }
     Float_t GetZdMax() const { return fZdMax; }
@@ -57,7 +59,9 @@
     Float_t GetWavelengthMax() const { return fWavelengthMax; }
 
-    UInt_t GetParticleID() const { return fParticleID; }
+    Float_t GetSlopeSpectrum() const { return fSlopeSpectrum; }
+    Float_t GetEnergyMin() const { return fEnergyMin; }
+    Float_t GetEnergyMax() const { return fEnergyMax; }
 
-    //Float_t GetImpactMax() const { return fImpactMax; }
+    Float_t GetImpactMax() const { return fImpactMax; }
 
     Float_t GetViewConeOuterAngle() const { return fViewConeOuterAngle; }
Index: trunk/MagicSoft/Mars/melectronics/MPulseShape.cc
===================================================================
--- trunk/MagicSoft/Mars/melectronics/MPulseShape.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/melectronics/MPulseShape.cc	(revision 9312)
@@ -127,4 +127,5 @@
     Clear();
     fSpline = new MSpline3(g);//, fRunHeader->GetFreqSampling()/1000.);
+    fSpline->SetTitle("MPulseShape");
 
     // FIXME: Make a boundary condition e1b1,0,0 (First der, at Xmin and Xmax==0)
@@ -146,4 +147,5 @@
     Clear();
     fSpline = new MSpline3(f);//, fRunHeader->GetFreqSampling()/1000.);
+    fSpline->SetTitle("MPulseShape");
 
     // FIXME: Make a boundary condition e1b1,0,0 (First der, at Xmin and Xmax==0)
@@ -200,2 +202,19 @@
     return rc;
 }
+
+void MPulseShape::Paint(Option_t *)
+{
+    fSpline->SetMarkerStyle(kFullDotMedium);
+
+    if (!fSpline->GetHistogram())
+        fSpline->Paint();
+
+    TH1 *h = fSpline->GetHistogram();
+    if (!h)
+        return;
+
+    h->SetXTitle("t [ns]");
+    h->SetYTitle("a.u.");
+
+    fSpline->Paint("PC");
+}
Index: trunk/MagicSoft/Mars/melectronics/MPulseShape.h
===================================================================
--- trunk/MagicSoft/Mars/melectronics/MPulseShape.h	(revision 9311)
+++ trunk/MagicSoft/Mars/melectronics/MPulseShape.h	(revision 9312)
@@ -36,4 +36,5 @@
 
     void Clear(Option_t *o="");
+    void Paint(Option_t *o="");
 
     MSpline3 *GetSpline() const { return fSpline; }
@@ -43,5 +44,5 @@
     Float_t GetXmax() const;
 
-    ClassDef(MPulseShape, 0) // Parameter container to hold the setup for a pulse shape
+    ClassDef(MPulseShape, 1) // Parameter container to hold the setup for a pulse shape
 };
 
Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9312)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.43 2009-02-07 20:40:12 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.44 2009-02-10 20:00:09 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -1813,2 +1813,58 @@
     return "MH::GetObjectInfo: unknown class.";
 }
+
+// --------------------------------------------------------------------------
+//
+// Set the pad-range such that at the smallest width it is still
+// two times max and that the displayed "pixels" (i.e. its coordinate
+// system) have the width to height ratio of aspect.
+//
+void MH::SetPadRange(Float_t max, Float_t aspect)
+{
+    if (!gPad)
+        return;
+
+    const Float_t w = gPad->GetWw();
+    const Float_t h = gPad->GetWh();
+
+    if (w>aspect*h)
+    {
+        const Double_t dx = ((w/h-aspect)/2+1)*max;
+        gPad->Range(-dx, -max, dx, max);
+    }
+    else
+    {
+        const Double_t dy = ((h/w-1./aspect)/2+1)*max;
+        gPad->Range(-max, -dy, max, dy);
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the range of a pad in a way that the coordinates fit into the pad
+// without abberation.
+//
+void MH::SetPadRange(Float_t x0, Float_t y0, Float_t x1, Float_t y1)
+{
+    if (!gPad)
+        return;
+
+    const Float_t w = x1-x0;                              // Width  in user coordinates
+    const Float_t h = y1-y0;                              // Hieght in user coordinates
+
+    const Float_t ww = gPad->GetWw()*gPad->GetAbsWNDC();  // Width  of pad in pixels
+    const Float_t hh = gPad->GetWh()*gPad->GetAbsHNDC();  // Height of pad in pixels
+
+    if (ww/hh > w/h)
+    {
+        const Double_t dx = (ww/hh-w/h)/2*h;
+
+        gPad->Range(x0-dx, y0, x1+dx, y1);
+    }
+    else
+    {
+        const Double_t dy = (hh/ww-h/w)/2*w;
+
+        gPad->Range(x0, y0-dy, x1, y1+dy);
+    }
+}
Index: trunk/MagicSoft/Mars/mhbase/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.h	(revision 9311)
+++ trunk/MagicSoft/Mars/mhbase/MH.h	(revision 9312)
@@ -130,4 +130,6 @@
 
     static void SetPalette(TString paletteName="pretty", Int_t ncol=50);
+    static void SetPadRange(Float_t max, Float_t aspect=1);
+    static void SetPadRange(Float_t x0, Float_t y0, Float_t x1, Float_t y1);
 
     static char *GetObjectInfoH(Int_t px, Int_t py, const TH1 &h);
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 9312)
@@ -91,5 +91,5 @@
 //
 MHCamEvent::MHCamEvent(const char *name, const char *title)
-: fSum(NULL), fEvt(NULL), fType(0), fErrorSpread(kTRUE), fErrorRelative(kFALSE),
+: fSum(NULL), fErr(NULL), fEvt(NULL), fType(0), fErrorSpread(kTRUE), fErrorRelative(kFALSE),
 fThreshold(0), fUseThreshold(0)
 {
@@ -104,5 +104,5 @@
 //
 MHCamEvent::MHCamEvent(Int_t type, const char *name, const char *title)
-: fSum(NULL), fEvt(NULL), fType(type), fErrorSpread(kTRUE), fErrorRelative(kFALSE),
+: fSum(NULL), fErr(NULL), fEvt(NULL), fType(type), fErrorSpread(kTRUE), fErrorRelative(kFALSE),
 fThreshold(0), fUseThreshold(0)
 {
@@ -120,4 +120,28 @@
     if (fSum)
         delete fSum;
+}
+
+Bool_t MHCamEvent::InitGeom(const MParList &plist)
+{
+    MGeomCam *cam = (MGeomCam*)plist.FindObject(fNameGeom, "MGeomCam");
+    if (!cam)
+    {
+        *fLog << err << fNameGeom << " [MGeomCam] not found... abort." << endl;
+        return kFALSE;
+    }
+
+    // combine name
+    const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
+
+    fSum->SetGeometry(*cam, name+";avg");
+    if (fTitle!=gsDefTitle)
+        fSum->SetTitle(fTitle);
+    if (!fTitle.Contains(";"))
+        fSum->SetYTitle("a.u.");
+
+    if (fErr)
+        fErr->SetGeometry(*fSum->GetGeometry(), fErr->GetName(), fErr->GetTitle());
+
+    return kTRUE;
 }
 
@@ -142,21 +166,11 @@
     }
 
-    MGeomCam *cam = (MGeomCam*)plist->FindObject(fNameGeom, "MGeomCam");
-    if (!cam)
-    {
-        *fLog << err << fNameGeom << " [MGeomCam] not found... abort." << endl;
+    fSum->Reset();
+
+    fNumReInit = 0;
+
+    if (!InitGeom(*plist))
         return kFALSE;
-    }
-
-    // combine name
-    const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
-
-    fSum->Reset();
-    fSum->SetGeometry(*cam, name+";avg");
-
-    if (fTitle!=gsDefTitle)
-        fSum->SetTitle(fTitle);
-    if (!fTitle.Contains(";"))
-        fSum->SetYTitle("a.u.");
+
     if (fUseThreshold!=kCollectMin && fUseThreshold!=kCollectMax)
         fSum->SetBit(MHCamera::kProfile);
@@ -169,4 +183,16 @@
 // --------------------------------------------------------------------------
 //
+// The geometry read from the RunHeaders might have changed. This does not
+// effect anything in PreProcess. So we set a new geometry. We don't move
+// this away from PreProcess to support also loops without calling ReInit.
+//
+Bool_t MHCamEvent::ReInit(MParList *plist)
+{
+    return fNumReInit++==0 ? InitGeom(*plist) : kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
 // Fill the histograms with data from a MCamEvent-Container.
 //
@@ -250,4 +276,18 @@
 }
 
+TString MHCamEvent::Format(const char *ext) const
+{
+    TString n = fSum->GetName();
+
+    const Ssiz_t pos = n.Last(';');
+    if (pos<0)
+        return "";
+
+    n  = n(0, pos);
+    n += ";";
+    n += ext;
+    return n;
+}
+
 void MHCamEvent::Paint(Option_t *)
 {
@@ -255,7 +295,7 @@
 
     pad->cd(2);
-    if (gPad->FindObject(MString::Format("%s;proj", fName.Data())))
-    {
-        TH1 *h=fSum->Projection(MString::Format("%s;proj", fName.Data()));
+    if (gPad->FindObject(Format("proj")))
+    {
+        TH1 *h=fSum->Projection(Format("proj"));
         if (h->GetMaximum()>0)
             gPad->SetLogy();
@@ -263,14 +303,14 @@
 
     pad->cd(5);
-    if (gPad->FindObject(MString::Format("%s;rad", fName.Data())))
-        fSum->RadialProfile(MString::Format("%s;rad", fName.Data()));
+    if (gPad->FindObject(Format("rad")))
+        fSum->RadialProfile(Format("rad"));
 
     pad->cd(6);
-    if (gPad->FindObject(MString::Format("%s;az", fName.Data())))
-        fSum->AzimuthProfile(MString::Format("%s;az", fName.Data()));
+    if (gPad->FindObject(Format("az")))
+        fSum->AzimuthProfile(Format("az"));
 
     pad->cd(4);
     gPad->cd(1);
-    MHCamera *cam = (MHCamera*)gPad->FindObject(MString::Format("%s;err", fName.Data()));
+    MHCamera *cam = (MHCamera*)gPad->FindObject(Format("err"));
     if (cam)
         cam->SetCamContent(*fSum, fErrorRelative ? 1 : 2);
@@ -300,5 +340,5 @@
     p->Draw();
     p->cd();
-    TH1 *h = fSum->Projection(MString::Format("%s;proj", fName.Data()), 50);
+    TH1 *h = fSum->Projection(Format("proj"), 50);
     h->SetTitle("Projection");
     h->SetBit(kCanDelete);
@@ -328,11 +368,12 @@
         e += "/v_{i}";
 
-    MHCamera *cam = new MHCamera(*fSum->GetGeometry());
-    cam->SetName(MString::Format("%s;err", fName.Data()));
-    cam->SetTitle(e);
-    cam->SetYTitle(fSum->GetYaxis()->GetTitle());
-    cam->SetCamContent(*fSum, fErrorRelative ? 1 : 2);
-    cam->SetBit(kCanDelete);
-    cam->Draw();
+    fErr = new MHCamera(*fSum->GetGeometry());
+    fErr->SetName(Format("err"));
+    fErr->SetTitle(e);
+    fErr->SetYTitle(fSum->GetYaxis()->GetTitle());
+    fErr->SetCamContent(*fSum, fErrorRelative ? 1 : 2);
+    fErr->SetBit(kMustCleanup);
+    fErr->SetBit(kCanDelete);
+    fErr->Draw();
 
     pad->cd();
@@ -343,5 +384,5 @@
     p->Draw();
     p->cd();
-    h = (TH1*)fSum->RadialProfile(MString::Format("%s;rad", fName.Data()), 20);
+    h = (TH1*)fSum->RadialProfile(Format("rad"), 20);
     h->SetTitle("Radial Profile");
     h->SetBit(kCanDelete|TH1::kNoStats);
@@ -355,5 +396,5 @@
     p->Draw();
     p->cd();
-    h = (TH1*)fSum->AzimuthProfile(MString::Format("%s;az", fName.Data()), 30);
+    h = (TH1*)fSum->AzimuthProfile(Format("az"), 30);
     h->SetTitle("Azimuth Profile");
     h->SetBit(kCanDelete|TH1::kNoStats);
@@ -361,2 +402,8 @@
 }
 
+
+void MHCamEvent::RecursiveRemove(TObject *obj)
+{
+    if (obj==fErr)
+        fErr = 0;
+}
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 9311)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 9312)
@@ -17,4 +17,5 @@
 protected:
     MHCamera  *fSum;       // storing the sum
+    MHCamera  *fErr;       //! storing the err
     MCamEvent *fEvt;       //! the current event
 
@@ -29,7 +30,13 @@
     Char_t fUseThreshold;  // Use a threshold? Which direction has it?
 
-    void Init(const char *name, const char *title);
+    Int_t fNumReInit;      //!
+
+    TString Format(const char *ext) const;
+
+    void   Init(const char *name, const char *title);
+    Bool_t InitGeom(const MParList &plist);
 
     Bool_t SetupFill(const MParList *pList);
+    Bool_t ReInit(MParList *plist);
     Int_t  Fill(const MParContainer *par, const Stat_t w=1);
 
@@ -62,4 +69,6 @@
     void SetErrorRelative(Bool_t b=kTRUE) { fErrorRelative = b; }
 
+    void RecursiveRemove(TObject *obj);
+
     ClassDef(MHCamEvent, 2) // Histogram to sum camera events
 };
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 9312)
@@ -964,5 +964,9 @@
     if (fFormatVersion>6)
         *fLog << "Sampling:     " << fSamplingFrequency << "MHz with " << (int)fFadcResolution << " significant bits" << endl;
-    *fLog << "Samples:      " << fNumSamplesHiGain << "/" << fNumSamplesLoGain << " (hi/lo) * " << fNumBytesPerSample << "B/sample = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate * fNumBytesPerSample/1000 << "kB/Evt" << endl;
+    *fLog << "Samples:      " << fNumSamplesHiGain << "/" << fNumSamplesLoGain << " (hi/lo) * " << fNumBytesPerSample << "B/sample = ";
+    if (fNumCrates>0)
+        *fLog << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate * fNumBytesPerSample/1000 << "kB/Evt" << endl;
+    else
+        *fLog << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumBytesPerSample << "B/pix" << endl;
     *fLog << "Evt Counter:  " << fNumEvents;
     if (fFormatVersion>8)
Index: trunk/MagicSoft/Mars/msignal/MSignalCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MSignalCalc.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/msignal/MSignalCalc.cc	(revision 9312)
@@ -128,5 +128,5 @@
 {
     if (!fPedestals)
-        return kFALSE;
+        return kTRUE;
 
     const Int_t npix = fRawEvt->GetNumPixels();
Index: trunk/MagicSoft/Mars/msimreflector/MMirror.cc
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MMirror.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MMirror.cc	(revision 9312)
@@ -78,4 +78,6 @@
 #include <TRandom.h>
 
+#include "MLog.h"
+
 #include "MQuaternion.h"
 
@@ -133,2 +135,13 @@
     return dn;  // Return the vector to be added to the normal vector
 }
+
+void MMirror::Print(Option_t *o) const
+{
+    gLog << fPos.X()  << " " << fPos.Y()  << " " << fPos.Z() << " ";
+    gLog << fNorm.X() << " " << fNorm.Y() << " " << fNorm.Z() << " ";
+    gLog << fFocalLength << " ";
+
+    const TString n = ClassName();
+
+    gLog << n(7, n.Length());
+}
Index: trunk/MagicSoft/Mars/msimreflector/MMirror.h
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MMirror.h	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MMirror.h	(revision 9312)
@@ -70,11 +70,11 @@
     // ----- Mirror specialized functions -----
 
-    // This should fit with Paint()
     virtual Bool_t HasHit(const MQuaternion &p) const=0;
-    // This should fit with HasHit()
-    //void Paint(Option_t *)=0;
     virtual Bool_t CanHit(const MQuaternion &p) const=0;
 
     virtual Int_t ReadM(const TObjArray &tok)=0;
+
+    // TObject
+    void Print(Option_t *o) const;
 
     /*
@@ -86,5 +86,5 @@
     }
     */
-    ClassDef(MMirror, 0) // Base class to describe a mirror
+    ClassDef(MMirror, 1) // Base class to describe a mirror
 };
 
Index: trunk/MagicSoft/Mars/msimreflector/MMirrorDisk.cc
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MMirrorDisk.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MMirrorDisk.cc	(revision 9312)
@@ -38,4 +38,6 @@
 #include <TEllipse.h>
 #include <TVirtualPad.h>
+
+#include "MLog.h"
 
 #include "MQuaternion.h"
@@ -99,4 +101,14 @@
 // ------------------------------------------------------------------------
 //
+// Print the contents of the mirror
+//
+void MMirrorDisk::Print(Option_t *o) const
+{
+    MMirror::Print(o);
+    gLog << " " << fR << endl;
+}
+
+// ------------------------------------------------------------------------
+//
 // Paint the mirror in x/y.
 //
Index: trunk/MagicSoft/Mars/msimreflector/MMirrorDisk.h
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MMirrorDisk.h	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MMirrorDisk.h	(revision 9312)
@@ -9,19 +9,22 @@
 {
 private:
-    Double_t fR;
+    Double_t fR; // Radius of the disk
 
 public:
     MMirrorDisk() : fR(24.75) { }
 
+    // MMirror
     Double_t GetMaxR() const { return fR; }
 
-    // This should fit with Paint()
+    Bool_t CanHit(const MQuaternion &p) const;
     Bool_t HasHit(const MQuaternion &p) const;
-    // This should fit with HasHit()
-    void Paint(Option_t *);
-    Bool_t CanHit(const MQuaternion &p) const;
+
     Int_t ReadM(const TObjArray &tok);
 
-    ClassDef(MMirrorDisk, 0)  // A spherical disk type mirror
+    //TObject
+    void Paint(Option_t *);
+    void Print(Option_t *) const;
+
+    ClassDef(MMirrorDisk, 1)  // A spherical disk type mirror
 };
 
Index: trunk/MagicSoft/Mars/msimreflector/MMirrorHex.cc
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MMirrorHex.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MMirrorHex.cc	(revision 9312)
@@ -39,4 +39,6 @@
 #include <TEllipse.h>
 #include <TVirtualPad.h>
+
+#include "MLog.h"
 
 #include "MHexagon.h"
@@ -142,4 +144,14 @@
 // ------------------------------------------------------------------------
 //
+// Print the contents of the mirror
+//
+void MMirrorHex::Print(Option_t *o) const
+{
+    MMirror::Print(o);
+    gLog << " " << fD*2 << endl;
+}
+
+// ------------------------------------------------------------------------
+//
 // Read the mirror's setup from a file. The first eight tokens should be
 // ignored. (This could be fixed!)
Index: trunk/MagicSoft/Mars/msimreflector/MMirrorHex.h
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MMirrorHex.h	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MMirrorHex.h	(revision 9312)
@@ -21,14 +21,17 @@
     MMirrorHex() { SetD(24.75); }
 
+    // MMirror
     Double_t GetMaxR() const { return fMaxR; }
 
-    // This should fit with Paint()
+    Bool_t CanHit(const MQuaternion &p) const;
     Bool_t HasHit(const MQuaternion &p) const;
-    // This should fit with HasHit()
-    void Paint(Option_t *);
-    Bool_t CanHit(const MQuaternion &p) const;
+
     Int_t ReadM(const TObjArray &tok);
 
-    ClassDef(MMirrorHex, 0) // A spherical hexagon type mirror
+    // TObject
+    void Paint(Option_t *);
+    void Print(Option_t *) const;
+
+    ClassDef(MMirrorHex, 1) // A spherical hexagon type mirror
 };
 
Index: trunk/MagicSoft/Mars/msimreflector/MMirrorSquare.cc
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MMirrorSquare.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MMirrorSquare.cc	(revision 9312)
@@ -40,4 +40,6 @@
 #include <TEllipse.h>
 #include <TVirtualPad.h>
+
+#include "MLog.h"
 
 #include "MQuaternion.h"
@@ -139,4 +141,14 @@
 // ------------------------------------------------------------------------
 //
+// Print the contents of the mirror
+//
+void MMirrorSquare::Print(Option_t *o) const
+{
+    MMirror::Print(o);
+    gLog << " " << fSideLength << endl;
+}
+
+// ------------------------------------------------------------------------
+//
 // Read the mirror's setup from a file. The first eight tokens should be
 // ignored. (This could be fixed!)
Index: trunk/MagicSoft/Mars/msimreflector/MMirrorSquare.h
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MMirrorSquare.h	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MMirrorSquare.h	(revision 9312)
@@ -10,17 +10,21 @@
 private:
     Double_t fSideLength; // HALF of the side length!
+
 public:
     MMirrorSquare() : fSideLength(24.75) { }
 
+    // MMirror
     Double_t GetMaxR() const;
 
-    // This should fit with Paint()
     Bool_t HasHit(const MQuaternion &p) const;
-    // This should fit with HasHit()
-    void Paint(Option_t *);
     Bool_t CanHit(const MQuaternion &p) const;
+
     Int_t ReadM(const TObjArray &tok);
 
-    ClassDef(MMirrorSquare, 0) // A spherical square type mirror
+    // TObject
+    void Paint(Option_t *);
+    void Print(Option_t *) const;
+
+    ClassDef(MMirrorSquare, 1) // A spherical square type mirror
 };
 
Index: trunk/MagicSoft/Mars/msimreflector/MReflector.h
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MReflector.h	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MReflector.h	(revision 9312)
@@ -28,4 +28,5 @@
     void InitMaxR();
 
+    // MParContainer
     Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
@@ -46,7 +47,9 @@
     Int_t ExecuteReflector(MQuaternion &p, MQuaternion &u) const;
 
+    // TObject
     void Paint(Option_t *o);
+    void Print(Option_t *o) const;
 
-    ClassDef(MReflector, 0) // Parameter container storing a collection of several mirrors (reflector)
+    ClassDef(MReflector, 1) // Parameter container storing a collection of several mirrors (reflector)
 };
     
Index: trunk/MagicSoft/Mars/msimreflector/MSimReflector.cc
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MSimReflector.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/msimreflector/MSimReflector.cc	(revision 9312)
@@ -559,4 +559,11 @@
     fEvt->Sort(kTRUE);
 
+    // FIXME FIXME FIXME: Set maxindex, first and last time.
+    // SetMaxIndex(fReflector->GetNumMirrors()-1)
+    // if (fEvt->GetNumPhotons())
+    // {
+    //    SetTime(fEvt->GetFirst()->GetTime(), fEvt->GetLast()->GetTime());
+    // }
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mtools/MagicJam.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicJam.cc	(revision 9311)
+++ trunk/MagicSoft/Mars/mtools/MagicJam.cc	(revision 9312)
@@ -77,4 +77,5 @@
 #include <TGFileDialog.h>
 
+#include "MH.h"
 #include "MHexagon.h"
 #include "MGeomCam.h"
@@ -365,5 +366,7 @@
     if (fImage)
     {
-        SetRange();
+        const Float_t r = fGeomCam->GetMaxRadius();
+
+        MH::SetPadRange(-r*1.02, -r*1.02, TestBit(kNoLegend) ? r : 1.15*r, r*1.2);
 
         Double_t x1, y1, x2, y2;
@@ -732,4 +735,6 @@
         cam[i].SetNeighbors(nn[0], nn[1], nn[2], nn[3], nn[4], nn[5]);
     }
+
+    cam.InitGeometry();
 
     SetGeometry(cam);
@@ -856,5 +861,4 @@
         o->Draw();
         gPad->SetBit(kCannotPick);
-        gPad->GetPad(1)->SetBit(kCannotPick);
     }
 
Index: trunk/MagicSoft/include-Classes/MMcFormat/MMcCorsikaRunHeader.h
===================================================================
--- trunk/MagicSoft/include-Classes/MMcFormat/MMcCorsikaRunHeader.h	(revision 9311)
+++ trunk/MagicSoft/include-Classes/MMcFormat/MMcCorsikaRunHeader.h	(revision 9312)
@@ -109,4 +109,9 @@
 		Int_t CTnum);
 
+    void SetSpectrum(Float_t slope, Float_t emin, Float_t emax)
+    {
+        fSlopeSpec=slope; fELowLim=emin; fEUppLim=emax;
+    }
+
     MGeomCorsikaCT &operator[](Int_t i) const;
 
Index: trunk/MagicSoft/include-Classes/MMcFormat/MMcEvt.hxx
===================================================================
--- trunk/MagicSoft/include-Classes/MMcFormat/MMcEvt.hxx	(revision 9311)
+++ trunk/MagicSoft/include-Classes/MMcFormat/MMcEvt.hxx	(revision 9312)
@@ -109,4 +109,7 @@
     void SetCoreY(Float_t CoreY) { fCoreY=CoreY; }                //Set Core y pos
 
+    void SetEvtNumber(UInt_t n) { fEvtNumber=n; }
+    void SetPhotElfromShower(UInt_t n) { fPhotElfromShower=n; }
+
     void Fill( UInt_t, ParticleId_t, Float_t, Float_t, Float_t,
                Float_t, Float_t, Float_t, Float_t, Float_t, Float_t,
Index: trunk/MagicSoft/include-Classes/MMcFormat/MMcEvtBasic.cc
===================================================================
--- trunk/MagicSoft/include-Classes/MMcFormat/MMcEvtBasic.cc	(revision 9311)
+++ trunk/MagicSoft/include-Classes/MMcFormat/MMcEvtBasic.cc	(revision 9312)
@@ -89,4 +89,17 @@
 // --------------------------------------------------------------------------
 //
+// Copy operator. Copy all data members
+//
+void MMcEvtBasic::operator=(const MMcEvtBasic &evt)
+{
+    fPartId         = evt.fPartId;
+    fEnergy         = evt.fEnergy;
+    fImpact         = evt.fImpact;
+    fTelescopePhi   = evt.fTelescopePhi;
+    fTelescopeTheta = evt.fTelescopeTheta;
+}
+
+// --------------------------------------------------------------------------
+//
 //  Reset all values: Fill(kUNDEFINED, -1, -1, 0, 0)
 //
Index: trunk/MagicSoft/include-Classes/MMcFormat/MMcEvtBasic.h
===================================================================
--- trunk/MagicSoft/include-Classes/MMcFormat/MMcEvtBasic.h	(revision 9311)
+++ trunk/MagicSoft/include-Classes/MMcFormat/MMcEvtBasic.h	(revision 9312)
@@ -5,5 +5,4 @@
 #include "MParContainer.h"
 #endif
-
 
 class MMcEvtBasic : public MParContainer
@@ -41,4 +40,5 @@
   MMcEvtBasic();
   MMcEvtBasic(ParticleId_t, Float_t, Float_t, Float_t, Float_t);
+  void operator=(const MMcEvtBasic &evt);
 
   // Getter
Index: trunk/MagicSoft/include-Classes/MMcFormat/MMcRunHeader.cxx
===================================================================
--- trunk/MagicSoft/include-Classes/MMcFormat/MMcRunHeader.cxx	(revision 9311)
+++ trunk/MagicSoft/include-Classes/MMcFormat/MMcRunHeader.cxx	(revision 9312)
@@ -138,7 +138,8 @@
     fSlopeSpec = 0.0;
 
-    fCorsikaVersion = 0;
-    fReflVersion = 0;
-    fCamVersion = 0;
+    fCorsikaVersion = UShort_t(-1);
+    fReflVersion    = UShort_t(-1);
+    fCamVersion     = UShort_t(-1);
+
     fOpticLinksNoise= 0;
 
Index: trunk/MagicSoft/include-Classes/MMcFormat/MMcRunHeader.hxx
===================================================================
--- trunk/MagicSoft/include-Classes/MMcFormat/MMcRunHeader.hxx	(revision 9311)
+++ trunk/MagicSoft/include-Classes/MMcFormat/MMcRunHeader.hxx	(revision 9312)
@@ -6,4 +6,19 @@
 #endif
 
+// -------------------------------------------------------------
+//
+//  The following data member are in use:
+//
+//    fCorsikaVersion        MHCollectionArea
+//    fReflVersion           MSrcPosCalc
+//    fCamVersion            MMcCalibrationUpdate, MReadMarsFile,
+//                           MMcPedestalCopy, MMcPedestalNSBAdd
+//    fStarField*            MMcBadPixelSet
+//    fImpactMax             MHCollectionArea
+//    fNumSimulatedShowers   MHCollectionArea
+//    [fAllEvtsTriggered]    MHCollectionArea
+//    fNumPheFromDNSB        MMcPedestalNSBAdd
+//
+// -------------------------------------------------------------
 
 class MMcRunHeader : public MParContainer
@@ -146,4 +161,7 @@
   Float_t GetImpactMax() const            {return fImpactMax;}
 
+  void SetNumSimulatedShowers(UInt_t n) { fNumSimulatedShowers=n; }
+  void SetImpactMax(Float_t im) { fImpactMax=im; }
+
   ClassDef(MMcRunHeader, 7)	// storage container for general run info
 };
