Belle II Software  release-08-01-10
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 
17 namespace Belle2 {
23  namespace VXD {
24 
30  public:
32  enum SensorType {
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;
143  return m_length * m_splitLength / m_vCells;
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 
240  bool inside(const ROOT::Math::XYZVector& local) const
241  {
242  double nw = local.Z() / getThickness() + 0.5;
243  return inside(local.X(), local.Y()) && 0 <= nw && nw <= 1;
244  }
245 
250  void forceInside(double& u, double& v) const
251  {
252  double length = getLength() / 2.0;
253  v = std::min(length, std::max(-length, v));
254  double width = getWidth(v) / 2.0;
255  u = std::min(width, std::max(-width, u));
256  }
257 
262  void forceInside(ROOT::Math::XYZVector& local) const;
263 
269  ROOT::Math::XYZVector pointToGlobal(const ROOT::Math::XYZVector& local, bool reco = false) const;
270 
276  ROOT::Math::XYZVector vectorToGlobal(const ROOT::Math::XYZVector& local, bool reco = false) const;
277 
283  ROOT::Math::XYZVector pointToLocal(const ROOT::Math::XYZVector& global, bool reco = false) const;
284 
290  ROOT::Math::XYZVector vectorToLocal(const ROOT::Math::XYZVector& global, bool reco = false) const;
291 
296  void setTransformation(const TGeoHMatrix& transform, bool reco = false)
297  {
298  if (reco) m_recoTransform = transform;
299  else m_transform = transform;
300  }
301 
306  const TGeoHMatrix& getTransformation(bool reco = false) const
307  {
308  if (reco) return m_recoTransform;
309  else return m_transform;
310  }
311 
313  void setSurfaceParameters(const std::vector<double>& planarParameters)
314  {
315  m_surfaceDeformationParameters = planarParameters;
316  }
317 
319  const std::vector<double>& getSurfaceParameters() const
320  {
322  }
323 
324  protected:
328  unsigned short m_id;
330  double m_width;
332  double m_length;
334  double m_thickness;
336  double m_deltaWidth;
340  int m_uCells;
342  int m_vCells;
346  TGeoHMatrix m_transform;
348  TGeoHMatrix m_recoTransform;
350  std::vector<double> m_surfaceDeformationParameters = std::vector<double>(12, 0.0);
351  };
352 
353  inline void SensorInfoBase::forceInside(ROOT::Math::XYZVector& local) const
354  {
355  double u = local.X();
356  double v = local.Y();
357  double thickness = getThickness() / 2.0;
358  forceInside(u, v);
359  local.SetX(u);
360  local.SetY(v);
361  local.SetZ(std::min(thickness, std::max(-thickness, local.Z())));
362  }
363 
364  inline ROOT::Math::XYZVector SensorInfoBase::pointToGlobal(const ROOT::Math::XYZVector& local, bool reco) const
365  {
366  double clocal[3];
367  double cmaster[3];
368  local.GetCoordinates(clocal);
369  if (reco) m_recoTransform.LocalToMaster(clocal, cmaster);
370  else m_transform.LocalToMaster(clocal, cmaster);
371  return ROOT::Math::XYZVector(cmaster[0], cmaster[1], cmaster[2]);
372  }
373 
374  inline ROOT::Math::XYZVector SensorInfoBase::vectorToGlobal(const ROOT::Math::XYZVector& local, bool reco) const
375  {
376  double clocal[3];
377  double cmaster[3];
378  local.GetCoordinates(clocal);
379  if (reco) m_recoTransform.LocalToMasterVect(clocal, cmaster);
380  else m_transform.LocalToMasterVect(clocal, cmaster);
381  return ROOT::Math::XYZVector(cmaster[0], cmaster[1], cmaster[2]);
382  }
383 
384  inline ROOT::Math::XYZVector SensorInfoBase::pointToLocal(const ROOT::Math::XYZVector& global, bool reco) const
385  {
386  double clocal[3];
387  double cmaster[3];
388  global.GetCoordinates(cmaster);
389  if (reco) m_recoTransform.MasterToLocal(cmaster, clocal);
390  else m_transform.MasterToLocal(cmaster, clocal);
391  return ROOT::Math::XYZVector(clocal[0], clocal[1], clocal[2]);
392  }
393 
394  inline ROOT::Math::XYZVector SensorInfoBase::vectorToLocal(const ROOT::Math::XYZVector& global, bool reco) const
395  {
396  double clocal[3];
397  double cmaster[3];
398  global.GetCoordinates(cmaster);
399  if (reco) m_recoTransform.MasterToLocalVect(cmaster, clocal);
400  else m_transform.MasterToLocalVect(cmaster, clocal);
401  return ROOT::Math::XYZVector(clocal[0], clocal[1], clocal[2]);
402  }
403  }
405 } //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.
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.
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.
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.
bool inside(const ROOT::Math::XYZVector &local) const
Check wether a given point is inside the active area.
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.
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.
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.
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.