Index: /fact/tools/rootmacros/PulseTemplates/pixel.C
===================================================================
--- /fact/tools/rootmacros/PulseTemplates/pixel.C	(revision 13658)
+++ /fact/tools/rootmacros/PulseTemplates/pixel.C	(revision 13659)
@@ -1,5 +1,3 @@
 #include <iostream>
-#include "TObjArray.h"
-#include "TCanvas.h"
 
 #include "rootfilehandler.h"
@@ -11,38 +9,4 @@
 //============================= LIFECYCLE ====================================
 
-Pixel::Pixel(
-        TString     pixelname,
-        int         maxPulsorder,
-        int         verbosityLevel,
-        bool        stats,
-        TFile*      filename
-        )
-{
-    mConstructorType        = 1;        //important for deletion 0 delete distribution 1 delete TemplateHistos
-    mChid                   = -1;
-    mName                   = pixelname;
-    mStats                  = stats;
-    mMaxPulseOrder          = maxPulsorder;
-    mVerbosityLevel         = verbosityLevel;
-    mRootFile               = filename;
-
-    hMaxOverlay  = new TH2F*[mMaxPulseOrder];
-    hEdgeOverlay = new TH2F*[mMaxPulseOrder];
-    hMaxProfile  = new TProfile*[mMaxPulseOrder];
-    hEdgeProfile = new TProfile*[mMaxPulseOrder];
-
-    hPixelMax  = new TH1F*[mMaxPulseOrder];
-    hPixelMedian = new TH1F*[mMaxPulseOrder];
-    hPixelMean  = new TH1F*[mMaxPulseOrder];
-
-    hPixelEdgeMax  = new TH1F*[mMaxPulseOrder];
-    hPixelEdgeMedian = new TH1F*[mMaxPulseOrder];
-    hPixelEdgeMean  = new TH1F*[mMaxPulseOrder];
-
-    hList           = new TObjArray;
-
-    BookPixelHistos();
-    BookTemplateHistos();
-}
 
 Pixel::Pixel(
@@ -161,4 +125,186 @@
 
 //============================= OPERATIONS ===================================
+void
+Pixel::DrawOverlayHistograms(
+        TCanvas**    pixelCanvas,
+        int*        histoFrameNr
+        )
+{
+    if (mVerbosityLevel > 2) cout << endl << "...drawing pulse histograms" ;
+    for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
+    {
+        pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
+        hMaxOverlay[pulse_order]->Draw("COLZ");
+        pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
+        hMaxProfile[pulse_order]->Draw();
+        hEdgeProfile[pulse_order]->Draw("SAME");
+
+        pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
+        hEdgeOverlay[pulse_order]->Draw("COLZ");
+    }
+}
+// end of DrawOverlayHistograms
+//----------------------------------------------------------------------------
+
+void
+Pixel::DrawDistributionHistograms(
+        TCanvas**    pixelCanvas,
+        int*        histoFrameNr
+        )
+{
+    if (mVerbosityLevel > 2) cout << endl << "...drawing distribution histograms" ;
+    bool nothing_to_fill = true;
+    for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
+    {
+        if (mOptions.Contains("S") )
+        {
+        pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
+        hSlopeRisingEdge[pulse_order]->Draw();
+        nothing_to_fill = false;
+        }
+
+        if (mOptions.Contains("R") )
+        {
+        pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
+        hRisingEdgeToMax[pulse_order]->Draw();
+        nothing_to_fill = false;
+        }
+
+        if (mOptions.Contains("M") )
+        {
+        pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
+        hPosOfMax[pulse_order]->Draw();
+        nothing_to_fill = false;
+        }
+
+    }
+    if (nothing_to_fill)
+    {
+        cout << endl << "there were NO DISTRIBUTION HISTOGRAMS to fill" << endl;
+    }
+}
+// end of DrawDistributionHistograms
+//----------------------------------------------------------------------------
+
+void
+Pixel::DrawTemplateHistograms(
+        TCanvas**    pixelCanvas,
+        int*        histoFrameNr
+        )
+{
+    if (mVerbosityLevel > 2) cout << endl << "...drawing Template histograms" ;
+    for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
+    {
+        pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
+        hPixelMax[pulse_order]->Draw();
+
+        pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
+        hPixelMedian[pulse_order]->Draw();
+
+        pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
+        hPixelMean[pulse_order]->Draw();
+
+    }
+}
+// end of DrawTemplateHistograms
+//----------------------------------------------------------------------------
+
+void
+Pixel::DrawEdgeTemplateHistograms(
+        TCanvas**    pixelCanvas,
+        int*        histoFrameNr
+        )
+{
+    if (mVerbosityLevel > 2) cout << endl << "...drawing Template histograms" ;
+    for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
+    {
+        pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
+        hPixelEdgeMax[pulse_order]->Draw();
+
+        pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
+        hPixelEdgeMedian[pulse_order]->Draw();
+
+        pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
+        hPixelEdgeMean[pulse_order]->Draw();
+
+    }
+}
+// end of DrawTemplateHistograms
+//----------------------------------------------------------------------------
+
+
+
+
+void
+Pixel::SavePixelHistograms(
+        TString outRootFileName,
+        bool        saveResults
+        )
+{
+    if (mVerbosityLevel > 2) cout << endl << "Saving histograms of Pixel# " << mChid;
+    if (!saveResults) return;
+    SaveHistograms(
+            outRootFileName,
+            CreateSubDirName( mChid ),
+            hList,
+            saveResults,
+            mVerbosityLevel
+            );
+}
+// end of SavePixelHistograms
+//----------------------------------------------------------------------------
+
+
+
+TString
+Pixel::HistoName(
+        TString     histoname,
+        int         order
+        )
+{
+    histoname +=   mChid;
+    histoname +=   "_";
+    histoname +=   order;
+    return histoname;
+}
+
+TString
+Pixel::HistoTitle(
+        TString     histo_title,
+        int         order
+        )
+{
+    histo_title +=   " [Pixel_Order] ";
+    histo_title +=   mChid;
+    histo_title +=   "_";
+    histo_title +=   order;
+    return histo_title;
+}
+
+TString
+Pixel::CsvFileName(
+        TString     path,
+        TString     overlayMethod,
+        int         order
+        )
+{
+    path += "CSV/";
+    path += overlayMethod;
+    path += "OverlayTemplate";
+    path += "_";
+    path +=   mChid;
+    path +=   "_";
+    path +=   order;
+    path +=   ".csv";
+    return path;
+}
+
+
+//============================= ACESS      ===================================
+//============================= INQUIRY    ===================================
+/////////////////////////////// PROTECTED  ///////////////////////////////////
+
+/////////////////////////////// PRIVATE    ///////////////////////////////////
+
 void
 Pixel::BookPixelHistos()
@@ -492,111 +638,27 @@
 //----------------------------------------------------------------------------
 
-
-void
-Pixel::DrawOverlayHistograms(
-        TCanvas**    pixelCanvas,
-        int*        histoFrameNr
-        )
-{
-    if (mVerbosityLevel > 2) cout << endl << "...drawing pulse histograms" ;
-    for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
-    {
-        pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
-        hMaxOverlay[pulse_order]->Draw("COLZ");
-        pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
-        hMaxProfile[pulse_order]->Draw();
-        hEdgeProfile[pulse_order]->Draw("SAME");
-
-        pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
-        hEdgeOverlay[pulse_order]->Draw("COLZ");
-    }
-}
-// end of DrawOverlayHistograms
-//----------------------------------------------------------------------------
-
-void
-Pixel::DrawDistributionHistograms(
-        TCanvas**    pixelCanvas,
-        int*        histoFrameNr
-        )
-{
-    if (mVerbosityLevel > 2) cout << endl << "...drawing distribution histograms" ;
-    bool nothing_to_fill = true;
-    for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
-    {
-        if (mOptions.Contains("S") )
-        {
-        pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
-        hSlopeRisingEdge[pulse_order]->Draw();
-        nothing_to_fill = false;
-        }
-
-        if (mOptions.Contains("R") )
-        {
-        pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
-        hRisingEdgeToMax[pulse_order]->Draw();
-        nothing_to_fill = false;
-        }
-
-        if (mOptions.Contains("M") )
-        {
-        pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
-        hPosOfMax[pulse_order]->Draw();
-        nothing_to_fill = false;
-        }
-
-    }
-    if (nothing_to_fill)
-    {
-        cout << endl << "there were NO DISTRIBUTION HISTOGRAMS to fill" << endl;
-    }
-}
-// end of DrawDistributionHistograms
-//----------------------------------------------------------------------------
-
-void
-Pixel::DrawTemplateHistograms(
-        TCanvas**    pixelCanvas,
-        int*        histoFrameNr
-        )
-{
-    if (mVerbosityLevel > 2) cout << endl << "...drawing Template histograms" ;
-    for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
-    {
-        pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
-        hPixelMax[pulse_order]->Draw();
-
-        pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
-        hPixelMedian[pulse_order]->Draw();
-
-        pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
-        hPixelMean[pulse_order]->Draw();
-
-    }
-}
-// end of DrawTemplateHistograms
-//----------------------------------------------------------------------------
-
-void
-Pixel::DrawEdgeTemplateHistograms(
-        TCanvas**    pixelCanvas,
-        int*        histoFrameNr
-        )
-{
-    if (mVerbosityLevel > 2) cout << endl << "...drawing Template histograms" ;
-    for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
-    {
-        pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
-        hPixelEdgeMax[pulse_order]->Draw();
-
-        pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
-        hPixelEdgeMedian[pulse_order]->Draw();
-
-        pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
-        hPixelEdgeMean[pulse_order]->Draw();
-
-    }
-}
-// end of DrawTemplateHistograms
+void
+Pixel::LoadPulseHistos()
+{
+    mRootFile->cd();
+    mRootFile->cd(CreateSubDirName( mChid ));
+    if (mVerbosityLevel > 2) cout << endl << "...load pixel histograms" << endl;
+    for (int order = 0; order < mMaxPulseOrder; order++)
+    {
+
+        if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hMaxOverlay", order) << endl;
+        hMaxOverlay[order]  = (TH2F*)mRootFile->Get( HistoName("hMaxOverlay", order) );
+
+        if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hEdgeOverlay", order) << endl;
+        hEdgeOverlay[order] = (TH2F*)mRootFile->Get( HistoName("hEdgeOverlay", order) );
+
+        if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hMaxProfile", order) << endl;
+        hMaxProfile[order]  = (TProfile*)mRootFile->Get( HistoName("hMaxProfile", order) );
+
+        if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hEdgeProfile", order) << endl;
+        hEdgeProfile[order] = (TProfile*)mRootFile->Get( HistoName("hEdgeProfile", order) );
+    }
+}
+// end of LoadPulseHistos
 //----------------------------------------------------------------------------
 
@@ -741,9 +803,5 @@
         if (mVerbosityLevel > 3)
         cout << endl << "\t\t...deleting hPixelMax"
-                                      << mChid << "_" << order
-                                      << " hPixelMax[order] adr " << hPixelMax[order]
-                                      << " hPixelMax adr " << hPixelMax
-                                         ;
-
+                                      << mChid << "_" << order;
         delete hPixelMax[order];
         hPixelMax[order] = NULL;
@@ -828,93 +886,110 @@
 
 void
-Pixel::SavePixelHistograms(
-        TString outRootFileName,
-        bool        saveResults
-        )
-{
-    if (mVerbosityLevel > 2) cout << endl << "Saving histograms of Pixel# " << mChid;
-    if (!saveResults) return;
-    SaveHistograms(
-            outRootFileName,
-            CreateSubDirName( mChid ),
-            hList,
-            saveResults,
-            mVerbosityLevel
-            );
-}
-// end of SavePixelHistograms
-//----------------------------------------------------------------------------
-
-void
-Pixel::LoadPulseHistos()
-{
-    mRootFile->cd();
-    mRootFile->cd(CreateSubDirName( mChid ));
-    for (int order = 0; order < mMaxPulseOrder; order++)
-    {
-        hMaxOverlay[order]  = (TH2F*)mRootFile->Get( HistoName("hMaxOverlay", order) );
-        hEdgeOverlay[order] = (TH2F*)mRootFile->Get( HistoName("hEdgeOverlay", order) );
-        hMaxProfile[order]  = (TProfile*)mRootFile->Get( HistoName("hMaxProfile", order) );
-        hEdgeProfile[order] = (TProfile*)mRootFile->Get( HistoName("hEdgeProfile", order) );
-    }
-}
-// end of LoadPulseHistos
-//----------------------------------------------------------------------------
-
-TString
-Pixel::HistoName(
-        TString     histoname,
-        int         order
-        )
-{
-    histoname +=   mChid;
-    histoname +=   "_";
-    histoname +=   order;
-    return histoname;
-}
-
-TString
-Pixel::HistoTitle(
-        TString     histo_title,
-        int         order
-        )
-{
-    histo_title +=   " [Pixel_Order] ";
-    histo_title +=   mChid;
-    histo_title +=   "_";
-    histo_title +=   order;
-    return histo_title;
-}
-
-TString
-Pixel::CsvFileName(
-        TString     path,
-        TString     overlayMethod,
-        int         order
-        )
-{
-    path += "CSV/";
-    path += overlayMethod;
-    path += "OverlayTemplate";
-    path += "_";
-    path +=   mChid;
-    path +=   "_";
-    path +=   order;
-    path +=   ".csv";
-    return path;
-}
-
-
-//============================= ACESS      ===================================
-//============================= INQUIRY    ===================================
-/////////////////////////////// PROTECTED  ///////////////////////////////////
-
-/////////////////////////////// PRIVATE    ///////////////////////////////////
-
-
-
-
-
-
-
-
+Pixel::MakeTH1Pretty(
+        TH1*                histo,
+        TString             histName,
+        TString             histTitle,
+        int                 order
+        )
+{
+    if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName(histName, order) << endl;
+
+    histo->SetNameTitle(
+                HistoName(histName, order),
+                HistoTitle(histTitle, order)
+                );
+
+    histo->SetBins(
+                mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
+                (-1*mPixelOverlayXaxisLeft)-0.5,
+                mPixelOverlayXaxisRight-0.5
+                );
+
+    histo->SetAxisRange(
+                        mBSLMean - 5,
+                        (mGainMean*(order+1)) + 10,
+                        "Y");
+
+    histo->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
+    histo->GetYaxis()->SetTitle( "Amplitude [mV]" );
+    //histo->SetBit(TH2F::kCanRebin);
+    histo->SetStats(mStats);
+}
+// end of MakeTH2Pretty
+//----------------------------------------------------------------------------
+
+
+void
+Pixel::MakeTH2Pretty(
+        TH2*                histo,
+        TString             histName,
+        TString             histTitle,
+        int                 order
+        )
+{
+    if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName(histName, order) << endl;
+
+    histo->SetNameTitle(
+                HistoName(histName, order),
+                HistoTitle(histTitle, order)
+                );
+
+    histo->SetBins(
+                mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
+                (-1*mPixelOverlayXaxisLeft)-0.5,
+                mPixelOverlayXaxisRight-0.5 ,
+                512,
+                -55.5,
+                200.5
+                );
+
+    histo->SetAxisRange(
+                        mBSLMean - 5,
+                        (mGainMean*(order+1)) + 10,
+                        "Y");
+
+    histo->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
+    histo->GetYaxis()->SetTitle( "Amplitude [mV]" );
+    //histo->SetBit(TH2F::kCanRebin);
+    histo->SetStats(mStats);
+}
+// end of MakeTH2Pretty
+//----------------------------------------------------------------------------
+
+void
+Pixel::MakeTProfilePretty(
+        TProfile*           histo,
+        TString             histName,
+        TString             histTitle,
+        int                 order
+        )
+{
+    if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName(histName, order) << endl;
+
+    histo->SetNameTitle(
+                HistoName(histName, order),
+                HistoTitle(histTitle, order)
+                );
+
+    histo->SetBins(
+                mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
+                (-1*mPixelOverlayXaxisLeft)-0.5,
+                mPixelOverlayXaxisRight-0.5
+                );
+    histo->SetOption( "s" );
+
+    histo->SetAxisRange(
+                        mBSLMean - 5,
+                        (mGainMean*(order+1)) + 10,
+                        "Y");
+
+    histo->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
+    histo->GetYaxis()->SetTitle( "Amplitude [mV]" );
+    //histo->SetBit(TH2F::kCanRebin);
+    histo->SetStats(mStats);
+}
+// end of MakeTProfilePretty
+//----------------------------------------------------------------------------
+
+
+
