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