14#include <framework/core/ModuleParam.templateDetails.h>
15#include <dqm/analysis/modules/DQMHistComparitor.h>
19#include <TDirectory.h>
40 addParam(
"HistoList",
m_histlist,
"['histname', 'refhistname', 'canvas', 'minentry', 'warnlvl', 'errlvl', 'pvname'],[...],...");
41 addParam(
"RefHistoFile",
m_refFileName,
"Reference histrogram file name", std::string(
"refHisto.root"));
42 addParam(
"ColorAlert",
m_color,
"Whether to show the color alert",
true);
43 B2DEBUG(1,
"DQMHistComparitor: Constructor done.");
49 if (ca_current_context()) ca_context_destroy();
59 B2DEBUG(20,
"findHist failed " << histoname <<
" not in memfile");
64 TString myl = histoname;
68 while (myl.Tokenize(tok, from,
"/")) {
72 if (myl.Tokenize(dummy, f,
"/")) {
73 auto e = d->GetDirectory(tok);
75 B2DEBUG(20,
"Cd Dir " << tok <<
" from " << d->GetPath());
78 B2DEBUG(20,
"cd failed " << tok <<
" from " << d->GetPath());
84 TObject* obj = d->FindObject(tok);
86 if (obj->IsA()->InheritsFrom(
"TH1")) {
87 B2DEBUG(20,
"Histo " << histoname <<
" found in ref file");
90 B2DEBUG(20,
"Histo " << histoname <<
" found in ref file but wrong type");
94 TIter next(d->GetListOfKeys());
96 while ((key = (TKey*)next())) {
97 TObject* obj2 = key->ReadObj() ;
98 if (obj2->InheritsFrom(
"TH1")) {
99 if (obj2->GetName() == tok) {
101 B2DEBUG(20,
"Histo " << histoname <<
" found as key -> readobj");
106 if (hh1 == NULL) B2DEBUG(20,
"Histo " << histoname <<
" NOT found in ref file " << tok);
111 B2DEBUG(20,
"Histo " << histoname <<
" not in memfile or ref file");
113 TDirectory* d = gROOT;
114 TString myl = histoname;
117 while (myl.Tokenize(tok, from,
"/")) {
121 if (myl.Tokenize(dummy, f,
"/")) {
122 auto e = d->GetDirectory(tok);
124 B2DEBUG(20,
"Cd Dir " << tok);
126 }
else B2DEBUG(20,
"cd failed " << tok);
132 TObject* obj = d->FindObject(tok);
134 if (obj->IsA()->InheritsFrom(
"TH1")) {
135 B2DEBUG(20,
"Histo " << histoname <<
" found in mem");
139 B2DEBUG(20,
"Histo " << histoname <<
" NOT found in mem");
145 B2DEBUG(20,
"Histo " << histoname <<
" not found");
158 gStyle->SetOptStat(0);
159 gStyle->SetStatStyle(1);
160 gStyle->SetOptDate(22);
163 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
166 if (it.size() != 7) {
167 B2WARNING(
"Histolist with wrong nr of parameters (" << it.size() <<
"), hist1=" << it.at(0));
173 TString a = it.at(2).c_str();
176 n->histo1 = it.at(0);
177 n->histo2 = it.at(1);
178 TCanvas* c =
new TCanvas(a);
181 n->min_entries = atoi(it.at(3).c_str());
182 n->warning = atof(it.at(4).c_str());
183 n->error = atof(it.at(5).c_str());
184 n->epicsflag =
false;
187 if (it.at(6) !=
"") {
188 SEVCHK(ca_create_channel(it.at(6).c_str(), NULL, NULL, 10, &n->mychid),
"ca_create_channel failure");
195 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
198 B2DEBUG(20,
"DQMHistComparitor: initialized.");
204 B2DEBUG(20,
"DQMHistComparitor: beginRun called.");
213 B2DEBUG(20,
"== Search for " << it->histo1 <<
" with ref " << it->histo2 <<
"==");
215 if (!hist1) B2DEBUG(20,
"NOT Found " << it->histo1);
217 if (!hist2) B2DEBUG(20,
"NOT Found " << it->histo2);
219 if (!hist1)
continue;
220 if (!hist2)
continue;
222 B2DEBUG(20,
"Compare " << it->histo1 <<
" with ref " << it->histo2);
226 double data = hist1->KolmogorovTest(hist2,
"");
231 if (it->epicsflag) SEVCHK(ca_put(DBR_DOUBLE, it->mychid, (
void*)&data),
"ca_set failure");
234 hist2->SetLineStyle(3);
235 hist2->SetLineColor(3);
237 TIter nextkey(it->canvas->GetListOfPrimitives());
239 while ((obj = (TObject*)nextkey())) {
240 if (obj->IsA()->InheritsFrom(
"TH1")) {
241 if (
string(obj->GetName()) ==
string(hist2->GetName())) {
250 h = (TH1*)hist2->Clone();
251 if (abs(hist2->Integral()) > 0)
252 h->Scale(hist1->Integral() / hist2->Integral());
259 hist1->SetFillColor(0);
260 if (h->GetMaximum() > hist1->GetMaximum())
261 hist1->SetMaximum(1.1 * h->GetMaximum());
263 h->Draw(
"hist,same");
265 it->canvas->Pad()->SetFrameFillColor(10);
267 if (hist1->GetEntries() < it->min_entries) {
269 it->canvas->Pad()->SetFillColor(6);
271 if (data < it->error) {
272 it->canvas->Pad()->SetFillColor(2);
273 }
else if (data < it->warning) {
274 it->canvas->Pad()->SetFillColor(5);
276 it->canvas->Pad()->SetFillColor(0);
280 it->canvas->Pad()->SetFillColor(0);
282 it->canvas->Modified();
283 it->canvas->Update();
286 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
292 B2DEBUG(20,
"DQMHistComparitor: endRun called");
298 B2DEBUG(20,
"DQMHistComparitor: terminate called");
The base class for the histogram analysis module.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
TH1 * findHistInCanvas(const std::string &hname, TCanvas **canvas=nullptr)
Find histogram in corresponding canvas.
std::string m_refFileName
Reference Histogram Root file name.
bool m_color
Whether to use the color code for warnings and errors.
void initialize() override final
Initializer.
~DQMHistComparitorModule()
Destructor.
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.
TH1 * GetHisto(TString histoname)
Get histogram by its name.
void endRun() override final
This method is called if the current run ends.
std::vector< std::vector< std::string > > m_histlist
Parameter list for histograms.
void beginRun() override final
Called when entering a new run.
DQMHistComparitorModule()
Constructor.
std::vector< CMPNODE * > m_pnode
Struct for extracted parameters + EPICS PV.
TFile * m_refFile
The pointer to the reference file.
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.
The struct for reference histogram comparison.