Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9307)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9308)
@@ -18,4 +18,86 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2009/02/08 Thomas Bretz
+
+   * Makefile.conf.linux:
+     - added -Winit-self
+
+   * msimcamera/MSimCalibrationSignal.[h,cc]:
+     - account for the pulse shape/width
+     - make number of photons settable
+     - make time jitter settable
+     - renamned fNumEntries to fNumEvents
+     - don't set daq event number (should be set by the "daq")
+     - set trigger pattern
+     - print number of events in PreProcess
+
+   * msimreflector/MSimReflector.[h,cc]:
+     - made the detector margin settable
+
+   * datacenter/macros/insertcacofile.C, datacenter/macros/insertsequence.C:
+     - print an error and exit
+
+   * macros/optim/optimdisp.C:
+     - set the default values as default
+     - added a short summary what a good strategy for optimization is
+
+   * mastro/MAstro.cc:
+     - replaced Form by MString::Form
+
+   * mcorsika/MCorsikaEvtHeader.[h,cc], mcorsika/MCorsikaRunHeader.[h,cc]:
+     - moved fParticleID from event header to run header
+     - increased Class Version accordingly
+     - added an error if more than one observation levels are read
+
+   * mhcalib/MHGausEvents.cc:
+     - replaced Form by MString::Form
+     - handle the creating of the TF1 fExpFit a bit more "root-safe"
+
+   * mhist/MHCamEvent.[h,cc]:
+     - added a new option to collect the maximum or minimum contents
+
+   * mhist/MHCamera.[h,cc]:
+     - added new functions SetMax/MinCamContent
+
+   * mraw/MRawEvtHeader.cc:
+     - initialize the data members in constructor
+
+   * mraw/MRawEvtHeader.h:
+     - removed bits for trigger type they were never used
+
+   * mraw/MRawRunHeader.cc:
+     - tiny cosmetics
+
+   * msim/MHPhotonEvent.[h,cc]:
+     - added a histogram to display the height
+     - don't fill kNightSky photons
+
+   * msim/MPhotonData.h:
+     - added getter for fProductionHeight
+
+   * msim/MPhotonEvent.h:
+     - commented IsValid (was not used anyhow)
+
+   * msimcamera/MSimGeomCam.[h,cc]:
+     - added one sample to the window to allow for time jitter of one sample
+     - make the code for the window indentical to MSimCalibrationSignal
+
+   * msimcamera/MSimReadout.[h,cc]:
+     - Set the daq event number (readout number)
+
+   * msimcamera/MSimTrigger.[h,cc]:
+     - added comments
+     - made the signal length settable
+     - made the coincidence time settable
+     - removed setting of the daq event number (should be done by the "daq")
+     - changed the trigger output from all to inf/inf2
+
+   * msimcamera/Makefile:
+     - added -I../mtrigger
+
+
+
+
 
  2009/02/07 Thomas Bretz
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 9307)
+++ trunk/MagicSoft/Mars/NEWS	(revision 9308)
@@ -3,7 +3,8 @@
 == <cvs> ==
 
- ;merpp
-
-   * added support for Arehucas Version >= 200812140
+ ;general
+
+   * fixed a few small bugs which could cause the display to crash in ganymed
+     and sponde
 
  ;database
@@ -12,4 +13,32 @@
      to set size of plot
 
+ ;merpp
+
+   * added support for Arehucas Version >= 200812140
+
+ ;ceres
+
+   * added a uniformly distributed one-bin time jitter for the start of the
+     digitization. Otherwise the first photon would be digitized always with
+     the same alignment to the bins
+
+   * Added a plot showing the production height of the photons
+
+   * Moved the particle id from the event header to the run header
+
+   * Added the possibility to simulate a psf on the camera plane (MSimPSF)
+
+   * Added a new plot ''SignalMax'' showing the maximum entry into the pixels
+
+   * Added many new options to control the tasks. For deatils see ''ceres.rc''
+
+   * Removed obsolete plots in pedestal and calibration mode
+
+   * Removed the non-NightSky photons from the plots where they are just
+     disturbing
+
+   * Added a trigger pattern to the output (Ped, Cal or Lvl1)
+
+   * The daq event number now represents the readout number
 
 
Index: trunk/MagicSoft/Mars/datacenter/macros/insertcacofile.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/insertcacofile.C	(revision 9307)
+++ trunk/MagicSoft/Mars/datacenter/macros/insertcacofile.C	(revision 9308)
@@ -68,4 +68,7 @@
 int insertcacofile(TString runnumber, TString newrunnumber)
 {
+    cout << "ERROR - TelescopeNumber and FileNumber not implemeted." << endl;
+    return 2;
+/*
     MSQLServer serv("sql.rc");
     if (!serv.IsConnected())
@@ -96,5 +99,4 @@
     delete res;
     return 1;
+    */
 }
