Belle II Software  release-06-01-15
PXDRecoHit.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 <framework/logging/Logger.h>
10 #include <pxd/reconstruction/PXDRecoHit.h>
11 #include <pxd/reconstruction/PXDClusterPositionEstimator.h>
12 #include <pxd/reconstruction/PXDGainCalibrator.h>
13 #include <pxd/dataobjects/PXDTrueHit.h>
14 #include <pxd/dataobjects/PXDCluster.h>
15 #include <pxd/geometry/SensorInfo.h>
16 #include <vxd/geometry/SensorPlane.h>
17 #include <vxd/geometry/GeoCache.h>
18 
19 #include <genfit/DetPlane.h>
20 #include <TVector3.h>
21 #include <TRandom.h>
22 
23 using namespace std;
24 using namespace Belle2;
25 
26 PXDRecoHit::PXDRecoHit():
27  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(0), m_cluster(0),
28  m_energyDep(0)//, m_energyDepError(0)
29 {}
30 
31 PXDRecoHit::PXDRecoHit(const PXDTrueHit* hit, const genfit::TrackCandHit*, float sigmaU, float sigmaV):
32  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(hit), m_cluster(0),
33  m_energyDep(0)//, m_energyDepError(0)
34 {
35  if (!gRandom) B2FATAL("gRandom not initialized, please set up gRandom first");
36 
37  // Set the sensor UID
38  m_sensorID = hit->getSensorID();
39 
40  //If no error is given, estimate the error by dividing the pixel size by sqrt(12)
41  if (sigmaU < 0 || sigmaV < 0) {
42  const PXD::SensorInfo& geometry = dynamic_cast<const PXD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
43  sigmaU = geometry.getUPitch(hit->getV()) / sqrt(12);
44  sigmaV = geometry.getVPitch(hit->getV()) / sqrt(12);
45  }
46 
47  // Set positions
48  rawHitCoords_(0) = gRandom->Gaus(hit->getU(), sigmaU);
49  rawHitCoords_(1) = gRandom->Gaus(hit->getV(), sigmaV);
50  // Set the error covariance matrix
51  rawHitCov_(0, 0) = sigmaU * sigmaU;
52  rawHitCov_(0, 1) = 0;
53  rawHitCov_(1, 0) = 0;
54  rawHitCov_(1, 1) = sigmaV * sigmaV;
55  // Set physical parameters
56  m_energyDep = hit->getEnergyDep();
57  // Setup geometry information
59 }
60 
61 PXDRecoHit::PXDRecoHit(const PXDCluster* hit, float sigmaU, float sigmaV, float covUV):
62  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(0), m_cluster(hit),
63  m_energyDep(0)//, m_energyDepError(0)
64 {
65  // Set the sensor UID
66  m_sensorID = hit->getSensorID();
67  // Set positions
68  rawHitCoords_(0) = hit->getU();
69  rawHitCoords_(1) = hit->getV();
70  // Set the error covariance matrix
71  rawHitCov_(0, 0) = sigmaU * sigmaU;
72  rawHitCov_(0, 1) = covUV;
73  rawHitCov_(1, 0) = covUV;
74  rawHitCov_(1, 1) = sigmaV * sigmaV;
75  // Set physical parameters
78  SensorInfo.getVCellID(hit->getV()));
79  m_energyDep = hit->getCharge() * ADUToEnergy;
80  //m_energyDepError = 0;
81  // Setup geometry information
83 }
84 
85 
87  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(0), m_cluster(hit),
88  m_energyDep(0)//, m_energyDepError(0)
89 {
90  // Set the sensor UID
91  m_sensorID = hit->getSensorID();
92  // Set positions
93  rawHitCoords_(0) = hit->getU();
94  rawHitCoords_(1) = hit->getV();
95  // Set the error covariance matrix
96  rawHitCov_(0, 0) = hit->getUSigma() * hit->getUSigma();
97  rawHitCov_(0, 1) = hit->getRho() * hit->getUSigma() * hit->getVSigma();
98  rawHitCov_(1, 0) = hit->getRho() * hit->getUSigma() * hit->getVSigma();
99  rawHitCov_(1, 1) = hit->getVSigma() * hit->getVSigma();
100  // Set physical parameters
103  SensorInfo.getVCellID(hit->getV()));
104  m_energyDep = hit->getCharge() * ADUToEnergy;
105  //m_energyDepError = 0;
106  // Setup geometry information
108 }
109 
111 {
112  return new PXDRecoHit(*this);
113 }
114 
115 
117 {
118  // Construct a finite detector plane and set it.
119  const PXD::SensorInfo& geometry = dynamic_cast<const PXD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
120 
121  // Construct vectors o, u, v
122  TVector3 uLocal(1, 0, 0);
123  TVector3 vLocal(0, 1, 0);
124  TVector3 origin = geometry.pointToGlobal(TVector3(0, 0, 0), true);
125  TVector3 uGlobal = geometry.vectorToGlobal(uLocal, true);
126  TVector3 vGlobal = geometry.vectorToGlobal(vLocal, true);
127 
128  //Construct the detector plane
129  VXD::SensorPlane* finitePlane = new VXD::SensorPlane(m_sensorID, 20.0, 20.0);
130  genfit::SharedPlanePtr detPlane(new genfit::DetPlane(origin, uGlobal, vGlobal, finitePlane));
131  setPlane(detPlane, m_sensorID);
132 }
133 
134 
136 {
137  // We need an associated cluster
138  if (this->getCluster()) {
139  // Likelyhood depends on the fitted incidence angles into the sensor
140  const TVectorD& state5 = state.getState();
141  return PXD::PXDClusterPositionEstimator::getInstance().getShapeLikelyhood(*this->getCluster(), state5[1], state5[2]);
142  }
143  // If we reach here, we can do no better than return zero
144  return 0;
145 }
146 
147 TVectorD PXDRecoHit::applyPlanarDeformation(TVectorD hitCoords, std::vector<double> planarParameters,
148  const genfit::StateOnPlane& state) const
149 {
150  // Legendre parametrization of deformation
151  auto L1 = [](double x) {return x;};
152  auto L2 = [](double x) {return (3 * x * x - 1) / 2;};
153  auto L3 = [](double x) {return (5 * x * x * x - 3 * x) / 2;};
154  auto L4 = [](double x) {return (35 * x * x * x * x - 30 * x * x + 3) / 8;};
155 
156  const PXD::SensorInfo& geometry = dynamic_cast<const PXD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
157 
158  double u = hitCoords[0];
159  double v = hitCoords[1];
160  double width = geometry.getWidth(v); // Width of sensor (U side)
161  double length = geometry.getLength(); // Length of sensor (V side)
162  u = u * 2 / width; // Legendre parametrization required U in (-1, 1)
163  v = v * 2 / length; // Legendre parametrization required V in (-1, 1)
164 
165  /* Planar deformation using Legendre parametrization
166  w(u, v) = L_{31} * L2(u) + L_{32} * L1(u) * L1(v) + L_{33} * L2(v) +
167  L_{41} * L3(u) + L_{42} * L2(u) * L1(v) + L_{43} * L1(u) * L2(v) + L_{44} * L3(v) +
168  L_{51} * L4(u) + L_{52} * L3(u) * L1(v) + L_{53} * L2(u) * L2(v) + L_{54} * L1(u) * L3(v) + L_{55} * L4(v); */
169  double dw =
170  planarParameters[0] * L2(u) + planarParameters[1] * L1(u) * L1(v) + planarParameters[2] * L2(v) +
171  planarParameters[3] * L3(u) + planarParameters[4] * L2(u) * L1(v) + planarParameters[5] * L1(u) * L2(v) + planarParameters[6] * L3(
172  v) +
173  planarParameters[7] * L4(u) + planarParameters[8] * L3(u) * L1(v) + planarParameters[9] * L2(u) * L2(v) + planarParameters[10] * L1(
174  u) * L3(v) + planarParameters[11] * L4(v);
175 
176  double du_dw = state.getState()[1]; // slope in U direction
177  double dv_dw = state.getState()[2]; // slope in V direction
178 
179  u = u * width / 2; // from Legendre to Local parametrization
180  v = v * length / 2; // from Legendre to Local parametrization
181 
182  TVectorD pos(2);
183 
184  pos[0] = u + dw * du_dw;
185  pos[1] = v + dw * dv_dw;
186 
187  return pos;
188 }
189 
190 std::vector<genfit::MeasurementOnPlane*> PXDRecoHit::constructMeasurementsOnPlane(const genfit::StateOnPlane& state) const
191 {
192  // Track-based update only takes place when the RecoHit has an associated cluster
193  if (this->getCluster()) {
194  // Check if we can correct position coordinates based on track info
195  const TVectorD& state5 = state.getState();
196  auto offset = PXD::PXDClusterPositionEstimator::getInstance().getClusterOffset(*this->getCluster(), state5[1], state5[2]);
197 
198  if (offset != nullptr) {
199  // Found a valid offset, lets apply it
200  const Belle2::VxdID& sensorID = (*this->getCluster()).getSensorID();
201  const Belle2::PXD::SensorInfo& Info = dynamic_cast<const Belle2::PXD::SensorInfo&>(VXD::GeoCache::get(sensorID));
202  double posU = Info.getUCellPosition((*this->getCluster()).getUStart());
203  double posV = Info.getVCellPosition((*this->getCluster()).getVStart());
204 
205  TVectorD hitCoords(2);
206  hitCoords(0) = posU + offset->getU();
207  hitCoords(1) = posV + offset->getV();
208  TMatrixDSym hitCov(2);
209  hitCov(0, 0) = offset->getUSigma2();
210  hitCov(0, 1) = offset->getUVCovariance();
211  hitCov(1, 0) = offset->getUVCovariance();
212  hitCov(1, 1) = offset->getVSigma2();
213 
214  // Apply planar deformation
215  TVectorD pos = applyPlanarDeformation(hitCoords, VXD::GeoCache::get(m_sensorID).getSurfaceParameters(), state);
216 
217  return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(
218  pos, hitCov, state.getPlane(), state.getRep(), this->constructHMatrix(state.getRep())
219  ));
220  }
221  }
222 
223  // Apply planar deformation
224  TVectorD pos = applyPlanarDeformation(rawHitCoords_, VXD::GeoCache::get(m_sensorID).getSurfaceParameters(), state);
225 
226  // If we reach here, we can do no better than what we have
227  return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(
228  pos, rawHitCov_, state.getPlane(), state.getRep(), this->constructHMatrix(state.getRep())
229  ));
230 }
231 
232 
233 
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
float getShapeLikelyhood(const genfit::StateOnPlane &state) const
Get deposited energy error.
Definition: PXDRecoHit.cc:135
virtual std::vector< genfit::MeasurementOnPlane * > constructMeasurementsOnPlane(const genfit::StateOnPlane &state) const override
Methods that actually interface to Genfit.
Definition: PXDRecoHit.cc:190
float m_energyDep
transient member (not written out during streaming)
Definition: PXDRecoHit.h:141
unsigned short m_sensorID
Unique sensor identifier.
Definition: PXDRecoHit.h:136
const PXDCluster * getCluster() const
Get pointer to the Cluster used when creating this RecoHit, can be NULL if created from something els...
Definition: PXDRecoHit.h:106
PXDRecoHit()
Default constructor for ROOT IO.
Definition: PXDRecoHit.cc:26
TVectorD applyPlanarDeformation(TVectorD hitCoords, std::vector< double > planarParameters, const genfit::StateOnPlane &state) const
Apply planar deformation of sensors.
Definition: PXDRecoHit.cc:147
void setDetectorPlane()
Set up Detector plane information.
Definition: PXDRecoHit.cc:116
VxdID getSensorID() const
Get the compact ID.
Definition: PXDRecoHit.h:101
genfit::AbsMeasurement * clone() const override
Creating a deep copy of this hit.
Definition: PXDRecoHit.cc:110
Class PXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: PXDTrueHit.h:31
static PXDClusterPositionEstimator & getInstance()
Main (and only) way to access the PXDClusterPositionEstimator.
const PXDClusterOffsetPar * getClusterOffset(const PXDCluster &cluster, double tu, double tv) const
Return pointer to cluster offsets, can be nullptr.
float getShapeLikelyhood(const PXDCluster &cluster, double tu, double tv) const
Return cluster shape likelyhood.
float getADUToEnergy(VxdID id, unsigned int uid, unsigned int vid) const
Get conversion factor from ADU to energy.
static PXDGainCalibrator & getInstance()
Main (and only) way to access the PXDGainCalibrator.
Specific implementation of SensorInfo for PXD Sensors which provides additional pixel specific inform...
Definition: SensorInfo.h:23
static const SensorInfoBase & get(Belle2::VxdID id)
Return a reference to the SensorInfo of a given SensorID.
Definition: GeoCache.h:139
double getVCellPosition(int vID) const
Return the position of a specific strip/pixel in v direction.
double getUCellPosition(int uID, int vID=-1) const
Return the position of a specific strip/pixel in u direction.
int getVCellID(double v, bool clamp=false) const
Return the corresponding pixel/strip ID of a given v coordinate.
int getUCellID(double u, double v=0, bool clamp=false) const
Return the corresponding pixel/strip ID of a given u coordinate.
A Finite plane of one VXD Sensor.
Definition: SensorPlane.h:34
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Contains the measurement and covariance in raw detector coordinates.
Detector plane.
Definition: DetPlane.h:59
Measured coordinates on a plane.
A state with arbitrary dimension defined in a DetPlane.
Definition: StateOnPlane.h:47
Hit object for use in TrackCand.
Definition: TrackCandHit.h:34
Abstract base class for different kinds of events.
Defines for I/O streams used for error and debug printing.
std::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.