Index: fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 13789)
+++ fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 13790)
@@ -101,8 +101,6 @@
 {
 
-
-    InputPath = SetHostsPaths(true, InputPath );
-    OutPutPath = SetHostsPaths(true, OutPutPath );
-
+    InputPath       = SetHostsPaths(true, InputPath );
+    OutPutPath      = SetHostsPaths(true, OutPutPath );
 
 //----------------------------------------------------------------------------
@@ -114,8 +112,11 @@
     }
 
-    TFile * inputRootFile   = OpenRootFile( InputPath, InRootFileName, verbosityLevel );
-    TFile * outputRootFile  = OpenRootFile( OutPutPath, OutputRootFileName, verbosityLevel );
-//----------------------------------------------------------------------------
-//	global variable Settings
+    TFile * inputRootFile
+            = OpenRootFile( InputPath, InRootFileName, verbosityLevel );
+
+    TFile * outputRootFile
+            = OpenRootFile( OutPutPath, OutputRootFileName, verbosityLevel );
+//----------------------------------------------------------------------------
+//	Define operation range
 //----------------------------------------------------------------------------
     if ( npixel == -1 )
@@ -129,4 +130,5 @@
         pixelSetSize = firstpixel +npixel;
     }
+
 //    float GainMean  = GainMean;  // this has to be extracted from root files
 //    float BSLMean   = BSLMean;    // this has to be extracted from root files
@@ -155,5 +157,5 @@
 
     //Canvas Pad numbering
