Index: fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 14811)
+++ fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C	(revision 14943)
@@ -96,23 +96,53 @@
 //----------------------------------------------------------------------------
 int FCalcPulseTemplate(
-    TString     InRootFileName        = "20120802templ_0mV_entries.root",
-//    TString     InRootFileName        = "20120309_032.root",
-//    TString     InputPath           = "analysis/analysis/FPulseTemplate/20120309_017/Overlay/",
-    TString     InputPath           = "",
-//    TString     InputPath           = "analysis/analysis/FPulseTemplate/20120309_032/Overlay/",
-    TString     OutputRootFileName     = "test.root",
-    TString     OutPutPath          = "",
-    int         firstpixel          = 0,
-    int         npixel              = 1,
-    int         pixelSetSize        = 200,
-    int         maxPulseOrder       = 1,
-//    TString     histoOptions        = "SRM",
-    bool        ProduceGraphic      = true,
-    bool        stats               = true,
-    bool        saveResults         = false,
-//    bool        fitdata             = false,
-    bool        debugPixel          = true,
-//    int         refresh_rate        = 500,      //refresh rate for canvases
-    int         verbosityLevel      = 1        // different verbosity levels can be implemented here
+
+        // ------------{ Files }------------
+//        TString     InRootFileName        = "20120802_0mV_newSelectAlg.root",
+        TString     InRootFileName          = "20120802_0mV_Stacking_G11B-2AWW8.root",
+//        TString     InRootFileName          = "20120802_200mV_Stacking_G13B-2AWW8.root",
+        TString     InputPath               = "analysis/PulsTemplateAnalysis/20120802/",
+        TString     OutputRootFileName      = "20120802_0mV_Extraction_G11B-2AWW8_model2.root",
+//        TString     OutputRootFileName      = "20120802_200mV_Extraction_G13B-2AWW8_model0.root",
+        TString     OutPutPath              = "analysis/PulsTemplateAnalysis/20120802/",
+        //    TString     InRootFileName        = "20120309_032.root",
+        //    TString     InRootFileName        = "20120309_017.root",
+        //    TString     InputPath           = "analysis/analysis/FPulseTemplate/20120309_017/Overlay/",
+        //    TString     InputPath           = "analysis/analysis/FPulseTemplate/20120309_032/Overlay/",
+        // ------------{ data quantity }------------
+        int     firstpixel              = 0,
+        int     npixel                  = 1,
+        int     pixelSetSize            = 200,
+        int     maxPulseOrder           = 6,
+        // ------------{ analysis parameters }------------
+        float   meanGain                = 11.,
+        float   meanBsl                 = -2.5,
+        int     bootstrapIt             = 10,
+        int     pulseModell             = 0,
+        float   pixelOverlayXaxisLeft   = 0,
+        float   pixelOverlayXaxisRight  = 400,
+
+        // ------------{ program options }------------
+        //    TString     histoOptions        = "SRM",
+
+        // show graphical output
+        bool        ProduceGraphic      = true,
+
+        // show stats in plots
+        bool        stats               = true,
+
+        // save data
+        bool        saveResults         = false,
+        //    bool        fitdata             = false,
+
+        //pause after each pixel
+        bool        debugPixel          = true,
+
+        //refresh rate for canvases
+        //    int         refresh_rate        = 500,
+
+        TString fitOption = "Q",
+
+        // different verbosity levels can be set here
+        int         verbosityLevel      = 1
         )
 {
@@ -265,4 +295,5 @@
     TH1D hAmplitude[maxPulseOrder];
     TH1D hRiseTime[maxPulseOrder];
+    TList* histoList = new TList();
 
     //Lopp over pulse order configure distribution histograms
@@ -272,49 +303,64 @@
         TString title;
         title = "hBSL";
-        title.Append(i);
+        title += "_";
+        title += i;
         hBsl[i].SetNameTitle(title, title);
-        hBsl[i].SetBins(400, -2-0.005, 2-0.005);
-
+        hBsl[i].SetBins(800, -4-0.005, 4-0.005);
+        histoList->Add( &hBsl[i] );
         //Asymptote
         title = "hAsymptote";
-        title.Append(i);
+        title += "_";
+        title += i;
         hAsymptote[i].SetNameTitle(title, title);
         hAsymptote[i].SetBins(60, -10.5, 49.5);
+        histoList->Add( &hAsymptote[i] );
 
         //T0
         title = "hT0";
-        title.Append(i);
+        title += "_";
+        title += i;
         hT0[i].SetNameTitle(title, title);
         hT0[i].SetBins(80, 39.5, 119.5);
+        histoList->Add( &hT0[i] );
 
         //Tau1
         title = "hTau1";
-        title.Append(i);
+        title += "_";
+        title += i;
         hTau1[i].SetNameTitle(title, title);
         hTau1[i].SetBins(10, -10.5, 9.5);
+        histoList->Add( &hTau1[i] );
 
         //Tau2
         title = "hTau2";
-        title.Append(i);
+        title += "_";
+        title += i;
         hTau2[i].SetNameTitle(title, title);
         hTau2[i].SetBins(40, 19.5, 59.5);
+        histoList->Add( &hTau2[i] );
 
         //Integral
         title = "hIntegral";
-        title.Append(i);
+        title += "_";
+        title += i;
         hIntegral[i].SetNameTitle(title, title);
         hIntegral[i].SetBins(500, (i+1)*-0.5, (i+1)*499.5);
+        histoList->Add( &hIntegral[i] );
 
         //Amplitude
         title = "hAmplitude";
-        title.Append(i);
+        title += "_";
+        title += i;
         hAmplitude[i].SetNameTitle(title, title);
         hAmplitude[i].SetBins(400, (i+1)*4.95, (i+1)*24.95);
+        histoList->Add( &hAmplitude[i] );
 
         //hRiseTime
         title = "hRiseTime";
-        title.Append(i);
+        title += "_";
+        title += i;
         hRiseTime[i].SetNameTitle(title, title);
         hRiseTime[i].SetBins(20, -0, 10);
+        histoList->Add( &hRiseTime[i] );
     }
 
