Index: fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C	(revision 13581)
+++ fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C	(revision 13595)
@@ -28,4 +28,5 @@
 #include <TString.h>
 #include <TObjArray.h>
+#include <TF1.h>
 
 #include <stdio.h>
@@ -468,4 +469,6 @@
                                 maxPulseOrder,
                                 verbosityLevel,
+                                false,
+                                NULL,
                                 gPixelOverlayXaxisLeft,
                                 gPixelOverlayXaxisRight,
@@ -534,4 +537,5 @@
                 removeRegionOnFallingEdge( *pZXings, 100);
                 findTimeOfHalfMaxLeft(*pZXings, Vcorr, gBSLMean, 5, 10, verbosityLevel );
+                removeRegionWithToFlatSlope(*pZXings, 0.5);
                 if (verbosityLevel > 2) cout << "...done" << endl;
 
@@ -577,5 +581,5 @@
 //                                )
 //                            {
-                                pixel[firstPixelOfSet]->DrawHistograms(
+                                pixel[firstPixelOfSet]->DrawOverlayHistograms(
                                             cgpPixelPulses,
                                             pulsesCanvasFrameNrs
@@ -634,5 +638,5 @@
             if (ProduceGraphic)
             {
-                pixel[pixelID]->DrawHistograms(
+                pixel[pixelID]->DrawOverlayHistograms(
                             cgpPixelPulses,
                             pulsesCanvasFrameNrs
@@ -1033,37 +1037,75 @@
     debugHistos[Ameas_].Draw();
 
+    TF1 *OneEdge;
+//    vector<TF1*> MyEdges;
+    int left    = debugHistos[Ameas_].GetXaxis()->GetFirst();
+    int right   = debugHistos[Ameas_].GetXaxis()->GetLast();
     vector<Region>::iterator reg;
-    for (reg = pZXings->begin() ; reg < pZXings->end() ; reg++){
+    for (reg = pZXings->begin() ; reg < pZXings->end() ; reg++)
+    {
         if (reg->slopeOfRisingEdge < 0)
         {
             has_negative_slope = true;
             cout << "Slope is: " << reg->slopeOfRisingEdge << endl;
+
+//            xBegin = (reg->halfRisingEdgePos - reg->distanceEdgeToMax);
+//            yBegin = reg->interceptRisingEdge + reg->slopeOfRisingEdge * (xBegin)
+
+            OneEdge = new TF1(
+                "OneEdge",
+                "[0]*x+[1]",
+                left,
+                right
+                );
+
+            OneEdge->SetParameters(
+                        reg->slopeOfRisingEdge,
+                        reg->interceptRisingEdge
+                        );
+
+            OneEdge->SetLineColor(kRed);
+            OneEdge->SetLineWidth(1);
+//            MyEdges.push_back(OneEdge);
+
+            OneEdge->Draw("SAME");
         }
-
-    }
-
-    cFiltered->cd(2);
-    gPad->SetGrid();
-    debugHistos[Vcorr_].Draw();
-
-    cFiltered->cd(3);
-    gPad->SetGrid();
-    debugHistos[Vslide_].Draw();
-
+    }
+
+    TLine *OneLine;
     TBox *OneBox;
-    vector<TBox*> MyBoxes;
+//    vector<TBox*> MyBoxes;
     for (unsigned int i=0; i<pZXings->size(); i++){
             OneBox = new TBox(
-                    pZXings->at(i).maxPos -10 ,
-                    pZXings->at(i).maxVal -0.5,
-                    pZXings->at(i).maxPos +10 ,
-                    pZXings->at(i).maxVal +0.5);
+                        pZXings->at(i).maxPos -10 ,
+                        pZXings->at(i).maxVal -0.5,
+                        pZXings->at(i).maxPos +10 ,
+                        pZXings->at(i).maxVal +0.5);
             OneBox->SetLineColor(kBlue);
             OneBox->SetLineWidth(1);
             OneBox->SetFillStyle(0);
             OneBox->SetFillColor(kRed);
-            MyBoxes.push_back(OneBox);
+//            MyBoxes.push_back(OneBox);
             OneBox->Draw();
-    }
+
+            OneLine = new TLine(
+                        pZXings->at(i).halfRisingEdgePos,
+                        Ameas[pZXings->at(i).halfRisingEdgePos],
+                        pZXings->at(i).halfRisingEdgePos,
+                        pZXings->at(i).halfRisingEdgePos * pZXings->at(i).slopeOfRisingEdge + pZXings->at(i).interceptRisingEdge
+                        );
+            OneLine->SetLineColor(kBlue);
+            OneLine->SetLineWidth(3);
+//            MyBoxes.push_back(OneBox);
+            OneLine->Draw();
+    }
+
+    cFiltered->cd(2);
+    gPad->SetGrid();
+    debugHistos[Vcorr_].Draw();
+
+    cFiltered->cd(3);
+    gPad->SetGrid();
+    debugHistos[Vslide_].Draw();
+
 
 //            cFiltered->cd(3);
@@ -1086,4 +1128,17 @@
                 breakout=true;
         }
+
+
+//        for (unsigned int i=0; i<pZXings->size(); i++)
+//        {
+//            delete MyEdges.at(i)
+//            delete MyBoxes.at(i);
+//        }
+        delete OneBox;
+        delete OneEdge;
+        delete OneLine;
+
+//        MyEdges.erase();
+//        MyBoxes.erase();
     }
 
