Belle II Software  release-06-02-00
SpacePoint.cc
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 #include <tracking/spacePointCreation/SpacePoint.h>
10 #include <vxd/dataobjects/VxdID.h>
11 #include <pxd/reconstruction/PXDRecoHit.h>
12 #include <svd/reconstruction/SVDRecoHit.h>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 //---PXD related constructor---
18 SpacePoint::SpacePoint(const PXDCluster* pxdCluster,
19  const VXD::SensorInfoBase* aSensorInfo) : m_clustersAssigned( {true, true}), m_vxdID(pxdCluster->getSensorID())
20 {
21  //We need some handle to translate IDs to local and global coordinates.
22  //aSensorInfo exists only for testing purposes, so this is the relevant case!
23  if (aSensorInfo == nullptr) {
24  aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(m_vxdID);
25  }
26 
27  // the second parameter set to true results in alignment constants being applied
28  m_position = aSensorInfo->pointToGlobal(TVector3(pxdCluster->getU(), pxdCluster->getV(), 0), true);
29 
30  setPositionError(pxdCluster->getUSigma(), pxdCluster->getVSigma(), aSensorInfo);
31 
32  m_normalizedLocal = convertLocalToNormalizedCoordinates({ pxdCluster->getU(), pxdCluster->getV() },
33  m_vxdID, aSensorInfo);
34 
35  m_sensorType = aSensorInfo->getType();
36 }
37 
38 
39 //---SVD related constructor---
40 SpacePoint::SpacePoint(std::vector<const SVDCluster*>& clusters,
41  const VXD::SensorInfoBase* aSensorInfo)
42 {
43  //---The following contains only sanity checks without effect, if nobody gave buggy information---
44  //We have 1 or two SVD Clusters.
45  B2ASSERT("You have to insert 1 or two SVD Clusters, but gave: " << clusters.size(), ((clusters.size() == 1)
46  || (clusters.size() == 2)));
47 
48  //No cluster pointer is a nullptr.
49  for (auto && cluster : clusters) {
50  B2ASSERT("An SVDCluster Pointer is a nullptr!", cluster != nullptr);
51  }
52 
53  //In case of 2 clusters, they are compatible with each other.
54  if (clusters.size() == 2) {
55  B2ASSERT("Clusters are on different Sensors.", clusters[0]->getSensorID() == clusters[1]->getSensorID());
56  B2ASSERT("Clusters are of same direction type.", clusters[0]->isUCluster() != clusters[1]->isUCluster());
57  }
58  //---End sanity checks---
59 
60  m_vxdID = clusters[0]->getSensorID();
61 
62  //We need some handle to translate IDs to local and global coordinates.
63  if (aSensorInfo == nullptr) {
65  }
66 
67  m_sensorType = aSensorInfo->getType();
68 
69  // retrieve position and sigma-values
70  double uCoord = 0; // 0 = center of Sensor
71  double vCoord = 0; // 0 = center of Sensor
72  double uSigma = -1; // negative sigmas are not possible, setting to -1 for catching cases of missing Cluster
73  double vSigma = -1; // negative sigmas are not possible, setting to -1 for catching cases of missing Cluster
74 
75  const SVDCluster* vCluster(nullptr), *uCluster(nullptr);
76  for (const SVDCluster* aCluster : clusters) {
77  if (aCluster->isUCluster() == true) {
78  m_clustersAssigned.first = true;
79  uCoord = aCluster->getPosition();
80  uSigma = aCluster->getPositionSigma();
81  uCluster = aCluster;
82  } else {
83  m_clustersAssigned.second = true;
84  vCoord = aCluster->getPosition();
85  vSigma = aCluster->getPositionSigma();
86  vCluster = aCluster;
87  }
88  }
89 
90  if (aSensorInfo->getBackwardWidth() > aSensorInfo->getForwardWidth() &&
91  vCluster != nullptr && uCluster != nullptr) // is a WedgeSensor and we do have a vCluster
92  uCoord = uCluster->getPosition(vCoord);
93 
94  // the second parameter set to true results in alignment constants being applied
95  m_position = aSensorInfo->pointToGlobal(TVector3(uCoord, vCoord, 0), true);
96  m_normalizedLocal = convertLocalToNormalizedCoordinates({ uCoord, vCoord } , m_vxdID, aSensorInfo);
97 
98  // if sigma for a coordinate is not known, a uniform distribution over the whole sensor is asumed:
99  if (uSigma < 0) {
100  uSigma = aSensorInfo->getUSize(vCoord) / sqrt(12.);
101  }
102  if (vSigma < 0) {
103  vSigma = aSensorInfo->getVSize() / sqrt(12.);
104  }
105 
106  setPositionError(uSigma, vSigma, aSensorInfo);
107 
108  //retrieve and set hit times
109  for (const SVDCluster* aCluster : clusters)
110  if (aCluster->isUCluster() == true)
111  m_UClusterTime = aCluster->getClsTime();
112  else
113  m_VClusterTime = aCluster->getClsTime();
114 
115 }
116 
117 
118 vector< genfit::PlanarMeasurement > SpacePoint::getGenfitCompatible() const
119 {
120  // XYRecoHit will be stored as their base-class, which is detector-independent.
121  vector< genfit::PlanarMeasurement > collectedMeasurements;
122 
123 
124  // get the related clusters to this spacePoint and create a genfit::PlanarMeasurement for each of them:
125  if (getType() == VXD::SensorInfoBase::SensorType::SVD) {
126 
127  auto relatedClusters = this->getRelationsTo<SVDCluster>("ALL");
128  for (unsigned i = 0; i < relatedClusters.size(); i++) {
129  collectedMeasurements.push_back(SVDRecoHit(relatedClusters[i]));
130  }
131 
132  } else if (getType() == VXD::SensorInfoBase::SensorType::PXD) {
133 
134  // since we do not know the name of the attached PXDCluster, getRelatedTo does not work, however, getRelationsTo seems to be less sensible and therefore can be used, but in this case, one has to loop over the entries (which should be only one in this case)
135  auto relatedClusters = this->getRelationsTo<PXDCluster>("ALL");
136  for (unsigned i = 0; i < relatedClusters.size(); i++) {
137  collectedMeasurements.push_back(PXDRecoHit(relatedClusters[i]));
138  }
139 
140  } else {
141  B2FATAL("unknown detector type");
142  }
143 
144  B2DEBUG(50, "SpacePoint::getGenfitCompatible(): collected " << collectedMeasurements.size() << " meaturements");
145 
146  return collectedMeasurements;
147 }
148 
149 
151  const std::pair<double, double>& hitLocal, VxdID vxdID,
152  const VXD::SensorInfoBase* aSensorInfo)
153 {
154  //We need some handle to translate IDs to local and global
155  // coordinates.
156  if (aSensorInfo == nullptr) {
157  aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID);
158  }
159 
160  //As the 0 is in the middle of sensor in the geometry, and we want
161  // to normalize all positions to numbers between [0,1],
162  // where the middle will be 0.5,
163  // we need to do some calculation.
164  double sensorSizeU = aSensorInfo->getUSize(hitLocal.second); // this deals with the case of trapezoidal sensors too
165  double sensorSizeV = aSensorInfo->getVSize();
166 
167  double normalizedUPosition = (hitLocal.first + 0.5 * sensorSizeU) /
168  sensorSizeU; // indepedent of the trapezoidal sensor-issue by definition
169  double normalizedVPosition = (hitLocal.second + 0.5 * sensorSizeV) / sensorSizeV;
170 
171  boundaryEnforce(normalizedUPosition, normalizedVPosition, 0, 1 , 0, vxdID);
172  boundaryEnforce(normalizedVPosition, normalizedUPosition, 0, 1, 1, vxdID);
173 
174  return { normalizedUPosition, normalizedVPosition };
175 }
176 
177 
178 
180  const std::pair<double, double>& hitNormalized, VxdID vxdID,
181  const VXD::SensorInfoBase* aSensorInfo)
182 {
183  //We need some handle to translate IDs to local and global
184  // coordinates.
185  if (aSensorInfo == nullptr) {
186  aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID);
187  }
188 
189  // normalized coordinate range is from 0 to 1
190  // local coordinate range is from - halfSensorSize to + halfSensorSize
191  double localVPosition = (hitNormalized.second - 0.5) * aSensorInfo->getVSize();
192  double uSizeAtHit = aSensorInfo->getUSize(localVPosition);
193  double localUPosition = (hitNormalized.first - 0.5) * uSizeAtHit;
194 
195  boundaryEnforce(localVPosition, localUPosition,
196  -0.5 * aSensorInfo->getVSize(), 0.5 * aSensorInfo->getVSize(), 1, vxdID); // restrain hits to sensor boundaries
197 
198  boundaryEnforce(localUPosition, localVPosition, -0.5 * uSizeAtHit, 0.5 * uSizeAtHit,
199  0, vxdID); // restrain hits to sensor boundaries
200 
201  return { localUPosition, localVPosition };
202 }
203 
204 
205 B2Vector3<double> SpacePoint::getGlobalCoordinates(std::pair<double, double> const& hitLocal, VxdID vxdID,
206  VXD::SensorInfoBase const* aSensorInfo)
207 {
208  //We need some handle to translate IDs to local and global coordinates.
209  if (aSensorInfo == nullptr) {
210  aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID);
211  }
212 
213  // the second parameter set to true results in alignment constants being applied
214  return aSensorInfo->pointToGlobal(TVector3(hitLocal.first, hitLocal.second, 0), true);
215 }
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
PXDRecoHit - an extended form of PXDCluster containing geometry information.
Definition: PXDRecoHit.h:49
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:28
float getPosition(double v=0) const
Get the coordinate of reconstructed hit.
Definition: SVDCluster.h:116
SVDRecoHit - an extended form of SVDHit containing geometry information.
Definition: SVDRecoHit.h:47
double m_VClusterTime
Time of the cluster on the V side in ns.
Definition: SpacePoint.h:362
static void boundaryEnforce(double &value, const double &otherValue, double lower=0, double higher=1, unsigned int side=0, VxdID vxdID=VxdID())
Enforce 'value' in the range ['lower', 'higher'].
Definition: SpacePoint.h:296
std::pair< bool, bool > m_clustersAssigned
The bool value is true, when correct information of the coordinate exists.
Definition: SpacePoint.h:370
VXD::SensorInfoBase::SensorType m_sensorType
Stores the SensorType using the scheme of SensorInfoBase.
Definition: SpacePoint.h:380
B2Vector3< double > m_position
Global position vector.
Definition: SpacePoint.h:341
double m_UClusterTime
Time of the cluster on the U side in ns.
Definition: SpacePoint.h:358
SpacePoint()
Default constructor for the ROOT IO.
Definition: SpacePoint.h:63
void setPositionError(double uSigma, double vSigma, const VXD::SensorInfoBase *aSensorInfo)
Setter for global position error from on-sensor sigmas.
Definition: SpacePoint.h:322
static std::pair< double, double > convertLocalToNormalizedCoordinates(const std::pair< double, double > &hitLocal, VxdID vxdID, const VXD::SensorInfoBase *aSensorInfo=nullptr)
converts a local hit into sensor-independent relative coordinates.
Definition: SpacePoint.cc:150
VxdID::baseType m_vxdID
Stores the VxdID.
Definition: SpacePoint.h:373
Belle2::VXD::SensorInfoBase::SensorType getType() const
Return SensorType (PXD, SVD, ...) on which the SpacePoint lives.
Definition: SpacePoint.h:145
static std::pair< double, double > convertNormalizedToLocalCoordinates(const std::pair< double, double > &hitNormalized, Belle2::VxdID vxdID, const Belle2::VXD::SensorInfoBase *aSensorInfo=nullptr)
converts a hit in sensor-independent relative coordinates into local coordinate of given sensor.
Definition: SpacePoint.cc:179
static B2Vector3< double > getGlobalCoordinates(const std::pair< double, double > &hitLocal, VxdID vxdID, const VXD::SensorInfoBase *aSensorInfo=nullptr)
converts a local hit on a given sensor into global coordinates.
Definition: SpacePoint.cc:205
virtual std::vector< genfit::PlanarMeasurement > getGenfitCompatible() const
returns a vector of genfit::PlanarMeasurement, which is needed for genfit::track.
Definition: SpacePoint.cc:118
std::pair< double, double > m_normalizedLocal
Local position vector normalized to sensor size (0 <= x <= 1).
Definition: SpacePoint.h:354
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:66
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:213
Base class to provide Sensor Information for PXD and SVD.
double getVSize() const
Return the length of the sensor.
SensorType getType() const
Return the Type of the Sensor.
double getForwardWidth() const
Convinience Wrapper to return width at forward side.
double getBackwardWidth() const
Convinience Wrapper to return width at backward side.
TVector3 pointToGlobal(const TVector3 &local, bool reco=false) const
Convert a point from local to global coordinates.
double getUSize(double v=0) const
Return the width of the sensor.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Abstract base class for different kinds of events.