@@ -326,4 +372,5 @@
 
     //Lopp over pulse order configure distribution histograms
+    float roi = 1024.;
     for (int i = 0; i<maxPulseOrder; i++)
     {
@@ -331,19 +378,22 @@
         TString title;
         title = "hMedianErrors";
-        title.Append(i);
+        title += "_";
+        title += i;
         hMedianErrors[i].SetNameTitle(title, title);
-        hMedianErrors[i].SetBins(300, -0.5, 300.5);
+        hMedianErrors[i].SetBins(roi, -0.5, roi + 0.5);
 
         //hMeanErrors
         title = "hMeanErrors";
-        title.Append(i);
+        title += "_";
+        title += i;
         hMeanErrors[i].SetNameTitle(title, title);
-        hMeanErrors[i].SetBins(300, -0.5, 300.5);
+        hMeanErrors[i].SetBins(roi, -0.5, roi + 0.5);
 
         //hMaxErrors
         title = "hMaxErrors";
-        title.Append(i);
+        title += "_";
+        title += i;
         hMaxErrors[i].SetNameTitle(title, title);
-        hMaxErrors[i].SetBins(300, -0.5, 300.5);
+        hMaxErrors[i].SetBins(roi, -0.5, roi + 0.5);
     }
 
@@ -355,12 +405,15 @@
     grPheVsAmpl.SetNameTitle("grPheVsAmpl", "Distribution of Pulse Amplitude vs. Photon equivalent");
     grPheVsAmpl.SetMarkerStyle(21);
+    histoList->Add( &grPheVsAmpl );
 
     TGraphErrors grPheVsIntegral;
     grPheVsIntegral.SetNameTitle("grPheVsIntegral", "Distribution of Pulse Integral vs. Photon equivalent");
     grPheVsIntegral.SetMarkerStyle(21);
+    histoList->Add( &grPheVsIntegral );
 
     TGraphErrors grPheVsTau2;
     grPheVsTau2.SetNameTitle("grPheVsTau2", "Distribution of Tau2 vs. Photon equivalent");
     grPheVsTau2.SetMarkerStyle(21);
+    histoList->Add( &grPheVsTau2 );
 //-----------------------------------------------------------------------------
 // Variables
@@ -462,8 +515,8 @@
                        stats,
                        "L",
