Belle II Software  release-06-02-00
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 #ifndef VXD_SENSORINFO_H
10 #define VXD_SENSORINFO_H
11 
12 #include <vxd/dataobjects/VxdID.h>
13 #include <float.h>
14 
15 #include <TGeoMatrix.h>
16 #include <TVector3.h>
17 
18 namespace Belle2 {
24  namespace VXD {
25 
31  public:
33  enum SensorType {
34  PXD = 0,
35  SVD = 1,
36  TEL = 2,
37  VXD = -1,
38  };
39 
61  SensorInfoBase(SensorType type, VxdID id, double width, double length, double thickness,
62  int uCells, int vCells, double width2 = -1, double splitLength = -1, int vCells2 = 0):
63  m_type(type), m_id(id), m_width(width), m_length(length), m_thickness(thickness),
64  m_deltaWidth(0), m_splitLength(0), m_uCells(uCells), m_vCells(vCells), m_vCells2(vCells2)
65  {
66  if (width2 > 0) m_deltaWidth = width2 - width;
67  if (splitLength > 0) m_splitLength = splitLength / length;
68  }
70  virtual ~SensorInfoBase() {}
71 
73  SensorType getType() const { return m_type; }
75  VxdID getID() const { return m_id; }
76 
81  double getWidth(double v = 0) const
82  {
83  if (m_deltaWidth == 0) return m_width;
84  return m_width + (v / m_length + 0.5) * m_deltaWidth;
85  }
86 
90  double getBackwardWidth() const
91  {
92  return getWidth(-0.5 * m_length);
93  }
94 
98  double getForwardWidth() const
99  {
100  return getWidth(0.5 * m_length);
101  }
102 
106  double getLength() const { return m_length; }
107 
111  double getThickness() const { return m_thickness; }
112 
117  double getUSize(double v = 0) const { return getWidth(v); }
118 
122  double getVSize() const { return getLength(); }
123 
127  double getWSize() const { return getThickness(); }
128 
133  double getUPitch(double v = 0) const { return getWidth(v) / m_uCells; }
134 
140  double getVPitch(double v = 0) const
141  {
142  if (m_splitLength <= 0) return m_length / m_vCells;
143  if (v / m_length + 0.5 >= m_splitLength) return m_length * (1 - m_splitLength) / m_vCells2;
144  return m_length * m_splitLength / m_vCells;
145  }
146 
157  int getVPitchID(double v = 0) const
158  {
159  if (m_splitLength <= 0) return 0;
160  if (v / m_length + 0.5 >= m_splitLength) return 0;
161  return 1;
162  }
163 
169  double getUCellPosition(int uID, int vID = -1) const
170  {
171  if (m_deltaWidth == 0) return ((uID + 0.5) / m_uCells - 0.5) * m_width;
172  double v = 0;
173  if (vID >= 0) v = getVCellPosition(vID);
174  return ((uID + 0.5) / m_uCells - 0.5) * getWidth(v);
175  }
176 
181  double getVCellPosition(int vID) const
182  {
183  if (m_splitLength <= 0) return ((vID + 0.5) / m_vCells - 0.5) * m_length;
184  if (vID >= m_vCells) return ((vID - m_vCells + 0.5) / m_vCells2 * (1 - m_splitLength) - 0.5 + m_splitLength) * m_length;
185  return ((vID + 0.5) / m_vCells * m_splitLength - 0.5) * m_length;
186  }
187 
194  int getUCellID(double u, double v = 0, bool clamp = false) const
195  {
196  if (clamp) return std::min(getUCells() - 1, std::max(0, getUCellID(u, v, false)));
197  return static_cast<int>((u / getWidth(v) + 0.5) * m_uCells);
198  }
199 
205  int getVCellID(double v, bool clamp = false) const
206  {
207  if (clamp) return std::min(getVCells() - 1, std::max(0, getVCellID(v, false)));
208  double nv = v / m_length + 0.5;
209  if (m_splitLength <= 0) return static_cast<int>(nv * m_vCells);
210  if (nv >= m_splitLength) return static_cast<int>((nv - m_splitLength) / (1 - m_splitLength) * m_vCells2) + m_vCells;
211  return static_cast<int>(nv / m_splitLength * m_vCells);
212  }
213 
215  int getUCells() const { return m_uCells; }
217  int getVCells() const { return m_vCells + m_vCells2; }
219  int getVCells2() const { return m_vCells2; }
220 
230  bool inside(double u, double v, double uTolerance = DBL_EPSILON, double vTolerance = DBL_EPSILON) const
231  {
232  double nu = u / (getWidth(v) + 2 * uTolerance) + 0.5;
233  double nv = v / (getLength() + 2 * vTolerance) + 0.5;
234  return 0 <= nu && nu <= 1 && 0 <= nv && nv <= 1;
235  }
236 
241  bool inside(const TVector3& local) const
242  {
243  double nw = local.z() / getThickness() + 0.5;
244  return inside(local.x(), local.y()) && 0 <= nw && nw <= 1;
245  }
246 
251  void forceInside(double& u, double& v) const
252  {
253  double length = getLength() / 2.0;
254  v = std::min(length, std::max(-length, v));
255  double width = getWidth(v) / 2.0;
256  u = std::min(width, std::max(-width, u));
257  }
258 
263  void forceInside(TVector3& local) const;
264 
270  TVector3 pointToGlobal(const TVector3& local, bool reco = false) const;
271 
277  TVector3 vectorToGlobal(const TVector3& local, bool reco = false) const;
278 
284  TVector3 pointToLocal(const TVector3& global, bool reco = false) const;
285 
291  TVector3 vectorToLocal(const TVector3& global, bool reco = false) const;
292 
297  void setTransformation(const TGeoHMatrix& transform, bool reco = false)
298  {
299  if (reco) m_recoTransform = transform;
300  else m_transform = transform;
301  }
302 
307  const TGeoHMatrix& getTransformation(bool reco = false) const
308  {
309  if (reco) return m_recoTransform;
310  else return m_transform;
311  }
312 
314  void setSurfaceParameters(const std::vector<double>& planarParameters)
315  {
316  m_surfaceDeformationParameters = planarParameters;
317  }
318 
320  const std::vector<double>& getSurfaceParameters() const
321  {
323  }
324 
325  protected:
329  unsigned short m_id;
331  double m_width;
333  double m_length;
335  double m_thickness;
337  double m_deltaWidth;
341  int m_uCells;
343  int m_vCells;
347  TGeoHMatrix m_transform;
349  TGeoHMatrix m_recoTransform;
351  std::vector<double> m_surfaceDeformationParameters = std::vector<double>(12, 0.0);
352  };
353 
354  inline void SensorInfoBase::forceInside(TVector3& local) const
355  {
356  double u = local.x();
357  double v = local.y();
358  double thickness = getThickness() / 2.0;
359  forceInside(u, v);
360  local.SetX(u);
361  local.SetY(v);
362  local.SetZ(std::min(thickness, std::max(-thickness, local.z())));
363  }
364 
365  inline TVector3 SensorInfoBase::pointToGlobal(const TVector3& local, bool reco) const
366  {
367  double clocal[3];
368  double cmaster[3];
369  local.GetXYZ(clocal);
370  if (reco) m_recoTransform.LocalToMaster(clocal, cmaster);
371  else m_transform.LocalToMaster(clocal, cmaster);
372  return TVector3(cmaster);
373  }
374 
375  inline TVector3 SensorInfoBase::vectorToGlobal(const TVector3& local, bool reco) const
376  {
377  double clocal[3];
378  double cmaster[3];
379  local.GetXYZ(clocal);
380  if (reco) m_recoTransform.LocalToMasterVect(clocal, cmaster);
381  else m_transform.LocalToMasterVect(clocal, cmaster);
382  return TVector3(cmaster);
383  }
384 
385  inline TVector3 SensorInfoBase::pointToLocal(const TVector3& global, bool reco) const
386  {
387  double clocal[3];
388  double cmaster[3];
389  global.GetXYZ(cmaster);
390  if (reco) m_recoTransform.MasterToLocal(cmaster, clocal);
391  else m_transform.MasterToLocal(cmaster, clocal);
392  return TVector3(clocal);
393  }
394 
395  inline TVector3 SensorInfoBase::vectorToLocal(const TVector3& global, bool reco) const
396  {
397  double clocal[3];
398  double cmaster[3];
399  global.GetXYZ(cmaster);
400  if (reco) m_recoTransform.MasterToLocalVect(cmaster, clocal);
401  else m_transform.MasterToLocalVect(cmaster, clocal);
402  return TVector3(clocal);
403  }
404  }
406 } //Belle2 namespace
407 #endif
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.
const std::vector< double > & getSurfaceParameters() const
Return parameters of planar deformation.
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.
double getWSize() const
Return the thickness of the sensor.
SensorType getType() const
Return the Type of the Sensor.
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.
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.
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.
TVector3 pointToLocal(const TVector3 &global, bool reco=false) const
Convert a point from global to local coordinates.
double m_width
Width of the sensor.
TVector3 pointToGlobal(const TVector3 &local, bool reco=false) const
Convert a point from local to global coordinates.
const TGeoHMatrix & getTransformation(bool reco=false) const
Return the transformation matrix of the Sensor.
std::vector< double > m_surfaceDeformationParameters
Vector contains all parameter needed for description planar deformation of sensors.
bool inside(const TVector3 &local) const
Check wether a given point is inside the active area.
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.
TVector3 vectorToGlobal(const TVector3 &local, bool reco=false) const
Convert a vector from local to global coordinates.
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.
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.
TVector3 vectorToLocal(const TVector3 &global, bool reco=false) const
Convert a vector from global to local coordinates.
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.
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.