Index: fact/tools/rootmacros/PulseTemplates/pixel.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/pixel.C	(revision 13659)
+++ fact/tools/rootmacros/PulseTemplates/pixel.C	(revision 13784)
@@ -15,51 +15,18 @@
         int         verbosityLevel,
         bool        stats,
-        TFile*      filename
-        )
-{
-    mConstructorType        = 1;        //important for deletion 0 delete distribution 1 delete TemplateHistos
-    mChid                   = pixelID;
-    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;
-
-    LoadPulseHistos( );
-    BookTemplateHistos();
-}
-
-Pixel::Pixel(
-        int         pixelID,
-        int         maxPulsorder,
-        int         verbosityLevel,
-        bool        stats,
-        TFile*      filename,
+        TString     options,
         int         pixelOverlayXaxisLeft,
         int         pixelOverlayXaxisRight,
         float       bSLMean,
         float       gainMean,
-        TString     options
-        )
-{
-    mConstructorType        = 0;
+        TFile*      filename
+        )
+{
+    mConstructorType        = 1;        //important for deletion 0 delete distribution 1 delete TemplateHistos
+
     mChid                   = pixelID;
-    mStats                  = stats;        ///TODO: HANDOVER THE VALUE
     mMaxPulseOrder          = maxPulsorder;
     mVerbosityLevel         = verbosityLevel;
+    mStats                  = stats;
     mOptions                = options;
     mPixelOverlayXaxisLeft  = pixelOverlayXaxisLeft;
@@ -74,4 +41,54 @@
     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 TList();
+    if (options.Contains("L"))
+    {
+        LoadPulseHistos( );
+    }
+    else
+    {
+       BookPixelHistos();
+    }
+    BookTemplateHistos();
+    BookEdgeTemplateHistos();
+}
+
+Pixel::Pixel(
+        int         pixelID,
+        int         maxPulsorder,
+        int         verbosityLevel,
+        bool        stats,
+        TString     options,
+        int         pixelOverlayXaxisLeft,
+        int         pixelOverlayXaxisRight,
+        float       bSLMean,
+        float       gainMean
+        )
+{
+    mConstructorType        = 0;
+
+    mChid                   = pixelID;
+    mMaxPulseOrder          = maxPulsorder;
+    mVerbosityLevel         = verbosityLevel;
+    mStats                  = stats;        ///TODO: HANDOVER THE VALUE
+    mOptions                = options;
+    mPixelOverlayXaxisLeft  = pixelOverlayXaxisLeft;
+    mPixelOverlayXaxisRight = pixelOverlayXaxisRight;
+    mBSLMean                = bSLMean;
+    mGainMean               = gainMean;
+
+    hMaxOverlay  = new TH2F*[mMaxPulseOrder];
+    hEdgeOverlay = new TH2F*[mMaxPulseOrder];
+    hMaxProfile  = new TProfile*[mMaxPulseOrder];
+    hEdgeProfile = new TProfile*[mMaxPulseOrder];
+
     if (mOptions.Contains("S") )
     {
@@ -89,5 +106,5 @@
     }
 
-    hList           = new TObjArray;
+    hList           = new TList();
 
     BookPixelHistos();
@@ -97,19 +114,29 @@
 Pixel::~Pixel()
 {
-    if (mVerbosityLevel > 1) cout << endl << "...delete histograms of pixel " << mChid ;
+    if (mVerbosityLevel > 1)
+    {
+        cout << endl << "...delete histograms of pixel " << mChid ;
+        cout << endl << "...mConstructorType = " << mConstructorType ;
+    }
+
+    if (mConstructorType == 0)
+    {
+        DeleteDistributionHistos();
+    }
+
+    if (mConstructorType == 1)
+    {
+        DeleteTemplateHistos();
+        DeleteEdgeTemplateHistos();
+    }
 
     DeletePixelHistos();
-    if (mConstructorType == 0)
-    {
-        DeleteDistributionHistos();
-    }
-
-    if (mConstructorType == 1)
-    {
-        DeleteTemplateHistos();
-    }
     delete hList;
     hList = NULL;
-
+    if (mVerbosityLevel > 1)
+    {
+        cout << endl << "...histograms of pixel " << mChid ;
+        cout << "...deleted " << endl ;
+    }
 }// ~Pixel
 
@@ -193,5 +220,5 @@
         )
 {
-    if (mVerbosityLevel > 2) cout << endl << "...drawing Template histograms" ;
+    if (mVerbosityLevel > 2) cout << "...drawing Template histograms" << endl ;
     for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
     {
@@ -266,4 +293,15 @@
     histoname +=   "_";
     histoname +=   order;
+    return histoname;
+}
+
+TString
+Pixel::ChooseCycleNumber(
+        TString     histoname,
+        int         cycleNumber
+        )
+{
+    histoname +=   ";";
+    histoname +=   cycleNumber;
     return histoname;
 }
@@ -500,5 +538,9 @@
     for (int order = 0; order < mMaxPulseOrder; order++)
     {
-        if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hPixelMax", order) << endl;
+        if (mVerbosityLevel > 3)
+        {
+            cout << "\t...booking " << HistoName("hPixelMax", order) << endl;
+        }
+
         hPixelMax[order]=new TH1F(
                     HistoName("hPixelMax", order),
@@ -641,22 +683,45 @@
 Pixel::LoadPulseHistos()
 {
-    mRootFile->cd();
-    mRootFile->cd(CreateSubDirName( mChid ));
+    if (mVerbosityLevel > 1)
+    {
+        mRootFile->ls();
+        cout << "Current File: " ;
+        gFile->pwd();
+    }
+
+    mRootFile->cd( CreateSubDirName( mChid ) ); //Go to pixel's subdirectory
+    mDirectory = gDirectory;
+
+    if (mVerbosityLevel > 1)
+    {
+        cout << "Current Directory: " ;
+        gDirectory->ls();
+    }
+
+//    mPixelOverlayXaxisRight   =70;   ///TODO: get it from the root file
+//    mPixelOverlayXaxisLeft    =230;  ///TODO: get it from the root file
+//    mBSLMean                  =-1;   ///TODO: get it from the root file
+//    mGainMean                 =9;    ///TODO: get it from the root file
+//    mOptions                  ="SRM"; ///TODO: get it from the root file
+
     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) );
-    }
+        if (mVerbosityLevel > 3) cout << "\t...loading " << ChooseCycleNumber( HistoName("hMaxOverlay", order), 1) << endl;
+        hMaxOverlay[order]  = (TH2F*)mDirectory->Get( ChooseCycleNumber( HistoName("hMaxOverlay", order), 1) );
+
+        if (mVerbosityLevel > 3) cout << "\t...loading " << HistoName("hEdgeOverlay", order) << endl;
+        hEdgeOverlay[order] = (TH2F*)mDirectory->Get( ChooseCycleNumber( HistoName("hEdgeOverlay", order), 1) );
+
+        if (mVerbosityLevel > 3) cout << "\t...loading " << HistoName("hMaxProfile", order) << endl;
+        hMaxProfile[order]  = (TProfile*)mDirectory->Get( ChooseCycleNumber( HistoName("hMaxProfile", order), 1) );
+        cout << "histoname: " << HistoName("hMaxProfile", order)
+             << "histoname: " << ChooseCycleNumber( HistoName("hMaxProfile", order), 1)
+             << "histoname: " << hMaxProfile[order];
+        if (mVerbosityLevel > 3) cout << "\t...loading " << HistoName("hEdgeProfile", order) << endl;
+        hEdgeProfile[order] = (TProfile*)mDirectory->Get( ChooseCycleNumber( HistoName("hEdgeProfile", order), 1) );
+    }
+
 }
 // end of LoadPulseHistos
