Belle II Software development
DetectorOccupanciesDQMModule.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#include "reconstruction/modules/detectorOccupanciesDQM/DetectorOccupanciesDQMModule.h"
10
11#include <TDirectory.h>
12
13
14
15using namespace Belle2;
16
17//-----------------------------------------------------------------
18// Register the Module
19//-----------------------------------------------------------------
20REG_MODULE(DetectorOccupanciesDQM);
21
22
23//-----------------------------------------------------------------
24// Implementation
25//-----------------------------------------------------------------
26
28 , m_eklmElementNumbers{&(EKLMElementNumbers::Instance())}
29{
30 setDescription("DQM Module to monitor basic detector quantities");
31
32 addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of the directory where histograms will be placed.",
33 std::string("DetectorOccupancies"));
34
35 addParam("eclEnergyThr", m_eclEnergyThr, "Energy threshold (in MeV) for ECL occupancy histogram", 5.0);
36
38}
39
40
41DetectorOccupanciesDQMModule::~DetectorOccupanciesDQMModule()
42{
43}
44
45//------------------------------------------------------------------
46// Function to define histograms
47//-----------------------------------------------------------------
48
50{
51
52 // Create a separate histogram directories and cd into it.
53 TDirectory* oldDir = gDirectory;
54 if (m_histogramDirectoryName != "") {
55 oldDir->mkdir(m_histogramDirectoryName.c_str());
56 oldDir->cd(m_histogramDirectoryName.c_str());
57 }
58
59 //histogram index:
60 // 0 if the event is triggered OUTSIDE the active_veto window
61 const std::string tag[2] = {"OUT", "IN"};
62 const std::string title[2] = {"[Outside Active Veto Window]", "[Inside Active Veto Window]"};
63
64
65 //BKLM plane occupancy (phi)
66 //outside active_veto window:
67 std::string histoName = "bklm_plane_phi_occupancy";
68 std::string histoTitle = "BKLM plane occupancy (#phi readout)";
69 m_BKLM_PlanePhi_Occupancy[0] = new TH1F((histoName + "_" + tag[0]).c_str(),
70 (histoTitle + " " + title[0]).c_str(),
71 240, 0.5, 240.5);
72 m_BKLM_PlanePhi_Occupancy[0]->GetXaxis()->SetTitle("Layer number");
73
74 //inside active_veto window:
76 m_BKLM_PlanePhi_Occupancy[1]->SetName((histoName + "_" + tag[1]).c_str());
77
78 m_BKLM_PlanePhi_Occupancy[1]->SetTitle((histoTitle + " " + title[1]).c_str());
79
80
81 //BKLM plane occupancy (z)
82 //outside active_veto window:
83 histoName = "bklm_plane_z_occupancy";
84 histoTitle = "BKLM plane occupancy (z readout)";
85 m_BKLM_PlaneZ_Occupancy[0] = new TH1F((histoName + "_" + tag[0]).c_str(),
86 (histoTitle + " " + title[0]).c_str(),
87 240, 0.5, 240.5);
88 m_BKLM_PlaneZ_Occupancy[0]->GetXaxis()->SetTitle("Layer number");
89
90 //inside active_veto window:
92 m_BKLM_PlaneZ_Occupancy[1]->SetName((histoName + "_" + tag[1]).c_str());
93 m_BKLM_PlaneZ_Occupancy[1]->SetTitle((histoTitle + " " + title[1]).c_str());
94
95
96 //EKLM plane occupancy
97 //outside active_veto window:
98 histoName = "eklm_plane_occupancy";
99 histoTitle = "EKLM plane occupancy (both readouts)";
100 m_EKLM_Plane_Occupancy[0] = new TH1F((histoName + "_" + tag[0]).c_str(),
101 (histoTitle + " " + title[0]).c_str(),
102 208, 0.5, 208.5);
103 m_EKLM_Plane_Occupancy[0]->GetXaxis()->SetTitle("Plane number");
104
105 //inside active_veto window:
107 m_EKLM_Plane_Occupancy[1]->SetName((histoName + "_" + tag[1]).c_str());
108 m_EKLM_Plane_Occupancy[1]->SetTitle((histoTitle + " " + title[1]).c_str());
109
110 //RPC Time
111 histoName = "bklm_rpc_time";
112 histoTitle = "BKLM RPC Hit Time";
113 m_BKLM_TimeRPC[0] = new TH1F((histoName + "_" + tag[0]).c_str(),
114 (histoTitle + " " + title[0]).c_str(),
115 128, double(-1223.5), double(-199.5));
116 m_BKLM_TimeRPC[0]->GetXaxis()->SetTitle("Time [ns]");
117
118 //inside active_veto window:
119 m_BKLM_TimeRPC[1] = new TH1F(*m_BKLM_TimeRPC[0]);
120 m_BKLM_TimeRPC[1]->SetName((histoName + "_" + tag[1]).c_str());
121 m_BKLM_TimeRPC[1]->SetTitle((histoTitle + " " + title[1]).c_str());
122
123 //BKLM Scintillator Time
124 histoName = "bklm_scintillator_time";
125 histoTitle = "BKLM Scintillator Hit Time";
126 m_BKLM_TimeScintillator[0] = new TH1F((histoName + "_" + tag[0]).c_str(),
127 (histoTitle + " " + title[0]).c_str(),
128 100, double(-5300), double(-4300));
129 m_BKLM_TimeScintillator[0]->GetXaxis()->SetTitle("Time [ns]");
130
131 //inside active_veto window:
133 m_BKLM_TimeScintillator[1]->SetName((histoName + "_" + tag[1]).c_str());
134 m_BKLM_TimeScintillator[1]->SetTitle((histoTitle + " " + title[1]).c_str());
135
136 //EKLM SCintillator Time
137 histoName = "eklm_scintillator_time";
138 histoTitle = "EKLM Scintillator Hit Time";
139 m_EKLM_TimeScintillator[0] = new TH1F((histoName + "_" + tag[0]).c_str(),
140 (histoTitle + " " + title[0]).c_str(),
141 100, double(-5300), double(-4300));
142 m_EKLM_TimeScintillator[0]->GetXaxis()->SetTitle("Time [ns]");
143
144 //inside active_veto window:
146 m_EKLM_TimeScintillator[1]->SetName((histoName + "_" + tag[1]).c_str());
147 m_EKLM_TimeScintillator[1]->SetTitle((histoTitle + " " + title[1]).c_str());
148
149 //ARICH plane occupancy
150 //outside active_veto window:
151 histoName = "arich_occupancy";
152 histoTitle = "ARICH Occupancy";
153 m_ARICH_Occupancy[0] = new TH1F((histoName + "_" + tag[0]).c_str(),
154 (histoTitle + " " + title[0]).c_str(),
155 201, -0.5, 200.5);
156 m_ARICH_Occupancy[0]->GetXaxis()->SetTitle("hits per event");
157
158 //inside active_veto window:
159 m_ARICH_Occupancy[1] = new TH1F(*m_ARICH_Occupancy[0]);
160 m_ARICH_Occupancy[1]->SetName((histoName + "_" + tag[1]).c_str());
161 m_ARICH_Occupancy[1]->SetTitle((histoTitle + " " + title[1]).c_str());
162
163 //TOP occupancy
164 histoName = "top_occupancy";
165 histoTitle = "TOP Occupancy for good hits";
166 for (int i = 0; i < 2; i++) {
167 m_TOP_Occupancy[i] = new TH1F((histoName + "_" + tag[i]).c_str(),
168 (histoTitle + " " + title[i]).c_str(),
169 1000, 0, 10000);
170 m_TOP_Occupancy[i]->SetXTitle("hits per event");
171 m_TOP_Occupancy[i]->SetYTitle("entries per bin");
172 }
173
174 //ECL occupancy
175 histoName = "ecl_occupancy";
176 histoTitle = "ECL occupancy (for hits with E > " + std::to_string((int)m_eclEnergyThr) + " MeV)";
177 for (int i = 0; i < 2; i++) {
178 m_ECL_Occupancy[i] = new TProfile((histoName + "_" + tag[i]).c_str(),
179 (histoTitle + " " + title[i]).c_str(),
182 m_ECL_Occupancy[i]->SetXTitle("cell id");
183 m_ECL_Occupancy[i]->SetYTitle("Occupancy (hits / evt_count)");
184 }
185
186
187 oldDir->cd();
188}
189
191{
192 m_eventMetaData.isOptional();
193 m_trgSummary.isOptional();
194 m_KLMDigits.isOptional();
195 m_BklmHit1ds.isOptional();
196 m_ARICHHits.isOptional();
197 m_topDigits.isOptional();
198 m_eclCalDigits.isOptional();
199
200 // Register histograms (calls back defineHisto)
201 REG_HISTOGRAM
202}
203
204
206{
207
208 for (int i = 0; i < 2; i++) {
209 if (m_BKLM_PlanePhi_Occupancy[i] != nullptr) m_BKLM_PlanePhi_Occupancy[i]->Reset();
210 if (m_BKLM_PlaneZ_Occupancy[i] != nullptr) m_BKLM_PlaneZ_Occupancy[i]->Reset();
211 if (m_EKLM_Plane_Occupancy[i] != nullptr) m_EKLM_Plane_Occupancy[i]->Reset();
212 if (m_BKLM_TimeRPC[i] != nullptr) m_BKLM_TimeRPC[i]->Reset();
213 if (m_BKLM_TimeScintillator[i] != nullptr) m_BKLM_TimeScintillator[i]->Reset();
214 if (m_EKLM_TimeScintillator[i] != nullptr) m_EKLM_TimeScintillator[i]->Reset();
215 if (m_ARICH_Occupancy[i] != nullptr) m_ARICH_Occupancy[i]->Reset();
216 if (m_TOP_Occupancy[i] != nullptr) m_TOP_Occupancy[i]->Reset();
217 if (m_ECL_Occupancy[i] != nullptr) m_ECL_Occupancy[i]->Reset();
218
219 }
220}
221
222
224{
225
226 //skip events in which we do not have EventMetaData or TRGSummary
227 if (!m_eventMetaData.isValid()) return;
228 if (!m_trgSummary.isValid()) return;
229
230 //skip the empty events
232 return;
233
235 return;
236
238 return;
239
241 return;
242
243 //find out if we are in the passive veto (i=0) or in the active veto window (i=1)
244 int index = 0; //events accepted in the passive veto window but not in the active
245 if (m_trgSummary->testInput("passive_veto") == 1 && m_trgSummary->testInput("cdcecl_veto") == 0) index = 1;
246
247
248 //fill the BKLM plane occupancy plots
249 for (const BKLMHit1d& hit1d : m_BklmHit1ds) {
250 int section = hit1d.getSection();
251 int sector = hit1d.getSector();
252 int layer = hit1d.getLayer();
254 section, sector, layer);
255 if (hit1d.isPhiReadout())
256 m_BKLM_PlanePhi_Occupancy[index]->Fill(layerGlobal);
257 else
258 m_BKLM_PlaneZ_Occupancy[index]->Fill(layerGlobal);
259
260 }
261
262 for (const KLMDigit& digit : m_KLMDigits) {
263 /*
264 * Reject digits that are below the threshold (such digits may appear
265 * for simulated events).
266 */
267 if (!digit.isGood())
268 continue;
269
270 if (digit.getSubdetector() == KLMElementNumbers::c_EKLM) {
271 int section = digit.getSection();
272 int layer = digit.getLayer();
273 int sector = digit.getSector();
274 int plane = digit.getPlane();
275 int planeGlobal = m_eklmElementNumbers->planeNumber(section, layer, sector, plane);
276 m_EKLM_Plane_Occupancy[index]->Fill(planeGlobal);
277 m_EKLM_TimeScintillator[index]->Fill(digit.getTime());
278 } else if (digit.getSubdetector() == KLMElementNumbers::c_BKLM) {
279
280 if (digit.inRPC()) m_BKLM_TimeRPC[index]->Fill(digit.getTime());
281 else m_BKLM_TimeScintillator[index]->Fill(digit.getTime());
282 }
283 }
284
285 float xMax = m_ARICH_Occupancy[0]->GetXaxis()->GetBinCenter(m_ARICH_Occupancy[0]->GetNbinsX());
286 int arichNentr = m_ARICHHits.isValid() ? m_ARICHHits.getEntries() : 0;
287 m_ARICH_Occupancy[index] -> Fill(arichNentr > xMax ? xMax : arichNentr);
288
289
290 int topGoodHits = 0;
291 for (const auto& digit : m_topDigits) {
292 if (digit.getHitQuality() != TOPDigit::c_Junk) topGoodHits++;
293 }
294 m_TOP_Occupancy[index]->Fill(topGoodHits);
295
296 std::array<bool, ECLElementNumbers::c_NCrystals> crystal_hit;
297
298 for (const auto& digit : m_eclCalDigits) {
299 const double thresholdGeV = m_eclEnergyThr * 1e-3;
300 if (digit.getEnergy() > thresholdGeV)
301 crystal_hit.at(digit.getCellId() - 1) = true;
302 }
303 for (int cid0 = 0; cid0 < ECLElementNumbers::c_NCrystals; cid0++) {
304 m_ECL_Occupancy[index]->Fill(cid0 + 1, crystal_hit[cid0]);
305 }
306
307}
static int layerGlobalNumber(int section, int sector, int layer)
Get layer global number.
Store one reconstructed BKLM 1D hit as a ROOT object.
Definition: BKLMHit1d.h:30
void initialize() override final
Module function initialize.
TH1F * m_EKLM_Plane_Occupancy[2]
EKLM plane integrated occupancy.
TH1F * m_TOP_Occupancy[2]
TOP occupancy (good hits only)
StoreArray< KLMDigit > m_KLMDigits
KLM digits.
const EKLMElementNumbers * m_eklmElementNumbers
EKLM Element numbers.
void defineHisto() override final
Defines Histograms.
StoreObjPtr< TRGSummary > m_trgSummary
trg summary
TH1F * m_BKLM_PlanePhi_Occupancy[2]
BKLM phi plane integrated occupancy.
StoreObjPtr< EventMetaData > m_eventMetaData
event meta data
void event() override final
Module function event.
std::string m_histogramDirectoryName
Name of the histogram directory in ROOT file.
double m_eclEnergyThr
Energy threshold (in MeV) for ECL occupancy histogram.
StoreArray< BKLMHit1d > m_BklmHit1ds
BKLM hit 1D.
void beginRun() override final
Module function beginRun.
TH1F * m_ARICH_Occupancy[2]
ARICH Digit Occupancy.
TH1F * m_BKLM_TimeScintillator[2]
BKLM Scintillator Hit Time.
StoreArray< ARICHHit > m_ARICHHits
ARICH hits.
TH1F * m_EKLM_TimeScintillator[2]
EKLM Scintillator Hit Time.
TProfile * m_ECL_Occupancy[2]
ECL occupancy (hits above 5 MeV)
StoreArray< TOPDigit > m_topDigits
collection of TOP digits
StoreArray< ECLCalDigit > m_eclCalDigits
collection of ECL digits
TH1F * m_BKLM_PlaneZ_Occupancy[2]
BKLM z plane integrated occupancy.
EKLM element numbers.
int planeNumber(int section, int layer, int sector, int plane) const
Get plane number.
@ c_B2LinkPacketCRCError
Belle2link CRC error is detected in the event.
Definition: EventMetaData.h:44
@ c_HLTCrash
The HLT reconstruction crashed in this event or the event before.
Definition: EventMetaData.h:46
@ c_ReconstructionAbort
The event was not reconstructed, e.g.
Definition: EventMetaData.h:47
@ c_B2LinkEventCRCError
HSLB_COPPER CRC error is detected in the event.
Definition: EventMetaData.h:45
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
KLM digit (class representing a digitized hit in RPCs or scintillators).
Definition: KLMDigit.h:29
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
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.