10#include <dqm/analysis/modules/DQMHistAnalysisKLM2.h>
13#include <klm/dataobjects/KLMChannelIndex.h>
32 setDescription(
"Module used to analyze KLM Efficiency DQM histograms (depends on tracking variables).");
35 std::string(
"ref/KLMEfficiencyDQM"));
36 addParam(
"RefHistoFile",
m_refFileName,
"Reference histogram file name", std::string(
"KLM_DQM_REF_BEAM.root"));
42 addParam(
"RatioPlot",
m_ratio,
"2D efficiency ratio or difference plot ",
bool(
true));
71 B2INFO(
"DQMHistAnalysisKLM2: reference root file (" <<
m_refFileName <<
") FOUND, able to read ref histograms");
75 B2INFO(
"DQMHistAnalysisKLM2: eff_bklm_plane histogram was found in reference");
80 B2WARNING(
"DQMHistAnalysisKLM2: eff_bklm_plane histogram not found in reference");
95 B2INFO(
"DQMHistAnalysisKLM2: eff_eklm_plane histogram was found in reference");
100 B2WARNING(
"DQMHistAnalysisKLM2: eff_eklm_plane histogram not found in reference");
112 B2WARNING(
"DQMHistAnalysisKLM2: reference root file (" <<
m_refFileName <<
") not found, or closed");
149 "Plane Efficiency in BKLM",
151 m_eff_bklm->GetXaxis()->SetTitle(
"Layer number");
156 "Plane Efficiency in EKLM",
158 m_eff_eklm->GetXaxis()->SetTitle(
"Plane number");
163 "Sector Efficiency in BKLM",
170 "Sector Efficiency in EKLM",
190 TString eff2d_hist_bklm_title;
191 TString eff2d_hist_eklm_title;
193 eff2d_hist_bklm_title =
"Plane Efficiency Ratios in BKLM";
194 eff2d_hist_eklm_title =
"Plane Efficiency Ratios in EKLM";
196 eff2d_hist_bklm_title =
"Plane Efficiency Diffs in BKLM";
197 eff2d_hist_eklm_title =
"Plane Efficiency Diffs in EKLM";
216 std::string BB_sec =
"BB" + std::to_string(sec_id);
217 m_eff2d_bklm->GetXaxis()->SetBinLabel(sec_id + 1, BB_sec.c_str());
219 std::string BF_sec =
"BF" + std::to_string(sec_id);
224 std::string B_lay = std::to_string(lay_id);
225 m_eff2d_bklm->GetYaxis()->SetBinLabel(lay_id + 1, B_lay.c_str());
232 n_sectors_eklm, 0.5, n_sectors_eklm + 0.5,
239 n_sectors_eklm, 0.5, n_sectors_eklm + 0.5,
247 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
250 layerGlobal, §ion, &layer);
255 name += std::to_string(layer);
256 m_eff2d_eklm->GetXaxis()->SetBinLabel(layerGlobal, name.c_str());
260 std::string E_lay = std::to_string(lay_id);
261 m_eff2d_eklm->GetYaxis()->SetBinLabel(lay_id + 1, E_lay.c_str());
284 double valuesThr[] = { tempStop, tempAlarm, tempWarn };
287 std::sort(std::begin(valuesThr), std::end(valuesThr));
296 B2WARNING(
"DQMHistAnalysisKLM2Module: Found that alarmThr or alarmStop is greater than warnThr...");
320 if (bin < bklmMaxSector)
324 name += std::to_string(bin % bklmMaxSector);
330 if (bin < eklmLocalMaxSector)
334 name += std::to_string(bin % eklmLocalMaxSector);
339 for (
int layer = 0; layer <
m_eff_bklm->GetXaxis()->GetNbins(); layer++) {
342 if (layer / bklmMaxLayer < bklmMaxSector) {
347 name += std::to_string(
int(layer / bklmMaxLayer) % bklmMaxSector) +
"_layer" + std::to_string(1 + (layer % bklmMaxLayer));
350 for (
int layer = 0; layer <
m_eff_eklm->GetXaxis()->GetNbins(); layer++) {
352 if (layer / eklmGlobalMaxSector < eklmBLayerCount)
353 name +=
"B" + std::to_string(layer / eklmGlobalMaxSector + 1);
355 name +=
"F" + std::to_string(layer / eklmGlobalMaxSector - eklmBLayerCount + 1);
356 name += +
"_num" + std::to_string(((layer) % eklmGlobalMaxSector) + 1);
365 std::unique_ptr<TH1> effClone(
static_cast<TH1*
>
368 if (denominator !=
nullptr && numerator !=
nullptr) {
369 effHist->Divide(numerator, denominator, 1, 1,
"B");
374 if (ref) {ref->Draw(
"hist,same");}
380 auto deltaDenom =
getDelta(
"", denominator->GetName());
381 auto deltaNumer =
getDelta(
"", numerator->GetName());
387 if ((deltaNumer !=
nullptr) && (deltaDenom !=
nullptr)) {
388 B2INFO(
"DQMHistAnalysisKLM2: Eff Delta Num/Denom Entries is " << deltaNumer->GetEntries() <<
"/" << deltaDenom->GetEntries());
389 effClone->Divide(deltaNumer, deltaDenom, 1, 1,
"B");
390 effClone->SetLineColor(kOrange);
391 effClone->DrawCopy(
"SAME");
399 const std::string& histName, TH1* histogram)
403 if (canvas == NULL) {
408 histogram->SetStats(
false);
409 double histMin = gPad->GetUymin();
410 double histMax = gPad->GetUymax();
411 double histRange = histMax - histMin;
412 if (histName.find(
"bklm") != std::string::npos) {
416 int bin = maximalLayer * sector + 1;
417 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
418 double xText = histogram->GetXaxis()->GetBinLowEdge(bin + maximalLayer / 2);
419 double yText = histMin + 0.98 * histRange;
421 m_PlaneLine.DrawLine(xLine, histMin, xLine, histMin + histRange);
435 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
436 int bin = maxPlane * layerGlobal + 1;
437 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
438 double xText = histogram->GetXaxis()->GetBinLowEdge(bin - maxPlane / 2);
439 double yText = histMin + 0.98 * histRange;
440 if (layerGlobal < maximalLayer)
441 m_PlaneLine.DrawLine(xLine, histMin, xLine, histMin + histRange);
444 layerGlobal, §ion, &layer);
449 name += std::to_string(layer);
459 TH1* mainHist, TH1* refHist, TH2* eff2dHist, TH2* errHist,
int layers,
int sectors,
bool ratioPlot,
460 int* pvcount,
double layerLimit, TCanvas* eff2dCanv)
468 float maxVal =
m_max;
469 float minVal =
m_min;
474 bool setAlarm =
false;
475 bool setWarn =
false;
482 mainEntries = mainHist->GetEntries();
484 for (
int binx = 0; binx < sectors; binx++) {
486 for (
int biny = 0; biny < layers; biny++) {
488 mainEff = mainHist->GetBinContent(i + 1);
489 mainErr = mainHist->GetBinError(i + 1);
491 refEff = refHist->GetBinContent(i + 1);
492 refErr = refHist->GetBinError(i + 1);
498 if ((mainEff == 0.) and (refEff == 0.)) {
500 eff2dHist->SetBinContent(binx + 1, biny + 1, 0.);
501 }
else if ((refEff == 0.) and (ratioPlot)) {
503 eff2dHist->SetBinContent(binx + 1, biny + 1, maxVal);
504 }
else if (mainEff == 0.) {
506 eff2dHist->SetBinContent(binx + 1, biny + 1, 0.);
507 errHist->SetBinContent(binx + 1, biny + 1, 0.);
511 eff2dVal = mainEff / refEff;
512 if (eff2dVal < alarmThr) {errHist->SetBinContent(binx + 1, biny + 1, eff2dVal);}
514 eff2dVal = (mainEff - refEff) / pow(pow(mainErr, 2) + pow(refErr, 2), 0.5);
518 if ((eff2dVal > minVal) and (eff2dVal < maxVal)) {
520 eff2dHist->SetBinContent(binx + 1, biny + 1, eff2dVal);
521 }
else if (eff2dVal > maxVal) {
523 eff2dHist->SetBinContent(binx + 1, biny + 1, maxVal);
524 }
else if (eff2dVal < minVal) {
526 eff2dHist->SetBinContent(binx + 1, biny + 1, minVal);
533 if (eff2dVal < warnThr) {
535 if ((eff2dVal <= alarmThr) && (eff2dVal >= stopThr)) {
537 }
else if (eff2dVal < stopThr) {
549 if (*pvcount > (
int) layerLimit) {
553 eff2dHist->SetMinimum(minVal);
554 eff2dHist->SetMaximum(maxVal);
557 eff2dHist->Draw(
"COLZ");
558 errHist->Draw(
"TEXT SAME");
561 }
else if (setAlarm) {
563 }
else if (setWarn) {
568 eff2dCanv->Modified();
575 TH1* daqInclusion =
findHist(
"KLM/daq_inclusion");
576 if (not(daqInclusion == NULL)) {
577 int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
578 if (isKlmIncluded == 0)
598 if ((all_ext_bklm ==
nullptr || matched_hits_bklm ==
nullptr) && (
m_IsPhysicsRun)) {
599 B2INFO(
"Histograms needed for BKLM plane efficiency computation are not found");
602 if ((all_ext_eklm ==
nullptr || matched_hits_eklm ==
nullptr) && (
m_IsPhysicsRun)) {
603 B2INFO(
"Histograms needed for EKLM plane efficiency computation are not found");
605 if ((all_ext_bklm_sector ==
nullptr || matched_hits_bklm_sector ==
nullptr) && (
m_IsPhysicsRun)) {
606 B2INFO(
"Histograms needed for BKLM sector efficiency computation are not found");
608 if ((all_ext_eklm_sector ==
nullptr || matched_hits_eklm_sector ==
nullptr) && (
m_IsPhysicsRun)) {
609 B2INFO(
"Histograms needed for EKLM sector efficiency computation are not found");
633 B2DEBUG(20,
"DQMHistAnalysisKLM2: Updating EPICS PVs");
637 B2INFO(
"DQMHistAnalysisKLM2: Null run detected. No PV Update.");
640 auto* daqDataSize =
findHist(
"DAQ/KLMDataSize");
641 double meanDAQDataSize = 0.;
642 if (daqDataSize !=
nullptr) {
643 meanDAQDataSize = daqDataSize->GetMean();
644 B2INFO(
"DAQ/KLMDataSize's mean is " << meanDAQDataSize);
646 B2WARNING(
"DQMHistAnalysisKLM2: Cannot find KLMDataSize");
647 if ((daqDataSize !=
nullptr) and (meanDAQDataSize != 0.)) {
658 B2INFO(
"DQMHistAnalysisKLM2: KLM Not included. No PV Update. ");
static constexpr int getMaximalLayerGlobalNumber()
Get maximal layer global number.
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.
TH1 * m_ref_efficiencies_bklm
BKLM efficiencies reference histogram.
std::string m_refFileName
2D layer-sector efficiency differences
TLine m_PlaneLine
TLine for boundary in plane histograms.
int m_nEffEKLMLayers
Number of inefficient EKLM Layers.
void initialize() override final
Initializer.
TCanvas * m_c_eff2d_bklm
BKLM efficiencies ratio canvas.
double m_EKLMLayerWarn
alarm limits from inefficient EKLM layers PV
std::string m_refHistogramDirectoryName
Name of histogram directory for reference file.
TCanvas * m_c_eff2d_eklm
EKLM efficiencies ratio canvas.
TH1 * m_eff_bklm_sector
Histogram for BKLM sector efficiency.
void processPlaneHistogram(const std::string &histName, TH1 *histogram)
Process histogram containing the number of hits in plane.
bool m_IsPhysicsRun
Run type flag for null runs.
float m_stopThr
efficiency ratio (run-)stop threshold
double m_minEntries
Minimal number of entries for delta histogram and PV update.
TH1 * m_eff_eklm
Histogram for EKLM plane efficiency.
void processEfficiencyHistogram(TH1 *effHist, TH1 *denominator, TH1 *numerator, TCanvas *canvas)
Process histogram containing the efficiencies.
TCanvas * m_c_eff_eklm_sector
Histogram for EKLM sector efficiency.
const EKLMElementNumbers * m_EklmElementNumbers
EKLM element numbers.
TH1 * m_eff_eklm_sector
Histogram for EKLM sector efficiency.
float m_max
efficiency ratio max z scale
double m_BKLMLayerWarn
alarm limits from inefficient BKLM layers PV
MonitoringObject * m_monObj
Monitoring object.
TH1 * m_ref_efficiencies_eklm
ELM efficiencies reference histogram.
float m_alarmThr
efficiency ratio alarm threshold
void process2DEffHistogram(TH1 *mainHist, TH1 *refHist, TH2 *planeHist, TH2 *errHist, int layers, int sectors, bool ratioPlot, int *pvcount, double layerLimit, TCanvas *eff2dCanv)
Process 2D efficiency histograms.
void event() override final
This method is called for each event.
TCanvas * m_c_eff_bklm_sector
Histogram for BKLM sector efficiency.
float m_warnThr
efficiency ratio warning threshold
std::string m_histogramDirectoryName
Name of histogram directory.
TH2 * m_err_bklm
BKLM efficiencies error histogram.
float m_min
efficiency ratio min z scale
TH2 * m_eff2d_bklm
BKLM efficiencies 2dim histogram.
TH1 * m_eff_bklm
Histogram for BKLM plane efficiency.
TCanvas * m_c_eff_bklm
BKLM plane efficiency canvas.
TText m_PlaneText
TText for names in plane histograms.
TCanvas * m_c_eff_eklm
EKLM plane efficiency canvas.
void endRun() override final
This method is called if the current run ends.
void beginRun() override final
Called when entering a new run.
bool m_ratio
show efficiency ratio or difference
TH2 * m_err_eklm
EKLM efficiencies error histogram.
bool m_IsNullRun
Run type flag for null runs.
TH2 * m_eff2d_eklm
EKLM efficiencies 2dim histogram.
int m_nEffBKLMLayers
Number of inefficient BKLM layers.
DQMHistAnalysisKLM2Module()
Constructor.
TFile * m_refFile
reference histogram 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.
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_StatusWarning
Analysis result: Warning, there may be minor issues.
@ 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)
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
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.
static constexpr int getMaximalPlaneGlobalNumber()
Get maximal plane global number.
@ c_BackwardSection
Backward.
static constexpr int getMaximalSectorNumber()
Get maximal sector number.
static constexpr int getMaximalPlaneNumber()
Get maximal plane number.
static constexpr int getMaximalSectorGlobalNumberKLMOrder()
Get maximal sector global number with KLM ordering (section, 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)
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.
Abstract base class for different kinds of events.