Belle II Software  release-06-00-14
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 <svd/reconstruction/SVDRecoHit.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 SVDRecoHit::SVDRecoHit():
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 
30 SVDRecoHit::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) {
44  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
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 
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.
69  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
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.
92  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
93  bool isWedgeU = m_isU && (geometry.getBackwardWidth() > geometry.getForwardWidth());
94 
95  // Construct vectors o, u, v
96  TVector3 uLocal(1, 0, 0);
97  TVector3 vLocal(0, 1, 0);
98  TVector3 origin = geometry.pointToGlobal(TVector3(0, 0, 0), true);
99  TVector3 uGlobal = geometry.vectorToGlobal(uLocal, true);
100  TVector3 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(origin, uGlobal, vGlobal, finitePlane));
106  setPlane(detPlane, m_sensorID);
107 }
108 
110 {
111  return new SVDRecoHit(*this);
112 }
113 
114 TVectorD SVDRecoHit::applyPlanarDeformation(TVectorD rawHit, std::vector<double> planarParameters,
115  const genfit::StateOnPlane& state) const
116 {
117  // Legendre parametrization of deformation
118  auto L1 = [](double x) {return x;};
119  auto L2 = [](double x) {return (3 * x * x - 1) / 2;};
120  auto L3 = [](double x) {return (5 * x * x * x - 3 * x) / 2;};
121  auto L4 = [](double x) {return (35 * x * x * x * x - 30 * x * x + 3) / 8;};
122 
123  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
124 
125  double u = 0;
126  double v = 0;
127  double length = 0;
128  double width = 0;
129 
130  if (m_isU) {
131  u = rawHit[0]; // U coordinate of hit
132  v = state.getState()(4); // V coordinate of hit
133  width = geometry.getWidth(v); // Width of sensor (U side) is function of V (slanted)
134  length = geometry.getLength(); // Length of sensor (V side)
135 
136  u = u * 2 / width; // Legendre parametrization required U in (-1, 1)
137  v = v * 2 / length; // Legendre parametrization required V in (-1, 1)
138 
139  } else {
140  v = rawHit[0]; // V coordinate of hit
141  u = state.getState()(3); // U coordinate of hit
142  length = geometry.getLength(); // Length of sensor (V side) is fuction of V (slanted)
143  width = geometry.getWidth(v); // Width of sensor (U side)
144 
145  v = v * 2 / length; // Legendre parametrization required V in (-1, 1)
146  u = u * 2 / width; // Legendre parametrization required U in (-1, 1)
147 
148  }
149 
150  /* Planar deformation using Legendre parametrization
151  w(u, v) = L_{31} * L2(u) + L_{32} * L1(u) * L1(v) + L_{33} * L2(v) +
152  L_{41} * L3(u) + L_{42} * L2(u) * L1(v) + L_{43} * L1(u) * L2(v) + L_{44} * L3(v) +
153  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); */
154  double dw =
155  planarParameters[0] * L2(u) + planarParameters[1] * L1(u) * L1(v) + planarParameters[2] * L2(v) +
156  planarParameters[3] * L3(u) + planarParameters[4] * L2(u) * L1(v) + planarParameters[5] * L1(u) * L2(v) + planarParameters[6] * L3(
157  v) +
158  planarParameters[7] * L4(u) + planarParameters[8] * L3(u) * L1(v) + planarParameters[9] * L2(u) * L2(v) + planarParameters[10] * L1(
159  u) * L3(v) + planarParameters[11] * L4(v);
160 
161  double du_dw = state.getState()[1]; // slope in U direction
162  double dv_dw = state.getState()[2]; // slope in V direction
163 
164  u = u * width / 2; // from Legendre to Local parametrization
165  v = v * length / 2; // from Legendre to Local parametrization
166 
167  TVectorD pos(1);
168 
169  if (m_isU) {
170  pos[0] = u + dw * du_dw;
171  } else {
172  pos[0] = v + dw * dv_dw;
173  }
174 
175  return pos;
176 }
177 
178 std::vector<genfit::MeasurementOnPlane*> SVDRecoHit::constructMeasurementsOnPlane(const genfit::StateOnPlane& state) const
179 {
180  if (!m_isU || m_rotationPhi == 0.0) {
181 
182  // Apply planar deformation to rectangular sensor or V coordinate of slanted sensor
183  TVectorD pos = applyPlanarDeformation(rawHitCoords_, VXD::GeoCache::get(m_sensorID).getSurfaceParameters(), state);
184 
185  return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(pos, rawHitCov_, state.getPlane(),
186  state.getRep(), this->constructHMatrix(state.getRep())));
187  }
188 
189  // Wedged sensor: the measured coordinate in U depends on V and the
190  // rotation angle. Namely, it needs to be scaled.
191  double u = rawHitCoords_(0);
192  double v = state.getState()(4);
193  double uPrime = u - v * tan(m_rotationPhi);
194  double scale = uPrime / u;
195 
196  TVectorD coords(1);
197  coords(0) = uPrime;
198 
199  // Apply planar deformation to U coordinate of slanted sensor
200  TVectorD pos = applyPlanarDeformation(coords, VXD::GeoCache::get(m_sensorID).getSurfaceParameters(), state);
201 
202  TMatrixDSym cov(scale * scale * rawHitCov_);
203 
204  return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(pos, cov, state.getPlane(), state.getRep(),
205  this->constructHMatrix(state.getRep())));
206 }
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:28
virtual std::vector< genfit::MeasurementOnPlane * > constructMeasurementsOnPlane(const genfit::StateOnPlane &state) const override
Methods that actually interface to Genfit.
Definition: SVDRecoHit.cc:178
TVectorD applyPlanarDeformation(TVectorD rawHit, std::vector< double > planarParameters, const genfit::StateOnPlane &state) const
Apply planar deformation of sensors.
Definition: SVDRecoHit.cc:114
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:109
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
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
void setRotation(double phi)
Set plane rotation angle.
Definition: SensorPlane.h:49
Contains the measurement and covariance in raw detector coordinates.
Detector plane.
Definition: DetPlane.h:59
Measured coordinates on a plane.
void setStripV(bool v=true)
Use if the coordinate for 1D hits measured in V direction.
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.