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();
200 if (ref_histogram) {ref_histogram->Draw(
"hist,same");}
201 float ref_average = 0;
203 if (ref_histogram !=
nullptr) {
204 for (i = 1; i <= n; i++) {
205 double nHitsPerModuleRef = ref_histogram->GetBinContent(i);
206 ref_average = ref_average + nHitsPerModuleRef;
210 for (i = 1; i <= n; i++) {
214 double nHitsPerModule = histogram->GetBinContent(i);
215 average = average + nHitsPerModule;
217 channelNumber, &channelSubdetector, &channelSection, &channelSector,
218 &layer, &plane, &strip);
219 if ((channelSubdetector != subdetector) ||
220 (channelSection != section) ||
221 (channelSector != sector))
222 B2FATAL(
"Inconsistent element numbers.");
224 subdetector, section, sector, layer);
228 module, nHitsPerModule));
230 it->second += nHitsPerModule;
233 unsigned int activeModuleChannels = 0;
234 int message_counter = 0;
237 if (it->second != 0) {
242 moduleNumber, &channelSubdetector, &channelSection, &channelSector, &layer);
246 channelSubdetector, channelSection, channelSector, layer, 1, 1);
249 if (electronicsChannel ==
nullptr)
250 B2FATAL(
"Incomplete KLM electronics map.");
251 str =
"No data from lane " + std::to_string(electronicsChannel->
getLane());
252 latex.DrawLatexNDC(x, y, str.c_str());
258 std::vector<KLMModuleNumber>::iterator ite =
272 if (activeModuleChannels == 0)
274 average /= activeModuleChannels;
275 ref_average /= activeModuleChannels;
277 for (i = 1; i <= n; ++i) {
281 double nHits = histogram->GetBinContent(i);
283 channelNumber, &channelSubdetector, &channelSection, &channelSector,
284 &layer, &plane, &strip);
285 std::string channelStatus =
"Normal";
287 channelStatus =
"Masked";
288 std::vector<KLMModuleNumber>::iterator ite =
294 B2DEBUG(20,
"KLM@MaskMe " << channelNumber);
296 channelStatus =
"Hot";
298 if (channelStatus !=
"Normal") {
301 if (electronicsChannel ==
nullptr)
302 B2FATAL(
"Incomplete BKLM electronics map.");
303 if (channelStatus ==
"Masked") {
304 histogram->SetBinContent(i, 0);
305 if (delta !=
nullptr)
306 delta->SetBinContent(i, 0);
308 str = channelStatus +
" channel: ";
310 str += (
"L" + std::to_string(electronicsChannel->
getLane()) +
311 " A" + std::to_string(electronicsChannel->
getAxis()) +
312 " Ch" + std::to_string(electronicsChannel->
getChannel()));
315 latex.DrawLatexNDC(x, y, str.c_str());
321 std::string verbose_message =
" more messages";
322 verbose_message = std::to_string(message_counter -
m_MessageThreshold) + verbose_message;
323 latex.DrawLatexNDC(x, y, verbose_message.c_str());
329 histogram->SetMinimum(1);
331 }
else if (ref_histogram !=
nullptr) {
334 histogram->SetMinimum(1);
349 if (subdetector == 1) {
358 for (
int k = 0; k < divisions; k++) {
359 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
365 if ((section == 2) && (index == 0 || index == 1))
369 for (
int k = 0; k < divisions; k++) {
370 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
385 histogram->SetStats(
false);
386 histogram->Draw(
"COLZ");
399 const std::string& histName)
402 if (histogram ==
nullptr) {
408 if (canvas ==
nullptr) {
420 if (delta !=
nullptr) {
421 B2INFO(
"DQMHistAnalysisKLM: Time Delta Entries is " << delta->GetEntries());
426 if (ref) {ref->Draw(
"hist,same");}
431 const std::string& histName)
434 if (histogram ==
nullptr) {
439 if (canvas ==
nullptr) {
448 int channelSubdetector, channelSection, channelSector;
449 int layer, plane, strip;
452 channel, &channelSubdetector, &channelSection, &channelSector,
453 &layer, &plane, &strip);
460 histogram->Fill(sectorIndex);
463 histogram->SetStats(
false);
470 const std::string& histName, TLatex& latex)
474 if (histogram ==
nullptr) {
479 if (canvas ==
nullptr) {
483 std::string name, alarm;
484 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
485 double xAlarm = 0.15;
489 histogram->SetStats(
false);
493 if (ref) {ref->Draw(
"hist,same");}
495 int message_counter = 0;
496 if (histName.find(
"bklm") != std::string::npos) {
500 int bin = maximalLayer * sector + 1;
501 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
502 double xText = histogram->GetXaxis()->GetBinLowEdge(bin + maximalLayer / 2);
503 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
505 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
521 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
523 alarm +=
", layer " + std::to_string(moduleLayer);
526 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
541 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
542 int bin = maxPlane * layerGlobal + 1;
543 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
544 double xText = histogram->GetXaxis()->GetBinLowEdge(bin - maxPlane / 2);
545 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
546 if (layerGlobal < maximalLayer)
547 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
550 layerGlobal, §ion, &layer);
555 name += std::to_string(layer);
565 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
567 alarm +=
", layer " + std::to_string(moduleLayer);
570 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
583 std::string verbose_string =
" more messages";
584 verbose_string = std::to_string(message_counter -
m_MessageThreshold) + verbose_string;
585 latex.DrawLatexNDC(xAlarm, yAlarm, verbose_string.c_str());
596 if (not(daqInclusion ==
nullptr)) {
597 int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
598 if (isKlmIncluded == 0)
606 std::string str, histogramName, canvasName;
608 latex.SetTextColor(kRed);
609 latex.SetTextAlign(11);
618 for (
int j = 0; j < nHistograms; j++) {
619 str =
"strip_hits_subdetector_" +
620 std::to_string(klmSector.getSubdetector()) +
621 "_section_" + std::to_string(klmSector.getSection()) +
622 "_sector_" + std::to_string(klmSector.getSector()) +
623 "_" + std::to_string(j);
626 TH1* histogram =
findHist(histogramName);
628 auto delta =
getDelta(
"", histogramName);
630 if (histogram ==
nullptr) {
631 B2WARNING(
"KLM DQM histogram " << histogramName <<
" is not found.");
635 if (canvas ==
nullptr) {
636 B2WARNING(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
644 klmSector.getSubdetector(), klmSector.getSection(),
645 klmSector.getSector(), j, histogram, delta, canvas, latex);
650 gStyle->SetPalette(kLightTemperature);
657 for (
int j = 1; j <= maximalLayerNumber; ++j) {
658 str =
"spatial_2d_hits_subdetector_" + std::to_string(subdetector) +
659 "_section_" + std::to_string(section) +
660 "_layer_" + std::to_string(j);
663 TH2F* histogram =
static_cast<TH2F*
>(
findHist(histogramName));
664 if (histogram ==
nullptr) {
665 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
669 if (canvas ==
nullptr) {
670 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
678 gStyle->SetPalette(kBird);
680 latex.SetTextColor(kBlue);
689 B2DEBUG(20,
"Updating EPICS PVs for DQMHistAnalysisKLM");
693 B2INFO(
"DQMHistAnalysisKLM: Null run detected. No PV Update.");
696 auto* daqDataSize =
findHist(
"DAQ/KLMDataSize");
697 double meanDAQDataSize = 0.;
698 if (daqDataSize !=
nullptr) {
699 meanDAQDataSize = daqDataSize->GetMean();
701 B2WARNING(
"DQMHistAnalysisKLM: Cannot find KLMDataSize");
702 if ((daqDataSize !=
nullptr) and (meanDAQDataSize != 0.)) {
707 B2DEBUG(20,
"DQMHistAnalysisKLM: MaskedChannels " <<
m_MaskedChannels.size());
712 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 TH1 * findRefHist(const std::string &histname, ERefScaling scaling=ERefScaling::c_RefScaleNone, const TH1 *hist=nullptr)
Get referencehistogram from list (no other search).
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.
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.
@ c_RefScaleEntries
to number of entries (integral)
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.