10#include <dqm/analysis/modules/DQMHistAnalysisKLM.h>
13#include <klm/dataobjects/KLMChannelIndex.h>
38 "Threshold X for masked channels: if a channel has an occupancy X times larger than the average, it will be masked.", 100);
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).",
43 "Threshold Z for log scale view: if a channel has an occupancy Z times larger than the average, canvas shifts to log scale.",
48 "Minimal number of processed events required to print error messages", 10000.);
50 "Minimal number for delta histogram updates", 50000.);
52 "Max number of messages to show up in channel occupancy plots", 12);
74 B2FATAL(
"The threshold used for hot channels is larger than the one for masked channels."
98 for (
int j = 0; j < nHistograms; j++) {
99 str =
"strip_hits_subdetector_" +
100 std::to_string(klmSector.getSubdetector()) +
101 "_section_" + std::to_string(klmSector.getSection()) +
102 "_sector_" + std::to_string(klmSector.getSector()) +
103 "_" + std::to_string(j);
118 B2FATAL(
"No KLM electronics map.");
130 int hist_max_bin;
double max_position;
133 hist_max_bin = time_rpc->GetMaximumBin();
134 max_position = time_rpc->GetXaxis()->GetBinCenter(hist_max_bin);
139 if (time_scint_bklm) {
140 hist_max_bin = time_scint_bklm->GetMaximumBin();
141 max_position = time_scint_bklm->GetXaxis()->GetBinCenter(hist_max_bin);
146 if (time_scint_eklm) {
147 hist_max_bin = time_scint_eklm->GetMaximumBin();
148 max_position = time_scint_eklm->GetXaxis()->GetBinCenter(hist_max_bin);
156 B2WARNING(
"Either DAQ/Nevent is not found or Nevent = 0.");
165 if (delta !=
nullptr) {
166 Double_t scale = (Double_t) histogram->Integral();
169 delta->SetLineColor(kBlackBody);
170 delta->SetLineStyle(4);
171 delta->DrawNormalized(
"SAME", scale);
178 int subdetector,
int section,
int sector,
int index,
179 TH1* histogram, TH1* delta, TCanvas* canvas, TLatex& latex)
185 std::map<KLMModuleNumber, double>::iterator it;
187 int channelSubdetector, channelSection, channelSector;
188 int layer, plane, strip;
192 histogram->SetStats(
false);
196 n = histogram->GetXaxis()->GetNbins();
199 TH1* ref_histogram =
findRefHist(histogram->GetName(),
false);
200 float ref_average = 0;
202 if (ref_histogram !=
nullptr) {
203 for (i = 1; i <= n; i++) {
204 double nHitsPerModuleRef = ref_histogram->GetBinContent(i);
205 ref_average = ref_average + nHitsPerModuleRef;
209 for (i = 1; i <= n; i++) {
213 double nHitsPerModule = histogram->GetBinContent(i);
214 average = average + nHitsPerModule;
216 channelNumber, &channelSubdetector, &channelSection, &channelSector,
217 &layer, &plane, &strip);
218 if ((channelSubdetector != subdetector) ||
219 (channelSection != section) ||
220 (channelSector != sector))
221 B2FATAL(
"Inconsistent element numbers.");
223 subdetector, section, sector, layer);
227 module, nHitsPerModule));
229 it->second += nHitsPerModule;
232 unsigned int activeModuleChannels = 0;
233 int message_counter = 0;
236 if (it->second != 0) {
241 moduleNumber, &channelSubdetector, &channelSection, &channelSector, &layer);
245 channelSubdetector, channelSection, channelSector, layer, 1, 1);
248 if (electronicsChannel ==
nullptr)
249 B2FATAL(
"Incomplete KLM electronics map.");
250 str =
"No data from lane " + std::to_string(electronicsChannel->
getLane());
251 latex.DrawLatexNDC(x, y, str.c_str());
257 std::vector<KLMModuleNumber>::iterator ite =
271 if (activeModuleChannels == 0)
273 average /= activeModuleChannels;
274 ref_average /= activeModuleChannels;
276 for (i = 1; i <= n; ++i) {
280 double nHits = histogram->GetBinContent(i);
282 channelNumber, &channelSubdetector, &channelSection, &channelSector,
283 &layer, &plane, &strip);
284 std::string channelStatus =
"Normal";
286 channelStatus =
"Masked";
287 std::vector<KLMModuleNumber>::iterator ite =
293 B2DEBUG(20,
"KLM@MaskMe " << channelNumber);
295 channelStatus =
"Hot";
297 if (channelStatus !=
"Normal") {
300 if (electronicsChannel ==
nullptr)
301 B2FATAL(
"Incomplete BKLM electronics map.");
302 if (channelStatus ==
"Masked") {
303 histogram->SetBinContent(i, 0);
304 if (delta !=
nullptr)
305 delta->SetBinContent(i, 0);
307 str = channelStatus +
" channel: ";
309 str += (
"L" + std::to_string(electronicsChannel->
getLane()) +
310 " A" + std::to_string(electronicsChannel->
getAxis()) +
311 " Ch" + std::to_string(electronicsChannel->
getChannel()));
314 latex.DrawLatexNDC(x, y, str.c_str());
320 std::string verbose_message =
" more messages";
321 verbose_message = std::to_string(message_counter -
m_MessageThreshold) + verbose_message;
322 latex.DrawLatexNDC(x, y, verbose_message.c_str());
328 histogram->SetMinimum(1);
330 }
else if (ref_histogram !=
nullptr) {
333 histogram->SetMinimum(1);
348 if (subdetector == 1) {
357 for (
int k = 0; k < divisions; k++) {
358 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
364 if ((section == 2) && (index == 0 || index == 1))
368 for (
int k = 0; k < divisions; k++) {
369 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
384 histogram->SetStats(
false);
385 histogram->Draw(
"COLZ");
398 const std::string& histName)
401 if (histogram ==
nullptr) {
407 if (canvas ==
nullptr) {
419 if (delta !=
nullptr) {
420 B2INFO(
"DQMHistAnalysisKLM: Time Delta Entries is " << delta->GetEntries());
427 const std::string& histName)
430 if (histogram ==
nullptr) {
435 if (canvas ==
nullptr) {
444 int channelSubdetector, channelSection, channelSector;
445 int layer, plane, strip;
448 channel, &channelSubdetector, &channelSection, &channelSector,
449 &layer, &plane, &strip);
456 histogram->Fill(sectorIndex);
459 histogram->SetStats(
false);
466 const std::string& histName, TLatex& latex)
470 if (histogram ==
nullptr) {
475 if (canvas ==
nullptr) {
479 std::string name, alarm;
480 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
481 double xAlarm = 0.15;
485 histogram->SetStats(
false);
488 int message_counter = 0;
489 if (histName.find(
"bklm") != std::string::npos) {
493 int bin = maximalLayer * sector + 1;
494 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
495 double xText = histogram->GetXaxis()->GetBinLowEdge(bin + maximalLayer / 2);
496 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
498 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
514 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
516 alarm +=
", layer " + std::to_string(moduleLayer);
519 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
534 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
535 int bin = maxPlane * layerGlobal + 1;
536 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
537 double xText = histogram->GetXaxis()->GetBinLowEdge(bin - maxPlane / 2);
538 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
539 if (layerGlobal < maximalLayer)
540 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
543 layerGlobal, §ion, &layer);
548 name += std::to_string(layer);
558 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
560 alarm +=
", layer " + std::to_string(moduleLayer);
563 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
576 std::string verbose_string =
" more messages";
577 verbose_string = std::to_string(message_counter -
m_MessageThreshold) + verbose_string;
578 latex.DrawLatexNDC(xAlarm, yAlarm, verbose_string.c_str());
589 if (not(daqInclusion ==
nullptr)) {
590 int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
591 if (isKlmIncluded == 0)
599 std::string str, histogramName, canvasName;
601 latex.SetTextColor(kRed);
602 latex.SetTextAlign(11);
611 for (
int j = 0; j < nHistograms; j++) {
612 str =
"strip_hits_subdetector_" +
613 std::to_string(klmSector.getSubdetector()) +
614 "_section_" + std::to_string(klmSector.getSection()) +
615 "_sector_" + std::to_string(klmSector.getSector()) +
616 "_" + std::to_string(j);
619 TH1* histogram =
findHist(histogramName);
621 auto delta =
getDelta(
"", histogramName);
623 if (histogram ==
nullptr) {
624 B2WARNING(
"KLM DQM histogram " << histogramName <<
" is not found.");
628 if (canvas ==
nullptr) {
629 B2WARNING(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
637 klmSector.getSubdetector(), klmSector.getSection(),
638 klmSector.getSector(), j, histogram, delta, canvas, latex);
643 gStyle->SetPalette(kLightTemperature);
650 for (
int j = 1; j <= maximalLayerNumber; ++j) {
651 str =
"spatial_2d_hits_subdetector_" + std::to_string(subdetector) +
652 "_section_" + std::to_string(section) +
653 "_layer_" + std::to_string(j);
656 TH2F* histogram =
static_cast<TH2F*
>(
findHist(histogramName));
657 if (histogram ==
nullptr) {
658 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
662 if (canvas ==
nullptr) {
663 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
671 gStyle->SetPalette(kBird);
673 latex.SetTextColor(kBlue);
682 B2DEBUG(20,
"Updating EPICS PVs for DQMHistAnalysisKLM");
686 B2INFO(
"DQMHistAnalysisKLM: Null run detected. No PV Update.");
689 auto* daqDataSize =
findHist(
"DAQ/KLMDataSize");
690 double meanDAQDataSize = 0.;
691 if (daqDataSize !=
nullptr) {
692 meanDAQDataSize = daqDataSize->GetMean();
694 B2WARNING(
"DQMHistAnalysisKLM: Cannot find KLMDataSize");
695 if ((daqDataSize !=
nullptr) and (meanDAQDataSize != 0.)) {
700 B2DEBUG(20,
"DQMHistAnalysisKLM: MaskedChannels " <<
m_MaskedChannels.size());
705 B2INFO(
"DQMHistAnalysisKLM: KLM Not included. No PV Update. ");
static constexpr int getMaximalLayerNumber()
Get maximal layer number (1-based).
static constexpr int getMaximalSectorNumber()
Get maximal sector number (1-based).
static constexpr int getMaximalSectorGlobalNumber()
Get maximal sector global number.
static int getNStrips(int section, int sector, int layer, int plane)
Get number of strips.
TLine m_PlaneLine
TLine for boundary in plane histograms.
double m_ProcessedEvents
Number of processed events.
void initialize() override final
Initializer.
int m_MessageThreshold
Message Threshold for expert pots.
int m_ThresholdForLog
Threshold for log scale.
double m_minEntries
Minimal number of entries for delta histogram update.
int m_MinHitsForFlagging
Minimal number of hits for flagging.
const KLMElementNumbers * m_ElementNumbers
KLM element numbers.
const EKLMElementNumbers * m_EklmElementNumbers
EKLM element numbers.
void processSpatial2DHitEndcapHistogram(uint16_t section, TH2F *histogram, TCanvas *canvas)
Process spatial 2D hits histograms for endcap.
MonitoringObject * m_monObj
Monitoring object.
void deltaDrawer(TH1 *delta, TH1 *histogram, TCanvas *canvas)
Scales and draws desired delta histogram for current canvas.
void processTimeHistogram(const std::string &histName)
Process histogram containing the hit times.
std::vector< uint16_t > m_MaskedChannels
Vector of masked channels.
void terminate() override final
This method is called at the end of the event processing.
void event() override final
This method is called for each event.
int m_ThresholdForHot
Threshold for hot channels.
std::vector< uint16_t > m_DeadBarrelModules
Vector of dead barrel modules.
std::string m_histogramDirectoryName
Name of histogram directory.
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.
DQMHistAnalysisKLMModule()
Constructor.
void endRun() override final
This method is called if the current run ends.
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.
void beginRun() override final
Called when entering a new run.
double m_MinProcessedEventsForMessages
Minimal number of processed events for error messages.
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.
void analyseChannelHitHistogram(int subdetector, int section, int sector, int index, TH1 *histogram, TH1 *delta, TCanvas *canvas, TLatex &latex)
Analyse channel hit histogram.
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 MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
void colorizeCanvas(TCanvas *canvas, EStatus status)
Helper function for Canvas colorization.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
static const std::string & getRunType(void)
Get the Run Type.
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
static TH1 * findRefHist(const std::string &histname, int scaling=0, const TH1 *hist=nullptr)
Get referencehistogram from list (no other search).
void setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
@ c_StatusTooFew
Not enough entries/event to judge.
@ c_StatusError
Analysis result: Severe issue found.
@ c_StatusGood
Analysis result: Good.
static int getEventProcessed(void)
Get the number of processed events.
int registerEpicsPV(std::string pvname, std::string keyname="")
EPICS related Functions.
void UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
static constexpr int getNStripsSector()
Get number of strips in a sector.
static constexpr int getMaximalLayerGlobalNumber()
Get maximal detector layer global number.
int getMaximalDetectorLayerNumber(int section) const
Get maximal detector layer number.
void layerNumberToElementNumbers(int layerGlobal, int *section, int *layer) const
Get element numbers by detector layer global number.
@ c_ForwardSection
Forward.
@ c_BackwardSection
Backward.
static constexpr int getMaximalSectorNumber()
Get maximal sector number.
static constexpr int getMaximalPlaneNumber()
Get maximal plane number.
@ c_IndexLevelSection
Section.
@ c_IndexLevelSector
Sector.
void setIndexLevel(enum IndexLevel indexLevel)
Set index level.
BKLM electronics channel.
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.
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.
void setDescription(const std::string &description)
Sets the description of the module.
void setVariable(const std::string &var, float val, float upErr=-1., float dwErr=-1)
set value to float variable (new variable is made if not yet existing)
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).
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
uint16_t KLMSectorNumber
Sector number.
uint16_t KLMChannelNumber
Channel number.
uint16_t KLMSubdetectorNumber
Subdetector number.
uint16_t KLMModuleNumber
Module number.
uint16_t KLMSectionNumber
Section number.
Abstract base class for different kinds of events.