From 7af820a6813047099fdb6d6e7241fcce784dcad0 Mon Sep 17 00:00:00 2001
From: Siarhei Harkusha <Siarhei.Harkusha@cern.ch>
Date: Thu, 23 Sep 2021 17:38:14 +0200
Subject: [PATCH] TileMonitoring: Use new binning for histograms in laser LG
 and HG

Tile monitoring histograms produced for laser calibration runs
have been modified by Tibor to use new binning in low and high gains
(non-uniform bin width in the case of high gain).

Final calibration units has been made configurable via JO,
and default units have been changed also
(CesiumPicoCoulombs for physics runs and PicoCoulombs for others).
---
 .../TileMonitoring/TilePaterMonTool.h         | 13 +++--
 .../TileMonitoring/TileRawChannelMonTool.h    |  2 +
 .../TileMonitoring/src/TilePaterMonTool.cxx   | 11 ++++
 .../src/TileRawChannelMonTool.cxx             | 52 +++++++++++++++----
 4 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/TileCalorimeter/TileMonitoring/TileMonitoring/TilePaterMonTool.h b/TileCalorimeter/TileMonitoring/TileMonitoring/TilePaterMonTool.h
index da2a4e784e66..f70817c0711e 100644
--- a/TileCalorimeter/TileMonitoring/TileMonitoring/TilePaterMonTool.h
+++ b/TileCalorimeter/TileMonitoring/TileMonitoring/TilePaterMonTool.h
@@ -66,14 +66,14 @@ class TilePaterMonTool: public ManagedMonitorToolBase
 
 protected:
 /// Implicit version of book1D 
