10 #include <background/modules/BeamBkgHitRateMonitor/TOPHitRateCounter.h>
13 #include <top/geometry/TOPGeometryPar.h>
16 #include <framework/gearbox/Unit.h>
17 #include <framework/logging/Logger.h>
26 namespace Background {
28 void TOPHitRateCounter::initialize(TTree* tree)
31 m_digits.isOptional();
34 tree->Branch(
"top", &m_rates,
"slotRates[16]/F:averageRate/F:numEvents/I:valid/O");
37 m_hits =
new TH1F(
"top_hits",
"time distribution of hits; digit.time [ns]",
39 m_hitsInWindow =
new TH1F(
"top_hitsInWindow",
40 "time distribution of hits; digit.time [ns]",
41 100, m_timeOffset - m_timeWindow / 2,
42 m_timeOffset + m_timeWindow / 2);
45 if (m_timeWindow <= 0) B2FATAL(
"invalid time window for TOP: " << m_timeWindow);
51 void TOPHitRateCounter::clear()
56 void TOPHitRateCounter::accumulate(
unsigned timeStamp)
59 if (not m_digits.isValid())
return;
62 auto& rates = m_buffer[timeStamp];
68 const auto* topgp = TOP::TOPGeometryPar::Instance();
69 for (
const auto& digit : m_digits) {
70 if (digit.getHitQuality() != TOPDigit::c_Good)
continue;
71 m_hits->Fill(digit.getTime());
73 if (fabs(digit.getTime() - m_timeOffset) > m_timeWindow / 2)
continue;
74 m_hitsInWindow->Fill(digit.getTime());
76 auto effi = topgp->getRelativePixelEfficiency(digit.getModuleID(),
78 float wt = std::min(1.0 / effi, 10.0);
79 rates.slotRates[digit.getModuleID() - 1] += wt;
80 rates.averageRate += wt;
88 void TOPHitRateCounter::normalize(
unsigned timeStamp)
91 m_rates = m_buffer[timeStamp];
93 if (not m_rates.valid)
return;
99 for (
auto& slotRate : m_rates.slotRates) {
100 slotRate /= m_timeWindow / Unit::us * 32;
102 m_rates.averageRate /= m_timeWindow / Unit::us * 32 * 16;
105 if (m_channelMask.hasChanged()) setActiveFractions();
108 for (
int m = 0; m < 16; m++) {
109 double fraction = m_activeFractions[m];
111 m_rates.slotRates[m] /= fraction;
113 m_rates.slotRates[m] = 0;
116 m_rates.averageRate /= m_activeTotal;
120 void TOPHitRateCounter::setActiveFractions()
122 if (not m_channelMask.isValid()) {
123 for (
auto& fraction : m_activeFractions) fraction = 1;
125 B2WARNING(
"TOPHitRateCounter: no valid channel mask - active fractions set to 1");
129 for (
int m = 0; m < 16; m++) {
130 m_activeFractions[m] = m_channelMask->getActiveFraction(m + 1);
132 m_activeTotal = m_channelMask->getActiveFraction();
Abstract base class for different kinds of events.