-
-
Index: trunk/MagicSoft/Mars/datacenter/macros/insertsequence.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/insertsequence.C	(revision 9307)
+++ trunk/MagicSoft/Mars/datacenter/macros/insertsequence.C	(revision 9308)
@@ -60,4 +60,7 @@
 int insertsequence(TString filename, Bool_t dummy=kTRUE)
 {
+    cout << "ERROR - TelescopeNumber and FileNumber not implemeted." << endl;
+    return 2;
+/*
     TEnv env("sql.rc");
     TEnv sequ(filename);
@@ -220,4 +223,5 @@
 
     return 1;
+    */
 }
 
Index: trunk/MagicSoft/Mars/macros/optim/optimdisp.C
===================================================================
--- trunk/MagicSoft/Mars/macros/optim/optimdisp.C	(revision 9307)
+++ trunk/MagicSoft/Mars/macros/optim/optimdisp.C	(revision 9308)
@@ -18,17 +18,18 @@
     char *r = "M[0]*([0] + [1]*M[1] + [2]*M[2] + (M[3]>[3])*[4]*(M[3]-[3])^2)";
 
-    opt.FixParameter(0, 1.266195);
-    opt.FixParameter(1, 0.100577);
-    opt.FixParameter(2, 1.80309);
-    opt.FixParameter(3, 2.87177);
-    opt.FixParameter(4, 0.616823); 
+    opt.FixParameter(0, 1.15136);
+    opt.FixParameter(1, 0.0681437);
+    opt.FixParameter(2, 2.62932);
+    opt.FixParameter(3, 1.51279);
+    opt.FixParameter(4, 0.0507821);
 
     opt.AddPreCut("MNewImagePar.fLeakage1>0");
-    opt.AddPreCut("log10(MHillas.fSize)<3.2");
+    //opt.AddPreCut("log10(MHillas.fSize)<2.5"); //3.2
+
+    opt.AddPreCut("MHillasExt.fM3Long*sign(MHillasSrc.fCosDeltaAlpha)*MGeomCam.fConvMm2Deg>-0.07");
+    opt.AddPreCut("DataType.fVal>0.5");
 
     //opt.AddPreCut("abs(MHillasSrc.fDCA*MGeomCam.fConvMm2Deg)<0.2");
     //opt.AddPreCut("(MHillasSrc.fDist*MGeomCam.fConvMm2Deg-0.5)*7.2>MHillasExt.fSlopeLong*sign(MHillasSrc.fCosDeltaAlpha)/MGeomCam.fConvMm2Deg");
-    opt.AddPreCut("MHillasExt.fM3Long*sign(MHillasSrc.fCosDeltaAlpha)*MGeomCam.fConvMm2Deg>-0.07");
-    opt.AddPreCut("DataType.fVal>0.5");
 
     // -------------------- Run ----------------------------
@@ -66,4 +67,5 @@
      */
 
+    // opt.SetPathOut("optimdisp.root");
     opt.RunDisp("ganymed00000001-summary.root", r);
 }
@@ -73,8 +75,10 @@
    Par  |   0    1     2      3     4     |  Cut
  -------+---------------------------------+-----------------------
-  Fit 1 |  1.3  0.8  fix=0  fix=0  fix=0  | Leak1==0 lgSize<2.5
-  Fit 2 |  fix  fix  fix=0   2.4    0.3   | Leak1==0
+  Fit 1 |  1.3  0.1  fix=0  fix=0  fix=0  | Leak1==0 lgSize<2.5
+  Fit 2 |  fix  fix  fix=0   2.5    0.2   | Leak1==0
   Fit 2 |  fix  fix   1.8    fix    fix   | Leak1>0
   Fit 3 |  free free  fix    fix    fix   | -/-
+  Fit 4 |  fix  fix   fix    free   free  | -/-
+  Fit 5 |  fix  fix   free   fix    fix   | -/-
  -------+---------------------------------+-----------------------
 */
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9308)
@@ -26,5 +26,10 @@
 //
 // MCorsikaEvtHeader 
-//    
+//
+// Class Version 2:
+// ----------------
+//  - UInt_t fParticleID
+//
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MCorsikaEvtHeader.h"
@@ -38,5 +43,5 @@
 #include "MLogManip.h"
 
