Belle II Software  release-06-02-00
DQMHistAnalysisKLM2.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 /* Own header. */
10 #include <dqm/analysis/modules/DQMHistAnalysisKLM2.h>
11 
12 /* Belle 2 headers. */
13 #include <klm/dataobjects/KLMChannelIndex.h>
14 
15 /* ROOT headers. */
16 #include <TROOT.h>
17 
18 
19 using namespace Belle2;
20 
21 REG_MODULE(DQMHistAnalysisKLM2)
22 
25  m_EklmElementNumbers{&(EKLMElementNumbers::Instance())}
26 {
27  m_PlaneLine.SetLineColor(kMagenta);
28  m_PlaneLine.SetLineWidth(1);
29  m_PlaneLine.SetLineStyle(2); // dashed
30  m_PlaneText.SetTextAlign(22); // centered, middle
31  m_PlaneText.SetTextColor(kMagenta);
32  m_PlaneText.SetTextFont(42); // Helvetica regular
33  m_PlaneText.SetTextSize(0.02); // 2% of TPad's full height
34 }
35 
37 {
38 }
39 
41 {
42  gROOT->cd();
43  m_c_eff_bklm = new TCanvas("KLMEfficiencyDQM/c_eff_bklm_plane");
44  m_c_eff_eklm = new TCanvas("KLMEfficiencyDQM/c_eff_eklm_plane");
45  m_c_eff_bklm_sector = new TCanvas("KLMEfficiencyDQM/c_eff_bklm_sector");
46  m_c_eff_eklm_sector = new TCanvas("KLMEfficiencyDQM/c_eff_eklm_sector");
47 
48  m_eff_bklm = new TH1F("KLMEfficiencyDQM/eff_bklm_plane",
49  "Plane Efficiency in BKLM",
51  m_eff_bklm->GetXaxis()->SetTitle("Layer number");
52  m_eff_bklm->SetStats(false);
53  m_eff_bklm->SetOption("HIST");
54 
55  m_eff_eklm = new TH1F("KLMEfficiencyDQM/eff_eklm_plane",
56  "Plane Efficiency in EKLM",
58  m_eff_eklm->GetXaxis()->SetTitle("Plane number");
59  m_eff_eklm->SetStats(false);
60  m_eff_eklm->SetOption("HIST");
61 
62  m_eff_bklm_sector = new TH1F("KLMEfficiencyDQM/eff_bklm_sector",
63  "Sector Efficiency in BKLM",
65  m_eff_bklm_sector->GetXaxis()->SetTitle("Sector number");
66  m_eff_bklm_sector->SetStats(false);
67  m_eff_bklm_sector->SetOption("HIST");
68 
69  m_eff_eklm_sector = new TH1F("KLMEfficiencyDQM/eff_eklm_sector",
70  "Sector Efficiency in EKLM",
72  m_eff_eklm_sector->GetXaxis()->SetTitle("Sector number");
73  m_eff_eklm_sector->SetStats(false);
74  m_eff_eklm_sector->SetOption("HIST");
75 
76 }
77 
79 {
80 }
81 
83 {
84  m_RunType = findHist("DQMInfo/rtype");
85  m_RunTypeString = m_RunType ? m_RunType->GetTitle() : "";
86  m_IsPhysicsRun = (m_RunTypeString == "physics");
87 }
88 
90 {
91 }
92 
93 
94 
96  const std::string& histName, TH1* histogram)
97 {
98  std::string name;
99  const double histMinNDC = 0.1;
100  const double histMaxNDC = 0.9;
101  const double histRangeNDC = histMaxNDC - histMinNDC;
102 
103  TCanvas* canvas = findCanvas("KLMEfficiencyDQM/c_" + histName);
104  if (canvas == NULL) {
105  B2ERROR("KLMDQM2 histogram canvas KLMEfficiencyDQM/c_" << histName << " is not found.");
106  return;
107  }
108  canvas->Clear();
109  canvas->cd();
110  histogram->SetStats(false);
111  histogram->Draw();
112  if (histName.find("bklm") != std::string::npos) {
113  /* First draw the vertical lines and the sector names. */
114  const double maximalSector = BKLMElementNumbers::getMaximalSectorGlobalNumber();
115  for (int sector = 0; sector < BKLMElementNumbers::getMaximalSectorGlobalNumber(); ++sector) {
116  double xLineNDC = histMinNDC + (histRangeNDC * sector) / maximalSector;
117  double xTextNDC = histMinNDC + (histRangeNDC * (sector + 0.5)) / maximalSector;
118  double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
119  if (sector > 0)
120  m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
121  name = "B";
122  if (sector < 8)
123  name += "B";
124  else
125  name += "F";
126  name += std::to_string(sector % 8);
127  m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
128  }
129 
130  } else {
131  /* First draw the vertical lines and the sector names. */
132  const double maximalLayer = EKLMElementNumbers::getMaximalLayerGlobalNumber();
133  for (int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
134  double xLineNDC = histMinNDC + (histRangeNDC * layerGlobal) / maximalLayer;
135  double xTextNDC = histMinNDC + (histRangeNDC * (layerGlobal - 0.5)) / maximalLayer;
136  double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
137  if (layerGlobal < maximalLayer)
138  m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
139  int section, layer;
141  layerGlobal, &section, &layer);
143  name = "B";
144  else
145  name = "F";
146  name += std::to_string(layer);
147  m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
148  }
149  canvas->Modified();
150  canvas->Update();
151  }
152 }
153 
155 {
156  /* If KLM is not included, stop here and return. */
157  TH1* daqInclusion = findHist("KLM/daq_inclusion");
158  if (not(daqInclusion == NULL)) {
159  int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin("Yes"));
160  if (isKlmIncluded == 0)
161  return;
162  }
163 
164  /* Reset efficiency histograms*/
165  m_eff_bklm->Reset();
166  m_eff_eklm->Reset();
167  m_eff_bklm_sector->Reset();
168  m_eff_eklm_sector->Reset();
169 
170  /* Obtain plots necessary for efficiency plots */
171  TH1F* all_ext_bklm = (TH1F*)findHist("KLMEfficiencyDQM/all_ext_hitsBKLM");
172  TH1F* matched_hits_bklm = (TH1F*)findHist("KLMEfficiencyDQM/matched_hitsBKLM");
173 
174  TH1F* all_ext_eklm = (TH1F*)findHist("KLMEfficiencyDQM/all_ext_hitsEKLM");
175  TH1F* matched_hits_eklm = (TH1F*)findHist("KLMEfficiencyDQM/matched_hitsEKLM");
176 
177 
178  TH1F* all_ext_bklm_sector = (TH1F*)findHist("KLMEfficiencyDQM/all_ext_hitsBKLMSector");
179  TH1F* matched_hits_bklm_sector = (TH1F*)findHist("KLMEfficiencyDQM/matched_hitsBKLMSector");
180 
181  TH1F* all_ext_eklm_sector = (TH1F*)findHist("KLMEfficiencyDQM/all_ext_hitsEKLMSector");
182  TH1F* matched_hits_eklm_sector = (TH1F*)findHist("KLMEfficiencyDQM/matched_hitsEKLMSector");
183 
184  /* Check if efficiency histograms exist*/
185  if ((all_ext_bklm == nullptr || matched_hits_bklm == nullptr) && (m_IsPhysicsRun)) {
186  B2INFO("Histograms needed for BKLM plane efficiency computation are not found");
187  }
188 
189  if ((all_ext_eklm == nullptr || matched_hits_eklm == nullptr) && (m_IsPhysicsRun)) {
190  B2INFO("Histograms needed for EKLM plane efficiency computation are not found");
191  }
192  if ((all_ext_bklm_sector == nullptr || matched_hits_bklm_sector == nullptr) && (m_IsPhysicsRun)) {
193  B2INFO("Histograms needed for BKLM sector efficiency computation are not found");
194  }
195  if ((all_ext_eklm_sector == nullptr || matched_hits_eklm_sector == nullptr) && (m_IsPhysicsRun)) {
196  B2INFO("Histograms needed for EKLM sector efficiency computation are not found");
197  }
198 
199  /* Check if efficiency histograms exist*/
200  m_eff_bklm->Divide(matched_hits_bklm,
201  all_ext_bklm, 1, 1, "B");
202  m_eff_eklm->Divide(matched_hits_eklm,
203  all_ext_eklm, 1, 1, "B");
204 
205  m_eff_bklm_sector->Divide(matched_hits_bklm_sector,
206  all_ext_bklm_sector, 1, 1, "B");
207  m_eff_eklm_sector->Divide(matched_hits_eklm_sector,
208  all_ext_eklm_sector, 1, 1, "B");
209 
210  /* Draw histograms onto canvases*/
211  m_c_eff_bklm->cd();
212  m_eff_bklm->Draw();
213  m_c_eff_bklm->Modified();
214 
215  m_c_eff_eklm->cd();
216  m_eff_eklm->Draw();
217  m_c_eff_eklm->Modified();
218 
219  m_c_eff_bklm_sector->cd();
220  m_eff_bklm_sector->Draw();
221  m_c_eff_bklm_sector->Modified();
222 
223  m_c_eff_eklm_sector->cd();
224  m_eff_eklm_sector->Draw();
225  m_c_eff_eklm_sector->Modified();
226 
227  processPlaneHistogram("eff_bklm_plane", m_eff_bklm);
228  processPlaneHistogram("eff_eklm_plane", m_eff_eklm);
229 
230 }
231 
232 
static constexpr int getMaximalLayerGlobalNumber()
Get maximal layer global number.
static constexpr int getMaximalSectorGlobalNumber()
Get maximal sector global number.
Analysis of KLM DQM histograms.
TLine m_PlaneLine
TLine for boundary in plane histograms.
TH1 * m_eff_bklm_sector
Histogram for BKLM sector efficiency.
void processPlaneHistogram(const std::string &histName, TH1 *histogram)
Process histogram containing the number of hits in plane.
bool m_IsPhysicsRun
Run type flag for null runs.
void initialize() override
Initializer.
void event() override
This method is called for each event.
TH1 * m_eff_eklm
Histogram for EKLM plane efficiency.
TCanvas * m_c_eff_eklm_sector
Histogram for EKLM sector efficiency.
void endRun() override
This method is called if the current run ends.
const EKLMElementNumbers * m_EklmElementNumbers
EKLM element numbers.
TH1 * m_eff_eklm_sector
Histogram for EKLM sector efficiency.
void terminate() override
This method is called at the end of the event processing.
TCanvas * m_c_eff_bklm_sector
Histogram for BKLM sector efficiency.
TString m_RunTypeString
String with run type.
void beginRun() override
Called when entering a new run.
TH1 * m_eff_bklm
Histogram for BKLM plane efficiency.
TCanvas * m_c_eff_bklm
BKLM plane efficiency canvas.
TText m_PlaneText
TText for names in plane histograms.
TCanvas * m_c_eff_eklm
EKLM plane efficiency canvas.
TH1 * m_RunType
Histogram from DQMInfo with run type.
The base class for the histogram analysis module.
TCanvas * findCanvas(TString cname)
Find canvas by name.
static TH1 * findHist(const std::string &histname)
Find histogram.
static constexpr int getMaximalLayerGlobalNumber()
Get maximal detector layer global number.
static const EKLMElementNumbers & Instance()
Instantiation.
void layerNumberToElementNumbers(int layerGlobal, int *section, int *layer) const
Get element numbers by detector layer global number.
static constexpr int getMaximalPlaneGlobalNumber()
Get maximal plane global number.
static constexpr int getMaximalSectorGlobalNumberKLMOrder()
Get maximal sector global number with KLM ordering (section, sector).
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.