Belle II Software  release-06-01-15
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 include
10 #include <dqm/analysis/modules/DQMHistAnalysisARICH.h>
11 
12 //DQM
13 #include <dqm/analysis/modules/DQMHistAnalysis.h>
14 
15 #include <TH1F.h>
16 #include <TH2F.h>
17 #include <TCanvas.h>
18 #include <TLine.h>
19 #include <TClass.h>
20 #include <TROOT.h>
21 
22 #include <fstream>
23 #include <vector>
24 #include <algorithm>
25 
26 using namespace std;
27 using namespace Belle2;
28 
29 //-----------------------------------------------------------------
30 // Register module
31 //-----------------------------------------------------------------
32 
33 REG_MODULE(DQMHistAnalysisARICH);
34 
35 DQMHistAnalysisARICHModule::DQMHistAnalysisARICHModule()
37 {
38  // set module description (e.g. insert text)
39  setDescription("Modify and analyze the data quality histograms of ARICH");
41  addParam("debug", m_debug, "debug mode", false);
42  addParam("alert", m_enableAlert, "Enable color alert", true);
43 }
44 
46 {
47 }
48 
50 {
51  gROOT->cd();
52 
53  //definition of new TObjects for modification and analysis
54  for (int i = 0; i < 5; i++) {
55  m_LineForMB[i] = new TLine();
56  m_LineForMB[i]->SetLineStyle(3);
57  m_LineForMB[i]->SetLineWidth(1);
58  m_LineForMB[i]->SetLineColor(kBlack);
59  }
60 
61  m_apdHist = new ARICHChannelHist("tmpChHist", "tmpChHist", 2);
62  m_apdPoly = new TH2Poly();
63  m_apdPoly->SetName("ARICH/apdHitMap");
64  m_apdPoly->SetTitle("# of hits/APD/event");
65  m_apdPoly->SetOption("colz");
66  m_c_apdHist = new TCanvas("ARICH/c_apdHist");
67 
68  B2DEBUG(20, "DQMHistAnalysisARICH: initialized.");
69 }
70 
72 {
73 }
74 
76 {
77 
78  //Show alert by empty bins = red and strange entries = yellow
79  //Draw lines on mergerHits histogram for shifters to divide sectors
80  TH1* m_h_mergerHit = findHist("ARICH/mergerHit");
81  m_c_mergerHit = findCanvas("ARICH/c_mergerHit");
82  if (m_h_mergerHit != NULL && m_c_mergerHit != NULL) {
83  m_c_mergerHit->Clear();
84  m_c_mergerHit->cd();
85  m_h_mergerHit->SetMinimum(0);
86  m_h_mergerHit->Draw("hist");
87  gPad->Update();
88 
89  int alertMerger = 0;
90  double mean = m_h_mergerHit->Integral() / 72;
91  for (int i = 0; i < 72; i++) {
92  int hit = m_h_mergerHit->GetBinContent(i + 1);
93  if ((bool)hit ^ (bool)m_h_mergerHit->GetEntries()) {
94  //only if the empty bin is not a masked merger, show alert.
95  auto itr = std::find(maskedMergers.begin(), maskedMergers.end(), i + 1);
96  if (itr == maskedMergers.end()) {
97  alertMerger = 2;
98  break;
99  }
100  }
101  if (hit > mean * 100 && alertMerger < 1) alertMerger = 1;
102  }
103  if (m_enableAlert && m_minStats < m_h_mergerHit->GetEntries()) m_c_mergerHit->SetFillColor(alertColor[alertMerger]);
104 
105  //Draw lines divide the sectors
106  for (int i = 0; i < 5; i++) {
107  m_LineForMB[i]->DrawLine(12 * (i + 1) + 0.5, 0, 12 * (i + 1) + 0.5, gPad->GetUymax());
108  }
109 
110  m_c_mergerHit->Modified();
111  } else {
112  B2INFO("Histogram/canvas named mergerHit is not found.");
113  }
114 
115 
116  //Show alert by the ratio of center 2 bins to side 2bins. <1.5 = red, <2 = yellow
117  TH1* m_h_bits = findHist("ARICH/bits");
118  m_c_bits = findCanvas("ARICH/c_bits");
119  if (m_h_bits != NULL && m_c_bits != NULL) {
120  m_c_bits->Clear();
121  m_c_bits->cd();
122  m_h_bits->SetMinimum(0);
123  m_h_bits->Draw("hist");
124  gPad->Update();
125 
126  int alertBits = 0;
128  double side = m_h_bits->GetBinContent(2) + m_h_bits->GetBinContent(5);
129  double center = m_h_bits->GetBinContent(3) + m_h_bits->GetBinContent(4);
130  if (center / side < 2) alertBits = 1;
131  if (center / side < 1.5) alertBits = 2;
132  if (m_enableAlert && m_minStats < m_h_bits->GetEntries()) m_c_bits->SetFillColor(alertColor[alertBits]);
133 
134  m_c_bits->Modified();
135  } else {
136  B2INFO("Histogram/canvas named bits is not found.");
137  }
138 
139  //Show alert by no entry = red and 0 peak = yellow
140  TH1* m_h_hitsPerEvent = findHist("ARICH/hitsPerEvent");
141  m_c_hitsPerEvent = findCanvas("ARICH/c_hitsPerEvent");
142  if (m_h_hitsPerEvent != NULL && m_c_hitsPerEvent != NULL) {
143  m_c_hitsPerEvent->Clear();
144  m_c_hitsPerEvent->cd();
145  m_h_hitsPerEvent->SetMinimum(0);
146  m_h_hitsPerEvent->Draw("hist");
147  gPad->Update();
148 
149  int alertHitsPerEvent = 0;
150  double mean = m_h_hitsPerEvent->GetMean();
151  if (mean < 1) alertHitsPerEvent = 1;
152  double entry = m_h_hitsPerEvent->GetEntries();
153  if (entry == 0) alertHitsPerEvent = 2;
154  if (m_enableAlert) m_c_hitsPerEvent->SetFillColor(alertColor[alertHitsPerEvent]);
155 
156  m_c_hitsPerEvent->Modified();
157  } else {
158  B2INFO("Histogram/canvas named hitsPerEvent is not found.");
159  }
160 
161  //Draw 2D hit map of channels and APDs
162  TH1* m_h_chHit = findHist("ARICH/chipHit");
163  if (m_h_chHit != NULL) {
164  int nevt = 0;
165  TH1* htmp = findHist("ARICH/hitsPerEvent");
166  if (htmp) nevt = htmp->GetEntries();
167  m_apdHist->fillFromTH1(m_h_chHit);
168  if (nevt) m_apdHist->Scale(1. / float(nevt));
169  m_apdPoly->SetMaximum(0.1);
171  m_apdPoly->SetMinimum(0.0001);
172  m_c_apdHist->Clear();
173  m_c_apdHist->cd();
174  m_apdPoly->Draw("colz");
175  m_apdPoly->GetXaxis()->SetTickLength(0);
176  m_apdPoly->GetYaxis()->SetTickLength(0);
177  gPad->SetLogz();
178  m_c_apdHist->Update();
179  } else {
180  B2INFO("Histogram named chipHit is not found.");
181  }
182 
183 }
184 
186 {
187  B2DEBUG(20, "DQMHistAnalysisARICH : endRun called");
188 }
189 
191 {
192 
193  B2DEBUG(20, "terminate called");
194 }
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.
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.
virtual void initialize() override
Initialize the Module.
bool m_enableAlert
Enable alert by base color of canvases.
virtual void event() override
Event processor.
Belle2::ARICHChannelHist * m_apdHist
ARICH TObject to draw hit map for each APD.
virtual void endRun() override
End-of-run action.
virtual void terminate() override
Termination action.
virtual void beginRun() override
Called when entering a new run.
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.
virtual ~DQMHistAnalysisARICHModule()
Destructor.
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)
Find histogram.
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.