-#include "MMcEvt.hxx"
+//#include "MMcEvt.hxx"
 
 ClassImp(MCorsikaEvtHeader);
@@ -71,5 +76,5 @@
     *fLog << all;
     *fLog << "Event Number:              " << dec << fEvtNumber << endl;
-    *fLog << "Particle ID:               " << MMcEvt::GetParticleName(fParticleID) << endl;
+//    *fLog << "Particle ID:               " << MMcEvt::GetParticleName(fParticleID) << endl;
     *fLog << "Energy:                    " << fTotalEnergy << "GeV" << endl;
     *fLog << "Starting Altitude:         " << fStartAltitude << "g/cm²" << endl;
@@ -102,5 +107,5 @@
 
     fEvtNumber  = TMath::Nint(f[0]);
-    fParticleID = TMath::Nint(f[1]);
+//    fParticleID = TMath::Nint(f[1]);
 
     fTotalEnergy            = f[2];
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h	(revision 9307)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h	(revision 9308)
@@ -18,5 +18,5 @@
 private:
     UInt_t   fEvtNumber;              // Event number
-    UInt_t   fParticleID;             // Particle ID (see MMcEvtBasic or CORSIKA manual)
+//    UInt_t   fParticleID;             // Particle ID (see MMcEvtBasic or CORSIKA manual)
     Float_t  fTotalEnergy;            // [GeV] 
 
@@ -44,5 +44,5 @@
 
     UInt_t GetEvtNumber() const { return fEvtNumber; }
-    UInt_t GetParticleID() const { return fParticleID; }
+//    UInt_t GetParticleID() const { return fParticleID; }
 
     TVector3 GetMomentum() const { return TVector3(fMomentumX, fMomentumY, fMomentumZ); }
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9308)
@@ -30,4 +30,8 @@
 // Root storage container for the RUN HEADER information
 //
+// Class Version 2:
+// ----------------
+//  + UInt_t fParticleID
+//
 ////////////////////////////////////////////////////////////////////////////
 
@@ -39,4 +43,6 @@
 #include "MLog.h"
 #include "MLogManip.h"
+
+#include "MMcEvt.hxx"
 
 ClassImp(MCorsikaRunHeader);
@@ -81,4 +87,10 @@
     fProgramVersion = f[2];          //FIXME: INT???
     fNumObsLevel    = TMath::Nint(f[3]);
+
+    if (fNumObsLevel!=1)
+    {
+        *fLog << err << "ERROR - Currently only one observation level is allowed." << endl;
+        return kFALSE;
+    }
 
     memset(fObsLevel, 0, 10*4);
@@ -127,5 +139,5 @@
     fin.seekg(-274*4, ios::cur);
 
-    const Int_t n = TMath::Nint(g[96]);  // Numbr i of uses of each cherenkov event
+    const Int_t n = TMath::Nint(g[96]);  // Number i of uses of each cherenkov event
     if (n!=1)
     {
@@ -133,4 +145,6 @@
         return kFALSE;
     }
+
+    fParticleID = TMath::Nint(g[1]);
 
     //fImpactMax = g[86];
@@ -208,4 +222,5 @@
     *fLog << all << endl;
     *fLog << "Run Number:  " << fRunNumber << "  (" << fRunStart.GetStringFmt("%d.%m.%Y") << ", V" << fProgramVersion << ")" << endl;
+    *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
     if (fNumEvents>0)
         *fLog << "Num Events:  " << fNumEvents << endl;
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9307)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9308)
@@ -17,4 +17,5 @@
 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)
@@ -22,5 +23,5 @@
 
     Byte_t    fNumObsLevel;       // Number of observation levels
-    Float_t   fObsLevel[10];      //[fNumObsLevel] Observation levels [cm]
+    Float_t   fObsLevel[10];      // Observation levels [cm]
 
     Float_t   fSlopeSpectrum;     // Slope of energy spectrum
@@ -56,4 +57,6 @@
     Float_t GetWavelengthMax() const { return fWavelengthMax; }
 
+    UInt_t GetParticleID() const { return fParticleID; }
+
     //Float_t GetImpactMax() const { return fImpactMax; }
 
@@ -68,5 +71,5 @@
     Bool_t SeekEvtEnd(istream &fin);
 
-    ClassDef(MCorsikaRunHeader, 1)	// storage container for general info
+    ClassDef(MCorsikaRunHeader, 2)	// storage container for general info
 };
 #endif
Index: trunk/MagicSoft/Mars/mhcalib/MHGausEvents.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHGausEvents.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/mhcalib/MHGausEvents.cc	(revision 9308)
@@ -90,4 +90,5 @@
 
 #include "MFFT.h"