-    int PixelCanvasFrameNrs[4] = {
+    int PixelCanvasFrameNrs[4]      = {
         1,  // Top left
         2,  // Top right
@@ -163,5 +165,5 @@
 
     //Canvas Pad numbering
-    int AllpixelCanvasFrameNrs[4] = {
+    int AllpixelCanvasFrameNrs[4]   = {
         1,  // Top left
         2,  // Top right
@@ -174,10 +176,10 @@
 
         //Canvases
-        cgpPixelPulses      = new TCanvas*[maxPulseOrder];
-        cgpDistributions    = new TCanvas*[maxPulseOrder];
+        cgpPixelPulses              = new TCanvas*[maxPulseOrder];
+        cgpDistributions            = new TCanvas*[maxPulseOrder];
 
         //TCanvas*    gpcDevelopment = NULL;
-        TString cName   = "";
-        TString cTitle  = "";
+        TString cName               = "";
+        TString cTitle              = "";
 
         //naming of pulse canvases
@@ -189,29 +191,23 @@
         {
             cName   ="cgpDistributions";
-            cName   += pulse_order;
-            cTitle   ="Distributions of Pulses with Order of: ";
-            cTitle   += pulse_order;
-            cgpDistributions[pulse_order] = new TCanvas(cName,cTitle, 720,pulse_order*20,720,720);
+            cName  += pulse_order;
+
+            cTitle  ="Distributions of Pulses with Order of: ";
+            cTitle += pulse_order;
+
+            cgpDistributions[pulse_order]
+                    = new TCanvas(cName,cTitle, 720,pulse_order*20,720,720);
             cgpDistributions[pulse_order]->Divide(2, 2);
+
             cName   ="cgpPixelPulses";
-            cName   += pulse_order;
-            cTitle   ="Overlays of Pulses with Order of: ";
-            cTitle   += pulse_order;
-            cgpPixelPulses[pulse_order] = new TCanvas(cName,cTitle, 0,pulse_order*20,720,720);
+            cName  += pulse_order;
+
+            cTitle  ="Overlays of Pulses with Order of: ";
+            cTitle  += pulse_order;
+
+            cgpPixelPulses[pulse_order]
+                     = new TCanvas(cName,cTitle, 0,pulse_order*20,720,720);
             cgpPixelPulses[pulse_order]->Divide(2, 2);
         }
-
-
-        // Create (pointer to) Canvases, which are used in every run,
-        // also in 'non-debug' runs
-                // Canvases only need if spike Debug, but I want to deklare
-                // the pointers anyway ...
-
-//        if (testmode)
-//        {
-//        //additional Test histograms
-//        cgpTestHistos = new TCanvas( "cgpTestHistos", "Test Histograms", 360, 420, 360, 360 );
-//        cgpTestHistos->Divide(2,0);
-//        }
     }
 
@@ -226,5 +222,5 @@
 
 //----------------------------------------------------------------------------
-// Initialize Pixel
+// Initialize Pixels
 //----------------------------------------------------------------------------
     if (verbosityLevel > 0)
@@ -233,5 +229,5 @@
     }
 
-    Pixel** pixel = new Pixel*[NPIX];
+    Pixel**     pixel       = new Pixel*[NPIX];
 
     for (int i = 0 ; i < NPIX; i++)
@@ -240,7 +236,8 @@
     }
 
-    PixelSum* wholeCamera = NULL;
-
-    bool first_pass = true;
+    PixelSum*   wholeCamera = NULL;
+
+    bool        first_pass  = true;
+
 //-------------------------------------
 // Loop over Pixel Sets
@@ -252,9 +249,11 @@
         if (verbosityLevel >= 0)
         {
-            cout << "------------------------------------------------" << endl
+            cout << "------------------------------------------------"
+                 << endl
                  << "...processing Pixel: "
                  << firstPixelOfSet
                  << " to Pixel: "
-                 << firstPixelOfSet+pixelSetSize-1 << endl;
+                 << firstPixelOfSet+pixelSetSize-1
+                 << endl;
         }
 
@@ -263,18 +262,20 @@
         //--------------------------------------------------------------------
         for ( int pixelID = firstPixelOfSet;
-                pixelID < firstPixelOfSet + pixelSetSize
-                && pixelID < firstpixel + npixel;
-                pixelID++ )
+              pixelID < firstPixelOfSet + pixelSetSize
+              && pixelID < firstpixel + npixel;
+              pixelID++ )
         {
 
             if (verbosityLevel > 1)
             {
-             cout << "-------------------------------------" << endl
-                  << "...processing Set from Pixel "
-                  << firstPixelOfSet
-                  << " to Pixel "
-                  << firstPixelOfSet+pixelSetSize-1
-                  << " Pixel: " << pixelID
-                  << "/" << firstpixel + npixel -1 << endl;
+                cout << "-------------------------------------"
+                     << endl
+                     << "...processing Set from Pixel "
+                     << firstPixelOfSet
+                     << " to Pixel "
+                     << firstPixelOfSet+pixelSetSize-1
+                     << " Pixel: " << pixelID
+                     << "/" << firstpixel + npixel -1
+                     << endl;
             }
 
@@ -286,4 +287,5 @@
                 cout << "...creating pixel: " << pixelID << endl;
             }
+
            pixel[pixelID] = new Pixel(
                        pixelID,
@@ -308,4 +310,5 @@
                     cout << endl << "...preparing camera" << endl;
                 }
+
                 wholeCamera = new PixelSum(
                             "AllPixel",
@@ -321,4 +324,5 @@
                             outputRootFile
                             );
+
                 first_pass = false;
             }
@@ -333,5 +337,6 @@
                 if (verbosityLevel > 2)
                 {
-                    cout << "-------------------------------------" << endl
+                    cout << "-------------------------------------"
+                         << endl
                          << "...processing Set from Pixel "
                          << firstPixelOfSet
@@ -340,14 +345,18 @@
                          << " Pixel: " << pixelID
                          << "/" << firstpixel + npixel -1
-                         << " Pulse-Order: " << pulse_order << endl;
+                         << " Pulse-Order: " << pulse_order
+                         << endl;
                 }
 
                 // Calculate Max Prop. Value of each slice
                 //-------------------------------------
+
+                //from Maximum Overlay
                 if (verbosityLevel > 2)
                 {
-                    cout << "...extracting templates from Maximum Overlay " << endl;
+                    cout << "...extracting templates from Maximum Overlay "
+                         << endl;
                 }
