Index: fact/tools/rootmacros/PulseTemplates/pixel.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/pixel.C	(revision 13465)
+++ fact/tools/rootmacros/PulseTemplates/pixel.C	(revision 13473)
@@ -19,12 +19,12 @@
 
 Pixel::Pixel(
-        int         pixelID         = 0,
-        int         maxPulsorder    = 1,
-        int         verbosityLevel  = 0,
+        int         pixelID,
+        int         maxPulsorder,
+        int         verbosityLevel,
         int         pixelOverlayXaxisLeft,
         int         pixelOverlayXaxisRight,
         int         bSLMean,
         int         gainMean,
-        const char* options         = "",
+        TString options
         )
 {
@@ -38,20 +38,32 @@
     mGainMean               = gainMean;
 
-    hMaxOverlay     = (TH2F*) calloc(mMaxPulseOrder, sizeof(TH2F));
-    hEdgeOverlay    = (TH2F*) calloc(mMaxPulseOrder, sizeof(TH2F));
-    hMaxProfile     = (TProfile*) calloc(mMaxPulseOrder, sizeof(TProfile));
-    hEdgeProfile    = (TProfile*) calloc(mMaxPulseOrder, sizeof(TProfile));
-
+//    hMaxOverlay     = (TH2F*) calloc(mMaxPulseOrder, sizeof(TH2F*));
+    hMaxOverlay = new TH2F*[mMaxPulseOrder];
+//    hEdgeOverlay    = (TH2F*) calloc(mMaxPulseOrder, sizeof(TH2F*));
+    hEdgeOverlay = new TH2F*[mMaxPulseOrder];
+//    hMaxProfile     = (TProfile*) calloc(mMaxPulseOrder, sizeof(TProfile));
+    hMaxProfile = new TProfile*[mMaxPulseOrder];
+//    hEdgeProfile    = (TProfile*) calloc(mMaxPulseOrder, sizeof(TProfile));
+    hEdgeProfile = new TProfile*[mMaxPulseOrder];
     if (mOptions == "S")
-        hSlopeRisingEdge= (TH1F*) calloc(mMaxPulseOrder, sizeof(TH1F));
+    {
+//        hSlopeRisingEdge= (TH1F*) calloc(mMaxPulseOrder, sizeof(TH1F));
+        hSlopeRisingEdge = new TH1F*[mMaxPulseOrder];
+    }
     if (mOptions == "R")
-        hRisingToMaxEdge= (TH1F*) calloc(mMaxPulseOrder, sizeof(TH1F));
+    {
+//        hRisingEdgeToMax= (TH1F*) calloc(mMaxPulseOrder, sizeof(TH1F));
+        hRisingEdgeToMax = new TH1F*[mMaxPulseOrder];
+    }
     if (mOptions == "P")
-        hPosOfMax       = (TH1F*) calloc(mMaxPulseOrder, sizeof(TH1F));
+    {
+//        hPosOfMax       = (TH1F*) calloc(mMaxPulseOrder, sizeof(TH1F));
+        hPosOfMax = new TH1F*[mMaxPulseOrder];
+    }
 
     hList           = new TObjArray;
 
     BookPixelHistos();
-    BookDistributionHistos()
+    BookDistributionHistos();
 }
 