+#include "MString.h"
 #include "MArrayF.h"
 
@@ -320,5 +321,5 @@
   fPowerSpectrum     = fourier.PowerSpectrumDensity(&fEvents);
   fHPowerProbability = ProjectArray(*fPowerSpectrum, fPowerProbabilityBins,
-                                    Form("%s%s","PowerProb",GetName()),
+                                    MString::Format("PowerProb%s", GetName()),
                                     "Probability of Power occurrance");
   fHPowerProbability->SetXTitle("P(f)");
@@ -332,5 +333,8 @@
   const Double_t xmax = fHPowerProbability->GetXaxis()->GetXmax();
 
-  fFExpFit = new TF1("FExpFit","exp([0]-[1]*x)",0.,xmax);
+  fFExpFit = new TF1("","exp([0]-[1]*x)",0.,xmax);
+  fFExpFit->SetName("FExpFit");
+  gROOT->GetListOfFunctions()->Remove(fFExpFit);
+
 
   const Double_t slope_guess  = (TMath::Log(fHPowerProbability->GetEntries())+1.)/xmax;
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 9308)
@@ -159,5 +159,6 @@
     if (!fTitle.Contains(";"))
         fSum->SetYTitle("a.u.");
-    fSum->SetBit(MHCamera::kProfile);
+    if (fUseThreshold!=kCollectMin && fUseThreshold!=kCollectMax)
+        fSum->SetBit(MHCamera::kProfile);
     if (!fErrorSpread)
         fSum->SetBit(MHCamera::kErrorMean);
@@ -178,8 +179,29 @@
         return kERROR;
     }
-    if (fUseThreshold)
+
+    switch (fUseThreshold)
+    {
+    case kNoBound:
+        fSum->AddCamContent(*evt, fType);
+        break;
+
+    case kIsLowerBound:
+    case kIsUpperBound:
         fSum->CntCamContent(*evt, fThreshold, fType, fUseThreshold>0);
-    else
-        fSum->AddCamContent(*evt, fType);
+        break;
+
+    case kCollectMin:
+        fSum->SetMinCamContent(*evt, /*fThreshold,*/ fType);
+        break;
+
+    case kCollectMax:
+        fSum->SetMaxCamContent(*evt, /*fThreshold,*/ fType);
+        break;
+
+    default:
+        *fLog << err << "ERROR - MHCamEvent::Fill: Unknown type." << endl;
+        return kERROR;
+    }
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 9307)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 9308)
@@ -35,5 +35,5 @@
 
 public:
-    enum { kIsLowerBound=1, kIsUpperBound=-1, kNoBound=0 };
+    enum { kIsLowerBound=1, kIsUpperBound=-1, kNoBound=0, kCollectMin=-2, kCollectMax=2 };
 
     MHCamEvent(const char *name=NULL, const char *title=NULL);
@@ -57,4 +57,6 @@
 
     void SetThreshold(Float_t f=0, Char_t direction=kIsLowerBound) { fThreshold = f; fUseThreshold=direction; }
+    void SetCollectMin() { fUseThreshold=kCollectMin; }
+    void SetCollectMax() { fUseThreshold=kCollectMax; }
     void SetErrorSpread(Bool_t b=kTRUE) { fErrorSpread = b; }
     void SetErrorRelative(Bool_t b=kTRUE) { fErrorRelative = b; }
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9308)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.113 2009-02-07 20:47:41 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.114 2009-02-09 11:30:53 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -1591,6 +1591,8 @@
 //
 // Call this function to add a MCamEvent on top of the present contents.
-// 1 is added to each pixel if the contents of MCamEvent>threshold (in case isabove is set to kTRUE == default)
-// 1 is added to each pixel if the contents of MCamEvent<threshold (in case isabove is set to kFALSE)
+// 1 is added to each pixel if the contents of MCamEvent>threshold
+//   (in case isabove is set to kTRUE == default)
+// 1 is added to each pixel if the contents of MCamEvent<threshold
+//   (in case isabove is set to kFALSE)
 //
 // in unused pixel is not counted if it didn't fullfill the condition.
@@ -1658,6 +1660,8 @@
 //
 // Call this function to add a MCamEvent on top of the present contents.
-// 1 is added to each pixel if the contents of MCamEvent>threshold (in case isabove is set to kTRUE == default)
-// 1 is added to each pixel if the contents of MCamEvent<threshold (in case isabove is set to kFALSE)
+// 1 is added to each pixel if the contents of MCamEvent>threshold
+//   (in case isabove is set to kTRUE == default)
+// 1 is added to each pixel if the contents of MCamEvent<threshold
+//   (in case isabove is set to kFALSE)
 //
 // in unused pixel is not counted if it didn't fullfill the condition.
