Index: fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C	(revision 15371)
+++ fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C	(revision 15372)
@@ -215,12 +215,13 @@
         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",
+        //TString     OutRootFileName     = "20120802_100mV_Stacking_G12B-2AWW8.root",
+        TString     OutRootFileName     = "new_dist_test.root",
         //---------------{Process parameters}---------------
-        int         nRuns               = -1,
+        int         nRuns               = 5,
         int         firstevent          = 1,        // Hast to be between 1 and infinity NOT 0!!!!
         int         nevents             = -1,
         int         firstpixel          = 0,
-        int         npixel              = -1,
-        int         pixelSetSize       = 150,
+        int         npixel              = 1,
+        int         pixelSetSize        = 150,
         int         maxPulseOrder       = 6,
         //---------------{stacking parameters}---------------
@@ -241,5 +242,5 @@
         float       risingEdgeMinSlope  = 0.5,
         //---------------{graphical options}---------------
-        bool            select_pulses   = false,
+        bool        select_pulses       = false,
         bool        ProduceGraphic      = false,
         bool        spikeDebug          = false,
@@ -258,7 +259,7 @@
 
     // Amplitude below which pulses will be discarted
-    float minPulseAmplitude     = 0.3*(GainMean-BSLMean);
+    float minPulseAmplitude     = 0.3*(GainMean)+BSLMean;
     // Amplitude above which pulses will be discarted
-    float maxPulseAmplitude     = 2*(GainMean-BSLMean)*maxPulseOrder;
+    float maxPulseAmplitude     = (maxPulseOrder+1)*(GainMean)+BSLMean;
     // pulses within this distance to timeline edge be discarted
     int   timeLineEdgeWidth     = 2;
@@ -298,5 +299,5 @@
     //fill vector of fits files to read
     cout << "generating file list:" << endl;
-    if(nRuns < fitsFileNames.size() && nRuns != -1)
+    if(nRuns < (int)fitsFileNames.size() && nRuns != -1)
     {
         fitsFileNames.resize(   nRuns);
@@ -729,40 +730,46 @@
                     // first Argument 1 means ... *rising* edge
                     // second Argument 1 means ... seagRCh with stepsize 1 ... 10 is okay as well
-                    vector<Region>* pZXings = zerosearch( gVcfd2 , 1 , 8);
+                    vector<Region>* pZXings = zerosearch( gVcfd2 , 1 , 8, verbosityLevel);
                     // pZXings means "zero cross ings"
 
-                    int init_reg_size = pZXings->size();
-                    int curr_reg_size = initial_region_size;
+                    float init_reg_size = pZXings->size();
+                    float curr_reg_size = init_reg_size;
                     int step = 0;
-                    pixel[pixelID]->hDiscartedPulses->Fill(step, init_reg_size - curr_reg_size);
+
+                    pixel[pixelID]->hDiscartedPulses->Fill(step, 1 - curr_reg_size/init_reg_size);
 
                     //enlare the search window
                     curr_reg_size = EnlargeRegion(*pZXings, 10, 10);
-                    pixel[pixelID]->hDiscartedPulses->Fill(step++, init_reg_size - curr_reg_size);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, 1 - curr_reg_size/init_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);
-
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, 1 - curr_reg_size/init_reg_size);
+
+//                    curr_reg_size = calcCFDPositions(*pZXings, gVcfd2);
+//                    pixel[pixelID]->hDiscartedPulses->Fill(step++, 1 - curr_reg_size/init_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--)
+                        //float minimum = 0.0;
+                        for (int sl = reg_it->maxPos; sl < 1; sl--)
                         {
                             if (gVcfd2[sl] > 0 && gVcfd2[sl-2] <= 0 && gVcfd2[sl-4] < 0)
                             {
-                                minimum = gVcfd2[sl-2];
+                                //minimum = gVcfd2[sl-2];
                                 break;
                             }
                         }
-
                         pixel[pixelID]->hAfterPulses->Fill(
                                     reg_it->maxPos - first_pos,
-                                    reg_it->maxVal - minimum
+                                    reg_it->maxVal// - minimum
                                     );
+                        reg_it++;
                     }
                     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -770,26 +777,10 @@
                     // 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);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, 1 - curr_reg_size/init_reg_size);
 
                     // Calculate the position (sample) of a pulses half maximum
                     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;
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++,  1 - curr_reg_size/init_reg_size);
+
 
                     // Fill arrival times into histograms
@@ -800,9 +791,30 @@
                         pixel[pixelID]->hEdgePos->Fill(     it->halfRisingEdgePos);
                         pixel[pixelID]->hEdgeSlope->Fill(   it->slopeOfRisingEdge);
+                        pixel[pixelID]->hMaxEdgeSlope->Fill(   it->maxSlope);
                         pixel[pixelID]->hIntercept->Fill(   it->interceptRisingEdge);
-                        pixel[pixelID]->hEdgeLength->Fill(  it->lengthOfRisingEdge);
+                        pixel[pixelID]->hEdgeLength->Fill(  it->distanceEdgeToMax);
                         pixel[pixelID]->hMaxAmpl->Fill(     it->maxVal);
                         ++it;
                     }
+
+                    // remove pulses at the pipeline fringes
+                    curr_reg_size = removeRegionWithMaxOnEdge( *pZXings, timeLineEdgeWidth);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, 1 - curr_reg_size/init_reg_size);
+
+                    //sometimes pulses where found with a very flat slope, DISCARD them
+                    curr_reg_size = removeRegionWithToFlatSlope(*pZXings, risingEdgeMinSlope);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, 1 - curr_reg_size/init_reg_size);
+                    if (verbosityLevel > 2) cout << "...done" << endl;
+
+                    // remove peaks above that are larger tha the largest amplitude to be studied
+                    curr_reg_size = removeMaximaAbove( *pZXings, maxPulseAmplitude);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, 1 - curr_reg_size/init_reg_size);
+
+
+                    // remove "Afterpulses" from pulse list
+                    curr_reg_size = removeRegionOnFallingEdge( *pZXings, FallingEdgeWidth);
+                    pixel[pixelID]->hDiscartedPulses->Fill(step++, 1 - curr_reg_size/init_reg_size);
+
+
 
     //-----------------------------------------------------------------------------
@@ -1237,4 +1249,5 @@
                 if (pos > reg->maxPos + 1)
                 {
+                    last_pos = pos;
                     // check if the current slice is close to the end of the overlay window
                     if ( pos+5 >= Right )
