Index: /fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C
===================================================================
--- /fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C	(revision 13498)
+++ /fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C	(revision 13499)
@@ -172,5 +172,5 @@
 //void SaveHistograms( const char*, const char*, TObjArray*, int );
 
-void FillHistograms(Pixel*, vector<Region>*, int, int, int, int);
+void FillHistograms(Pixel*, vector<Region>*, int, int, TString, int, int);
 void DrawTestHistograms( int);
 void ProduceDebugHistos( vector<Region> *pZXings);
@@ -185,21 +185,21 @@
 //----------------------------------------------------------------------------
 int FPulseOverlay(
-        char*           datafilename        = "../data/2011/11/09/20111109_006.fits.gz",
-        const char*     drsfilename         = "../data/2011/11/09/20111109_003.drs.fits.gz",
-        const char*     OutRootFileName     = "../analysis/FPulseTemplate/20111109_006/20111109_006.pulses.root",
-        bool            ProduceGraphic      = false,
+        char*           datafilename        = "../../data/2011/11/09/20111109_006.fits.gz",
+        const char*     drsfilename         = "../../data/2011/11/09/20111109_003.drs.fits.gz",
+        const char*     OutRootFileName     = "../../analysis/FPulseTemplate/20111109_006/20111109_006.pulses.root",
+        bool            ProduceGraphic      = true,
         bool            spikeDebug          = false,
-        bool            debugPixel          = false,
+        bool            debugPixel          = true,
         bool            testmode            = false,
         bool            saveResults         = false,
-        int             verbosityLevel      = 0,        // different verbosity levels can be implemented here
+        int             verbosityLevel      = 4,        // different verbosity levels can be implemented here
         int             firstevent          = 0,
-        int             nevents             = 2000,
+        int             nevents             = 10,
         int             firstpixel          = 0,
-        int             npixel              = 37,
+        int             npixel              = 80,
         int             sampleSetSize       = 36,
         int             maxPulseOrder       = 1,
         int             AmplWindowWidth     = 14,       //Width of Window for selection of pulses to histograms
-        const char*     histoOptions        = "S",
+        TString         histoOptions        = "S",
         float           GainMean            = 8,
         float           BSLMean             = -1,        //4 Histogramms will be drawn, decide how far pulsehights differ from eachother
@@ -219,5 +219,8 @@
 //	Save-Root-File Settings
 //----------------------------------------------------------------------------
+    if (saveResults)
+    {
     CreateRootFile( OutRootFileName, verbosityLevel );
+    }
 
 //----------------------------------------------------------------------------
@@ -271,4 +274,10 @@
               )
         {
+            cName   ="cgpDistributions";
+            cName   += pulse_order;
+            cTitle   ="Pulses of Order: ";
+            cTitle   += pulse_order;
+            cgpDistributions[pulse_order] = new TCanvas(cName,cTitle, 0,pulse_order*20,800,800);
+            cgpDistributions[pulse_order]->Divide(2, 2);
             cName   ="cgpPixelPulses";
             cName   += pulse_order;
@@ -396,7 +405,7 @@
         {
             cout << "------------------------------------------------" << endl
-                 << "...processing Sample from Pixel: "
+                 << "...processing Sample from Pixel "
                  << firstPixelOfSample
-                 << "to Pixel: "
+                 << " to Pixel "
                  << firstPixelOfSample+sampleSetSize-1 << endl;
         }
@@ -421,6 +430,7 @@
 //--------------------------------------------------------------------
             for ( int pixelID = firstPixelOfSample;
-                  pixelID < sampleSetSize || pixelID < firstpixel + npixel;
-                pixelID++ )
+                    pixelID < firstPixelOfSample + sampleSetSize
+                    && pixelID < firstpixel + npixel;
+                    pixelID++ )
             {
                 if (verbosityLevel > 0)
@@ -428,5 +438,5 @@
                  cout << "-------------------------------------" << endl
                       << "...processing Pixel: " << pixelID
-                      << "/" << firstpixel + npixel << endl;
+                      << "/" << firstpixel + npixel -1 << endl;
                 }
 
@@ -516,4 +526,5 @@
                             AmplWindowWidth,
                             ev,
+                            histoOptions,
                             maxPulseOrder,
                             verbosityLevel
