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