@@ -1702,4 +1706,76 @@
         if (!ispos || fArray[idx+1]>0)
             SetUsed(idx);
+    }
+    fEntries++;
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to add a MCamEvent on top of the present contents.
+// 1 is added to each pixel if the contents of MCamEvent>threshold
+//   (in case isabove is set to kTRUE == default)
+// 1 is added to each pixel if the contents of MCamEvent<threshold
+//   (in case isabove is set to kFALSE)
+//
+// in unused pixel is not counted if it didn't fullfill the condition.
+//
+void MHCamera::SetMaxCamContent(const MCamEvent &event, Int_t type)
+{
+    if (fNcells<=1 || IsFreezed())
+        return;
+
+    // FIXME: Security check missing!
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+        Double_t val=0;
+        const Bool_t rc = event.GetPixelContent(val, idx, *fGeomCam, type);
+        if (!rc)
+            continue;
+
+        if (!IsUsed(idx))
+        {
+            fArray[idx+1] = val;
+            SetUsed(idx);
+            fBinEntries.fArray[idx+1]=1;
+        }
+        else
+            if (val>fArray[idx+1])
+                fArray[idx+1] = val;
+    }
+    fEntries++;
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to add a MCamEvent on top of the present contents.
+// 1 is added to each pixel if the contents of MCamEvent>threshold
+//   (in case isabove is set to kTRUE == default)
+// 1 is added to each pixel if the contents of MCamEvent<threshold
+//   (in case isabove is set to kFALSE)
+//
+// in unused pixel is not counted if it didn't fullfill the condition.
+//
+void MHCamera::SetMinCamContent(const MCamEvent &event, Int_t type)
+{
+    if (fNcells<=1 || IsFreezed())
+        return;
+
+    // FIXME: Security check missing!
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+        Double_t val=0;
+        const Bool_t rc = event.GetPixelContent(val, idx, *fGeomCam, type);
+        if (!rc)
+            continue;
+
+        if (!IsUsed(idx))
+        {
+            fArray[idx+1] = val;
+            SetUsed(idx);
+            fBinEntries.fArray[idx+1]=1;
+        }
+        else
+            if (val<fArray[idx+1])
+                fArray[idx+1] = val;
     }
     fEntries++;
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 9307)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 9308)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-!  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.66 2008-12-02 11:22:19 tbretz Exp $
+!  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.67 2009-02-09 11:30:53 tbretz Exp $
 \* ======================================================================== */
 #ifndef MARS_MHCamera
@@ -180,4 +180,7 @@
     virtual void     CntCamContent(const TArrayD &evt, Double_t threshold, Bool_t ispos=kTRUE);
     virtual void     CntCamContent(const MCamEvent &event, Int_t type1, const MCamEvent &thresevt, Int_t type2, Double_t threshold, Bool_t isabove);
+
+    virtual void     SetMaxCamContent(const MCamEvent &evt, Int_t type=0);
+    virtual void     SetMinCamContent(const MCamEvent &evt, Int_t type=0);
 
     Stat_t   GetBinContent(Int_t bin) const;
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 9308)
@@ -129,4 +129,5 @@
 //
 MRawEvtHeader::MRawEvtHeader(const char *name, const char *title)
+    : fTime(0), fNumTrigLvl1(0), fNumTrigLvl2(0), fNumLoGainOn(0), fPixLoGainOn(0)
 {
     fName  = name  ? name  : "MRawEvtHeader";
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 9307)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 9308)
@@ -23,5 +23,5 @@
     //
     // Trigger Type (TT)
-    //
+    /*
     enum {
         kTTEvent       = 0,
@@ -30,5 +30,5 @@
         kTTPinDiode    = 3
     };
-
+    */
     enum CLColor_t 
       {
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 9308)
@@ -1124,6 +1124,6 @@
     {
     case 1:
+        fNumSamplesHiGain  =   15;
         fNumSamplesLoGain  =   15;
-        fNumSamplesHiGain  =   15;
         fNumBytesPerSample =    1;    // number of bytes per sample
         fSamplingFrequency =  300;    // Sampling Frequency [MHz]
Index: trunk/MagicSoft/Mars/msim/MHPhotonEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MHPhotonEvent.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/msim/MHPhotonEvent.cc	(revision 9308)
@@ -54,4 +54,10 @@
 // Fill expects a MPhotonEvent (the second argumnet in MFillH).
 //
+//
+// Class Version 2:
+// ----------------
+//  + TH1D fHistH;
+//
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MHPhotonEvent.h"
@@ -113,6 +119,13 @@
     fHistWL.SetDirectory(NULL);
 
+    fHistH.SetName("Height");
+    fHistH.SetTitle("Production Height");
+    fHistH.SetXTitle("h [km]");
+    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);
 }
 
