12 #include <background/modules/BeamBkgHitRateMonitor/ARICHHitRateCounter.h>
15 #include <framework/logging/Logger.h>
24 namespace Background {
26 void ARICHHitRateCounter::initialize(TTree* tree)
32 tree->Branch(
"arich", &m_rates,
"segmentRates[18]/F:averageRate/F:numEvents/I:valid/O");
36 int nModInRing[7] = {0, 42, 90, 144, 204, 270, 342};
38 for (
int i = 0; i < 420; i++) {
39 if (i == nModInRing[iRing + 1]) iRing++;
40 int segment = (i - nModInRing[iRing]) / (7 + iRing);
41 if (iRing > 0) segment += 6;
42 if (iRing > 3) segment += 6;
43 m_segmentMap[i] = segment;
50 void ARICHHitRateCounter::clear()
55 void ARICHHitRateCounter::accumulate(
unsigned timeStamp)
58 if (not m_hits.isValid())
return;
61 auto& rates = m_buffer[timeStamp];
67 for (
const auto& hit : m_hits) {
68 if (hit.getModule() < 1 || hit.getModule() > 420)
continue;
69 auto effi = m_modulesInfo->getChannelQE(hit.getModule(), hit.getChannel());
70 float wt = std::min(1.0 / effi, 100.);
71 rates.segmentRates[m_segmentMap[hit.getModule() - 1]] += wt;
72 rates.averageRate += wt;
80 void ARICHHitRateCounter::normalize(
unsigned timeStamp)
83 m_rates = m_buffer[timeStamp];
85 if (not m_rates.valid)
return;
91 if (m_channelMask.hasChanged()) setActiveHapds();
93 for (
int iSegment = 0; iSegment < 18; iSegment++) {
94 double nHapds = m_activeHapds[iSegment];
95 if (nHapds > 0) m_rates.segmentRates[iSegment] /= nHapds;
96 else m_rates.segmentRates[iSegment] = 0;
98 m_rates.averageRate /= m_activeTotal;
101 void ARICHHitRateCounter::setActiveHapds()
103 for (
auto& nactive : m_activeHapds) nactive = 0;
105 if (not m_channelMask.isValid()) {
106 for (
unsigned imod = 1; imod < 421; imod++) m_activeHapds[m_segmentMap[imod - 1]] += 1.;
108 B2WARNING(
"ARICHHitRateCounter: no valid channel mask - all HAPDs set to active");
112 int nactiveTotal = 0;
113 for (
unsigned imod = 1; imod < 421; imod++) {
115 for (
unsigned ichn = 0; ichn < 144; ichn++) {
116 if (m_channelMask->isActive(imod, ichn)) nactive++;
118 nactiveTotal += nactive;
119 m_activeHapds[m_segmentMap[imod - 1]] += (float)nactive / 144.;
121 m_activeTotal = (float)nactiveTotal / 144.;