10 #include <dqm/analysis/modules/DQMHistAnalysisKLM.h>
13 #include <klm/dataobjects/KLMChannelIndex.h>
36 setDescription(
"Module used to analyze KLM DQM histograms.");
37 addParam(
"ThresholdForMasked", m_ThresholdForMasked,
38 "Threshold X for masked channels: if a channel has an occupancy X times larger than the average, it will be masked.", 100);
39 addParam(
"ThresholdForHot", m_ThresholdForHot,
40 "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).",
42 addParam(
"ThresholdForLog", m_ThresholdForLog,
43 "Threshold Z for log scale view: if a channel has an occupancy Z times larger than the average, canvas shifts to log scale.",
45 addParam(
"MinHitsForFlagging", m_MinHitsForFlagging,
"Minimal number of hits in a channel required to flag it as 'Masked' or 'Hot'",
47 addParam(
"MinProcessedEventsForMessages", m_MinProcessedEventsForMessagesInput,
48 "Minimal number of processed events required to print error messages", 10000.);
50 m_MinProcessedEventsForMessages = m_MinProcessedEventsForMessagesInput;
51 m_2DHitsLine.SetLineColor(kRed);
52 m_2DHitsLine.SetLineWidth(3);
53 m_2DHitsLine.SetLineStyle(2);
54 m_PlaneLine.SetLineColor(kMagenta);
55 m_PlaneLine.SetLineWidth(1);
56 m_PlaneLine.SetLineStyle(2);
57 m_PlaneText.SetTextAlign(22);
58 m_PlaneText.SetTextColor(kMagenta);
59 m_PlaneText.SetTextFont(42);
60 m_PlaneText.SetTextSize(0.02);
70 B2FATAL(
"The threshold used for hot channels is larger than the one for masked channels."
83 B2FATAL(
"No KLM electronics map.");
101 TH1* histogram =
findHist(
"DAQ/Nevent");
102 if (histogram ==
nullptr) {
103 B2WARNING(
"DAQ DQM histogram DAQ/Nevent is not found.");
108 return histogram->GetEntries();
112 int subdetector,
int section,
int sector,
113 TH1* histogram, TCanvas* canvas, TLatex& latex)
119 std::map<uint16_t, double>::iterator it;
121 int channelSubdetector, channelSection, channelSector;
122 int layer, plane, strip;
126 histogram->SetStats(
false);
128 n = histogram->GetXaxis()->GetNbins();
129 for (i = 1; i <= n; i++) {
130 uint16_t channelIndex = std::round(histogram->GetBinCenter(i));
132 double nHitsPerModule = histogram->GetBinContent(i);
133 average = average + nHitsPerModule;
135 channelNumber, &channelSubdetector, &channelSection, &channelSector,
136 &layer, &plane, &strip);
137 if ((channelSubdetector != subdetector) ||
138 (channelSection != section) ||
139 (channelSector != sector))
140 B2FATAL(
"Inconsistent element numbers.");
142 subdetector, section, sector, layer);
145 moduleHitMap.insert(std::pair<uint16_t, double>(module, nHitsPerModule));
147 it->second += nHitsPerModule;
149 unsigned int activeModuleChannels = 0;
151 uint16_t moduleNumber = it->first;
152 if (it->second != 0) {
157 moduleNumber, &channelSubdetector, &channelSection, &channelSector, &layer);
160 channelSubdetector, channelSection, channelSector,
164 if (electronicsChannel ==
nullptr)
165 B2FATAL(
"Incomplete KLM electronics map.");
166 str =
"No data from HSLB ";
169 electronicsChannel->
getSlot());
172 electronicsChannel->
getSlot());
174 str +=
", lane " + std::to_string(electronicsChannel->
getLane());
175 latex.DrawLatexNDC(x, y, str.c_str());
193 if (activeModuleChannels == 0)
195 average /= activeModuleChannels;
196 for (i = 1; i <= n; ++i) {
197 uint16_t channelIndex = std::round(histogram->GetBinCenter(i));
199 double nHits = histogram->GetBinContent(i);
201 channelNumber, &channelSubdetector, &channelSection, &channelSector,
202 &layer, &plane, &strip);
203 std::string channelStatus =
"Normal";
205 channelStatus =
"Masked";
211 B2DEBUG(20,
"KLM@MaskMe " << channelNumber);
213 channelStatus =
"Hot";
215 if (channelStatus !=
"Normal") {
218 if (electronicsChannel ==
nullptr)
219 B2FATAL(
"Incomplete BKLM electronics map.");
220 if (channelStatus ==
"Masked")
221 histogram->SetBinContent(i, 0);
222 str = channelStatus +
" channel: HSLB ";
225 electronicsChannel->
getSlot());
228 electronicsChannel->
getSlot());
230 str += (
", lane " + std::to_string(electronicsChannel->
getLane()) +
231 ", axis " + std::to_string(electronicsChannel->
getAxis()) +
232 ", channel " + std::to_string(electronicsChannel->
getChannel()));
233 latex.DrawLatexNDC(x, y, str.c_str());
244 uint16_t section, TH2F* histogram, TCanvas* canvas)
248 histogram->SetStats(
false);
249 histogram->Draw(
"COLZ");
261 const std::string& histName)
263 TH1* histogram =
findHist(
"KLM/" + histName);
264 if (histogram ==
nullptr) {
265 B2ERROR(
"KLM DQM histogram KLM/" << histName <<
" is not found.");
268 TCanvas* canvas =
findCanvas(
"KLM/c_" + histName);
269 if (canvas ==
nullptr) {
270 B2ERROR(
"KLM DQM histogram canvas KLM/c_" << histName <<
" is not found.");
277 int channelSubdetector, channelSection, channelSector;
278 int layer, plane, strip;
281 channel, &channelSubdetector, &channelSection, &channelSector,
282 &layer, &plane, &strip);
283 uint16_t sectorNumber;
289 histogram->Fill(sectorIndex);
292 histogram->SetStats(
false);
298 const std::string& histName, TLatex& latex)
300 std::string name, alarm;
301 const double histMinNDC = 0.1;
302 const double histMaxNDC = 0.9;
303 const double histRangeNDC = histMaxNDC - histMinNDC;
304 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
305 double xAlarm = 0.15;
307 TH1* histogram =
findHist(
"KLM/" + histName);
308 if (histogram ==
nullptr) {
309 B2ERROR(
"KLM DQM histogram KLM/" << histName <<
" is not found.");
312 TCanvas* canvas =
findCanvas(
"KLM/c_" + histName);
313 if (canvas ==
nullptr) {
314 B2ERROR(
"KLM DQM histogram canvas KLM/c_" << histName <<
" is not found.");
319 histogram->SetStats(
false);
321 if (histName.find(
"bklm") != std::string::npos) {
325 double xLineNDC = histMinNDC + (histRangeNDC * sector) / maximalSector;
326 double xTextNDC = histMinNDC + (histRangeNDC * (sector + 0.5)) / maximalSector;
327 double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
329 m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
335 name += std::to_string(sector % 8);
336 m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
341 canvas->Pad()->SetFillColor(kWhite);
345 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
347 alarm +=
", layer " + std::to_string(moduleLayer);
348 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
352 alarm =
"Call the KLM experts immediately!";
353 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
354 canvas->Pad()->SetFillColor(kRed);
360 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
361 double xLineNDC = histMinNDC + (histRangeNDC * layerGlobal) / maximalLayer;
362 double xTextNDC = histMinNDC + (histRangeNDC * (layerGlobal - 0.5)) / maximalLayer;
363 double yTextNDC = histMinNDC + 0.98 * histRangeNDC;
364 if (layerGlobal < maximalLayer)
365 m_PlaneLine.DrawLineNDC(xLineNDC, histMinNDC, xLineNDC, histMaxNDC);
368 layerGlobal, §ion, &layer);
373 name += std::to_string(layer);
374 m_PlaneText.DrawTextNDC(xTextNDC, yTextNDC, name.c_str());
379 canvas->Pad()->SetFillColor(kWhite);
383 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
385 alarm +=
", layer " + std::to_string(moduleLayer);
386 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
390 alarm =
"Call the KLM experts immediately!";
391 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
392 canvas->Pad()->SetFillColor(kRed);
403 TH1* daqInclusion =
findHist(
"KLM/daq_inclusion");
404 if (not(daqInclusion ==
nullptr)) {
405 int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
406 if (isKlmIncluded == 0)
414 std::string str, histogramName, canvasName;
416 latex.SetTextColor(kRed);
417 latex.SetTextAlign(11);
425 for (
int j = 0; j < nHistograms; j++) {
426 str =
"strip_hits_subdetector_" +
427 std::to_string(klmSector.getSubdetector()) +
428 "_section_" + std::to_string(klmSector.getSection()) +
429 "_sector_" + std::to_string(klmSector.getSector()) +
430 "_" + std::to_string(j);
431 histogramName =
"KLM/" + str;
432 canvasName =
"KLM/c_" + str;
433 TH1* histogram =
findHist(histogramName);
434 if (histogram ==
nullptr) {
435 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
439 if (canvas ==
nullptr) {
440 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
444 klmSector.getSubdetector(), klmSector.getSection(),
445 klmSector.getSector(), histogram, canvas, latex);
449 gStyle->SetPalette(kLightTemperature);
452 uint16_t subdetector = klmSection.getSubdetector();
454 uint16_t section = klmSection.getSection();
456 for (
int j = 1; j <= maximalLayerNumber; ++j) {
457 str =
"spatial_2d_hits_subdetector_" + std::to_string(subdetector) +
458 "_section_" + std::to_string(section) +
459 "_layer_" + std::to_string(j);
460 histogramName =
"KLM/" + str;
461 canvasName =
"KLM/c_" + str;
462 TH2F* histogram =
static_cast<TH2F*
>(
findHist(histogramName));
463 if (histogram ==
nullptr) {
464 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
468 if (canvas ==
nullptr) {
469 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
477 gStyle->SetPalette(kBird);
479 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.
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.
TString m_RunTypeString
String with run type.
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.
TH1 * m_RunType
Histogram from DQMInfo with run type.
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.
bool m_IsNullRun
Run type flag for null runs.
~DQMHistAnalysisKLMModule()
Destructor.
void fillMaskedChannelsHistogram(const std::string &histName)
Fill histogram containing masked channels per sector.
The base class for the histogram analysis module.
TCanvas * findCanvas(TString cname)
Find canvas by name.
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.