@@ -259,4 +272,7 @@
         const MPhotonData &ph = (*evt)[idx];
 
+        if (ph.GetPrimary()==MMcEvtBasic::kNightSky)
+            continue;
+
         const Double_t x = ph.GetPosX();
         const Double_t y = ph.GetPosY();
@@ -265,4 +281,5 @@
         const Double_t t = ph.GetTime()-min;
         const Double_t w = ph.GetWavelength();
+        const Double_t h = ph.GetProductionHeight()/100000;
 
         //TVector3 dir = dat->GetDir3();
@@ -273,4 +290,5 @@
         fHistT.Fill(x, y, t);
         fHistWL.Fill(w);
+        fHistH.Fill(h);
     }
 
@@ -341,3 +359,8 @@
     gPad->SetGrid();
     fHistWL.Draw();
-}
+
+    pad->cd(6);
+    gPad->SetBorderMode(0);
+    gPad->SetGrid();
+    fHistH.Draw();
+}
Index: trunk/MagicSoft/Mars/msim/MHPhotonEvent.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MHPhotonEvent.h	(revision 9307)
+++ trunk/MagicSoft/Mars/msim/MHPhotonEvent.h	(revision 9308)
@@ -23,4 +23,5 @@
     TProfile2D fHistT;
     TH1D       fHistWL;
+    TH1D       fHistH;
 
     Int_t      fType;
@@ -40,5 +41,5 @@
     void Paint(Option_t *o="");
 
-    ClassDef(MHPhotonEvent, 1) // Histogram to display the information of MPhotonEvents
+    ClassDef(MHPhotonEvent, 2) // Histogram to display the information of MPhotonEvents
 };
 
Index: trunk/MagicSoft/Mars/msim/MPhotonData.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MPhotonData.h	(revision 9307)
+++ trunk/MagicSoft/Mars/msim/MPhotonData.h	(revision 9308)
@@ -83,4 +83,5 @@
     // Getter Others
     UShort_t GetWavelength() const { return fWavelength; }
+    Float_t GetProductionHeight() const { return fProductionHeight; }
     MMcEvtBasic::ParticleId_t GetPrimary() const { return fPrimary; }
 
Index: trunk/MagicSoft/Mars/msim/MPhotonEvent.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MPhotonEvent.h	(revision 9307)
+++ trunk/MagicSoft/Mars/msim/MPhotonEvent.h	(revision 9308)
@@ -157,5 +157,5 @@
     Int_t GetMaxIndex() const { return fMaxIndex; }
 
-    Bool_t IsValid() const { return fTimeLast>=fTimeFirst; }
+//    Bool_t IsValid() const { return fTimeLast>=fTimeFirst; }
 
     ClassDef(MPhotonStatistics, 1)
Index: trunk/MagicSoft/Mars/msimcamera/MSimGeomCam.cc
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimGeomCam.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/msimcamera/MSimGeomCam.cc	(revision 9308)
@@ -170,13 +170,18 @@
     }
 
+    const Float_t freq = fHeader->GetFreqSampling()/1000.;
+
+    // We add an additional sample at the end to support a possible shift
+    // of the start time of the first event by 0 to 1 sample.
+    const Int_t   ns   = fHeader->GetNumSamplesHiGain()+1;
+
     const Float_t first = cnt>0 ? fEvt->GetFirst()->GetTime() :  0;
-    const Float_t last  = cnt>0 ? fEvt->GetLast()->GetTime()  : -1;
+    const Float_t last  = cnt>0 ? fEvt->GetLast()->GetTime()  : ns*freq;
 
     // Length (ns), Pulse position (Units ns)
-    const Float_t ns = fHeader->GetFreqSampling()/1000.*fHeader->GetNumSamplesHiGain();
-    const Float_t pp = fPulsePos->GetVal();
-    const Float_t pw = fPulse->GetPulseWidth();
-
-    fStat->SetTime(first-pp-pw, last+(ns-pp)+pw);
+    const Float_t pp   = fPulsePos->GetVal();
+    const Float_t pw   = fPulse->GetPulseWidth();
+
+    fStat->SetTime(first-pp-pw, last-pp+pw + ns*freq);
     fStat->SetMaxIndex(fGeom->GetNumPixels()-1);
     fStat->SetReadyToSave();
