Belle II Software development
TOPCalModuleAlignment.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/TOPCalModuleAlignment.h>
10#include <framework/logging/Logger.h>
11#include <Math/RotationX.h>
12#include <Math/RotationY.h>
13#include <Math/RotationZ.h>
14#include <Math/Translation3D.h>
15
16using namespace std;
17using namespace ROOT::Math;
18
19namespace Belle2 {
25 void TOPCalModuleAlignment::setAlpha(int moduleID, double alpha, double errAlpha)
26 {
27 unsigned module = moduleID - 1;
28 if (module >= c_numModules) {
29 B2ERROR("Invalid module number, constant not set (" << ClassName() << ")");
30 return;
31 }
32 m_alpha[module] = alpha;
33 m_errAlpha[module] = errAlpha;
34 m_transforms.clear();
35 }
36
37 void TOPCalModuleAlignment::setBeta(int moduleID, double beta, double errBeta)
38 {
39 unsigned module = moduleID - 1;
40 if (module >= c_numModules) {
41 B2ERROR("Invalid module number, constant not set (" << ClassName() << ")");
42 return;
43 }
44 m_beta[module] = beta;
45 m_errBeta[module] = errBeta;
46 m_transforms.clear();
47 }
48
49 void TOPCalModuleAlignment::setGamma(int moduleID, double gamma, double errGamma)
50 {
51 unsigned module = moduleID - 1;
52 if (module >= c_numModules) {
53 B2ERROR("Invalid module number, constant not set (" << ClassName() << ")");
54 return;
55 }
56 m_gamma[module] = gamma;
57 m_errGamma[module] = errGamma;
58 m_transforms.clear();
59 }
60
61 void TOPCalModuleAlignment::setX(int moduleID, double x, double errX)
62 {
63 unsigned module = moduleID - 1;
64 if (module >= c_numModules) {
65 B2ERROR("Invalid module number, constant not set (" << ClassName() << ")");
66 return;
67 }
68 m_x[module] = x;
69 m_errX[module] = errX;
70 m_transforms.clear();
71 }
72
73 void TOPCalModuleAlignment::setY(int moduleID, double y, double errY)
74 {
75 unsigned module = moduleID - 1;
76 if (module >= c_numModules) {
77 B2ERROR("Invalid module number, constant not set (" << ClassName() << ")");
78 return;
79 }
80 m_y[module] = y;
81 m_errY[module] = errY;
82 m_transforms.clear();
83 }
84
85 void TOPCalModuleAlignment::setZ(int moduleID, double z, double errZ)
86 {
87 unsigned module = moduleID - 1;
88 if (module >= c_numModules) {
89 B2ERROR("Invalid module number, constant not set (" << ClassName() << ")");
90 return;
91 }
92 m_z[module] = z;
93 m_errZ[module] = errZ;
94 m_transforms.clear();
95 }
96
98 {
99 unsigned module = moduleID - 1;
100 if (module >= c_numModules) {
101 B2ERROR("Invalid module number, status not set (" << ClassName() << ")");
102 return;
103 }
104 m_status[module] = c_Calibrated;
105 m_transforms.clear();
106 }
107
109 {
110 unsigned module = moduleID - 1;
111 if (module >= c_numModules) {
112 B2ERROR("Invalid module number, status not set (" << ClassName() << ")");
113 return;
114 }
115 m_status[module] = c_Unusable;
116 m_transforms.clear();
117 }
118
119 double TOPCalModuleAlignment::getAlpha(int moduleID) const
120 {
121 unsigned module = moduleID - 1;
122 if (module >= c_numModules) {
123 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
124 return 0;
125 }
126 return m_alpha[module];
127 }
128
129 double TOPCalModuleAlignment::getBeta(int moduleID) const
130 {
131 unsigned module = moduleID - 1;
132 if (module >= c_numModules) {
133 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
134 return 0;
135 }
136 return m_beta[module];
137 }
138
139 double TOPCalModuleAlignment::getGamma(int moduleID) const
140 {
141 unsigned module = moduleID - 1;
142 if (module >= c_numModules) {
143 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
144 return 0;
145 }
146 return m_gamma[module];
147 }
148
149 double TOPCalModuleAlignment::getX(int moduleID) const
150 {
151 unsigned module = moduleID - 1;
152 if (module >= c_numModules) {
153 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
154 return 0;
155 }
156 return m_x[module];
157 }
158
159 double TOPCalModuleAlignment::getY(int moduleID) const
160 {
161 unsigned module = moduleID - 1;
162 if (module >= c_numModules) {
163 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
164 return 0;
165 }
166 return m_y[module];
167 }
168
169 double TOPCalModuleAlignment::getZ(int moduleID) const
170 {
171 unsigned module = moduleID - 1;
172 if (module >= c_numModules) {
173 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
174 return 0;
175 }
176 return m_z[module];
177 }
178
179 double TOPCalModuleAlignment::getAlphaErr(int moduleID) const
180 {
181 unsigned module = moduleID - 1;
182 if (module >= c_numModules) {
183 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
184 return 0;
185 }
186 return m_errAlpha[module];
187 }
188
189 double TOPCalModuleAlignment::getBetaErr(int moduleID) const
190 {
191 unsigned module = moduleID - 1;
192 if (module >= c_numModules) {
193 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
194 return 0;
195 }
196 return m_errBeta[module];
197 }
198
199 double TOPCalModuleAlignment::getGammaErr(int moduleID) const
200 {
201 unsigned module = moduleID - 1;
202 if (module >= c_numModules) {
203 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
204 return 0;
205 }
206 return m_errGamma[module];
207 }
208
209 double TOPCalModuleAlignment::getXErr(int moduleID) const
210 {
211 unsigned module = moduleID - 1;
212 if (module >= c_numModules) {
213 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
214 return 0;
215 }
216 return m_errX[module];
217 }
218
219 double TOPCalModuleAlignment::getYErr(int moduleID) const
220 {
221 unsigned module = moduleID - 1;
222 if (module >= c_numModules) {
223 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
224 return 0;
225 }
226 return m_errY[module];
227 }
228
229 double TOPCalModuleAlignment::getZErr(int moduleID) const
230 {
231 unsigned module = moduleID - 1;
232 if (module >= c_numModules) {
233 B2WARNING("Invalid module number, returning 0 (" << ClassName() << ")");
234 return 0;
235 }
236 return m_errZ[module];
237 }
238
239 bool TOPCalModuleAlignment::isCalibrated(int moduleID) const
240 {
241 unsigned module = moduleID - 1;
242 if (module >= c_numModules) return false ;
243 return m_status[module] == c_Calibrated;
244 }
245
246 bool TOPCalModuleAlignment::isDefault(int moduleID) const
247 {
248 unsigned module = moduleID - 1;
249 if (module >= c_numModules) return false ;
250 return m_status[module] == c_Default;
251 }
252
253 bool TOPCalModuleAlignment::isUnusable(int moduleID) const
254 {
255 unsigned module = moduleID - 1;
256 if (module >= c_numModules) return false ;
257 return m_status[module] == c_Unusable;
258 }
259
261 {
262 for (int i = 0; i < c_numModules; i++) {
263 if (m_status[i] != c_Calibrated) return false;
264 }
265 return true;
266 }
267
268 bool TOPCalModuleAlignment::areAllPrecise(double spatialPrecision,
269 double angularPrecision) const
270 {
271 for (int i = 0; i < c_numModules; i++) {
272 if (m_errAlpha[i] > angularPrecision) return false;
273 if (m_errBeta[i] > angularPrecision) return false;
274 if (m_errGamma[i] > angularPrecision) return false;
275 if (m_errX[i] > spatialPrecision) return false;
276 if (m_errY[i] > spatialPrecision) return false;
277 if (m_errZ[i] > spatialPrecision) return false;
278 }
279 return true;
280 }
281
283 {
284 for (int i = 0; i < c_numModules; i++) {
285 Transform3D T;
286 if (m_status[i] == c_Calibrated) {
287 RotationX Rx(m_alpha[i]);
288 RotationY Ry(m_beta[i]);
289 RotationZ Rz(m_gamma[i]);
290 Translation3D t(m_x[i], m_y[i], m_z[i]);
291 T = Transform3D(Rz * Ry * Rx, t);
292 }
293 m_transforms.push_back(T);
294 }
295 m_transforms.push_back(Transform3D()); // for invalid module ID
296 }
297
298 const Transform3D& TOPCalModuleAlignment::getTransformation(int moduleID) const
299 {
300 if (m_transforms.empty()) setTransformations();
301 unsigned module = moduleID - 1;
302 if (module >= c_numModules) {
303 B2ERROR("Invalid module number, returning identity transformation (" << ClassName() << ")");
305 }
306 return m_transforms[module];
307 }
308
309
311} // namespace Belle2
312
EStatus m_status[c_numModules]
calibration status
float m_errGamma[c_numModules]
error on gamma
float m_gamma[c_numModules]
rotation angle around the z axis
std::vector< ROOT::Math::Transform3D > m_transforms
cache for transformations (from local to nominal)
float m_y[c_numModules]
displacement along the y axis
float m_errX[c_numModules]
error on the x displacement
@ c_Calibrated
good calibrated value
@ c_Default
uncalibrated default value
float m_x[c_numModules]
displacement along the x axis
float m_errBeta[c_numModules]
error on beta
float m_alpha[c_numModules]
rotation angle around the x axis
float m_z[c_numModules]
displacement along the z axis
float m_beta[c_numModules]
rotation angle around the y axis
float m_errY[c_numModules]
error on the y displacement
float m_errZ[c_numModules]
error on the z displacement
float m_errAlpha[c_numModules]
error on alpha
double getGammaErr(int moduleID) const
Returns the error on gamma on a single module.
bool areAllCalibrated() const
Returns true if all modules are calibrated.
void setGamma(int moduleID, double gamma, double errGamma)
Sets the angle gamma on a single module.
double getX(int moduleID) const
Returns the shift x on a single module.
double getBetaErr(int moduleID) const
Returns the error on beta on a single module.
bool isCalibrated(int moduleID) const
Returns calibration status.
void setX(int moduleID, double x, double errX)
Sets the displacement x on a single module.
const ROOT::Math::Transform3D & getTransformation(int moduleID) const
Returns transformation from local to nominal frame.
void setTransformations() const
Sets the transformation cache.
double getAlpha(int moduleID) const
Gets the angle alpha on a single module.
double getZ(int moduleID) const
Returns the shift z on a single module.
double getAlphaErr(int moduleID) const
Returns the error on alpha on a single module.
void setBeta(int moduleID, double beta, double errBeta)
Sets the angle beta on a single module.
double getBeta(int moduleID) const
Gets the angle beta on a single module.
double getXErr(int moduleID) const
Returns the error on x on a single module.
bool areAllPrecise(double spatialPrecision, double angularPrecision) const
Returns true if calibration precision for all modules is within specified values.
void setUnusable(int moduleID)
Switches calibration status to unusable to flag badly calibrated constant.
bool isDefault(int moduleID) const
Returns calibration status.
bool isUnusable(int moduleID) const
Returns calibration status.
void setCalibrated(int moduleID)
Switches calibration status to calibrated.
void setAlpha(int moduleID, double alpha, double errAlpha)
Sets the angle alpha on a single module.
double getGamma(int moduleID) const
Gets the angle gamma on a single module.
double getZErr(int moduleID) const
Returns the error on z on a single module.
void setZ(int moduleID, double z, double errZ)
Sets the displacement z on a single module.
double getYErr(int moduleID) const
Returns the error on y on a single module.
void setY(int moduleID, double y, double errY)
Sets the displacement y on a single module.
double getY(int moduleID) const
Returns the shift y on a single module.
Abstract base class for different kinds of events.
STL namespace.