13 #include <dqm/analysis/modules/DQMHistAnalysisKLM.h>
16 #include <klm/dataobjects/KLMChannelIndex.h>
38 setDescription(
"Module used to analyze KLM DQM histograms.");
39 addParam(
"ThresholdForMasked", m_ThresholdForMasked,
40 "Threshold X for masked channels: if a channel has an occupancy X times larger than the average, it will be masked.", 100);
41 addParam(
"ThresholdForHot", m_ThresholdForHot,
42 "Threshold Y for hot channels: if a channel has an occupancy Y times larger than the average, it will be marked as hot (but not masked).",
44 addParam(
"MinHitsForFlagging", m_MinHitsForFlagging,
"Minimal number of hits in a channel required to flag it as 'Masked' or 'Hot'",
46 addParam(
"MinProcessedEventsForMessages", m_MinProcessedEventsForMessagesInput,
47 "Minimal number of processed events required to print error messages", 10000.);
49 m_MinProcessedEventsForMessages = m_MinProcessedEventsForMessagesInput;
50 m_2DHitsLine.SetLineColor(kRed);
51 m_2DHitsLine.SetLineWidth(3);
52 m_2DHitsLine.SetLineStyle(2);
53 m_PlaneLine.SetLineColor(kMagenta);
54 m_PlaneLine.SetLineWidth(1);
55 m_PlaneLine.SetLineStyle(2);
56 m_PlaneText.SetTextAlign(22);
57 m_PlaneText.SetTextColor(kMagenta);
58 m_PlaneText.SetTextFont(42);
59 m_PlaneText.SetTextSize(0.02);
69 B2FATAL(
"The threshold used for hot channels is larger than the one for masked channels."
81 B2FATAL(
"No KLM electronics map.");
95 TH1* histogram =
findHist(
"DAQ/Nevent");
96 if (histogram ==
nullptr) {
97 B2WARNING(
"DAQ DQM histogram DAQ/Nevent is not found.");
102 return histogram->GetEntries();
106 int subdetector,
int section,
int sector,
107 TH1* histogram, TCanvas* canvas, TLatex& latex)
113 std::map<uint16_t, double>::iterator it;
115 int channelSubdetector, channelSection, channelSector;
116 int layer, plane, strip;
120 histogram->SetStats(
false);
122 n = histogram->GetXaxis()->GetNbins();
123 for (i = 1; i <= n; i++) {
124 uint16_t channelIndex = std::round(histogram->GetBinCenter(i));
126 double nHitsPerModule = histogram->GetBinContent(i);
127 average = average + nHitsPerModule;
129 channelNumber, &channelSubdetector, &channelSection, &channelSector,
130 &layer, &plane, &strip);
131 if ((channelSubdetector != subdetector) ||
132 (channelSection != section) ||
133 (channelSector != sector))
134 B2FATAL(
"Inconsistent element numbers.");
136 subdetector, section, sector, layer);
139 moduleHitMap.insert(std::pair<uint16_t, double>(module, nHitsPerModule));
141 it->second += nHitsPerModule;
143 unsigned int activeModuleChannels = 0;
145 uint16_t moduleNumber = it->first;
146 if (it->second != 0) {
151 moduleNumber, &channelSubdetector, &channelSection, &channelSector, &layer);
154 channelSubdetector, channelSection, channelSector,
158 if (electronicsChannel ==
nullptr)
159 B2FATAL(
"Incomplete KLM electronics map.");
160 str =
"No data from HSLB ";
163 electronicsChannel->
getSlot());
166 electronicsChannel->
getSlot());
168 str +=
", lane " + std::to_string(electronicsChannel->
getLane());
169 latex.DrawLatexNDC(x, y, str.c_str());
187 if (activeModuleChannels == 0)
189 average /= activeModuleChannels;
190 for (i = 1; i <= n; ++i) {
191 uint16_t channelIndex = std::round(histogram->GetBinCenter(i));
193 double nHits = histogram->GetBinContent(i);
195 channelNumber, &channelSubdetector, &channelSection, &channelSector,
196 &layer, &plane, &strip);
197 std::string channelStatus =
"Normal";
199 channelStatus =
"Masked";
205 B2DEBUG(20,
"KLM@MaskMe " << channelNumber);
207 channelStatus =
"Hot";
209 if (channelStatus !=
"Normal") {
212 if (electronicsChannel ==
nullptr)
213 B2FATAL(
"Incomplete BKLM electronics map.");
214 if (channelStatus ==
"Masked")
215 histogram->SetBinContent(i, 0);
216 str = channelStatus +
" channel: HSLB ";
219 electronicsChannel->
getSlot());
222 electronicsChannel->
getSlot());
224 str += (
", lane " + std::to_string(electronicsChannel->
getLane()) +
225 ", axis " + std::to_string(electronicsChannel->
getAxis()) +
226 ", channel " + std::to_string(electronicsChannel->
getChannel()));
227 latex.DrawLatexNDC(x, y, str.c_str());
235 uint16_t section, TH2F* histogram, TCanvas* canvas)
239 histogram->SetStats(
false);
240 histogram->Draw(
"COLZ");
252 const std::string& histName)
254 TH1* histogram =
findHist(
"KLM/" + histName);
255 if (histogram ==
nullptr) {
256 B2ERROR(
"KLM DQM histogram KLM/" << histName <<
" is not found.");
259 TCanvas* canvas =
findCanvas(
"KLM/c_" + histName);
260 if (canvas ==
nullptr) {
261 B2ERROR(
"KLM DQM histogram canvas KLM/c_" << histName <<
" is not found.");
268 int channelSubdetector, channelSection, channelSector;
269 int layer, plane, strip;
272 channel, &channelSubdetector, &channelSection, &channelSector,
273 &layer, &plane, &strip);
274 uint16_t sectorNumber;
280 histogram->Fill(sectorIndex);
283 histogram->SetStats(
false);
289 const std::string& histName, TLatex& latex)
291 std::string name, alarm;
292 const double histMinNDC = 0.1;
293 const double histMaxNDC = 0.9;
294 const double histRangeNDC = histMaxNDC - histMinNDC;
295 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
296 double xAlarm = 0.15;
298 TH1* histogram =
findHist(
"KLM/" + histName);
299 if (histogram ==
nullptr) {
300 B2ERROR(
"KLM DQM histogram KLM/" << histName <<
" is not found.");
303 TCanvas* canvas =
findCanvas(
"KLM/c_" + histName);
304 if (canvas ==
nullptr) {
305 B2ERROR(
"KLM DQM histogram canvas KLM/c_" << histName <<
" is not found.");
310 histogram->SetStats(
false);
312 if (histName.find(
"bklm") != std::string::npos) {
316 double xLineNDC = histMinNDC + (histRangeNDC * sector) / maximalSector;
317 double xTextNDC = histMinNDC + (histRangeNDC * (sector + 0.5)) / maximalSector;
318 double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
320 m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
326 name += std::to_string(sector % 8);
327 m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
332 canvas->Pad()->SetFillColor(kWhite);
336 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
338 alarm +=
", layer " + std::to_string(moduleLayer);
339 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
342 alarm =
"Call the KLM experts immediately!";
343 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
344 canvas->Pad()->SetFillColor(kRed);
349 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
350 double xLineNDC = histMinNDC + (histRangeNDC * layerGlobal) / maximalLayer;
351 double xTextNDC = histMinNDC + (histRangeNDC * (layerGlobal - 0.5)) / maximalLayer;
352 double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
353 if (layerGlobal < maximalLayer)
354 m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
357 layerGlobal, §ion, &layer);
362 name += std::to_string(layer);
363 m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
368 canvas->Pad()->SetFillColor(kWhite);
372 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
374 alarm +=
", layer " + std::to_string(moduleLayer);
375 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
378 alarm =
"Call the KLM experts immediately!";
379 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
380 canvas->Pad()->SetFillColor(kRed);
389 TIter nextkey(gROOT->GetListOfCanvases());
390 TObject* obj =
nullptr;
391 while ((obj =
dynamic_cast<TObject*
>(nextkey()))) {
392 if (obj->IsA()->InheritsFrom(
"TCanvas")) {
393 if (obj->GetName() == canvasName)
394 return dynamic_cast<TCanvas*
>(obj);
403 int isKlmIncluded = 1;
405 TH1* daqInclusion =
findHist(
"KLM/daq_inclusion");
406 if (not(daqInclusion ==
nullptr)) {
407 isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
408 if (isKlmIncluded == 0)
416 std::string str, histogramName, canvasName;
418 latex.SetTextColor(kRed);
419 latex.SetTextAlign(11);
427 for (
int j = 0; j < nHistograms; j++) {
428 str =
"strip_hits_subdetector_" +
429 std::to_string(klmSector.getSubdetector()) +
430 "_section_" + std::to_string(klmSector.getSection()) +
431 "_sector_" + std::to_string(klmSector.getSector()) +
432 "_" + std::to_string(j);
433 histogramName =
"KLM/" + str;
434 canvasName =
"KLM/c_" + str;
435 TH1* histogram =
findHist(histogramName);
436 if (histogram ==
nullptr) {
437 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
441 if (canvas ==
nullptr) {
442 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
446 klmSector.getSubdetector(), klmSector.getSection(),
447 klmSector.getSector(), histogram, canvas, latex);
451 gStyle->SetPalette(kLightTemperature);
454 uint16_t subdetector = klmSection.getSubdetector();
456 uint16_t section = klmSection.getSection();
458 for (
int j = 1; j <= maximalLayerNumber; ++j) {
459 str =
"spatial_2d_hits_subdetector_" + std::to_string(subdetector) +
460 "_section_" + std::to_string(section) +
461 "_layer_" + std::to_string(j);
462 histogramName =
"KLM/" + str;
463 canvasName =
"KLM/c_" + str;
464 TH2F* histogram =
static_cast<TH2F*
>(
findHist(histogramName));
465 if (histogram ==
nullptr) {
466 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
470 if (canvas ==
nullptr) {
471 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
479 gStyle->SetPalette(kBird);
481 latex.SetTextColor(kBlue);