-                       70,   //pixelOverlayXaxisLeft /TODO: get it from the root file
-                       230,  //pixelOverlayXaxisRight /TODO: get it from the root file
-                       -1,   //bslMean   /TODO: get it from the root file
-                       9,    //gain mean /TODO: get it from the root file
+                       pixelOverlayXaxisLeft,   //TODO: get it from the root file
+                       pixelOverlayXaxisRight,  //TODO: get it from the root file
+                       meanBsl,   //bslMean     /TODO: get it from the root file
+                       meanGain,    //gain mean /TODO: get it from the root file
                        inputRootFile,
                        outputRootFile
@@ -472,28 +525,4 @@
             if (breakout)   break;
 
-            //Preparing Camera
-            if (first_pass)
-            {
-                if (verbosityLevel > 0)
-                {
-                    cout << endl << "...preparing camera" << endl;
-                }
-
-                wholeCamera = new PixelSum(
-                            "AllPixel",
-                            1440,
-                            maxPulseOrder,
-                            verbosityLevel,
-                            stats,
-                            "C",
-                            pixel[pixelID]->mPixelOverlayXaxisLeft,
-                            pixel[pixelID]->mPixelOverlayXaxisRight ,
-                            pixel[pixelID]->mBSLMean ,
-                            pixel[pixelID]->mGainMean ,
-                            outputRootFile
-                            );
-
-                first_pass = false;
-            }
             //-------------------------------------
             // Histogramms of Maximas in Overlay Spectra
@@ -521,4 +550,6 @@
                 //-------------------------------------
 
+//                pixel[pixelID]->Normalize2Dhistos(pulse_order);
+
                 //from Maximum Overlay
                 if (verbosityLevel > 2)
@@ -550,4 +581,7 @@
                             );
 
+                pixel[pixelID]->SetRangeUser(pixelOverlayXaxisLeft, pixelOverlayXaxisRight, pulse_order);
+
+
                 PixelCsv.WritePointSet(
                             pixel[pixelID],
@@ -618,22 +652,22 @@
 
 //                pulses.cd(1);
-                Pulse maxMaxPulse("maxMaxPulse", pixel[pixelID]->hPixelMax[pulse_order], "Q", 1,pulse_order);
+                Pulse maxMaxPulse("maxMaxPulse", pixel[pixelID]->hPixelMax[pulse_order], fitOption, pulseModell,pulse_order);
                 pulseFits[0] = &maxMaxPulse;
 
 //                pulses.cd(2);
-                Pulse maxMedianPulse("maxMedianPulse", pixel[pixelID]->hPixelMedian[pulse_order], "Q",1,pulse_order);
+                Pulse maxMedianPulse("maxMedianPulse", pixel[pixelID]->hPixelMedian[pulse_order], fitOption,pulseModell,pulse_order);
                 pulseFits[1] = &maxMedianPulse;
 
 //                pulses.cd(3);
-                Pulse maxMeanPulse("maxMeanPulse", pixel[pixelID]->hPixelMean[pulse_order], "Q",1,pulse_order);
+                Pulse maxMeanPulse("maxMeanPulse", pixel[pixelID]->hPixelMean[pulse_order], fitOption,pulseModell,pulse_order);
                 pulseFits[2] = &maxMeanPulse;
 
-                Pulse edgeMaxPulse("edgeMaxPulse", pixel[pixelID]->hPixelEdgeMax[pulse_order], "Q",1,pulse_order);
+                Pulse edgeMaxPulse("edgeMaxPulse", pixel[pixelID]->hPixelEdgeMax[pulse_order], fitOption,pulseModell,pulse_order);
                 pulseFits[3] = &edgeMaxPulse;
 
-                Pulse edgeMedianPulse("edgeMedianPulse", pixel[pixelID]->hPixelEdgeMedian[pulse_order], "Q",1,pulse_order);
+                Pulse edgeMedianPulse("edgeMedianPulse", pixel[pixelID]->hPixelEdgeMedian[pulse_order], fitOption,pulseModell,pulse_order);
                 pulseFits[4] = &edgeMedianPulse;
 
-                Pulse edgeMeanPulse("edgeMeanPulse", pixel[pixelID]->hPixelEdgeMean[pulse_order], "Q",1,pulse_order);
+                Pulse edgeMeanPulse("edgeMeanPulse", pixel[pixelID]->hPixelEdgeMean[pulse_order], fitOption,pulseModell,pulse_order);
                 pulseFits[5] = &edgeMeanPulse;
 
@@ -754,4 +788,30 @@
 //                            verbosityLevel
 //                            );
+
+                //Preparing Camera
+                if (first_pass)
+                {
+                    if (verbosityLevel > 0)
+                    {
+                        cout << endl << "...preparing camera" << endl;
+                    }
+
+                    wholeCamera = new PixelSum(
+                                "AllPixel",
+                                1440,
+                                maxPulseOrder,
+                                verbosityLevel,
+                                stats,
+                                "C",
+                                pixel[pixelID]->mPixelOverlayXaxisLeft,
+                                pixel[pixelID]->mPixelOverlayXaxisRight ,
+                                pixel[pixelID]->mBSLMean ,
+                                pixel[pixelID]->mGainMean ,
+                                outputRootFile
+                                );
+
+                    first_pass = false;
+                }
+
                 //-------------------------------------
                 // Fill Histogramms of Camera
@@ -897,5 +957,5 @@
                     "Maximum",
                     pulse_order,
-                    10,
+                    bootstrapIt,
                     verbosityLevel
                     );
