Index: fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C	(revision 13602)
+++ fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C	(revision 13610)
@@ -178,5 +178,5 @@
 void FillHistograms(Pixel*, vector<Region>*, int, int, int , int );
 void DrawTestHistograms( int);
-void ProduceDebugHistos( vector<Region> *pZXings);
+bool ProduceDebugHistos( vector<Region> *pZXings);
 bool  UseThisPulse( int, int, int, int, int, int);
 void UpdateCanvases( int, int, bool);
@@ -191,16 +191,16 @@
         const char*     datafilename        = "/fact/raw/2011/11/09/20111109_006.fits.gz",
         const char*     drsfilename         = "/fact/raw/2011/11/09/20111109_003.drs.fits.gz",
-        const char*     OutRootFileName     = "/home_nfs/isdc/jbbuss/analysis/FPulseTemplate/test.root",
-        bool            ProduceGraphic      = true,
-        bool            spikeDebug          = true,
-        bool            debugPixel          = true,
+        const char*     OutRootFileName     = "/home_nfs/isdc/jbbuss/analysis/FPulseTemplate/20111109_006/Overlay/pulseoverlay.root",
+        bool            ProduceGraphic      = false,
+        bool            spikeDebug          = false,
+        bool            debugPixel          = false,
         bool            testmode            = false,
         bool            saveResults         = true,
         int             verbosityLevel      = 1,        // different verbosity levels can be implemented here
         int             firstevent          = 1,        // Hast to be between 1 and infinity NOT 0!!!!
-        int             nevents             = 100,
-        int             firstpixel          = 15,
-        int             npixel              = 3,
-        int             pixelSetSize       = 40,
+        int             nevents             = -1,
+        int             firstpixel          = 0,
+        int             npixel              = -1,
+        int             pixelSetSize       = 120,
         int             maxPulseOrder       = 3,
         int             AmplWindowWidth     = 14,       //Width of Window for selection of pulses to histograms
@@ -386,6 +386,5 @@
 //-----------------------------------------------------------------------------
 
-    if (spikeDebug)
-        BookDebugHistos(verbosityLevel );
+
 
     if (testmode)
@@ -565,5 +564,6 @@
                 if ( spikeDebug )
                 {
-                    ProduceDebugHistos( pZXings );
+                    BookDebugHistos(verbosityLevel );
+                breakout = ProduceDebugHistos( pZXings );
                 }// end of if(spikeDebug)
 
@@ -1025,5 +1025,5 @@
 //----------------------------------------------------------------------------
 
-void
+bool
 ProduceDebugHistos(
         vector<Region>* pZXings
@@ -1045,4 +1045,5 @@
        debugHistos[Vcfd2_].SetBinContent( sl, Vcfd2[sl] );
     }
+
     bool has_negative_slope = false;
     cFiltered->cd(1);
@@ -1050,6 +1051,11 @@
     debugHistos[Ameas_].Draw();
 
-    TF1 *OneEdge;
-//    vector<TF1*> MyEdges;
+    TF1             *OneEdge;
+    TLine           *OneLine;
+    TBox            *OneBox;
+    vector<TF1*>    MyEdges;
+    vector<TBox*>   MyBoxes;
+    vector<TBox*>   MyLines;
+
     int left    = debugHistos[Ameas_].GetXaxis()->GetFirst();
     int right   = debugHistos[Ameas_].GetXaxis()->GetLast();
@@ -1060,64 +1066,94 @@
         {
             has_negative_slope = true;
-            cout << "Slope is: " << reg->slopeOfRisingEdge << endl;
+        }
+    }
+
+    if (has_negative_slope)
+    {
+    for (unsigned int i=0; i<pZXings->size(); i++){
+        Region* reg = &pZXings->at(i);
+        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");
-        }
-    }
-
-    TLine *OneLine;
-    TBox *OneBox;
-//    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);
-            OneBox->SetLineColor(kBlue);
-            OneBox->SetLineWidth(1);
-            OneBox->SetFillStyle(0);
-            OneBox->SetFillColor(kRed);
-//            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();
+        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");
+//            delete OneEdge;
+
+        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);
+        OneBox->SetLineColor(kBlue);
+        OneBox->SetLineWidth(1);
+        OneBox->SetFillStyle(0);
+        OneBox->SetFillColor(kRed);
+        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);
+        MyLines.push_back(OneBox);
+        OneLine->Draw();
     }
 
     cFiltered->cd(2);
     gPad->SetGrid();
-    debugHistos[Vcorr_].Draw();
+    debugHistos[Vslide_].Draw();
+    debugHistos[Vcorr_].Draw("SAME");
+
+    for (unsigned int i=0; i<MyEdges.size(); i++){
+        MyEdges.at(i)->Draw("SAME");
+    }
+    for (unsigned int i=0; i<MyBoxes.size(); i++){
+        MyBoxes.at(i)->Draw();
+    }
+    for (unsigned int i=0; i<MyLines.size(); i++){
+        MyLines.at(i)->Draw();
+    }
 
     cFiltered->cd(3);
     gPad->SetGrid();
-    debugHistos[Vslide_].Draw();
+    debugHistos[Vcorr_].SetLineColor(kBlue);
+    debugHistos[Vcorr_].Draw();
+    debugHistos[Ameas_].Draw("SAME");
+    debugHistos[Vslide_].SetLineColor(kRed);
+    debugHistos[Vslide_].Draw("SAME");
+    debugHistos[Vcfd_].SetLineColor(kGreen);
+    debugHistos[Vcfd_].Draw("SAME");
+    debugHistos[Vcfd2_].SetLineColor(kViolet);
+    debugHistos[Vcfd2_].Draw("SAME");
+    for (unsigned int i=0; i<MyEdges.size(); i++){
+        MyEdges.at(i)->Draw("SAME");
+    }
+    for (unsigned int i=0; i<MyBoxes.size(); i++){
+        MyBoxes.at(i)->Draw();
+    }
+    for (unsigned int i=0; i<MyLines.size(); i++){
+        MyLines.at(i)->Draw();
+    }
 
 
@@ -1128,6 +1164,5 @@
 //            zeroline->SetLineColor(kBlue);
 //            zeroline->Draw();
-    if (has_negative_slope)
-    {
+
         cFiltered->Update();
 
@@ -1139,7 +1174,10 @@
         timer.TurnOff();
         if (input=="q\n") {
-                breakout=true;
-        }
-
+                return true;
+        }
+
+        MyLines.clear();
+        MyBoxes.clear();
+        MyEdges.clear();
 
 //        for (unsigned int i=0; i<pZXings->size(); i++)
@@ -1148,7 +1186,7 @@
 //            delete MyBoxes.at(i);
 //        }
-        delete OneBox;
-        delete OneEdge;
-        delete OneLine;
+//        delete OneBox;
+//        delete OneEdge;
+//        delete OneLine;
 
 //        MyEdges.erase();
@@ -1159,5 +1197,5 @@
     // do some Garbage collection ...
     // all the Objects on the heap should be deleted here.
-
+return false;
 }// end of if(spikeDebug)
 
