Belle II Software development
EKLMDataCheckerModule.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 <klm/eklm/modules/EKLMDataChecker/EKLMDataCheckerModule.h>
11
12/* C++ headers. */
13#include <algorithm>
14
15using namespace Belle2;
16
17REG_MODULE(EKLMDataChecker);
18
20 Module(),
22 m_GeoDat(nullptr)
23{
24 setDescription("EKLM data checker module.");
25}
26
30
36
40
42{
43 const uint16_t c_ChargeError = 0x0FFF;
44 int i, n, strip;
45 std::map<int, StripData>::iterator it;
46 StripData data;
47 n = m_Digits.getEntries();
48 for (i = 0; i < n; i++) {
49 KLMDigit* eklmDigit = m_Digits[i];
50 if (eklmDigit->getSubdetector() != KLMElementNumbers::c_EKLM)
51 continue;
52 strip = m_ElementNumbers->stripNumber(
53 eklmDigit->getSection(), eklmDigit->getLayer(),
54 eklmDigit->getSector(), eklmDigit->getPlane(),
55 eklmDigit->getStrip());
56 it = m_StripDataMap.find(strip);
57 if (it == m_StripDataMap.end()) {
58 data.strip = strip;
59 data.nDigits = 1;
60 data.nBadDigits = (eklmDigit->getCharge() == c_ChargeError) ? 1 : 0;
61 m_StripDataMap.insert(std::pair<int, StripData>(strip, data));
62 } else {
63 it->second.nDigits++;
64 if (eklmDigit->getCharge() == c_ChargeError)
65 it->second.nBadDigits++;
66 }
67 }
68}
69
73
74static bool compareBadDigitRate(EKLMDataCheckerModule::StripData& dat1,
76{
77 return (double(dat1.nBadDigits) / dat1.nDigits) >
78 (double(dat2.nBadDigits) / dat2.nDigits);
79}
80
81static bool compareStripNumber(const EKLMDataCheckerModule::StripData& dat1,
83{
84 return dat1.strip < dat2.strip;
85}
86
88{
89 int section, layer, sector, plane, strip, stripGlobal;
90 std::map<int, StripData>::iterator it;
91 std::vector<StripData> stripDataVector;
92 std::vector<StripData>::iterator it2, it3, it4;
93 for (it = m_StripDataMap.begin(); it != m_StripDataMap.end(); ++it)
94 stripDataVector.push_back(it->second);
95 sort(stripDataVector.begin(), stripDataVector.end(), compareBadDigitRate);
96 printf("EKLM data checker report.\n"
97 "Strips with readout errors sorted by error rate:\n");
98 it2 = stripDataVector.begin();
99 while (it2 != stripDataVector.end()) {
100 if (it2->nBadDigits == 0)
101 break;
102 it3 = it2;
103 while (it3 != stripDataVector.end()) {
104 if (it3->nBadDigits != it2->nBadDigits || it3->nDigits != it2->nDigits)
105 break;
106 ++it3;
107 }
108 sort(it2, it3, compareStripNumber);
109 for (it4 = it2; it4 != it3; ++it4) {
110 m_ElementNumbers->stripNumberToElementNumbers(
111 it4->strip, &section, &layer, &sector, &plane, &strip);
112 printf("Section %d, layer %d, sector %d, plane %d, strip %d: %.1f%% "
113 "(%d/%d)\n",
114 section, layer, sector, plane, strip,
115 float(it4->nBadDigits) / it4->nDigits * 100,
116 it4->nBadDigits, it4->nDigits);
117 }
118 it2 = it3;
119 }
120 printf("Strips with no data collected:\n");
121 for (section = 1; section <= m_GeoDat->getNSections(); section++) {
122 for (layer = 1; layer <= m_GeoDat->getNDetectorLayers(section); layer++) {
123 for (sector = 1; sector <= m_GeoDat->getNSectors(); sector++) {
124 for (plane = 1; plane <= m_GeoDat->getNPlanes(); plane++) {
125 for (strip = 1; strip <= m_GeoDat->getNStrips(); strip++) {
126 stripGlobal = m_ElementNumbers->stripNumber(
127 section, layer, sector, plane, strip);
128 it = m_StripDataMap.find(stripGlobal);
129 if (it == m_StripDataMap.end()) {
130 printf("Section %d, layer %d, sector %d, plane %d, strip %d.\n",
131 section, layer, sector, plane, strip);
132 }
133 }
134 }
135 }
136 }
137 }
138}
139
const EKLM::GeometryData * m_GeoDat
Geometry data.
StoreArray< KLMDigit > m_Digits
Digits.
void initialize() override
Initializer.
std::map< int, struct StripData > m_StripDataMap
Map of strip data information.
void event() override
This method is called for each event.
void endRun() override
This method is called if the current run ends.
void terminate() override
This method is called at the end of the event processing.
void beginRun() override
Called when entering a new run.
const EKLMElementNumbers * m_ElementNumbers
Element numbers.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
KLM digit (class representing a digitized hit in RPCs or scintillators).
Definition KLMDigit.h:29
int getSubdetector() const
Get subdetector number.
Definition KLMDigit.h:72
int getLayer() const
Get layer number.
Definition KLMDigit.h:126
int getSection() const
Get section number.
Definition KLMDigit.h:90
int getPlane() const
Get plane number.
Definition KLMDigit.h:144
int getStrip() const
Get strip number.
Definition KLMDigit.h:162
int getSector() const
Get sector number.
Definition KLMDigit.h:108
uint16_t getCharge() const
Get charge.
Definition KLMDigit.h:222
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Module()
Constructor.
Definition Module.cc:30
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.
int nBadDigits
Number of digits with readout error.