Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9346)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9347)
@@ -18,4 +18,50 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2009/02/18 Thomas Bretz
+
+   * datacenter/scripts/runcorsika:
+     - added a comment
+
+   * mbase/MParList.cc:
+     - when adding a TCollectionn only add MParContainers
+
+   * mcorsika/MCorsikaRunHeader.[h,cc]:
+     - added reading of Atmospheric coefficients
+     - added reading of Cherenkov Flag
+     - added corsika's Earth Radius
+
+   * melectronics/MDigitalSignal.[h,cc]:
+     - added and initialized an index to allow to "connect"
+       the digital signal to a channel
+
+   * mjtrain/MJTrainSeparation.cc:
+     - replaced kGreen by kBlue
+
+   * mmain/MEventDisplay.cc:
+     - added a type==3 which is for ceres-reflector files
+
+   * mmain/Makefile:
+     - added -I../mcorsika
+     - added -I../msim
+     - added -I../msimcamera
+
+   * msim/MHPhotonEvent.[h,cc]:
+     - set the binning more automatically from the run-headers
+       where possible
+     - added RadEnv
+     - added Clear function for external access
+
+   * msim/MSimAbsorption.cc:
+     - addec const-qualifier for photon
+
+   * msimcamera/MSimGeomCam.cc:
+     - allow usage also without pulse and pulse position (for display)
+
+   * msimcamera/MSimSignalCam.cc:
+     - allow usage also without TriggerPos
+     - added a check whether MSignalCam was correctly initialized
+
+
+
  2009/02/16 Thomas Bretz
 
@@ -44,4 +90,11 @@
      - now read the ganymed.rc and write it to the output
 
+   * mhflux/MHEffectiveOnTime.h:
+     - increased class version by 1
+
+   * mhflux/MHAlpha.cc:
+     - removed erronornously comittet SetSumw2
+     - don't output the numbe rof excess events vs time
+
 
 
@@ -71,8 +124,4 @@
    * mfileio/MWriteRootFile.cc:
      - don't output title if empty
-
-   * mhflux/MHAlpha.cc:
-     - removed erronornously comittet SetSumw2
-     - don't output the numbe rof excess events vs time
 
    * mhflux/MHEffectiveOnTime.[h,cc]:
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 9346)
+++ trunk/MagicSoft/Mars/NEWS	(revision 9347)
@@ -36,4 +36,6 @@
 
    * The display now also displays the trigger pattern
+
+   * The display can now display ceres reflector (_R_) files
 
  ;ceres
Index: trunk/MagicSoft/Mars/datacenter/scripts/runcorsika
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runcorsika	(revision 9346)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runcorsika	(revision 9347)
@@ -68,5 +68,8 @@
    # positive if array x-direction points to the west
    echo "ARRANG -7.0"
-   # Atmosphere
+   # Atmosphere (model, true/false for atmospheric refraction of cer-photons)
+   # Atmosphere read from atmprof11.dat
+   # My current understanding is that only refraction (bending of light
+   # but no absorption of photons is taken into account) setting T.
    echo "ATMOSPHERE 11 T"
    # Other parameters
Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 9346)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 9347)
@@ -261,9 +261,7 @@
     while ((cont=Next()))
     {
-        if (!dynamic_cast<MParContainer*>(cont))
-            continue;
-
-        cont->SetBit(kMustCleanup);
-        AddToList(cont);
+        MParContainer *par = dynamic_cast<MParContainer*>(cont);
+        if (par)
+            AddToList(par);
     }
 }
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9346)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9347)
@@ -37,4 +37,8 @@
 //  + Float_t fMagneticFieldZ
 //  + Float_t fMagneticFieldAz
+//  + Float_t fAtmosphericCoeffA[5]
+//  + Float_t fAtmosphericCoeffB[5]
+//  + Float_t fAtmosphericCoeffC[5]
+//  + UInt_t  fCerenkovFlag
 //
 ////////////////////////////////////////////////////////////////////////////
@@ -53,4 +57,6 @@
 
 using namespace std;
