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 of entries for delta histogram updates", 30000.);
52 "Minimal number of processed events for delta histogram updates", 30000.);
54 "Max number of messages to show up in channel occupancy plots", 12);
76 B2FATAL(
"The threshold used for hot channels is larger than the one for masked channels."
111 bklmSectors * 2, 0.5, 0.5 + bklmSectors * 2);
119 eklmPlanes, 0.5, 0.5 + eklmPlanes);
126 totalSectors, -0.5, totalSectors - 0.5);
131 std::string label =
m_ElementNumbers->getSectorDAQName(klmSector.getSubdetector(), klmSector.getSection(), klmSector.getSector());
140 for (
int j = 0; j < nHistograms; j++) {
141 str =
"strip_hits_subdetector_" +
142 std::to_string(klmSector.getSubdetector()) +
143 "_section_" + std::to_string(klmSector.getSection()) +
144 "_sector_" + std::to_string(klmSector.getSector()) +
145 "_" + std::to_string(j);
160 B2FATAL(
"No KLM electronics map.");
172 int hist_max_bin;
double max_position;
175 hist_max_bin = time_rpc->GetMaximumBin();
176 max_position = time_rpc->GetXaxis()->GetBinCenter(hist_max_bin);
177 m_monObj->setVariable(
"RPC_Time_Peak", max_position);
181 if (time_scint_bklm) {
182 hist_max_bin = time_scint_bklm->GetMaximumBin();
183 max_position = time_scint_bklm->GetXaxis()->GetBinCenter(hist_max_bin);
184 m_monObj->setVariable(
"BKLM_Scint_Time_Peak", max_position);
188 if (time_scint_eklm) {
189 hist_max_bin = time_scint_eklm->GetMaximumBin();
190 max_position = time_scint_eklm->GetXaxis()->GetBinCenter(hist_max_bin);
191 m_monObj->setVariable(
"EKLM_Scint_Time_Peak", max_position);
198 B2WARNING(
"Either DAQ/Nevent is not found or Nevent = 0.");
207 if (delta !=
nullptr) {
208 Double_t scale = (Double_t) histogram->Integral();
211 delta->SetLineColor(kBlackBody);
212 delta->SetLineStyle(4);
213 delta->DrawNormalized(
"SAME", scale);
220 int subdetector,
int section,
int sector,
int index,
221 TH1* histogram, TH1* delta, TCanvas* canvas, TLatex& latex)
227 std::map<KLMModuleNumber, double>::iterator it;
229 int channelSubdetector, channelSection, channelSector;
230 int layer, plane, strip;
234 histogram->SetStats(
false);
238 n = histogram->GetXaxis()->GetNbins();
242 if (ref_histogram) {ref_histogram->Draw(
"hist,same");}
243 float ref_average = 0;
245 if (ref_histogram !=
nullptr) {
246 for (i = 1; i <= n; i++) {
247 double nHitsPerModuleRef = ref_histogram->GetBinContent(i);
248 ref_average = ref_average + nHitsPerModuleRef;
252 for (i = 1; i <= n; i++) {
256 double nHitsPerModule = histogram->GetBinContent(i);
257 average = average + nHitsPerModule;
259 channelNumber, &channelSubdetector, &channelSection, &channelSector,
260 &layer, &plane, &strip);
261 if ((channelSubdetector != subdetector) ||
262 (channelSection != section) ||
263 (channelSector != sector))
264 B2FATAL(
"Inconsistent element numbers.");
266 subdetector, section, sector, layer);
270 module, nHitsPerModule));
272 it->second += nHitsPerModule;
275 unsigned int activeModuleChannels = 0;
276 int message_counter = 0;
279 if (it->second != 0) {
284 moduleNumber, &channelSubdetector, &channelSection, &channelSector, &layer);
288 channelSubdetector, channelSection, channelSector, layer, 1, 1);
291 if (electronicsChannel ==
nullptr)
292 B2FATAL(
"Incomplete KLM electronics map.");
293 str =
"No data from lane " + std::to_string(electronicsChannel->
getLane());
294 latex.DrawLatexNDC(x, y, str.c_str());
300 std::vector<KLMModuleNumber>::iterator ite =
314 if (activeModuleChannels == 0)
316 average /= activeModuleChannels;
317 ref_average /= activeModuleChannels;
319 for (i = 1; i <= n; ++i) {
323 double nHits = histogram->GetBinContent(i);
325 channelNumber, &channelSubdetector, &channelSection, &channelSector,
326 &layer, &plane, &strip);
327 std::string channelStatus =
"Normal";
329 channelStatus =
"Masked";
330 std::vector<KLMModuleNumber>::iterator ite =
336 B2DEBUG(20,
"KLM@MaskMe " << channelNumber);
338 channelStatus =
"Hot";
340 if (channelStatus !=
"Normal") {
343 if (electronicsChannel ==
nullptr)
344 B2FATAL(
"Incomplete BKLM electronics map.");
345 if (channelStatus ==
"Masked") {
346 histogram->SetBinContent(i, 0);
347 if (delta !=
nullptr)
348 delta->SetBinContent(i, 0);
350 str = channelStatus +
" channel: ";
352 str += (
"L" + std::to_string(electronicsChannel->
getLane()) +
353 " A" + std::to_string(electronicsChannel->
getAxis()) +
354 " Ch" + std::to_string(electronicsChannel->
getChannel()));
357 latex.DrawLatexNDC(x, y, str.c_str());
363 std::string verbose_message =
" more messages";
364 verbose_message = std::to_string(message_counter -
m_MessageThreshold) + verbose_message;
365 latex.DrawLatexNDC(x, y, verbose_message.c_str());
371 histogram->SetMinimum(1);
373 }
else if (ref_histogram !=
nullptr) {
376 histogram->SetMinimum(1);
391 if (subdetector == 1) {
400 for (
int k = 0; k < divisions; k++) {
401 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
407 if ((section == 2) && (index == 0 || index == 1))
411 for (
int k = 0; k < divisions; k++) {
412 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
427 histogram->SetStats(
false);
428 histogram->Draw(
"COLZ");
441 const std::string& histName)
444 if (histogram ==
nullptr) {
450 if (canvas ==
nullptr) {
462 if (delta !=
nullptr) {
463 B2INFO(
"DQMHistAnalysisKLM: Time Delta Entries is " << delta->GetEntries());
468 if (ref) {ref->Draw(
"hist,same");}
473 TH1* histogram, TCanvas* canvas)
479 int channelSubdetector, channelSection, channelSector;
480 int layer, plane, strip;
483 channel, &channelSubdetector, &channelSection, &channelSector,
484 &layer, &plane, &strip);
487 sectorNumber =
m_ElementNumbers->sectorNumberBKLM(channelSection, channelSector);
489 sectorNumber =
m_ElementNumbers->sectorNumberEKLM(channelSection, channelSector);
491 histogram->Fill(sectorIndex);
494 histogram->SetStats(
false);
495 histogram->SetTitle(
"Number of masked channels per sector");
502 const std::string& histName, TLatex* latex =
nullptr, TH1* histogram =
nullptr)
521 histogram->SetStats(
false);
527 ref->Draw(
"hist,same");
531 double xAlarm = 0.15, yAlarm = 0.8;
532 int message_counter = 0;
536 bool isBKLM = histName.find(
"bklm") != std::string::npos;
539 bool isFE = histName.find(
"fe") != std::string::npos;
547 int bin = maximalLayer * sector + 1;
548 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
549 double xText = histogram->GetXaxis()->GetBinLowEdge(bin + maximalLayer / 2);
550 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
553 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
568 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
569 int bin = maxPlane * layerGlobal + 1;
570 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
571 double xText = histogram->GetXaxis()->GetBinLowEdge(bin - maxPlane / 2);
572 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
574 if (layerGlobal < maximalLayer) {
575 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
592 std::string verbose_string = std::to_string(message_counter -
m_MessageThreshold) +
" more messages";
593 latex->DrawLatexNDC(xAlarm, yAlarm, verbose_string.c_str());
602 TCanvas* canvas,
const std::vector<KLMModuleNumber>& deadModules,
603 TLatex* latex,
int& message_counter,
double xAlarm,
double yAlarm)
605 if (deadModules.empty()) {
609 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
610 m_ElementNumbers->moduleNumberToElementNumbers(module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
612 std::string alarm =
"No data from " +
m_ElementNumbers->getSectorDAQName(moduleSubdetector, moduleSection, moduleSector)
613 +
", layer " + std::to_string(moduleLayer);
616 latex->DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
630 const std::string& histName, TLatex& latex)
639 B2WARNING(
"processFEHistogram: feHist is null, exiting function.");
643 B2WARNING(
"processFEHistogram: canvas is null, cannot draw histograms.");
652 std::unique_ptr<TH1> feClone(
static_cast<TH1*
>(feHist->Clone()));
656 if (denominator !=
nullptr && numerator !=
nullptr) {
658 auto tempNumerator = std::unique_ptr<TH1>(
static_cast<TH1*
>(numerator->Clone()));
659 auto tempSum = std::unique_ptr<TH1>(
static_cast<TH1*
>(denominator->Clone()));
662 tempSum->Add(numerator);
665 feHist->Divide(tempNumerator.get(), tempSum.get(), 1.0, 1.0,
"B");
671 ref->Draw(
"hist,same");
672 B2INFO(
"processFEHistogram: Found and drew reference histogram.");
674 B2WARNING(
"processFEHistogram: Reference histogram not found.");
679 B2INFO(
"processFEHistogram: Updated canvas after first draw.");
687 if (deltaNumer !=
nullptr && deltaDenom !=
nullptr) {
688 B2INFO(
"DQMHistAnalysisKLM: FE Ratio Delta Num/Denom Entries is "
689 << deltaNumer->GetEntries() <<
"/" << deltaDenom->GetEntries());
692 auto deltaTempNumerator = std::unique_ptr<TH1>(
static_cast<TH1*
>(deltaNumer->Clone()));
693 auto deltaTempSum = std::unique_ptr<TH1>(
static_cast<TH1*
>(deltaDenom->Clone()));
696 deltaTempSum->Add(deltaNumer);
699 feClone->Divide(deltaTempNumerator.get(), deltaTempSum.get(), 1.0, 1.0,
"B");
700 feClone->SetLineColor(kOrange);
701 feClone->DrawCopy(
"SAME");
710 B2WARNING(
"processFEHistogram: Skipped histogram processing due to missing numerator/denominator.");
718 if (not(daqInclusion ==
nullptr)) {
719 int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
720 if (isKlmIncluded == 0)
728 std::string str, histogramName, canvasName;
730 latex.SetTextColor(kRed);
731 latex.SetTextAlign(11);
740 for (
int j = 0; j < nHistograms; j++) {
741 str =
"strip_hits_subdetector_" +
742 std::to_string(klmSector.getSubdetector()) +
743 "_section_" + std::to_string(klmSector.getSection()) +
744 "_sector_" + std::to_string(klmSector.getSector()) +
745 "_" + std::to_string(j);
748 TH1* histogram =
findHist(histogramName);
750 auto delta =
getDelta(
"", histogramName);
752 if (histogram ==
nullptr) {
753 B2WARNING(
"KLM DQM histogram " << histogramName <<
" is not found.");
757 if (canvas ==
nullptr) {
758 B2WARNING(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
766 klmSector.getSubdetector(), klmSector.getSection(),
767 klmSector.getSector(), j, histogram, delta, canvas, latex);
772 gStyle->SetPalette(kLightTemperature);
779 for (
int j = 1; j <= maximalLayerNumber; ++j) {
780 str =
"spatial_2d_hits_subdetector_" + std::to_string(subdetector) +
781 "_section_" + std::to_string(section) +
782 "_layer_" + std::to_string(j);
785 TH2F* histogram =
static_cast<TH2F*
>(
findHist(histogramName));
786 if (histogram ==
nullptr) {
787 B2ERROR(
"KLM DQM histogram " << histogramName <<
" is not found.");
791 if (canvas ==
nullptr) {
792 B2ERROR(
"KLM DQM histogram canvas " << canvasName <<
" is not found.");
801 gStyle->SetPalette(kBird);
803 latex.SetTextColor(kBlue);
818 B2DEBUG(20,
"Updating EPICS PVs for DQMHistAnalysisKLM");
822 B2INFO(
"DQMHistAnalysisKLM: Null run detected. No PV Update.");
825 auto* daqDataSize =
findHist(
"DAQ/KLMDataSize");
826 double meanDAQDataSize = 0.;
827 if (daqDataSize !=
nullptr) {
828 meanDAQDataSize = daqDataSize->GetMean();
830 B2WARNING(
"DQMHistAnalysisKLM: Cannot find KLMDataSize");
831 if ((daqDataSize !=
nullptr) and (meanDAQDataSize != 0.)) {
836 B2DEBUG(20,
"DQMHistAnalysisKLM: MaskedChannels " <<
m_MaskedChannels.size());
841 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.
void processFEHistogram(TH1 *feHist, const std::string &histName, TCanvas *canvas)
Process histogram containing the efficiencies.
double m_ProcessedEvents
Number of processed events.
void initialize() override final
Initializer.
int m_MessageThreshold
Message Threshold for expert pots.
void updateCanvasStatus(TCanvas *canvas, const std::vector< KLMModuleNumber > &deadModules, TLatex *latex, int &message_counter, double xAlarm, double yAlarm)
Helper function to update the canvas status based on dead modules.
void processPlaneHistogram(const std::string &histName, TLatex *latex, TH1 *histogram)
Process histogram containing the number of hits in plane.
TH1 * m_fe_eklm_ratio
Histogram for EKLM plane events fraction w/ FE.
int m_ThresholdForLog
Threshold for log scale.
double m_minEntries
Minimal number of entries for delta histogram update.
TCanvas * m_c_fe_eklm_ratio
Canvas for EKLM plane events fraction w/ FE.
int m_MinHitsForFlagging
Minimal number of hits for flagging.
const KLMElementNumbers * m_ElementNumbers
KLM element numbers.
const EKLMElementNumbers * m_EklmElementNumbers
EKLM element numbers.
double m_minEvents
Minimal number of processed events for delta histogram update.
void fillMaskedChannelsHistogram(TH1 *histogram, TCanvas *canvas)
Fill histogram containing masked channels per sector.
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.
TCanvas * m_c_fe_bklm_ratio
Canvas for BKLM plane events fraction w/ FE.
int m_ThresholdForHot
Threshold for hot channels.
TH1 * m_fe_bklm_ratio
Histogram for BKLM plane events fraction w/ FE.
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.
TH1 * m_MaskedChannelsHist
Histogram for masked channels per sector.
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.
TCanvas * m_c_masked_channels
Canvas for masked channels per sector summary.
static 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).
int registerEpicsPV(const std::string &pvname, const std::string &keyname="")
EPICS related Functions.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
static void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static 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 void UpdateCanvas(const std::string &name, bool updated=true)
Mark canvas as updated (or not)
static const std::string & getRunType(void)
Get the list of the reference histograms.
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
DQMHistAnalysisModule()
Constructor / Destructor.
@ 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)
@ c_RefScaleNone
no scaling
static int getEventProcessed(void)
Get the number of processed events.
void setEpicsPV(const std::string &keyname, double value)
Write value to a EPICS PV.
static constexpr int getNStripsSector()
Get number of strips in a sector.
static constexpr int getMaximalLayerGlobalNumber()
Get maximal detector layer global number.
static constexpr int getMaximalPlaneGlobalNumber()
Get maximal plane 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.
void setDescription(const std::string &description)
Sets the description of the module.
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.