@@ -669,4 +734,5 @@
     {
         cout << endl
+             << endl
              << "\t...delete current overlay histograms of Pixel# " << mChid;
     }
@@ -677,8 +743,5 @@
         if (mVerbosityLevel > 3)
         cout << endl << "\t\t...deleting hMaxOverlay"
-                                      << mChid << "_" << order
-                                      << " hMaxOverlay[order] adr " << hMaxOverlay[order]
-                                      << " hMaxOverlay adr " << hMaxOverlay
-                                         ;
+                                      << mChid << "_" << order;
 
         delete hMaxOverlay[order];
@@ -801,9 +864,8 @@
          order ++)
     {
-        if (mVerbosityLevel > 3)
-        cout << endl << "\t\t...deleting hPixelMax"
-                                      << mChid << "_" << order;
-        delete hPixelMax[order];
-        hPixelMax[order] = NULL;
+        if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelMean"
+                                      << mChid << "_" << order ;
+        delete hPixelMean[order];
+        hPixelMean[order] = NULL;
 
         if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelMedian"
@@ -812,8 +874,9 @@
         hPixelMedian[order] = NULL;
 
-        if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelMean"
-                                      << mChid << "_" << order ;
-        delete hPixelMean[order];
-        hPixelMean[order] = NULL;
+        if (mVerbosityLevel > 3)
+                                 cout << endl << "\t\t...deleting hPixelMax"
+                                      << mChid << "_" << order;
+        delete hPixelMax[order];
+        hPixelMax[order] = NULL;
 
     }
@@ -841,5 +904,5 @@
     {
         cout << endl
-             << "\t...delete current template histograms of Pixel# " << mChid;
+             << "\t...delete current Edge template histograms of Pixel# " << mChid;
     }
     for (int order = 0;
@@ -928,5 +991,5 @@
         )
 {
-    if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName(histName, order) << endl;
+    if (mVerbosityLevel > 3) cout << "\t...designing " << HistoName(histName, order) << endl;
 
     histo->SetNameTitle(