+
+const Double_t MCorsikaRunHeader::fgEarthRadius = 637131500; // [cm] Earth radius as defined in CORSIKA
 
 // --------------------------------------------------------------------------
@@ -81,6 +87,6 @@
     }
 
-    Float_t f[68];
-    fin.read((char*)f, 68);
+    Float_t f[272*4];
+    fin.read((char*)f, 272*4);
 
     fRunNumber = TMath::Nint(f[0]);
@@ -105,5 +111,9 @@
     fEnergyMax      = f[16];
 
-    fin.seekg(1020, ios::cur);     // skip the remaining data of this block
+    // 0/10 not supported?
+
+    memcpy(fAtmosphericCoeffA, f+253, 5*4);
+    memcpy(fAtmosphericCoeffB, f+258, 5*4);
+    memcpy(fAtmosphericCoeffC, f+263, 5*4);
 
     // -------------------- Read first event header -------------------
@@ -157,4 +167,7 @@
     fMagneticFieldAz =  g[91];  // Azimuth angle of magnetic north expressed in telescope coordinates
 
+    // WITH rounding: unbelievable!
+    fCerenkovFlag = TMath::Nint(g[75]);
+
     fZdMin = g[79];                // lower edge of theta in °
     fZdMax = g[80];                // upper edge of theta in °
@@ -173,6 +186,6 @@
     fImpactMax = g[86];
 
-    fWavelengthMin = g[95];        // Cherenkov bandwidth lower end in nm
-    fWavelengthMax = g[96];        // Cherenkov bandwidth upper end in nm
+    fWavelengthMin = g[94];        // Cherenkov bandwidth lower end in nm
+    fWavelengthMax = g[95];        // Cherenkov bandwidth upper end in nm
 
     fViewConeInnerAngle = g[151];  // inner angle of view cone (°)
@@ -251,4 +264,5 @@
 
     *fLog << "Spectrum:      Slope=" << fSlopeSpectrum << "  (" << fEnergyMin << "GeV-" << fEnergyMax << "GeV)" <<  endl;
+    *fLog << "Wavelength:    " << fWavelengthMin << "nm - " << fWavelengthMax << "nm" << endl;
 
     if (fViewConeOuterAngle>0)
@@ -269,4 +283,17 @@
         *fLog << endl;
     }
