Index: trunk/Mars/msimcamera/MSimTrigger.cc
===================================================================
--- trunk/Mars/msimcamera/MSimTrigger.cc	(revision 19664)
+++ trunk/Mars/msimcamera/MSimTrigger.cc	(revision 19665)
@@ -492,7 +492,25 @@
     const Double_t freq    = fRunHeader->GetFreqSampling()/1000.;
     const Float_t  nsamp   = fRunHeader->GetNumSamplesHiGain();
-    const Float_t  pulspos = fPulsePos->GetVal()/freq;
-
-    // Valid range in units of bins
+
+    // The trigger position in the readout window
+    // FIXME:  This currently corresponds to the start of the spline!
+    const Float_t  pulspos = fPulsePos->GetVal()*freq;
+
+    // Valid range in units of bins for the trigger
+    //
+    // GetValidRangeMin/Max contains the earliest and latest
+    // reasonable sample. The earliest is determined by the
+    // the fact that at least a full pulse must fit in front.
+    // The latest ends with the full sampling range.
+    //
+    // As the first trigger can only be initiated by the first
+    // photon from the shower, the valid range for triggers
+    // starts the pulsewidth before the trigger position,
+    // i.e. ValidRangeMin+triggerposition
+    //
+    // If the last photon triggers, then there must at least
+    // be sampling window minus trigger position samples left.
+    // Therefore, the last trigger must be at
+    // ValidRangeMax-(window-triggerpositon)
     const Float_t min = fCamera->GetValidRangeMin()+pulspos;
     const Float_t max = fCamera->GetValidRangeMax()-(nsamp-pulspos);
@@ -588,4 +606,8 @@
         const Double_t offset = fElectronicNoise ? (*fElectronicNoise)[i].GetPedestal() : 0;
         const Double_t gain   = fGain            ? (*fGain)[i].GetPedestal()            : 1;
+        // FIXME: fCableDelay not taken into account when calculating the
+        // valid range, therefore, fCableDelay must be smaller than the pulse width
+        // FIXME: Start seraching at pulsepos is faster, but breaks things like
+        // ratescans triggering on noise events
         ttls.AddAt(
                     (*patches)[i].Discriminate(
@@ -736,5 +758,7 @@
     // FIXME: Store triggers! (+ Reversed pixels?)
 
-    SetTrigger(triggers.GetFirstTrigger(), triggers.GetFirstIndex());
+    // Shift the trigger such that the pulse position X=0 coincides with the
+    // the trigger position in the readout window
+    SetTrigger(triggers.GetFirstTrigger()/freq, triggers.GetFirstIndex());
 
     // No trigger issued. Go on.
@@ -749,9 +773,9 @@
     // Coincidence signals emitted. (If the total number is higher than
     // the number of triggers either some triggers had to be removed or
-    // or a patch has emitted more than one trigger signal)
+    // a patch has emitted more than one trigger signal)
     // FIXME: inf2?
     *fLog << inf << GetNumExecutions() << ": ";
     *fLog << setw(3) << triggers.GetNumSignals() << " triggers left out of ";
-    *fLog << setw(3) << cnt << " (" << rmlo << "/" << rmhi << " trigger out of valid range), T=" << fTrigger->GetVal();
+    *fLog << setw(3) << cnt << " (" << rmlo << "/" << rmhi << " trigger out of valid range), T=" << fTrigger->GetVal()-fCamera->GetValidRangeMin()/freq << "ns";
     *fLog << endl;
 
