Index: fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C	(revision 14940)
+++ fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C	(revision 14941)
@@ -211,26 +211,34 @@
 //----------------------------------------------------------------------------
 int FPulseOverlay_filelist(
+        //---------------{Process Files}---------------
         TString     inputPath           = "raw/2012/08/02/",
-        TString     sequenzFileName = "/home_nfs/isdc/jbbuss/analysis/pulseShape/lists/20120802templ_vs_0mV.csv",
-//        int         firstRunId          = 18,
+        TString     sequenzFileName     = "/home_nfs/isdc/jbbuss/analysis/pulseShape/lists/20120802templ_vs_100mV.csv",
+        TString     OutputPath          = "analysis/PulsTemplateAnalysis/20120802/",
+        TString     OutRootFileName     = "20120802_100mV_Stacking_G12B-2AWW8.root",
+        //---------------{Process parameters}---------------
         int         nRuns               = -1,
-//        TString     drsfilename         = "20120309_012.drs.fits.gz",
-        TString     OutputPath          = "analysis/pulseShape/",
-        TString     OutRootFileName     = "20120802_0mV_newSelectAlg.root",
         int         firstevent          = 1,        // Hast to be between 1 and infinity NOT 0!!!!
         int         nevents             = -1,
         int         firstpixel          = 0,
-        int         npixel              = 1,
+        int         npixel              = -1,
         int         pixelSetSize       = 150,
         int         maxPulseOrder       = 6,
-        int         verbosityLevel      = 0,        // different verbosity levels can be implemented here
+        //---------------{stacking parameters}---------------
         TString     histoOptions        = "SRM",
-        int         AmplWindowWidth     = 7,       //Width of Window for selection of pulses to histograms
-        float       GainMean            = 11,
+        int         AmplWindowWidth     = 8,       //Width of Window for selection of pulses to histograms
+        float       GainMean            = 12,
         float       BSLMean             = -2,        //4 Histogramms will be drawn, decide how far pulsehights differ from eachother
         int         avg1                = 8,
         int         avg2                = 8,
-        int         OverlayWindowLeft   = 1024,
+        int         OverlayWindowLeft   = 100,
         int         OverlayWindowRight  = 1024,
+
+        // pulses within this distance behind pulse max will be discarted
+        int         beginRisingEdge     = 5,
+        int         endRisingEdge       = 10,
+
+        // pulses within this distance behind pulse max will be discarted
+        float       risingEdgeMinSlope  = 0.5,
+        //---------------{graphical options}---------------
         bool            select_pulses   = false,
         bool        ProduceGraphic      = false,
@@ -240,5 +248,7 @@
         bool        saveResults         = true,
         bool        testmode            = false,
-        int         refresh_rate        = 500      //refresh rate for canvases
+        //---------------{verbosity}---------------
+        int         refresh_rate        = 500,      //refresh rate for canvases
+        int         verbosityLevel      = 0        // different verbosity levels can be implemented here
         )
 {
@@ -247,11 +257,13 @@
 //-----------------------------------------------------------------------------
 
+    // Amplitude below which pulses will be discarted
     float minPulseAmplitude     = 0.3*(GainMean-BSLMean);
+    // Amplitude above which pulses will be discarted
     float maxPulseAmplitude     = 2*(GainMean-BSLMean)*maxPulseOrder;
+    // pulses within this distance to timeline edge be discarted
     int   timeLineEdgeWidth     = 2;
+    // pulses within this distance behind pulse max will be discarted
     int   FallingEdgeWidth      = 200;
-    int   beginRisingEdge       = 5;
-    int   endRisingEdge         = 10;
-    float   risingEdgeMinSlope    = 0.5;
+
 
 //-----------------------------------------------------------------------------
@@ -896,5 +908,5 @@
 //-------------------------------------
     TString test = "root";
-    SaveHistograms(     //save histograms of generell results into output root file
+    SaveList(     //save histograms of generell results into output root file
                 OutRootFileName,
                 test,
@@ -1123,7 +1135,31 @@
             }
 
+            float average_of_max = gVcorr[reg->maxPos];
+            average_of_max += gVcorr[reg->maxPos + 1];
+            average_of_max += gVcorr[reg->maxPos - 1];
+            average_of_max /= 3;
+
+            float slope_of_follow = 0.0;
+
             //Histograms for Maximum Overlay
             for ( int pos = Left; pos < Right; pos++)
             {
+                if (pos > reg->maxPos + 2)
+                {
+                    if ( pos+5 >= Right )
+                    {
+                        break;
+                    }
+                    if (gVcorr[pos+1] > average_of_max)
+                    {
+                        break;
+                    }
+                    slope_of_follow = (gVcorr[pos+5] - gVcorr[pos+1])/5;
+
+                    if (slope_of_follow > 1)
+                    {
+                        break;
+                    }
+                }
                 CurrentPixel->hMaxOverlay[order_of_pulse]->Fill( pos - (reg->maxPos), gVcorr[pos]) ;
                 CurrentPixel->hMaxProfile[order_of_pulse]->Fill( pos - (reg->maxPos), gVcorr[pos]) ;
@@ -1132,4 +1168,29 @@
             for ( int pos = EdgeLeft; pos < EdgeRight; pos++)
             {
+                if (pos > reg->maxPos + 2)
+                {
+                    if ( pos+5 >= Right )
+                    {
+                        break;
+                    }
+                    if (gVcorr[pos+1] > average_of_max)
+                    {
+                        break;
+                    }
+                    slope_of_follow = (gVcorr[pos+5] - gVcorr[pos+1])/5;
+
+                    if (slope_of_follow > 1)
+                    {
+                        break;
+                    }
+                }
+//                if (pos > reg->maxPos
+//                        && gVcorr[pos] < average_of_max
+//                        && gVcorr[pos+3] > average_of_max
+//                        && gVcorr[pos+10] > average_of_max
+//                        )
+//                {
+//                    break;
+//                }
                 CurrentPixel->hEdgeOverlay[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gVcorr[pos]) ;
                 CurrentPixel->hEdgeProfile[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gVcorr[pos]) ;
