Index: fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 13641)
+++ fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 13656)
@@ -40,4 +40,5 @@
 #include "rootfilehandler.h"
 #include "pixel.h"
+#include "pixelsum.h"
 #include "templateextractors.h"
 
@@ -83,16 +84,16 @@
 //----------------------------------------------------------------------------
 int FCalcPulseTemplate(
-    TString     InRootFileName        = "20111109_006.pulses.root",
-    TString     InputPath           = "../analysis/FPulseTemplate/20111109_006/",
+    TString     InRootFileName        = "pulseoverlay.root",
+    TString     InputPath           = "/home_nfs/isdc/jbbuss/analysis/FPulseTemplate/20111109_006/Overlay/",
     TString     OutputRootFileName     = "20111109_006.pulses.root",
-    TString     OutPutPath          = "../analysis/FPulseTemplate/20111109_006/Templates/",
+    TString     OutPutPath          = "/home_nfs/isdc/jbbuss/analysis/FPulseTemplate/20111109_006/Template/",
     bool        ProduceGraphic      = false,
-    bool        fitdata             = false,
+//    bool        fitdata             = false,
     bool        stats               = false,
     bool        debugPixel          = false,
     int         pixelSetSize        = 40,
     int         maxPulseOrder       = 3,
-    int         refresh_rate        = 500,      //refresh rate for canvases
-    int         verbosityLevel      = 0,        // different verbosity levels can be implemented here
+//    int         refresh_rate        = 500,      //refresh rate for canvases
+    int         verbosityLevel      = 4,        // different verbosity levels can be implemented here
     int         firstpixel          = 0,
     int         npixel              = -1
@@ -103,6 +104,11 @@
 //	Open-Root-File Settings
 //----------------------------------------------------------------------------
-    TFile * inputRootFile = OpenRootFile( InputPath, InRootFileName, verbosityLevel );
-
+    if (verbosityLevel > 0)
+    {
+        cout << endl << "...load root file" << endl;
+    }
+
+    TFile * inputRootFile   = OpenRootFile( InputPath, InRootFileName, verbosityLevel );
+    TFile * outputRootFile  = OpenRootFile( OutPutPath, OutputRootFileName, verbosityLevel );
 //----------------------------------------------------------------------------
 //	global variable Settings
@@ -124,7 +130,12 @@
 //	root global Settings
 //----------------------------------------------------------------------------
+    if (verbosityLevel > 0)
+    {
+        cout << endl << "...setting up root environment" ;
+    }
+
     gStyle->SetPalette(1,0);
     gROOT->SetStyle("Plain");
-    gPad->SetGrid();
+//    gPad->SetGrid();
 
 
@@ -133,7 +144,11 @@
 //	root Canvas Settings
 //----------------------------------------------------------------------------
+    if (verbosityLevel > 0)
+    {
+        cout << endl << "...preparing canvases" << endl;
+    }
 
     //Canvas Pad numbering
-    int pulsesCanvasFrameNrs[4] = {
+    int PixelCanvasFrameNrs[4] = {
         1,  // Top left
         2,  // Top right
@@ -143,5 +158,5 @@
 
     //Canvas Pad numbering
-    int distributionCanvasFrameNrs[4] = {
+    int AllpixelCanvasFrameNrs[4] = {
         1,  // Top left
         2,  // Top right
@@ -208,4 +223,9 @@
 // Initialize Pixel
 //----------------------------------------------------------------------------
+    if (verbosityLevel > 0)
+    {
+        cout << endl << "...preparing pixels" << endl;
+    }
+
     Pixel** pixel = new Pixel*[NPIX];
 
@@ -215,4 +235,7 @@
     }
 
+    PixelSum* wholeCamera = NULL;
+
+    bool first_pass = true;
 //-------------------------------------
 // Loop over Pixel Sets
@@ -227,5 +250,5 @@
                  << "...processing Pixel: "
                  << firstPixelOfSet
-                 << "to Pixel: "
+                 << " to Pixel: "
                  << firstPixelOfSet+pixelSetSize-1 << endl;
         }
@@ -254,4 +277,8 @@
             // Create individual Pixel
             //-------------------------------------
+            if (verbosityLevel > 3)
+            {
+                cout << "...creating pixel: " << pixelID << endl;
+            }
            pixel[pixelID] = new Pixel(
                        pixelID,
@@ -264,4 +291,26 @@
             if (breakout)   break;
 
+            //Preparing Camera
+            if (first_pass)
+            {
+                if (verbosityLevel > 0)
+                {
+                    cout << endl << "...preparing camera" << endl;
+                }
+                wholeCamera = new PixelSum(
+                            "AllPixel",
+                            1440,
+                            maxPulseOrder,
+                            verbosityLevel,
+                            stats,
+                            outputRootFile,
+                            pixel[pixelID]->mPixelOverlayXaxisLeft,
+                            pixel[pixelID]->mPixelOverlayXaxisRight ,
+                            pixel[pixelID]->mBSLMean ,
+                            pixel[pixelID]->mGainMean ,
+                            pixel[pixelID]->mOptions
+                            );
+                first_pass = false;
+            }
             //-------------------------------------
             // Histogramms of Maximas in Overlay Spectra
@@ -280,11 +329,14 @@
                          << firstPixelOfSet+pixelSetSize-1
                          << " Pixel: " << pixelID
-                         << "/" << firstpixel + npixel -1 << endl
-                         << " Pulse-Order: " << pulse_order;
+                         << "/" << firstpixel + npixel -1
+                         << " Pulse-Order: " << pulse_order << endl;
                 }
 
                 // Calculate Max Prop. Value of each slice
                 //-------------------------------------
-
+                if (verbosityLevel > 2)
+                {
+                    cout << "...extracting templates from Maximum Overlay " << endl;
+                }
                 //from Maximum Overlay
                 ExtractPulseTemplate(
@@ -295,4 +347,8 @@
                             );
 
+                if (verbosityLevel > 2)
+                {
+                    cout << "...extracting templates from Edge Overlay " << endl;
+                }
                 //from Edge Overlay
                 ExtractPulseTemplate(
@@ -321,12 +377,31 @@
                 pixel[pixelID]->DrawTemplateHistograms(
                             cgpPixelPulses,
-                            pulsesCanvasFrameNrs
+                            PixelCanvasFrameNrs
                             );
 
                 pixel[pixelID]->DrawEdgeTemplateHistograms(
                             cgpPixelPulses,
-                            pulsesCanvasFrameNrs
-                            );
-
+                            PixelCanvasFrameNrs
+                            );
+
+                //-------------------------------------
+                // Fill Histogramms of Camera
+                //-------------------------------------
+
+                wholeCamera->hMaxOverlay[pulse_order]->Add(
+                            pixel[pixelID]->hMaxOverlay[pulse_order]
+                            );
+
+                wholeCamera->hMaxProfile[pulse_order]->Add(
+                            pixel[pixelID]->hMaxProfile[pulse_order]
+                            );
+
+                wholeCamera->hEdgeOverlay[pulse_order]->Add(
+                            pixel[pixelID]->hEdgeOverlay[pulse_order]
+                            );
+
+                wholeCamera->hEdgeProfile[pulse_order]->Add(
+                            pixel[pixelID]->hEdgeProfile[pulse_order]
+                            );
 
 
@@ -357,4 +432,9 @@
             }
 
+
+
+            //deleteCurrent Pixel from Heap
+            delete pixel[pixelID];
+
             if (verbosityLevel > 2)
             {
@@ -386,4 +466,59 @@
 //-------------------------------------
 
+    for ( int pulse_order = 0 ;
+          pulse_order < wholeCamera->mMaxPulseOrder ;
+          pulse_order ++)
+    {
+        if (verbosityLevel > 2)
+        {
+            cout << "-------------------------------------" << endl
+                 << "...processing Pulse-Order: " << pulse_order;
+        }
+
+        // Calculate Max Prop. Value of each slice
+        //-------------------------------------
+
+        //from Maximum Overlay
+        ExtractPulseTemplate(
+                    wholeCamera,
+                    "Maximum",
+                    pulse_order,
+                    verbosityLevel
+                    );
+
+        //from Edge Overlay
+        ExtractPulseTemplate(
+                    wholeCamera,
+                    "Edge",
+                    pulse_order,
+                    verbosityLevel
+                    );
+
+        WritePixelTemplateToCsv(
+                    wholeCamera,
+                    OutPutPath,
+                    "Maximum",
+                    pulse_order,
+                    verbosityLevel
+                    );
+
+        WritePixelTemplateToCsv(
+                    wholeCamera,
+                    OutPutPath,
+                    "Edge",
+                    pulse_order,
+                    verbosityLevel
+                    );
+
+        wholeCamera->DrawTemplateHistograms(
+                    cgpPixelPulses,
+                    PixelCanvasFrameNrs
+                    );
+
+        wholeCamera->DrawEdgeTemplateHistograms(
+                    cgpPixelPulses,
+                    PixelCanvasFrameNrs
+                    );
+    }
 //    SaveHistograms(     //save histograms of all pixel into output root file
 //                OutInRootFileName,
@@ -417,5 +552,9 @@
 //                );
 
+    delete pixel;
+    delete wholeCamera;
     DeletePixelCanvases( maxPulseOrder ,verbosityLevel );
+    delete inputRootFile;
+    delete outputRootFile;
     return( 0 );
 }
