Belle II Software  release-05-02-19
SensorInfoBase.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef VXD_SENSORINFO_H
12 #define VXD_SENSORINFO_H
13 
14 #include <vxd/dataobjects/VxdID.h>
15 #include <float.h>
16 
17 #include <TGeoMatrix.h>
18 #include <TVector3.h>
19 
20 namespace Belle2 {
26  namespace VXD {
27 
32  class SensorInfoBase {
33  public:
35  enum SensorType {
36  PXD = 0,
37  SVD = 1,
38  TEL = 2,
39  VXD = -1,
40  };
41 
63  SensorInfoBase(SensorType type, VxdID id, double width, double length, double thickness,
64  int uCells, int vCells, double width2 = -1, double splitLength = -1, int vCells2 = 0):
65  m_type(type), m_id(id), m_width(width), m_length(length), m_thickness(thickness),
66  m_deltaWidth(0), m_splitLength(0), m_uCells(uCells), m_vCells(vCells), m_vCells2(vCells2)
67  {
68  if (width2 > 0) m_deltaWidth = width2 - width;
69  if (splitLength > 0) m_splitLength = splitLength / length;
70  }
72  virtual ~SensorInfoBase() {}
73 
75  SensorType getType() const { return m_type; }
77  VxdID getID() const { return m_id; }
78 
83  double getWidth(double v = 0) const
84  {
85  if (m_deltaWidth == 0) return m_width;
86  return m_width + (v / m_length + 0.5) * m_deltaWidth;
87  }
88 
92  double getBackwardWidth() const
93  {
94  return getWidth(-0.5 * m_length);
95  }
96 
100  double getForwardWidth() const
101  {
102  return getWidth(0.5 * m_length);
103  }
104 
108  double getLength() const { return m_length; }
109 
113  double getThickness() const { return m_thickness; }
114 
119  double getUSize(double v = 0) const { return getWidth(v); }
120 
124  double getVSize() const { return getLength(); }
125 
129  double getWSize() const { return getThickness(); }
130 
135  double getUPitch(double v = 0) const { return getWidth(v) / m_uCells; }
136 
142  double getVPitch(double v = 0) const
143  {
144  if (m_splitLength <= 0) return m_length / m_vCells;
145  if (v / m_length + 0.5 >= m_splitLength) return m_length * (1 - m_splitLength) / m_vCells2;
146  return m_length * m_splitLength / m_vCells;
147  }
148 
159  int getVPitchID(double v = 0) const
160  {
161  if (m_splitLength <= 0) return 0;
162  if (v / m_length + 0.5 >= m_splitLength) return 0;
163  return 1;
164  }
165 
171  double getUCellPosition(int uID, int vID = -1) const
172  {
173  if (m_deltaWidth == 0) return ((uID + 0.5) / m_uCells - 0.5) * m_width;
174  double v = 0;
175  if (vID >= 0) v = getVCellPosition(vID);
176  return ((uID + 0.5) / m_uCells - 0.5) * getWidth(v);
177  }
178 
183  double getVCellPosition(int vID) const
184  {
185  if (m_splitLength <= 0) return ((vID + 0.5) / m_vCells - 0.5) * m_length;
186  if (vID >= m_vCells) return ((vID - m_vCells + 0.5) / m_vCells2 * (1 - m_splitLength) - 0.5 + m_splitLength) * m_length;
187  return ((vID + 0.5) / m_vCells * m_splitLength - 0.5) * m_length;
188  }
189 
195  int getUCellID(double u, double v = 0, bool clamp = false) const
196  {
197  if (clamp) return std::min(getUCells() - 1, std::max(0, getUCellID(u, v, false)));
198  return static_cast<int>((u / getWidth(v) + 0.5) * m_uCells);
199  }
200 
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
Belle2::VXD::SensorInfoBase::getForwardWidth
double getForwardWidth() const
Convinience Wrapper to return width at forward side.
Definition: SensorInfoBase.h:108
Belle2::VXD::SensorInfoBase::m_recoTransform
TGeoHMatrix m_recoTransform
Alignment-corrected transformation matrix of the Sensor for use in reconstruction.
Definition: SensorInfoBase.h:357
Belle2::VXD::SensorInfoBase::m_vCells
int m_vCells
Number of strips/pixels in v direction (up to splitLength for two pixel sizes)
Definition: SensorInfoBase.h:351
Belle2::VXD::SensorInfoBase::getSurfaceParameters
const std::vector< double > & getSurfaceParameters() const
Return parameters of planar deformation.
Definition: SensorInfoBase.h:328
Belle2::VXD::SensorInfoBase::getUCells
int getUCells() const
Return number of pixel/strips in u direction.
Definition: SensorInfoBase.h:223
Belle2::VXD::SensorInfoBase::m_uCells
int m_uCells
Number of strips/pixels in u direction.
Definition: SensorInfoBase.h:349
Belle2::VXD::SensorInfoBase::m_surfaceDeformationParameters
std::vector< double > m_surfaceDeformationParameters
Vector contains all parameter needed for description planar deformation of sensors.
Definition: SensorInfoBase.h:359
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::VXD::SensorInfoBase::SensorType
SensorType
Enum specifing the type of sensor the SensorInfo represents.
Definition: SensorInfoBase.h:43
Belle2::VXD::SensorInfoBase::getUCellID
int getUCellID(double u, double v=0, bool clamp=false) const
Return the corresponding pixel/strip ID of a given u coordinate.
Definition: SensorInfoBase.h:203
Belle2::VXD::SensorInfoBase::m_id
unsigned short m_id
ID of the Sensor.
Definition: SensorInfoBase.h:337
Belle2::VXD::SensorInfoBase::~SensorInfoBase
virtual ~SensorInfoBase()
Default constructor to make class polymorph.
Definition: SensorInfoBase.h:80
Belle2::VXD::SensorInfoBase::getTransformation
const TGeoHMatrix & getTransformation(bool reco=false) const
Return the transformation matrix of the Sensor.
Definition: SensorInfoBase.h:315
Belle2::VXD::SensorInfoBase::setSurfaceParameters
void setSurfaceParameters(const std::vector< double > &planarParameters)
Fill parameters of planar deformation to vector.
Definition: SensorInfoBase.h:322
Belle2::VXD::SensorInfoBase::vectorToGlobal
TVector3 vectorToGlobal(const TVector3 &local, bool reco=false) const
Convert a vector from local to global coordinates.
Definition: SensorInfoBase.h:383
Belle2::VXD::SensorInfoBase::VXD
@ VXD
Any type of VXD Sensor.
Definition: SensorInfoBase.h:47
Belle2::VXD::SensorInfoBase::m_width
double m_width
Width of the sensor.
Definition: SensorInfoBase.h:339
Belle2::VXD::SensorInfoBase::getWidth
double getWidth(double v=0) const
Return the width of the sensor.
Definition: SensorInfoBase.h:91
Belle2::VXD::SensorInfoBase::getID
VxdID getID() const
Return the ID of the Sensor.
Definition: SensorInfoBase.h:85
Belle2::VXD::SensorInfoBase::getVPitchID
int getVPitchID(double v=0) const
Return the pitch ID of the sensor.
Definition: SensorInfoBase.h:167
Belle2::VXD::SensorInfoBase::getVPitch
double getVPitch(double v=0) const
Return the pitch of the sensor.
Definition: SensorInfoBase.h:150
Belle2::VXD::SensorInfoBase::m_type
SensorType m_type
Type of the Sensor.
Definition: SensorInfoBase.h:335
Belle2::VXD::SensorInfoBase::forceInside
void forceInside(double &u, double &v) const
Force a position to be inside the active area.
Definition: SensorInfoBase.h:259
Belle2::VXD::SensorInfoBase::getLength
double getLength() const
Return the length of the sensor.
Definition: SensorInfoBase.h:116
Belle2::VXD::SensorInfoBase::SensorInfoBase
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.
Definition: SensorInfoBase.h:71
Belle2::VXD::SensorInfoBase::setTransformation
void setTransformation(const TGeoHMatrix &transform, bool reco=false)
Set the transformation matrix of the Sensor.
Definition: SensorInfoBase.h:305
Belle2::VXD::SensorInfoBase::getVCellID
int getVCellID(double v, bool clamp=false) const
Return the corresponding pixel/strip ID of a given v coordinate.
Definition: SensorInfoBase.h:213
Belle2::VXD::SensorInfoBase::getVCellPosition
double getVCellPosition(int vID) const
Return the position of a specific strip/pixel in v direction.
Definition: SensorInfoBase.h:191
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXD::SensorInfoBase::getThickness
double getThickness() const
Return the thickness of the sensor.
Definition: SensorInfoBase.h:121
Belle2::VXD::SensorInfoBase::getVCells
int getVCells() const
Return number of pixel/strips in v direction.
Definition: SensorInfoBase.h:225
Belle2::VXD::SensorInfoBase::m_splitLength
double m_splitLength
Relative length at which second pixel size starts, 0 for only one pixel size.
Definition: SensorInfoBase.h:347
Belle2::VXD::SensorInfoBase::SVD
@ SVD
SVD Sensor.
Definition: SensorInfoBase.h:45
Belle2::VXD::SensorInfoBase::getUSize
double getUSize(double v=0) const
Return the width of the sensor.
Definition: SensorInfoBase.h:127
Belle2::VXD::SensorInfoBase::pointToGlobal
TVector3 pointToGlobal(const TVector3 &local, bool reco=false) const
Convert a point from local to global coordinates.
Definition: SensorInfoBase.h:373
prepareAsicCrosstalkSimDB.u
u
merged u1 and u2
Definition: prepareAsicCrosstalkSimDB.py:46
Belle2::VXD::SensorInfoBase::getWSize
double getWSize() const
Return the thickness of the sensor.
Definition: SensorInfoBase.h:137
Belle2::VXD::SensorInfoBase::pointToLocal
TVector3 pointToLocal(const TVector3 &global, bool reco=false) const
Convert a point from global to local coordinates.
Definition: SensorInfoBase.h:393
Belle2::VXD::SensorInfoBase::getUPitch
double getUPitch(double v=0) const
Return the pitch of the sensor.
Definition: SensorInfoBase.h:143
Belle2::VXD::SensorInfoBase::m_transform
TGeoHMatrix m_transform
Nominal transformation matrix of the Sensor.
Definition: SensorInfoBase.h:355
Belle2::VXD::SensorInfoBase::getVCells2
int getVCells2() const
Return number of pixel/strips in v direction up to change pitch.
Definition: SensorInfoBase.h:227
Belle2::VXD::SensorInfoBase::TEL
@ TEL
Testbeam telescope sensor.
Definition: SensorInfoBase.h:46
Belle2::VXD::SensorInfoBase::PXD
@ PXD
PXD Sensor.
Definition: SensorInfoBase.h:44
Belle2::VXD::SensorInfoBase::getType
SensorType getType() const
Return the Type of the Sensor.
Definition: SensorInfoBase.h:83
Belle2::VXD::SensorInfoBase::m_thickness
double m_thickness
Thickness of the Sensor.
Definition: SensorInfoBase.h:343
Belle2::VXD::SensorInfoBase::m_vCells2
int m_vCells2
Number of strips/pixels in v direction after splitLength, 0 for only one pixel size.
Definition: SensorInfoBase.h:353
Belle2::VXD::SensorInfoBase::vectorToLocal
TVector3 vectorToLocal(const TVector3 &global, bool reco=false) const
Convert a vector from global to local coordinates.
Definition: SensorInfoBase.h:403
Belle2::VXD::SensorInfoBase::getUCellPosition
double getUCellPosition(int uID, int vID=-1) const
Return the position of a specific strip/pixel in u direction.
Definition: SensorInfoBase.h:179
Belle2::VXD::SensorInfoBase::getVSize
double getVSize() const
Return the length of the sensor.
Definition: SensorInfoBase.h:132
Belle2::VXD::SensorInfoBase::getBackwardWidth
double getBackwardWidth() const
Convinience Wrapper to return width at backward side.
Definition: SensorInfoBase.h:100
Belle2::VXD::SensorInfoBase::m_length
double m_length
Length of the Sensor.
Definition: SensorInfoBase.h:341
Belle2::VXD::SensorInfoBase::inside
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.
Definition: SensorInfoBase.h:238
Belle2::VXD::SensorInfoBase::m_deltaWidth
double m_deltaWidth
Difference between backward and forward width, 0 for rectangular sensors.
Definition: SensorInfoBase.h:345