Index: fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C	(revision 13547)
+++ fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C	(revision 13558)
@@ -157,5 +157,5 @@
 
     //Root-File Objects
-//    TObjArray*  hList[sampleSetSize] = {NULL};
+//    TObjArray*  hList[pixelSetSize] = {NULL};
     TObjArray*  hRootList           = NULL;
 
@@ -175,8 +175,8 @@
 //void SaveHistograms( const char*, const char*, TObjArray*, int );
 
-void FillHistograms(Pixel*, vector<Region>*, int, int, TString, int, int);
+void FillHistograms(Pixel*, vector<Region>*, int, int, int , int );
 void DrawTestHistograms( int);
 void ProduceDebugHistos( vector<Region> *pZXings);
-
+bool  UseThisPulse( int, int, int, int, int, int);
 void UpdateCanvases( int, int);
 void DeletePixelCanvases( int, int );
@@ -190,20 +190,20 @@
         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     = "test.root",
-        bool            ProduceGraphic      = false,
+        const char*     OutRootFileName     = "/home_nfs/isdc/jbbuss/analysis/FPulseTemplate/test.root",
+        bool            ProduceGraphic      = true,
         bool            spikeDebug          = false,
-        bool            debugPixel          = false,
+        bool            debugPixel          = true,
         bool            testmode            = false,
         bool            saveResults         = false,
         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          = 0,
-        int             npixel              = -1,
-        int             sampleSetSize       = 40,
-        int             maxPulseOrder       = 3,
+        int             nevents             = 1000,
+        int             firstpixel          = 15,
+        int             npixel              = 3,
+        int             pixelSetSize       = 40,
+        int             maxPulseOrder       = 4,
         int             AmplWindowWidth     = 14,       //Width of Window for selection of pulses to histograms
         TString         histoOptions        = "S",
-        float           GainMean            = 8,
+        float           GainMean            = 9,
         float           BSLMean             = -1,        //4 Histogramms will be drawn, decide how far pulsehights differ from eachother
         int             avg1                = 8,
@@ -275,5 +275,5 @@
             cName   ="cgpDistributions";
             cName   += pulse_order;
-            cTitle   ="Pulses of Order: ";
+            cTitle   ="Distributions of Pulses with Order of: ";
             cTitle   += pulse_order;
             cgpDistributions[pulse_order] = new TCanvas(cName,cTitle, 0,pulse_order*20,800,800);
@@ -281,5 +281,5 @@
             cName   ="cgpPixelPulses";
             cName   += pulse_order;
-            cTitle   ="Pulses of Order: ";
+            cTitle   ="Overlays of Pulses with Order of: ";
             cTitle   += pulse_order;
             cgpPixelPulses[pulse_order] = new TCanvas(cName,cTitle, 0,pulse_order*20,800,800);
@@ -405,7 +405,7 @@
 // Loop over Pixel Sets
 //-------------------------------------