-}
-
+
+    *fLog << "Atm.Coeff A:  ";
+    for (int i=0; i<5; i++)
+        *fLog << " " << fAtmosphericCoeffA[i];
+    *fLog << endl;
+    *fLog << "Atm.Coeff B:  ";
+    for (int i=0; i<5; i++)
+        *fLog << " " << fAtmosphericCoeffB[i];
+    *fLog << endl;
+    *fLog << "Atm.Coeff C:  ";
+    for (int i=0; i<5; i++)
+        *fLog << " " << fAtmosphericCoeffC[i];
+    *fLog << endl;
+}
+
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9346)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9347)
@@ -14,6 +14,20 @@
 {
     friend class MCorsikaEvtHeader;
+public:
+    enum CerenkovFlag_t
+    {
+        kCerenkov   = BIT(0),
+        kIact       = BIT(1),
+        kCeffic     = BIT(2),
+        kAtmext     = BIT(3),
+        kRefraction = BIT(4),
+        kVolumedet  = BIT(5),
+        kCurved     = BIT(6),
+        kSlant      = BIT(8)
+    };
 
 private:
+    static const Double_t fgEarthRadius; // Take same Earth radius as in CORSIKA (cm)
+
     UInt_t  fRunNumber;               // Run number
     UInt_t  fParticleID;              // Particle ID (see MMcEvtBasic or CORSIKA manual)
@@ -45,4 +59,10 @@
     Float_t fViewConeInnerAngle;      // [deg]
     Float_t fViewConeOuterAngle;      // [deg]
+
+    Float_t fAtmosphericCoeffA[5];    // [g/cm²] AATM (see Corsika Manual for details)
+    Float_t fAtmosphericCoeffB[5];    // [g/cm²] BATM (see Corsika Manual for details)
+    Float_t fAtmosphericCoeffC[5];    // [cm]    CATM (see Corsika Manual for details)
+
+    UInt_t fCerenkovFlag;
 
 public:
@@ -80,4 +100,17 @@
     Bool_t HasViewCone() const { return fViewConeOuterAngle>0; }
 
+    Float_t GetObsLevel(UInt_t i=0) const { return i>9 ? -1 : fObsLevel[i]; }
+
+    Bool_t Has(CerenkovFlag_t opt) { return fCerenkovFlag&opt ? 1 : 0; }
+
+    static Double_t EarthRadius() { return fgEarthRadius; }
+
+    // Preliminary!
+    const Float_t *GetAtmosphericCoeffA() const { return fAtmosphericCoeffA; }
+    const Float_t *GetAtmosphericCoeffB() const { return fAtmosphericCoeffB; }
+    const Float_t *GetAtmosphericCoeffC() const { return fAtmosphericCoeffC; }
+
+    UInt_t GetNumAtmosphericModel() const { return (fCerenkovFlag>>10)&0x3ff; }
+
     // I/O
     Bool_t ReadEvt(istream& fin);
Index: trunk/MagicSoft/Mars/melectronics/MDigitalSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/melectronics/MDigitalSignal.cc	(revision 9346)
+++ trunk/MagicSoft/Mars/melectronics/MDigitalSignal.cc	(revision 9347)
@@ -46,5 +46,5 @@
 // signals.
 //
-MDigitalSignal::MDigitalSignal(const MDigitalSignal &ttl1, const MDigitalSignal &ttl2)
+MDigitalSignal::MDigitalSignal(const MDigitalSignal &ttl1, const MDigitalSignal &ttl2) : fIndex(-1)
 {
     const Double_t new0 = TMath::Max(ttl1.fStart,              ttl2.fStart);
Index: trunk/MagicSoft/Mars/melectronics/MDigitalSignal.h
===================================================================
--- trunk/MagicSoft/Mars/melectronics/MDigitalSignal.h	(revision 9346)
+++ trunk/MagicSoft/Mars/melectronics/MDigitalSignal.h	(revision 9347)
@@ -13,14 +13,19 @@
     Double_t fLength;
 
+    Int_t fIndex;
+
 public:
-    MDigitalSignal(Double_t start=0, Double_t len=1e12/*FLT_MAX*/) : fStart(start), fLength(len)
+    MDigitalSignal(Double_t start=0, Double_t len=1e12/*FLT_MAX*/) : fStart(start), fLength(len), fIndex(-1)
     {
     }
 
-    MDigitalSignal(const MDigitalSignal &ttl) : TObject(ttl), fStart(ttl.fStart), fLength(ttl.fLength)
+    MDigitalSignal(const MDigitalSignal &ttl) : TObject(ttl), fStart(ttl.fStart), fLength(ttl.fLength), fIndex(ttl.fIndex)
     {
     }
 
     MDigitalSignal(const MDigitalSignal &ttl1, const MDigitalSignal &ttl2);
+
+    // Setter
+    void SetIndex(Int_t idx=-1) { fIndex=idx; }
 
     // Getter
@@ -30,4 +35,7 @@
     Double_t GetEnd() const    { return fStart+fLength; }
     Double_t GetLength() const { return fLength; }
+
+    Int_t GetIndex() const { return fIndex; }
+    Bool_t IsConnected() const { return fIndex>=0; }
 
     // TObject
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 9346)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc	(revision 9347)
@@ -98,5 +98,5 @@
 
     h.SetMarkerColor(kRed);
-    g.SetMarkerColor(kGreen);
+    g.SetMarkerColor(kBlue);
 
     TH2D res1(g);
Index: trunk/MagicSoft/Mars/mmain/MEventDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 9346)
+++ trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 9347)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MEventDisplay.cc,v 1.69 2009-02-12 20:05:06 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MEventDisplay.cc,v 1.70 2009-02-18 12:06:39 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -92,4 +92,6 @@
 #include "MContinue.h"                 // MContinue
 #include "MTriggerPatternDecode.h"     // MTriggerPatternDecode
