Index: fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 13656)
+++ fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 13780)
@@ -84,9 +84,9 @@
 //----------------------------------------------------------------------------
 int FCalcPulseTemplate(
-    TString     InRootFileName        = "pulseoverlay.root",
-    TString     InputPath           = "/home_nfs/isdc/jbbuss/analysis/FPulseTemplate/20111109_006/Overlay/",
-    TString     OutputRootFileName     = "20111109_006.pulses.root",
-    TString     OutPutPath          = "/home_nfs/isdc/jbbuss/analysis/FPulseTemplate/20111109_006/Template/",
-    bool        ProduceGraphic      = false,
+    TString     InRootFileName        = "20120309_018.root",
+    TString     InputPath           = "analysis/FPulseTemplate/20120309_018/Overlay/",
+    TString     OutputRootFileName     = "test.root",
+    TString     OutPutPath          = "analysis/FPulseTemplate/20120309_018/",
+    bool        ProduceGraphic      = true,
 //    bool        fitdata             = false,
     bool        stats               = false,
@@ -95,9 +95,14 @@
     int         maxPulseOrder       = 3,
 //    int         refresh_rate        = 500,      //refresh rate for canvases
-    int         verbosityLevel      = 4,        // different verbosity levels can be implemented here
+    int         verbosityLevel      = 5,        // different verbosity levels can be implemented here
     int         firstpixel          = 0,
-    int         npixel              = -1
+    int         npixel              = 2
         )
 {
+
+
+    InputPath = SetHostsPaths(true, InputPath );
+    OutPutPath = SetHostsPaths(true, OutPutPath );
+
 
 //----------------------------------------------------------------------------
@@ -286,4 +291,9 @@
                        verbosityLevel,
                        stats,
+                       "L",
+                       70,   ///TODO: get it from the root file
+                       230,  ///TODO: get it from the root file
+                       -1,   ///TODO: get it from the root file
+                       9,    ///TODO: get it from the root file
                        inputRootFile
                     );
@@ -304,10 +314,10 @@
                             verbosityLevel,
                             stats,
-                            outputRootFile,
+                            "",
                             pixel[pixelID]->mPixelOverlayXaxisLeft,
                             pixel[pixelID]->mPixelOverlayXaxisRight ,
                             pixel[pixelID]->mBSLMean ,
                             pixel[pixelID]->mGainMean ,
-                            pixel[pixelID]->mOptions
+                            outputRootFile
                             );
                 first_pass = false;
@@ -374,5 +384,6 @@
                             verbosityLevel
                             );
-
+                if (ProduceGraphic)
+                {
                 pixel[pixelID]->DrawTemplateHistograms(
                             cgpPixelPulses,
@@ -384,25 +395,33 @@
                             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;
+                }
 
             }
@@ -436,5 +455,5 @@
             //deleteCurrent Pixel from Heap
             delete pixel[pixelID];
-
+            pixel[pixelID] = NULL;
             if (verbosityLevel > 2)
             {
@@ -462,4 +481,6 @@
     }
 
+    delete[] pixel;
+    pixel = NULL;
 //-------------------------------------
 // Draw All Pixel Histograms
@@ -476,6 +497,6 @@
         }
 
-        // Calculate Max Prop. Value of each slice
-        //-------------------------------------
+//         Calculate Max Prop. Value of each slice
+//        -------------------------------------
 
         //from Maximum Overlay
@@ -511,14 +532,19 @@
                     );
 
-        wholeCamera->DrawTemplateHistograms(
-                    cgpPixelPulses,
-                    PixelCanvasFrameNrs
-                    );
-
-        wholeCamera->DrawEdgeTemplateHistograms(
-                    cgpPixelPulses,
-                    PixelCanvasFrameNrs
-                    );
-    }
+//        wholeCamera->DrawTemplateHistograms(
+//                    cgpPixelPulses,
+//                    PixelCanvasFrameNrs
+//                    );
+
+//        wholeCamera->DrawEdgeTemplateHistograms(
+//                    cgpPixelPulses,
+//                    PixelCanvasFrameNrs
+//                    );
+    } //EOF: Draw All Pixel Histograms
+
+//-------------------------------------
+// Save All Pixel Histograms
+//-------------------------------------
+
 //    SaveHistograms(     //save histograms of all pixel into output root file
 //                OutInRootFileName,
@@ -541,18 +567,14 @@
 //        UpdateCanvases(
 //                    verbosityLevel,
-//                    MAX_PULS_ORDER
+//                    MAX_PULS_ORDER,
+//                    false
 //                    );
 //    }
 
-//    WriteAllPixelTemplateToCsv(
-//                OutPutPath,
-//                "PulseTemplate_PointSet",
-//                "Maximum",
-//                verbosityLevel
-//                );
-
-    delete pixel;
     delete wholeCamera;
-    DeletePixelCanvases( maxPulseOrder ,verbosityLevel );
+    if (ProduceGraphic)
+    {
+        DeletePixelCanvases( maxPulseOrder ,verbosityLevel );
+    }
     delete inputRootFile;
     delete outputRootFile;
@@ -575,12 +597,19 @@
         )
 {
-    if (verbosityLevel > 2) cout << endl << "...delete pixel Canvases" ;
+    if (verbosityLevel > 2)
+    {
+        cout << endl << "...delete pixel Canvases" << endl;
+    }
     for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
     {
         delete cgpPixelPulses[pulse_order];
+        cgpPixelPulses[pulse_order] = NULL;
         delete cgpDistributions[pulse_order];
+        cgpDistributions[pulse_order] = NULL;
     }
     delete[] cgpPixelPulses;
+    cgpPixelPulses = NULL;
     delete[] cgpDistributions;
+    cgpDistributions = NULL;
 }
 
