Index: /trunk/Mars/mbase/MArrayF.h
===================================================================
--- /trunk/Mars/mbase/MArrayF.h	(revision 17681)
+++ /trunk/Mars/mbase/MArrayF.h	(revision 17682)
@@ -170,5 +170,53 @@
 
     template<class T>
-        void Add(T *src, Int_t n, Int_t p=0)
+    void Add(T *src, Int_t n, Int_t p=0, Float_t m=1.)
+    {
+        // under these 3 conditions, we return immediately, because they either make no sense,
+        // or result in an invariant array.
+        if (p >= fN)
+        {
+            // maybe throw a warning, because p >= fN makes no sense at all
+            return;
+        }
+        if ( n <= 0)
+        {
+            return;
+        }
+        if (m == 0.)
+        {
+            return;
+        }
+        if (src == NULL)
+        {
+            return;
+        }
+
+        Float_t *dest = fArray + p;
+        Float_t *end  = dest;
+        if (n < fN-p)
+        {
+            end += n;
+        }
+        else
+        {
+            end += fN-p;
+        }
+
+        // we treat the case m==1. special, in order to speed up the code a bit
+        // since when m==1. the multiplication can be omitted and this should be a bit faster then.
+        if (m == 1.)
+        {
+            while (dest<end)
+                *dest++ += *src++;
+        }
+        else
+        {
+            while (dest<end)
+                *dest++ += (*src++) * m;
+        }
+    }
+
+    template<class T>
+        void AddClipped(Double_t th, T src, Int_t n, Int_t p=0)
     {
         Float_t *dest = fArray + p;
@@ -176,14 +224,4 @@
 
         while (dest<end)
-            *dest++ += *src++;
-    }
-
-    template<class T>
-        void AddClipped(Double_t th, T src, Int_t n, Int_t p=0)
-    {
-        Float_t *dest = fArray + p;
-        Float_t *end  = dest   + n;
-
-        while (dest<end)
             *dest++ += TMath::Min(*src++, th);
     }
Index: /trunk/Mars/melectronics/MAnalogSignal.cc
===================================================================
--- /trunk/Mars/melectronics/MAnalogSignal.cc	(revision 17681)
+++ /trunk/Mars/melectronics/MAnalogSignal.cc	(revision 17682)
@@ -153,8 +153,10 @@
 // Add a second analog signal. Just by addining it bin by bin.
 //
-void MAnalogSignal::AddSignal(const MAnalogSignal &s)
-{
-    Add(s.GetArray(), s.fN);
-}
+void MAnalogSignal::AddSignal(const MAnalogSignal &s, Int_t delay,
+                              Float_t dampingFactor )
+{
+    Add(s.GetArray(), s.fN, delay, dampingFactor);
+}
+
 
 // Deprecated. Use MSimRandomPhotons instead
Index: /trunk/Mars/melectronics/MAnalogSignal.h
===================================================================
--- /trunk/Mars/melectronics/MAnalogSignal.h	(revision 17681)
+++ /trunk/Mars/melectronics/MAnalogSignal.h	(revision 17682)
@@ -21,5 +21,5 @@
     Bool_t AddPulse(const MSpline3 &spline, Float_t t, Float_t f=1);
     Bool_t AddPulse(const TF1 &f1, Float_t t, Float_t f=1);
-    void   AddSignal(const MAnalogSignal &s);
+    void   AddSignal(const MAnalogSignal &s, Int_t delay=0,Float_t dampingFact=1.0);
 
     // Deprecated. Use MSimRandomPhotons instead
Index: /trunk/Mars/msimcamera/MSimTrigger.cc
===================================================================
--- /trunk/Mars/msimcamera/MSimTrigger.cc	(revision 17681)
+++ /trunk/Mars/msimcamera/MSimTrigger.cc	(revision 17682)
@@ -97,9 +97,22 @@
 //
 MSimTrigger::MSimTrigger(const char *name, const char *title)