-                //from Maximum Overlay
+
                 ExtractPulseTemplate(
                             pixel[pixelID],
@@ -357,9 +366,10 @@
                             );
 
+                //from Edge Overlay
                 if (verbosityLevel > 2)
                 {
-                    cout << "...extracting templates from Edge Overlay " << endl;
+                    cout << "...extracting templates from Edge Overlay "
+                         << endl;
                 }
-                //from Edge Overlay
                 ExtractPulseTemplate(
                             pixel[pixelID],
@@ -384,43 +394,44 @@
                             verbosityLevel
                             );
+
                 if (ProduceGraphic)
                 {
-                pixel[pixelID]->DrawTemplateHistograms(
-                            cgpPixelPulses,
-                            PixelCanvasFrameNrs
-                            );
-
-                pixel[pixelID]->DrawEdgeTemplateHistograms(
-                            cgpPixelPulses,
-                            PixelCanvasFrameNrs
-                            );
+                    pixel[pixelID]->DrawTemplateHistograms(
+                                cgpPixelPulses,
+                                PixelCanvasFrameNrs
+                                );
+
+                    pixel[pixelID]->DrawEdgeTemplateHistograms(
+                                cgpPixelPulses,
+                                PixelCanvasFrameNrs
+                                );
                 }
                 //-------------------------------------
                 // Fill Histogramms of Camera
                 //-------------------------------------
-                cout << "1" << endl;
+
                 wholeCamera->hMaxOverlay[pulse_order]->Add(
                             pixel[pixelID]->hMaxOverlay[pulse_order]
                             );
-                cout << wholeCamera->hMaxOverlay[pulse_order]->GetName() << endl;
-cout << "2" << endl;
+
                 wholeCamera->hMaxProfile[pulse_order]->Add(
                             pixel[pixelID]->hMaxProfile[pulse_order]
                             );
-cout << "3" << endl;
+
                 wholeCamera->hEdgeOverlay[pulse_order]->Add(
                             pixel[pixelID]->hEdgeOverlay[pulse_order]
                             );
-cout << "4" << endl;
+
                 wholeCamera->hEdgeProfile[pulse_order]->Add(
                             pixel[pixelID]->hEdgeProfile[pulse_order]
                             );
-cout << "5" << endl;
+
 
                 if (verbosityLevel > 2)
                 {
-                cout << endl << "...End of pulseorder "
-                    << pulse_order
-                    << endl;
+                cout << endl
+                     << "...End of pulseorder "
+                     << pulse_order
+                     << endl;
                 }
 
@@ -430,9 +441,9 @@
             if (ProduceGraphic)
             {
-            UpdateCanvases(
-                        verbosityLevel,
-                        MAX_PULS_ORDER,
-                        false
-                        );
+                UpdateCanvases(
+                            verbosityLevel,
+                            MAX_PULS_ORDER,
+                            false
+                            );
             }
 
@@ -454,11 +465,14 @@
 
             //deleteCurrent Pixel from Heap
-            delete pixel[pixelID];
-            pixel[pixelID] = NULL;
+            delete  pixel[pixelID];
+            pixel[pixelID]  = NULL;
+
             if (verbosityLevel > 2)
             {
-            cout << endl << "...End of Pixel"
-                << endl << "------------------------------------------------"
-                << endl;
+            cout << endl
+                 << "...End of Pixel"
+                 << endl
+                 << "------------------------------------------------"
+                 << endl;
             }
         }
@@ -467,7 +481,9 @@
         if (verbosityLevel > 1)
         {
-        cout << endl << "...End of Loop over all Pixels of set"
-            << endl << "------------------------------------------------"
-            << endl;
+        cout << endl
+             << "...End of Loop over all Pixels of set"
+             << endl
+             << "------------------------------------------------"
+             << endl;
         }
     }
@@ -476,11 +492,14 @@
     if (verbosityLevel > 0)
     {
-    cout << endl << "...End of Loop over all Pixelsets"
-        << endl << "------------------------------------------------"
-        << endl;
+    cout << endl
+         << "...End of Loop over all Pixelsets"
+         << endl
+         << "------------------------------------------------"
+         << endl;
     }
 
     delete[] pixel;
     pixel = NULL;