@@ -916,5 +976,5 @@
                     "Edge",
                     pulse_order,
-                    10,
+                    bootstrapIt,
                     verbosityLevel
                     );
@@ -959,22 +1019,22 @@
 
         pulses.cd(1);
-        Pulse maxCamMaxPulse("maxMaxPulse", wholeCamera->hPixelMax[pulse_order], "Q", 1);
+        Pulse maxCamMaxPulse("maxMaxPulse", wholeCamera->hPixelMax[pulse_order], "Q", pulseModell);
         allPulseFits[0] = &maxCamMaxPulse;
 
         pulses.cd(2);
-        Pulse maxCamMedianPulse("maxMedianPulse", wholeCamera->hPixelMedian[pulse_order], "Q", 1);
+        Pulse maxCamMedianPulse("maxMedianPulse", wholeCamera->hPixelMedian[pulse_order], "Q", pulseModell);
         allPulseFits[1] = &maxCamMedianPulse;
 
         pulses.cd(3);
-        Pulse maxCamMeanPulse("maxMeanPulse", wholeCamera->hPixelMean[pulse_order],"Q", 1);
+        Pulse maxCamMeanPulse("maxMeanPulse", wholeCamera->hPixelMean[pulse_order],"Q", pulseModell);
         allPulseFits[2] = &maxCamMeanPulse;
 
-        Pulse edgeCamMaxPulse("edgeMaxPulse", wholeCamera->hPixelEdgeMax[pulse_order], "Q", 1);
+        Pulse edgeCamMaxPulse("edgeMaxPulse", wholeCamera->hPixelEdgeMax[pulse_order], "Q", pulseModell);
         allPulseFits[3] = &edgeCamMaxPulse;
 
-        Pulse edgeCamMedianPulse("edgeMedianPulse", wholeCamera->hPixelEdgeMedian[pulse_order],"Q", 1);
+        Pulse edgeCamMedianPulse("edgeMedianPulse", wholeCamera->hPixelEdgeMedian[pulse_order],"Q", pulseModell);
         allPulseFits[4] = &edgeCamMedianPulse;
 
-        Pulse edgeCamMeanPulse("edgeMeanPulse", wholeCamera->hPixelEdgeMean[pulse_order], "Q", 1);
+        Pulse edgeCamMeanPulse("edgeMeanPulse", wholeCamera->hPixelEdgeMean[pulse_order], "Q", pulseModell);
         allPulseFits[5] = &edgeCamMeanPulse;
 
@@ -1061,4 +1121,14 @@
                     saveResults
                     );
+
+        SaveList(
+                outFile,
+                    "",
+                histoList,
+                saveResults,
+                verbosityLevel
+                );
+
+
     }
 
@@ -1090,4 +1160,5 @@
     delete inputRootFile;
     delete outputRootFile;
+    delete histoList;
 
     return( 0 );
