Index: /fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C
===================================================================
--- /fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C	(revision 15120)
+++ /fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C	(revision 15121)
@@ -225,5 +225,5 @@
         int         maxPulseOrder       = 6,
         //---------------{stacking parameters}---------------
-        TString     histoOptions        = "SRM",
+        TString     histoOptions        = "SRMTILDAP",
         int         AmplWindowWidth     = 8,       //Width of Window for selection of pulses to histograms
         float       GainMean            = 12,
@@ -731,15 +731,78 @@
                     vector<Region>* pZXings = zerosearch( gVcfd2 , 1 , 8);
                     // pZXings means "zero cross ings"
-                    EnlargeRegion(*pZXings, 10, 10);
-                    findAbsMaxInRegions(*pZXings, gVslide);
-                    removeMaximaBelow( *pZXings, minPulseAmplitude);
-                    removeMaximaAbove( *pZXings, maxPulseAmplitude);
-                    removeRegionWithMaxOnEdge( *pZXings, timeLineEdgeWidth);
-                    removeRegionOnFallingEdge( *pZXings, FallingEdgeWidth);
+
+                    int init_reg_size = pZXings->size();
+                    int curr_reg_size = initial_region_size;
+                    int step = 0;
+                    pixel[pixelID]->hDiscartedPulses->Fill(step, init_reg_size - curr_reg_size);
+
+                    //enlare the search window
+                    curr_reg_size = EnlargeRegion(*pZXings, 10, 10);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, init_reg_size - curr_reg_size);
+
+                    // find the the max position of a peak
+                    curr_reg_size = findAbsMaxInRegions(*pZXings, gVslide);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, init_reg_size - curr_reg_size);
+
+                    //do a small after pulse analysis, fill in delayed pulses
+                    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++
+                    vector<Region>::iterator reg_it = pZXings->begin();
+                    int first_pos = pZXings->begin()->maxPos;
+                    while( reg_it != pZXings->end() )
+                    {
+                        float minimum = 0.0;
+                        for (int sl = reg_it->maxPos; sl < 1; i--)
+                        {
+                            if (gVcfd2[sl] > 0 && gVcfd2[sl-2] <= 0 && gVcfd2[sl-4] < 0)
+                            {
+                                minimum = gVcfd2[sl-2];
+                                break;
+                            }
+                        }
+
+                        pixel[pixelID]->hAfterPulses->Fill(
+                                    reg_it->maxPos - first_pos,
+                                    reg_it->maxVal - minimum
+                                    );
+                    }
+                    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+                    // remove peaks below 1 p.e.
+                    curr_reg_size = removeMaximaBelow( *pZXings, minPulseAmplitude);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, init_reg_size - curr_reg_size);
+
+                    // remove peaks above that are larger tha the largest amplitude to be studied
+                    curr_reg_size = removeMaximaAbove( *pZXings, maxPulseAmplitude);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, init_reg_size - curr_reg_size);
+
+                    // remove pulses at the pipeline fringes
+                    curr_reg_size = removeRegionWithMaxOnEdge( *pZXings, timeLineEdgeWidth);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, init_reg_size - curr_reg_size);
+
+                    // remove "Afterpulses" from pulse list
+                    curr_reg_size = removeRegionOnFallingEdge( *pZXings, FallingEdgeWidth);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, init_reg_size - curr_reg_size);
+
                     // Calculate the position (sample) of a pulses half maximum
-                    findTimeOfHalfMaxLeft(*pZXings, gVslide, gBSLMean, beginRisingEdge, endRisingEdge, verbosityLevel );
-                    //sometimes pulses where found with a very flat slope, DISMISS them
-                    removeRegionWithToFlatSlope(*pZXings, risingEdgeMinSlope);
+                    curr_reg_size = findTimeOfHalfMaxLeft(*pZXings, gVslide, gBSLMean, beginRisingEdge, endRisingEdge, verbosityLevel );
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, init_reg_size - curr_reg_size);
+
+                    //sometimes pulses where found with a very flat slope, DISCARD them
+                    curr_reg_size = removeRegionWithToFlatSlope(*pZXings, risingEdgeMinSlope);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, init_reg_size - curr_reg_size);
                     if (verbosityLevel > 2) cout << "...done" << endl;
+
+                    // Fill arrival times into histograms
+                    vector<Region>::iterator it = pZXings->begin();
+                    while( it != pZXings->end() )
+                    {
+                        pixel[pixelID]->hMaxPos->Fill(      it->maxPos);
+                        pixel[pixelID]->hEdgePos->Fill(     it->halfRisingEdgePos);
+                        pixel[pixelID]->hEdgeSlope->Fill(   it->slopeOfRisingEdge);
+                        pixel[pixelID]->hIntercept->Fill(   it->interceptRisingEdge);
+                        pixel[pixelID]->hEdgeLength->Fill(  it->lengthOfRisingEdge);
+                        pixel[pixelID]->hMaxAmpl->Fill(     it->maxVal);
+                        ++it;
+                    }
 
     //-----------------------------------------------------------------------------
@@ -1145,5 +1208,5 @@
             for ( int pos = Left; pos < Right; pos++)
             {
-                if (pos > reg->maxPos + 2)
+                if (pos > reg->maxPos + 1)
                 {
                     if ( pos+5 >= Right )
@@ -1156,5 +1219,4 @@
                     }
                     slope_of_follow = (gVcorr[pos+5] - gVcorr[pos+1])/5;
-
                     if (slope_of_follow > 1)
                     {
@@ -1165,12 +1227,18 @@
                 CurrentPixel->hMaxProfile[order_of_pulse]->Fill( pos - (reg->maxPos), gVcorr[pos]) ;
             }
+
             //Histograms for Edge Overlay
+            int last_pos = 0;
+            bool ap_cutoff = false;
+            slope_of_follow = 0.0;
+
             for ( int pos = EdgeLeft; pos < EdgeRight; pos++)
             {
-                if (pos > reg->maxPos + 2)
+                if (pos > reg->maxPos + 1)
                 {
                     // check if the current slice is close to the end of the overlay window
                     if ( pos+5 >= Right )
                     {
+                        ap_cutoff = false;
                         break;
                     }
@@ -1180,4 +1248,5 @@
                     if (gVcorr[pos+1] > average_of_max)
                     {
+                        ap_cutoff = true;
                         break;
                     }
@@ -1187,4 +1256,5 @@
                     if (slope_of_follow > 1)
                     {
+                        ap_cutoff = true;
                         break;
                     }
@@ -1200,4 +1270,14 @@
                 CurrentPixel->hEdgeOverlay[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gVcorr[pos]) ;
                 CurrentPixel->hEdgeProfile[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gVcorr[pos]) ;
+            }
+
+            CurrentPixel->hPulseLength->Fill(last_pos - (reg->halfRisingEdgePos));
+            if (ap_cutoff)
+            {
+                CurrentPixel->hPulseLengthAPcutoff->Fill(last_pos - (reg->halfRisingEdgePos));
+            }
+            else
+            {
+                CurrentPixel->hPulseLengthTLcutoff->Fill(last_pos - (reg->halfRisingEdgePos));
             }
 
