Belle II Software  release-08-01-10
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 <TVector3.h>
18 #include <TRandom.h>
19 #include <cmath>
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 SVDRecoHit::SVDRecoHit():
25  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(0),
26  m_cluster(0), m_isU(0), m_energyDep(0), m_rotationPhi(0)
27 {
28  setStripV(!m_isU);
29 }
30 
31 SVDRecoHit::SVDRecoHit(const SVDTrueHit* hit, bool uDirection, float sigma):
32  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(hit),
33  m_cluster(0), m_isU(uDirection), m_energyDep(0), m_rotationPhi(0)
34 {
35  setStripV(!m_isU);
36 
37  // Smear the coordinate when constructing from a TrueHit.
38  if (!gRandom) B2FATAL("gRandom not initialized, please set up gRandom first");
39 
40  // Set the sensor UID
41  m_sensorID = hit->getSensorID();
42 
43  //If no error is given, estimate the error to pitch/sqrt(12)
44  if (sigma < 0) {
45  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
46  sigma = (m_isU) ? geometry.getUPitch(hit->getV()) / sqrt(12) : geometry.getVPitch() / sqrt(12);
47  }
48 
49  // Set positions
50  rawHitCoords_(0) = (m_isU) ? gRandom->Gaus(hit->getU(), sigma) : gRandom->Gaus(hit->getV(), sigma);
51  // Set the error covariance matrix
52  rawHitCov_(0, 0) = sigma * sigma;
53  // Set physical parameters
54  m_energyDep = hit->getEnergyDep();
55  // Setup geometry information
57 }
58 
60  genfit::PlanarMeasurement(HIT_DIMENSIONS), m_sensorID(0), m_trueHit(0),
61  m_cluster(hit), m_energyDep(0), m_rotationPhi(0)
62 {
63  // Set the sensor UID
64  m_sensorID = hit->getSensorID();
65  m_isU = hit->isUCluster();
66 
67  setStripV(!m_isU);
68 
69  // Determine if we have a wedge sensor.
70  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
71 
72  bool isWedgeU = m_isU && (geometry.getBackwardWidth() > geometry.getForwardWidth());
73 
74  // Set positions
75  rawHitCoords_(0) = hit->getPosition();
76  if (isWedgeU) {
77  // For u coordinate in a wedge sensor, the position line is not u = const.
78  // We have to rotate the coordinate system to achieve this.
79  m_rotationPhi = atan2((geometry.getBackwardWidth() - geometry.getForwardWidth()) / geometry.getWidth(0) * hit->getPosition(),
80  geometry.getLength());
81  }
82  // Set the error covariance matrix (this does not scale with position)
83  rawHitCov_(0, 0) = hit->getPositionSigma() * hit->getPositionSigma();
84  // Set physical parameters
85  m_energyDep = hit->getCharge();
86  // Setup geometry information
88 }
89 
91 {
92  // Construct a finite detector plane and set it.
93  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
94  bool isWedgeU = m_isU && (geometry.getBackwardWidth() > geometry.getForwardWidth());
95 
96  // Construct vectors o, u, v
97  ROOT::Math::XYZVector uLocal(1, 0, 0);
98  ROOT::Math::XYZVector vLocal(0, 1, 0);
99  ROOT::Math::XYZVector origin = geometry.pointToGlobal(ROOT::Math::XYZVector(0, 0, 0), true);
100  ROOT::Math::XYZVector uGlobal = geometry.vectorToGlobal(uLocal, true);
101  ROOT::Math::XYZVector vGlobal = geometry.vectorToGlobal(vLocal, true);
102 
103  //Construct the detector plane
104  VXD::SensorPlane* finitePlane = new VXD::SensorPlane(m_sensorID, 20.0, 20.0);
105  if (isWedgeU) finitePlane->setRotation(m_rotationPhi);
106  genfit::SharedPlanePtr detPlane(new genfit::DetPlane(XYZToTVector(origin), XYZToTVector(uGlobal), XYZToTVector(vGlobal),
107  finitePlane));
108  setPlane(detPlane, m_sensorID);
109 }
110 
112 {
113  return new SVDRecoHit(*this);
114 }
115 
116 TVectorD SVDRecoHit::applyPlanarDeformation(TVectorD rawHit, std::vector<double> planarParameters,
117  const genfit::StateOnPlane& state) const
118 {
119  // Legendre parametrization of deformation
120  auto L1 = [](double x) {return x;};
121  auto L2 = [](double x) {return (3 * x * x - 1) / 2;};
122  auto L3 = [](double x) {return (5 * x * x * x - 3 * x) / 2;};
123  auto L4 = [](double x) {return (35 * x * x * x * x - 30 * x * x + 3) / 8;};
124 
125  const SVD::SensorInfo& geometry = dynamic_cast<const SVD::SensorInfo&>(VXD::GeoCache::get(m_sensorID));
126 
127  double u = 0;
128  double v = 0;
129  double length = 0;
130  double width = 0;
131 
132  if (m_isU) {
133  u = rawHit[0]; // U coordinate of hit
134  v = state.getState()(4); // V coordinate of hit
135  width = geometry.getWidth(v); // Width of sensor (U side) is function of V (slanted)
136  length = geometry.getLength(); // Length of sensor (V side)
137 
138  u = u * 2 / width; // Legendre parametrization required U in (-1, 1)
139  v = v * 2 / length; // Legendre parametrization required V in (-1, 1)
140 
141  } else {
142  v = rawHit[0]; // V coordinate of hit
143  u = state.getState()(3); // U coordinate of hit
144  length = geometry.getLength(); // Length of sensor (V side) is fuction of V (slanted)
145  width = geometry.getWidth(v); // Width of sensor (U side)
146 
147  v = v * 2 / length; // Legendre parametrization required V in (-1, 1)
148  u = u * 2 / width; // Legendre parametrization required U in (-1, 1)
149 
150  }
151 
152  /* Planar deformation using Legendre parametrization
153  w(u, v) = L_{31} * L2(u) + L_{32} * L1(u) * L1(v) + L_{33} * L2(v) +
154  L_{41} * L3(u) + L_{42} * L2(u) * L1(v) + L_{43} * L1(u) * L2(v) + L_{44} * L3(v) +
155  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); */
156  double dw =
157  planarParameters[0] * L2(u) + planarParameters[1] * L1(u) * L1(v) + planarParameters[2] * L2(v) +
158  planarParameters[3] * L3(u) + planarParameters[4] * L2(u) * L1(v) + planarParameters[5] * L1(u) * L2(v) + planarParameters[6] * L3(
159  v) +
160  planarParameters[7] * L4(u) + planarParameters[8] * L3(u) * L1(v) + planarParameters[9] * L2(u) * L2(v) + planarParameters[10] * L1(
161  u) * L3(v) + planarParameters[11] * L4(v);
162 
163  double du_dw = state.getState()[1]; // slope in U direction
164  double dv_dw = state.getState()[2]; // slope in V direction
165 
166  u = u * width / 2; // from Legendre to Local parametrization
167  v = v * length / 2; // from Legendre to Local parametrization
168 
169  TVectorD pos(1);
170 
171  if (m_isU) {
172  pos[0] = u + dw * du_dw;
173  } else {
174  pos[0] = v + dw * dv_dw;
175  }
176 
177  return pos;
178 }
179 
180 std::vector<genfit::MeasurementOnPlane*> SVDRecoHit::constructMeasurementsOnPlane(const genfit::StateOnPlane& state) const
181 {
182  if (!m_isU || m_rotationPhi == 0.0) {
183 
184  // Apply planar deformation to rectangular sensor or V coordinate of slanted sensor
185  TVectorD pos = applyPlanarDeformation(rawHitCoords_, VXD::GeoCache::get(m_sensorID).getSurfaceParameters(), 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::get(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:180
TVectorD applyPlanarDeformation(TVectorD rawHit, std::vector< double > planarParameters, const genfit::StateOnPlane &state) const
Apply planar deformation of sensors.
Definition: SVDRecoHit.cc:116
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:90
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:111
SVDRecoHit()
Default constructor for ROOT IO.
Definition: SVDRecoHit.cc:24
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
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
double tan(double a)
tan for double
Definition: beamHelpers.h:31
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.