Belle II Software development
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 <framework/geometry/VectorUtil.h>
11#include <svd/reconstruction/SVDRecoHit2D.h>
12#include <svd/geometry/SensorInfo.h>
13#include <vxd/geometry/SensorPlane.h>
14#include <vxd/geometry/GeoCache.h>
15
16#include <genfit/DetPlane.h>
17#include <TRandom.h>
18#include <cmath>
19
20using namespace std;
21using namespace Belle2;
22
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
28SVDRecoHit2D::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) {
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
58SVDRecoHit2D::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) {
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)
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::getInstance().getSensorInfo(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
117SVDRecoHit2D::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 =
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::getInstance().getSensorInfo(m_sensorID));
161
162 // Construct vectors o, u, v
163 ROOT::Math::XYZVector origin = geometry.pointToGlobal(ROOT::Math::XYZVector(0, 0, 0), true);
164 ROOT::Math::XYZVector uGlobal = geometry.vectorToGlobal(ROOT::Math::XYZVector(1, 0, 0), true);
165 ROOT::Math::XYZVector vGlobal = geometry.vectorToGlobal(ROOT::Math::XYZVector(0, 1, 0), true);
166
167 //Construct the detector plane
168 genfit::SharedPlanePtr detPlane(new genfit::DetPlane(XYZToTVector(origin), XYZToTVector(uGlobal), XYZToTVector(vGlobal),
169 new VXD::SensorPlane(m_sensorID, 20, 20)));
170 setPlane(detPlane, m_sensorID);
171}
172
173TVectorD SVDRecoHit2D::applyPlanarDeformation(TVectorD rawHit, std::vector<double> planarParameters,
174 const genfit::StateOnPlane& state) const
175{
176 // Legendre parametrization of deformation
177 auto L1 = [](double x) {return x;};
178 auto L2 = [](double x) {return (3 * x * x - 1) / 2;};
179 auto L3 = [](double x) {return (5 * x * x * x - 3 * x) / 2;};
180 auto L4 = [](double x) {return (35 * x * x * x * x - 30 * x * x + 3) / 8;};
181
182 const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::getInstance().getSensorInfo(m_sensorID));
183
184 double u = rawHit[0]; // U coordinate of hit
185 double v = rawHit[1]; // V coordinate of hit
186 double width = geometry.getWidth(v); // Width of sensor (U side)
187 double length = geometry.getLength(); // Length of sensor (V side)
188 u = u * 2 / width; // Legendre parametrization required U in (-1, 1)
189 v = v * 2 / length; // Legendre parametrization required V in (-1, 1)
190
191 /* Planar deformation using Legendre parametrization
192 w(u, v) = L_{31} * L2(u) + L_{32} * L1(u) * L1(v) + L_{33} * L2(v) +
193 L_{41} * L3(u) + L_{42} * L2(u) * L1(v) + L_{43} * L1(u) * L2(v) + L_{44} * L3(v) +
194 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); */
195 double dw =
196 planarParameters[0] * L2(u) + planarParameters[1] * L1(u) * L1(v) + planarParameters[2] * L2(v) +
197 planarParameters[3] * L3(u) + planarParameters[4] * L2(u) * L1(v) + planarParameters[5] * L1(u) * L2(v) + planarParameters[6] * L3(
198 v) +
199 planarParameters[7] * L4(u) + planarParameters[8] * L3(u) * L1(v) + planarParameters[9] * L2(u) * L2(v) + planarParameters[10] * L1(
200 u) * L3(v) + planarParameters[11] * L4(v);
201
202 double du_dw = state.getState()[1]; // slope in U direction
203 double dv_dw = state.getState()[2]; // slope in V direction
204
205 u = u * width / 2; // from Legendre to Local parametrization
206 v = v * length / 2; // from Legendre to Local parametrization
207
208 TVectorD pos(2);
209
210 pos[0] = u + dw * du_dw;
211 pos[1] = v + dw * dv_dw;
212
213 return pos;
214}
215
216std::vector<genfit::MeasurementOnPlane*> SVDRecoHit2D::constructMeasurementsOnPlane(const genfit::StateOnPlane& state) const
217{
218 // Apply planar deformation
219 TVectorD pos = applyPlanarDeformation(rawHitCoords_, VXD::GeoCache::getInstance().getSensorInfo(m_sensorID).getSurfaceParameters(),
220 state);
221
222 return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(pos, rawHitCov_, state.getPlane(),
223 state.getRep(), this->constructHMatrix(state.getRep())));
224}
225
226genfit::AbsMeasurement* SVDRecoHit2D::clone() const
227{
228 return new SVDRecoHit2D(*this);
229}
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
float getCharge() const
Get collected charge.
Definition: SVDCluster.h:144
bool isUCluster() const
Get the direction of strips.
Definition: SVDCluster.h:110
float getPosition(double v=0) const
Get the coordinate of reconstructed hit.
Definition: SVDCluster.h:117
float getPositionSigma() const
Get the error of the reconstructed hit coordinate.
Definition: SVDCluster.h:129
unsigned short getRawSensorID() const
Get raw sensor ID.
Definition: SVDCluster.h:105
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
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
A Finite plane of one VXD Sensor.
Definition: SensorPlane.h:34
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:36
static constexpr auto XYZToTVector
Helper function to convert XYZVector to TVector3.
Definition: VectorUtil.h:24
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.
STL namespace.