+#include "MSimSignalCam.h"             // MSimSignalCam
+#include "MSimGeomCam.h"               // MSimGeomCam
 //#include "MMcTriggerLvl2Calc.h"        // MMcTriggerLvl2Calc
 
@@ -112,4 +114,5 @@
 #include "MCalibrationChargeCam.h"     // MCalibrationChargeCam
 #include "MMuonSearchPar.h"            // MMuonCalibPar
+#include "MHPhotonEvent.h"             // MHPhotonEvent
 //#include "MMcTriggerLvl2.h"            // MMcTriggerLvl2
 
@@ -180,4 +183,7 @@
         return 2;
 
+    if (t->FindBranch("MPhotonEvent."))
+        return 3;
+
     return -2;
 }
@@ -197,4 +203,5 @@
     case  1: gLog << all << "Calibrated Data File detected..." << endl; break;
     case  2: gLog << all << "Raw Data File detected..." << endl; break;
+    case  3: gLog << all << "Ceres reflector file detected..." << endl; break;
     case -2: gLog << err << "File type unknown... abort." << endl; return;
     case -1: gLog << err << "Tree " << tname << " not found... abort." << endl; return;
@@ -237,4 +244,24 @@
     tlist->AddToList(read);
 
+    MGeomApply *apl = new MGeomApply;
+    tlist->AddToList(apl);
+
+    if (type==3)
+    {
+        MHPhotonEvent *phevt = new MHPhotonEvent;
+        phevt->PermanentReset();
+        plist->AddToList(phevt);
+
+        MFillH *fillh = new MFillH(phevt, "MPhotonEvent");
+        fillh->SetNameTab("Detector");
+        tlist->AddToList(fillh);
+
+        MSimGeomCam *simgeom = new MSimGeomCam;
+        tlist->AddToList(simgeom);
+
+        MSimSignalCam *sim = new MSimSignalCam;
+        tlist->AddToList(sim);
+    }
+
     MContinue *mcevts = new MContinue("MRawEvtData.GetNumPixels==0", "ContEmpty");
     if (type==2)
@@ -247,7 +274,4 @@
     contevt->SetInverted();
     tlist->AddToList(contevt);
-
-    MGeomApply *apl = new MGeomApply;
-    tlist->AddToList(apl);
 
     MTriggerPatternDecode *decode = new MTriggerPatternDecode;
@@ -297,12 +321,4 @@
     plist->AddToList(evt10);
 
-    MExtractTimeAndChargeDigitalFilter *digf = new MExtractTimeAndChargeDigitalFilter;
-    digf->SetNameWeightsFile("msignal/cosmics_weights46.dat");
-
-    MTaskEnv *taskenv1=new MTaskEnv("ExtractSignal");
-    taskenv1->SetDefault(digf);
-    taskenv1->SetOwner();
-
-    MSignalCalc     *nanal   = new MSignalCalc;
     MFillH          *fill01  = new MFillH(evt01, "MSignalCam", "MFillH01");
     MImgCleanStd    *clean   = new MImgCleanStd;
@@ -317,4 +333,13 @@
     MFillH          *fill10  = new MFillH(evt10, "MSignalCam",    "MFillH10");
 
+    MExtractTimeAndChargeDigitalFilter *digf = new MExtractTimeAndChargeDigitalFilter;
+    digf->SetNameWeightsFile("msignal/cosmics_weights46.dat");
+
+    MTaskEnv *taskenv1=new MTaskEnv("ExtractSignal");
+    taskenv1->SetDefault(digf);
+    taskenv1->SetOwner();
+
+    MSignalCalc     *nanal   = new MSignalCalc;
+
     MBadPixelsCalc  *bcalc   = new MBadPixelsCalc;
     MBadPixelsTreat *btreat  = new MBadPixelsTreat;
@@ -379,5 +404,6 @@
     if (type==2)
         tlist->AddToList(fill03);