Index: trunk/MagicSoft/Mars/msimcamera/MSimReadout.cc
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimReadout.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/msimcamera/MSimReadout.cc	(revision 9308)
@@ -73,5 +73,5 @@
 //
 MSimReadout::MSimReadout(const char* name, const char *title)
-: fRunHeader(0), fCamera(0), fPulsePos(0), fTrigger(0), fData(0)
+: fRunHeader(0), fEvtHeader(0), fCamera(0), fPulsePos(0), fTrigger(0), fData(0)
 {
     fName  = name  ? name  : "MSimReadout";
@@ -113,4 +113,8 @@
         return kFALSE;
     }
+
+    fEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
+    if (!fEvtHeader)
+        return kFALSE;
 
     fData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
@@ -244,4 +248,8 @@
     fData->SetReadyToSave();
 
+    // Set the trigger/daq event number
+    fEvtHeader->SetDAQEvtNumber(GetNumExecutions());
+    fEvtHeader->SetReadyToSave();
+
     // FIMXE: This will never be stored correctly :(
     fRunHeader->SetNumEvents(fRunHeader->GetNumEvents()+1);
Index: trunk/MagicSoft/Mars/msimcamera/MSimReadout.h
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimReadout.h	(revision 9307)
+++ trunk/MagicSoft/Mars/msimcamera/MSimReadout.h	(revision 9308)
@@ -10,4 +10,5 @@
 class MRawEvtData;
 class MRawRunHeader;
+class MRawEvtHeader;
 class MAnalogChannels;
 
@@ -16,4 +17,5 @@
 private:
     MRawRunHeader    *fRunHeader;  //! Digitization window and frequency
+    MRawEvtHeader    *fEvtHeader;  //! Event header which is filled with the event number
     MAnalogChannels  *fCamera;     //! Analog channes to be read out
     MParameterD      *fPulsePos;   //! Intended pulse position
Index: trunk/MagicSoft/Mars/msimcamera/MSimTrigger.cc
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimTrigger.cc	(revision 9307)
+++ trunk/MagicSoft/Mars/msimcamera/MSimTrigger.cc	(revision 9308)
@@ -36,7 +36,18 @@
 // is calculated using a threshold and optional a fixed digital signal length.
 //
+// The signal length of the digital signal emitted by the discriminator
+// can either be bound to the time the signal is above the threshold
+// defined by fDiscriminatorThreshold if fDigitalSignalLength<0 or set to a
+// fixed length (fDigitalSignalLength>0).
+//
 // With a second look-up table fCoincidenceMap the analog channels are
-// checked for coincidences. The earliest coincide is then stored as
+// checked for coincidences. The coincidense must at least be of the length
+// defined by fCoincidenceTime. The earliest coincide is then stored as
 // trigger position.
+//
+//
+// For MAGIC1:
+//  - fDigitalSignalLength between 6ns and 12ns
+//  - fCoincidenceTime between 0.25ns to 1ns
 //
 //
@@ -69,4 +80,6 @@
 #include "MDigitalSignal.h"
 
+#include "MTriggerPattern.h"
+
 ClassImp(MSimTrigger);
 
@@ -79,5 +92,5 @@
 MSimTrigger::MSimTrigger(const char *name, const char *title)
     : fCamera(0), fPulsePos(0), fTrigger(0), fRunHeader(0), fEvtHeader(0),
