10#include <klm/dataobjects/KLMChannelArrayIndex.h>
11#include <klm/dataobjects/KLMElementNumbers.h>
12#include <klm/dataobjects/KLMSectorArrayIndex.h>
15#include <framework/logging/Logger.h>
29int main(
int argc,
char* argv[])
32 if (argc == 1 or std::string(argv[1]) ==
"--help" or std::string(argv[1]) ==
"-h") {
33 std::cout <<
"Usage: " << argv[0] <<
" [INPUT_FILE] [CHANNEL1] [CHANNEL2] ... [CHANNELN]\n\n"
34 " This tool masks the given channels of the KLM DQM reference plots stored\n"
35 " in the given input file (here 'channel' means 'channel number').\n\n"
36 " The plots on which this tool acts are:\n"
37 " KLM/masked_channels;\n"
38 " KLM/strip_hits_subdetector_<X>_section_<Y>_sector_<W>_<Z>.\n\n"
39 " This tool is not intended to be run standalone, since it is executed\n"
40 " by 'b2klm-mask-dqm', which automatically detects the channels to be masked.\n";
44 int nChannels = argc - 2;
46 B2ERROR(
"There are no channels to mask!");
49 std::string inputFileName(argv[1]);
50 if (inputFileName.find(
".root") == std::string::npos) {
51 B2ERROR(
"The input file is not a .root file!");
54 if (gSystem->AccessPathName(inputFileName.c_str())) {
55 B2ERROR(
"The input file does not exist!");
58 TFile* inputFile =
new TFile(inputFileName.c_str(),
"UPDATE");
59 if (!inputFile or inputFile->IsZombie()) {
60 B2ERROR(
"The input file is not working!");
68 TH1* histoSummary =
static_cast<TH1*
>(inputFile->Get(
"KLM/masked_channels"));
70 B2ERROR(
"The histogram KLM/masked_channels is not found!");
73 for (
int i = 2; i <= nChannels + 1; ++i) {
75 int subdetector, section, sector, layer, plane, strip;
77 channelNumber, &subdetector, §ion, §or, &layer, &plane, &strip);
85 for (
int j = 0; j < nHistoOccupancy; ++j) {
86 std::string histoOccupancyName =
"KLM/strip_hits_subdetector_" + std::to_string(subdetector) +
87 "_section_" + std::to_string(section) +
88 "_sector_" + std::to_string(sector) +
89 "_" + std::to_string(j);
90 TH1* histoOccupancy =
static_cast<TH1*
>(inputFile->Get(histoOccupancyName.c_str()));
91 if (!histoOccupancy) {
92 B2ERROR(
"The histogram " << histoOccupancyName <<
" is not found!");
95 TAxis* xAxis = histoOccupancy->GetXaxis();
96 double xMin = xAxis->GetXmin();
97 double xMax = xAxis->GetXmax();
98 if ((channelIndex >= xMin) and (channelIndex < xMax)) {
99 int bin = xAxis->FindBin(channelIndex);
100 histoOccupancy->SetBinContent(bin, 0);
101 inputFile->Write(
"", TObject::kOverwrite);
110 uint16_t sectorIndex = sectorArrayIndex->
getIndex(sectorNumber);
111 histoSummary->Fill(sectorIndex);
113 inputFile->Write(
"", TObject::kOverwrite);
116 B2INFO(
"Masking complete: the reference file " << inputFileName <<
" is now ready.");
static const KLMChannelArrayIndex & Instance()
Instantiation.
uint16_t getIndex(uint16_t number) const
Get element index.
KLMSectorNumber sectorNumberEKLM(int section, int sector) const
Get sector number for EKLM.
static KLMSectorNumber sectorNumberBKLM(int section, int sector)
Get sector number for BKLM.
static const KLMElementNumbers & Instance()
Instantiation.
void channelNumberToElementNumbers(KLMChannelNumber channel, int *subdetector, int *section, int *sector, int *layer, int *plane, int *strip) const
Get element numbers by channel number.
static const KLMSectorArrayIndex & Instance()
Instantiation.
uint16_t KLMSectorNumber
Sector number.
uint16_t KLMChannelNumber
Channel number.
Abstract base class for different kinds of events.