-    tlist->AddToList(fill04);
+    if (type!=3)
+        tlist->AddToList(fill04);
     tlist->AddToList(fill06a);
     tlist->AddToList(fill06b);
@@ -393,5 +419,5 @@
 	//tlist->AddToList(fill09);
     }
-    if (type==1)
+    if (type==1 || type==3)
     {
         MFillH *fill08 = new MFillH(evt08, "MSignalCam", "MFillH8");
@@ -662,4 +688,5 @@
     *fLog << all;
     fLog->Separator(MString::Format("Entry %d", reader->GetNumEntry()+1));
+
     ((MHillas*)     plist->FindObject("MHillas"))->Print(*geom);
     ((MHillasExt*)  plist->FindObject("MHillasExt"))->Print(*geom);
@@ -716,8 +743,12 @@
     };
 
+    const Int_t ismc = plist->FindObject("MHPhotonEvent") ? 1 : 0;
 
     for (int i=1; i<7; i++)
     {
-        TCanvas *c = GetCanvas(i);
+        TCanvas *c = GetCanvas(i+ismc);
+        if (!c)
+            continue;
+
         c->cd(1);
 
Index: trunk/MagicSoft/Mars/mmain/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mmain/Makefile	(revision 9346)
+++ trunk/MagicSoft/Mars/mmain/Makefile	(revision 9347)
@@ -24,5 +24,5 @@
            -I../mdata -I../msignal -I../mcalib -I../mbadpixels            \
            -I../mpointing -I../mpedestal -I../mmuon -I../mfilter -I../mjobs \
-	   -I../mtrigger
+	   -I../mtrigger -I../mcorsika -I../msimcamera -I../msim
 
 SRCFILES = MBrowser.cc \
Index: trunk/MagicSoft/Mars/msim/MHPhotonEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MHPhotonEvent.cc	(revision 9346)
+++ trunk/MagicSoft/Mars/msim/MHPhotonEvent.cc	(revision 9347)
@@ -115,5 +115,5 @@
     fHistWL.SetName("Spectrum");
     fHistWL.SetTitle("Wavelength distribution");
-    fHistWL.SetXTitle("\\lamba [nm]");
+    fHistWL.SetXTitle("\\lambda [nm]");
     fHistWL.SetYTitle("Counts");
     fHistWL.SetDirectory(NULL);
@@ -124,8 +124,4 @@
     fHistH.SetYTitle("Counts");
     fHistH.SetDirectory(NULL);
-
-    // FIXME: Get this information from the corsika run-header
-    MBinning(70, 275, 625).Apply(fHistWL);
-    MBinning(100, 0, 25).Apply(fHistH);
 }
 
@@ -169,4 +165,22 @@
 // --------------------------------------------------------------------------
 //
+// Find good limits for a binning num x [-max;max]
+// and apply it to fHistXY and fHistT.
+//
+void MHPhotonEvent::SetBinningXY(Int_t num, Double_t max)
+{
+    Double_t min = -max;
+
+    MH::FindGoodLimits(num, num, min, max, kFALSE);
+
+    MBinning binsd, binsa, binsz;
+    binsd.SetEdges(num, min, max);
+
+    SetBinning(&fHistXY, &binsd, &binsd);
+    SetBinning(&fHistT,  &binsd, &binsd);
+}
+
+// --------------------------------------------------------------------------
+//
 // Search for MRflEvtData, MRflEvtHeader and MGeomCam
 //
@@ -175,4 +189,8 @@
     Double_t xmax =  -1;
     Int_t    num  = 100;
+
+    const Int_t f = fPermanentReset ? 2 : 1;
+    MBinning(100/f, 0, 25).Apply(fHistH);
+    MBinning(70, 275, 625).Apply(fHistWL);
 
     switch (fType)
@@ -182,14 +200,6 @@
         // case0: Take a value defined by the user
     case 1:
