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
38{
39 const uint16_t c_ChargeError = 0x0FFF;
40 int i, n, strip;
41 std::map<int, StripData>::iterator it;
42 StripData data;
43 n = m_Digits.getEntries();
44 for (i = 0; i < n; i++) {
45 const KLMDigit* eklmDigit = m_Digits[i];
46 if (eklmDigit->getSubdetector() != KLMElementNumbers::c_EKLM)
47 continue;
48 strip = m_ElementNumbers->stripNumber(
49 eklmDigit->getSection(), eklmDigit->getLayer(),
50 eklmDigit->getSector(), eklmDigit->getPlane(),
51 eklmDigit->getStrip());
52 it = m_StripDataMap.find(strip);
53 if (it == m_StripDataMap.end()) {
54 data.strip = strip;
55 data.nDigits = 1;
56 data.nBadDigits = (eklmDigit->getCharge() == c_ChargeError) ? 1 : 0;
57 m_StripDataMap.insert(std::pair<int, StripData>(strip, data));
58 } else {
59 it->second.nDigits++;
60 if (eklmDigit->getCharge() == c_ChargeError)
61 it->second.nBadDigits++;
62 }
63 }
64}
65
66static bool compareBadDigitRate(const EKLMDataCheckerModule::StripData& dat1,
68{
69 return (double(dat1.nBadDigits) / dat1.nDigits) >
70 (double(dat2.nBadDigits) / dat2.nDigits);
71}
72
73static bool compareStripNumber(const EKLMDataCheckerModule::StripData& dat1,
75{
76 return dat1.strip < dat2.strip;
77}
78
80{
81 int section, layer, sector, plane, strip, stripGlobal;
82 std::map<int, StripData>::iterator it;
83 std::vector<StripData> stripDataVector;
84 std::vector<StripData>::iterator it2, it3, it4;
85 for (it = m_StripDataMap.begin(); it != m_StripDataMap.end(); ++it)
86 stripDataVector.push_back(it->second);
87 sort(stripDataVector.begin(), stripDataVector.end(), compareBadDigitRate);
88 printf("EKLM data checker report.\n"
89 "Strips with readout errors sorted by error rate:\n");
90 it2 = stripDataVector.begin();
91 while (it2 != stripDataVector.end()) {
92 if (it2->nBadDigits == 0)
93 break;
94 it3 = it2;
95 while (it3 != stripDataVector.end()) {
96 if (it3->nBadDigits != it2->nBadDigits || it3->nDigits != it2->nDigits)
97 break;
98 ++it3;
99 }
100 sort(it2, it3, compareStripNumber);
101 for (it4 = it2; it4 != it3; ++it4) {
102 m_ElementNumbers->stripNumberToElementNumbers(
103 it4->strip, &section, &layer, &sector, &plane, &strip);
104 printf("Section %d, layer %d, sector %d, plane %d, strip %d: %.1f%% "
105 "(%d/%d)\n",
106 section, layer, sector, plane, strip,
107 float(it4->nBadDigits) / it4->nDigits * 100,
108 it4->nBadDigits, it4->nDigits);
109 }
110 it2 = it3;
111 }
112 printf("Strips with no data collected:\n");
113 for (section = 1; section <= m_GeoDat->getNSections(); section++) {
114 for (layer = 1; layer <= m_GeoDat->getNDetectorLayers(section); layer++) {
115 for (sector = 1; sector <= m_GeoDat->getNSectors(); sector++) {
116 for (plane = 1; plane <= m_GeoDat->getNPlanes(); plane++) {
117 for (strip = 1; strip <= m_GeoDat->getNStrips(); strip++) {
118 stripGlobal = m_ElementNumbers->stripNumber(
119 section, layer, sector, plane, strip);
120 it = m_StripDataMap.find(stripGlobal);
121 if (it == m_StripDataMap.end()) {
122 printf("Section %d, layer %d, sector %d, plane %d, strip %d.\n",
123 section, layer, sector, plane, strip);
124 }
125 }
126 }
127 }
128 }
129 }
130}
131
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 terminate() override
This method is called at the end of the event processing.
const EKLMElementNumbers * m_ElementNumbers
Element numbers.
~EKLMDataCheckerModule() override
Destructor.
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:224
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.