10 #include <background/modules/BeamBkgHitRateMonitor/CDCHitRateCounter.h>
13 #include <framework/gearbox/Unit.h>
14 #include <framework/gearbox/Const.h>
15 #include <framework/logging/Logger.h>
17 #include <tracking/trackFindingCDC/rootification/StoreWrappedObjPtr.h>
18 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
20 #include <cdc/geometry/CDCGeometryPar.h>
21 #include <cdc/dataobjects/WireID.h>
31 using TrackFindingCDC::StoreWrappedObjPtr;
32 using TrackFindingCDC::CDCWireHit;
34 namespace Background {
36 void CDCHitRateCounter::initialize(TTree* tree)
39 m_digits.isOptional();
43 stringstream leafList;
46 <<
"superLayerHitRate[" << f_nSuperLayer <<
"]/F:"
47 <<
"layerHitRate[" << f_nLayer <<
"]/F:"
48 <<
"layerPhiHitRate[" << f_nLayer <<
"][" << f_nPhiDivision <<
"]/F:"
49 <<
"timeWindowForSmallCell/I:"
50 <<
"timeWindowForNormalCell/I:"
51 <<
"nActiveWireInTotal/I:"
52 <<
"nActiveWireInSuperLayer[" << f_nSuperLayer <<
"]/I:"
53 <<
"nActiveWireInLayer[" << f_nLayer <<
"]/I:"
54 <<
"nActiveWireInLayerPhi[" << f_nLayer <<
"][" << f_nPhiDivision <<
"]/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 unsigned short iSuperLayer = hit.getISuperLayer();
112 const unsigned short iLayer = hit.getICLayer();
113 const unsigned short iWireInLayer = hit.getIWire();
114 const unsigned short iPhiBin = getIPhiBin(iSuperLayer, iWireInLayer);
115 const unsigned short adc = hit.getADCCount();
116 const short tdc = hit.getTDCCount();
118 if (m_enableBackgroundHitFilter) {
119 if (CDCHitToBackgroundFlag[&hit]) {
120 if (m_enableMarkBackgroundHit) {
121 unsigned short newStatus = (hit.getStatus() | 0x100);
122 hit.setStatus(newStatus);
127 if (iSuperLayer == 0 && adc < 15)
129 if (iSuperLayer != 0 && adc < 18)
133 if (not isInTimeWindow(iSuperLayer, tdc))
137 rates.averageRate += 1;
138 rates.superLayerHitRate[iSuperLayer] += 1;
139 rates.layerHitRate[iLayer] += 1;
140 rates.layerPhiHitRate[iLayer][iPhiBin] += 1;
147 void CDCHitRateCounter::normalize(
unsigned timeStamp)
150 m_rates = m_buffer[timeStamp];
152 if (not m_rates.valid)
return;
154 m_rates.timeWindowForSmallCell = m_timeWindowUpperEdge_smallCell - m_timeWindowLowerEdge_smallCell;
155 m_rates.timeWindowForNormalCell = m_timeWindowUpperEdge_normalCell - m_timeWindowLowerEdge_normalCell;
162 if (m_nActiveWireInTotal == 0) {
163 m_rates.averageRate = 0;
165 m_rates.averageRate /= m_nActiveWireInTotal;
168 for (
int iSL = 0 ; iSL < f_nSuperLayer ; ++iSL)
169 if (m_nActiveWireInSuperLayer[iSL] == 0) {
170 m_rates.superLayerHitRate[iSL] = 0;
172 m_rates.superLayerHitRate[iSL] /= m_nActiveWireInSuperLayer[iSL];
175 for (
int iLayer = 0 ; iLayer < f_nLayer ; ++iLayer)
176 if (m_nActiveWireInLayer[iLayer] == 0) {
177 m_rates.layerHitRate[iLayer] = 0;
179 m_rates.layerHitRate[iLayer] /= m_nActiveWireInLayer[iLayer];
182 for (
int iLayer = 0 ; iLayer < f_nLayer ; ++iLayer)
183 for (
int iPhi = 0 ; iPhi < f_nPhiDivision ; ++iPhi)
184 if (m_nActiveWireInLayerPhi[iLayer][iPhi] == 0) {
185 m_rates.layerPhiHitRate[iLayer][iPhi] = 0;
187 m_rates.layerPhiHitRate[iLayer][iPhi] /= m_nActiveWireInLayerPhi[iLayer][iPhi];
191 m_rates.nActiveWireInTotal = m_nActiveWireInTotal;
192 for (
int i = 0 ; i < f_nSuperLayer ; ++i)
193 m_rates.nActiveWireInSuperLayer[i] = m_nActiveWireInSuperLayer[i];
194 for (
int i = 0 ; i < f_nLayer ; ++i)
195 m_rates.nActiveWireInLayer[i] = m_nActiveWireInLayer[i];
196 for (
int i = 0 ; i < f_nLayer ; ++i)
197 for (
int j = 0 ; j < f_nPhiDivision ; ++j)
198 m_rates.nActiveWireInLayerPhi[i][j] = m_nActiveWireInLayerPhi[i][j];
202 void CDCHitRateCounter::countActiveWires_countAll()
204 static const unsigned short nlayer_in_SL[f_nSuperLayer] = { 8, 6, 6,
208 static const unsigned short nwire_in_layer[f_nSuperLayer] = { 160, 160, 192,
213 m_nActiveWireInTotal = 0;
215 for (
int iSL = 0 ; iSL < f_nSuperLayer ; ++iSL) {
216 m_nActiveWireInSuperLayer[iSL] = 0;
217 for (
int i = 0 ; i < nlayer_in_SL[iSL] ; ++i) {
218 m_nActiveWireInTotal += nwire_in_layer[iSL];
219 m_nActiveWireInSuperLayer[iSL] += nwire_in_layer[iSL];
220 m_nActiveWireInLayer[contLayerID] = nwire_in_layer[iSL];
221 for (
int j = 0 ; j < f_nPhiDivision ; ++j)
222 m_nActiveWireInLayerPhi[contLayerID][j] = nwire_in_layer[iSL] / f_nPhiDivision;
230 void CDCHitRateCounter::countActiveWires()
232 static const unsigned short nlayer_in_SL[f_nSuperLayer] = { 8, 6, 6,
236 static const unsigned short nwire_in_layer[f_nSuperLayer] = { 160, 160, 192,
243 m_nActiveWireInTotal = 0;
246 for (
int iSL = 0 ; iSL < f_nSuperLayer ; ++iSL) {
247 m_nActiveWireInSuperLayer[iSL] = 0;
248 for (
int iL = 0 ; iL < nlayer_in_SL[iSL] ; ++iL) {
249 m_nActiveWireInLayer[contLayerID] = 0;
250 for (
int iPhi = 0 ; iPhi < f_nPhiDivision ; ++iPhi)
251 m_nActiveWireInLayerPhi[contLayerID][iPhi] = 0;
253 for (
int i = 0 ; i < nwire_in_layer[iSL] ; ++i) {
254 WireID wireID(iSL, iL, i);
256 ++m_nActiveWireInLayerPhi[contLayerID][getIPhiBin(iSL, i)];
257 ++m_nActiveWireInLayer[contLayerID];
260 m_nActiveWireInSuperLayer[iSL] += m_nActiveWireInLayer[contLayerID];
263 m_nActiveWireInTotal += m_nActiveWireInSuperLayer[iSL];
268 std::cout <<
"CDC, # of Active wires / # of total wires" << std::endl;
269 int contLayerID_2 = 0;
270 for (
int iSL = 0 ; iSL < f_nSuperLayer ; ++iSL) {
271 for (
int iL = 0 ; iL < nlayer_in_SL[iSL] ; ++iL) {
273 std::cout <<
"Layer " << contLayerID_2 <<
": "
274 << m_nActiveWireInLayer[contLayerID_2] <<
" / "
276 << nwire_in_layer[iSL] << std::endl;
284 unsigned short CDCHitRateCounter::getIPhiBin(
unsigned short iSL,
unsigned short iWireInLayer)
286 static const unsigned short nwire_in_layer[f_nSuperLayer] = { 160, 160, 192,
290 return iWireInLayer / (nwire_in_layer[iSL] / f_nPhiDivision);
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
The Class for CDC Geometry Parameters.
bool isBadWire(const WireID &wid)
Inquire if the wire is totally-dead.
This class is for convenience access and registration of objects, that are stored inside the StoreWra...
Class to identify a wire inside the CDC.
Abstract base class for different kinds of events.