-        {
-            MCorsikaRunHeader *h = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
-            if (!h)
-            {
-                *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
-                return kFALSE;
-            }
-            xmax = 25000;//h->GetImpactMax()*1.25; // Estimate scattering in the atmosphere
-            break;
-        }
+        xmax = 25000;
+        break;
     case 2:
         {
@@ -222,13 +232,39 @@
     }
 
-    Double_t xmin = -xmax;
+    SetBinningXY(num, xmax);
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// ReInit overwrites the binning of the Wavelength histogram
+// by the wavlenegth band from MCorsikaRunHeader.
+// The bin-width is 5nm (fPermanentReset==kTRUE) or 10nm (kFALSE).
+//
+Bool_t MHPhotonEvent::ReInit(MParList *pList)
+{
+    MCorsikaRunHeader *h = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
+    if (!h)
+    {
+        *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    /*
+    // What is the size of the light pool onm the ground?
+    if (fType==1)
+        SetBinningXY(100, h->GetImpactMax());
+    */
+
+    const Int_t f = fPermanentReset ? 2 : 1;
+
+    Double_t xmin = h->GetWavelengthMin();
+    Double_t xmax = h->GetWavelengthMax();
+    Int_t    num  = TMath::CeilNint((xmax-xmin)/(5*f));
 
     MH::FindGoodLimits(num, num, xmin, xmax, kFALSE);
 
-    MBinning binsd, binsa, binsz;
-    binsd.SetEdges(num, xmin, xmax);
-
-    SetBinning(&fHistXY, &binsd, &binsd);
-    SetBinning(&fHistT,  &binsd, &binsd);
+    MBinning(abs(num), xmin, xmax).Apply(fHistWL);
 
     return kTRUE;
@@ -250,9 +286,5 @@
     // Check if we want to use this class as a single event display
     if (fPermanentReset && evt->GetNumPhotons()>0)
-    {
-        fHistXY.Reset();
-        fHistUV.Reset();
-        fHistT.Reset();
-    }
+        Clear();
 
     // Get number of photons
@@ -365,2 +397,18 @@
     fHistH.Draw();
 }
+
+// --------------------------------------------------------------------------
+//
+// PermanentReset: Off
+//
+Int_t MHPhotonEvent::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "PermanentReset", print))
+    {
+        rc = kTRUE;
+        fPermanentReset = GetEnvValue(env, prefix, "PermanentReset", fPermanentReset);
+    }
+
+    return rc;
+}
Index: trunk/MagicSoft/Mars/msim/MHPhotonEvent.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MHPhotonEvent.h	(revision 9346)
+++ trunk/MagicSoft/Mars/msim/MHPhotonEvent.h	(revision 9347)
@@ -28,16 +28,35 @@
     Bool_t     fPermanentReset;
 
+    // MHPhotonEvent
     void Init(const char *name, const char *title);
+    void SetBinningXY(Int_t num, Double_t max);
 
+    // MParContainer
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
+
+    // MH
     Bool_t SetupFill(const MParList *pList);
+    Bool_t ReInit(MParList *pList);
     Int_t  Fill(const MParContainer *par, const Stat_t weight=1);
     //Bool_t Finalize();
 
 public:
-    MHPhotonEvent(Double_t max=0, const char *name=0, const char *title=0);
-    MHPhotonEvent(Int_t type,     const char *name=0, const char *title=0);
+    MHPhotonEvent(Double_t max, const char *name=0, const char *title=0);
+    MHPhotonEvent(Int_t type=3, const char *name=0, const char *title=0);
 
+    void PermanentReset(Bool_t b=kTRUE) { fPermanentReset=b; }
+
+    // TObject
     void Draw(Option_t *o="");
     void Paint(Option_t *o="");
+
+    void Clear(Option_t *o="")
+    {
+        fHistXY.Reset();
+        fHistUV.Reset();
+        fHistT.Reset();
+        fHistWL.Reset();
+        fHistH.Reset();
+    }
 
     ClassDef(MHPhotonEvent, 2) // Histogram to display the information of MPhotonEvents
