12 #include <background/modules/BeamBkgHitRateMonitor/CDCHitRateCounter.h>
15 #include <framework/gearbox/Unit.h>
16 #include <framework/gearbox/Const.h>
17 #include <framework/logging/Logger.h>
19 #include <tracking/trackFindingCDC/rootification/StoreWrappedObjPtr.h>
20 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
22 #include <cdc/geometry/CDCGeometryPar.h>
23 #include <cdc/dataobjects/WireID.h>
33 using TrackFindingCDC::StoreWrappedObjPtr;
34 using TrackFindingCDC::CDCWireHit;
36 namespace Background {
38 void CDCHitRateCounter::initialize(TTree* tree)
41 m_digits.isOptional();
45 stringstream leafList;
47 <<
"layerHitRate[" << f_nLayer <<
"]/F:"
48 <<
"superLayerHitRate[" << f_nSuperLayer <<
"]/F:"
50 <<
"timeWindowForSmallCell/I:"
51 <<
"timeWindowForNormalCell/I:"
52 <<
"nActiveWireInLayer[" << f_nLayer <<
"]/I:"
53 <<
"nActiveWireInSuperLayer[" << f_nSuperLayer <<
"]/I:"
54 <<
"nActiveWireInTotal/I:"
57 tree->Branch(
"cdc", &m_rates, leafList.str().c_str());
59 if (m_enableBadWireTreatment) {
62 countActiveWires_countAll();
66 void CDCHitRateCounter::clear()
71 void CDCHitRateCounter::accumulate(
unsigned timeStamp)
74 if (not m_digits.isValid())
return;
77 auto& rates = m_buffer[timeStamp];
83 std::map<const CDCHit*, bool> CDCHitToBackgroundFlag;
84 if (m_enableBackgroundHitFilter) {
86 if (not storeVector) {
87 B2FATAL(
"CDCWireHitVector is unaccessible in DataStore."
88 "Need TFCDC_WireHitParameter module before.");
90 const std::vector<CDCWireHit>& cdcWireHitVector = *storeVector;
91 for (
const auto& cdcWireHit : cdcWireHitVector) {
92 const CDCHit* cdcHit = cdcWireHit.getHit();
93 CDCHitToBackgroundFlag[cdcHit] = cdcWireHit->hasBackgroundFlag();
106 for (
CDCHit& hit : m_digits) {
107 const WireID wireID(hit.getID());
108 if (m_enableBadWireTreatment && geometryPar.
isBadWire(wireID))
111 const int iLayer = hit.getICLayer();
112 const int iSuperLayer = hit.getISuperLayer();
113 const unsigned short adc = hit.getADCCount();
114 const short tdc = hit.getTDCCount();
116 if (m_enableBackgroundHitFilter) {
117 if (CDCHitToBackgroundFlag[&hit]) {
118 if (m_enableMarkBackgroundHit) {
119 unsigned short newStatus = (hit.getStatus() | 0x100);
120 hit.setStatus(newStatus);
125 if (iSuperLayer == 0 && adc < 15)
127 if (iSuperLayer != 0 && adc < 18)
131 if (not isInTimeWindow(iSuperLayer, tdc))
135 rates.layerHitRate[iLayer] += 1;
136 rates.superLayerHitRate[iSuperLayer] += 1;
137 rates.averageRate += 1;
144 void CDCHitRateCounter::normalize(
unsigned timeStamp)
147 m_rates = m_buffer[timeStamp];
149 if (not m_rates.valid)
return;
151 m_rates.timeWindowForSmallCell = m_timeWindowUpperEdge_smallCell - m_timeWindowLowerEdge_smallCell;
152 m_rates.timeWindowForNormalCell = m_timeWindowUpperEdge_normalCell - m_timeWindowLowerEdge_normalCell;
159 if (m_nActiveWireInTotal == 0) {
160 m_rates.averageRate = 0;
162 m_rates.averageRate /= m_nActiveWireInTotal;
165 for (
int iSL = 0 ; iSL < f_nSuperLayer ; ++iSL)
166 if (m_nActiveWireInSuperLayer[iSL] == 0) {
167 m_rates.superLayerHitRate[iSL] = 0;
169 m_rates.superLayerHitRate[iSL] /= m_nActiveWireInSuperLayer[iSL];
172 for (
int iLayer = 0 ; iLayer < f_nLayer ; ++iLayer)
173 if (m_nActiveWireInLayer[iLayer] == 0) {
174 m_rates.layerHitRate[iLayer] = 0;
176 m_rates.layerHitRate[iLayer] /= m_nActiveWireInLayer[iLayer];
178 for (
int i = 0 ; i < f_nLayer ; ++i)
179 m_rates.nActiveWireInLayer[i] = m_nActiveWireInLayer[i];
180 for (
int i = 0 ; i < f_nSuperLayer ; ++i)
181 m_rates.nActiveWireInSuperLayer[i] = m_nActiveWireInSuperLayer[i];
182 m_rates.nActiveWireInTotal = m_nActiveWireInTotal;
186 void CDCHitRateCounter::countActiveWires_countAll()
188 const int nlayer_in_SL[f_nSuperLayer] = { 8, 6, 6,
192 const int nwire_in_layer[f_nSuperLayer] = { 160, 160, 192,
197 m_nActiveWireInTotal = 0;
199 for (
int iSL = 0 ; iSL < f_nSuperLayer ; ++iSL) {
200 m_nActiveWireInSuperLayer[iSL] = 0;
201 for (
int i = 0 ; i < nlayer_in_SL[iSL] ; ++i) {
202 m_nActiveWireInLayer[contLayerID] = nwire_in_layer[iSL];
203 m_nActiveWireInSuperLayer[iSL] += nwire_in_layer[iSL];
204 m_nActiveWireInTotal += nwire_in_layer[iSL];
212 void CDCHitRateCounter::countActiveWires()
214 const int nlayer_in_SL[f_nSuperLayer] = { 8, 6, 6,
218 const int nwire_in_layer[f_nSuperLayer] = { 160, 160, 192,
225 m_nActiveWireInTotal = 0;
228 for (
int iSL = 0 ; iSL < f_nSuperLayer ; ++iSL) {
229 m_nActiveWireInSuperLayer[iSL] = 0;
230 for (
int iL = 0 ; iL < nlayer_in_SL[iSL] ; ++iL) {
231 m_nActiveWireInLayer[contLayerID] = 0;
232 for (
int i = 0 ; i < nwire_in_layer[iSL] ; ++i) {
233 WireID wireID(iSL, iL, i);
235 ++m_nActiveWireInLayer[contLayerID];
237 m_nActiveWireInSuperLayer[iSL] += m_nActiveWireInLayer[contLayerID];
240 m_nActiveWireInTotal += m_nActiveWireInSuperLayer[iSL];
245 std::cout <<
"CDC, # of Active wires / # of total wires" << std::endl;
246 int contLayerID_2 = 0;
247 for (
int iSL = 0 ; iSL < f_nSuperLayer ; ++iSL) {
248 for (
int iL = 0 ; iL < nlayer_in_SL[iSL] ; ++iL) {
250 std::cout <<
"Layer " << contLayerID_2 <<
": "
251 << m_nActiveWireInLayer[contLayerID_2] <<
" / "
253 << nwire_in_layer[iSL] << std::endl;