10 #include <dqm/analysis/modules/DQMHistAnalysisKLM.h>
13 #include <klm/dataobjects/KLMChannelIndex.h>
35 setDescription(
"Module used to analyze KLM DQM histograms.");
36 addParam(
"ThresholdForMasked", m_ThresholdForMasked,
37 "Threshold X for masked channels: if a channel has an occupancy X times larger than the average, it will be masked.", 100);
38 addParam(
"ThresholdForHot", m_ThresholdForHot,
39 "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).",
41 addParam(
"ThresholdForLog", m_ThresholdForLog,
42 "Threshold Z for log scale view: if a channel has an occupancy Z times larger than the average, canvas shifts to log scale.",
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());
238 uint16_t section, TH2F* histogram, TCanvas* canvas)
242 histogram->SetStats(
false);
243 histogram->Draw(
"COLZ");
255 const std::string& histName)
257 TH1* histogram =
findHist(
"KLM/" + histName);
258 if (histogram ==
nullptr) {
259 B2ERROR(
"KLM DQM histogram KLM/" << histName <<
" is not found.");
262 TCanvas* canvas =
findCanvas(
"KLM/c_" + histName);
263 if (canvas ==
nullptr) {
264 B2ERROR(
"KLM DQM histogram canvas KLM/c_" << histName <<
" is not found.");
271 int channelSubdetector, channelSection, channelSector;
272 int layer, plane, strip;
275 channel, &channelSubdetector, &channelSection, &channelSector,
276 &layer, &plane, &strip);
277 uint16_t sectorNumber;
283 histogram->Fill(sectorIndex);
286 histogram->SetStats(
false);
292 const std::string& histName, TLatex& latex)
294 std::string name, alarm;
295 const double histMinNDC = 0.1;
296 const double histMaxNDC = 0.9;
297 const double histRangeNDC = histMaxNDC - histMinNDC;
298 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
299 double xAlarm = 0.15;
301 TH1* histogram =
findHist(
"KLM/" + histName);
302 if (histogram ==
nullptr) {
303 B2ERROR(
"KLM DQM histogram KLM/" << histName <<
" is not found.");
306 TCanvas* canvas =
findCanvas(
"KLM/c_" + histName);
307 if (canvas ==
nullptr) {
308 B2ERROR(
"KLM DQM histogram canvas KLM/c_" << histName <<
" is not found.");
313 histogram->SetStats(
false);
315 if (histName.find(
"bklm") != std::string::npos) {
319 double xLineNDC = histMinNDC + (histRangeNDC * sector) / maximalSector;
320 double xTextNDC = histMinNDC + (histRangeNDC * (sector + 0.5)) / maximalSector;
321 double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
323 m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
329 name += std::to_string(sector % 8);
330 m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
335 canvas->Pad()->SetFillColor(kWhite);
339 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
341 alarm +=
", layer " + std::to_string(moduleLayer);
342 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
345 alarm =
"Call the KLM experts immediately!";
346 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
347 canvas->Pad()->SetFillColor(kRed);
352 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
353 double xLineNDC = histMinNDC + (histRangeNDC * layerGlobal) / maximalLayer;
354 double xTextNDC = histMinNDC + (histRangeNDC * (layerGlobal - 0.5)) / maximalLayer;
355 double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
356 if (layerGlobal < maximalLayer)
357 m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
360 layerGlobal, §ion, &layer);
365 name += std::to_string(layer);
366 m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
371 canvas->Pad()->SetFillColor(kWhite);
375 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
377 alarm +=
", layer " + std::to_string(moduleLayer);
378 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
381 alarm =
"Call the KLM experts immediately!";
382 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
383 canvas->Pad()->SetFillColor(kRed);
392 TIter nextkey(gROOT->GetListOfCanvases());
393 TObject* obj =
nullptr;
394 while ((obj =
dynamic_cast<TObject*
>(nextkey()))) {
395 if (obj->IsA()->InheritsFrom(
"TCanvas")) {
396 if (obj->GetName() == canvasName)
397 return dynamic_cast<TCanvas*
>(obj);
407 TH1* daqInclusion =
findHist(
"KLM/daq_inclusion");
408 if (not(daqInclusion ==
nullptr)) {
409 int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
410 if (isKlmIncluded == 0)
418 std::string str, histogramName, canvasName;
420 latex.SetTextColor(kRed);
421 latex.SetTextAlign(11);
429 for (
int j = 0; j < nHistograms; j++) {
430 str =
"strip_hits_subdetector_" +
431 std::to_string(klmSector.getSubdetector()) +
432 "_section_" + std::to_string(klmSector.getSection()) +
433 "_sector_" + std::to_string(klmSector.getSector()) +
434 "_" + std::to_string(j);
435 histogramName =
"KLM/" + str;
436 canvasName =
"KLM/c_" + str;
437 TH1* histogram =
findHist(histogramName);
438 if (histogram ==
nullptr) {
439 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
443 if (canvas ==
nullptr) {
444 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
448 klmSector.getSubdetector(), klmSector.getSection(),
449 klmSector.getSector(), histogram, canvas, latex);
453 gStyle->SetPalette(kLightTemperature);
456 uint16_t subdetector = klmSection.getSubdetector();
458 uint16_t section = klmSection.getSection();
460 for (
int j = 1; j <= maximalLayerNumber; ++j) {
461 str =
"spatial_2d_hits_subdetector_" + std::to_string(subdetector) +
462 "_section_" + std::to_string(section) +
463 "_layer_" + std::to_string(j);
464 histogramName =
"KLM/" + str;
465 canvasName =
"KLM/c_" + str;
466 TH2F* histogram =
static_cast<TH2F*
>(
findHist(histogramName));
467 if (histogram ==
nullptr) {
468 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
472 if (canvas ==
nullptr) {
473 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
481 gStyle->SetPalette(kBird);
483 latex.SetTextColor(kBlue);
static std::string getHSLBName(int copper, int slot)
Get HSLB name.
static constexpr int getMaximalSectorGlobalNumber()
Get maximal sector global number.
Analysis of KLM DQM histograms.
TLine m_PlaneLine
TLine for boundary in plane histograms.
double m_ProcessedEvents
Number of processed events.
void initialize() override
Initializer.
int m_ThresholdForLog
Threshold for log scale.
void event() override
This method is called for each event.
TCanvas * findCanvas(const std::string &canvasName)
Find TCanvas that matches a given name.
int m_MinHitsForFlagging
Minimal number of hits for flagging.
const KLMElementNumbers * m_ElementNumbers
KLM element numbers.
void endRun() override
This method is called if the current run ends.
const EKLMElementNumbers * m_EklmElementNumbers
EKLM element numbers.
void terminate() override
This method is called at the end of the event processing.
void processSpatial2DHitEndcapHistogram(uint16_t section, TH2F *histogram, TCanvas *canvas)
Process spatial 2D hits histograms for endcap.
std::vector< uint16_t > m_MaskedChannels
Vector of masked channels.
int m_ThresholdForHot
Threshold for hot channels.
std::vector< uint16_t > m_DeadBarrelModules
Vector of dead barrel modules.
void beginRun() override
Called when entering a new run.
double m_MinProcessedEventsForMessagesInput
Input parameter for minimal number of processed events for error messages.
TText m_PlaneText
TText for names in plane histograms.
DBObjPtr< KLMElectronicsMap > m_ElectronicsMap
Electronics map.
void processPlaneHistogram(const std::string &histName, TLatex &latex)
Process histogram containing the number of hits in plane.
int m_ThresholdForMasked
Threshold for masked channels.
const KLMSectorArrayIndex * m_SectorArrayIndex
KLM sector array index.
double m_MinProcessedEventsForMessages
Minimal number of processed events for error messages.
void analyseChannelHitHistogram(int subdetector, int section, int sector, TH1 *histogram, TCanvas *canvas, TLatex &latex)
Analyse channel hit histogram.
std::vector< uint16_t > m_DeadEndcapModules
Vector of dead endcap modules.
double getProcessedEvents()
Get number of processed events.
TLine m_2DHitsLine
TLine for background region in 2d hits histograms.
const KLMChannelArrayIndex * m_ChannelArrayIndex
KLM channel array index.
~DQMHistAnalysisKLMModule()
Destructor.
void fillMaskedChannelsHistogram(const std::string &histName)
Fill histogram containing masked channels per sector.
The base class for the histogram analysis module.
static TH1 * findHist(const std::string &histname)
Find histogram.
static constexpr int getMaximalLayerGlobalNumber()
Get maximal detector layer global number.
int getMaximalDetectorLayerNumber(int section) const
Get maximal detector layer number.
static const EKLMElementNumbers & Instance()
Instantiation.
void layerNumberToElementNumbers(int layerGlobal, int *section, int *layer) const
Get element numbers by detector layer global number.
@ c_ForwardSection
Forward.
@ c_BackwardSection
Backward.
static std::string getHSLBName(int copper, int slot)
Get HSLB name.
static const KLMChannelArrayIndex & Instance()
Instantiation.
@ c_IndexLevelSection
Section.
@ c_IndexLevelSector
Sector.
void setIndexLevel(enum IndexLevel indexLevel)
Set index level.
BKLM electronics channel.
int getSlot() const
Get slot.
int getCopper() const
Get copper.
int getChannel() const
Get channel.
int getAxis() const
Get axis.
int getLane() const
Get lane.
uint16_t getNumber(uint16_t index) const
Get element number.
uint16_t getIndex(uint16_t number) const
Get element index.
KLMSectorNumber sectorNumberEKLM(int section, int sector) const
Get sector number for EKLM.
KLMChannelNumber channelNumber(int subdetector, int section, int sector, int layer, int plane, int strip) const
Get channel number.
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.
unsigned int getNChannelsModule(KLMModuleNumber module) const
Get number of channels in module.
void moduleNumberToElementNumbers(KLMModuleNumber module, int *subdetector, int *section, int *sector, int *layer) const
Get element numbers by module number.
KLMModuleNumber moduleNumber(int subdetector, int section, int sector, int layer) const
Get module number.
KLMSectorNumber sectorNumberBKLM(int section, int sector) const
Get sector number for BKLM.
std::string getSectorDAQName(int subdetector, int section, int sector) const
Get DAQ name for a given sector.
static const KLMSectorArrayIndex & Instance()
Instantiation.
Class to store variables with their name which were sent to the logging service.
TH2 * moduleHitMap(TH1 *hitMap, int moduleID)
Make hit map in HAPD view (12*12 channels)
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.