Belle II Software  release-06-01-15
SVDRecoHit2D.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 <svd/reconstruction/SVDRecoHit2D.h>
11 #include <svd/geometry/SensorInfo.h>
12 #include <vxd/geometry/SensorPlane.h>
13 #include <vxd/geometry/GeoCache.h>
14 
15 #include <genfit/DetPlane.h>
16 #include <TVector3.h>
17 #include <TRandom.h>
18 #include <cmath>
19 
20 using namespace std;
21 using namespace Belle2;
22 
23 SVDRecoHit2D::SVDRecoHit2D():
24  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(0), m_uCluster(0), m_vCluster(0),
25  m_energyDep(0)//, m_energyDepError(0)
26 {}
27 
28 SVDRecoHit2D::SVDRecoHit2D(const SVDTrueHit* hit, const genfit::TrackCandHit*, float sigmaU, float sigmaV):
29  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(hit), m_uCluster(0), m_vCluster(0),
30  m_energyDep(0)//, m_energyDepError(0)
31 {
32  if (!gRandom) B2FATAL("gRandom not initialized, please set up gRandom first");
33 
34  // Set the sensor UID
35  m_sensorID = hit->getSensorID();
36 
37  //If no error is given, estimate the error by dividing the pixel size by sqrt(12)
38  if (sigmaU < 0 || sigmaV < 0) {
39  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
40  sigmaU = geometry.getUPitch(hit->getV()) / sqrt(12);
41  sigmaV = geometry.getVPitch(hit->getV()) / sqrt(12);
42  }
43 
44  // Set positions
45  rawHitCoords_(0) = gRandom->Gaus(hit->getU(), sigmaU);
46  rawHitCoords_(1) = gRandom->Gaus(hit->getV(), sigmaV);
47  // Set the error covariance matrix
48  rawHitCov_(0, 0) = sigmaU * sigmaU;
49  rawHitCov_(0, 1) = 0;
50  rawHitCov_(1, 0) = 0;
51  rawHitCov_(1, 1) = sigmaV * sigmaV;
52  // Set physical parameters
53  m_energyDep = hit->getEnergyDep();
54  // Setup geometry information
56 }
57 
58 SVDRecoHit2D::SVDRecoHit2D(VxdID::baseType vxdid, const double u, const double v, double sigmaU, double sigmaV):
59  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(vxdid), m_trueHit(nullptr), m_uCluster(0), m_vCluster(0),
60  m_energyDep(0)//, m_energyDepError(0)
61 {
62  //If no error is given, estimate the error by dividing the pixel size by sqrt(12)
63  if (sigmaU < 0 || sigmaV < 0) {
64  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
65  sigmaU = geometry.getUPitch(v) / sqrt(12);
66  sigmaV = geometry.getVPitch(v) / sqrt(12);
67  }
68  // Set positions
69  rawHitCoords_(0) = u;
70  rawHitCoords_(1) = v;
71  // Set the error covariance matrix
72  rawHitCov_(0, 0) = sigmaU * sigmaU;
73  rawHitCov_(0, 1) = 0;
74  rawHitCov_(1, 0) = 0;
75  rawHitCov_(1, 1) = sigmaV * sigmaV;
76  // Setup geometry information
78 }
79 
81  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_trueHit(nullptr), m_uCluster(&uHit), m_vCluster(&vHit),
82  m_energyDep(0)
83 {
84  if ((uHit.getRawSensorID() != vHit.getRawSensorID()) || !uHit.isUCluster() || vHit.isUCluster())
85  B2FATAL("Error in SVDRecoHit2D: Incorrect SVDCluster instances on input!");
86 
87  m_sensorID = uHit.getRawSensorID();
88 
89  // Now that we have a v coordinate, we can rescale u.
90  const SVD::SensorInfo& info =
91  dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
92 
93  double DeltaU =
94  (info.getForwardWidth() - info.getBackwardWidth()) / info.getLength() / info.getWidth(0);
95  double scaleFactorU = 1 + DeltaU * vHit.getPosition();
96  double tan_phi = DeltaU * uHit.getPosition(); // need u at v=0!
97  double one_over_cos_phi_sqr = 1 + tan_phi * tan_phi;
98 
99  rawHitCoords_[0] = uHit.getPosition() * scaleFactorU;
100  rawHitCoords_[1] = vHit.getPosition();
101 
102  double sigmaU = uHit.getPositionSigma() * scaleFactorU;
103  double sigmaU_sq = sigmaU * sigmaU;
104  double sigmaV = vHit.getPositionSigma();
105  double sigmaV_sq = sigmaV * sigmaV;
106 
107  m_energyDep = 0.5 * (uHit.getCharge() + vHit.getCharge());
108 
109  rawHitCov_(0, 0) = sigmaV_sq * tan_phi * tan_phi + sigmaU_sq * one_over_cos_phi_sqr;
110  rawHitCov_(0, 1) = sigmaV_sq * tan_phi;
111  rawHitCov_(1, 0) = sigmaV_sq * tan_phi;
112  rawHitCov_(1, 1) = sigmaV_sq;
113  // Setup geometry information
114  setDetectorPlane();
115 }
116 
117 SVDRecoHit2D::SVDRecoHit2D(const SVDRecoHit& uRecoHit, const SVDRecoHit& vRecoHit):
118  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_trueHit(nullptr), m_uCluster(0), m_vCluster(0), m_energyDep(0)
119 {
120  const SVDCluster& uHit = *(uRecoHit.getCluster());
121  const SVDCluster& vHit = *(vRecoHit.getCluster());
122  if ((uHit.getRawSensorID() != vHit.getRawSensorID()) || !uHit.isUCluster() || vHit.isUCluster())
123  B2FATAL("Error in SVDRecoHit2D: Incorrect SVDCluster instances on input!");
124 
125  m_sensorID = uHit.getRawSensorID();
126  m_uCluster = &uHit;
127  m_vCluster = &vHit;
128 
129  // Now that we have a v coordinate, we can rescale u.
130  const SVD::SensorInfo& info =
131  dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
132 
133  double DeltaU =
134  (info.getForwardWidth() - info.getBackwardWidth()) / info.getLength() / info.getWidth(0);
135  double scaleFactorU = 1 + DeltaU * vHit.getPosition();
136  double tan_phi = DeltaU * uHit.getPosition(); // need u at v=0!
137  double one_over_cos_phi_sqr = 1 + tan_phi * tan_phi;
138 
139  rawHitCoords_[0] = uHit.getPosition() * scaleFactorU;
140  rawHitCoords_[1] = vHit.getPosition();
141 
142  double sigmaU = uHit.getPositionSigma() * scaleFactorU;
143  double sigmaU_sq = sigmaU * sigmaU;
144  double sigmaV = vHit.getPositionSigma();
145  double sigmaV_sq = sigmaV * sigmaV;
146 
147  m_energyDep = 0.5 * (uHit.getCharge() + vHit.getCharge());
148 
149  rawHitCov_(0, 0) = sigmaV_sq * tan_phi * tan_phi + sigmaU_sq * one_over_cos_phi_sqr;
150  rawHitCov_(0, 1) = sigmaV_sq * tan_phi;
151  rawHitCov_(1, 0) = sigmaV_sq * tan_phi;
152  rawHitCov_(1, 1) = sigmaV_sq;
153  // Setup geometry information
155 }
156 
158 {
159  // Construct a finite detector plane and set it.
160  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
161 
162  // Construct vectors o, u, v
163  TVector3 origin = geometry.pointToGlobal(TVector3(0, 0, 0), true);
164  TVector3 uGlobal = geometry.vectorToGlobal(TVector3(1, 0, 0), true);
165  TVector3 vGlobal = geometry.vectorToGlobal(TVector3(0, 1, 0), true);
166 
167  //Construct the detector plane
168  genfit::SharedPlanePtr detPlane(new genfit::DetPlane(origin, uGlobal, vGlobal, new VXD::SensorPlane(m_sensorID, 20, 20)));
169  setPlane(detPlane, m_sensorID);
170 }
171 
172 TVectorD SVDRecoHit2D::applyPlanarDeformation(TVectorD rawHit, std::vector<double> planarParameters,
173  const genfit::StateOnPlane& state) const
174 {
175  // Legendre parametrization of deformation
176  auto L1 = [](double x) {return x;};
177  auto L2 = [](double x) {return (3 * x * x - 1) / 2;};
178  auto L3 = [](double x) {return (5 * x * x * x - 3 * x) / 2;};
179  auto L4 = [](double x) {return (35 * x * x * x * x - 30 * x * x + 3) / 8;};
180 
181  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
182 
183  double u = rawHit[0]; // U coordinate of hit
184  double v = rawHit[1]; // V coordinate of hit
185  double width = geometry.getWidth(v); // Width of sensor (U side)
186  double length = geometry.getLength(); // Length of sensor (V side)
187  u = u * 2 / width; // Legendre parametrization required U in (-1, 1)
188  v = v * 2 / length; // Legendre parametrization required V in (-1, 1)
189 
190  /* Planar deformation using Legendre parametrization
191  w(u, v) = L_{31} * L2(u) + L_{32} * L1(u) * L1(v) + L_{33} * L2(v) +
192  L_{41} * L3(u) + L_{42} * L2(u) * L1(v) + L_{43} * L1(u) * L2(v) + L_{44} * L3(v) +
193  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); */
194  double dw =
195  planarParameters[0] * L2(u) + planarParameters[1] * L1(u) * L1(v) + planarParameters[2] * L2(v) +
196  planarParameters[3] * L3(u) + planarParameters[4] * L2(u) * L1(v) + planarParameters[5] * L1(u) * L2(v) + planarParameters[6] * L3(
197  v) +
198  planarParameters[7] * L4(u) + planarParameters[8] * L3(u) * L1(v) + planarParameters[9] * L2(u) * L2(v) + planarParameters[10] * L1(
199  u) * L3(v) + planarParameters[11] * L4(v);
200 
201  double du_dw = state.getState()[1]; // slope in U direction
202  double dv_dw = state.getState()[2]; // slope in V direction
203 
204  u = u * width / 2; // from Legendre to Local parametrization
205  v = v * length / 2; // from Legendre to Local parametrization
206 
207  TVectorD pos(2);
208 
209  pos[0] = u + dw * du_dw;
210  pos[1] = v + dw * dv_dw;
211 
212  return pos;
213 }
214 
215 std::vector<genfit::MeasurementOnPlane*> SVDRecoHit2D::constructMeasurementsOnPlane(const genfit::StateOnPlane& state) const
216 {
217  // Apply planar deformation
218  TVectorD pos = applyPlanarDeformation(rawHitCoords_, VXD::GeoCache::get(m_sensorID).getSurfaceParameters(), state);
219 
220  return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(pos, rawHitCov_, state.getPlane(),
221  state.getRep(), this->constructHMatrix(state.getRep())));
222 }
223 
225 {
226  return new SVDRecoHit2D(*this);
227 }
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:28
float getCharge() const
Get collected charge.
Definition: SVDCluster.h:143
bool isUCluster() const
Get the direction of strips.
Definition: SVDCluster.h:109
float getPosition(double v=0) const
Get the coordinate of reconstructed hit.
Definition: SVDCluster.h:116
float getPositionSigma() const
Get the error of the reconstructed hit coordinate.
Definition: SVDCluster.h:128
unsigned short getRawSensorID() const
Get raw sensor ID.
Definition: SVDCluster.h:104
virtual std::vector< genfit::MeasurementOnPlane * > constructMeasurementsOnPlane(const genfit::StateOnPlane &state) const override
Get deposited energy error.
TVectorD applyPlanarDeformation(TVectorD rawHit, std::vector< double > planarParameters, const genfit::StateOnPlane &state) const
Apply planar deformation of sensors.
float m_energyDep
deposited energy.
Definition: SVDRecoHit2D.h:140
unsigned short m_sensorID
Unique sensor identifier.
Definition: SVDRecoHit2D.h:135
const SVDCluster * m_uCluster
Pointer to mother uCluster.
Definition: SVDRecoHit2D.h:137
void setDetectorPlane()
Set up Detector plane information.
genfit::AbsMeasurement * clone() const override
Creating a deep copy of this hit.
SVDRecoHit2D()
Default constructor for ROOT IO.
Definition: SVDRecoHit2D.cc:23
const SVDCluster * m_vCluster
Pointer to mother vCluster.
Definition: SVDRecoHit2D.h:138
SVDRecoHit - an extended form of SVDHit containing geometry information.
Definition: SVDRecoHit.h:47
const SVDCluster * getCluster() const
Get pointer to the Cluster used when creating this RecoHit, can be nullptr if created from something ...
Definition: SVDRecoHit.h:88
Class SVDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: SVDTrueHit.h:33
Specific implementation of SensorInfo for SVD Sensors which provides additional sensor specific infor...
Definition: SensorInfo.h:25
static const SensorInfoBase & get(Belle2::VxdID id)
Return a reference to the SensorInfo of a given SensorID.
Definition: GeoCache.h:139
A Finite plane of one VXD Sensor.
Definition: SensorPlane.h:34
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:36
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.