Belle II Software  release-08-01-10
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 
12 using namespace std;
13 
14 namespace 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 
52  void TOPCalChannelT0::suppressAverage()
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
Abstract base class for different kinds of events.