Index: trunk/MagicSoft/Mars/msimcamera/MSimCalibrationSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimCalibrationSignal.cc	(revision 9305)
+++ trunk/MagicSoft/Mars/msimcamera/MSimCalibrationSignal.cc	(revision 9306)
@@ -61,4 +61,6 @@
 
 #include "MGeomCam.h"
+#include "MPulseShape.h"
+#include "MTriggerPattern.h"
 
 #include "MRawRunHeader.h"
@@ -77,6 +79,7 @@
 //
 MSimCalibrationSignal::MSimCalibrationSignal(const char* name, const char *title)
-    : fParList(0), fGeom(0), fPulsePos(0), fTrigger(0), fRunHeader(0), fEvtHeader(0),
-    fEvt(0), fStat(0),  fNumEntries(1000)
+    : fParList(0), fGeom(0), fPulse(0), fPulsePos(0), fTrigger(0),
+    fRunHeader(0), fEvtHeader(0),  fEvt(0), fStat(0),
+    fNumEvents(1000), fNumPhotons(5), fTimeJitter(1)
 {
     fName  = name  ? name  : "MRead";//"MSimCalibrationSignal";
@@ -130,4 +133,13 @@
     }
 
+    fPulse = (MPulseShape*)pList->FindObject("MPulseShape");
+    if (!fPulse)
+    {
+        *fLog << err << "MPulsShape not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    *fLog << all << "Number of Events: " << fNumEvents << endl;
+
     //
     // Search for MTaskList
@@ -167,5 +179,5 @@
 Int_t MSimCalibrationSignal::Process()
 {
-    if (GetNumExecutions()>fNumEntries)
+    if (GetNumExecutions()>fNumEvents)
         return kFALSE;
 
@@ -178,10 +190,11 @@
         for (UInt_t idx=0; idx<fGeom->GetNumPixels(); idx++)
         {
-            // FIXME: Where to get this number from?
-            for (int i=0; i<5; i++)
+            // FIXME: How does the distribution look like? Poissonian?
+            for (UInt_t i=0; i<fNumPhotons; i++)
             {
                 MPhotonData &ph = fEvt->Add(cnt++);
 
-                const Float_t tm = gRandom->Gaus(0, 1);
+                // FIMXE: Is this the correct distribution
+                const Float_t tm = gRandom->Gaus(0, fTimeJitter);
 
                 ph.SetPrimary(MMcEvtBasic::kArtificial);
@@ -201,12 +214,16 @@
     const Double_t freq = fRunHeader->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 = fRunHeader->GetNumSamplesHiGain()+1;
+
     // Length (ns), Pulse position (Units ns)
-    const Float_t ns = fRunHeader->GetNumSamplesHiGain()*freq;
     const Float_t pp = fPulsePos->GetVal();
+    const Float_t pw = fPulse->GetPulseWidth();
 
     const Float_t first = cnt>0 ? fEvt->GetFirst()->GetTime() : 0;
-    const Float_t last  = cnt>0 ? fEvt->GetLast()->GetTime()  : ns;
-
-    fStat->SetTime(first-pp, last+(ns-pp));
+    const Float_t last  = cnt>0 ? fEvt->GetLast()->GetTime()  : ns*freq;
+
+    fStat->SetTime(first-pp-pw, last-pp+pw + ns*freq);
     fStat->SetMaxIndex(fGeom->GetNumPixels()-1);
     fStat->SetReadyToSave();
@@ -214,10 +231,43 @@
     // FIXME: Jitter! (Own class?)
     fTrigger->SetVal(pp*freq);
-
-    // FIXME: Set from somewhere else? (see also MSimTrigger)
-    fEvtHeader->SetDAQEvtNumber(GetNumExecutions());
+    fTrigger->SetReadyToSave();
+
+    // Set trigger pattern according to the trigger type
+    const UInt_t p = fRunHeader->IsCalibrationRun() ? MTriggerPattern::kCalibration : MTriggerPattern::kPedestal;
+    fEvtHeader->SetTriggerPattern(~(p | (p<<8)));
     fEvtHeader->SetReadyToSave();
 
     return kTRUE;
-
-}
+}
+
+// --------------------------------------------------------------------------
+//
+// Read the parameters from the resource file.
+//
+//    NumEvents:   1000
+//    NumPhotons:     5
+//    TimeJitter:     1
+//
+Int_t MSimCalibrationSignal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "NumEvents", print))
+    {
+        rc = kTRUE;
+        fNumEvents = GetEnvValue(env, prefix, "NumEvents", (Int_t)fNumEvents);
+    }
+
+    if (IsEnvDefined(env, prefix, "NumPhotons", print))
+    {
+        rc = kTRUE;
+        fNumPhotons = GetEnvValue(env, prefix, "NumPhotons", (Int_t)fNumPhotons);
+    }
+
+    if (IsEnvDefined(env, prefix, "TimeJitter", print))
+    {
+        rc = kTRUE;
+        fTimeJitter = GetEnvValue(env, prefix, "TimeJitter", fTimeJitter);
+    }
+
+    return rc;
+}
Index: trunk/MagicSoft/Mars/msimcamera/MSimCalibrationSignal.h
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimCalibrationSignal.h	(revision 9305)
+++ trunk/MagicSoft/Mars/msimcamera/MSimCalibrationSignal.h	(revision 9306)
@@ -8,4 +8,5 @@
 class MGeomCam;
 class MParList;
+class MPulseShape;
 class MPhotonEvent;
 class MPhotonStatistics;
@@ -19,9 +20,10 @@
     MParList          *fParList;    //! Store pointer to MParList for initializing ReInit
     MGeomCam          *fGeom;       //! Camera geometry to know the number of expected pixels
+    MPulseShape       *fPulse;      //! Pulse Shape to get pulse width from
     MParameterD       *fPulsePos;   //! Expected position at which the pulse should be
     MParameterD       *fTrigger;    //! Position in analog channels at which the triggersignal  is raised
     MRawRunHeader     *fRunHeader;  //! Digitization window and frequency
 
-    MRawEvtHeader     *fEvtHeader;  //! Event header which is filled
+    MRawEvtHeader     *fEvtHeader;  //! Event header which is filled by the trigger pattern
     MPhotonEvent      *fEvt;        //! Photon event into which the new photons are stored
     MPhotonStatistics *fStat;       //! Photon statistic which is filled
@@ -29,5 +31,10 @@
     TString fNameGeomCam;           // Name of the camera geometry
 
-    UInt_t fNumEntries;             // Number of events to produce
+    UInt_t  fNumEvents;             // Number of events to produce
+    UInt_t  fNumPhotons;            // Average number of photons to produce
+    Float_t fTimeJitter;            // Time jitter (sigma)
+
+    // MParContainer
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
 
     // MTask
@@ -44,5 +51,5 @@
     void SetNameGeomCam(const char *name="MGeomCam") { fNameGeomCam = name; }
 
-    UInt_t  GetEntries() { return fNumEntries; }
+    UInt_t  GetEntries() { return fNumEvents; }
     TString GetFullFileName() const { return "cer000000"; }
     //virtual Bool_t  Rewind();
