10 #include <dqm/analysis/modules/DQMHistAnalysisKLM2.h>
13 #include <klm/dataobjects/KLMChannelIndex.h>
31 setDescription(
"Module used to analyze KLM Efficiency DQM histograms (depends on tracking variables).");
34 addParam(
"RefHistoFile",
m_refFileName,
"Reference histogram file name", std::string(
"KLM_DQM_REF_BEAM.root"));
39 addParam(
"RatioPlot",
m_ratio,
"2D efficiency ratio or difference plot ",
bool(
true));
68 B2INFO(
"DQMHistAnalysisKLM2: reference root file (" <<
m_refFileName <<
") FOUND, able to read ref histograms");
81 B2WARNING(
"DQMHistAnalysisKLM2: reference root file (" <<
m_refFileName <<
") not found, or closed");
117 "Plane Efficiency in BKLM",
119 m_eff_bklm->GetXaxis()->SetTitle(
"Layer number");
124 "Plane Efficiency in EKLM",
126 m_eff_eklm->GetXaxis()->SetTitle(
"Plane number");
131 "Sector Efficiency in BKLM",
138 "Sector Efficiency in EKLM",
158 TString eff2d_hist_bklm_title;
159 TString eff2d_hist_eklm_title;
161 eff2d_hist_bklm_title =
"Plane Efficiency Ratios in BKLM";
162 eff2d_hist_eklm_title =
"Plane Efficiency Ratios in EKLM";
164 eff2d_hist_bklm_title =
"Plane Efficiency Diffs in BKLM";
165 eff2d_hist_eklm_title =
"Plane Efficiency Diffs in EKLM";
184 std::string BB_sec =
"BB" + std::to_string(sec_id);
185 m_eff2d_bklm->GetXaxis()->SetBinLabel(sec_id + 1, BB_sec.c_str());
187 std::string BF_sec =
"BF" + std::to_string(sec_id);
192 std::string B_lay = std::to_string(lay_id);
193 m_eff2d_bklm->GetYaxis()->SetBinLabel(lay_id + 1, B_lay.c_str());
200 n_sectors_eklm, 0.5, n_sectors_eklm + 0.5,
207 n_sectors_eklm, 0.5, n_sectors_eklm + 0.5,
215 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
218 layerGlobal, §ion, &layer);
223 name += std::to_string(layer);
224 m_eff2d_eklm->GetXaxis()->SetBinLabel(layerGlobal, name.c_str());
228 std::string E_lay = std::to_string(lay_id);
229 m_eff2d_eklm->GetYaxis()->SetBinLabel(lay_id + 1, E_lay.c_str());
250 m_alarmThr = (float) std::min(tempAlarm, tempWarn);
251 m_warnThr = (float) std::max(tempAlarm, tempWarn);
254 B2WARNING(
"DQMHistAnalysisKLM2Module: Found that alarmThr is greater than warnThr...");
275 name += std::to_string(bin % 8);
285 name += std::to_string(bin % 4);
290 for (
int layer = 0; layer <
m_eff_bklm->GetXaxis()->GetNbins(); layer++) {
292 if (layer / 15 < 8) {
297 name += std::to_string(
int(layer / 15) % 8) +
"_layer" + std::to_string(1 + (layer % 15));
300 for (
int layer = 0; layer <
m_eff_eklm->GetXaxis()->GetNbins(); layer++) {
303 name +=
"B" + std::to_string(layer / 8 + 1);
305 name +=
"F" + std::to_string(layer / 8 - 11);
306 name += +
"_num" + std::to_string(((layer) % 8) + 1);
315 TH1* effClone = (TH1*)effHist->Clone();
316 if (denominator !=
nullptr && numerator !=
nullptr) {
318 effHist->Divide(numerator, denominator, 1, 1,
"B");
324 auto deltaDenom =
getDelta(
"", denominator->GetName());
325 auto deltaNumer =
getDelta(
"", numerator->GetName());
328 UpdateCanvas(canvas->GetName(), (deltaNumer !=
nullptr && deltaDenom !=
nullptr));
329 if ((deltaNumer !=
nullptr) && (deltaDenom !=
nullptr)) {
330 effClone->Divide(deltaNumer, deltaDenom, 1, 1,
"B");
331 effClone->Draw(
"SAME");
340 const std::string& histName, TH1* histogram)
344 if (canvas == NULL) {
350 histogram->SetStats(
false);
352 double histMin = gPad->GetUymin();
353 double histMax = gPad->GetUymax();
354 double histRange = histMax - histMin;
355 if (histName.find(
"bklm") != std::string::npos) {
359 int bin = maximalLayer * sector + 1;
360 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
361 double xText = histogram->GetXaxis()->GetBinLowEdge(bin + maximalLayer / 2);
362 double yText = histMin + 0.98 * histRange;
364 m_PlaneLine.DrawLine(xLine, histMin, xLine, histMin + histRange);
370 name += std::to_string(sector % 8);
378 for (
int layerGlobal = 1; layerGlobal <= maximalLayer; ++layerGlobal) {
379 int bin = maxPlane * layerGlobal + 1;
380 double xLine = histogram->GetXaxis()->GetBinLowEdge(bin);
381 double xText = histogram->GetXaxis()->GetBinLowEdge(bin - maxPlane / 2);
382 double yText = histMin + 0.98 * histRange;
383 if (layerGlobal < maximalLayer)
384 m_PlaneLine.DrawLine(xLine, histMin, xLine, histMin + histRange);
387 layerGlobal, §ion, &layer);
392 name += std::to_string(layer);
402 TH1* mainHist, TH1* refHist, TH2* eff2dHist, TH2* errHist,
int layers,
int sectors,
bool ratioPlot,
403 int* pvcount,
double layerLimit, TCanvas* eff2dCanv)
411 float maxVal =
m_max;
412 float minVal =
m_min;
414 bool setAlarm =
false;
415 bool setWarn =
false;
418 for (
int binx = 0; binx < sectors; binx++) {
420 for (
int biny = 0; biny < layers; biny++) {
422 mainEff = mainHist->GetBinContent(i + 1);
423 mainErr = mainHist->GetBinError(i + 1);
425 refEff = refHist->GetBinContent(i + 1);
426 refErr = refHist->GetBinError(i + 1);
432 if ((mainEff == 0) and (refEff == 0)) {
434 eff2dHist->SetBinContent(binx + 1, biny + 1, 0);
435 }
else if (refEff == 0) {
437 eff2dHist->SetBinContent(binx + 1, biny + 1, maxVal);
438 }
else if (mainEff == 0) {
440 eff2dHist->SetBinContent(binx + 1, biny + 1, 0);
441 errHist->SetBinContent(binx + 1, biny + 1, 0);
445 eff2dVal = mainEff / refEff;
446 if (eff2dVal <
m_alarmThr) {errHist->SetBinContent(binx + 1, biny + 1, eff2dVal);}
448 eff2dVal = (mainEff - refEff) / pow(pow(mainErr, 2) + pow(refErr, 2), 0.5);
452 if ((eff2dVal > minVal) and (eff2dVal < maxVal)) {
454 eff2dHist->SetBinContent(binx + 1, biny + 1, eff2dVal);
455 }
else if (eff2dVal > maxVal) {
457 eff2dHist->SetBinContent(binx + 1, biny + 1, maxVal);
458 }
else if (eff2dVal < minVal) {
460 eff2dHist->SetBinContent(binx + 1, biny + 1, minVal);
478 if (*pvcount > (
int) layerLimit) {
482 eff2dHist->SetMinimum(
m_min);
483 eff2dHist->SetMaximum(
m_max);
486 eff2dHist->Draw(
"COLZ");
487 errHist->Draw(
"TEXT SAME");
489 eff2dCanv->Pad()->SetFillColor(kRed);
490 }
else if (setWarn) {
491 eff2dCanv->Pad()->SetFillColor(kYellow);
493 eff2dCanv->Modified();
500 TH1* daqInclusion =
findHist(
"KLM/daq_inclusion");
501 if (not(daqInclusion == NULL)) {
502 int isKlmIncluded = daqInclusion->GetBinContent(daqInclusion->GetXaxis()->FindBin(
"Yes"));
503 if (isKlmIncluded == 0)
523 if ((all_ext_bklm ==
nullptr || matched_hits_bklm ==
nullptr) && (
m_IsPhysicsRun)) {
524 B2INFO(
"Histograms needed for BKLM plane efficiency computation are not found");
527 if ((all_ext_eklm ==
nullptr || matched_hits_eklm ==
nullptr) && (
m_IsPhysicsRun)) {
528 B2INFO(
"Histograms needed for EKLM plane efficiency computation are not found");
530 if ((all_ext_bklm_sector ==
nullptr || matched_hits_bklm_sector ==
nullptr) && (
m_IsPhysicsRun)) {
531 B2INFO(
"Histograms needed for BKLM sector efficiency computation are not found");
533 if ((all_ext_eklm_sector ==
nullptr || matched_hits_eklm_sector ==
nullptr) && (
m_IsPhysicsRun)) {
534 B2INFO(
"Histograms needed for EKLM sector efficiency computation are not found");
558 B2DEBUG(20,
"Updating EPICS PVs in DQMHistAnalysisKLM2");
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
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.
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.
double m_minEvents
Minimal number of entries for delta histogram update.
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
TString m_RunTypeString
String with run type.
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.
TH1 * m_RunType
Histogram from DQMInfo with run type.
bool m_ratio
show efficiency ratio or difference
TH2 * m_err_eklm
EKLM efficiencies error histogram.
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.
int registerEpicsPV(std::string pvname, std::string keyname="", bool update_pvs=true)
EPICS related Functions.
void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
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.
void UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
static MonitoringObject * getMonitoringObject(const std::string &histname)
Get MonitoringObject with given name (new object is created if non-existing)
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
int updateEpicsPVs(float timeout)
Update all EPICS PV (flush to network)
static constexpr int getMaximalLayerGlobalNumber()
Get maximal detector layer global 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)
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Abstract base class for different kinds of events.