Belle II Software development
ARICHHitRateCounter.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9// Own header.
10#include <background/modules/BeamBkgHitRateMonitor/ARICHHitRateCounter.h>
11
12// framework aux
13#include <framework/logging/Logger.h>
14
15using namespace std;
16
17namespace Belle2 {
22 namespace Background {
23
25 {
26 // register collection(s) as optional, your detector might be excluded in DAQ
27 m_hits.isOptional();
28
29 // set branch address
30 tree->Branch("arich", &m_rates, "segmentRates[18]/F:averageRate/F:numEvents/I:valid/O");
31
32 // make map of modules to 18 segments
33 // (first hapd ring is 6 segments (by sector), for the rest, each segment merges 3 hapd rings (again by sector))
34 const int nModInRing[7] = {0, 42, 90, 144, 204, 270, 342};
35 int iRing = 0;
36 for (int i = 0; i < 420; i++) {
37 if (i == nModInRing[iRing + 1]) iRing++;
38 int segment = (i - nModInRing[iRing]) / (7 + iRing);
39 if (iRing > 0) segment += 6;
40 if (iRing > 3) segment += 6;
41 m_segmentMap[i] = segment;
42 }
43
44 // set fractions of active channels
46 }
47
49 {
50 m_buffer.clear();
51 }
52
53 void ARICHHitRateCounter::accumulate(unsigned timeStamp)
54 {
55 // check if data are available
56 if (not m_hits.isValid()) return;
57
58 // get buffer element
59 auto& rates = m_buffer[timeStamp];
60
61 // increment event counter
62 rates.numEvents++;
63
64 // count and weight hits accoring to channel efficiecny
65 for (const auto& hit : m_hits) {
66 if (hit.getModule() < 1 || hit.getModule() > 420) continue;
67 auto effi = m_modulesInfo->getChannelQE(hit.getModule(), hit.getChannel());
68 float wt = std::min(1.0 / effi, 100.);
69 rates.segmentRates[m_segmentMap[hit.getModule() - 1]] += wt;
70 rates.averageRate += wt;
71 }
72
73 // set flag to true to indicate the rates are valid
74 rates.valid = true;
75
76 }
77
78 void ARICHHitRateCounter::normalize(unsigned timeStamp)
79 {
80 // copy buffer element
81 m_rates = m_buffer[timeStamp];
82
83 if (not m_rates.valid) return;
84
85 // normalize
87
88 // correct rates for masked-out channels
89 if (m_channelMask.hasChanged()) setActiveHapds();
90
91 for (int iSegment = 0; iSegment < 18; iSegment++) {
92 double nHapds = m_activeHapds[iSegment];
93 if (nHapds > 0) m_rates.segmentRates[iSegment] /= nHapds;
94 else m_rates.segmentRates[iSegment] = 0;
95 }
97 }
98
100 {
101 for (auto& nactive : m_activeHapds) nactive = 0;
102
103 if (not m_channelMask.isValid()) {
104 for (unsigned imod = 1; imod < 421; imod++) m_activeHapds[m_segmentMap[imod - 1]] += 1.;
105 m_activeTotal = 420;
106 B2WARNING("ARICHHitRateCounter: no valid channel mask - all HAPDs set to active");
107 return;
108 }
109
110 int nactiveTotal = 0;
111 for (unsigned imod = 1; imod < 421; imod++) {
112 int nactive = 0;
113 for (unsigned ichn = 0; ichn < 144; ichn++) {
114 if (m_channelMask->isActive(imod, ichn)) nactive++;
115 }
116 nactiveTotal += nactive;
117 m_activeHapds[m_segmentMap[imod - 1]] += (float)nactive / 144.;
118 }
119 m_activeTotal = (float)nactiveTotal / 144.;
120 }
121
122 } // Background namespace
124} // Belle2 namespace
125
std::map< unsigned, TreeStruct > m_buffer
average rates in time stamps
void setActiveHapds()
Sets number of active hapds in each segment.
virtual void initialize(TTree *tree) override
Class initializer: set branch addresses and other staf.
double m_activeTotal
total number of active HAPDS
int m_segmentMap[420]
mapping from module ID to segments
virtual void accumulate(unsigned timeStamp) override
Accumulate hits.
StoreArray< ARICHHit > m_hits
collection of digits
DBObjPtr< ARICHModulesInfo > m_modulesInfo
HAPD modules info.
DBObjPtr< ARICHChannelMask > m_channelMask
channel mask
double m_activeHapds[18]
number of active HAPDS in each segment
virtual void normalize(unsigned timeStamp) override
Normalize accumulated hits (e.g.
virtual void clear() override
Clear time-stamp buffer to prepare for 'accumulate'.
Abstract base class for different kinds of events.
STL namespace.
float segmentRates[18]
hit rates per HAPD [Hz] for 18 segments of arich
float averageRate
total detector average hit rate per HAPD [Hz]
void normalize()
normalize accumulated hits to single event