Index: trunk/MagicSoft/Mars/msim/MSimAbsorption.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimAbsorption.cc	(revision 9346)
+++ trunk/MagicSoft/Mars/msim/MSimAbsorption.cc	(revision 9347)
@@ -296,5 +296,5 @@
     {
         // Get i-th photon from the list
-        MPhotonData &ph = (*fEvt)[i];
+        const MPhotonData &ph = (*fEvt)[i];
 
         // Depending on fUseTheta get the incident angle of the wavelength
Index: trunk/MagicSoft/Mars/msimcamera/MSimGeomCam.cc
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimGeomCam.cc	(revision 9346)
+++ trunk/MagicSoft/Mars/msimcamera/MSimGeomCam.cc	(revision 9347)
@@ -37,6 +37,7 @@
 //   MPhotonEvent
 //   fNameGeomCam [MGeomCam]
-//   IntendedTrigPos [MParameterD]
 //   MRawRunHeader
+//   [IntendedPulsePos [MParameterD]]
+//   [MPulseShape]
 //
 //  Output Containers:
@@ -103,4 +104,5 @@
 
     fPulse = (MPulseShape*)pList->FindObject("MPulseShape");
+/*
     if (!fPulse)
     {
@@ -108,6 +110,7 @@
         return kFALSE;
     }
-
+ */
     fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
+/*
     if (!fPulsePos)
     {
@@ -115,5 +118,5 @@
         return kFALSE;
     }
-
+*/
     fHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
     if (!fHeader)
@@ -168,11 +171,11 @@
 
     // ------ FIXME: Move somewhere else? MSimCalibrationSignal ------
-
+/*
     if (!fEvt->IsSorted())
     {
-        *fLog << err << "ERROR - MPhotonEvent must be sorted!" << endl;
+        *fLog << err << "ERROR - MSimGeomCam: MPhotonEvent must be sorted!" << endl;
         return kERROR;
     }
-
+ */
     const Float_t freq = fHeader->GetFreqSampling()/1000.;
 
@@ -185,6 +188,6 @@
 
     // Length (ns), Pulse position (Units ns)
-    const Float_t pp   = fPulsePos->GetVal();
-    const Float_t pw   = fPulse->GetPulseWidth();
+    const Float_t pp   = fPulsePos ? fPulsePos->GetVal()     : 0;
+    const Float_t pw   = fPulse    ? fPulse->GetPulseWidth() : 0;
 
     fStat->SetTimeMedDev(fEvt->GetTimeMedianDev());
Index: trunk/MagicSoft/Mars/msimcamera/MSimSignalCam.cc
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimSignalCam.cc	(revision 9346)
+++ trunk/MagicSoft/Mars/msimcamera/MSimSignalCam.cc	(revision 9347)
@@ -35,4 +35,5 @@
 //   MPhotonEvent
 //   MPhotonStatistics
+//   [TriggerPos [MParameterD]]
 //
 //  Output Containers:
@@ -90,4 +91,5 @@
 
     fTrigger = (MParameterD*)pList->FindObject("TriggerPos", "MParameterD");
+/*
     if (!fTrigger)
     {
@@ -95,5 +97,5 @@
         return kFALSE;
     }
-
+*/
     fSignal = (MSignalCam*)pList->FindCreateObj("MSignalCam");
     if (!fSignal)
@@ -111,4 +113,10 @@
 {
     const UInt_t npix = fSignal->GetNumPixels();
+
+    if (npix==0)
+    {
+        *fLog << err << "ERROR - MSignalCam has 0 entries. Presumably MGeomApply::ReInit not done." << endl;
+        return kFALSE;
+    }
 
     if (fCont.GetSize()!=npix)
@@ -163,5 +171,5 @@
     // What about events with trigger<0?
     const Float_t trig  = fTrigger && fTrigger->GetVal()>=0 ? fTrigger->GetVal()  : 0;
-    const Float_t first = fStat->GetTimeFirst()+trig /*+50+40*/;
+    const Float_t first = fStat->GetTimeFirst()+trig;
 
     // Loop over all pixels and set signal and arrival time.
