10 #include <dqm/analysis/modules/DQMHistAnalysisIP.h>
32 addParam(
"HistoName", m_histoname,
"Name of Histogram (incl dir)", std::string(
""));
33 addParam(
"PVName", m_pvPrefix,
"PV Prefix", std::string(
"DQM:TEST:hist:"));
34 addParam(
"MonitorPrefix", m_monPrefix,
"Monitor Prefix");
35 addParam(
"useEpics", m_useEpics,
"useEpics",
true);
36 addParam(
"minEntries", m_minEntries,
"minimum number of new Entries for a fit", 1000);
37 B2DEBUG(20,
"DQMHistAnalysisIP: Constructor done.");
41 DQMHistAnalysisIPModule::~DQMHistAnalysisIPModule()
45 if (ca_current_context()) ca_context_destroy();
50 void DQMHistAnalysisIPModule::initialize()
52 B2DEBUG(20,
"DQMHistAnalysisIP: initialized.");
54 m_monObj = getMonitoringObject(
"ip");
58 m_c1 =
new TCanvas(a +
"_fit");
60 m_line =
new TLine(0, 10, 0, 0);
61 m_line->SetVertical(
true);
62 m_line->SetLineColor(8);
63 m_line->SetLineWidth(3);
65 m_monObj->addCanvas(m_c1);
70 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
72 aa = m_pvPrefix +
"Mean";
73 SEVCHK(ca_create_channel(aa.c_str(), NULL, NULL, 10, &mychid[0]),
"ca_create_channel failure");
74 aa = m_pvPrefix +
"RMS";
75 SEVCHK(ca_create_channel(aa.c_str(), NULL, NULL, 10, &mychid[1]),
"ca_create_channel failure");
78 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
84 void DQMHistAnalysisIPModule::beginRun()
87 B2DEBUG(20,
"DQMHistAnalysisIP: beginRun called.");
91 hh1 = findHist(m_histoname.c_str());
94 B2DEBUG(20,
"Histo " << m_histoname <<
" not in memfile");
96 TDirectory* d = gROOT;
97 TString myl = m_histoname;
100 while (myl.Tokenize(tok, from,
"/")) {
104 if (myl.Tokenize(dummy, f,
"/")) {
105 auto e = d->GetDirectory(tok);
107 B2DEBUG(20,
"Cd Dir " << tok);
115 TObject* obj = d->FindObject(tok);
117 if (obj->IsA()->InheritsFrom(
"TH1")) {
118 B2DEBUG(20,
"Histo " << m_histoname <<
" found in mem");
122 B2DEBUG(20,
"Histo " << m_histoname <<
" NOT found in mem");
131 B2DEBUG(20,
"Histo " << m_histoname <<
" not found");
134 if (m_h_last) m_h_last->Reset();
137 void DQMHistAnalysisIPModule::event()
142 hh1 = findHist(m_histoname.c_str());
144 B2DEBUG(20,
"Histo " << m_histoname <<
" not in memfile");
146 TDirectory* d = gROOT;
147 TString myl = m_histoname;
150 while (myl.Tokenize(tok, from,
"/")) {
154 if (myl.Tokenize(dummy, f,
"/")) {
155 auto e = d->GetDirectory(tok);
157 B2DEBUG(20,
"Cd Dir " << tok);
165 TObject* obj = d->FindObject(tok);
167 if (obj->IsA()->InheritsFrom(
"TH1")) {
168 B2DEBUG(20,
"Histo " << m_histoname <<
" found in mem");
173 B2DEBUG(20,
"Histo " << m_histoname <<
" NOT found in mem");
179 B2DEBUG(20,
"Initial Clone");
181 m_h_last = (TH1*)hh1->Clone();
182 m_h_last->SetName(TString(hh1->GetName()) +
"_last");
186 double last = m_h_last->GetEntries();
187 double current = hh1->GetEntries();
188 B2DEBUG(20,
"Entries: " << last <<
"," << current);
189 if (current - last >= m_minEntries) {
190 B2DEBUG(20,
"Update Delta & Fit");
192 TH1* delta = (TH1*)hh1->Clone();
193 delta->Add(m_h_last, -1.);
201 double x = delta->GetMean();
202 double w = delta->GetRMS();
203 double y1 = delta->GetMaximum();
204 double y2 = delta->GetMinimum();
205 B2DEBUG(20,
"Fit " << x <<
"," << w <<
"," << y1 <<
"," << y2);
206 m_line->SetY1(y1 + (y1 - y2) * 0.05);
209 delta->GetXaxis()->SetRangeUser(x - 3 * w, x + 3 * w);
217 m_monObj->setVariable(m_monPrefix +
"_mean", x);
218 m_monObj->setVariable(m_monPrefix +
"_width", w);
222 B2INFO(
"Update EPICS");
223 if (mychid[0]) SEVCHK(ca_put(DBR_DOUBLE, mychid[0], (
void*)&x),
"ca_set failure");
224 if (mychid[1]) SEVCHK(ca_put(DBR_DOUBLE, mychid[1], (
void*)&w),
"ca_set failure");
225 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
230 B2DEBUG(20,
"Histo " << m_histoname <<
" not found");
235 void DQMHistAnalysisIPModule::terminate()
240 if (m_parameters > 0) {
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");
248 B2DEBUG(20,
"DQMHistAnalysisIP: terminate called");