Belle II Software development
SVDRecoHit.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/SVDRecoHit.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),
25 m_cluster(0), m_isU(0), m_energyDep(0), m_rotationPhi(0)
26{
27 setStripV(!m_isU);
28}
29
30SVDRecoHit::SVDRecoHit(const SVDTrueHit* hit, bool uDirection, float sigma):
31 genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(hit),
32 m_cluster(0), m_isU(uDirection), m_energyDep(0), m_rotationPhi(0)
33{
34 setStripV(!m_isU);
35
36 // Smear the coordinate when constructing from a TrueHit.
37 if (!gRandom) B2FATAL("gRandom not initialized, please set up gRandom first");
38
39 // Set the sensor UID
40 m_sensorID = hit->getSensorID();
41
42 //If no error is given, estimate the error to pitch/sqrt(12)
43 if (sigma < 0) {
45 sigma = (m_isU) ? geometry.getUPitch(hit->getV()) / sqrt(12) : geometry.getVPitch() / sqrt(12);
46 }
47
48 // Set positions
49 rawHitCoords_(0) = (m_isU) ? gRandom->Gaus(hit->getU(), sigma) : gRandom->Gaus(hit->getV(), sigma);
50 // Set the error covariance matrix
51 rawHitCov_(0, 0) = sigma * sigma;
52 // Set physical parameters
53 m_energyDep = hit->getEnergyDep();
54 // Setup geometry information
56}
57
58SVDRecoHit::SVDRecoHit(const SVDCluster* hit, const genfit::TrackCandHit*):
59 genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(0),
60 m_cluster(hit), m_energyDep(0), m_rotationPhi(0)
61{
62 // Set the sensor UID
63 m_sensorID = hit->getSensorID();
64 m_isU = hit->isUCluster();
65
66 setStripV(!m_isU);
67
68 // Determine if we have a wedge sensor.
70
71 bool isWedgeU = m_isU && (geometry.getBackwardWidth() > geometry.getForwardWidth());
72
73 // Set positions
74 rawHitCoords_(0) = hit->getPosition();
75 if (isWedgeU) {
76 // For u coordinate in a wedge sensor, the position line is not u = const.
77 // We have to rotate the coordinate system to achieve this.
78 m_rotationPhi = atan2((geometry.getBackwardWidth() - geometry.getForwardWidth()) / geometry.getWidth(0) * hit->getPosition(),
79 geometry.getLength());
80 }
81 // Set the error covariance matrix (this does not scale with position)
82 rawHitCov_(0, 0) = hit->getPositionSigma() * hit->getPositionSigma();
83 // Set physical parameters
84 m_energyDep = hit->getCharge();
85 // Setup geometry information
87}
88
90{
91 // Construct a finite detector plane and set it.
93 bool isWedgeU = m_isU && (geometry.getBackwardWidth() > geometry.getForwardWidth());
94
95 // Construct vectors o, u, v
96 ROOT::Math::XYZVector uLocal(1, 0, 0);
97 ROOT::Math::XYZVector vLocal(0, 1, 0);
98 ROOT::Math::XYZVector origin = geometry.pointToGlobal(ROOT::Math::XYZVector(0, 0, 0), true);
99 ROOT::Math::XYZVector uGlobal = geometry.vectorToGlobal(uLocal, true);
100 ROOT::Math::XYZVector vGlobal = geometry.vectorToGlobal(vLocal, true);
101
102 //Construct the detector plane
103 VXD::SensorPlane* finitePlane = new VXD::SensorPlane(m_sensorID, 20.0, 20.0);
104 if (isWedgeU) finitePlane->setRotation(m_rotationPhi);
105 genfit::SharedPlanePtr detPlane(new genfit::DetPlane(XYZToTVector(origin), XYZToTVector(uGlobal), XYZToTVector(vGlobal),
106 finitePlane));
107 setPlane(detPlane, m_sensorID);
108}
109
110genfit::AbsMeasurement* SVDRecoHit::clone() const
111{
112 return new SVDRecoHit(*this);
113}
114
115TVectorD SVDRecoHit::applyPlanarDeformation(TVectorD rawHit, std::vector<double> planarParameters,
116 const genfit::StateOnPlane& state) const
117{
118 // Legendre parametrization of deformation
119 auto L1 = [](double x) {return x;};
120 auto L2 = [](double x) {return (3 * x * x - 1) / 2;};
121 auto L3 = [](double x) {return (5 * x * x * x - 3 * x) / 2;};
122 auto L4 = [](double x) {return (35 * x * x * x * x - 30 * x * x + 3) / 8;};
123
124 const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::getInstance().getSensorInfo(m_sensorID));
125
126 double u = 0;
127 double v = 0;
128 double length = 0;
129 double width = 0;
130
131 if (m_isU) {
132 u = rawHit[0]; // U coordinate of hit
133 v = state.getState()(4); // V coordinate of hit
134 width = geometry.getWidth(v); // Width of sensor (U side) is function of V (slanted)
135 length = geometry.getLength(); // Length of sensor (V side)
136
137 u = u * 2 / width; // Legendre parametrization required U in (-1, 1)
138 v = v * 2 / length; // Legendre parametrization required V in (-1, 1)
139
140 } else {
141 v = rawHit[0]; // V coordinate of hit
142 u = state.getState()(3); // U coordinate of hit
143 length = geometry.getLength(); // Length of sensor (V side) is fuction of V (slanted)
144 width = geometry.getWidth(v); // Width of sensor (U side)
145
146 v = v * 2 / length; // Legendre parametrization required V in (-1, 1)
147 u = u * 2 / width; // Legendre parametrization required U in (-1, 1)
148
149 }
150
151 /* Planar deformation using Legendre parametrization
152 w(u, v) = L_{31} * L2(u) + L_{32} * L1(u) * L1(v) + L_{33} * L2(v) +
153 L_{41} * L3(u) + L_{42} * L2(u) * L1(v) + L_{43} * L1(u) * L2(v) + L_{44} * L3(v) +
154 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); */
155 double dw =
156 planarParameters[0] * L2(u) + planarParameters[1] * L1(u) * L1(v) + planarParameters[2] * L2(v) +
157 planarParameters[3] * L3(u) + planarParameters[4] * L2(u) * L1(v) + planarParameters[5] * L1(u) * L2(v) + planarParameters[6] * L3(
158 v) +
159 planarParameters[7] * L4(u) + planarParameters[8] * L3(u) * L1(v) + planarParameters[9] * L2(u) * L2(v) + planarParameters[10] * L1(
160 u) * L3(v) + planarParameters[11] * L4(v);
161
162 double du_dw = state.getState()[1]; // slope in U direction
163 double dv_dw = state.getState()[2]; // slope in V direction
164
165 u = u * width / 2; // from Legendre to Local parametrization
166 v = v * length / 2; // from Legendre to Local parametrization
167
168 TVectorD pos(1);
169
170 if (m_isU) {
171 pos[0] = u + dw * du_dw;
172 } else {
173 pos[0] = v + dw * dv_dw;
174 }
175
176 return pos;
177}
178
179std::vector<genfit::MeasurementOnPlane*> SVDRecoHit::constructMeasurementsOnPlane(const genfit::StateOnPlane& state) const
180{
181 if (!m_isU || m_rotationPhi == 0.0) {
182
183 // Apply planar deformation to rectangular sensor or V coordinate of slanted sensor
184 TVectorD pos = applyPlanarDeformation(rawHitCoords_, VXD::GeoCache::getInstance().getSensorInfo(m_sensorID).getSurfaceParameters(),
185 state);
186
187 return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(pos, rawHitCov_, state.getPlane(),
188 state.getRep(), this->constructHMatrix(state.getRep())));
189 }
190
191 // Wedged sensor: the measured coordinate in U depends on V and the
192 // rotation angle. Namely, it needs to be scaled.
193 double u = rawHitCoords_(0);
194 double v = state.getState()(4);
195 double uPrime = u - v * tan(m_rotationPhi);
196 double scale = uPrime / u;
197
198 TVectorD coords(1);
199 coords(0) = uPrime;
200
201 // Apply planar deformation to U coordinate of slanted sensor
202 TVectorD pos = applyPlanarDeformation(coords, VXD::GeoCache::getInstance().getSensorInfo(m_sensorID).getSurfaceParameters(), state);
203
204 TMatrixDSym cov(scale * scale * rawHitCov_);
205
206 return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(pos, cov, state.getPlane(), state.getRep(),
207 this->constructHMatrix(state.getRep())));
208}
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
virtual std::vector< genfit::MeasurementOnPlane * > constructMeasurementsOnPlane(const genfit::StateOnPlane &state) const override
Methods that actually interface to Genfit.
Definition: SVDRecoHit.cc:179
TVectorD applyPlanarDeformation(TVectorD rawHit, std::vector< double > planarParameters, const genfit::StateOnPlane &state) const
Apply planar deformation of sensors.
Definition: SVDRecoHit.cc:115
float m_energyDep
deposited energy.
Definition: SVDRecoHit.h:123
bool m_isU
transient member (not written out during streaming)
Definition: SVDRecoHit.h:122
unsigned short m_sensorID
Unique sensor identifier.
Definition: SVDRecoHit.h:117
void setDetectorPlane()
Set up Detector plane information.
Definition: SVDRecoHit.cc:89
float m_rotationPhi
angle of the plane rotation, for u in wedge sensors.
Definition: SVDRecoHit.h:125
genfit::AbsMeasurement * clone() const override
Creating a deep copy of this hit.
Definition: SVDRecoHit.cc:110
SVDRecoHit()
Default constructor for ROOT IO.
Definition: SVDRecoHit.cc:23
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
void setRotation(double phi)
Set plane rotation angle.
Definition: SensorPlane.h:49
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.