@@ -588,6 +599,7 @@
 
         for ( int pixelID = firstPixelOfSample;
-              pixelID < sampleSetSize || pixelID < firstpixel + npixel;
-            pixelID++ )
+              pixelID < firstPixelOfSample + sampleSetSize
+              && pixelID < firstpixel + npixel;
+              pixelID++ )
         {
             //here is what happends at the end of each loop over all Events
@@ -597,11 +609,11 @@
 //                        );
 
-            SaveHistograms(     //save histograms of generell results into output root file
-                        OutRootFileName,
-                        CreateSubDirName(pixel[pixelID]->mChid),
-                        pixel[pixelID]->hList,
-                        saveResults,
-                        verbosityLevel
-                        );
+//            SaveHistograms(     //save histograms of generell results into output root file
+//                        OutRootFileName,
+//                        CreateSubDirName(pixel[pixelID]->mChid),
+//                        pixel[pixelID]->hList,
+//                        saveResults,
+//                        verbosityLevel
+//                        );
 
             if (ProduceGraphic)
@@ -661,8 +673,15 @@
                     );
 
-    DeletePixelCanvases(
-                maxPulseOrder,
-                verbosityLevel
-                );
+        //Process gui events asynchronously during input
+        cout << endl;
+        TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
+        timer.TurnOn();
+        Getline("Press <return> to go on");
+        timer.TurnOff();
+
+        DeletePixelCanvases(
+                    maxPulseOrder,
+                    verbosityLevel
+                    );
     }
     return( 0 );
@@ -754,10 +773,11 @@
 void
 FillHistograms(
-        Pixel* CurrentPixel,
+        Pixel*          CurrentPixel,
         vector<Region>* pZXings,
-        int AmplWindowWidth,
-        int eventNumber,
-        int maxPulseOrder,
-        int verbosityLevel
+        int             AmplWindowWidth,
+        int             eventNumber,
+        TString         histoOptions,
+        int             maxPulseOrder,
+        int             verbosityLevel
         )
 {
@@ -770,4 +790,5 @@
     for (reg = pZXings->begin() ; reg < pZXings->end() ; reg++)
     {
+
         //skip those who are at the Rim of the ROI
         if (reg->maxPos < 12 || (unsigned int) reg->maxPos > gRegionOfInterest-12)
@@ -776,19 +797,18 @@
             continue;
         }
-        //domstest->Fill(reg->maxPos);
 
         // Define axis range of Histogram
-        int Left = reg->maxPos - gPixelOverlayXaxisLeft;
-        int Right = reg->maxPos + gPixelOverlayXaxisRight;
-        int EdgeLeft = reg->halfRisingEdgePos - gPixelOverlayXaxisLeft;
-        int EdgeRight = reg->halfRisingEdgePos + gPixelOverlayXaxisRight;
-
-        if (Left < 0) Left =0;
-        if (Right > (int)Ameas.size() ) Right=Ameas.size() ;
-        if (EdgeLeft < 0) EdgeLeft =0;
-        if (EdgeRight > (int)Ameas.size() ) EdgeRight=Ameas.size() ;
-
-
-        hTesthisto2->Fill( eventNumber, reg->slopeOfRisingEdge ) ;
+        int Left        = reg->maxPos - gPixelOverlayXaxisLeft;
+        int Right       = reg->maxPos + gPixelOverlayXaxisRight;
+        int EdgeLeft    = reg->halfRisingEdgePos - gPixelOverlayXaxisLeft;
+        int EdgeRight   = reg->halfRisingEdgePos + gPixelOverlayXaxisRight;
+
+        if (Left < 0)                           Left        =   0;
+        if (EdgeLeft < 0)                       EdgeLeft    =   0;
+        if (Right > (int)Ameas.size() )         Right       =   Ameas.size();
+        if (EdgeRight > (int)Ameas.size() )     EdgeRight   =   Ameas.size();
+
+
+//        hTesthisto2->Fill( eventNumber, reg->slopeOfRisingEdge ) ;
 
         if (verbosityLevel > 2) cout << endl << "\t...choosing Histogram" ;
@@ -804,5 +824,4 @@
                 order_of_pulse = order;
                 use_this_peak = true;
-                CurrentPixel->hSlopeRisingEdge[order_of_pulse]->Fill( reg->slopeOfRisingEdge ) ;
                 break;
             }
@@ -811,4 +830,12 @@
                 use_this_peak = false;
                 if (verbosityLevel > 2) cout << "...NONE" << endl ;
+            }
+            if (use_this_peak)
+            {
+                if ( histoOptions.Contains("S") )
+                {
+                     if (verbosityLevel > 2) cout << endl << "\t...filling Edge Histogram" ;
+                    CurrentPixel->hSlopeRisingEdge[order]->Fill( reg->slopeOfRisingEdge ) ;
+                }
             }
         }
@@ -879,9 +906,11 @@
 {
     if (verbosityLevel > 2) cout << endl << "...delete pixel Canvases" ;
-    for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order ++)
+    for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
     {
         delete cgpPixelPulses[pulse_order];
+        delete cgpDistributions[pulse_order];
     }
     delete[] cgpPixelPulses;
+    delete[] cgpDistributions;
 }
 
