Belle II Software  release-08-01-10
DQMHistAnalysisARICH.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/DQMHistAnalysisARICH.h>
11 
12 #include <TH1F.h>
13 #include <TH2F.h>
14 #include <TCanvas.h>
15 #include <TLine.h>
16 #include <TClass.h>
17 #include <TROOT.h>
18 
19 #include <fstream>
20 #include <vector>
21 #include <algorithm>
22 
23 using namespace std;
24 using namespace Belle2;
25 
26 //-----------------------------------------------------------------
27 // Register module
28 //-----------------------------------------------------------------
29 
30 REG_MODULE(DQMHistAnalysisARICH);
31 
32 DQMHistAnalysisARICHModule::DQMHistAnalysisARICHModule()
34 {
35  // set module description (e.g. insert text)
36  setDescription("Modify and analyze the data quality histograms of ARICH");
38  addParam("debug", m_debug, "debug mode", false);
39  addParam("alert", m_enableAlert, "Enable color alert", true);
40 }
41 
43 {
44 }
45 
47 {
48  gROOT->cd();
49 
50  //definition of new TObjects for modification and analysis
51  for (int i = 0; i < 5; i++) {
52  m_LineForMB[i] = new TLine();
53  m_LineForMB[i]->SetLineStyle(3);
54  m_LineForMB[i]->SetLineWidth(1);
55  m_LineForMB[i]->SetLineColor(kBlack);
56  }
57 
58  m_apdHist = new ARICHChannelHist("tmpChHist", "tmpChHist", 2);
59  m_apdPoly = new TH2Poly();
60  m_apdPoly->SetName("ARICH/apdHitMap");
61  m_apdPoly->SetTitle("# of hits/APD/event");
62  m_apdPoly->SetOption("colz");
63  m_c_apdHist = new TCanvas("ARICH/c_apdHist");
64 
65  B2DEBUG(20, "DQMHistAnalysisARICH: initialized.");
66 }
67 
68 
70 {
71 
72  //Show alert by empty bins = red and strange entries = yellow
73  //Draw lines on mergerHits histogram for shifters to divide sectors
74  TH1* m_h_mergerHit = findHist("ARICH/mergerHit");
75  m_c_mergerHit = findCanvas("ARICH/c_mergerHit");
76  if (m_h_mergerHit != NULL && m_c_mergerHit != NULL) {
77  m_c_mergerHit->Clear();
78  m_c_mergerHit->cd();
79  m_h_mergerHit->SetMinimum(0);
80  m_h_mergerHit->Draw("hist");
81  gPad->Update();
82 
83  int alertMerger = 0;
84  double mean = m_h_mergerHit->Integral() / 72;
85  for (int i = 0; i < 72; i++) {
86  int hit = m_h_mergerHit->GetBinContent(i + 1);
87  if ((bool)hit ^ (bool)m_h_mergerHit->GetEntries()) {
88  //only if the empty bin is not a masked merger, show alert.
89  auto itr = std::find(maskedMergers.begin(), maskedMergers.end(), i + 1);
90  if (itr == maskedMergers.end()) {
91  alertMerger = 2;
92  break;
93  }
94  }
95  if (hit > mean * 100 && alertMerger < 1) alertMerger = 1;
96  }
97  if (m_enableAlert && m_minStats < m_h_mergerHit->GetEntries()) m_c_mergerHit->SetFillColor(alertColor[alertMerger]);
98 
99  //Draw lines divide the sectors
100  for (int i = 0; i < 5; i++) {
101  m_LineForMB[i]->DrawLine(12 * (i + 1) + 0.5, 0, 12 * (i + 1) + 0.5, gPad->GetUymax());
102  }
103 
104  m_c_mergerHit->Modified();
105  } else {
106  B2INFO("Histogram/canvas named mergerHit is not found.");
107  }
108 
109 
110  //Show alert by the ratio of center 2 bins to side 2bins. <1.5 = red, <2 = yellow
111  TH1* m_h_bits = findHist("ARICH/bits");
112  m_c_bits = findCanvas("ARICH/c_bits");
113  if (m_h_bits != NULL && m_c_bits != NULL) {
114  m_c_bits->Clear();
115  m_c_bits->cd();
116  m_h_bits->SetMinimum(0);
117  m_h_bits->Draw("hist");
118  gPad->Update();
119 
120  int alertBits = 0;
122  double side = m_h_bits->GetBinContent(2) + m_h_bits->GetBinContent(5);
123  double center = m_h_bits->GetBinContent(3) + m_h_bits->GetBinContent(4);
124  if (center / side < 2) alertBits = 1;
125  if (center / side < 1.5) alertBits = 2;
126  if (m_enableAlert && m_minStats < m_h_bits->GetEntries()) m_c_bits->SetFillColor(alertColor[alertBits]);
127 
128  m_c_bits->Modified();
129  } else {
130  B2INFO("Histogram/canvas named bits is not found.");
131  }
132 
133  //Show alert by no entry = red and 0 peak = yellow
134  TH1* m_h_hitsPerEvent = findHist("ARICH/hitsPerEvent");
135  m_c_hitsPerEvent = findCanvas("ARICH/c_hitsPerEvent");
136  if (m_h_hitsPerEvent != NULL && m_c_hitsPerEvent != NULL) {
137  m_c_hitsPerEvent->Clear();
138  m_c_hitsPerEvent->cd();
139  m_h_hitsPerEvent->SetMinimum(0);
140  m_h_hitsPerEvent->Draw("hist");
141  gPad->Update();
142 
143  int alertHitsPerEvent = 0;
144  double mean = m_h_hitsPerEvent->GetMean();
145  if (mean < 1) alertHitsPerEvent = 1;
146  double entry = m_h_hitsPerEvent->GetEntries();
147  if (entry == 0) alertHitsPerEvent = 2;
148  if (m_enableAlert) m_c_hitsPerEvent->SetFillColor(alertColor[alertHitsPerEvent]);
149 
150  m_c_hitsPerEvent->Modified();
151  } else {
152  B2INFO("Histogram/canvas named hitsPerEvent is not found.");
153  }
154 
155  //Draw 2D hit map of channels and APDs
156  TH1* m_h_chHit = findHist("ARICH/chipHit");
157  if (m_h_chHit != NULL) {
158  int nevt = 0;
159  TH1* htmp = findHist("ARICH/hitsPerEvent");
160  if (htmp) nevt = htmp->GetEntries();
161  m_apdHist->fillFromTH1(m_h_chHit);
162  if (nevt) m_apdHist->Scale(1. / float(nevt));
163  m_apdPoly->SetMaximum(0.1);
165  m_apdPoly->SetMinimum(0.0001);
166  m_c_apdHist->Clear();
167  m_c_apdHist->cd();
168  m_apdPoly->Draw("colz");
169  m_apdPoly->GetXaxis()->SetTickLength(0);
170  m_apdPoly->GetYaxis()->SetTickLength(0);
171  gPad->SetLogz();
172  m_c_apdHist->Update();
173  } else {
174  B2INFO("Histogram named chipHit is not found.");
175  }
176 
177 }
178 
180 {
181  B2DEBUG(20, "DQMHistAnalysisARICH : endRun called");
182 }
183 
185 {
186 
187  B2DEBUG(20, "terminate called");
188 }
ARICH histogram with HAPD plane 3 options for bin segmentation are available type 0 - one bin per HAP...
void fillFromTH1(TH1 *hist)
Fill the channelHist from the histogram Type 0 channelHist has to be filled with 420*144bin TH1 (each...
void setPoly(TH2Poly *poly)
Fill pure TH2Poly from ARICHChannelHist, makes bins and fills content.
void initialize() override final
Initialize the Module.
TCanvas * m_c_apdHist
Canvas for 2D hit map of APDs.
TH2Poly * m_apdPoly
hit map for each APD
TLine * m_LineForMB[5]
Lines to divide the sectors on mergerHit histogram.
TCanvas * m_c_mergerHit
Canvas for modified mergerHit histogram.
bool m_enableAlert
Enable alert by base color of canvases.
Belle2::ARICHChannelHist * m_apdHist
ARICH TObject to draw hit map for each APD.
void terminate() override final
Termination action.
void event() override final
Event processor.
void endRun() override final
End-of-run action.
TCanvas * m_c_bits
Canvas for modified bits histogram.
std::vector< int > maskedMergers
The id numbers of masked merger boards to avoid unnecessary alert.
TCanvas * m_c_hitsPerEvent
Canvas for modified hitsPerTrack histogram.
int alertColor[3]
Alert color of canvases.
The base class for the histogram analysis module.
TCanvas * findCanvas(TString cname)
Find canvas by name.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#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.