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,
"useEpics",
true);
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);
69 m_monObj->addCanvas(m_c1);
74 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
76 aa = m_pvPrefix +
"Mean";
77 SEVCHK(ca_create_channel(aa.c_str(), NULL, NULL, 10, &mychid[0]),
"ca_create_channel failure");
78 aa = m_pvPrefix +
"RMS";
79 SEVCHK(ca_create_channel(aa.c_str(), NULL, NULL, 10, &mychid[1]),
"ca_create_channel failure");
82 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
88 void DQMHistAnalysisIPModule::beginRun()
91 B2DEBUG(20,
"DQMHistAnalysisIP: beginRun called.");
95 hh1 = findHist(m_histoname.c_str());
98 B2DEBUG(20,
"Histo " << m_histoname <<
" not in memfile");
99 TDirectory* d = gROOT;
100 TString myl = m_histoname;
103 while (myl.Tokenize(tok, from,
"/")) {
107 if (myl.Tokenize(dummy, f,
"/")) {
108 auto e = d->GetDirectory(tok);
110 B2DEBUG(20,
"Cd Dir " << tok);
118 TObject* obj = d->FindObject(tok);
120 if (obj->IsA()->InheritsFrom(
"TH1")) {
121 B2DEBUG(20,
"Histo " << m_histoname <<
" found in mem");
125 B2DEBUG(20,
"Histo " << m_histoname <<
" NOT found in mem");
134 B2DEBUG(20,
"Histo " << m_histoname <<
" not found");
137 if (m_h_last) m_h_last->Reset();
140 void DQMHistAnalysisIPModule::event()
145 hh1 = findHist(m_histoname.c_str());
147 B2DEBUG(20,
"Histo " << m_histoname <<
" not in memfile");
148 TDirectory* d = gROOT;
149 TString myl = m_histoname;
152 while (myl.Tokenize(tok, from,
"/")) {
156 if (myl.Tokenize(dummy, f,
"/")) {
157 auto e = d->GetDirectory(tok);
159 B2DEBUG(20,
"Cd Dir " << tok);
167 TObject* obj = d->FindObject(tok);
169 if (obj->IsA()->InheritsFrom(
"TH1")) {
170 B2DEBUG(20,
"Histo " << m_histoname <<
" found in mem");
175 B2DEBUG(20,
"Histo " << m_histoname <<
" NOT found in mem");
181 B2DEBUG(20,
"Initial Clone");
183 m_h_last = (TH1*)hh1->Clone();
184 m_h_last->SetName(TString(hh1->GetName()) +
"_last");
188 double last = m_h_last->GetEntries();
189 double current = hh1->GetEntries();
190 B2DEBUG(20,
"Entries: " << last <<
"," << current);
191 if (current - last >= m_minEntries) {
192 B2DEBUG(20,
"Update Delta & Fit");
194 TH1* delta = (TH1*)hh1->Clone();
195 delta->Add(m_h_last, -1.);
203 double x = delta->GetMean();
204 double w = delta->GetRMS();
205 double y1 = delta->GetMaximum();
206 double y2 = delta->GetMinimum();
207 B2DEBUG(20,
"Fit " << x <<
"," << w <<
"," << y1 <<
"," << y2);
208 m_line->SetY1(y1 + (y1 - y2) * 0.05);
211 delta->GetXaxis()->SetRangeUser(x - 3 * w, x + 3 * w);
219 m_monObj->setVariable(m_monPrefix +
"_mean", x);
220 m_monObj->setVariable(m_monPrefix +
"_width", w);
224 B2INFO(
"Update EPICS");
225 if (mychid[0]) SEVCHK(ca_put(DBR_DOUBLE, mychid[0], (
void*)&x),
"ca_set failure");
226 if (mychid[1]) SEVCHK(ca_put(DBR_DOUBLE, mychid[1], (
void*)&w),
"ca_set failure");
227 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
232 B2DEBUG(20,
"Histo " << m_histoname <<
" not found");
237 void DQMHistAnalysisIPModule::terminate()
241 for (
auto i = 0; i < m_parameters; i++) {
242 if (mychid[i]) SEVCHK(ca_clear_channel(mychid[i]),
"ca_clear_channel failure");
244 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
247 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.