-    : fCamera(0), fPulsePos(0), fTrigger(0), fRunHeader(0),
-    fEvtHeader(0), fElectronicNoise(0), fGain(0),
-    fDiscriminatorThreshold(-1), fDigitalSignalLength(8), fCoincidenceTime(0.5),
-    fShiftBaseline(kTRUE), fUngainSignal(kTRUE), fSimulateElectronics(kTRUE),
-    fMinMultiplicity(-1)
+    : fCamera(0),
+      fPulsePos(0),
+      fTrigger(0),
+      fRunHeader(0),
+      fEvtHeader(0),
+      fElectronicNoise(0),
+      fGain(0),
+      fDiscriminatorThreshold(-1),
+      fDigitalSignalLength(8),
+      fCoincidenceTime(0.5),
+      fShiftBaseline(kTRUE),
+      fUngainSignal(kTRUE),
+      fSimulateElectronics(kTRUE),
+      fMinMultiplicity(-1),
+      fCableDelay(21),
+      fCableDamping(0.)     // default Damping Set to zero, so users, who do not set
+                            // the CableDamoing in the ceres.rc do not see a difference.
+
 {
     fName  = name  ? name  : "MSimTrigger";
@@ -385,4 +398,16 @@
     *fLog << "Using discriminator threshold of " << fDiscriminatorThreshold << endl;
 
+    *fLog << "Using fCableDelay " << fCableDelay << endl;
+    *fLog << "Using fCableDamping " << fCableDamping << endl;
+
+    ////////////////////////////////
+    // open some output files for debugging
+//    patch_file.open("/home/fact_opr/patch_file.csv", ios_base::out);
+//    clipped_file.open("/home/fact_opr/clipped_file.csv", ios_base::out);
+//    digital_file.open("/home/fact_opr/digital_file.csv", ios_base::out);
+//    ratescan_file.open("/home/fact_opr/ratescan_file.csv", ios_base::out);
+
+
+
     return kTRUE;
 }
@@ -497,4 +522,5 @@
     // summed overwrite with a newly allocated set of analog channels
     MAnalogChannels *patches = fCamera;
+    MAnalogChannels *raw_patches = fCamera;
     if (!empty)
     {
@@ -502,18 +528,55 @@
 
         patches = new MAnalogChannels(npatch, fCamera->GetNumSamples());
-        for (UInt_t i=0; i<npatch; i++)
-        {
-            const MArrayI &row = fRouteAC.GetRow(i);
-            for (UInt_t j=0; j<row.GetSize(); j++)
+        raw_patches = new MAnalogChannels(npatch, fCamera->GetNumSamples());
+        for (UInt_t patch_id=0; patch_id<npatch; patch_id++)
+        {
+            const MArrayI &row = fRouteAC.GetRow(patch_id);
+            for (UInt_t pxl_in_patch=0; pxl_in_patch<row.GetSize(); pxl_in_patch++)
             {
-                const UInt_t idx = row[j];
+                const UInt_t pixel_id = row[pxl_in_patch];
 
                 // FIXME: Shrinking the mapping table earlier (e.g.
                 //        ReInit) would avoid a lot of if's
-                if (idx<fCamera->GetNumChannels())
-                    (*patches)[i].AddSignal((*fCamera)[idx]);
+                if (pixel_id<fCamera->GetNumChannels())
+                {
+                    (*raw_patches)[patch_id].AddSignal((*fCamera)[pixel_id]);
+                    (*patches)[patch_id].AddSignal((*fCamera)[pixel_id]);
+                    (*patches)[patch_id].AddSignal((*fCamera)[pixel_id], fCableDelay, fCableDamping);
+                }
             }
         }
     }
+
+    // DN: 20140219 Ratescan:
+    //
+    //
+//    for (UInt_t patch_id=0; patch_id<npatch; patch_id++)
+//    {
+//        MAnalogSignal current_patch = (*raw_patches)[patch_id];
+//        float max = current_patch[0];
+//        for (UInt_t i=1; i<current_patch.GetSize(); i++)
+//        {
+//            if (current_patch[i] > max)
+//            {
+//                max = current_patch[i];
+//            }
+//        }
+//        ratescan_file << max << " ";
+//    }
+//    ratescan_file << endl;
+
+//    // DN 20131108: DEBUGGING:
+//    for (UInt_t patch_id=0; patch_id<npatch; patch_id++)
+//    {
+//        for (UInt_t slice=0; slice<fCamera->GetNumSamples(); slice++)
+//        {
+//            patch_file << (*raw_patches)[patch_id][slice] << "\t";
+//            clipped_file << (*patches)[patch_id][slice] << "\t";
+//        }
+//        patch_file << endl;
+//        clipped_file << endl;
+//    }
+
+
 
     // FIXME: Write patches
@@ -529,5 +592,14 @@
         const Double_t offset = fElectronicNoise ? (*fElectronicNoise)[i].GetPedestal() : 0;
         const Double_t gain   = fGain            ? (*fGain)[i].GetPedestal()            : 1;
-        ttls.AddAt((*patches)[i].Discriminate(fDiscriminatorThreshold*gain+offset, fDigitalSignalLength), i);
+        ttls.AddAt(
+                    (*patches)[i].Discriminate(
+                        fDiscriminatorThreshold*gain+offset,                // treshold
+                        Double_t(fCableDelay),                              // start
+                        Double_t(fCamera->GetNumSamples() - fCableDelay),   // end
+                        //fDigitalSignalLength                              // time-over-threshold, or fixed-length?
+                        -1                                                  // -1 = time-over-threshold
+                        ),
+                    i
+                    );
     }
 
