10#include <dqm/analysis/modules/DQMHistAnalysisKLMMonObj.h>
30 setDescription(
"Module to add Monitoring Variables for KLM on Mirabelle");
34 std::string(
"DetectorOccupancies_before_filter"));
35 addParam(
"lookbackWindow",
m_lookbackWindow,
"Lookback window in seconds for hit rate calculation (default: 10.4 microseconds)",
64 B2DEBUG(20,
"DQMHistAnalysisKLMMonObj: event called.");
68 Double_t layerArea, Double_t& hitRate, Double_t& hitRateErr)
70 if (!hist || hist->GetDimension() != 2 || layer <= 0 || layerArea <= 0 || totalEvents <= 0) {
71 B2ERROR(
"CalculateKLMHitRate: Invalid input parameters.");
79 Double_t numDigits = 0.0;
81 int nBinsX = hist->GetNbinsX();
82 int nBinsY = hist->GetNbinsY();
85 if (layer > 0 && layer <= nBinsX) {
86 for (
int binY = 1; binY <= nBinsY; binY++) {
87 Double_t binContent = hist->GetBinContent(layer, binY);
88 numDigits += binContent;
91 B2ERROR(
"CalculateKLMHitRate: Layer number out of range.");
100 if (denominator > 0 && numDigits > 0) {
101 hitRate = numDigits / denominator;
104 Double_t relErr =
sqrt(1.0 / numDigits + 1.0 / totalEvents);
107 hitRateErr = hitRate * relErr;
121 std::string histPrefix =
"/bklm_plane_trg_occupancy";
123 for (
size_t i = 0; i < 2; i++) {
127 auto* background_trigger_count =
findHist(
"KLM/event_background_trigger_summary");
128 if (not background_trigger_count) {
129 B2ERROR(
"Cannot find histogram: KLM/event_background_trigger_summary");
133 Double_t totalEventsTrg = background_trigger_count->GetBinContent(1);
134 std::string prefix =
"KLM_";
135 std::string suffix =
"hitRate";
137 for (
size_t i = 0; i < 2; i++) {
138 if (not bklm_trg[i]) {
142 for (
int layerGlobal = 0; layerGlobal < 240; layerGlobal++) {
143 int section, sector, layer;
145 layerGlobal, §ion, §or, &layer);
146 Double_t layerAreaTrg =
m_bklmGeoPar->getBKLMLayerArea(section, sector, layer);
147 Double_t hitRate, hitRateErr;
148 CalculateKLMHitRate(bklm_trg[i], layer, totalEventsTrg, layerAreaTrg, hitRate, hitRateErr);
150 std::string varName = prefix +
"B";
151 varName += (section == 0) ?
"B" :
"F";
153 varName +=
"_layer" + std::to_string(layer) +
"_trg_" + suffix +
"_" +
m_tag[i];
154 m_klmMonObj->setVariable(varName, hitRate, hitRateErr);
static constexpr int getMaximalSectorNumber()
Get maximal sector number (1-based).
void initialize() override final
Initializer.
const bklm::GeometryPar * m_bklmGeoPar
BKLM Geometry data.
Double_t m_lookbackWindow
Lookback window in seconds for hit rate calculation (default: 10.4 microseconds)
bool m_IsPhysicsRun
Run type flag for physics runs.
const BKLMElementNumbers * m_BklmElementNumbers
BKLM element numbers.
DQMHistAnalysisKLMMonObjModule()
Constructor.
void event() override final
This method is called for each event.
std::string m_histogramDirectoryName
Name of histogram directory.
void CalculateKLMHitRate(auto *hist, int layer, Double_t totalEvents, Double_t layerArea, Double_t &hitRate, Double_t &hitRateErr)
Calculate KLM hit rate for a specific layer from 2D histogram.
~DQMHistAnalysisKLMMonObjModule()
Destructor.
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_IsNullRun
Run type flag for null runs.
const std::string m_tag[2]
Tag suffix based on injection veto.
MonitoringObject * m_klmMonObj
KLM Monitoring object.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
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 list of the reference histograms.
DQMHistAnalysisModule()
Constructor / Destructor.
void setDescription(const std::string &description)
Sets the description of the module.
static GeometryPar * instance(void)
Static method to get a reference to the singleton GeometryPar instance.
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.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.