-    for ( int firstPixelOfSample = firstpixel;
-          firstPixelOfSample < firstpixel + npixel;
-          firstPixelOfSample += sampleSetSize )
+    for ( int firstPixelOfSet = firstpixel;
+          firstPixelOfSet < firstpixel + npixel;
+          firstPixelOfSet += pixelSetSize )
     {
 
@@ -413,8 +413,8 @@
         {
             cout << "------------------------------------------------" << endl
-                 << "...processing Sample from Pixel "
-                 << firstPixelOfSample
+                 << "...processing Set from Pixel "
+                 << firstPixelOfSet
                  << " to Pixel "
-                 << firstPixelOfSample+sampleSetSize-1 << endl;
+                 << firstPixelOfSet+pixelSetSize-1 << endl;
         }
 
@@ -425,5 +425,4 @@
         {
             // Get an Event --> consists of 1440 Pixel ...erm....data
-            cout << endl << "processing event " << ev << endl;
             datafile->GetRow( ev - 1 );
 
@@ -431,8 +430,8 @@
             {
              cout << "-------------------------------------" << endl
-                  << "...processing Sample from Pixel "
-                  << firstPixelOfSample
+                  << "...processing Set from Pixel "
+                  << firstPixelOfSet
                   << " to Pixel "
-                  << firstPixelOfSample+sampleSetSize-1
+                  << firstPixelOfSet+pixelSetSize-1
                   << "... Event: " << CurrentEventID
                   << "/" << nevents << endl;
@@ -442,6 +441,6 @@
 // Loops over every Pixel of a Set of Pixels
 //--------------------------------------------------------------------
-            for ( int pixelID = firstPixelOfSample;
-                    pixelID < firstPixelOfSample + sampleSetSize
+            for ( int pixelID = firstPixelOfSet;
+                    pixelID < firstPixelOfSet + pixelSetSize
                     && pixelID < firstpixel + npixel;
                     pixelID++ )
@@ -450,8 +449,8 @@
                 {
                  cout << "-------------------------------------" << endl
-                      << "...processing Sample from Pixel "
-                      << firstPixelOfSample
+                      << "...processing Set from Pixel "
+                      << firstPixelOfSet
                       << " to Pixel "
-                      << firstPixelOfSample+sampleSetSize-1
+                      << firstPixelOfSet+pixelSetSize-1
                       << "... Event: " << CurrentEventID
                       << "/" << nevents << endl
@@ -550,5 +549,5 @@
                             AmplWindowWidth,
                             ev,
-                            histoOptions,
+//                            histoOptions,
                             maxPulseOrder,
                             verbosityLevel
@@ -573,14 +572,14 @@
                         if (debugPixel)
                         {
-                            for ( int order = 0;
-                                order < maxPulseOrder;
-                                order++
-                                )
-                            {
-                                pixel[pixelID]->DrawHistograms(
-                                            cgpPixelPulses[order],
+//                            for ( int order = 0;
+//                                order < maxPulseOrder;
+//                                order++
+//                                )
+//                            {
+                                pixel[firstPixelOfSet]->DrawHistograms(
+                                            cgpPixelPulses,
                                             pulsesCanvasFrameNrs
                                             );
-                            }
+//                            }
                             if (testmode)
                             {
@@ -605,7 +604,7 @@
                          << endl << "-------------------------------------"<< endl;
                 }
-            }//End of Loop over Sample
-//-------------------------------------
-// end of Loops over Sample
+            }//End of Loop over Set
+//-------------------------------------
+// end of Loops over Set
 //-------------------------------------
 
@@ -621,29 +620,22 @@
 //-------------------------------------
 
-        for ( int pixelID = firstPixelOfSample;
-              pixelID < firstPixelOfSample + sampleSetSize
+        for ( int pixelID = firstPixelOfSet;
+              pixelID < firstPixelOfSet + pixelSetSize
               && pixelID < firstpixel + npixel;
               pixelID++ )
         {
             //here is what happends at the end of each loop over all Events
-//            pixel[pixelID]->DrawHistograms(
-//                        cgpPixelPulses,
-//                        pulsesCanvasFrameNrs
-//                        );
-
-//            SaveHistograms(     //save histograms of generell results into output root file
-//                        OutRootFileName,
-//                        CreateSubDirName(pixel[pixelID]->mChid),
-//                        pixel[pixelID]->hList,
-//                        saveResults,
-//                        verbosityLevel
-//                        );
 
             if (ProduceGraphic)
             {
-            UpdateCanvases(
-                           verbosityLevel,
-                           maxPulseOrder
-                           );
+                pixel[pixelID]->DrawHistograms(
+                            cgpPixelPulses,
+                            pulsesCanvasFrameNrs
+                            );
+
+                UpdateCanvases(
+                               verbosityLevel,
+                               maxPulseOrder
+                               );
             }
 
@@ -717,8 +709,14 @@
                     verbosityLevel
                     );
-    }
-
-    delete datafile;
-    delete[] pixel;
+        delete      cgpTestHistos;
+
+        if (spikeDebug)
+            delete      cFiltered;
+    }
+
+    delete      datafile;
+    delete[]    pixel;
+
+
     return( 0 );
 }
@@ -813,5 +811,4 @@
         int             AmplWindowWidth,
         int             eventNumber,
-        TString         histoOptions,
         int             maxPulseOrder,
         int             verbosityLevel
@@ -819,4 +816,5 @@
 {
     if (verbosityLevel > 2) cout << endl << "...filling pulse histograms" ;
+    if (verbosityLevel > 3) cout << endl << "...EventNR " << eventNumber ;
     bool use_this_peak=false;
     int order_of_pulse=0;
@@ -831,4 +829,5 @@
             continue;
         }
+
         // Define axis range of Histogram
         int Left        = reg->maxPos - gPixelOverlayXaxisLeft;
@@ -843,51 +842,54 @@
 
 
-//        hTesthisto2->Fill( eventNumber, reg->slopeOfRisingEdge ) ;
-
         if (verbosityLevel > 2) cout << endl << "\t...choosing Histogram" ;
-
         //determine order of pulse and which histogram shall be filled
-        for(int order = 0; order < maxPulseOrder; order++)
+        for ( int order = 0; order < maxPulseOrder; order++)
         {
-            if (Ameas[reg->maxPos] >= ((gGainMean*(order+1)) - (AmplWindowWidth/2))
-                && Ameas[reg->maxPos] < ((gGainMean*(order+1)) + AmplWindowWidth/2))
-            {
-                if (verbosityLevel > 2) cout << "...#" << order ;
+            use_this_peak = UseThisPulse(
+                        reg->maxPos,
+                        order,
+                        AmplWindowWidth,
+                        gGainMean,
+                        maxPulseOrder,
+                        verbosityLevel
+                        );
+            if ( use_this_peak)
+            {
                 order_of_pulse = order;
-                use_this_peak = true;
                 break;
             }
-            else if (order >= (maxPulseOrder - 1))
-            {
-                use_this_peak = false;
-                if (verbosityLevel > 2) cout << "...NONE" << endl ;
+        }
+        //Fill histograms
+        if (use_this_peak)
+        {
+            //Histograms for Distributions
+            if (CurrentPixel->mOptions.Contains("S") )
+            {
+                if (verbosityLevel > 2)
+                        cout << endl << "\t...filling Edge Histogram" ;
+                CurrentPixel->hSlopeRisingEdge[order_of_pulse]->Fill( reg->slopeOfRisingEdge ) ;
             }
-            if (use_this_peak)
-            {
-                if ( histoOptions.Contains("S") )
-                {
-//                     if (verbosityLevel > 2)
-                         cout << endl << "\t...filling Edge Histogram" ;
-                    CurrentPixel->hSlopeRisingEdge[order]->Fill( reg->slopeOfRisingEdge ) ;
-                }
+
+            //Histograms for Maximum Overlay
+            for ( int pos = Left; pos < Right; pos++)
+            {
+                CurrentPixel->hMaxOverlay[order_of_pulse]->Fill( pos - (reg->maxPos), Ameas[pos]) ;
+                CurrentPixel->hMaxProfile[order_of_pulse]->Fill( pos - (reg->maxPos), Ameas[pos]) ;
             }
-        }
-        //Fill overlay und profile histograms
-        if (use_this_peak){
-            for ( int pos = Left; pos < Right; pos++){
-//                if ();
-               CurrentPixel->hMaxOverlay[order_of_pulse]->Fill( pos - (reg->maxPos), Ameas[pos]) ;
-               CurrentPixel->hMaxProfile[order_of_pulse]->Fill( pos - (reg->maxPos), Ameas[pos]) ;
-            }
-            for ( int pos = EdgeLeft; pos < EdgeRight; pos++){
+            //Histograms for Edge Overlay
+            for ( int pos = EdgeLeft; pos < EdgeRight; pos++)
+            {
                 CurrentPixel->hEdgeOverlay[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), Ameas[pos]) ;
                 CurrentPixel->hEdgeProfile[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), Ameas[pos]) ;
-
             }
+
             if (verbosityLevel > 2) cout << "...done" << endl;
         }
+
         //Breakout option
         if (breakout)
-        break;
+        {
+            break;
+        }
    }
     if (verbosityLevel > 2) cout << "...done" << endl;
@@ -895,4 +897,37 @@
 // end of FillHistograms
 //----------------------------------------------------------------------------
+
+bool UseThisPulse(
+        int             maxPos,
+        int             order,
+        int             AmplWindowWidth,
+        int             gGainMean,
+        int             maxPulseOrder,
+        int             verbosityLevel
+        )
+{
+    //determine if pulse is of given order
+bool use_this_peak = false;
+        if (Ameas[maxPos] >= ((gGainMean*(order+1)) - (AmplWindowWidth/2))
+            && Ameas[maxPos] < ((gGainMean*(order+1)) + AmplWindowWidth/2))
+        {
+            if (verbosityLevel > 3) cout << "...#" << order ;
+            use_this_peak = true;
+        }
+        else
+        {
+            if (verbosityLevel > 3)
+            {
+                if (order >= (maxPulseOrder - 1))
+                {
+                    cout << "...NONE" << endl ;
+                }
+            }
+            use_this_peak = false;
+        }
+
+return use_this_peak;
+}
+
 
 void