-    fDiscriminatorThreshold(-1)
+    fDiscriminatorThreshold(-1), fDigitalSignalLength(8), fCoincidenceTime(0.5)
 {
     fName  = name  ? name  : "MSimTrigger";
@@ -189,8 +202,4 @@
     fTrigger->SetVal(-1);
 
-    // FIXME: Set from somewhere else? (see also MSimCalibrationSignal)
-    fEvtHeader->SetDAQEvtNumber(GetNumExecutions());
-    fEvtHeader->SetReadyToSave();
-
     // ================== Simulate channel bundling ====================
 
@@ -204,4 +213,5 @@
         for (UInt_t j=0; j<row.GetSize(); j++)
         {
+            // FIXME: Simulate clipping
             const UInt_t idx = row[j];
             patches[i].AddSignal((*fCamera)[idx]);
@@ -216,9 +226,6 @@
     ttls.SetOwner();
 
-        // MAGIC: Constant length of signals between 6ns and 12ns
-    const Double_t siglen = 8; // Signal length (-1: As long as Signal-above-Threshold)
-
     for (UInt_t i=0; i<npatch; i++)
-        ttls.AddAt(patches[i].Discriminate(fDiscriminatorThreshold, siglen), i);
+        ttls.AddAt(patches[i].Discriminate(fDiscriminatorThreshold, fDigitalSignalLength), i);
 
     // FIXME: Write TTLs!
@@ -235,7 +242,4 @@
     const Float_t max = fCamera->GetValidRangeMax()-(nsamp-pulspos);
 
-    // Define gate time (minimum coincidence time)
-    const Double_t gate = 1; // MAGIC: minimum coincidence time 0.25ns to 1ns,
-
     // Create an array for the individual triggers
     TObjArray triggers;
@@ -258,5 +262,5 @@
         {
             TObjArray *res = CalcCoincidence(*arr, *static_cast<TObjArray*>(ttls[idx[k]]),
-                                             gate);
+                                             fCoincidenceTime);
 
             // Delete the original array and keep the new one
@@ -303,5 +307,5 @@
     {
         if (rmlo>0 || rmhi>0)
-            *fLog << all << rmlo << "/" << rmhi << " trigger out of valid range. No trigger raised." << endl;
+            *fLog << inf2 << rmlo << "/" << rmhi << " trigger out of valid range. No trigger raised." << endl;
         return kTRUE;
     }
@@ -315,7 +319,12 @@
     // FIXME: Jitter! (Own class?)
     fTrigger->SetVal(static_cast<MDigitalSignal*>(triggers[0])->GetStart());
+    fTrigger->SetReadyToSave();
+
+    // Flag this event as triggered by the lvl1 trigger (FIXME?)
+    fEvtHeader->SetTriggerPattern((UInt_t)~(MTriggerPattern::kTriggerLvl1 | (MTriggerPattern::kTriggerLvl1<<8)));
+    fEvtHeader->SetReadyToSave();
 
     // inf2?
-    *fLog << all;
+    *fLog << inf;
     *fLog << cnt << " triggers left in " << triggers.GetEntriesFast() << " patches (" << rmlo << "/" << rmhi << " trigger out of valid range), T=" << fTrigger->GetVal();
     *fLog << endl;
@@ -329,4 +338,6 @@
 // FileNameCoincidenceMap:  coincidence.txt
 // DiscriminatorTheshold:   3.5
+// DigitalSignalLength:     8
+// CoincidenceTime:         0.5
 //
 Int_t MSimTrigger::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
@@ -351,4 +362,16 @@
     }
 
+    if (IsEnvDefined(env, prefix, "DigitalSignalLength", print))
+    {
+        rc = kTRUE;
+        fDigitalSignalLength = GetEnvValue(env, prefix, "DigitalSignalLength", fDigitalSignalLength);
+    }
+
+    if (IsEnvDefined(env, prefix, "CoincidenceTime", print))
+    {
+        rc = kTRUE;
+        fCoincidenceTime = GetEnvValue(env, prefix, "CoincidenceTime", fCoincidenceTime);
+    }
+
     return rc;
 }
Index: trunk/MagicSoft/Mars/msimcamera/MSimTrigger.h
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimTrigger.h	(revision 9307)
+++ trunk/MagicSoft/Mars/msimcamera/MSimTrigger.h	(revision 9308)
@@ -32,4 +32,6 @@
 
     Float_t fDiscriminatorThreshold;  // Discriminator threshold
+    Float_t fDigitalSignalLength;     // Length of the output of the discriminator
+    Float_t fCoincidenceTime;         // Minimum coincidence time (gate)
 
     // MSimTrigger
@@ -50,4 +52,6 @@
 
     void SetDiscriminatorThreshold(Float_t th) { fDiscriminatorThreshold=th; }
+    void SetDigitalSignalLength(Float_t ln) { fDigitalSignalLength=ln; }
+    void SetCoincidenceTime(Float_t tm) { fCoincidenceTime=tm; }
 
     ClassDef(MSimTrigger, 0) // Task to simulate trigger electronics
Index: trunk/MagicSoft/Mars/msimcamera/Makefile
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/Makefile	(revision 9307)
+++ trunk/MagicSoft/Mars/msimcamera/Makefile	(revision 9308)
@@ -20,5 +20,6 @@
 #
 INCLUDES = -I. -I../mbase -I../mgeom -I../msim -I../msignal -I../mcorsika \
-	   -I../mmc -I../mgui -I../mcalib -I../mraw -I../mfileio -I../melectronics
+	   -I../mmc -I../mgui -I../mcalib -I../mraw -I../mfileio -I../melectronics \
+	   -I../mtrigger
 
 SRCFILES = MSimPSF.cc \
