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"));
38 B2DEBUG(18,
"DQMHistAnalysisSVDDose: initialize");
63 TCanvas* c =
new TCanvas(
"SVDDOSE/c_svd_instOccupancy_" + group.nameSuffix +
"_pois",
64 "Instantaneous occupancy (Pois. trig.) " + group.titleSuffix);
66 c =
new TCanvas(
"SVDDOSE/c_svd_occuLER_" + group.nameSuffix +
"_pois",
67 "Occupancy vs time since LER inj. (Pois. trig.) " + group.titleSuffix);
70 c =
new TCanvas(
"SVDDOSE/c_svd_occuHER_" + group.nameSuffix +
"_pois",
71 "Occupancy vs time since HER inj. (Pois. trig.) " + group.titleSuffix);
74 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuLER_" + group.nameSuffix +
"_pois",
75 "Occupancy vs time since LER inj. (Pois. trig.) " + group.titleSuffix);
78 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuHER_" + group.nameSuffix +
"_pois",
79 "Occupancy vs time since HER inj. (Pois. trig.) " + group.titleSuffix);
83 c =
new TCanvas(
"SVDDOSE/c_svd_instOccupancy_" + group.nameSuffix +
"_all",
84 "Instantaneous occupancy (all events) " + group.titleSuffix);
86 c =
new TCanvas(
"SVDDOSE/c_svd_occuLER_" + group.nameSuffix +
"_all",
87 "Occupancy vs time since LER inj. (all events) " + group.titleSuffix);
90 c =
new TCanvas(
"SVDDOSE/c_svd_occuHER_" + group.nameSuffix +
"_all",
91 "Occupancy vs time since HER inj. (all events) " + group.titleSuffix);
94 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuLER_" + group.nameSuffix +
"_all",
95 "Occupancy vs time since LER inj. (all events) " + group.titleSuffix);
98 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuHER_" + group.nameSuffix +
"_all",
99 "Occupancy vs time since HER inj. (all events) " + group.titleSuffix);
104 m_legend =
new TPaveText(0.53, 0.73, 0.68, 0.88,
"brNDC");
105 m_legend->AddText(
"LER inj."); ((TText*)
m_legend->GetListOfLines()->Last())->SetTextColor(kRed);
106 m_legend->AddText(
"HER inj."); ((TText*)
m_legend->GetListOfLines()->Last())->SetTextColor(kAzure);
107 m_legend->AddText(
"No inj."); ((TText*)
m_legend->GetListOfLines()->Last())->SetTextColor(kBlack);
115 NULL, NULL, 10, &m_myPVs[g].mychid),
"ca_create_channel");
118 NULL, NULL, 10, &m_timeSinceLastPVUpdateChan),
"ca_create_channel");
120 NULL, NULL, 10, &m_stateChan),
"ca_create_channel");
122 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
125 SEVCHK(ca_get(DBR_CTRL_ENUM, m_stateChan, &m_stateCtrl),
"ca_get");
126 B2DEBUG(19,
"State PV initialized (ca_get)" <<
LogVar(
"value", m_stateCtrl.value));
127 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
129 B2DEBUG(18,
"State PV failed to initialize, will retry in beginRun(), event() and endRun().");
132 m_lastPVUpdate = getClockSeconds();
142 B2DEBUG(19,
"beginRun: setting state PV to RUNNING");
143 m_stateCtrl.value = 1;
145 SEVCHK(ca_put(DBR_ENUM, m_stateChan, &m_stateCtrl.value),
"ca_put");
148 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
150 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
152 m_lastPVUpdate = getClockSeconds();
161 double timeSinceLastPVUpdate = getClockSeconds() - m_lastPVUpdate;
165 SEVCHK(ca_get(DBR_CTRL_ENUM, m_stateChan, &m_stateCtrl),
"ca_get");
168 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
170 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
173 if (m_timeSinceLastPVUpdateChan) {
174 SEVCHK(ca_put(DBR_DOUBLE, m_timeSinceLastPVUpdateChan, (
void*)&timeSinceLastPVUpdate),
"ca_put");
177 "ca_create_channel (reconnection)");
179 m_stateCtrl.value = 1;
181 SEVCHK(ca_put(DBR_ENUM, m_stateChan, &m_stateCtrl.value),
"ca_put");
184 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
189 double nHits = 0.0, nEvts = 0.0;
190 for (TString dir : {
"SVDDoseLERInjPois",
"SVDDoseHERInjPois",
"SVDDoseNoInjPois"}) {
191 auto hHits =
findHistT<TH2F>(dir +
"/SVDHitsVsTime_" + group.nameSuffix);
193 if (!hHits || !hEvts) {
194 B2WARNING(
"Histograms needed for Average Poisson Occupancy U-side not found.");
198 nHits += hHits->GetEntries();
199 nEvts += hEvts->GetEntries();
202 B2DEBUG(19,
"DQMHistAnalysisSVDDose: PV write"
203 <<
LogVar(
"group", group.nameSuffix.Data())
206 auto& pv = m_myPVs[g];
207 double delta_nHits = nHits - pv.lastNHits;
208 double delta_nEvts = nEvts - pv.lastNEvts;
209 double occ = delta_nEvts > 0.0 ? (delta_nHits / delta_nEvts * 100.0 / group.nStrips) : -1.0;
211 SEVCHK(ca_put(DBR_DOUBLE, pv.mychid, (
void*)&occ),
"ca_put");
214 NULL, NULL, 10, &m_myPVs[g].mychid),
"ca_create_channel (reconnection)");
216 pv.lastNEvts = nEvts;
217 pv.lastNHits = nHits;
221 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
222 m_lastPVUpdate = getClockSeconds();
231 B2DEBUG(18,
"DQMHistAnalysisSVDDose: endRun");
236 B2DEBUG(19,
"endRun: setting state PV to NOT RUNNING");
237 m_stateCtrl.value = 0;
239 SEVCHK(ca_put(DBR_ENUM, m_stateChan, &m_stateCtrl.value),
"ca_put");
242 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
244 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
246 for (
auto& pv : m_myPVs)
247 pv.lastNEvts = pv.lastNHits = 0.0;
254 double nHits = 0.0, nEvts = 0.0;
255 for (TString dir : {
"SVDDoseLERInjPois",
"SVDDoseHERInjPois",
"SVDDoseNoInjPois"}) {
256 auto hHits =
findHistT<TH2F>(dir +
"/SVDHitsVsTime_" + group.nameSuffix);
258 if (!hHits || !hEvts) {
259 B2WARNING(
"Histograms needed for Average Poisson Occupancy U-side not found.");
263 nHits += hHits->GetEntries();
264 nEvts += hEvts->GetEntries();
267 B2DEBUG(19,
"DQMHistAnalysisSVDDose: MonObj write"
268 <<
LogVar(
"group", group.nameSuffix.Data())
272 const double occ = nHits / nEvts * 100.0 / group.nStrips;
273 TString vName = group.nameSuffix +
"OccPoisAvg";
274 m_monObj->setVariable(vName.Data(), occ);
283 B2DEBUG(18,
"DQMHistAnalysisSVDDose: updating canvases");
289 auto hLER =
findHistT<TH1F>(
"SVDDoseLERInjPois/SVDInstOccu_" + group.nameSuffix);
290 auto hHER =
findHistT<TH1F>(
"SVDDoseHERInjPois/SVDInstOccu_" + group.nameSuffix);
291 auto hNo =
findHistT<TH1F>(
"SVDDoseNoInjPois/SVDInstOccu_" + group.nameSuffix);
292 if (hLER && hHER && hNo) {
293 hLER->SetLineColor(kRed);
294 hHER->SetLineColor(kAzure);
295 hNo->SetLineColor(kBlack);
301 hNo->SetTitle(
"SVD instantaneous occu. " + group.titleSuffix +
" U-side Pois. trig.");
303 hLER->Draw(
"hist same");
304 hHER->Draw(
"hist same");
310 auto hHits =
findHistT<TH2F>(
"SVDDoseLERInjPois/SVDHitsVsTime_" + group.nameSuffix);
312 if (hHits && hEvts) {
314 m_h_occuLER[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. Pois. trig."
315 ";Time since last injection [#mus];Time in beam cycle [#mus]"
321 c->SetRightMargin(0.16);
328 auto hpHits =
findHistT<TH1F>(
"SVDDoseLERInjPois/SVDHitsVsTime1_" + group.nameSuffix);
329 if (hpHits && hpEvts) {
331 m_h_occuLER1[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. Pois. trig."
332 ";Time since last injection [#mus];Occupancy [%]");
343 hHits =
findHistT<TH2F>(
"SVDDoseHERInjPois/SVDHitsVsTime_" + group.nameSuffix);
345 if (hHits && hEvts) {
347 m_h_occuHER[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. Pois. trig."
348 ";Time since last injection [#mus];Time in beam cycle [#mus]"
354 c->SetRightMargin(0.16);
361 hpHits =
findHistT<TH1F>(
"SVDDoseHERInjPois/SVDHitsVsTime1_" + group.nameSuffix);
362 if (hpHits && hpEvts) {
364 m_h_occuHER1[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. Pois. trig."
365 ";Time since last injection [#mus];Occupancy [%]");
377 hLER =
findHistT<TH1F>(
"SVDDoseLERInjAll/SVDInstOccu_" + group.nameSuffix);
378 hHER =
findHistT<TH1F>(
"SVDDoseHERInjAll/SVDInstOccu_" + group.nameSuffix);
379 hNo =
findHistT<TH1F>(
"SVDDoseNoInjAll/SVDInstOccu_" + group.nameSuffix);
380 if (hLER && hHER && hNo) {
381 hLER->SetLineColor(kRed);
382 hHER->SetLineColor(kAzure);
383 hNo->SetLineColor(kBlack);
389 hNo->SetTitle(
"SVD instantaneous occu. " + group.titleSuffix +
" U-side all events");
391 hLER->Draw(
"hist same");
392 hHER->Draw(
"hist same");
398 hHits =
findHistT<TH2F>(
"SVDDoseLERInjAll/SVDHitsVsTime_" + group.nameSuffix);
400 if (hHits && hEvts) {
402 m_h_occuLERAll[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. all events"
403 ";Time since last injection [#mus];Time in beam cycle [#mus]"
409 c->SetRightMargin(0.16);
416 hpHits =
findHistT<TH1F>(
"SVDDoseLERInjAll/SVDHitsVsTime1_" + group.nameSuffix);
417 if (hpHits && hpEvts) {
419 m_h_occuLER1All[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. all events"
420 ";Time since last injection [#mus];Occupancy [%]");
431 hHits =
findHistT<TH2F>(
"SVDDoseHERInjAll/SVDHitsVsTime_" + group.nameSuffix);
433 if (hHits && hEvts) {
435 m_h_occuHERAll[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. all events"
436 ";Time since last injection [#mus];Time in beam cycle [#mus]"
442 c->SetRightMargin(0.16);
449 hpHits =
findHistT<TH1F>(
"SVDDoseHERInjAll/SVDHitsVsTime1_" + group.nameSuffix);
450 if (hpHits && hpEvts) {
452 m_h_occuHER1All[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. all events"
453 ";Time since last injection [#mus];Occupancy [%]");
467 int i = h->GetNbinsX();
468 float t = h->GetBinContent(i) + h->GetBinContent(i + 1);
469 h->SetBinContent(i, t);
470 h->SetBinContent(i + 1, 0);
474 {
"L31XU",
"L3.1",
"L3:1", 768 * 2},
475 {
"L32XU",
"L3.2",
"L3:2", 768 * 2},
476 {
"L3XXU",
"L3 avg.",
"L3", 768 * 14},
477 {
"L4XXU",
"L4 avg.",
"L4", 768 * 30},
478 {
"L5XXU",
"L5 avg.",
"L5", 768 * 48},
479 {
"L6XXU",
"L6 avg.",
"L6", 768 * 80}
static bool getUseEpics(void)
Getter for EPICS usage.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
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.
T * findHistT(TString name)
Utility method.
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.
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.