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", 30000.);
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."
107 bklmSectors * 2, 0.5, 0.5 + bklmSectors * 2);
115 eklmPlanes, 0.5, 0.5 + eklmPlanes);
122 totalSectors, -0.5, totalSectors - 0.5);
127 std::string label =
m_ElementNumbers->getSectorDAQName(klmSector.getSubdetector(), klmSector.getSection(), klmSector.getSector());
136 for (
int j = 0; j < nHistograms; j++) {
137 str =
"strip_hits_subdetector_" +
138 std::to_string(klmSector.getSubdetector()) +
139 "_section_" + std::to_string(klmSector.getSection()) +
140 "_sector_" + std::to_string(klmSector.getSector()) +
141 "_" + std::to_string(j);
156 B2FATAL(
"No KLM electronics map.");
168 int hist_max_bin;
double max_position;
171 hist_max_bin = time_rpc->GetMaximumBin();
172 max_position = time_rpc->GetXaxis()->GetBinCenter(hist_max_bin);
173 m_monObj->setVariable(
"RPC_Time_Peak", max_position);
177 if (time_scint_bklm) {
178 hist_max_bin = time_scint_bklm->GetMaximumBin();
179 max_position = time_scint_bklm->GetXaxis()->GetBinCenter(hist_max_bin);
180 m_monObj->setVariable(
"BKLM_Scint_Time_Peak", max_position);
184 if (time_scint_eklm) {
185 hist_max_bin = time_scint_eklm->GetMaximumBin();
186 max_position = time_scint_eklm->GetXaxis()->GetBinCenter(hist_max_bin);
187 m_monObj->setVariable(
"EKLM_Scint_Time_Peak", max_position);
194 B2WARNING(
"Either DAQ/Nevent is not found or Nevent = 0.");
203 if (delta !=
nullptr) {
204 Double_t scale = (Double_t) histogram->Integral();
207 delta->SetLineColor(kBlackBody);
208 delta->SetLineStyle(4);
209 delta->DrawNormalized(
"SAME", scale);
216 int subdetector,
int section,
int sector,
int index,
217 TH1* histogram, TH1* delta, TCanvas* canvas, TLatex& latex)
223 std::map<KLMModuleNumber, double>::iterator it;
225 int channelSubdetector, channelSection, channelSector;
226 int layer, plane, strip;
230 histogram->SetStats(
false);
234 n = histogram->GetXaxis()->GetNbins();
238 if (ref_histogram) {ref_histogram->Draw(
"hist,same");}
239 float ref_average = 0;
241 if (ref_histogram !=
nullptr) {
242 for (i = 1; i <= n; i++) {
243 double nHitsPerModuleRef = ref_histogram->GetBinContent(i);
244 ref_average = ref_average + nHitsPerModuleRef;
248 for (i = 1; i <= n; i++) {
252 double nHitsPerModule = histogram->GetBinContent(i);
253 average = average + nHitsPerModule;
255 channelNumber, &channelSubdetector, &channelSection, &channelSector,
256 &layer, &plane, &strip);
257 if ((channelSubdetector != subdetector) ||
258 (channelSection != section) ||
259 (channelSector != sector))
260 B2FATAL(
"Inconsistent element numbers.");
262 subdetector, section, sector, layer);
266 module, nHitsPerModule));
268 it->second += nHitsPerModule;
271 unsigned int activeModuleChannels = 0;
272 int message_counter = 0;
275 if (it->second != 0) {
280 moduleNumber, &channelSubdetector, &channelSection, &channelSector, &layer);
284 channelSubdetector, channelSection, channelSector, layer, 1, 1);
287 if (electronicsChannel ==
nullptr)
288 B2FATAL(
"Incomplete KLM electronics map.");
289 str =
"No data from lane " + std::to_string(electronicsChannel->
getLane());
290 latex.DrawLatexNDC(x, y, str.c_str());
296 std::vector<KLMModuleNumber>::iterator ite =
310 if (activeModuleChannels == 0)
312 average /= activeModuleChannels;
313 ref_average /= activeModuleChannels;
315 for (i = 1; i <= n; ++i) {
319 double nHits = histogram->GetBinContent(i);
321 channelNumber, &channelSubdetector, &channelSection, &channelSector,
322 &layer, &plane, &strip);
323 std::string channelStatus =
"Normal";
325 channelStatus =
"Masked";
326 std::vector<KLMModuleNumber>::iterator ite =
332 B2DEBUG(20,
"KLM@MaskMe " << channelNumber);
334 channelStatus =
"Hot";
336 if (channelStatus !=
"Normal") {
339 if (electronicsChannel ==
nullptr)
340 B2FATAL(
"Incomplete BKLM electronics map.");
341 if (channelStatus ==
"Masked") {
342 histogram->SetBinContent(i, 0);
343 if (delta !=
nullptr)
344 delta->SetBinContent(i, 0);
346 str = channelStatus +
" channel: ";
348 str += (
"L" + std::to_string(electronicsChannel->
getLane()) +
349 " A" + std::to_string(electronicsChannel->
getAxis()) +
350 " Ch" + std::to_string(electronicsChannel->
getChannel()));
353 latex.DrawLatexNDC(x, y, str.c_str());
359 std::string verbose_message =
" more messages";
360 verbose_message = std::to_string(message_counter -
m_MessageThreshold) + verbose_message;
361 latex.DrawLatexNDC(x, y, verbose_message.c_str());
367 histogram->SetMinimum(1);
369 }
else if (ref_histogram !=
nullptr) {
372 histogram->SetMinimum(1);
387 if (subdetector == 1) {
396 for (
int k = 0; k < divisions; k++) {
397 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
403 if ((section == 2) && (index == 0 || index == 1))
407 for (
int k = 0; k < divisions; k++) {
408 xLine = (histogram->GetXaxis()->GetBinLowEdge(bin) - canvas->GetX1()) / (canvas->GetX2() - canvas->GetX1());
423 histogram->SetStats(
false);
424 histogram->Draw(
"COLZ");
437 const std::string& histName)
440 if (histogram ==
nullptr) {
446 if (canvas ==
nullptr) {
458 if (delta !=
nullptr) {
459 B2INFO(
"DQMHistAnalysisKLM: Time Delta Entries is " << delta->GetEntries());
464 if (ref) {ref->Draw(
"hist,same");}
469 TH1* histogram, TCanvas* canvas)
475 int channelSubdetector, channelSection, channelSector;
476 int layer, plane, strip;
479 channel, &channelSubdetector, &channelSection, &channelSector,
480 &layer, &plane, &strip);
483 sectorNumber =
m_ElementNumbers->sectorNumberBKLM(channelSection, channelSector);
485 sectorNumber =
m_ElementNumbers->sectorNumberEKLM(channelSection, channelSector);
487 histogram->Fill(sectorIndex);
490 histogram->SetStats(
false);
491 histogram->SetTitle(
"Number of masked channels per sector");
498 const std::string& histName, TLatex* latex =
nullptr, TH1* histogram =
nullptr)
517 histogram->SetStats(
false);
523 ref->Draw(
"hist,same");
527 double xAlarm = 0.15, yAlarm = 0.8;
528 int message_counter = 0;
532 bool isBKLM = histName.find(
"bklm") != std::string::npos;
535 bool isFE = histName.find(
"fe") != std::string::npos;
543 int bin = maximalLayer * sector + 1;
544 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
545 double xText = histogram->GetXaxis()->GetBinLowEdge(bin + maximalLayer / 2);
546 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
549 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
564 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
565 int bin = maxPlane * layerGlobal + 1;
566 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
567 double xText = histogram->GetXaxis()->GetBinLowEdge(bin - maxPlane / 2);
568 double yText = gPad->GetUymin() + 0.98 * (gPad->GetUymax() - gPad->GetUymin());
570 if (layerGlobal < maximalLayer) {
571 m_PlaneLine.DrawLine(xLine, gPad->GetUymin(), xLine, gPad->GetUymax());
588 std::string verbose_string = std::to_string(message_counter -
m_MessageThreshold) +
" more messages";
589 latex->DrawLatexNDC(xAlarm, yAlarm, verbose_string.c_str());
598 TCanvas* canvas,
const std::vector<KLMModuleNumber>& deadModules,
599 TLatex* latex,
int& message_counter,
double xAlarm,
double yAlarm)
601 if (deadModules.empty()) {
605 int moduleSubdetector, moduleSection, moduleSector, moduleLayer;
606 m_ElementNumbers->moduleNumberToElementNumbers(module, &moduleSubdetector, &moduleSection, &moduleSector, &moduleLayer);
608 std::string alarm =
"No data from " +
m_ElementNumbers->getSectorDAQName(moduleSubdetector, moduleSection, moduleSector)
609 +
", layer " + std::to_string(moduleLayer);
612 latex->DrawLatexNDC(xAlarm, yAlarm, alarm.c_str());
626 const std::string& histName, TLatex& latex)
635 B2WARNING(
"processFEHistogram: feHist is null, exiting function.");
639 B2WARNING(
"processFEHistogram: canvas is null, cannot draw histograms.");
647 if (numerator ==
nullptr || denominator ==
nullptr) {
648 B2INFO(
"processFEHistogram: Histograms needed for FE Ratio computation are not found");
653 std::unique_ptr<TH1> feClone(
static_cast<TH1*
>(feHist->Clone()));
657 if (denominator !=
nullptr && numerator !=
nullptr) {
659 auto tempNumerator = std::unique_ptr<TH1>(
static_cast<TH1*
>(numerator->Clone()));
660 auto tempSum = std::unique_ptr<TH1>(
static_cast<TH1*
>(denominator->Clone()));
663 tempSum->Add(numerator);
666 feHist->Divide(tempNumerator.get(), tempSum.get(), 1.0, 1.0,
"B");
672 ref->Draw(
"hist,same");
673 B2INFO(
"processFEHistogram: Found and drew reference histogram.");
675 B2WARNING(
"processFEHistogram: Reference histogram not found.");
680 B2INFO(
"processFEHistogram: Updated canvas after first draw.");
688 if (deltaNumer !=
nullptr && deltaDenom !=
nullptr) {
689 B2INFO(
"DQMHistAnalysisKLM: FE Ratio Delta Num/Denom Entries is "
690 << deltaNumer->GetEntries() <<
"/" << deltaDenom->GetEntries());
693 auto deltaTempNumerator = std::unique_ptr<TH1>(
static_cast<TH1*
>(deltaNumer->Clone()));
694 auto deltaTempSum = std::unique_ptr<TH1>(
static_cast<TH1*
>(deltaDenom->Clone()));
697 deltaTempSum->Add(deltaNumer);
700 feClone->Divide(deltaTempNumerator.get(), deltaTempSum.get(), 1.0, 1.0,
"B");
701 feClone->SetLineColor(kOrange);
702 feClone->DrawCopy(
"SAME");
707 B2WARNING(
"processFEHistogram: Delta numerator or denominator not found.");
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.
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.