10 #include <background/modules/BeamBkgHitRateMonitor/SVDHitRateCounter.h>
13 #include <framework/logging/Logger.h>
14 #include <hlt/softwaretrigger/core/FinalTriggerDecisionCalculator.h>
15 #include <framework/gearbox/Const.h>
16 #include <framework/gearbox/Unit.h>
17 #include <vxd/geometry/GeoCache.h>
21 #define LOGRATIO(x,y) (x) << " / " << (y) << " = " << ((x) * 100 / (y)) << "%"
28 namespace Background {
30 void SVDHitRateCounter::initialize(TTree* tree)
33 m_digits.isOptional(m_svdShaperDigitsName);
34 m_clusters.isOptional();
35 m_resultStoreObjectPointer.isOptional();
36 m_eventInfo.isOptional();
38 B2DEBUG(10,
"SVDHitRateCounter: initialize()");
40 tree->Branch(
"svd", &m_rates,
41 "layerAverageRates[4]/F:layerLadderAverageRates[4][16]/F:layerSensorAverageRates[4][5]:averageRate/F:l3LadderSensorAverageRates[7][2]/F:numEvents/I:valid/O");
42 tree->Branch(
"svdU", &m_ratesU,
43 "layerAverageRates[4]/F:layerLadderAverageRates[4][16]/F:layerSensorAverageRates[4][5]:averageRate/F:l3LadderSensorAverageRates[7][2]/F:numEvents/I:valid/O");
44 tree->Branch(
"svdV", &m_ratesV,
45 "layerAverageRates[4]/F:layerLadderAverageRates[4][16]/F:layerSensorAverageRates[4][5]:averageRate/F:l3LadderSensorAverageRates[7][2]/F:numEvents/I:valid/O");
46 tree->Branch(
"svd_highE", &m_rates_highE,
47 "layerAverageRates[4]/F:layerLadderAverageRates[4][16]/F:layerSensorAverageRates[4][5]:averageRate/F:l3LadderSensorAverageRates[7][2]/F:numEvents/I:valid/O");
48 tree->Branch(
"svd_lowE", &m_rates_lowE,
49 "layerAverageRates[4]/F:layerLadderAverageRates[4][16]/F:layerSensorAverageRates[4][5]:averageRate/F:l3LadderSensorAverageRates[7][2]/F:numEvents/I:valid/O");
50 tree->Branch(
"svd_clustersU", &m_clustersU,
51 "layerAverageRates[4]/F:layerLadderAverageRates[4][16]/F:layerSensorAverageRates[4][5]:averageRate/F:l3LadderSensorAverageRates[7][2]/F:numEvents/I:valid/O");
52 tree->Branch(
"svd_clustersV", &m_clustersV,
53 "layerAverageRates[4]/F:layerLadderAverageRates[4][16]/F:layerSensorAverageRates[4][5]:averageRate/F:l3LadderSensorAverageRates[7][2]/F:numEvents/I:valid/O");
54 tree->Branch(
"svd_energyU", &m_rates_energyU,
55 "layerAverageRates[4]/F:layerLadderAverageRates[4][16]/F:layerSensorAverageRates[4][5]:averageRate/F:l3LadderSensorAverageRates[7][2]/F:numEvents/I:valid/O");
56 tree->Branch(
"svd_energyV", &m_rates_energyV,
57 "layerAverageRates[4]/F:layerLadderAverageRates[4][16]/F:layerSensorAverageRates[4][5]:averageRate/F:l3LadderSensorAverageRates[7][2]/F:numEvents/I:valid/O");
60 for (
int layer = 0; layer < m_nLayers; layer++) {
61 for (
int ladder = 0; ladder < m_nLadders[layer]; ladder++) {
62 for (
int sensor = 0; sensor < m_nSensors[layer]; sensor++) {
63 VxdID sensorID(layer + 3, ladder + 1, sensor + 1);
64 for (
bool isU : {
true,
false}) {
65 int nStrips = nStripsOnLayerSide(layer, isU);
66 for (
int strip = 0; strip < nStrips; strip++) {
67 if (isStripActive(sensorID, isU, strip)) {
69 m_layerActiveStrips[layer] ++;
70 m_layerLadderActiveStrips[layer][ladder] ++;
71 m_layerSensorActiveStrips[layer][sensor] ++;
74 m_layerActiveStripsU[layer]++;
75 m_layerLadderActiveStripsU[layer][ladder]++;
76 m_layerSensorActiveStripsU[layer][sensor]++;
79 m_layerActiveStripsV[layer]++;
80 m_layerLadderActiveStripsV[layer][ladder]++;
81 m_layerSensorActiveStripsV[layer][sensor]++;
90 for (
int ladder = 0; ladder < m_nLadders[layer]; ladder++) {
91 for (
int sensor = 0; sensor < m_nSensors[layer]; sensor++) {
92 VxdID sensorID(layer + 3, ladder + 1, sensor + 1);
93 for (
bool isU : {
true,
false}) {
94 int nStrips = nStripsOnLayerSide(layer, isU);
95 for (
int strip = 0; strip < nStrips; strip++) {
96 if (isStripActive(sensorID, isU, strip)) {
97 m_l3LadderSensorActiveStrips[ladder][sensor] ++;
99 m_l3LadderSensorActiveStripsU[ladder][sensor]++;
101 m_l3LadderSensorActiveStripsV[ladder][sensor]++;
107 B2INFO(
"SVD active strips = " << LOGRATIO(m_activeStrips, 223744));
108 for (layer = 0; layer < m_nLayers; layer++)
109 B2INFO(
" Active strips L" << layer + 3 <<
".X.X = "
110 << LOGRATIO(m_layerActiveStrips[layer], m_nLadders[layer] * m_nSensors[layer] * (nStripsOnLayerSide(layer,
false) + 768)));
111 for (layer = 0; layer < m_nLayers; layer++)
112 for (
int ladder = 0; ladder < m_nLadders[layer]; ladder++)
113 B2INFO(
" Active strips L" << layer + 3 <<
"." << ladder + 1 <<
".X = "
114 << LOGRATIO(m_layerLadderActiveStrips[layer][ladder], m_nSensors[layer] * (nStripsOnLayerSide(layer,
false) + 768)));
115 for (layer = 0; layer < m_nLayers; layer++)
116 for (
int sensor = 0; sensor < m_nSensors[layer]; sensor++)
117 B2INFO(
" Active strips L" << layer + 3 <<
".X." << sensor + 1 <<
" = "
118 << LOGRATIO(m_layerSensorActiveStrips[layer][sensor], m_nLadders[layer] * (nStripsOnLayerSide(layer,
false) + 768)));
120 for (
int ladder = 0; ladder < m_nLadders[layer]; ladder++)
121 for (
int sensor = 0; sensor < m_nSensors[layer]; sensor++)
122 B2INFO(
" Active strips L3." << ladder + 1 <<
"." << sensor + 1 <<
" = "
123 << LOGRATIO(m_l3LadderSensorActiveStrips[ladder][sensor], 2 * 768));
126 for (layer = 0; layer < m_nLayers; layer++) {
127 for (
int ladder = 0; ladder < m_nLadders[layer]; ladder++) {
128 for (
int sensor = 0; sensor < m_nSensors[layer]; sensor++) {
129 double mass = massOfSensor(layer, ladder, sensor);
131 m_layerMassKg[layer] += mass;
132 m_layerLadderMassKg[layer][ladder] += mass;
133 m_layerSensorMassKg[layer][sensor] += mass;
139 void SVDHitRateCounter::clear()
144 void SVDHitRateCounter::accumulate(
unsigned timeStamp)
146 B2DEBUG(10,
"SVDHitRateCounter: accumulate()");
149 if (m_resultStoreObjectPointer.isValid()) {
150 const bool eventAccepted = SoftwareTrigger::FinalTriggerDecisionCalculator::getFinalTriggerDecision(*m_resultStoreObjectPointer);
151 if (!eventAccepted)
return;
155 if (m_digits.isValid()) {
158 auto& rates = m_buffer[timeStamp];
159 auto& ratesU = m_bufferU[timeStamp];
160 auto& ratesV = m_bufferV[timeStamp];
168 for (
const auto& digit : m_digits) {
170 VxdID sensorID = digit.getSensorID();
174 rates.layerAverageRates[layer] ++;
175 rates.layerLadderAverageRates[layer][ladder] ++;
176 rates.layerSensorAverageRates[layer][sensor] ++;
177 rates.averageRate ++;
179 rates.l3LadderSensorAverageRates[ladder][sensor] ++;
181 if (digit.isUStrip()) {
182 ratesU.layerAverageRates[layer]++;
183 ratesU.layerLadderAverageRates[layer][ladder]++;
184 ratesU.layerSensorAverageRates[layer][sensor]++;
185 ratesU.averageRate++;
187 ratesU.l3LadderSensorAverageRates[ladder][sensor]++;
189 ratesV.layerAverageRates[layer]++;
190 ratesV.layerLadderAverageRates[layer][ladder]++;
191 ratesV.layerSensorAverageRates[layer][sensor]++;
192 ratesV.averageRate++;
194 ratesV.l3LadderSensorAverageRates[ladder][sensor]++;
205 if (m_clusters.isValid()) {
208 auto& rates_highE = m_buffer_highE[timeStamp];
209 auto& rates_lowE = m_buffer_lowE[timeStamp];
210 auto& clustersU = m_buffer_clustersU[timeStamp];
211 auto& clustersV = m_buffer_clustersV[timeStamp];
212 auto& rates_energyU = m_buffer_energyU[timeStamp];
213 auto& rates_energyV = m_buffer_energyV[timeStamp];
216 rates_highE.numEvents++;
217 rates_lowE.numEvents++;
218 clustersU.numEvents++;
219 clustersV.numEvents++;
220 rates_energyU.numEvents++;
221 rates_energyV.numEvents++;
224 for (
const auto& cluster : m_clusters) {
225 VxdID sensorID = cluster.getSensorID();
229 if (cluster.getCharge() > m_thrCharge) {
230 rates_highE.layerAverageRates[layer] ++;
231 rates_highE.layerLadderAverageRates[layer][ladder] ++;
232 rates_highE.layerSensorAverageRates[layer][sensor] ++;
233 rates_highE.averageRate ++;
235 rates_highE.l3LadderSensorAverageRates[ladder][sensor] ++;
237 rates_lowE.layerAverageRates[layer] ++;
238 rates_lowE.layerLadderAverageRates[layer][ladder] ++;
239 rates_lowE.layerSensorAverageRates[layer][sensor] ++;
240 rates_lowE.averageRate ++;
242 rates_lowE.l3LadderSensorAverageRates[ladder][sensor] ++;
247 double svdSamplingClock = c_SVDSamplingClockFrequency;
249 if (m_eventInfo.isValid())
250 nSamp = m_eventInfo->getNSamples();
252 B2WARNING(
"SVDEventInfo not available: assuming 6 samples were taken.");
255 if (nSamp < 2) nSamp = 2;
257 if (m_clockSettings.isValid())
258 svdSamplingClock = m_clockSettings->getClockFrequency(Const::SVD,
"sampling");
260 B2WARNING(
"HardwareClockSettings not available: using approximated SVD sampling clock frequency.");
261 double integrationTimeSeconds = (nSamp - 1) / svdSamplingClock / Unit::s;
262 double chargePerUnitTime = cluster.getCharge() / integrationTimeSeconds;
263 if (cluster.isUCluster()) {
264 rates_energyU.layerAverageRates[layer] += chargePerUnitTime;
265 rates_energyU.layerLadderAverageRates[layer][ladder] += chargePerUnitTime;
266 rates_energyU.layerSensorAverageRates[layer][sensor] += chargePerUnitTime;
267 rates_energyU.averageRate += chargePerUnitTime;
269 rates_energyU.l3LadderSensorAverageRates[ladder][sensor] += chargePerUnitTime;
270 clustersU.layerAverageRates[layer]++;
271 clustersU.layerLadderAverageRates[layer][ladder]++;
272 clustersU.layerSensorAverageRates[layer][sensor]++;
273 clustersU.averageRate++;
275 clustersU.l3LadderSensorAverageRates[ladder][sensor]++;
277 rates_energyV.layerAverageRates[layer] += chargePerUnitTime;
278 rates_energyV.layerLadderAverageRates[layer][ladder] += chargePerUnitTime;
279 rates_energyV.layerSensorAverageRates[layer][sensor] += chargePerUnitTime;
280 rates_energyV.averageRate += chargePerUnitTime;
282 rates_energyV.l3LadderSensorAverageRates[ladder][sensor] += chargePerUnitTime;
283 clustersV.layerAverageRates[layer]++;
284 clustersV.layerLadderAverageRates[layer][ladder]++;
285 clustersV.layerSensorAverageRates[layer][sensor]++;
286 clustersV.averageRate++;
288 clustersV.l3LadderSensorAverageRates[ladder][sensor]++;
293 rates_highE.valid =
true;
294 rates_lowE.valid =
true;
295 clustersU.valid =
true;
296 clustersV.valid =
true;
297 rates_energyU.valid =
true;
298 rates_energyV.valid =
true;
303 void SVDHitRateCounter::normalize(
unsigned timeStamp)
305 B2DEBUG(10,
"SVDHitRateCounter: normalize()");
307 m_rates = m_buffer[timeStamp];
308 m_ratesU = m_bufferU[timeStamp];
309 m_ratesV = m_bufferV[timeStamp];
310 m_rates_highE = m_buffer_highE[timeStamp];
311 m_rates_lowE = m_buffer_lowE[timeStamp];
312 m_clustersU = m_buffer_clustersU[timeStamp];
313 m_clustersV = m_buffer_clustersV[timeStamp];
314 m_rates_energyU = m_buffer_energyU[timeStamp];
315 m_rates_energyV = m_buffer_energyV[timeStamp];
317 SVDHitRateCounter::normalizeRates(m_rates);
318 SVDHitRateCounter::normalizeRates(m_ratesU,
true);
319 SVDHitRateCounter::normalizeRates(m_ratesV,
false,
true);
320 SVDHitRateCounter::normalizeRates(m_rates_highE);
321 SVDHitRateCounter::normalizeRates(m_rates_lowE);
322 SVDHitRateCounter::normalizeRates(m_clustersU,
true);
323 SVDHitRateCounter::normalizeRates(m_clustersV,
false,
true);
324 SVDHitRateCounter::normalizeEnergyRates(m_rates_energyU);
325 SVDHitRateCounter::normalizeEnergyRates(m_rates_energyV);
328 void SVDHitRateCounter::normalizeRates(
TreeStruct& rates,
bool isU,
bool isV)
330 if (not rates.
valid)
return;
336 const auto& activeStrips = isU ? m_activeStripsU : (isV ? m_activeStripsV : m_activeStrips);
337 const auto& layerActiveStrips = isU ? m_layerActiveStripsU : (isV ? m_layerActiveStripsV : m_layerActiveStrips);
338 const auto& layerLadderActiveStrips = isU ? m_layerLadderActiveStripsU
339 : (isV ? m_layerLadderActiveStripsV : m_layerLadderActiveStrips);
340 const auto& layerSensorActiveStrips = isU ? m_layerSensorActiveStripsU
341 : (isV ? m_layerSensorActiveStripsV : m_layerSensorActiveStrips);
342 const auto& l3LadderSensorActiveStrips = isU ? m_l3LadderSensorActiveStripsU
343 : (isV ? m_l3LadderSensorActiveStripsV : m_l3LadderSensorActiveStrips);
347 for (
int layer = 0; layer < m_nLayers; layer++) {
349 for (
int ladder = 0; ladder < m_nLadders[layer]; ladder++) {
352 for (
int sensor = 0; sensor < m_nSensors[layer]; sensor++) {
357 for (
int ladder = 0; ladder < m_nLadders[layer]; ladder++) {
358 for (
int sensor = 0; sensor < m_nSensors[layer]; sensor++) {
364 void SVDHitRateCounter::normalizeEnergyRates(
TreeStruct& rates)
366 static const double ehEnergyJoules = Const::ehEnergy / Unit::J;
368 static const double conv = ehEnergyJoules * 100e3;
370 if (!rates.
valid)
return;
375 for (
int layer = 0; layer < m_nLayers; layer++) {
377 for (
int ladder = 0; ladder < m_nLadders[layer]; ladder++)
379 for (
int sensor = 0; sensor < m_nSensors[layer]; sensor++)
383 for (
int ladder = 0; ladder < m_nLadders[layer]; ladder++)
384 for (
int sensor = 0; sensor < m_nSensors[layer]; sensor++)
388 double SVDHitRateCounter::massOfSensor(
int layer,
int ladder,
int sensor)
390 static const double rho_Si = 2.329 * Unit::g_cm3;
391 auto& sensorInfo = VXD::GeoCache::getInstance().getSensorInfo(
VxdID(layer + 3, ladder + 1, sensor + 1));
392 double length = sensorInfo.getLength();
393 double width = (sensorInfo.getForwardWidth() + sensorInfo.getBackwardWidth()) / 2.0;
394 double thickness = sensorInfo.getWSize();
395 return length * width * thickness * rho_Si / 1e3;
398 bool SVDHitRateCounter::isStripActive(
const VxdID& sensorID,
const bool& isU,
399 const unsigned short& strip)
401 return ((m_ignoreHotStripsPayload || !m_HotStripsCalib.isHot(sensorID, isU, strip))
402 && (m_ignoreMaskedStripsPayload || !m_FADCMaskedStrips.isMasked(sensorID, isU, strip)));
Class to uniquely identify a any structure of the PXD and SVD.
baseType getSensorNumber() const
Get the sensor id.
baseType getLadderNumber() const
Get the ladder id.
baseType getLayerNumber() const
Get the layer id.
Abstract base class for different kinds of events.
bool valid
status: true = rates valid
float layerAverageRates[4]
layer average occupancy
float layerLadderAverageRates[4][16]
[#layer][#ladder]
float layerSensorAverageRates[4][5]
[#layer][#sensor]
float averageRate
total SVD average occupancy
void normalize()
normalize accumulated hits to single event
float l3LadderSensorAverageRates[7][2]
Layer 3 sensors [#ladder][#sensor].