13 #include <dqm/analysis/modules/DQMHistAnalysisKLM.h>
16 #include <klm/dataobjects/KLMChannelIndex.h>
37 setDescription(
"Module used to analyze KLM DQM histograms.");
38 addParam(
"ThresholdForMasked", m_ThresholdForMasked,
39 "Threshold X for masked channels: if a channel has an occupancy X times larger than the average, it will be masked.", 100);
40 addParam(
"ThresholdForHot", m_ThresholdForHot,
41 "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).",
43 addParam(
"MinHitsForFlagging", m_MinHitsForFlagging,
"Minimal number of hits in a channel required to flag it as 'Masked' or 'Hot'",
45 addParam(
"MinProcessedEventsForMessages", m_MinProcessedEventsForMessagesInput,
46 "Minimal number of processed events required to print error messages", 10000.);
48 m_MinProcessedEventsForMessages = m_MinProcessedEventsForMessagesInput;
49 m_PlaneLine.SetLineColor(kMagenta);
50 m_PlaneLine.SetLineWidth(1);
51 m_PlaneLine.SetLineStyle(2);
52 m_PlaneText.SetTextAlign(22);
53 m_PlaneText.SetTextColor(kMagenta);
54 m_PlaneText.SetTextFont(42);
55 m_PlaneText.SetTextSize(0.02);
65 B2FATAL(
"The threshold used for hot channels is larger than the one for masked channels."
77 B2FATAL(
"No KLM electronics map.");
91 TH1* histogram =
findHist(
"DAQ/Nevent");
92 if (histogram ==
nullptr) {
93 B2WARNING(
"DAQ DQM histogram DAQ/Nevent is not found.");
98 return histogram->GetEntries();
102 int subdetector,
int section,
int sector,
103 TH1* histogram, TCanvas* canvas, TLatex& latex)
109 std::map<uint16_t, double>::iterator it;
111 int channelSubdetector, channelSection, channelSector;
112 int layer, plane, strip;
116 histogram->SetStats(
false);
118 n = histogram->GetXaxis()->GetNbins();
119 for (i = 1; i <= n; i++) {
120 uint16_t channelIndex = std::round(histogram->GetBinCenter(i));
122 double nHitsPerModule = histogram->GetBinContent(i);
123 average = average + nHitsPerModule;
125 channelNumber, &channelSubdetector, &channelSection, &channelSector,
126 &layer, &plane, &strip);
127 if ((channelSubdetector != subdetector) ||
128 (channelSection != section) ||
129 (channelSector != sector))
130 B2FATAL(
"Inconsistent element numbers.");
132 subdetector, section, sector, layer);
135 moduleHitMap.insert(std::pair<uint16_t, double>(module, nHitsPerModule));
137 it->second += nHitsPerModule;
139 unsigned int activeModuleChannels = 0;
141 uint16_t moduleNumber = it->first;
142 if (it->second != 0) {
147 moduleNumber, &channelSubdetector, &channelSection, &channelSector, &layer);
150 channelSubdetector, channelSection, channelSector,
154 if (electronicsChannel ==
nullptr)
155 B2FATAL(
"Incomplete KLM electronics map.");
156 str =
"No data from HSLB ";
159 electronicsChannel->
getSlot());
162 electronicsChannel->
getSlot());
164 str +=
", lane " + std::to_string(electronicsChannel->
getLane());
165 latex.DrawLatexNDC(x, y, str.c_str());
183 if (activeModuleChannels == 0)
185 average /= activeModuleChannels;
186 for (i = 1; i <= n; ++i) {
187 uint16_t channelIndex = std::round(histogram->GetBinCenter(i));
189 double nHits = histogram->GetBinContent(i);
191 channelNumber, &channelSubdetector, &channelSection, &channelSector,
192 &layer, &plane, &strip);
193 std::string channelStatus =
"Normal";
195 channelStatus =
"Masked";
201 B2DEBUG(20,
"KLM@MaskMe " << channelNumber);
203 channelStatus =
"Hot";
205 if (channelStatus !=
"Normal") {
208 if (electronicsChannel ==
nullptr)
209 B2FATAL(
"Incomplete BKLM electronics map.");
210 if (channelStatus ==
"Masked")
211 histogram->SetBinContent(i, 0);
212 str = channelStatus +
" channel: HSLB ";
215 electronicsChannel->
getSlot());
218 electronicsChannel->
getSlot());
220 str += (
", lane " + std::to_string(electronicsChannel->
getLane()) +
221 ", axis " + std::to_string(electronicsChannel->
getAxis()) +
222 ", channel " + std::to_string(electronicsChannel->
getChannel()));
223 latex.DrawLatexNDC(x, y, str.c_str());
231 const std::string& histName)
233 TH1* histogram =
findHist(
"KLM/" + histName);
234 if (histogram ==
nullptr) {
235 B2ERROR(
"KLM DQM histogram KLM/" << histName <<
" is not found.");
238 TCanvas* canvas =
findCanvas(
"KLM/c_" + histName);
239 if (canvas ==
nullptr) {
240 B2ERROR(
"KLM DQM histogram canvas KLM/c_" << histName <<
" is not found.");
247 int channelSubdetector, channelSection, channelSector;
248 int layer, plane, strip;
251 channel, &channelSubdetector, &channelSection, &channelSector,
252 &layer, &plane, &strip);
253 uint16_t sectorNumber;
259 histogram->Fill(sectorIndex);
262 histogram->SetStats(
false);
268 const std::string& histName, TLatex& latex)
270 std::string name, alarm;
271 const double histMinNDC = 0.1;
272 const double histMaxNDC = 0.9;
273 const double histRangeNDC = histMaxNDC - histMinNDC;
274 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
275 double xAlarm = 0.15;
277 TH1* histogram =
findHist(
"KLM/" + histName);
278 if (histogram ==
nullptr) {
279 B2ERROR(
"KLM DQM histogram KLM/" << histName <<
" is not found.");
282 TCanvas* canvas =
findCanvas(
"KLM/c_" + histName);
283 if (canvas ==
nullptr) {
284 B2ERROR(
"KLM DQM histogram canvas KLM/c_" << histName <<
" is not found.");
289 histogram->SetStats(
false);
291 if (histName.find(
"bklm") != std::string::npos) {
295 double xLineNDC = histMinNDC + (histRangeNDC * sector) / maximalSector;
296 double xTextNDC = histMinNDC + (histRangeNDC * (sector + 0.5)) / maximalSector;
297 double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
299 m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
305 name += std::to_string(sector % 8);
306 m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
311 canvas->Pad()->SetFillColor(kWhite);
315 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
317 alarm +=
", layer " + std::to_string(moduleLayer);
318 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
321 alarm =
"Call the KLM experts immediately!";
322 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
323 canvas->Pad()->SetFillColor(kRed);
328 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
329 double xLineNDC = histMinNDC + (histRangeNDC * layerGlobal) / maximalLayer;
330 double xTextNDC = histMinNDC + (histRangeNDC * (layerGlobal - 0.5)) / maximalLayer;
331 double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
332 if (layerGlobal < maximalLayer)
333 m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
336 layerGlobal, §ion, &layer);
341 name += std::to_string(layer);
342 m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
347 canvas->Pad()->SetFillColor(kWhite);
351 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
353 alarm +=
", layer " + std::to_string(moduleLayer);
354 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
357 alarm =
"Call the KLM experts immediately!";
358 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
359 canvas->Pad()->SetFillColor(kRed);
368 TIter nextkey(gROOT->GetListOfCanvases());
369 TObject* obj =
nullptr;
370 while ((obj =
dynamic_cast<TObject*
>(nextkey()))) {
371 if (obj->IsA()->InheritsFrom(
"TCanvas")) {
372 if (obj->GetName() == canvasName)
373 return dynamic_cast<TCanvas*
>(obj);
382 int isKlmIncluded = 1;
384 TH1* daqInclusion =
findHist(
"KLM/daq_inclusion");
385 if (not(daqInclusion ==
nullptr)) {
386 isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
387 if (isKlmIncluded == 0)
395 std::string str, histogramName, canvasName;
397 latex.SetTextColor(kRed);
398 latex.SetTextAlign(11);
406 for (
int j = 0; j < nHistograms; j++) {
407 str =
"strip_hits_subdetector_" +
408 std::to_string(klmSector.getSubdetector()) +
409 "_section_" + std::to_string(klmSector.getSection()) +
410 "_sector_" + std::to_string(klmSector.getSector()) +
411 "_" + std::to_string(j);
412 histogramName =
"KLM/" + str;
413 canvasName =
"KLM/c_" + str;
414 TH1* histogram =
findHist(histogramName);
415 if (histogram ==
nullptr) {
416 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
420 if (canvas ==
nullptr) {
421 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
425 klmSector.getSubdetector(), klmSector.getSection(),
426 klmSector.getSector(), histogram, canvas, latex);
430 latex.SetTextColor(kBlue);