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()
39 if (
getUseEpics() && ca_current_context()) ca_context_destroy();
45 B2DEBUG(18,
"DQMHistAnalysisSVDDose: initialize");
70 TCanvas* c =
new TCanvas(
"SVDDOSE/c_svd_instOccupancy_" + group.nameSuffix +
"_pois",
71 "Instantaneous occupancy (Pois. trig.) " + group.titleSuffix);
73 c =
new TCanvas(
"SVDDOSE/c_svd_occuLER_" + group.nameSuffix +
"_pois",
74 "Occupancy vs time since LER inj. (Pois. trig.) " + group.titleSuffix);
77 c =
new TCanvas(
"SVDDOSE/c_svd_occuHER_" + group.nameSuffix +
"_pois",
78 "Occupancy vs time since HER inj. (Pois. trig.) " + group.titleSuffix);
81 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuLER_" + group.nameSuffix +
"_pois",
82 "Occupancy vs time since LER inj. (Pois. trig.) " + group.titleSuffix);
85 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuHER_" + group.nameSuffix +
"_pois",
86 "Occupancy vs time since HER inj. (Pois. trig.) " + group.titleSuffix);
90 c =
new TCanvas(
"SVDDOSE/c_svd_instOccupancy_" + group.nameSuffix +
"_all",
91 "Instantaneous occupancy (all events) " + group.titleSuffix);
93 c =
new TCanvas(
"SVDDOSE/c_svd_occuLER_" + group.nameSuffix +
"_all",
94 "Occupancy vs time since LER inj. (all events) " + group.titleSuffix);
97 c =
new TCanvas(
"SVDDOSE/c_svd_occuHER_" + group.nameSuffix +
"_all",
98 "Occupancy vs time since HER inj. (all events) " + group.titleSuffix);
101 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuLER_" + group.nameSuffix +
"_all",
102 "Occupancy vs time since LER inj. (all events) " + group.titleSuffix);
105 c =
new TCanvas(
"SVDDOSE/c_svd_1DoccuHER_" + group.nameSuffix +
"_all",
106 "Occupancy vs time since HER inj. (all events) " + group.titleSuffix);
111 m_legend =
new TPaveText(0.53, 0.73, 0.68, 0.88,
"brNDC");
112 m_legend->AddText(
"LER inj."); ((TText*)
m_legend->GetListOfLines()->Last())->SetTextColor(kRed);
113 m_legend->AddText(
"HER inj."); ((TText*)
m_legend->GetListOfLines()->Last())->SetTextColor(kAzure);
114 m_legend->AddText(
"No inj."); ((TText*)
m_legend->GetListOfLines()->Last())->SetTextColor(kBlack);
118 if (!ca_current_context())
119 SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
124 NULL, NULL, 10, &m_myPVs[g].mychid),
"ca_create_channel");
127 NULL, NULL, 10, &m_timeSinceLastPVUpdateChan),
"ca_create_channel");
129 NULL, NULL, 10, &m_stateChan),
"ca_create_channel");
131 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
134 SEVCHK(ca_get(DBR_CTRL_ENUM, m_stateChan, &m_stateCtrl),
"ca_get");
135 B2DEBUG(19,
"State PV initialized (ca_get)" <<
LogVar(
"value", m_stateCtrl.value));
136 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
138 B2DEBUG(18,
"State PV failed to initialize, will retry in beginRun(), event() and endRun().");
141 m_lastPVUpdate = getClockSeconds();
151 B2DEBUG(19,
"beginRun: setting state PV to RUNNING");
152 m_stateCtrl.value = 1;
154 SEVCHK(ca_put(DBR_ENUM, m_stateChan, &m_stateCtrl.value),
"ca_put");
157 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
159 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
161 m_lastPVUpdate = getClockSeconds();
170 double timeSinceLastPVUpdate = getClockSeconds() - m_lastPVUpdate;
174 SEVCHK(ca_get(DBR_CTRL_ENUM, m_stateChan, &m_stateCtrl),
"ca_get");
177 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
179 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
182 if (m_timeSinceLastPVUpdateChan) {
183 SEVCHK(ca_put(DBR_DOUBLE, m_timeSinceLastPVUpdateChan, (
void*)&timeSinceLastPVUpdate),
"ca_put");
186 "ca_create_channel (reconnection)");
188 m_stateCtrl.value = 1;
190 SEVCHK(ca_put(DBR_ENUM, m_stateChan, &m_stateCtrl.value),
"ca_put");
193 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
198 double nHits = 0.0, nEvts = 0.0;
199 for (TString dir : {
"SVDDoseLERInjPois",
"SVDDoseHERInjPois",
"SVDDoseNoInjPois"}) {
200 auto hHits = findHistT<TH2F>(dir +
"/SVDHitsVsTime_" + group.nameSuffix);
201 auto hEvts = findHistT<TH2F>(dir +
"/SVDEvtsVsTime");
202 if (!hHits || !hEvts) {
203 B2WARNING(
"Histograms needed for Average Poisson Occupancy U-side not found.");
207 nHits += hHits->GetEntries();
208 nEvts += hEvts->GetEntries();
211 B2DEBUG(19,
"DQMHistAnalysisSVDDose: PV write"
212 <<
LogVar(
"group", group.nameSuffix.Data())
215 auto& pv = m_myPVs[g];
216 double delta_nHits = nHits - pv.lastNHits;
217 double delta_nEvts = nEvts - pv.lastNEvts;
218 double occ = delta_nEvts > 0.0 ? (delta_nHits / delta_nEvts * 100.0 / group.nStrips) : -1.0;
220 SEVCHK(ca_put(DBR_DOUBLE, pv.mychid, (
void*)&occ),
"ca_put");
223 NULL, NULL, 10, &m_myPVs[g].mychid),
"ca_create_channel (reconnection)");
225 pv.lastNEvts = nEvts;
226 pv.lastNHits = nHits;
230 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
231 m_lastPVUpdate = getClockSeconds();
240 B2DEBUG(18,
"DQMHistAnalysisSVDDose: endRun");
245 B2DEBUG(19,
"endRun: setting state PV to NOT RUNNING");
246 m_stateCtrl.value = 0;
248 SEVCHK(ca_put(DBR_ENUM, m_stateChan, &m_stateCtrl.value),
"ca_put");
251 NULL, NULL, 10, &m_stateChan),
"ca_create_channel (reconnection)");
253 SEVCHK(ca_pend_io(2.0),
"ca_pend_io");
255 for (
auto& pv : m_myPVs)
256 pv.lastNEvts = pv.lastNHits = 0.0;
263 double nHits = 0.0, nEvts = 0.0;
264 for (TString dir : {
"SVDDoseLERInjPois",
"SVDDoseHERInjPois",
"SVDDoseNoInjPois"}) {
265 auto hHits = findHistT<TH2F>(dir +
"/SVDHitsVsTime_" + group.nameSuffix);
266 auto hEvts = findHistT<TH2F>(dir +
"/SVDEvtsVsTime");
267 if (!hHits || !hEvts) {
268 B2WARNING(
"Histograms needed for Average Poisson Occupancy U-side not found.");
272 nHits += hHits->GetEntries();
273 nEvts += hEvts->GetEntries();
276 B2DEBUG(19,
"DQMHistAnalysisSVDDose: MonObj write"
277 <<
LogVar(
"group", group.nameSuffix.Data())
281 const double occ = nHits / nEvts * 100.0 / group.nStrips;
282 TString vName = group.nameSuffix +
"OccPoisAvg";
292 B2DEBUG(18,
"DQMHistAnalysisSVDDose: updating canvases");
298 auto hLER = findHistT<TH1F>(
"SVDDoseLERInjPois/SVDInstOccu_" + group.nameSuffix);
299 auto hHER = findHistT<TH1F>(
"SVDDoseHERInjPois/SVDInstOccu_" + group.nameSuffix);
300 auto hNo = findHistT<TH1F>(
"SVDDoseNoInjPois/SVDInstOccu_" + group.nameSuffix);
301 if (hLER && hHER && hNo) {
302 hLER->SetLineColor(kRed);
303 hHER->SetLineColor(kAzure);
304 hNo->SetLineColor(kBlack);
310 hNo->SetTitle(
"SVD instantaneous occu. " + group.titleSuffix +
" U-side Pois. trig.");
312 hLER->Draw(
"hist same");
313 hHER->Draw(
"hist same");
319 auto hHits = findHistT<TH2F>(
"SVDDoseLERInjPois/SVDHitsVsTime_" + group.nameSuffix);
320 auto hEvts = findHistT<TH2F>(
"SVDDoseLERInjPois/SVDEvtsVsTime");
321 if (hHits && hEvts) {
323 m_h_occuLER[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. Pois. trig."
324 ";Time since last injection [#mus];Time in beam cycle [#mus]"
330 c->SetRightMargin(0.16);
336 auto hpEvts = findHistT<TH1F>(
"SVDDoseLERInjPois/SVDEvtsVsTime1");
337 auto hpHits = findHistT<TH1F>(
"SVDDoseLERInjPois/SVDHitsVsTime1_" + group.nameSuffix);
338 if (hpHits && hpEvts) {
340 m_h_occuLER1[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. Pois. trig."
341 ";Time since last injection [#mus];Occupancy [%]");
352 hHits = findHistT<TH2F>(
"SVDDoseHERInjPois/SVDHitsVsTime_" + group.nameSuffix);
353 hEvts = findHistT<TH2F>(
"SVDDoseHERInjPois/SVDEvtsVsTime");
354 if (hHits && hEvts) {
356 m_h_occuHER[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. Pois. trig."
357 ";Time since last injection [#mus];Time in beam cycle [#mus]"
363 c->SetRightMargin(0.16);
369 hpEvts = findHistT<TH1F>(
"SVDDoseHERInjPois/SVDEvtsVsTime1");
370 hpHits = findHistT<TH1F>(
"SVDDoseHERInjPois/SVDHitsVsTime1_" + group.nameSuffix);
371 if (hpHits && hpEvts) {
373 m_h_occuHER1[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. Pois. trig."
374 ";Time since last injection [#mus];Occupancy [%]");
386 hLER = findHistT<TH1F>(
"SVDDoseLERInjAll/SVDInstOccu_" + group.nameSuffix);
387 hHER = findHistT<TH1F>(
"SVDDoseHERInjAll/SVDInstOccu_" + group.nameSuffix);
388 hNo = findHistT<TH1F>(
"SVDDoseNoInjAll/SVDInstOccu_" + group.nameSuffix);
389 if (hLER && hHER && hNo) {
390 hLER->SetLineColor(kRed);
391 hHER->SetLineColor(kAzure);
392 hNo->SetLineColor(kBlack);
398 hNo->SetTitle(
"SVD instantaneous occu. " + group.titleSuffix +
" U-side all events");
400 hLER->Draw(
"hist same");
401 hHER->Draw(
"hist same");
407 hHits = findHistT<TH2F>(
"SVDDoseLERInjAll/SVDHitsVsTime_" + group.nameSuffix);
408 hEvts = findHistT<TH2F>(
"SVDDoseLERInjAll/SVDEvtsVsTime");
409 if (hHits && hEvts) {
411 m_h_occuLERAll[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. all events"
412 ";Time since last injection [#mus];Time in beam cycle [#mus]"
418 c->SetRightMargin(0.16);
424 hpEvts = findHistT<TH1F>(
"SVDDoseLERInjAll/SVDEvtsVsTime1");
425 hpHits = findHistT<TH1F>(
"SVDDoseLERInjAll/SVDHitsVsTime1_" + group.nameSuffix);
426 if (hpHits && hpEvts) {
428 m_h_occuLER1All[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - LER inj. all events"
429 ";Time since last injection [#mus];Occupancy [%]");
440 hHits = findHistT<TH2F>(
"SVDDoseHERInjAll/SVDHitsVsTime_" + group.nameSuffix);
441 hEvts = findHistT<TH2F>(
"SVDDoseHERInjAll/SVDEvtsVsTime");
442 if (hHits && hEvts) {
444 m_h_occuHERAll[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. all events"
445 ";Time since last injection [#mus];Time in beam cycle [#mus]"
451 c->SetRightMargin(0.16);
457 hpEvts = findHistT<TH1F>(
"SVDDoseHERInjAll/SVDEvtsVsTime1");
458 hpHits = findHistT<TH1F>(
"SVDDoseHERInjAll/SVDHitsVsTime1_" + group.nameSuffix);
459 if (hpHits && hpEvts) {
461 m_h_occuHER1All[g]->SetTitle(
"SVD Occupancy " + group.titleSuffix +
" - HER inj. all events"
462 ";Time since last injection [#mus];Occupancy [%]");
476 int i = h->GetNbinsX();
477 float t = h->GetBinContent(i) + h->GetBinContent(i + 1);
478 h->SetBinContent(i, t);
479 h->SetBinContent(i + 1, 0);
483 {
"L31XU",
"L3.1",
"L3:1", 768 * 2},
484 {
"L32XU",
"L3.2",
"L3:2", 768 * 2},
485 {
"L3XXU",
"L3 avg.",
"L3", 768 * 14},
486 {
"L4XXU",
"L4 avg.",
"L4", 768 * 30},
487 {
"L5XXU",
"L5 avg.",
"L5", 768 * 48},
488 {
"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.