12 #include <klm/dataobjects/KLMChannelArrayIndex.h>
13 #include <klm/dataobjects/KLMChannelIndex.h>
14 #include <klm/dataobjects/KLMElementNumbers.h>
15 #include <klm/dataobjects/KLMSectorArrayIndex.h>
18 #include <framework/logging/Logger.h>
32 int main(
int argc,
char* argv[])
35 if (argc == 1 or std::string(argv[1]) ==
"--help" or std::string(argv[1]) ==
"-h") {
36 std::cout <<
"Usage: " << argv[0] <<
" [INPUT_FILE] [CHANNEL1] [CHANNEL2] ... [CHANNELN]\n\n"
37 " This tool masks the given channels of the KLM DQM reference plots stored\n"
38 " in the given input file (here 'channel' means 'channel number').\n\n"
39 " The plots on which this tool acts are:\n"
40 " KLM/masked_channels;\n"
41 " KLM/strip_hits_subdetector_<X>_section_<Y>_sector_<W>_<Z>.\n\n"
42 " This tool is not intended to be run standalone, since it is executed\n"
43 " by 'b2klm-mask-dqm', which automatically detects the channels to be masked.\n";
47 int nChannels = argc - 2;
49 B2ERROR(
"There are no channels to mask!");
52 std::string inputFileName(argv[1]);
53 if (inputFileName.find(
".root") == std::string::npos) {
54 B2ERROR(
"The input file is not a .root file!");
57 if (gSystem->AccessPathName(inputFileName.c_str())) {
58 B2ERROR(
"The input file does not exist!");
61 TFile* inputFile =
new TFile(inputFileName.c_str(),
"UPDATE");
62 if (!inputFile or inputFile->IsZombie()) {
63 B2ERROR(
"The input file is not working!");
71 TH1* histoSummary = (TH1*)inputFile->Get(
"KLM/masked_channels");
73 B2ERROR(
"The histogram KLM/masked_channels is not found!");
76 for (
int i = 2; i <= nChannels + 1; ++i) {
77 uint16_t channelNumber = std::atoi(argv[i]);
78 int subdetector, section, sector, layer, plane, strip;
80 channelNumber, &subdetector, §ion, §or, &layer, &plane, &strip);
82 uint16_t channelIndex = channelArrayIndex->
getIndex(channelNumber);
88 for (
int j = 0; j < nHistoOccupancy; ++j) {
89 std::string histoOccupancyName =
"KLM/strip_hits_subdetector_" + std::to_string(subdetector) +
90 "_section_" + std::to_string(section) +
91 "_sector_" + std::to_string(sector) +
92 "_" + std::to_string(j);
93 TH1* histoOccupancy = (TH1*)inputFile->Get(histoOccupancyName.c_str());
94 if (!histoOccupancy) {
95 B2ERROR(
"The histogram " << histoOccupancyName <<
" is not found!");
98 TAxis* xAxis = histoOccupancy->GetXaxis();
99 double xMin = xAxis->GetXmin();
100 double xMax = xAxis->GetXmax();
101 if ((channelIndex >= xMin) and (channelIndex < xMax)) {
102 int bin = xAxis->FindBin(channelIndex);
103 histoOccupancy->SetBinContent(bin, 0);
104 inputFile->Write(
"", TObject::kOverwrite);
108 uint16_t sectorNumber;
113 uint16_t sectorIndex = sectorArrayIndex->
getIndex(sectorNumber);
114 histoSummary->Fill(sectorIndex);
116 inputFile->Write(
"", TObject::kOverwrite);
119 B2INFO(
"Masking complete: the reference file " << inputFileName <<
" is now ready.");