Belle II Software development
DQMHistDeltaHisto.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8//+
9// File : DQMHistDeltaHisto.cc
10// Description : DQM Histogram analysis module to generate delta histograms
11//-
12
13
14#include <framework/core/ModuleParam.templateDetails.h>
15#include <dqm/analysis/modules/DQMHistDeltaHisto.h>
16#include <TROOT.h>
17#include <TClass.h>
18
19using namespace std;
20using namespace Belle2;
21
22//-----------------------------------------------------------------
23// Register the Module
24//-----------------------------------------------------------------
25REG_MODULE(DQMHistDeltaHisto);
26
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
30
33{
34 addParam("Interval", m_interval, "Interval time for diff histos [s]", 180);
35 addParam("MonitoredHistos", m_monitoredHistos, "List of histograms to monitor", vector<string>());
36 B2DEBUG(20, "DQMHistDeltaHisto: Constructor done.");
37}
38
40{
41 gROOT->cd();
42 B2DEBUG(20, "DQMHistDeltaHisto: initialized.");
43 for (auto& histoname : m_monitoredHistos) {
44 queue<SSNODE*> hq;
45 m_histosQueues[histoname] = hq;
46 }
47 m_evtMetaDataPtr.isRequired();
48}
49
50
52{
53 B2DEBUG(20, "DQMHistDeltaHisto: beginRun called.");
54 for (auto& histoname : m_monitoredHistos) {
55 queue<SSNODE*>& hq = m_histosQueues[histoname];
56 while (!hq.empty()) {
57 SSNODE* nn = hq.front();
58 clear_node(nn);
59 delete nn;
60 hq.pop();
61 }
62 }
63}
64
66{
67 delete n->histo;
68 delete n->diff_histo;
69}
70
72{
73
74 B2DEBUG(20, "DQMHistDeltaHisto: event called.");
75 if (!m_evtMetaDataPtr.isValid()) {
76 B2ERROR("No valid EventMetaData.");
77 return;
78 }
79 time_t cur_mtime = m_evtMetaDataPtr->getTime();
80
81 for (auto& histoname : m_monitoredHistos) {
82 auto hh = findHist(histoname.c_str());
83 if (hh == nullptr) continue;
84 if (hh->GetDimension() != 1) continue;
85 queue<SSNODE*>& hq = m_histosQueues[histoname];
86 if (hq.empty()) {
87 SSNODE* n = new SSNODE;
88 n->histo = (TH1*)hh->Clone();
89 n->diff_histo = (TH1*)hh->Clone();
90 n->time_modified = cur_mtime;
91 hq.push(n);
92 } else {
93 while (!hq.empty()) {
94 SSNODE* nn = hq.front();
95 if ((cur_mtime - nn->time_modified < m_interval) || (hq.size() == 1)) {
96 if (hq.back()->time_modified == cur_mtime) {
97 break;
98 }
99 SSNODE* n = new SSNODE;
100 n->histo = (TH1*)hh->Clone();
101 n->diff_histo = (TH1*)hh->Clone();
102 n->diff_histo->Add(nn->histo, -1);
103 n->time_modified = cur_mtime;
104 hq.push(n);
105 break;
106 } else {
107 clear_node(nn);
108 delete nn;
109 hq.pop();
110 }
111 }
112 }
113 auto s = StringSplit(histoname, '/');
114 auto dirname = s.at(0);
115 auto hname = s.at(1);
116 std::string canvas_name = dirname + "/c_" + hname;
117 TCanvas* c = findCanvas(canvas_name);
118 if (c == nullptr) continue;
119 TH1* h_diff = hq.back()->diff_histo;
120 h_diff->SetName((histoname + "_diff").data());
121 if (h_diff->Integral() != 0) h_diff->Scale(hh->Integral() / h_diff->Integral());
122 c->cd();
123 h_diff->SetLineColor(kRed);
124 h_diff->SetLineStyle(kDotted);
125 h_diff->SetStats(kFALSE);
126 h_diff->Draw("hist,same");
127 c->Modified();
128 c->Update();
129 }
130
131}
132
134{
135 B2DEBUG(20, "DQMHistDeltaHisto: endRun called");
136}
137
138
140{
141 B2DEBUG(20, "DQMHistDeltaHisto: terminate called");
142}
static TCanvas * findCanvas(TString cname)
Find canvas by name.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
static std::vector< std::string > StringSplit(const std::string &s, const char delim)
Helper function for string token split.
DQMHistAnalysisModule()
Constructor / Destructor.
void initialize() override final
Initializer.
StoreObjPtr< EventMetaData > m_evtMetaDataPtr
The metadata for each event.
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.
void clear_node(SSNODE *n)
Clear content of SSNODE.
void endRun() override final
This method is called if the current run ends.
int m_interval
Interval between checks in second.
std::map< std::string, std::queue< SSNODE * > > m_histosQueues
Map of histogram names to queues of monitoring objects.
void beginRun() override final
Called when entering a new run.
std::vector< std::string > m_monitoredHistos
Names of the histograms that should be monitored.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.
STL namespace.