@@ -59,21 +71,21 @@
 {
     if (mVerbosityLevel > 2) cout << endl << "...delete current pixel histograms" ;
-    for (int order = 0;
-         order < mMaxPulseOrder;
-         order ++)
-    {
-        if (mVerbosityLevel > 3) cout << endl << "...deleting hMaxOverlay" << mHistogramId;
-        delete hMaxOverlay[order];
+//    for (int order = 0;
+//         order < mMaxPulseOrder;
+//         order ++)
+//    {
+        if (mVerbosityLevel > 3) cout << endl << "...deleting hMaxOverlay";
+        delete[] hMaxOverlay;
         hMaxOverlay = NULL;
-        if (mVerbosityLevel > 3) cout << endl << "...deleting hEdgeOverlay" << mHistogramId;
-        delete hEdgeOverlay[order];
+        if (mVerbosityLevel > 3) cout << endl << "...deleting hEdgeOverlay";
+        delete[] hEdgeOverlay;
         hEdgeOverlay = NULL;
-        if (mVerbosityLevel > 3) cout << endl << "...deleting hMaxProfile" << mHistogramId;
-        delete hMaxProfile[order];
+        if (mVerbosityLevel > 3) cout << endl << "...deleting hMaxProfile";
+        delete[] hMaxProfile;
         hMaxProfile = NULL;
-        if (mVerbosityLevel > 3) cout << endl << "...deleting hMaxProfile2" << mHistogramId;
-        delete hEdgeProfile[order];
+        if (mVerbosityLevel > 3) cout << endl << "...deleting hMaxProfile2";
+        delete[] hEdgeProfile;
         hEdgeProfile = NULL;
-    }
+//    }
     if (mVerbosityLevel > 3) cout << endl << "...deleting hList";
     delete hList;
@@ -97,6 +109,19 @@
     if (mVerbosityLevel > 2) cout << endl << "...book pixel histograms" << endl;
     TString histo_name;
-    for (int order = 0; order < mMaxPulseOrder; order ++)
-    {
+
+    for (int order =0; order > mMaxPulseOrder; order++)
+    {
+        histo_name = "hMaxOverlay";
+        histo_name += order;
+        hMaxOverlay[order]=new TH2F(
+                histo_name,
+                "Overlay of detected pulses of one pulse order for one Pixel",
+                mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
+                (-1*mPixelOverlayXaxisLeft)-0.5,
+                mPixelOverlayXaxisRight-0.5 ,
+                512,
+                -55.5,
+                200.5
+                );
 /*
                 SetHistogramAttributes(
@@ -107,17 +132,5 @@
                             );
                             */
-        histo_name = "hMaxOverlay";
-        histo_name += order;
         if (mVerbosityLevel > 3) cout << "...booking " << histo_name << endl;
-        hMaxOverlay[order] = TH2F(
-                    histo_name,
-                    "Overlay of detected pulses of one pulse order for one Pixel",
-                    mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
-                    (-1*mPixelOverlayXaxisLeft)-0.5,
-                    mPixelOverlayXaxisRight-0.5 ,
-                    512,
-                    -55.5,
-                    200.5
-                    );
         hMaxOverlay[order]->SetAxisRange(
                     mBSLMean - 5,
@@ -128,4 +141,8 @@
         //hMaxProfile->SetBit(TH2F::kCanRebin);
         hList->Add( hMaxOverlay[order] );
+    }
+
+    for (int order = 0; order < mMaxPulseOrder; order ++)
+    {
 
 //------------------------------------------------------------------------
@@ -141,5 +158,5 @@
         histo_name += order;
         if (mVerbosityLevel > 3) cout << "...booking " << histo_name << endl;
-        hEdgeOverlay[order] = TH2F(
+        hEdgeOverlay[order] = new TH2F(
                     histo_name,
                     "Overlay at rising edge of detected pulses of one pulse order for one Pixel ",
@@ -172,5 +189,5 @@
         histo_name += order;
         if (mVerbosityLevel > 3) cout << "...booking " << histo_name << endl;
-        hMaxProfile[order] = TProfile(
+        hMaxProfile[order] = new TProfile(
                     histo_name,
                     "Mean value of each slice in overlay plot (Tprofile)",
@@ -201,25 +218,27 @@
                     );
                     */
-            histo_name = "hEdgeProfile";
-            histo_name += order;
-            if (mVerbosityLevel > 3) cout << "...booking " << histo_name << endl;
-            hEdgeProfile[order] = TProfile(
-                        histo_name,
-                        "Mean value of each slice in overlay plot (Tprofile)",
-                        mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,//nbinsx
-                        (-1*mPixelOverlayXaxisLeft)-0.5,                 //xlow
-                        mPixelOverlayXaxisRight-0.5 ,                    //xup
-        //                512,                                            //nbinsy
-                        -55.5,                                          //ylow
-                        300.5,                                          //yup
-                        "s");                                           //option
-            hEdgeProfile[order]->SetLineColor(kRed);
-            hEdgeProfile[order]->SetAxisRange(
-                        mBSLMean - 5,
-                        (mGainMean*(order+1)) + 10,
-                        "Y");
-            hEdgeProfile[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
-            hEdgeProfile[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
-            //hMaxProfile->SetBit(TH2F::kCanRebin);
+        histo_name = "hEdgeProfile";
+        histo_name += order;
+        if (mVerbosityLevel > 3) cout << "...booking " << histo_name << endl;
+        hEdgeProfile[order] = new TProfile(
+                    histo_name,
+                    "Mean value of each slice in overlay plot (Tprofile)",
+                    mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,//nbinsx
+                    (-1*mPixelOverlayXaxisLeft)-0.5,                 //xlow
+                    mPixelOverlayXaxisRight-0.5 ,                    //xup
+    //                512,                                            //nbinsy
+                    -55.5,                                          //ylow
+                    300.5,                                          //yup
+                    "s");                                           //option
+        hEdgeProfile[order]->SetLineColor(kRed);
+        hEdgeProfile[order]->SetAxisRange(
+                    mBSLMean - 5,
+                    (mGainMean*(order+1)) + 10,
+                    "Y");
+        hEdgeProfile[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
+        hEdgeProfile[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
+        //hMaxProfile->SetBit(TH2F::kCanRebin);
+        hList->Add( hEdgeProfile[order] );
+
     }
     if (mVerbosityLevel > 2) cout << "...done" << endl;
@@ -231,6 +250,6 @@
 void
 Pixel::DrawHistograms(
-        TCanvas*    pixelCanvas     = NULL,
-        int*        histoFrameNr    = NULL
+        TCanvas*    pixelCanvas,
+        int*        histoFrameNr
         )
 {
@@ -238,11 +257,11 @@
     for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
     {
-        pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
+        pixelCanvas[pulse_order].cd( histoFrameNr[0] );
         hMaxOverlay[pulse_order]->Draw("COLZ");
-        pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
+        pixelCanvas[pulse_order].cd( histoFrameNr[2] );
         hMaxProfile[pulse_order]->Draw("COLZ");
-        hMaxProfile2[pulse_order]->Draw("SAME");
-
-        pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
+        hEdgeProfile[pulse_order]->Draw("SAME");
+
+        pixelCanvas[pulse_order].cd( histoFrameNr[1] );
         hEdgeOverlay[pulse_order]->Draw("COLZ");
     }
@@ -257,12 +276,17 @@
     if (mOptions != "")
     {
-        if (mVerbosityLevel > 2) cout << endl
-                                      << "...book distribution histograms"
-                                      << endl;
-
-            if (mOptions != "S")
+        TString histo_name;
+        for (int order =0; order > mMaxPulseOrder; order++)
+        {
+            if (mVerbosityLevel > 2) cout << endl
+                                          << "...book distribution histograms"
+                                          << endl;
+
+            if (mOptions.Contains("S"))
             {
-                hSlopeRisingEdge = TH1F (
-                            "hSlopeRisingEdge",
+                histo_name = "hSlopeRisingEdge";
+                histo_name += order;
+                hSlopeRisingEdge[order] = new TH1F (
+                            histo_name,
                             "Distribution of rising edge",
                             600,
@@ -270,12 +294,15 @@
                             10.1
                             );
-                hSlopeRisingEdge->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
-                hSlopeRisingEdge->GetYaxis()->SetTitle( "counts" );
+                hSlopeRisingEdge[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
+                hSlopeRisingEdge[order]->GetYaxis()->SetTitle( "counts" );
+                hList->Add( hSlopeRisingEdge[order] );
             }
 
-            if (mOptions != "R")
+            if (mOptions.Contains("R"))
             {
-                hRisingToMaxEdge = TH1F (
-                            "hRisingToMaxEdge",
+                histo_name = "hRisingEdgeToMax";
+                histo_name += order;
+                hRisingEdgeToMax[order] = new TH1F (
+                            histo_name,
                             "Deviation of rising edge and maximum",
                             600,
@@ -283,12 +310,15 @@
                             10.1
                             );
-                hRisingToMaxEdge->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
-                hRisingToMaxEdge->GetYaxis()->SetTitle( "counts" );
+                hRisingEdgeToMax[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
+                hRisingEdgeToMax[order]->GetYaxis()->SetTitle( "counts" );
+                hList->Add( hRisingEdgeToMax[order] );
             }
 
-            if (mOptions != "P")
+            if (mOptions.Contains("P"))
             {
-                hPosOfMax = TH1F (
-                            "hPosOfMax",
+                histo_name = "hPosOfMax";
+                histo_name += order;
+                hPosOfMax[order] = new TH1F (
+                            histo_name,
                             "Deviation of rising edge and maximum",
                             600,
@@ -296,13 +326,47 @@
                             10.1
                             );
-                hPosOfMax->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
-                hPosOfMax->GetYaxis()->SetTitle( "counts" );
+                hPosOfMax[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
+                hPosOfMax[order]->GetYaxis()->SetTitle( "counts" );
+                hList->Add( hPosOfMax[order] );
             }
 
-        if (mVerbosityLevel > 2) cout << "...done" << endl;
-    }
-}
-
-
+            if (mVerbosityLevel > 2) cout << "...done" << endl;
+        }
+    }
+}
+
+void
+Pixel::DrawDistributionHistograms(
+        TCanvas*    pixelCanvas,
+        int*        histoFrameNr
+        )
+{
+    if (mVerbosityLevel > 2) cout << endl << "...drawing distribution histograms" ;
+    for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
+    {
+        pixelCanvas[pulse_order].cd( histoFrameNr[0] );
+        hSlopeRisingEdge[pulse_order]->Draw();
+        pixelCanvas[pulse_order].cd( histoFrameNr[1] );
+        hRisingEdgeToMax[pulse_order]->Draw();
+
+        pixelCanvas[pulse_order].cd( histoFrameNr[2] );
+        hPosOfMax[pulse_order]->Draw();
+    }
+}
+// end of DrawDistributionHistograms
+//----------------------------------------------------------------------------
+
+void
+Pixel::SavePixelHistograms(
+        const char* outRootFileName
+        )
+{
+    SaveHistograms(
+            outRootFileName,
+            CreateSubDirName( mChid ),
+            hList,
+            mVerbosityLevel
+            );
+}
 
 
