Belle II Software  release-08-01-10
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 
15 using namespace Belle2;
16 
17 REG_MODULE(EKLMDataChecker);
18 
20  Module(),
21  m_ElementNumbers(&(EKLMElementNumbers::Instance())),
22  m_GeoDat(nullptr)
23 {
24  setDescription("EKLM data checker module.");
25 }
26 
28 {
29 }
30 
32 {
33  m_Digits.isRequired();
35 }
36 
38 {
39 }
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;
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 
71 {
72 }
73 
74 static bool compareBadDigitRate(EKLMDataCheckerModule::StripData& dat1,
76 {
77  return (double(dat1.nBadDigits) / dat1.nDigits) >
78  (double(dat2.nBadDigits) / dat2.nDigits);
79 }
80 
81 static 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) {
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.
EKLM element numbers.
int stripNumber(int section, int layer, int sector, int plane, int strip) const
Get strip number.
void stripNumberToElementNumbers(int stripGlobal, int *section, int *layer, int *sector, int *plane, int *strip) const
Get element numbers by strip global number.
int getNPlanes() const
Get number of planes.
int getNSections() const
Get number of sections.
int getNDetectorLayers(int section) const
Get number of detector layers.
int getNStrips() const
Get number of strips.
int getNSectors() const
Get number of sectors.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
Definition: GeometryData.cc:33
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
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
REG_MODULE(arichBtest)
Register the Module.
Abstract base class for different kinds of events.
int nBadDigits
Number of digits with readout error.