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