9#include <dqm/analysis/modules/DQMHistAnalysisSVDDose.h>
10#include <framework/utilities/Utils.h>
22DQMHistAnalysisSVDDoseModule::DQMHistAnalysisSVDDoseModule()
24 setDescription(
"Monitoring of SVD Dose with events from Poisson trigger w/o inj. veto. See also SVDDQMDoseModule.");
28 "Minimum interval between two successive PV updates (in seconds).", 1000.0);
29 addParam(
"pvSuffix",
m_pvSuffix,
"Suffix for EPICS PVs.", std::string(
":Occ:Pois:Avg"));
31 std::string(
"Occ:Pois:UpdateInterval"));
33 std::string(
"Occ:Pois:State"));
36DQMHistAnalysisSVDDoseModule::~DQMHistAnalysisSVDDoseModule()
42 B2DEBUG(18,
"DQMHistAnalysisSVDDose: initialize");
67 TCanvas* c =
new TCanvas(
"SVDDOSE/c_svd_instOccupancy_" + group.nameSuffix +
"_pois",
68 "Instantaneous occupancy (Pois. trig.) " + group.titleSuffix);
70 c =
new TCanvas(
"SVDDOSE/c_svd_occuLER_" + group.nameSuffix +
"_pois",
71 "Occupancy vs time since LER inj. (Pois. trig.) " + group.titleSuffix);
74 c =
new TCanvas(
"SVDDOSE/c_svd_occuHER_" + group.nameSuffix +
"_pois",
75 "Occupancy vs time since HER inj. (Pois. trig.) " + group.titleSuffix);
78 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuLER_" + group.nameSuffix +
"_pois",
79 "Occupancy vs time since LER inj. (Pois. trig.) " + group.titleSuffix);
82 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuHER_" + group.nameSuffix +
"_pois",
83 "Occupancy vs time since HER inj. (Pois. trig.) " + group.titleSuffix);
87 c =
new TCanvas(
"SVDDOSE/c_svd_instOccupancy_" + group.nameSuffix +
"_all",
88 "Instantaneous occupancy (all events) " + group.titleSuffix);
90 c =
new TCanvas(
"SVDDOSE/c_svd_occuLER_" + group.nameSuffix +
"_all",
91 "Occupancy vs time since LER inj. (all events) " + group.titleSuffix);
94 c =
new TCanvas(
"SVDDOSE/c_svd_occuHER_" + group.nameSuffix +
"_all",
95 "Occupancy vs time since HER inj. (all events) " + group.titleSuffix);
98 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuLER_" + group.nameSuffix +
"_all",
99 "Occupancy vs time since LER inj. (all events) " + group.titleSuffix);
102 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuHER_" + group.nameSuffix +
"_all",
103 "Occupancy vs time since HER inj. (all events) " + group.titleSuffix);
108 m_legend =
new TPaveText(0.53, 0.73, 0.68, 0.88,
"brNDC");
109 m_legend->AddText(
"LER inj."); ((TText*)
m_legend->GetListOfLines()->Last())->SetTextColor(kRed);
110 m_legend->AddText(
"HER inj."); ((TText*)
m_legend->GetListOfLines()->Last())->SetTextColor(kAzure);
111 m_legend->AddText(
"No inj."); ((TText*)
m_legend->GetListOfLines()->Last())->SetTextColor(kBlack);
119 NULL, NULL, 10, &m_myPVs[g].mychid),
"ca_create_channel");
122 NULL, NULL, 10, &m_timeSinceLastPVUpdateChan),
"ca_create_channel");
124 NULL, NULL, 10, &m_stateChan),
"ca_create_channel");
126 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
129 SEVCHK(ca_get(DBR_CTRL_ENUM, m_stateChan, &m_stateCtrl),
"ca_get");
130 B2DEBUG(19,
"State PV initialized (ca_get)" <<
LogVar(
"value", m_stateCtrl.value));
131 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
133 B2DEBUG(18,
"State PV failed to initialize, will retry in beginRun(), event() and endRun().");
136 m_lastPVUpdate = getClockSeconds();
146 B2DEBUG(19,
"beginRun: setting state PV to RUNNING");
147 m_stateCtrl.value = 1;
149 SEVCHK(ca_put(DBR_ENUM, m_stateChan, &m_stateCtrl.value),
"ca_put");
152 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
154 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
156 m_lastPVUpdate = getClockSeconds();
165 double timeSinceLastPVUpdate = getClockSeconds() - m_lastPVUpdate;
169 SEVCHK(ca_get(DBR_CTRL_ENUM, m_stateChan, &m_stateCtrl),
"ca_get");
172 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
174 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
177 if (m_timeSinceLastPVUpdateChan) {
178 SEVCHK(ca_put(DBR_DOUBLE, m_timeSinceLastPVUpdateChan, (
void*)&timeSinceLastPVUpdate),
"ca_put");
181 "ca_create_channel (reconnection)");
183 m_stateCtrl.value = 1;
185 SEVCHK(ca_put(DBR_ENUM, m_stateChan, &m_stateCtrl.value),
"ca_put");
188 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
193 double nHits = 0.0, nEvts = 0.0;
194 for (TString dir : {
"SVDDoseLERInjPois",
"SVDDoseHERInjPois",
"SVDDoseNoInjPois"}) {
195 auto hHits = findHistT<TH2F>(dir +
"/SVDHitsVsTime_" + group.nameSuffix);
196 auto hEvts = findHistT<TH2F>(dir +
"/SVDEvtsVsTime");
197 if (!hHits || !hEvts) {
198 B2WARNING(
"Histograms needed for Average Poisson Occupancy U-side not found.");
202 nHits += hHits->GetEntries();
203 nEvts += hEvts->GetEntries();
206 B2DEBUG(19,
"DQMHistAnalysisSVDDose: PV write"
207 <<
LogVar(
"group", group.nameSuffix.Data())
210 auto& pv = m_myPVs[g];
211 double delta_nHits = nHits - pv.lastNHits;
212 double delta_nEvts = nEvts - pv.lastNEvts;
213 double occ = delta_nEvts > 0.0 ? (delta_nHits / delta_nEvts * 100.0 / group.nStrips) : -1.0;
215 SEVCHK(ca_put(DBR_DOUBLE, pv.mychid, (
void*)&occ),
"ca_put");
218 NULL, NULL, 10, &m_myPVs[g].mychid),
"ca_create_channel (reconnection)");
220 pv.lastNEvts = nEvts;
221 pv.lastNHits = nHits;
225 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
226 m_lastPVUpdate = getClockSeconds();
235 B2DEBUG(18,
"DQMHistAnalysisSVDDose: endRun");
240 B2DEBUG(19,
"endRun: setting state PV to NOT RUNNING");
241 m_stateCtrl.value = 0;
243 SEVCHK(ca_put(DBR_ENUM, m_stateChan, &m_stateCtrl.value),
"ca_put");
246 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
248 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
250 for (
auto& pv : m_myPVs)
251 pv.lastNEvts = pv.lastNHits = 0.0;
258 double nHits = 0.0, nEvts = 0.0;
259 for (TString dir : {
"SVDDoseLERInjPois",
"SVDDoseHERInjPois",
"SVDDoseNoInjPois"}) {
260 auto hHits = findHistT<TH2F>(dir +
"/SVDHitsVsTime_" + group.nameSuffix);
261 auto hEvts = findHistT<TH2F>(dir +
"/SVDEvtsVsTime");
262 if (!hHits || !hEvts) {
263 B2WARNING(
"Histograms needed for Average Poisson Occupancy U-side not found.");
267 nHits += hHits->GetEntries();
268 nEvts += hEvts->GetEntries();
271 B2DEBUG(19,
"DQMHistAnalysisSVDDose: MonObj write"
272 <<
LogVar(
"group", group.nameSuffix.Data())
276 const double occ = nHits / nEvts * 100.0 / group.nStrips;
277 TString vName = group.nameSuffix +
"OccPoisAvg";
287 B2DEBUG(18,
"DQMHistAnalysisSVDDose: updating canvases");
293 auto hLER = findHistT<TH1F>(
"SVDDoseLERInjPois/SVDInstOccu_" + group.nameSuffix);
294 auto hHER = findHistT<TH1F>(
"SVDDoseHERInjPois/SVDInstOccu_" + group.nameSuffix);
295 auto hNo = findHistT<TH1F>(
"SVDDoseNoInjPois/SVDInstOccu_" + group.nameSuffix);
296 if (hLER && hHER && hNo) {
297 hLER->SetLineColor(kRed);
298 hHER->SetLineColor(kAzure);
299 hNo->SetLineColor(kBlack);
305 hNo->SetTitle(
"SVD instantaneous occu. " + group.titleSuffix +
" U-side Pois. trig.");
307 hLER->Draw(
"hist same");
308 hHER->Draw(
"hist same");
314 auto hHits = findHistT<TH2F>(
"SVDDoseLERInjPois/SVDHitsVsTime_" + group.nameSuffix);
315 auto hEvts = findHistT<TH2F>(
"SVDDoseLERInjPois/SVDEvtsVsTime");
316 if (hHits && hEvts) {
318 m_h_occuLER[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. Pois. trig."
319 ";Time since last injection [#mus];Time in beam cycle [#mus]"
325 c->SetRightMargin(0.16);
331 auto hpEvts = findHistT<TH1F>(
"SVDDoseLERInjPois/SVDEvtsVsTime1");
332 auto hpHits = findHistT<TH1F>(
"SVDDoseLERInjPois/SVDHitsVsTime1_" + group.nameSuffix);
333 if (hpHits && hpEvts) {
335 m_h_occuLER1[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. Pois. trig."
336 ";Time since last injection [#mus];Occupancy [%]");
347 hHits = findHistT<TH2F>(
"SVDDoseHERInjPois/SVDHitsVsTime_" + group.nameSuffix);
348 hEvts = findHistT<TH2F>(
"SVDDoseHERInjPois/SVDEvtsVsTime");
349 if (hHits && hEvts) {
351 m_h_occuHER[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. Pois. trig."
352 ";Time since last injection [#mus];Time in beam cycle [#mus]"
358 c->SetRightMargin(0.16);
364 hpEvts = findHistT<TH1F>(
"SVDDoseHERInjPois/SVDEvtsVsTime1");
365 hpHits = findHistT<TH1F>(
"SVDDoseHERInjPois/SVDHitsVsTime1_" + group.nameSuffix);
366 if (hpHits && hpEvts) {
368 m_h_occuHER1[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. Pois. trig."
369 ";Time since last injection [#mus];Occupancy [%]");
381 hLER = findHistT<TH1F>(
"SVDDoseLERInjAll/SVDInstOccu_" + group.nameSuffix);
382 hHER = findHistT<TH1F>(
"SVDDoseHERInjAll/SVDInstOccu_" + group.nameSuffix);
383 hNo = findHistT<TH1F>(
"SVDDoseNoInjAll/SVDInstOccu_" + group.nameSuffix);
384 if (hLER && hHER && hNo) {
385 hLER->SetLineColor(kRed);
386 hHER->SetLineColor(kAzure);
387 hNo->SetLineColor(kBlack);
393 hNo->SetTitle(
"SVD instantaneous occu. " + group.titleSuffix +
" U-side all events");
395 hLER->Draw(
"hist same");
396 hHER->Draw(
"hist same");
402 hHits = findHistT<TH2F>(
"SVDDoseLERInjAll/SVDHitsVsTime_" + group.nameSuffix);
403 hEvts = findHistT<TH2F>(
"SVDDoseLERInjAll/SVDEvtsVsTime");
404 if (hHits && hEvts) {
406 m_h_occuLERAll[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. all events"
407 ";Time since last injection [#mus];Time in beam cycle [#mus]"
413 c->SetRightMargin(0.16);
419 hpEvts = findHistT<TH1F>(
"SVDDoseLERInjAll/SVDEvtsVsTime1");
420 hpHits = findHistT<TH1F>(
"SVDDoseLERInjAll/SVDHitsVsTime1_" + group.nameSuffix);
421 if (hpHits && hpEvts) {
423 m_h_occuLER1All[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. all events"
424 ";Time since last injection [#mus];Occupancy [%]");
435 hHits = findHistT<TH2F>(
"SVDDoseHERInjAll/SVDHitsVsTime_" + group.nameSuffix);
436 hEvts = findHistT<TH2F>(
"SVDDoseHERInjAll/SVDEvtsVsTime");
437 if (hHits && hEvts) {
439 m_h_occuHERAll[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. all events"
440 ";Time since last injection [#mus];Time in beam cycle [#mus]"
446 c->SetRightMargin(0.16);
452 hpEvts = findHistT<TH1F>(
"SVDDoseHERInjAll/SVDEvtsVsTime1");
453 hpHits = findHistT<TH1F>(
"SVDDoseHERInjAll/SVDHitsVsTime1_" + group.nameSuffix);
454 if (hpHits && hpEvts) {
456 m_h_occuHER1All[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. all events"
457 ";Time since last injection [#mus];Occupancy [%]");
471 int i = h->GetNbinsX();
472 float t = h->GetBinContent(i) + h->GetBinContent(i + 1);
473 h->SetBinContent(i, t);
474 h->SetBinContent(i + 1, 0);
478 {
"L31XU",
"L3.1",
"L3:1", 768 * 2},
479 {
"L32XU",
"L3.2",
"L3:2", 768 * 2},
480 {
"L3XXU",
"L3 avg.",
"L3", 768 * 14},
481 {
"L4XXU",
"L4 avg.",
"L4", 768 * 30},
482 {
"L5XXU",
"L5 avg.",
"L5", 768 * 48},
483 {
"L6XXU",
"L6 avg.",
"L6", 768 * 80}
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
bool getUseEpics(void)
Getter for EPICS usage.
void initialize() override final
Initializer.
std::vector< TCanvas * > m_c_occuLER
Canvases for the occu.
std::vector< TH2F * > m_h_occuHERAll
Histograms for the occu.
std::vector< TH1F * > m_h_occuLER1
Histograms for the 1D occu.
std::string m_deltaTPVSuffix
Suffix of the update-time monitoring PV.
std::vector< TCanvas * > m_c_occuHERAll
Canvases for the occu.
std::vector< TCanvas * > m_c_instOccu
Canvases for the instantaneous occupancy.
std::vector< TH2F * > m_h_occuLER
Histograms for the occ.
double m_epicsUpdateSeconds
Minimum interval between successive PV updates.
std::vector< TH2F * > m_h_occuLERAll
Histograms for the occu.
std::vector< TCanvas * > m_c_occuLER1
Canvases for the 1D occu.
std::string m_pvPrefix
Prefix for EPICS PVs.
std::vector< TH1F * > m_h_occuHER1All
Histograms for the 1D occu.
MonitoringObject * m_monObj
Monitoring object for MiraBelle.
std::vector< TCanvas * > m_c_occuLER1All
Canvases for the 1D occu.
void event() override final
This method is called for each event.
std::string m_statePVSuffix
Suffix of the state PV.
std::vector< TCanvas * > m_c_occuLERAll
Canvases for the occu.
std::vector< TCanvas * > m_c_occuHER
Canvases for the occu.
std::vector< TCanvas * > m_c_occuHER1All
Canvases for the 1D occu.
static void carryOverflowOver(TH1F *h)
Carries the content of the overflow bin into the last bin.
static const std::vector< SensorGroup > c_sensorGroups
List of sensors groups.
std::vector< TH1F * > m_h_occuLER1All
Histograms for the 1D occu.
void endRun() override final
This method is called if the current run ends.
void updateCanvases()
updated canvas
void beginRun() override final
Called when entering a new run.
std::vector< TH1F * > m_h_occuHER1
Histograms for the 1D occu.
std::vector< TCanvas * > m_c_instOccuAll
Canvases for the instantaneous occupancy.
static T * divide(T *num, T *den, float scale=1.0f, T *res=nullptr)
Divide two histograms, ignoring errors on the second histogram.
TPaveText * m_legend
Legend of the inst.
std::vector< TCanvas * > m_c_occuHER1
Canvases for the 1D occu.
std::vector< TH2F * > m_h_occuHER
Histograms for the occu.
std::string m_pvSuffix
Suffix for EPICS PVs.
void setDescription(const std::string &description)
Sets the description of the module.
void setVariable(const std::string &var, float val, float upErr=-1., float dwErr=-1)
set value to float variable (new variable is made if not yet existing)
Class to store variables with their name which were sent to the logging service.
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.
double getClock()
Return current value of the real-time clock.
Abstract base class for different kinds of events.