Belle II Software development
SensorInfoBase.h
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#pragma once
10
11#include <vxd/dataobjects/VxdID.h>
12#include <float.h>
13
14#include <Math/Vector3D.h>
15#include <TGeoMatrix.h>
16
17namespace Belle2 {
23 namespace VXD {
24
30 public:
33 PXD = 0,
34 SVD = 1,
35 TEL = 2,
36 VXD = -1,
37 };
38
60 SensorInfoBase(SensorType type, VxdID id, double width, double length, double thickness,
61 int uCells, int vCells, double width2 = -1, double splitLength = -1, int vCells2 = 0):
62 m_type(type), m_id(id), m_width(width), m_length(length), m_thickness(thickness),
63 m_deltaWidth(0), m_splitLength(0), m_uCells(uCells), m_vCells(vCells), m_vCells2(vCells2)
64 {
65 if (width2 > 0) m_deltaWidth = width2 - width;
66 if (splitLength > 0) m_splitLength = splitLength / length;
67 }
69 virtual ~SensorInfoBase() {}
70
72 SensorType getType() const { return m_type; }
74 VxdID getID() const { return m_id; }
75
80 double getWidth(double v = 0) const
81 {
82 if (m_deltaWidth == 0) return m_width;
83 return m_width + (v / m_length + 0.5) * m_deltaWidth;
84 }
85
89 double getBackwardWidth() const
90 {
91 return getWidth(-0.5 * m_length);
92 }
93
97 double getForwardWidth() const
98 {
99 return getWidth(0.5 * m_length);
100 }
101
105 double getLength() const { return m_length; }
106
110 double getThickness() const { return m_thickness; }
111
116 double getUSize(double v = 0) const { return getWidth(v); }
117
121 double getVSize() const { return getLength(); }
122
126 double getWSize() const { return getThickness(); }
127
132 double getUPitch(double v = 0) const { return getWidth(v) / m_uCells; }
133
139 double getVPitch(double v = 0) const
140 {
141 if (m_splitLength <= 0) return m_length / m_vCells;
142 if (v / m_length + 0.5 >= m_splitLength) return m_length * (1 - m_splitLength) / m_vCells2;
144 }
145
156 int getVPitchID(double v = 0) const
157 {
158 if (m_splitLength <= 0) return 0;
159 if (v / m_length + 0.5 >= m_splitLength) return 0;
160 return 1;
161 }
162
168 double getUCellPosition(int uID, int vID = -1) const
169 {
170 if (m_deltaWidth == 0) return ((uID + 0.5) / m_uCells - 0.5) * m_width;
171 double v = 0;
172 if (vID >= 0) v = getVCellPosition(vID);
173 return ((uID + 0.5) / m_uCells - 0.5) * getWidth(v);
174 }
175
180 double getVCellPosition(int vID) const
181 {
182 if (m_splitLength <= 0) return ((vID + 0.5) / m_vCells - 0.5) * m_length;
183 if (vID >= m_vCells) return ((vID - m_vCells + 0.5) / m_vCells2 * (1 - m_splitLength) - 0.5 + m_splitLength) * m_length;
184 return ((vID + 0.5) / m_vCells * m_splitLength - 0.5) * m_length;
185 }
186
193 int getUCellID(double u, double v = 0, bool clamp = false) const
194 {
195 if (clamp) return std::min(getUCells() - 1, std::max(0, getUCellID(u, v, false)));
196 return static_cast<int>((u / getWidth(v) + 0.5) * m_uCells);
197 }
198
204 int getVCellID(double v, bool clamp = false) const
205 {
206 if (clamp) return std::min(getVCells() - 1, std::max(0, getVCellID(v, false)));
207 double nv = v / m_length + 0.5;
208 if (m_splitLength <= 0) return static_cast<int>(nv * m_vCells);
209 if (nv >= m_splitLength) return static_cast<int>((nv - m_splitLength) / (1 - m_splitLength) * m_vCells2) + m_vCells;
210 return static_cast<int>(nv / m_splitLength * m_vCells);
211 }
212
214 int getUCells() const { return m_uCells; }
216 int getVCells() const { return m_vCells + m_vCells2; }
218 int getVCells2() const { return m_vCells2; }
219
229 bool inside(double u, double v, double uTolerance = DBL_EPSILON, double vTolerance = DBL_EPSILON) const
230 {
231 double nu = u / (getWidth(v) + 2 * uTolerance) + 0.5;
232 double nv = v / (getLength() + 2 * vTolerance) + 0.5;
233 return 0 <= nu && nu <= 1 && 0 <= nv && nv <= 1;
234 }
235
243 bool inside(const ROOT::Math::XYZVector& local, double uTolerance = DBL_EPSILON, double vTolerance = DBL_EPSILON,
244 double wTolerance = DBL_EPSILON) const
245 {
246 double nw = local.Z() / (getThickness() + 2 * wTolerance) + 0.5;
247
248 return inside(local.X(), local.Y(), uTolerance, vTolerance) && 0 <= nw && nw <= 1;
249 }
250
255 void forceInside(double& u, double& v) const
256 {
257 double length = getLength() / 2.0;
258 v = std::min(length, std::max(-length, v));
259 double width = getWidth(v) / 2.0;
260 u = std::min(width, std::max(-width, u));
261 }
262
267 void forceInside(ROOT::Math::XYZVector& local) const;
268
274 ROOT::Math::XYZVector pointToGlobal(const ROOT::Math::XYZVector& local, bool reco = false) const;
275
281 ROOT::Math::XYZVector vectorToGlobal(const ROOT::Math::XYZVector& local, bool reco = false) const;
282
288 ROOT::Math::XYZVector pointToLocal(const ROOT::Math::XYZVector& global, bool reco = false) const;
289
295 ROOT::Math::XYZVector vectorToLocal(const ROOT::Math::XYZVector& global, bool reco = false) const;
296
301 void setTransformation(const TGeoHMatrix& transform, bool reco = false)
302 {
303 if (reco) m_recoTransform = transform;
304 else m_transform = transform;
305 }
306
311 const TGeoHMatrix& getTransformation(bool reco = false) const
312 {
313 if (reco) return m_recoTransform;
314 else return m_transform;
315 }
316
318 void setSurfaceParameters(const std::vector<double>& planarParameters)
319 {
320 m_surfaceDeformationParameters = planarParameters;
321 }
322
324 const std::vector<double>& getSurfaceParameters() const
325 {
327 }
328
329 protected:
333 unsigned short m_id;
335 double m_width;
337 double m_length;
351 TGeoHMatrix m_transform;
353 TGeoHMatrix m_recoTransform;
355 std::vector<double> m_surfaceDeformationParameters = std::vector<double>(12, 0.0);
356 };
357
358 inline void SensorInfoBase::forceInside(ROOT::Math::XYZVector& local) const
359 {
360 double u = local.X();
361 double v = local.Y();
362 double thickness = getThickness() / 2.0;
363 forceInside(u, v);
364 local.SetX(u);
365 local.SetY(v);
366 local.SetZ(std::min(thickness, std::max(-thickness, local.Z())));
367 }
368
369 inline ROOT::Math::XYZVector SensorInfoBase::pointToGlobal(const ROOT::Math::XYZVector& local, bool reco) const
370 {
371 double clocal[3];
372 double cmaster[3];
373 local.GetCoordinates(clocal);
374 if (reco) m_recoTransform.LocalToMaster(clocal, cmaster);
375 else m_transform.LocalToMaster(clocal, cmaster);
376 return ROOT::Math::XYZVector(cmaster[0], cmaster[1], cmaster[2]);
377 }
378
379 inline ROOT::Math::XYZVector SensorInfoBase::vectorToGlobal(const ROOT::Math::XYZVector& local, bool reco) const
380 {
381 double clocal[3];
382 double cmaster[3];
383 local.GetCoordinates(clocal);
384 if (reco) m_recoTransform.LocalToMasterVect(clocal, cmaster);
385 else m_transform.LocalToMasterVect(clocal, cmaster);
386 return ROOT::Math::XYZVector(cmaster[0], cmaster[1], cmaster[2]);
387 }
388
389 inline ROOT::Math::XYZVector SensorInfoBase::pointToLocal(const ROOT::Math::XYZVector& global, bool reco) const
390 {
391 double clocal[3];
392 double cmaster[3];
393 global.GetCoordinates(cmaster);
394 if (reco) m_recoTransform.MasterToLocal(cmaster, clocal);
395 else m_transform.MasterToLocal(cmaster, clocal);
396 return ROOT::Math::XYZVector(clocal[0], clocal[1], clocal[2]);
397 }
398
399 inline ROOT::Math::XYZVector SensorInfoBase::vectorToLocal(const ROOT::Math::XYZVector& global, bool reco) const
400 {
401 double clocal[3];
402 double cmaster[3];
403 global.GetCoordinates(cmaster);
404 if (reco) m_recoTransform.MasterToLocalVect(cmaster, clocal);
405 else m_transform.MasterToLocalVect(cmaster, clocal);
406 return ROOT::Math::XYZVector(clocal[0], clocal[1], clocal[2]);
407 }
408 }
410} //Belle2 namespace
Base class to provide Sensor Information for PXD and SVD.
double getVCellPosition(int vID) const
Return the position of a specific strip/pixel in v direction.
double getUPitch(double v=0) const
Return the pitch of the sensor.
double getVSize() const
Return the length of the sensor.
double getUCellPosition(int uID, int vID=-1) const
Return the position of a specific strip/pixel in u direction.
SensorInfoBase(SensorType type, VxdID id, double width, double length, double thickness, int uCells, int vCells, double width2=-1, double splitLength=-1, int vCells2=0)
Constructor for a SensorInfo instance.
ROOT::Math::XYZVector pointToLocal(const ROOT::Math::XYZVector &global, bool reco=false) const
Convert a point from global to local coordinates.
double getWSize() const
Return the thickness of the sensor.
SensorType getType() const
Return the Type of the Sensor.
ROOT::Math::XYZVector pointToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a point from local to global coordinates.
virtual ~SensorInfoBase()
Default constructor to make class polymorph.
TGeoHMatrix m_recoTransform
Alignment-corrected transformation matrix of the Sensor for use in reconstruction.
int getVCells() const
Return number of pixel/strips in v direction.
SensorType
Enum specifing the type of sensor the SensorInfo represents.
@ VXD
Any type of VXD Sensor.
@ TEL
Testbeam telescope sensor.
int getUCells() const
Return number of pixel/strips in u direction.
ROOT::Math::XYZVector vectorToLocal(const ROOT::Math::XYZVector &global, bool reco=false) const
Convert a vector from global to local coordinates.
bool inside(double u, double v, double uTolerance=DBL_EPSILON, double vTolerance=DBL_EPSILON) const
Check wether a given point is inside the active area.
double getWidth(double v=0) const
Return the width of the sensor.
bool inside(const ROOT::Math::XYZVector &local, double uTolerance=DBL_EPSILON, double vTolerance=DBL_EPSILON, double wTolerance=DBL_EPSILON) const
Check wether a given point is inside the active area.
double getForwardWidth() const
Convinience Wrapper to return width at forward side.
VxdID getID() const
Return the ID of the Sensor.
double getVPitch(double v=0) const
Return the pitch of the sensor.
double getBackwardWidth() const
Convinience Wrapper to return width at backward side.
double m_width
Width of the sensor.
std::vector< double > m_surfaceDeformationParameters
Vector contains all parameter needed for description planar deformation of sensors.
double m_thickness
Thickness of the Sensor.
void setTransformation(const TGeoHMatrix &transform, bool reco=false)
Set the transformation matrix of the Sensor.
int m_vCells
Number of strips/pixels in v direction (up to splitLength for two pixel sizes)
double getThickness() const
Return the thickness of the sensor.
unsigned short m_id
ID of the Sensor.
int getVPitchID(double v=0) const
Return the pitch ID of the sensor.
double m_deltaWidth
Difference between backward and forward width, 0 for rectangular sensors.
double getUSize(double v=0) const
Return the width of the sensor.
SensorType m_type
Type of the Sensor.
int getVCellID(double v, bool clamp=false) const
Return the corresponding pixel/strip ID of a given v coordinate.
const TGeoHMatrix & getTransformation(bool reco=false) const
Return the transformation matrix of the Sensor.
ROOT::Math::XYZVector vectorToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a vector from local to global coordinates.
int getVCells2() const
Return number of pixel/strips in v direction up to change pitch.
TGeoHMatrix m_transform
Nominal transformation matrix of the Sensor.
double m_length
Length of the Sensor.
void setSurfaceParameters(const std::vector< double > &planarParameters)
Fill parameters of planar deformation to vector.
int m_vCells2
Number of strips/pixels in v direction after splitLength, 0 for only one pixel size.
int getUCellID(double u, double v=0, bool clamp=false) const
Return the corresponding pixel/strip ID of a given u coordinate.
int m_uCells
Number of strips/pixels in u direction.
double m_splitLength
Relative length at which second pixel size starts, 0 for only one pixel size.
const std::vector< double > & getSurfaceParameters() const
Return parameters of planar deformation.
double getLength() const
Return the length of the sensor.
void forceInside(double &u, double &v) const
Force a position to be inside the active area.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Abstract base class for different kinds of events.