@@ -537,4 +609,6 @@
     if (patches!=fCamera)
         delete patches;
+    if (raw_patches!=fCamera)
+        delete raw_patches;
 
     // =================== Simulate coincidences ======================
@@ -557,4 +631,12 @@
     Int_t rmlo = 0;
     Int_t rmhi = 0;
+
+//    cout << "MSimTrigger::fMinMultiplicity = " << fMinMultiplicity << endl;
+//    cout << "MSimTrigger::fCoincidenceTime = " << fCoincidenceTime << endl;
+//    cout << "fCoincidenceMap.GetEntries() = " << fCoincidenceMap.GetEntries() << endl;
+//    cout << "MSimTrigger::fCableDelay = " << fCableDelay << endl;
+//    cout << "MSimTrigger::fCableDamping = " << fCableDamping << endl;
+//    cout << "min:" << min << endl;
+//    cout << "max:" << max << endl;
 
     for (int j=0; j<fCoincidenceMap.GetEntries(); j++)
@@ -624,4 +706,15 @@
         arr->Compress();
 
+//        cout << "ttls(j=" << j << "):";
+//        TObjArray *arr2 = static_cast<TObjArray*>(ttls[j]);
+//        TIter Nexty(arr);
+//        MDigitalSignal *ttly = 0;
+//        while ((ttly=static_cast<MDigitalSignal*>(Nexty())))
+//        {
+//            cout << "|"<< ttly->GetStart() << ", " << ttly->GetLength();
+//        }
+//        cout << endl;
+
+
         // If we have at least one trigger keep the earliest one.
         // FIXME: The triggers might be ordered in time automatically:
@@ -674,4 +767,14 @@
 }
 
+Int_t MSimTrigger::PostProcess()
+{
+//    patch_file.close();
+//    clipped_file.close();
+//    digital_file.close();
+//    ratescan_file.close();
+    return kTRUE;
+}
+
+
 // --------------------------------------------------------------------------
 //
@@ -728,4 +831,18 @@
     }
 
+    if (IsEnvDefined(env, prefix, "CableDelay", print))
+    {
+        rc = kTRUE;
+        fCableDelay = GetEnvValue(env, prefix, "CableDelay", fCableDelay);
+    }
+
+    if (IsEnvDefined(env, prefix, "CableDamping", print))
+    {
+        rc = kTRUE;
+        fCableDamping = GetEnvValue(env, prefix, "CableDamping", fCableDamping);
+    }
+
+
+
     return rc;
 }
Index: /trunk/Mars/msimcamera/MSimTrigger.h
===================================================================
--- /trunk/Mars/msimcamera/MSimTrigger.h	(revision 17681)
+++ /trunk/Mars/msimcamera/MSimTrigger.h	(revision 17682)
@@ -9,4 +9,6 @@
 #include "MLut.h"
 #endif
+
+#include <fstream>
 
 class MParList;
@@ -36,5 +38,5 @@
     Float_t fDiscriminatorThreshold;    // Discriminator threshold
     Float_t fDigitalSignalLength;       // Length of the output of the discriminator
-    Float_t fCoincidenceTime;           // Minimum coincidence time (gate)
+    Float_t fCoincidenceTime;           // Minimum coincidence time (gate) [slices]
 
     Bool_t  fShiftBaseline;             // Shift the baseline back to 0 for the threshold (needs ElectronicNoise [MPedestalCam])
@@ -43,4 +45,17 @@
 
     Int_t   fMinMultiplicity;           // N out of M
+
+    Int_t   fCableDelay;                // signal runtime on the clipping cable in slices, e.g. 105cm cable = 2*105cm
+                                        // (20cm/ns) = 10.5ns = 21slices @ 2GHz [slices]
+
+    Float_t fCableDamping;              // the signal is damped a bit when reflecting at the end of the cable and is inverted as well.
+                                        // Damping factor in [-1..0]. In short tests by Kai Schennetten it looked like -0.96.
+
+    // debugging
+    std::ofstream patch_file;
+    std::ofstream clipped_file;
+    std::ofstream digital_file;
+    std::ofstream ratescan_file;
+
 
     // MSimTrigger
@@ -53,4 +68,5 @@
     Int_t PreProcess(MParList *pList);
     Int_t Process();
+    Int_t PostProcess();
 
     // MParContainer
