Belle II Software  release-05-02-19
SpacePoint.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - 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 #pragma once
11 
12 #include <framework/geometry/B2Vector3.h>
13 #include <framework/datastore/RelationsObject.h>
14 #include <framework/logging/Logger.h>
15 
16 #include <vxd/geometry/GeoCache.h>
17 #include <vxd/geometry/SensorInfoBase.h>
18 
19 #include <pxd/dataobjects/PXDCluster.h>
20 
21 #include <svd/dataobjects/SVDCluster.h>
22 
23 #include <genfit/PlanarMeasurement.h>
24 
25 #include <vector>
26 #include <string>
27 #include <utility> // std::pair
28 
29 namespace Belle2 {
44  class SpacePoint: public RelationsObject {
45 
46  public:
47  //--- C'tors and D'tors -------------------------------------------------------------------------------------------
53  explicit SpacePoint(const PXDCluster* pxdCluster,
54  const VXD::SensorInfoBase* aSensorInfo = nullptr);
55 
61  explicit SpacePoint(std::vector<SVDCluster const*>& clusters,
62  VXD::SensorInfoBase const* aSensorInfo = nullptr);
63 
65  SpacePoint() :
66  m_positionError(1., 1., 1.), //TODO: Describe Design Decision for not using the default (0.,0.,0.)
68  m_vxdID(0), m_sensorType(VXD::SensorInfoBase::SensorType::VXD) // type is set to generic VXD
69  {}
70 
82  SpacePoint(const B2Vector3<double>& pos, const B2Vector3<double>& posError, std::pair<double, double> normalizedLocal,
83  std::pair<bool, bool> clustersAssigned, VxdID sensorID, Belle2::VXD::SensorInfoBase::SensorType detID,
84  double UClusterTime = 0. , double VClusterTime = 0.) :
85  m_position(pos), m_positionError(posError),
86  m_normalizedLocal(normalizedLocal),
87  m_UClusterTime(UClusterTime), m_VClusterTime(VClusterTime),
88  m_clustersAssigned(clustersAssigned),
89  m_vxdID(sensorID), m_sensorType(detID)
90  {}
91 
93  virtual ~SpacePoint() {}
94  //-----------------------------------------------------------------------------------------------------------------
95 
97  friend std::ostream& operator<< (std::ostream& out, const SpacePoint& aSP) { return out << aSP.getName();}
98 
105  bool operator == (const SpacePoint& b) const
106  {
107  return getArrayIndex() == b.getArrayIndex();
108  }
109 
111  bool operator != (const SpacePoint& b) const
112  {
113  return !(*this == b);
114  }
115 
117  std::string getName() const override
118  {
119  return "SpacePoint with index: " + std::to_string(getArrayIndex()) +
120  "and VxdID: " + std::to_string(VxdID(m_vxdID));
121  }
122 
123  //--- Global Coordinate Getters -----------------------------------------------------------------------------------
125  double X() const { return m_position.X(); }
126 
128  double Y() const { return m_position.Y(); }
129 
131  double Z() const { return m_position.Z(); }
132 
134  double TimeU() const { return m_UClusterTime; }
135 
137  double TimeV() const { return m_VClusterTime; }
138 
140  const B2Vector3<double>& getPosition() const { return m_position; }
141 
143  const B2Vector3<double>& getPositionError() const { return m_positionError; }
144 
145  //---- Sensor Level Information Getters ---------------------------------------------------------------------------
148 
150  VxdID getVxdID() const { return m_vxdID; }
151 
153  double getNormalizedLocalU() const { return m_normalizedLocal.first; }
154 
156  double getNormalizedLocalV() const { return m_normalizedLocal.second; }
157  //-----------------------------------------------------------------------------------------------------------------
158 
164  std::pair<bool, bool> getIfClustersAssigned() const { return m_clustersAssigned; }
165 
167  unsigned short getNClustersAssigned() const
168  {
169  if (m_sensorType == VXD::SensorInfoBase::SensorType::SVD &&
170  m_clustersAssigned.first && m_clustersAssigned.second) {
171  return 2;
172  }
173  return 1;
174  }
175 
177  void setAssignmentState(bool isAssigned) const { m_isAssigned = isAssigned; }
178 
180  bool isUOnly() const { return m_clustersAssigned.first and not m_clustersAssigned.second; }
182  bool isVOnly() const { return not m_clustersAssigned.first and m_clustersAssigned.second; }
184  bool isUAndV() const { return m_clustersAssigned.first and m_clustersAssigned.second; }
185 
187  bool getAssignmentState() const { return m_isAssigned; }
188 
190  void setQualityEstimation(float qualityIndicator) {m_qualityIndicator = qualityIndicator; }
191 
193  float getQualityEstimation() const { return m_qualityIndicator; }
194 
196  void setQualityEstimationError(double qualityIndicatorError) {m_qualityIndicatorError = qualityIndicatorError;}
197 
199  float getQualityEstimationError() const {return m_qualityIndicatorError;}
200 
201 
202 //---------------------------------------------------------------------------------------------------------------------
203 //TODO: Some clarification, if the following conversions and especially the staticness of the functions below is needed
204 //in the version 2 of the VXDTF.
213  virtual std::vector<genfit::PlanarMeasurement> getGenfitCompatible() const ;
214 
215 
216 // static converter functions:
217 
228  static B2Vector3<double> getGlobalCoordinates(const std::pair<double, double>& hitLocal, VxdID vxdID,
229  const VXD::SensorInfoBase* aSensorInfo = nullptr);
230 
231 
242  static std::pair<double, double> convertLocalToNormalizedCoordinates(const std::pair<double, double>& hitLocal,
243  VxdID vxdID, const VXD::SensorInfoBase* aSensorInfo = nullptr);
244 
245 
253  static std::pair<double, double> convertNormalizedToLocalCoordinates(const std::pair<double, double>& hitNormalized,
254  Belle2::VxdID vxdID, const Belle2::VXD::SensorInfoBase* aSensorInfo = nullptr);
255 
256 
265  static double getUWedged(const std::pair<double, double>& hitLocalUnwedged, VxdID vxdID,
266  const VXD::SensorInfoBase* aSensorInfo = nullptr)
267  {
268  if (aSensorInfo == nullptr) { aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID); }
269  return (aSensorInfo->getWidth(hitLocalUnwedged.second) / aSensorInfo->getWidth()) * hitLocalUnwedged.first;
270  }
271 
272 
273 
280  static double getUUnwedged(const std::pair<double, double>& hitLocalWedged, VxdID::baseType vxdID,
281  const VXD::SensorInfoBase* aSensorInfo = nullptr)
282  {
283  if (aSensorInfo == nullptr) { aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID); }
284  return (aSensorInfo->getWidth() / aSensorInfo->getWidth(hitLocalWedged.second)) * hitLocalWedged.first;
285  }
286 
287 
288 
298  static void boundaryEnforce(double& value, const double& otherValue, double lower = 0, double higher = 1, unsigned int side = 0,
299  VxdID vxdID = VxdID())
300  {
301  // Times to times there are normalized coordinates that are out of the boundaries.
302  // We do apply a smal sloppyness here
303 
304  double sloppyTerm = 1e-3;
305  if (value < lower - sloppyTerm) {
306  B2WARNING("SpacePoint::boundaryEnforce: value had to be moved (lowerCheck)! old: " << value << ", new: " << lower);
307  B2WARNING("On sensor: " << vxdID << " side: " << (side == 0 ? " U " : " V") <<
308  " when the other coordinate is: " << otherValue);
309 
310  value = lower;
311  }
312  if (value > higher + sloppyTerm) {
313  B2WARNING("SpacePoint::boundaryEnforce: value had to be moved (higherCheck)! old: " << value << ", new: " << higher);
314  B2WARNING("On sensor: " << vxdID << " side: " << (side == 0 ? " U " : " V") <<
315  " when the other coordinate is: " << otherValue);
316  value = higher;
317  }
318 
319  }
320 //---------------------------------------------------------------------------------------------------------------------
321 
322  protected:
324  void setPositionError(double uSigma, double vSigma, const VXD::SensorInfoBase* aSensorInfo)
325  {
326  //As only variances, but not the sigmas transform linearly, we need to use some acrobatics.
327  m_positionError = aSensorInfo->vectorToGlobal(
328  TVector3(
329  uSigma * uSigma,
330  vSigma * vSigma,
331  0
332  ),
333  true // use alignment in transformation
334  );
336  }
337 
338  //--- Member variables --------------------------------------------------------------------------------------------
344 
350 
351 
356  std::pair<double, double> m_normalizedLocal;
357 
360  double m_UClusterTime;
361 
365 
366 
372  std::pair<bool, bool> m_clustersAssigned {false, false};
373 
376 
383 
388  float m_qualityIndicator {0.5};
389 
390 
395  float m_qualityIndicatorError {0.5};
396 
403  mutable bool m_isAssigned {false};
404 
405  ClassDefOverride(SpacePoint, 13)
406  };
408 }
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::SpacePoint::TimeV
double TimeV() const
return the time in ns of the cluster on the V side
Definition: SpacePoint.h:145
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::VXD::SensorInfoBase::SensorType
SensorType
Enum specifing the type of sensor the SensorInfo represents.
Definition: SensorInfoBase.h:43
Belle2::SpacePoint::m_positionError
B2Vector3< double > m_positionError
Global position error vector in sigma.
Definition: SpacePoint.h:357
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::X
double X() const
return the x-value of the global position of the SpacePoint
Definition: SpacePoint.h:133
Belle2::SpacePoint::TimeU
double TimeU() const
return the time in ns of the cluster on the U side
Definition: SpacePoint.h:142
Belle2::SpacePoint::operator<<
friend std::ostream & operator<<(std::ostream &out, const SpacePoint &aSP)
overloaded '<<' stream operator.
Definition: SpacePoint.h:105
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::SpacePoint::Z
double Z() const
return the z-value of the global position of the SpacePoint
Definition: SpacePoint.h:139
Belle2::SpacePoint::~SpacePoint
virtual ~SpacePoint()
Currently SpacePoint is used as base class for test beam related TBSpacePoint.
Definition: SpacePoint.h:101
Belle2::SpacePoint::m_qualityIndicator
float m_qualityIndicator
Stores a quality indicator.
Definition: SpacePoint.h:396
Belle2::SpacePoint::getIfClustersAssigned
std::pair< bool, bool > getIfClustersAssigned() const
Returns, if u(v)-coordinate is based on cluster information.
Definition: SpacePoint.h:172
Belle2::VXD::SensorInfoBase
Base class to provide Sensor Information for PXD and SVD.
Definition: SensorInfoBase.h:40
Belle2::SpacePoint::getUUnwedged
static double getUUnwedged(const std::pair< double, double > &hitLocalWedged, VxdID::baseType vxdID, const VXD::SensorInfoBase *aSensorInfo=nullptr)
takes a wedged uCoordinate, and transforms it to general uCoordinate.
Definition: SpacePoint.h:288
Belle2::B2Vector3::Z
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:434
Belle2::SpacePoint::operator==
bool operator==(const SpacePoint &b) const
Compare, if two SpacePoints are the same one.
Definition: SpacePoint.h:113
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
Belle2::SpacePoint::getPosition
const B2Vector3< double > & getPosition() const
return the position vector in global coordinates
Definition: SpacePoint.h:148
Belle2::SpacePoint::setAssignmentState
void setAssignmentState(bool isAssigned) const
Setter for association with a track.
Definition: SpacePoint.h:185
Belle2::B2Vector3< double >
Belle2::SpacePoint::getName
std::string getName() const override
Print out some info for this SpacePoint.
Definition: SpacePoint.h:125
Belle2::SpacePoint::Y
double Y() const
return the y-value of the global position of the SpacePoint
Definition: SpacePoint.h:136
Belle2::SpacePoint::setQualityEstimationError
void setQualityEstimationError(double qualityIndicatorError)
Setter for the spacePoint quality index error.
Definition: SpacePoint.h:204
Belle2::VxdID::baseType
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:46
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::SpacePoint::getQualityEstimation
float getQualityEstimation() const
Getter for the quality of this SpacePoint.
Definition: SpacePoint.h:201
Belle2::SpacePoint::m_isAssigned
bool m_isAssigned
Stores whether this SpacePoint is connected to a track.
Definition: SpacePoint.h:411
Belle2::SpacePoint::getAssignmentState
bool getAssignmentState() const
Getter for status of assignment to a track.
Definition: SpacePoint.h:195
Belle2::SpacePoint::isUOnly
bool isUOnly() const
Returns true if the SP is single clustered and the cluster is a u cluster.
Definition: SpacePoint.h:188
Belle2::B2Vector3::Sqrt
void Sqrt()
calculates the square root of the absolute values of the coordinates element-wise
Definition: B2Vector3.h:413
Belle2::SpacePoint::getNormalizedLocalV
double getNormalizedLocalV() const
Return normalized local coordinates of the cluster in v (0 <= posV <= 1).
Definition: SpacePoint.h:164
Belle2::RelationsInterface::getArrayIndex
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
Definition: RelationsObject.h:387
Belle2::SpacePoint::m_qualityIndicatorError
float m_qualityIndicatorError
Stores the error on the quality indicator.
Definition: SpacePoint.h:403
Belle2::SpacePoint::isUAndV
bool isUAndV() const
Returns true if the SP is not single clustered.
Definition: SpacePoint.h:192
Belle2::SpacePoint::operator!=
bool operator!=(const SpacePoint &b) const
Comparison for inequality with another SpacePoint.
Definition: SpacePoint.h:119
Belle2::SpacePoint::isVOnly
bool isVOnly() const
Returns true if the SP is single clustered and the cluster is a v cluster.
Definition: SpacePoint.h:190
Belle2::RelationsObject
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.
Definition: RelationsObject.h:443
Belle2::SpacePoint::setQualityEstimation
void setQualityEstimation(float qualityIndicator)
Setter for the quality of this SpacePoint.
Definition: SpacePoint.h:198
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::B2Vector3::X
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:430
Belle2::SpacePoint::getQualityEstimationError
float getQualityEstimationError() const
Getter for the spacePoint quality index error.
Definition: SpacePoint.h:207
Belle2::SpacePoint::getType
Belle2::VXD::SensorInfoBase::SensorType getType() const
Return SensorType (PXD, SVD, ...) on which the SpacePoint lives.
Definition: SpacePoint.h:155
Belle2::SpacePoint::getNClustersAssigned
unsigned short getNClustersAssigned() const
Returns the number of Clusters assigned to this SpacePoint.
Definition: SpacePoint.h:175
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::B2Vector3::Y
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:432
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::getPositionError
const B2Vector3< double > & getPositionError() const
return the hitErrors in sigma of the global position
Definition: SpacePoint.h:151
Belle2::SpacePoint::getVxdID
VxdID getVxdID() const
Return the VxdID of the sensor on which the the cluster of the SpacePoint lives.
Definition: SpacePoint.h:158
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::getNormalizedLocalU
double getNormalizedLocalU() const
Return normalized local coordinates of the cluster in u (0 <= posU <= 1).
Definition: SpacePoint.h:161
Belle2::SpacePoint::getUWedged
static double getUWedged(const std::pair< double, double > &hitLocalUnwedged, VxdID vxdID, const VXD::SensorInfoBase *aSensorInfo=nullptr)
takes a general uCoordinate, and transforms it to corrected uCoordinate for wedged sensors.
Definition: SpacePoint.h:273
Belle2::SpacePoint::m_UClusterTime
double m_UClusterTime
Time of the cluster on the U side in ns.
Definition: SpacePoint.h:368