-  TH1D* book1D(const std::string& nam, const std::string& tit, 
+  TH1D* book1D(const std::string& nam, const std::string& tit,
                int nx, double xmin, double xmax) 
   { 
     return book1D(m_path, nam, tit, nx, xmin, xmax); 
   }
 
 /// Implicit version of book2D 
-  TH2D* book2D(const std::string& nam, const std::string& tit, 
+  TH2D* book2D(const std::string& nam, const std::string& tit,
                int nx, double xmin, double xmax, 
                int ny, double ymin, double ymax)
  {
@@ -100,6 +100,11 @@ protected:
                Interval_t interval = run, MgmtAttr_t attribute = ATTRIB_MANAGED,
                std::string trigChain = "", std::string mergeAlgo = "");
 
+  TH1S* book1Sx(std::string dir, std::string nam, std::string tit,
+               int nx, const Double_t *xlgbins,
+               Interval_t interval = run, MgmtAttr_t attribute = ATTRIB_MANAGED,
+               std::string trigChain = "", std::string mergeAlgo = "");
+
   TH1C* book1C(std::string dir, std::string nam, std::string tit, 
                int nx, double xmin, double xmax,
                Interval_t interval = run, MgmtAttr_t attribute = ATTRIB_MANAGED,
@@ -205,12 +210,12 @@ protected:
   using ManagedMonitorToolBase::regGraph;
 
   template <typename T>
-  void regHist(const std::string& subDir, T* hist, 
+  void regHist(const std::string& subDir, T* hist,
                Interval_t interval = run, MgmtAttr_t attribute = ATTRIB_MANAGED, 
                std::string trigChain = "", std::string mergeAlgo = "" );
 
   template <typename T>
-  void regGraph(const std::string& subDir, T* graph, 
+  void regGraph(const std::string& subDir, T* graph,
                 Interval_t interval = run, MgmtAttr_t attribute = ATTRIB_MANAGED, 
                 std::string trigChain = "", std::string mergeAlgo = "" );
   
diff --git a/TileCalorimeter/TileMonitoring/TileMonitoring/TileRawChannelMonTool.h b/TileCalorimeter/TileMonitoring/TileMonitoring/TileRawChannelMonTool.h
index f79a9f4684e4..e52ef8673a3e 100644
--- a/TileCalorimeter/TileMonitoring/TileMonitoring/TileRawChannelMonTool.h
+++ b/TileCalorimeter/TileMonitoring/TileMonitoring/TileRawChannelMonTool.h
@@ -64,6 +64,7 @@ class TileRawChannelMonTool: public TilePaterMonTool {
 
     bool m_bookAll;
     bool m_book2D;
+    bool m_overlaphists;
     int m_runType;
     std::string m_contName;
     std::string m_contNameDSP;
@@ -170,6 +171,7 @@ class TileRawChannelMonTool: public TilePaterMonTool {
     const TileInfo* m_tileInfo;
     bool m_is12bit;
     SG::ReadHandleKey<TileDQstatus> m_DQstatusKey;
+    int m_intCalibUnit;
 };
 
 #endif
diff --git a/TileCalorimeter/TileMonitoring/src/TilePaterMonTool.cxx b/TileCalorimeter/TileMonitoring/src/TilePaterMonTool.cxx
index a17126cae70e..3ceed64524bf 100644
--- a/TileCalorimeter/TileMonitoring/src/TilePaterMonTool.cxx
+++ b/TileCalorimeter/TileMonitoring/src/TilePaterMonTool.cxx
@@ -176,6 +176,17 @@ TH1S * TilePaterMonTool::book1S(std::string subdir, std::string nam, std::string
   return hist;
 }
 
+TH1S * TilePaterMonTool::book1Sx(std::string subdir, std::string nam, std::string tit,
+                                int nx, const Double_t *xlgbins,
+                                Interval_t interval, MgmtAttr_t attribute,
+                                std::string trigChain, std::string mergeAlgo)
+{
+
+  TH1S* hist = new TH1S(TString(nam), TString(tit), nx, xlgbins);
+  regHist(subdir, hist, interval, attribute, trigChain, mergeAlgo);
+  return hist;
+}
+
 TH1I* TilePaterMonTool::book1I(std::string subdir, std::string nam, std::string tit,
                                  int nx, double xmin, double xmax,
                                  Interval_t interval, MgmtAttr_t attribute,
diff --git a/TileCalorimeter/TileMonitoring/src/TileRawChannelMonTool.cxx b/TileCalorimeter/TileMonitoring/src/TileRawChannelMonTool.cxx
index b1b714954716..982abee17b35 100644
--- a/TileCalorimeter/TileMonitoring/src/TileRawChannelMonTool.cxx
+++ b/TileCalorimeter/TileMonitoring/src/TileRawChannelMonTool.cxx
@@ -54,6 +54,7 @@ TileRawChannelMonTool::TileRawChannelMonTool(const std::string & type, const std
   declareInterface<IMonitorToolBase>(this);
 
   declareProperty("bookAllDrawers", m_bookAll = false);
+  declareProperty("overlaphists", m_overlaphists = false);
   declareProperty("book2D", m_book2D = true);
 
   // run type 1 - phys, 2 - las, 4 - ped, 8 - cis
@@ -79,6 +80,7 @@ TileRawChannelMonTool::TileRawChannelMonTool(const std::string & type, const std
   declareProperty("MinAmpForCorrectedTime", m_minAmpForCorrectedTime = 0.5);
   declareProperty("TileInfoName", m_infoName = "TileInfo");
   declareProperty("TileDQstatus", m_DQstatusKey = "TileDQstatus");
+  declareProperty("CalibUnit", m_intCalibUnit = (int)TileRawChannelUnit::Invalid);
 }
 
 /*---------------------------------------------------------*/
@@ -123,10 +125,16 @@ StatusCode TileRawChannelMonTool::bookHists()
     msg(MSG::DEBUG) << "Using base path " << m_path << endmsg;
   }
 
-  if ((m_runType == LasRun) || (m_runType == PhysRun) || (m_runType == LedRun)) {
-    m_calibUnit = TileRawChannelUnit::CesiumPicoCoulombs;
-  } else
-    m_calibUnit = TileRawChannelUnit::PicoCoulombs;
+  if (m_intCalibUnit>=0 && m_intCalibUnit<=3) {
+    m_calibUnit = (TileRawChannelUnit::UNIT)m_intCalibUnit;
+  }
+  if (m_calibUnit == TileRawChannelUnit::Invalid) {
+    if (m_runType == PhysRun) {
+      m_calibUnit = TileRawChannelUnit::CesiumPicoCoulombs;
+    } else {
+      m_calibUnit = TileRawChannelUnit::PicoCoulombs;
+    }
+  }
 
   if (m_bookAll) {
     for (int ros = 1; ros < 5; ++ros) {
@@ -214,9 +222,9 @@ void TileRawChannelMonTool::bookHists(int ros, int drawer)
         if (m_book2D) {
           std::string Hist2DName[4] = { "_amp_vs_q_100", "_amp_vs_q_5", "_time_vs_time_100", "_time_vs_time_5" };
           std::string Hist2DTitle[4] = { " amp vs charge 100 pF", " amp vs charge 5 pF", " time vs time 100 pF", " time vs time 5 pF" };
-	  float factor_charge = m_is12bit ? 2. : 1.;
-	  float factor_adc    = m_is12bit ? 4. : 1.;
-	  // Below, static_cast<float> is used to avoid warnings from -Wnarrowing
+          float factor_charge = m_is12bit ? 2. : 1.;
+          float factor_adc    = m_is12bit ? 4. : 1.;
+          // Below, static_cast<float> is used to avoid warnings from -Wnarrowing
           float LowX_low2D[4] = { -4., -0.5, -0.25, -0.25 };
           float HighX_low2D[4] = { 804., 50.5, 25.25, 25.25 };
           float LowX_hi2D[4] = { static_cast<float>(-0.0625 * factor_charge), static_cast<float>(-0.0625 * factor_charge), -0.25, -0.25 };
@@ -276,10 +284,27 @@ void TileRawChannelMonTool::bookHists(int ros, int drawer)
         } else {
           switch (gn) {
             case 0: // low gain
-              m_data->m_hist1[ros][drawer][ch][gn].push_back(book1S(subDir, histName, histTitle, 1101, -50.5, 1050.5));
+              if (m_overlaphists) {
+                const Int_t nlg1 = 49;
+                const Int_t nlg2 = 500;
+                const Int_t nlg3 = 1027;
+                Double_t xlgbin[nlg1 + nlg2 + nlg3 + 1];
+                for(Int_t i = 0; i <= nlg1; ++i)
+                  xlgbin[i] = -50.5+1.0*i;
+                for(Int_t i = 1; i <= nlg2; ++i)
+                  xlgbin[i + nlg1] = -1.5 + 0.05 * i;
+                for(Int_t i = 1; i <= nlg3; ++i)
+                  xlgbin[i + nlg1 + nlg2] = 23.5 + 1.0 * i;
+                m_data->m_hist1[ros][drawer][ch][gn].push_back(book1Sx(subDir, histName, histTitle, nlg1 + nlg2 + nlg3, xlgbin));
+              } else {
+                m_data->m_hist1[ros][drawer][ch][gn].push_back(book1S(subDir, histName, histTitle, 1101, -50.5, 1050.5));
+              }
               break;
             case 1: // high gain
-              m_data->m_hist1[ros][drawer][ch][gn].push_back(book1S(subDir, histName, histTitle, 826, -1.01, 15.51));
+              if (m_overlaphists)
+                m_data->m_hist1[ros][drawer][ch][gn].push_back(book1S(subDir, histName, histTitle, 500, -1.5, 23.5));
+              else
+                m_data->m_hist1[ros][drawer][ch][gn].push_back(book1S(subDir, histName, histTitle, 826, -1.01, 15.51));
               break;
             default: // single gain mode
               if (m_runType == PhysRun) {
@@ -1153,7 +1178,14 @@ StatusCode TileRawChannelMonTool::fillSummaryHistograms()
               //Lukas
 
               if (m_data->m_hist1[ros][drawer][ch][adc][0]->GetEntries() > 0) {
-                m_data->m_hist1[ros][drawer][ch][adc][0]->Fit("g", "NQ");
+                if (adc == 0 && m_overlaphists) { // We have for LB histograms with variable-width bins, not suitable for a fit
+                  TH1S *h4fit=new TH1S(*(m_data->m_hist1[ros][drawer][ch][adc][0]));
+                  h4fit->Scale(1,"width");
+                  h4fit->Fit("g", "NQ");
+                  delete(h4fit);
+                } else {
+                  m_data->m_hist1[ros][drawer][ch][adc][0]->Fit("g", "NQ");
+                }
                 Sigma = fit_gaus->GetParameter(2);
                 ErrS = fit_gaus->GetParError(2);
               }
-- 
GitLab