Belle II Software  release-05-02-19
EKLMDataCheckerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Kirill Chilikin *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 /* Own header. */
12 #include <klm/eklm/modules/EKLMDataChecker/EKLMDataCheckerModule.h>
13 
14 /* C++ headers. */
15 #include <algorithm>
16 
17 using namespace Belle2;
18 
19 REG_MODULE(EKLMDataChecker)
20 
22  Module(),
23  m_ElementNumbers(&(EKLMElementNumbers::Instance())),
24  m_GeoDat(nullptr)
25 {
26  setDescription("EKLM data checker module.");
27 }
28 
30 {
31 }
32 
34 {
35  m_Digits.isRequired();
37 }
38 
40 {
41 }
42 
44 {
45  const uint16_t c_ChargeError = 0x0FFF;
46  int i, n, strip;
47  std::map<int, StripData>::iterator it;
48  StripData data;
49  n = m_Digits.getEntries();
50  for (i = 0; i < n; i++) {
51  KLMDigit* eklmDigit = m_Digits[i];
52  if (eklmDigit->getSubdetector() != KLMElementNumbers::c_EKLM)
53  continue;
55  eklmDigit->getSection(), eklmDigit->getLayer(),
56  eklmDigit->getSector(), eklmDigit->getPlane(),
57  eklmDigit->getStrip());
58  it = m_StripDataMap.find(strip);
59  if (it == m_StripDataMap.end()) {
60  data.strip = strip;
61  data.nDigits = 1;
62  data.nBadDigits = (eklmDigit->getCharge() == c_ChargeError) ? 1 : 0;
63  m_StripDataMap.insert(std::pair<int, StripData>(strip, data));
64  } else {
65  it->second.nDigits++;
66  if (eklmDigit->getCharge() == c_ChargeError)
67  it->second.nBadDigits++;
68  }
69  }
70 }
71 
73 {
74 }
75 
76 static bool compareBadDigitRate(EKLMDataCheckerModule::StripData& dat1,
78 {
79  return (double(dat1.nBadDigits) / dat1.nDigits) >
80  (double(dat2.nBadDigits) / dat2.nDigits);
81 }
82 
83 static bool compareStripNumber(const EKLMDataCheckerModule::StripData& dat1,
85 {
86  return dat1.strip < dat2.strip;
87 }
88 
90 {
91  int section, layer, sector, plane, strip, stripGlobal;
92  std::map<int, StripData>::iterator it;
93  std::vector<StripData> stripDataVector;
94  std::vector<StripData>::iterator it2, it3, it4;
95  for (it = m_StripDataMap.begin(); it != m_StripDataMap.end(); ++it)
96  stripDataVector.push_back(it->second);
97  sort(stripDataVector.begin(), stripDataVector.end(), compareBadDigitRate);
98  printf("EKLM data checker report.\n"
99  "Strips with readout errors sorted by error rate:\n");
100  it2 = stripDataVector.begin();
101  while (it2 != stripDataVector.end()) {
102  if (it2->nBadDigits == 0)
103  break;
104  it3 = it2;
105  while (it3 != stripDataVector.end()) {
106  if (it3->nBadDigits != it2->nBadDigits || it3->nDigits != it2->nDigits)
107  break;
108  ++it3;
109  }
110  sort(it2, it3, compareStripNumber);
111  for (it4 = it2; it4 != it3; ++it4) {
113  it4->strip, &section, &layer, &sector, &plane, &strip);
114  printf("Section %d, layer %d, sector %d, plane %d, strip %d: %.1f%% "
115  "(%d/%d)\n",
116  section, layer, sector, plane, strip,
117  float(it4->nBadDigits) / it4->nDigits * 100,
118  it4->nBadDigits, it4->nDigits);
119  }
120  it2 = it3;
121  }
122  printf("Strips with no data collected:\n");
123  for (section = 1; section <= m_GeoDat->getNSections(); section++) {
124  for (layer = 1; layer <= m_GeoDat->getNDetectorLayers(section); layer++) {
125  for (sector = 1; sector <= m_GeoDat->getNSectors(); sector++) {
126  for (plane = 1; plane <= m_GeoDat->getNPlanes(); plane++) {
127  for (strip = 1; strip <= m_GeoDat->getNStrips(); strip++) {
128  stripGlobal = m_ElementNumbers->stripNumber(
129  section, layer, sector, plane, strip);
130  it = m_StripDataMap.find(stripGlobal);
131  if (it == m_StripDataMap.end()) {
132  printf("Section %d, layer %d, sector %d, plane %d, strip %d.\n",
133  section, layer, sector, plane, strip);
134  }
135  }
136  }
137  }
138  }
139  }
140 }
141 
Belle2::KLMDigit::getSubdetector
int getSubdetector() const
Get subdetector number.
Definition: KLMDigit.h:89
Belle2::KLMDigit::getPlane
int getPlane() const
Get plane number.
Definition: KLMDigit.h:161
Belle2::EKLMDataCheckerModule
Module for checking of collected data.
Definition: EKLMDataCheckerModule.h:41
Belle2::EKLMDataCheckerModule::StripData::nDigits
int nDigits
Total number of digits.
Definition: EKLMDataCheckerModule.h:50
Belle2::EKLMElementNumbers
EKLM element numbers.
Definition: EKLMElementNumbers.h:34
Belle2::EKLMDataCheckerModule::event
virtual void event() override
This method is called for each event.
Definition: EKLMDataCheckerModule.cc:43
Belle2::EKLMElementNumbers::stripNumberToElementNumbers
void stripNumberToElementNumbers(int stripGlobal, int *section, int *layer, int *sector, int *plane, int *strip) const
Get element numbers by strip global number.
Definition: EKLMElementNumbers.cc:220
Belle2::EKLMGeometry::getNPlanes
int getNPlanes() const
Get number of planes.
Definition: EKLMGeometry.h:1717
Belle2::EKLMDataCheckerModule::m_GeoDat
const EKLM::GeometryData * m_GeoDat
Geometry data.
Definition: EKLMDataCheckerModule.h:95
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::EKLMDataCheckerModule::StripData
Strip data information.
Definition: EKLMDataCheckerModule.h:48
Belle2::KLMElementNumbers::c_EKLM
@ c_EKLM
EKLM.
Definition: KLMElementNumbers.h:50
Belle2::KLMDigit::getSection
int getSection() const
Get section number.
Definition: KLMDigit.h:107
Belle2::KLMDigit::getSector
int getSector() const
Get sector number.
Definition: KLMDigit.h:125
Belle2::KLMDigit::getLayer
int getLayer() const
Get layer number.
Definition: KLMDigit.h:143
Belle2::KLMDigit::getCharge
uint16_t getCharge() const
Get charge.
Definition: KLMDigit.h:239
Belle2::KLMDigit
KLM digit (class representing a digitized hit in RPCs or scintillators).
Definition: KLMDigit.h:40
Belle2::EKLMDataCheckerModule::~EKLMDataCheckerModule
virtual ~EKLMDataCheckerModule()
Destructor.
Definition: EKLMDataCheckerModule.cc:29
Belle2::EKLMDataCheckerModule::beginRun
virtual void beginRun() override
Called when entering a new run.
Definition: EKLMDataCheckerModule.cc:39
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::EKLMGeometry::getNStrips
int getNStrips() const
Get number of strips.
Definition: EKLMGeometry.h:1741
Belle2::EKLMDataCheckerModule::endRun
virtual void endRun() override
This method is called if the current run ends.
Definition: EKLMDataCheckerModule.cc:72
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::EKLMDataCheckerModule::StripData::nBadDigits
int nBadDigits
Number of digits with readout error.
Definition: EKLMDataCheckerModule.h:51
Belle2::EKLMDataCheckerModule::m_Digits
StoreArray< KLMDigit > m_Digits
Digits.
Definition: EKLMDataCheckerModule.h:98
Belle2::EKLMGeometry::getNDetectorLayers
int getNDetectorLayers(int section) const
Get number of detector layers.
Definition: EKLMGeometry.cc:295
Belle2::EKLMElementNumbers::stripNumber
int stripNumber(int section, int layer, int sector, int plane, int strip) const
Get strip number.
Definition: EKLMElementNumbers.cc:212
Belle2::EKLMDataCheckerModule::m_ElementNumbers
const EKLMElementNumbers * m_ElementNumbers
Element numbers.
Definition: EKLMDataCheckerModule.h:92
Belle2::EKLMDataCheckerModule::m_StripDataMap
std::map< int, struct StripData > m_StripDataMap
Map of strip data information.
Definition: EKLMDataCheckerModule.h:101
Belle2::EKLMDataCheckerModule::StripData::strip
int strip
Strip global number.
Definition: EKLMDataCheckerModule.h:49
Belle2::KLMDigit::getStrip
int getStrip() const
Get strip number.
Definition: KLMDigit.h:179
Belle2::EKLMGeometry::getNSections
int getNSections() const
Get number of sections.
Definition: EKLMGeometry.h:1687
Belle2::EKLMGeometry::getNSectors
int getNSectors() const
Get number of sectors.
Definition: EKLMGeometry.h:1709
Belle2::EKLMDataCheckerModule::initialize
virtual void initialize() override
Initializer.
Definition: EKLMDataCheckerModule.cc:33
Belle2::EKLM::GeometryData::Instance
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
Definition: GeometryData.cc:35
Belle2::EKLMDataCheckerModule::terminate
virtual void terminate() override
This method is called at the end of the event processing.
Definition: EKLMDataCheckerModule.cc:89