Belle II Software development
ExtHit.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 <tracking/dataobjects/ExtHit.h>
10
11#include <TMatrixD.h>
12#include <TMatrixDSym.h>
13
14#include <cmath>
15
16using namespace Belle2;
17
18// empty constructor for ROOT - do not use this
21 m_PdgCode(0),
22 m_DetectorID(Const::EDetector::invalidDetector),
23 m_CopyID(0),
24 m_Status(EXT_FIRST),
25 m_BackwardPropagation(false),
26 m_TOF(0.0)
27{
28 m_Position[0] = 0.0;
29 m_Position[1] = 0.0;
30 m_Position[2] = 0.0;
31 m_Momentum[0] = 0.0;
32 m_Momentum[1] = 0.0;
33 m_Momentum[2] = 0.0;
34 for (int k = 0; k < 21; ++k) {
35 m_Covariance[k] = 0.0;
36 }
37}
38
39// Constructor with initial values
40ExtHit::ExtHit(int pdgCode, Const::EDetector detectorID, int copyID, ExtHitStatus status, bool backwardPropagation, double tof,
41 const ROOT::Math::XYZPoint& position, const ROOT::Math::XYZVector& momentum, const TMatrixDSym& covariance) :
43 m_PdgCode(pdgCode),
44 m_DetectorID(detectorID),
45 m_CopyID(copyID),
46 m_Status(status),
47 m_BackwardPropagation(backwardPropagation),
48 m_TOF(tof)
49{
50 m_Position[0] = position.X();
51 m_Position[1] = position.Y();
52 m_Position[2] = position.Z();
53 m_Momentum[0] = momentum.X();
54 m_Momentum[1] = momentum.Y();
55 m_Momentum[2] = momentum.Z();
56 int k = 0;
57 for (int i = 0; i < 6; ++i) {
58 for (int j = 0; j <= i; ++j) {
59 m_Covariance[k++] = covariance[i][j];
60 }
61 }
62}
63
64// Constructor with initial values
65ExtHit::ExtHit(int pdgCode, Const::EDetector detectorID, int copyID, ExtHitStatus status, bool backwardPropagation, double tof,
66 const G4ThreeVector& position, const G4ThreeVector& momentum, const G4ErrorSymMatrix& covariance) :
68 m_PdgCode(pdgCode),
69 m_DetectorID(detectorID),
70 m_CopyID(copyID),
71 m_Status(status),
72 m_BackwardPropagation(backwardPropagation),
73 m_TOF(tof)
74{
75 m_Position[0] = position.x();
76 m_Position[1] = position.y();
77 m_Position[2] = position.z();
78 m_Momentum[0] = momentum.x();
79 m_Momentum[1] = momentum.y();
80 m_Momentum[2] = momentum.z();
81 int k = 0;
82 for (int i = 0; i < 6; ++i) {
83 for (int j = 0; j <= i; ++j) {
84 m_Covariance[k++] = covariance[i][j];
85 }
86 }
87}
88
89// Copy constructor
92 m_PdgCode(h.m_PdgCode),
93 m_DetectorID(h.m_DetectorID),
94 m_CopyID(h.m_CopyID),
95 m_Status(h.m_Status),
96 m_TOF(h.m_TOF)
97{
98 m_Position[0] = h.m_Position[0];
99 m_Position[1] = h.m_Position[1];
100 m_Position[2] = h.m_Position[2];
101 m_Momentum[0] = h.m_Momentum[0];
102 m_Momentum[1] = h.m_Momentum[1];
103 m_Momentum[2] = h.m_Momentum[2];
104 for (int k = 0; k < 21; ++k) {
105 m_Covariance[k] = h.m_Covariance[k];
106 }
107}
108
109// Assignment operator
111{
112 m_PdgCode = h.m_PdgCode;
113 m_DetectorID = h.m_DetectorID;
114 m_CopyID = h.m_CopyID;
115 m_Status = h.m_Status;
116 m_TOF = h.m_TOF;
117 m_Position[0] = h.m_Position[0];
118 m_Position[1] = h.m_Position[1];
119 m_Position[2] = h.m_Position[2];
120 m_Momentum[0] = h.m_Momentum[0];
121 m_Momentum[1] = h.m_Momentum[1];
122 m_Momentum[2] = h.m_Momentum[2];
123 for (int k = 0; k < 21; ++k) {
124 m_Covariance[k] = h.m_Covariance[k];
125 }
126 return *this;
127}
128
129// Get phase-space covariance at this extrapolation hit
130TMatrixDSym ExtHit::getCovariance() const
131{
132 TMatrixDSym t(6);
133 int k = 0;
134 for (int i = 0; i < 6; ++i) {
135 for (int j = 0; j <= i; ++j) {
136 t[j][i] = t[i][j] = m_Covariance[k++];
137 }
138 }
139 return t;
140}
141
142// Update the information for this extrapolation hit
143void ExtHit::update(ExtHitStatus status, double tof, const G4ThreeVector& position,
144 const G4ThreeVector& momentum, const G4ErrorSymMatrix& covariance)
145{
146 m_Status = status;
147 m_TOF = tof;
148 m_Position[0] = position.x();
149 m_Position[1] = position.y();
150 m_Position[2] = position.z();
151 m_Momentum[0] = momentum.x();
152 m_Momentum[1] = momentum.y();
153 m_Momentum[2] = momentum.z();
154 int k = 0;
155 for (int i = 0; i < 6; ++i) {
156 for (int j = 0; j <= i; ++j) {
157 m_Covariance[k++] = covariance[i][j];
158 }
159 }
160}
161
162// Get the uncertainty in the polar angle theta
164{
165 return sqrt(getPolarCovariance(1));
166}
167
168// Get the uncertainty in the azimuthal angle phi
170{
171 return sqrt(getPolarCovariance(2));
172}
173
174double ExtHit::getPolarCovariance(int i) const
175{
176 TMatrixDSym covariance(3);
177 covariance[0][0] = m_Covariance[0];
178 covariance[0][1] = covariance[1][0] = m_Covariance[1];
179 covariance[1][1] = m_Covariance[2];
180 covariance[0][2] = covariance[2][0] = m_Covariance[3];
181 covariance[1][2] = covariance[2][1] = m_Covariance[4];
182 covariance[2][2] = m_Covariance[5];
183 double perpSq = m_Position[0] * m_Position[0] + m_Position[1] * m_Position[1];
184 double perp = sqrt(perpSq);
185 double rSq = perpSq + m_Position[2] * m_Position[2];
186 double r = sqrt(rSq);
187 TMatrixD jacobian(3, 3);
188 jacobian[0][0] = m_Position[0] / r;
189 jacobian[0][1] = m_Position[1] / r;
190 jacobian[0][2] = m_Position[2] / r;
191 jacobian[1][0] = m_Position[0] * m_Position[2] / (perp * rSq);
192 jacobian[1][1] = m_Position[1] * m_Position[2] / (perp * rSq);
193 jacobian[1][2] = -perp / rSq;
194 jacobian[2][0] = -m_Position[1] / perpSq;
195 jacobian[2][1] = m_Position[0] / perpSq;
196 jacobian[2][2] = 0.0;
197 return (covariance.Similarity(jacobian))[i][i];
198}
This class provides a set of constants for the framework.
Definition: Const.h:34
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
Store one Ext hit as a ROOT object.
Definition: ExtHit.h:31
ExtHit & operator=(const ExtHit &)
Assignment operator.
Definition: ExtHit.cc:110
int m_CopyID
copy ID
Definition: ExtHit.h:187
double getErrorPhi() const
Get the uncertainty in the azimuthal angle phi (radians)
Definition: ExtHit.cc:169
double getErrorTheta() const
Get the uncertainty in the azimuthal angle phi (radians)
Definition: ExtHit.cc:163
double getPolarCovariance(int i) const
Get diagonal elemment of the 3x3 position-covariance matrix in polar coordinates (r,...
Definition: ExtHit.cc:174
float m_Momentum[3]
momentum (GeV/c)
Definition: ExtHit.h:202
TMatrixDSym getCovariance() const
Get phase-space covariance at this extrapolation hit.
Definition: ExtHit.cc:130
int m_PdgCode
PDG code.
Definition: ExtHit.h:181
void update(ExtHitStatus status, double t, const G4ThreeVector &r, const G4ThreeVector &p, const G4ErrorSymMatrix &e)
Update the parameters of this extrapolation hit.
Definition: ExtHit.cc:143
float m_Covariance[21]
phase-space covariance (symmetric 6x6 linearized to 6*(6+1)/2: position & momentum in cm & GeV/c)
Definition: ExtHit.h:205
Const::EDetector m_DetectorID
detector ID
Definition: ExtHit.h:184
float m_TOF
time of flight (ns)
Definition: ExtHit.h:196
ExtHit()
Empty constructor for ROOT IO (needed to make the class storable)
Definition: ExtHit.cc:19
float m_Position[3]
position (cm)
Definition: ExtHit.h:199
ExtHitStatus m_Status
extrapolation state
Definition: ExtHit.h:190
Defines interface for accessing relations of objects in StoreArray.
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
ExtHitStatus
Define state of extrapolation for each recorded hit.
Definition: ExtHit.h:26
Abstract base class for different kinds of events.