14 #include <dqm/analysis/modules/DQMHistAnalysisIP.h>
36 addParam(
"HistoName", m_histoname,
"Name of Histogram (incl dir)", std::string(
""));
37 addParam(
"PVName", m_pvPrefix,
"PV Prefix", std::string(
"DQM:TEST:hist:"));
38 addParam(
"MonitorPrefix", m_monPrefix,
"Monitor Prefix");
39 addParam(
"useEpics", m_useEpics,
"Whether to update EPICS PVs.",
false);
40 addParam(
"minEntries", m_minEntries,
"minimum number of new Entries for a fit", 1000);
41 B2DEBUG(20,
"DQMHistAnalysisIP: Constructor done.");
45 DQMHistAnalysisIPModule::~DQMHistAnalysisIPModule()
49 if (ca_current_context()) ca_context_destroy();
54 void DQMHistAnalysisIPModule::initialize()
56 B2DEBUG(20,
"DQMHistAnalysisIP: initialized.");
58 m_monObj = getMonitoringObject(
"ip");
62 m_c1 =
new TCanvas(a +
"_fit");
64 m_line =
new TLine(0, 10, 0, 0);
65 m_line->SetVertical(
true);
66 m_line->SetLineColor(8);
67 m_line->SetLineWidth(3);
68 m_line2 =
new TLine(0, 10, 0, 0);
69 m_line2->SetVertical(
true);
70 m_line2->SetLineColor(9);
71 m_line2->SetLineWidth(3);
73 m_monObj->addCanvas(m_c1);
78 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
80 aa = m_pvPrefix +
"Mean";
81 SEVCHK(ca_create_channel(aa.c_str(), NULL, NULL, 10, &mychid[0]),
"ca_create_channel failure");
82 aa = m_pvPrefix +
"RMS";
83 SEVCHK(ca_create_channel(aa.c_str(), NULL, NULL, 10, &mychid[1]),
"ca_create_channel failure");
84 aa = m_pvPrefix +
"Median";
85 SEVCHK(ca_create_channel(aa.c_str(), NULL, NULL, 10, &mychid[2]),
"ca_create_channel failure");
88 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
94 void DQMHistAnalysisIPModule::beginRun()
97 B2DEBUG(20,
"DQMHistAnalysisIP: beginRun called.");
101 hh1 = findHist(m_histoname.c_str());
104 B2DEBUG(20,
"Histo " << m_histoname <<
" not in memfile");
105 TDirectory* d = gROOT;
106 TString myl = m_histoname;
109 while (myl.Tokenize(tok, from,
"/")) {
113 if (myl.Tokenize(dummy, f,
"/")) {
114 auto e = d->GetDirectory(tok);
116 B2DEBUG(20,
"Cd Dir " << tok);
124 TObject* obj = d->FindObject(tok);
126 if (obj->IsA()->InheritsFrom(
"TH1")) {
127 B2DEBUG(20,
"Histo " << m_histoname <<
" found in mem");
131 B2DEBUG(20,
"Histo " << m_histoname <<
" NOT found in mem");
141 B2DEBUG(20,
"Histo " << m_histoname <<
" not found");
144 if (m_h_last) m_h_last->Reset();
147 void DQMHistAnalysisIPModule::event()
152 hh1 = findHist(m_histoname.c_str());
154 B2DEBUG(20,
"Histo " << m_histoname <<
" not in memfile");
155 TDirectory* d = gROOT;
156 TString myl = m_histoname;
159 while (myl.Tokenize(tok, from,
"/")) {
163 if (myl.Tokenize(dummy, f,
"/")) {
164 auto e = d->GetDirectory(tok);
166 B2DEBUG(20,
"Cd Dir " << tok);
174 TObject* obj = d->FindObject(tok);
176 if (obj->IsA()->InheritsFrom(
"TH1")) {
177 B2DEBUG(20,
"Histo " << m_histoname <<
" found in mem");
182 B2DEBUG(20,
"Histo " << m_histoname <<
" NOT found in mem");
188 B2DEBUG(20,
"Initial Clone");
190 m_h_last = (TH1*)hh1->Clone();
191 m_h_last->SetName(TString(hh1->GetName()) +
"_last");
195 double last = m_h_last->GetEntries();
196 double current = hh1->GetEntries();
197 B2DEBUG(20,
"Entries: " << last <<
"," << current);
198 if (current - last >= m_minEntries) {
199 B2DEBUG(20,
"Update Delta & Fit");
201 TH1* delta = (TH1*)hh1->Clone();
202 delta->Add(m_h_last, -1.);
211 double x = delta->GetMean();
212 double w = delta->GetRMS();
215 delta->ComputeIntegral();
216 delta->GetQuantiles(1, &m, &q);
217 double y1 = delta->GetMaximum();
218 double y2 = delta->GetMinimum();
219 B2DEBUG(20,
"Fit " << x <<
"," << w <<
"," << y1 <<
"," << y2);
220 m_line->SetY1(y1 + (y1 - y2) * 0.05);
223 m_line2->SetY1(y1 + (y1 - y2) * 0.05);
226 delta->GetXaxis()->SetRangeUser(x - 3 * w, x + 3 * w);
235 m_monObj->setVariable(m_monPrefix +
"_median", m);
236 m_monObj->setVariable(m_monPrefix +
"_mean", x);
237 m_monObj->setVariable(m_monPrefix +
"_width", w);
241 B2INFO(
"Update EPICS");
242 if (mychid[0]) SEVCHK(ca_put(DBR_DOUBLE, mychid[0], (
void*)&x),
"ca_set failure");
243 if (mychid[1]) SEVCHK(ca_put(DBR_DOUBLE, mychid[1], (
void*)&w),
"ca_set failure");
244 if (mychid[2]) SEVCHK(ca_put(DBR_DOUBLE, mychid[2], (
void*)&m),
"ca_set failure");
245 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
250 B2DEBUG(20,
"Histo " << m_histoname <<
" not found");
255 void DQMHistAnalysisIPModule::terminate()
259 for (
auto i = 0; i < m_parameters; i++) {
260 if (mychid[i]) SEVCHK(ca_clear_channel(mychid[i]),
"ca_clear_channel failure");
262 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
265 B2DEBUG(20,
"DQMHistAnalysisIP: terminate called");
Class definition for the output module of Sequential ROOT I/O.
The base class for the histogram analysis module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.