Belle II Software development
TOPCalChannelT0.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#include <top/dbobjects/TOPCalChannelT0.h>
10#include <framework/logging/Logger.h>
11
12using namespace std;
13
14namespace Belle2 {
20 void TOPCalChannelT0::setT0(int moduleID, unsigned channel, double T0, double errT0)
21 {
22 unsigned module = moduleID - 1;
23 if (module >= c_numModules) {
24 B2ERROR("Invalid module number, constant not set (" << ClassName() << ")");
25 return;
26 }
27 if (channel >= c_numChannels) {
28 B2ERROR("Invalid channel number, constant not set (" << ClassName() << ")");
29 return;
30 }
31 m_T0[module][channel] = T0;
32 m_errT0[module][channel] = errT0;
33 m_status[module][channel] = c_Calibrated;
34 }
35
36
37 void TOPCalChannelT0::setUnusable(int moduleID, unsigned channel)
38 {
39 unsigned module = moduleID - 1;
40 if (module >= c_numModules) {
41 B2ERROR("Invalid module number, status not set (" << ClassName() << ")");
42 return;
43 }
44 if (channel >= c_numChannels) {
45 B2ERROR("Invalid channel number, status not set (" << ClassName() << ")");
46 return;
47 }
48 m_status[module][channel] = c_Unusable;
49 }
50
51
53 {
54 for (int m = 0; m < c_numModules; m++) {
55 float s = 0;
56 int n = 0;
57 for (int i = 0; i < c_numChannels; i++) {
58 if (m_status[m][i] == c_Calibrated) {
59 s += m_T0[m][i];
60 n++;
61 }
62 }
63 if (n == 0) continue;
64 s /= n;
65 for (int i = 0; i < c_numChannels; i++) {
66 if (m_status[m][i] != c_Default) m_T0[m][i] -= s;
67 }
68 B2INFO("Slot " << m + 1 << ": average of " << s << " ns subtracted.");
69 }
70 }
71
72
73 double TOPCalChannelT0::getT0(int moduleID, unsigned channel) const
74 {
75 unsigned module = moduleID - 1;
76 if (module >= c_numModules) {
77 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
78 return 0;
79 }
80 if (channel >= c_numChannels) {
81 B2WARNING("Invalid channel number, returning 0 (" << ClassName() << ")");
82 return 0;
83 }
84 return m_T0[module][channel];
85 }
86
87
88 double TOPCalChannelT0::getT0Error(int moduleID, unsigned channel) const
89 {
90 unsigned module = moduleID - 1;
91 if (module >= c_numModules) {
92 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
93 return 0;
94 }
95 if (channel >= c_numChannels) {
96 B2WARNING("Invalid channel number, returning 0 (" << ClassName() << ")");
97 return 0;
98 }
99 return m_errT0[module][channel];
100 }
101
102
103 bool TOPCalChannelT0::isCalibrated(int moduleID, unsigned channel) const
104 {
105 unsigned module = moduleID - 1;
106 if (module >= c_numModules) return false;
107 if (channel >= c_numChannels) return false;
108 return m_status[module][channel] == c_Calibrated;
109 }
110
111
112 bool TOPCalChannelT0::isDefault(int moduleID, unsigned channel) const
113 {
114 unsigned module = moduleID - 1;
115 if (module >= c_numModules) return false;
116 if (channel >= c_numChannels) return false;
117 return m_status[module][channel] == c_Default;
118 }
119
120
121 bool TOPCalChannelT0::isUnusable(int moduleID, unsigned channel) const
122 {
123 unsigned module = moduleID - 1;
124 if (module >= c_numModules) return false;
125 if (channel >= c_numChannels) return false;
126 return m_status[module][channel] == c_Unusable;
127 }
128
129
131} // end Belle2 namespace
EStatus m_status[c_numModules][c_numChannels]
calibration status
float m_T0[c_numModules][c_numChannels]
calibration constants
float m_errT0[c_numModules][c_numChannels]
errors on constants
@ c_Calibrated
good calibrated value
@ c_Unusable
bad calibrated value
@ c_Default
uncalibrated default value
@ c_numChannels
number of channels per module
@ c_numModules
number of modules
bool isCalibrated(int moduleID, unsigned channel) const
Returns calibration status.
double getT0(int moduleID, unsigned channel) const
Returns T0 of a single channel.
void suppressAverage()
Subtracts arithmetic average of a module from constants whose status is not c_Default.
void setT0(int moduleID, unsigned channel, double T0, double errT0)
Sets calibration for a single channel and switches status to calibrated.
void setUnusable(int moduleID, unsigned channel)
Switches calibration status to unusable to flag badly calibrated constant.
double getT0Error(int moduleID, unsigned channel) const
Returns error on T0 of a single channel.
bool isDefault(int moduleID, unsigned channel) const
Returns calibration status.
bool isUnusable(int moduleID, unsigned channel) const
Returns calibration status.
Abstract base class for different kinds of events.
STL namespace.