+
 //-------------------------------------
 // Draw All Pixel Histograms
@@ -493,10 +512,12 @@
         if (verbosityLevel > 2)
         {
-            cout << "-------------------------------------" << endl
-                 << "...processing Pulse-Order: " << pulse_order;
+            cout << "-------------------------------------"
+                 << endl
+                 << "...processing Pulse-Order: "
+                 << pulse_order;
         }
 
-//         Calculate Max Prop. Value of each slice
-//        -------------------------------------
+// Calculate Max Prop. Value of each slice
+//-------------------------------------
 
         //from Maximum Overlay
@@ -507,4 +528,11 @@
                     verbosityLevel
                     );
+        WritePixelTemplateToCsv(
+                    wholeCamera,
+                    OutPutPath,
+                    "Maximum",
+                    pulse_order,
+                    verbosityLevel
+                    );
 
         //from Edge Overlay
@@ -515,13 +543,4 @@
                     verbosityLevel
                     );
-
-        WritePixelTemplateToCsv(
-                    wholeCamera,
-                    OutPutPath,
-                    "Maximum",
-                    pulse_order,
-                    verbosityLevel
-                    );
-
         WritePixelTemplateToCsv(
                     wholeCamera,
@@ -543,4 +562,5 @@
     } //EOF: Draw All Pixel Histograms
 
+
 //-------------------------------------
 // Save All Pixel Histograms
@@ -560,6 +580,4 @@
 //                verbosityLevel
 //                );
-
-
 
 //    if (ProduceGraphic)
@@ -572,4 +590,7 @@
 //    }
 
+//-------------------------------------
+// Delete Objects on Heap
+//-------------------------------------
     delete wholeCamera;
     if (ProduceGraphic)
@@ -579,4 +600,5 @@
     delete inputRootFile;
     delete outputRootFile;
+
     return( 0 );
 }
@@ -593,37 +615,47 @@
 void
 DeletePixelCanvases(
-        int maxPulseOrder,
-        int verbosityLevel
+        int         maxPulseOrder,
+        int         verbosityLevel
         )
 {
     if (verbosityLevel > 2)
     {
-        cout << endl << "...delete pixel Canvases" << endl;
-    }
-    for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
+        cout << endl
+             << "...delete pixel Canvases"
+             << endl;
+    }
+
+    for ( int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
     {
         delete cgpPixelPulses[pulse_order];
-        cgpPixelPulses[pulse_order] = NULL;
+        cgpPixelPulses[pulse_order]     = NULL;
+
         delete cgpDistributions[pulse_order];
-        cgpDistributions[pulse_order] = NULL;
-    }
+        cgpDistributions[pulse_order]   = NULL;
+    }
+
     delete[] cgpPixelPulses;
-    cgpPixelPulses = NULL;
+    cgpPixelPulses      = NULL;
+
     delete[] cgpDistributions;
-    cgpDistributions = NULL;
+    cgpDistributions    = NULL;
 }
 
 void
 UpdateCanvases(
-        int verbosityLevel,
-        int max_pulse_order,
-        bool testmode
+        int         verbosityLevel,
+        int         max_pulse_order,
+        bool        testmode
         )
 {
-    if (verbosityLevel > 3) cout << endl << "...updating canvases" ;
+    if (verbosityLevel > 3)
+    {
+        cout << endl << "...updating canvases" << endl;
+    }
     for (int pulse_order = 0; pulse_order < max_pulse_order; pulse_order++)
     {
         cgpPixelPulses[pulse_order]->Modified();
         cgpPixelPulses[pulse_order]->Update();
+
         cgpDistributions[pulse_order]->Modified();
         cgpDistributions[pulse_order]->Update();
@@ -641,7 +673,5 @@
 int main()
 {
-
-FCalcPulseTemplate();
-return 0;
-
+    FCalcPulseTemplate();
+    return 0;
 }
