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);
55 addParam(
"RefHistoFile",
m_refFileName,
"Reference histogram file name", std::string(
"KLM_DQM_REF_BEAM.root"));
76 B2FATAL(
"The threshold used for hot channels is larger than the one for masked channels."
104 for (
int j = 0; j < nHistograms; j++) {
105 str =
"strip_hits_subdetector_" +
106 std::to_string(klmSector.getSubdetector()) +
107 "_section_" + std::to_string(klmSector.getSection()) +
108 "_sector_" + std::to_string(klmSector.getSector()) +
109 "_" + std::to_string(j);
118 B2INFO(
"DQMHistAnalysisKLM: reference root file (" <<
m_refFileName <<
") FOUND, able to read ref histograms");
121 B2WARNING(
"DQMHistAnalysisKLM: reference root file (" <<
m_refFileName <<
") not found, or closed");
135 B2FATAL(
"No KLM electronics map.");
147 int hist_max_bin;
double max_position;
150 hist_max_bin = time_rpc->GetMaximumBin();
151 max_position = time_rpc->GetXaxis()->GetBinCenter(hist_max_bin);
156 if (time_scint_bklm) {
157 hist_max_bin = time_scint_bklm->GetMaximumBin();
158 max_position = time_scint_bklm->GetXaxis()->GetBinCenter(hist_max_bin);
163 if (time_scint_eklm) {
164 hist_max_bin = time_scint_eklm->GetMaximumBin();
165 max_position = time_scint_eklm->GetXaxis()->GetBinCenter(hist_max_bin);
173 B2WARNING(
"Either DAQ/Nevent is not found or Nevent = 0.");
182 if (delta !=
nullptr) {
183 Double_t scale = (Double_t) histogram->Integral();
186 delta->SetLineColor(kBlackBody);
187 delta->SetLineStyle(4);
188 delta->DrawNormalized(
"SAME", scale);
195 int subdetector,
int section,
int sector,
int index,
196 TH1* histogram, TH1* delta, TCanvas* canvas, TLatex& latex)
202 std::map<KLMModuleNumber, double>::iterator it;
204 int channelSubdetector, channelSection, channelSector;
205 int layer, plane, strip;
209 histogram->SetStats(
false);
213 n = histogram->GetXaxis()->GetNbins();
216 TH1* ref_histogram =
nullptr;
217 float ref_average = 0;
220 if (!ref_histogram) {
225 if (ref_histogram !=
nullptr) {
226 for (i = 1; i <= n; i++) {
227 double nHitsPerModuleRef = ref_histogram->GetBinContent(i);
228 ref_average = ref_average + nHitsPerModuleRef;
232 for (i = 1; i <= n; i++) {
236 double nHitsPerModule = histogram->GetBinContent(i);
237 average = average + nHitsPerModule;
239 channelNumber, &channelSubdetector, &channelSection, &channelSector,
240 &layer, &plane, &strip);
241 if ((channelSubdetector != subdetector) ||
242 (channelSection != section) ||
243 (channelSector != sector))
244 B2FATAL(
"Inconsistent element numbers.");
246 subdetector, section, sector, layer);
250 module, nHitsPerModule));
252 it->second += nHitsPerModule;
255 unsigned int activeModuleChannels = 0;
256 int message_counter = 0;
259 if (it->second != 0) {
264 moduleNumber, &channelSubdetector, &channelSection, &channelSector, &layer);
268 channelSubdetector, channelSection, channelSector, layer, 1, 1);
271 if (electronicsChannel ==
nullptr)
272 B2FATAL(
"Incomplete KLM electronics map.");
273 str =
"No data from lane " + std::to_string(electronicsChannel->
getLane());
274 latex.DrawLatexNDC(x, y, str.c_str());
280 std::vector<KLMModuleNumber>::iterator ite =
294 if (activeModuleChannels == 0)
296 average /= activeModuleChannels;
297 ref_average /= activeModuleChannels;
299 for (i = 1; i <= n; ++i) {
303 double nHits = histogram->GetBinContent(i);
305 channelNumber, &channelSubdetector, &channelSection, &channelSector,
306 &layer, &plane, &strip);
307 std::string channelStatus =
"Normal";
309 channelStatus =
"Masked";
310 std::vector<KLMModuleNumber>::iterator ite =
316 B2DEBUG(20,
"KLM@MaskMe " << channelNumber);
318 channelStatus =
"Hot";
320 if (channelStatus !=
"Normal") {
323 if (electronicsChannel ==
nullptr)
324 B2FATAL(
"Incomplete BKLM electronics map.");
325 if (channelStatus ==
"Masked") {
326 histogram->SetBinContent(i, 0);
327 if (delta !=
nullptr)
328 delta->SetBinContent(i, 0);
330 str = channelStatus +
" channel: ";
332 str += (
"L" + std::to_string(electronicsChannel->
getLane()) +
333 " A" + std::to_string(electronicsChannel->
getAxis()) +
334 " Ch" + std::to_string(electronicsChannel->
getChannel()));
337 latex.DrawLatexNDC(x, y, str.c_str());
343 std::string verbose_message =
" more messages";
344 verbose_message = std::to_string(message_counter -
m_MessageThreshold) + verbose_message;
345 latex.DrawLatexNDC(x, y, verbose_message.c_str());
351 histogram->SetMinimum(1);
353 }
else if (ref_histogram !=
nullptr) {
356 histogram->SetMinimum(1);
371 if (subdetector == 1) {
380 for (
int k = 0; k < divisions; k++) {
381 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
387 if ((section == 2) && (index == 0 || index == 1))
391 for (
int k = 0; k < divisions; k++) {
392 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
407 histogram->SetStats(
false);
408 histogram->Draw(
"COLZ");
421 const std::string& histName)
424 if (histogram ==
nullptr) {
430 if (canvas ==
nullptr) {
442 if (delta !=
nullptr) {
443 B2INFO(
"DQMHistAnalysisKLM: Time Delta Entries is " << delta->GetEntries());
450 const std::string& histName)
453 if (histogram ==
nullptr) {
458 if (canvas ==
nullptr) {
467 int channelSubdetector, channelSection, channelSector;
468 int layer, plane, strip;
471 channel, &channelSubdetector, &channelSection, &channelSector,
472 &layer, &plane, &strip);
479 histogram->Fill(sectorIndex);
482 histogram->SetStats(
false);
489 const std::string& histName, TLatex& latex)
493 if (histogram ==
nullptr) {
498 if (canvas ==
nullptr) {
502 std::string name, alarm;
503 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
504 double xAlarm = 0.15;
508 histogram->SetStats(
false);
511 int message_counter = 0;
512 if (histName.find(
"bklm") != std::string::npos) {
516 int bin = maximalLayer * sector + 1;
517 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
518 double xText = histogram->GetXaxis()->GetBinLowEdge(bin + maximalLayer / 2);
519 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
521 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
537 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
539 alarm +=
", layer " + std::to_string(moduleLayer);
542 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
557 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
558 int bin = maxPlane * layerGlobal + 1;
559 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
560 double xText = histogram->GetXaxis()->GetBinLowEdge(bin - maxPlane / 2);
561 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
562 if (layerGlobal < maximalLayer)
563 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
566 layerGlobal, §ion, &layer);
571 name += std::to_string(layer);
581 module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
583 alarm +=
", layer " + std::to_string(moduleLayer);
586 latex.DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
599 std::string verbose_string =
" more messages";
600 verbose_string = std::to_string(message_counter -
m_MessageThreshold) + verbose_string;
601 latex.DrawLatexNDC(xAlarm, yAlarm, verbose_string.c_str());
612 if (not(daqInclusion ==
nullptr)) {
613 int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
614 if (isKlmIncluded == 0)
622 std::string str, histogramName, canvasName;
624 latex.SetTextColor(kRed);
625 latex.SetTextAlign(11);
634 for (
int j = 0; j < nHistograms; j++) {
635 str =
"strip_hits_subdetector_" +
636 std::to_string(klmSector.getSubdetector()) +
637 "_section_" + std::to_string(klmSector.getSection()) +
638 "_sector_" + std::to_string(klmSector.getSector()) +
639 "_" + std::to_string(j);
642 TH1* histogram =
findHist(histogramName);
644 auto delta =
getDelta(
"", histogramName);
646 if (histogram ==
nullptr) {
647 B2WARNING(
"KLM DQM histogram " << histogramName <<
" is not found.");
651 if (canvas ==
nullptr) {
652 B2WARNING(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
660 klmSector.getSubdetector(), klmSector.getSection(),
661 klmSector.getSector(), j, histogram, delta, canvas, latex);
666 gStyle->SetPalette(kLightTemperature);
673 for (
int j = 1; j <= maximalLayerNumber; ++j) {
674 str =
"spatial_2d_hits_subdetector_" + std::to_string(subdetector) +
675 "_section_" + std::to_string(section) +
676 "_layer_" + std::to_string(j);
679 TH2F* histogram =
static_cast<TH2F*
>(
findHist(histogramName));
680 if (histogram ==
nullptr) {
681 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
685 if (canvas ==
nullptr) {
686 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
694 gStyle->SetPalette(kBird);
696 latex.SetTextColor(kBlue);
705 B2DEBUG(20,
"Updating EPICS PVs for DQMHistAnalysisKLM");
709 B2INFO(
"DQMHistAnalysisKLM: Null run detected. No PV Update.");
712 auto* daqDataSize =
findHist(
"DAQ/KLMDataSize");
713 double meanDAQDataSize = 0.;
714 if (daqDataSize !=
nullptr) {
715 meanDAQDataSize = daqDataSize->GetMean();
717 B2WARNING(
"DQMHistAnalysisKLM: Cannot find KLMDataSize");
718 if ((daqDataSize !=
nullptr) and (meanDAQDataSize != 0.)) {
723 B2DEBUG(20,
"DQMHistAnalysisKLM: MaskedChannels " <<
m_MaskedChannels.size());
728 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.
std::string m_refFileName
Reference Histogram Root file name.
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.
std::string m_refHistogramDirectoryPrefix
Prefix to account for reference file.
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.
TFile * m_refFile
The pointer to the reference file.
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.
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.