Belle II Software  release-05-01-25
DATCONSVDSpacePoint.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Christian Wessel *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/dataobjects/DATCONSVDSpacePoint.h>
12 
13 using namespace std;
14 using namespace Belle2;
15 
16 //---SVD related constructor---
17 DATCONSVDSpacePoint::DATCONSVDSpacePoint(std::vector<const SVDCluster*>& clusters,
18  const VXD::SensorInfoBase* aSensorInfo)
19 {
20  //---The following contains only sanity checks without effect, if nobody gave buggy information---
21  //We have 1 or two SVD Clusters.
22  B2ASSERT("You have to insert 1 or two SVD Clusters, but gave: " << clusters.size(), ((clusters.size() == 1)
23  || (clusters.size() == 2)));
24 
25  //No cluster pointer is a nullptr.
26  for (auto && cluster : clusters) {
27  B2ASSERT("An (DATCON)SVDCluster Pointer is a nullptr!", cluster != nullptr);
28  }
29 
30  //In case of 2 clusters, they are compatible with each other.
31  if (clusters.size() == 2) {
32  B2ASSERT("Clusters are on different Sensors.", clusters[0]->getSensorID() == clusters[1]->getSensorID());
33  B2ASSERT("Clusters are of same direction type.", clusters[0]->isUCluster() != clusters[1]->isUCluster());
34  }
35  //---End sanity checks---
36 
37  m_vxdID = clusters[0]->getSensorID();
38 
39  //We need some handle to translate IDs to local and global coordinates.
40  if (aSensorInfo == NULL) {
41  aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(m_vxdID);
42  }
43 
44  m_sensorType = aSensorInfo->getType();
45 
46  // retrieve position and sigma-values
47  double uCoord = 0; // 0 = center of Sensor
48  double vCoord = 0; // 0 = center of Sensor
49  m_assignedDATCONSVDClusters.clear();
50 
51  const SVDCluster* vCluster(NULL), *uCluster(NULL);
52  for (const SVDCluster* aCluster : clusters) {
53  m_assignedDATCONSVDClusters.push_back(*aCluster);
54  if (aCluster->isUCluster() == true) {
55  m_clustersAssigned.first = true;
56  uCoord = aCluster->getPosition();
57  uCluster = aCluster;
58  } else {
59  m_clustersAssigned.second = true;
60  vCoord = aCluster->getPosition();
61  vCluster = aCluster;
62  }
63  }
64 
65  if (aSensorInfo->getBackwardWidth() > aSensorInfo->getForwardWidth() &&
66  vCluster != NULL && uCluster != NULL) // is a WedgeSensor and we do have a vCluster
67  uCoord = uCluster->getPosition(vCoord);
68 
69  m_position = aSensorInfo->pointToGlobal(TVector3(uCoord, vCoord, 0));
70  m_normalizedLocal = convertLocalToNormalizedCoordinates({ uCoord, vCoord } , m_vxdID, aSensorInfo);
71 
72 }
73 
74 
75 std::pair<double, double> DATCONSVDSpacePoint::convertLocalToNormalizedCoordinates(
76  const std::pair<double, double>& hitLocal, VxdID vxdID,
77  const VXD::SensorInfoBase* aSensorInfo)
78 {
79  //We need some handle to translate IDs to local and global
80  // coordinates.
81  if (aSensorInfo == NULL) {
82  aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID);
83  }
84 
85  //As the 0 is in the middle of sensor in the geometry, and we want
86  // to normalize all positions to numbers between [0,1],
87  // where the middle will be 0.5,
88  // we need to do some calculation.
89  double sensorSizeU = aSensorInfo->getUSize(hitLocal.second); // this deals with the case of trapezoidal sensors too
90  double sensorSizeV = aSensorInfo->getVSize();
91 
92  double normalizedUPosition = (hitLocal.first + 0.5 * sensorSizeU) /
93  sensorSizeU; // indepedent of the trapezoidal sensor-issue by definition
94  double normalizedVPosition = (hitLocal.second + 0.5 * sensorSizeV) / sensorSizeV;
95 
96  boundaryEnforce(normalizedUPosition, normalizedVPosition, 0, 1 , 0, vxdID);
97  boundaryEnforce(normalizedVPosition, normalizedUPosition, 0, 1, 1, vxdID);
98 
99  return { normalizedUPosition, normalizedVPosition };
100 }
101 
102 
103 
104 std::pair<double, double> DATCONSVDSpacePoint::convertNormalizedToLocalCoordinates(
105  const std::pair<double, double>& hitNormalized, VxdID vxdID,
106  const VXD::SensorInfoBase* aSensorInfo)
107 {
108  //We need some handle to translate IDs to local and global
109  // coordinates.
110  if (aSensorInfo == NULL) {
111  aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID);
112  }
113 
114  // normalized coordinate range is from 0 to 1
115  // local coordinate range is from - halfSensorSize to + halfSensorSize
116  double localVPosition = (hitNormalized.second - 0.5) * aSensorInfo->getVSize();
117  double uSizeAtHit = aSensorInfo->getUSize(localVPosition);
118  double localUPosition = (hitNormalized.first - 0.5) * uSizeAtHit;
119 
120  boundaryEnforce(localVPosition, localUPosition,
121  -0.5 * aSensorInfo->getVSize(), 0.5 * aSensorInfo->getVSize(), 1, vxdID); // restrain hits to sensor boundaries
122 
123  boundaryEnforce(localUPosition, localVPosition, -0.5 * uSizeAtHit, 0.5 * uSizeAtHit,
124  0, vxdID); // restrain hits to sensor boundaries
125 
126  return { localUPosition, localVPosition };
127 }
128 
129 
130 B2Vector3<double> DATCONSVDSpacePoint::getGlobalCoordinates(std::pair<double, double> const& hitLocal, VxdID vxdID,
131  VXD::SensorInfoBase const* aSensorInfo)
132 {
133  //We need some handle to translate IDs to local and global coordinates.
134  if (aSensorInfo == NULL) {
135  aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID);
136  }
137 
138  return aSensorInfo->pointToGlobal(TVector3(hitLocal.first, hitLocal.second, 0));
139 }
Belle2::VXD::SensorInfoBase::getForwardWidth
double getForwardWidth() const
Convinience Wrapper to return width at forward side.
Definition: SensorInfoBase.h:108
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::VXD::SensorInfoBase
Base class to provide Sensor Information for PXD and SVD.
Definition: SensorInfoBase.h:40
Belle2::B2Vector3< double >
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
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
Belle2::SVDCluster::getPosition
float getPosition(double v=0) const
Get the coordinate of reconstructed hit.
Definition: SVDCluster.h:125
Belle2::SVDCluster
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:38
Belle2::VXD::SensorInfoBase::getType
SensorType getType() const
Return the Type of the Sensor.
Definition: SensorInfoBase.h:83
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