10 #include <background/modules/BeamBkgHitRateMonitor/ECLHitRateCounter.h>
12 #include <ecl/dbobjects/ECLCrystalCalib.h>
13 #include <framework/database/DBObjPtr.h>
14 #include <framework/geometry/B2Vector3.h>
26 namespace Background {
28 void ECLHitRateCounter::initialize(TTree* tree)
35 tree->Branch(
"ecl", &m_rates,
"averageDspBkgRate[16]/F:numEvents/I:validDspRate/O");
39 ECLWaveformNoise(
"ECLWaveformRMS");
40 m_ADCtoEnergy.resize(8736);
41 if (ECLElectronicsCalib)
for (
int i = 0; i < 8736; i++) m_ADCtoEnergy[i] = ECLElectronicsCalib->getCalibVector()[i];
42 if (ECLECalib)
for (
int i = 0; i < 8736; i++) m_ADCtoEnergy[i] *= ECLECalib->getCalibVector()[i];
43 m_waveformNoise.resize(8736);
44 if (ECLWaveformNoise)
for (
int i = 0; i < 8736; i++) m_waveformNoise[i] = ECLWaveformNoise->getCalibVector()[i];
47 void ECLHitRateCounter::clear()
52 void ECLHitRateCounter::accumulate(
unsigned timeStamp)
55 if (not m_dsps.isValid())
return;
61 if (m_dsps.getEntries() == 8736) {
64 auto& rates = m_buffer[timeStamp];
69 for (
auto& aECLDsp : m_dsps) {
71 int nadc = aECLDsp.getNADCPoints();
72 int cellID = aECLDsp.getCellId();
73 int segmentNumber = findECLSegment(cellID);
74 int crysID = cellID - 1;
75 std::vector<int> dspAv = aECLDsp.getDspA();
78 double dspMean = (std::accumulate(dspAv.begin(), dspAv.begin() + nadc, 0.0)) / nadc;
80 for (
int v = 0; v < nadc; v++) {
81 wpsum += pow(dspAv[v] - dspMean, 2);
83 double dspRMS =
sqrt(wpsum / nadc);
84 double dspSigma = dspRMS * abs(m_ADCtoEnergy[crysID]);
87 double dspBkgRate = ((pow(dspSigma, 2)) - (pow(m_waveformNoise[crysID], 2))) / (2.53 * 1e-12);
93 rates.averageDspBkgRate[segmentNumber] += dspBkgRate;
98 rates.validDspRate =
true;
102 void ECLHitRateCounter::normalize(
unsigned timeStamp)
105 m_rates = m_buffer[timeStamp];
107 if (not m_rates.validDspRate)
return;
113 for (
int i = 0; i < 16; i++) {
114 m_rates.averageDspBkgRate[i] /= m_crystalsInSegment[i];
119 void ECLHitRateCounter::segmentECL()
122 for (
int cid = 1; cid < 8737; cid++) {
123 m_geometry->Mapping(cid);
124 const B2Vector3D position = m_geometry->GetCrystalPos(cid - 1);
125 const double phi = position.
Phi();
126 const double z = position.
Z();
129 if (phi > 0.7853 && phi < 2.356) {
130 m_segmentMap.insert(std::pair<int, int>(cid, 0));
131 m_crystalsInSegment[0] += 1;
132 }
else if (phi >= 2.356 || phi <= -2.356) {
133 m_segmentMap.insert(std::pair<int, int>(cid, 1));
134 m_crystalsInSegment[1] += 1;
135 }
else if (phi > -2.356 && phi < -0.7853) {
136 m_segmentMap.insert(std::pair<int, int>(cid, 2));
137 m_crystalsInSegment[2] += 1;
139 m_segmentMap.insert(std::pair<int, int>(cid, 3));
140 m_crystalsInSegment[3] += 1;
142 }
else if (cid < 7777) {
144 if (phi > 0.7853 && phi < 2.356) {
145 m_segmentMap.insert(std::pair<int, int>(cid, 4));
146 m_crystalsInSegment[4] += 1;
147 }
else if (phi >= 2.356 || phi <= -2.356) {
148 m_segmentMap.insert(std::pair<int, int>(cid, 5));
149 m_crystalsInSegment[5] += 1;
150 }
else if (phi > -2.356 && phi < -0.7853) {
151 m_segmentMap.insert(std::pair<int, int>(cid, 6));
152 m_crystalsInSegment[6] += 1;
154 m_segmentMap.insert(std::pair<int, int>(cid, 7));
155 m_crystalsInSegment[7] += 1;
158 if (phi > 0.7853 && phi < 2.356) {
159 m_segmentMap.insert(std::pair<int, int>(cid, 8));
160 m_crystalsInSegment[8] += 1;
161 }
else if (phi >= 2.356 || phi <= -2.356) {
162 m_segmentMap.insert(std::pair<int, int>(cid, 9));
163 m_crystalsInSegment[9] += 1;
164 }
else if (phi > -2.356 && phi < -0.7853) {
165 m_segmentMap.insert(std::pair<int, int>(cid, 10));
166 m_crystalsInSegment[10] += 1;
168 m_segmentMap.insert(std::pair<int, int>(cid, 11));
169 m_crystalsInSegment[11] += 1;
173 if (phi > 0.7853 && phi < 2.356) {
174 m_segmentMap.insert(std::pair<int, int>(cid, 12));
175 m_crystalsInSegment[12] += 1;
176 }
else if (phi >= 2.356 || phi <= -2.356) {
177 m_segmentMap.insert(std::pair<int, int>(cid, 13));
178 m_crystalsInSegment[13] += 1;
179 }
else if (phi > -2.356 && phi < -0.7853) {
180 m_segmentMap.insert(std::pair<int, int>(cid, 14));
181 m_crystalsInSegment[14] += 1;
183 m_segmentMap.insert(std::pair<int, int>(cid, 15));
184 m_crystalsInSegment[15] += 1;
DataType Phi() const
The azimuth angle.
DataType Z() const
access variable Z (= .at(2) without boundary check)
Class for accessing objects in the database.
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.