Belle II Software development
CDCObservations2D.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#include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
9
10#include <tracking/trackFindingCDC/fitting/EigenObservationMatrix.h>
11
12#include <tracking/trackingUtilities/eventdata/tracks/CDCTrack.h>
13#include <tracking/trackingUtilities/eventdata/tracks/CDCAxialSegmentPair.h>
14#include <tracking/trackingUtilities/eventdata/segments/CDCSegment3D.h>
15#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
16#include <tracking/trackingUtilities/eventdata/segments/CDCWireHitSegment.h>
17#include <tracking/trackingUtilities/eventdata/hits/CDCFacet.h>
18#include <tracking/trackingUtilities/eventdata/hits/CDCRLWireHitTriple.h>
19#include <tracking/trackingUtilities/eventdata/hits/CDCRLWireHitPair.h>
20#include <tracking/trackingUtilities/eventdata/hits/CDCRLWireHit.h>
21#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
22#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
23#include <tracking/trackingUtilities/geometry/VectorUtil.h>
24
25#include <cdc/topology/CDCWire.h>
26
27#include <Math/Vector2D.h>
28
29using namespace Belle2;
30using namespace CDC;
31using namespace TrackFindingCDC;
32using namespace TrackingUtilities;
33
39
40std::size_t
41CDCObservations2D::fill(double x, double y, double signedRadius, double weight)
42{
43 if (std::isnan(x)) return 0;
44 if (std::isnan(y)) return 0;
45
46 if (std::isnan(signedRadius)) {
47 B2WARNING("Signed radius is nan. Skipping observation");
48 return 0;
49 }
50
51 if (std::isnan(weight)) {
52 B2WARNING("Weight is nan. Skipping observation");
53 return 0;
54 }
55
56 m_observations.push_back(x);
57 m_observations.push_back(y);
58 m_observations.push_back(signedRadius);
59 m_observations.push_back(weight);
60 return 1;
61}
62
63std::size_t
64CDCObservations2D::fill(const ROOT::Math::XYVector& pos2D, double signedRadius, double weight)
65{
66 return fill(pos2D.x(), pos2D.y(), signedRadius, weight);
67}
68
69std::size_t CDCObservations2D::append(const CDCWireHit& wireHit, ERightLeft rlInfo)
70{
71 const ROOT::Math::XYVector& wireRefPos2D = wireHit.getRefPos2D();
72
73 double signedDriftLength = 0;
74 if (m_fitPos == EFitPos::c_RLDriftCircle and isValid(rlInfo)) {
75 signedDriftLength = static_cast<double>(rlInfo) * wireHit.getRefDriftLength();
76 } else {
77 signedDriftLength = 0;
78 }
79
80 double variance = 1;
81 if (m_fitVariance == EFitVariance::c_Unit) {
82 variance = 1;
83 } else if (m_fitVariance == EFitVariance::c_Nominal) {
85 } else if (m_fitVariance == EFitVariance::c_DriftLength) {
86 const double driftLength = wireHit.getRefDriftLength();
87 variance = fabs(driftLength);
88 } else if (m_fitVariance == EFitVariance::c_Pseudo) {
89 variance = getPseudoDriftLengthVariance(wireHit);
90 } else if (m_fitVariance == EFitVariance::c_Proper) {
91 if (abs(rlInfo) != 1) {
92 variance = getPseudoDriftLengthVariance(wireHit);
93 } else {
94 variance = wireHit.getRefDriftLengthVariance();
95 }
96 }
97 return fill(wireRefPos2D, signedDriftLength, 1 / variance);
98}
99
100std::size_t CDCObservations2D::append(const CDCWireHit* wireHit, ERightLeft rlInfo)
101{
102 if (wireHit) {
103 return append(*(wireHit), rlInfo);
104 } else {
105 return 0;
106 }
107}
108
109std::size_t CDCObservations2D::append(const CDCRLWireHit& rlWireHit)
110{
111 const ERightLeft rlInfo = rlWireHit.getRLInfo();
112
113 const double driftLength = rlWireHit.getRefDriftLength();
114 const double driftLengthVariance = rlWireHit.getRefDriftLengthVariance();
115
116 const ROOT::Math::XYVector& wireRefPos2D = rlWireHit.getRefPos2D();
117
118 double signedDriftLength = 0;
119 if (m_fitPos == EFitPos::c_RLDriftCircle and isValid(rlInfo)) {
120 signedDriftLength = static_cast<double>(rlInfo) * driftLength;
121 } else {
122 signedDriftLength = 0;
123 }
124
125 double variance = 1;
126 if (m_fitVariance == EFitVariance::c_Unit) {
127 variance = 1;
128 } else if (m_fitVariance == EFitVariance::c_Nominal) {
130 } else if (m_fitVariance == EFitVariance::c_DriftLength) {
131 variance = fabs(driftLength);
132 } else if (m_fitVariance == EFitVariance::c_Pseudo) {
133 variance = getPseudoDriftLengthVariance(driftLength, driftLengthVariance);
134 } else if (m_fitVariance == EFitVariance::c_Proper) {
135 if (abs(rlInfo) != 1) {
136 variance = getPseudoDriftLengthVariance(driftLength, driftLengthVariance);
137 } else {
138 variance = driftLengthVariance;
139 }
140 }
141
142 return fill(wireRefPos2D, signedDriftLength, 1 / variance);
143}
144
145std::size_t CDCObservations2D::append(const CDCRLWireHitPair& rlWireHitPair)
146{
147 return append(rlWireHitPair.getFromRLWireHit()) + append(rlWireHitPair.getToRLWireHit());
148}
149
150std::size_t CDCObservations2D::append(const CDCRLWireHitTriple& rlWireHitTriple)
151{
152 return append(rlWireHitTriple.getStartRLWireHit()) +
153 append(rlWireHitTriple.getMiddleRLWireHit()) + append(rlWireHitTriple.getEndRLWireHit());
154}
155
156std::size_t CDCObservations2D::append(const CDCFacet& facet)
157{
158 if (m_fitPos == EFitPos::c_RecoPos) {
159 return append(facet.getStartRecoHit2D()) + append(facet.getMiddleRecoHit2D()) +
160 append(facet.getEndRecoHit2D());
161 } else {
162 const CDCRLWireHitTriple& rlWireHitTriple = facet;
163 return append(rlWireHitTriple);
164 }
165}
166
167std::size_t CDCObservations2D::append(const CDCRecoHit2D& recoHit2D)
168{
169 ROOT::Math::XYVector fitPos2D;
170 double signedDriftLength = 0;
171 if (m_fitPos == EFitPos::c_RecoPos) {
172 fitPos2D = recoHit2D.getRecoPos2D();
173 signedDriftLength = 0;
174
175 // Fall back to the rl circle in case position is not setup
176 if (VectorUtil::hasNAN(fitPos2D)) {
177 fitPos2D = recoHit2D.getWire().getRefPos2D();
178 signedDriftLength = recoHit2D.getSignedRefDriftLength();
179 }
180
181 } else if (m_fitPos == EFitPos::c_RLDriftCircle) {
182 fitPos2D = recoHit2D.getWire().getRefPos2D();
183 signedDriftLength = recoHit2D.getSignedRefDriftLength();
184 } else if (m_fitPos == EFitPos::c_WirePos) {
185 fitPos2D = recoHit2D.getWire().getRefPos2D();
186 signedDriftLength = 0;
187 }
188
189 const double driftLength = recoHit2D.getRefDriftLength();
190 const ERightLeft rlInfo = recoHit2D.getRLInfo();
191
192 double variance = recoHit2D.getRefDriftLengthVariance();
193 if (m_fitVariance == EFitVariance::c_Unit) {
194 variance = 1;
195 } else if (m_fitVariance == EFitVariance::c_Nominal) {
197 } else if (m_fitVariance == EFitVariance::c_DriftLength) {
198 variance = std::fabs(driftLength);
199 } else if (m_fitVariance == EFitVariance::c_Pseudo or abs(rlInfo) != 1) {
200 // Fall back to the pseudo variance if the rl information is not known
201 variance = getPseudoDriftLengthVariance(driftLength, variance);
202 }
203 return fill(fitPos2D, signedDriftLength, 1 / variance);
204}
205
206std::size_t CDCObservations2D::append(const CDCRecoHit3D& recoHit3D)
207{
208 ROOT::Math::XYVector fitPos2D = recoHit3D.getRecoPos2D();
209 double signedDriftLength = 0;
210 if (m_fitPos == EFitPos::c_RecoPos) {
211 signedDriftLength = 0;
212 } else if (m_fitPos == EFitPos::c_RLDriftCircle) {
213 fitPos2D = recoHit3D.getRecoWirePos2D();
214 signedDriftLength = recoHit3D.getSignedRecoDriftLength();
215 } else if (m_fitPos == EFitPos::c_WirePos) {
216 fitPos2D = recoHit3D.getRecoWirePos2D();
217 signedDriftLength = 0;
218 }
219
220 const double driftLength = std::fabs(recoHit3D.getSignedRecoDriftLength());
221 const ERightLeft rlInfo = recoHit3D.getRLInfo();
222
223 double variance = recoHit3D.getRecoDriftLengthVariance();
224 if (m_fitVariance == EFitVariance::c_Unit) {
225 variance = 1;
226 } else if (m_fitVariance == EFitVariance::c_Nominal) {
228 } else if (m_fitVariance == EFitVariance::c_DriftLength) {
229 variance = std::fabs(driftLength);
230 } else if (m_fitVariance == EFitVariance::c_Pseudo or abs(rlInfo) != 1) {
231 // Fall back to the pseudo variance if the rl information is not known
232 variance = getPseudoDriftLengthVariance(driftLength, variance);
233 }
234 return fill(fitPos2D, signedDriftLength, 1 / variance);
235}
236
237std::size_t CDCObservations2D::appendRange(const CDCSegment2D& segment2D)
238{
239 std::size_t nAppendedHits = 0;
240 for (const CDCRecoHit2D& recoHit2D : segment2D) {
241 nAppendedHits += append(recoHit2D);
242 }
243 return nAppendedHits;
244}
245
246std::size_t CDCObservations2D::appendRange(const CDCSegment3D& segment3D)
247{
248 std::size_t nAppendedHits = 0;
249 for (const CDCRecoHit3D& recoHit3D : segment3D) {
250 nAppendedHits += append(recoHit3D);
251 }
252 return nAppendedHits;
253}
254
255std::size_t CDCObservations2D::appendRange(const CDCAxialSegmentPair& axialSegmentPair)
256{
257 std::size_t nAppendedHits = 0;
258 const CDCSegment2D* ptrStartSegment2D = axialSegmentPair.getStartSegment();
259 if (ptrStartSegment2D) {
260 const CDCSegment2D& startSegment2D = *ptrStartSegment2D;
261 nAppendedHits += appendRange(startSegment2D);
262 }
263
264 const CDCSegment2D* ptrEndSegment2D = axialSegmentPair.getEndSegment();
265 if (ptrEndSegment2D) {
266 const CDCSegment2D& endSegment2D = *ptrEndSegment2D;
267 nAppendedHits += appendRange(endSegment2D);
268 }
269 return nAppendedHits;
270}
271
273{
274 std::size_t nAppendedHits = 0;
275 for (const CDCRecoHit3D& recoHit3D : track) {
276 nAppendedHits += append(recoHit3D);
277 }
278 return nAppendedHits;
279}
280
281std::size_t CDCObservations2D::appendRange(const std::vector<const CDCWire*>& wires)
282{
283 std::size_t nAppendedHits = 0;
284 for (const CDCWire* ptrWire : wires) {
285 if (not ptrWire) continue;
286 const CDCWire& wire = *ptrWire;
287 const ROOT::Math::XYVector& wirePos = wire.getRefPos2D();
288 const double driftLength = 0.0;
289 const double weight = 1.0;
290 nAppendedHits += fill(wirePos, driftLength, weight);
291 }
292 return nAppendedHits;
293}
294
296{
297 std::size_t nAppendedHits = 0;
298 for (const CDCWireHit* ptrWireHit : wireHits) {
299 if (not ptrWireHit) continue;
300 const CDCWireHit& wireHit = *ptrWireHit;
301 nAppendedHits += append(wireHit);
302 }
303 return nAppendedHits;
304}
305
306double CDCObservations2D::getTotalPerpS(const CDCTrajectory2D& trajectory2D) const
307{
308 return trajectory2D.calcArcLength2DBetween(getFrontPos2D(), getBackPos2D());
309}
310
312{
313 std::size_t result = 0;
314 Index nObservations = size();
315
316 for (Index iObservation = 0; iObservation < nObservations; ++iObservation) {
317 const double driftLength = getDriftLength(iObservation);
318 bool hasDriftLength = (driftLength != 0.0);
319 result += hasDriftLength ? 1 : 0;
320 }
321
322 return result;
323}
324
325ROOT::Math::XYVector CDCObservations2D::getCentralPoint() const
326{
327 std::size_t n = size();
328 if (n == 0) return ROOT::Math::XYVector(NAN, NAN);
329 std::size_t i = n / 2;
330
331 if (isEven(n)) {
332 // For even number of observations use the middle one with the bigger distance from IP
333 ROOT::Math::XYVector center1(getX(i), getY(i));
334 ROOT::Math::XYVector center2(getX(i - 1), getY(i - 1));
335 return center1.Mag2() > center2.Mag2() ? center1 : center2;
336 } else {
337 ROOT::Math::XYVector center1(getX(i), getY(i));
338 return center1;
339 }
340}
341
342void CDCObservations2D::passiveMoveBy(const ROOT::Math::XYVector& origin)
343{
344 Eigen::Matrix<double, 1, 2> eigenOrigin(origin.x(), origin.y());
345 EigenObservationMatrix eigenObservations = getEigenObservationMatrix(this);
346 eigenObservations.leftCols<2>().rowwise() -= eigenOrigin;
347}
348
349ROOT::Math::XYVector CDCObservations2D::centralize()
350{
351 // Pick an observation at the center
352 ROOT::Math::XYVector centralPoint = getCentralPoint();
353 passiveMoveBy(centralPoint);
354 return centralPoint;
355}
static constexpr const double c_simpleDriftLengthVariance
A default value for the drift length variance if no variance from the drift length translation is ava...
Definition CDCWireHit.h:65
Class representing a sense wire in the central drift chamber.
Definition CDCWire.h:50
const ROOT::Math::XYVector & getRefPos2D() const
Getter for the wire reference position for 2D tracking Gives the wire's reference position projected ...
Definition CDCWire.h:221
EFitPos m_fitPos
Indicator which positional information should preferably be extracted from hits in calls to append.
ROOT::Math::XYVector getBackPos2D() const
Get the position of the first observation.
ROOT::Math::XYVector getFrontPos2D() const
Get the position of the first observation.
ROOT::Math::XYVector centralize()
Picks one observation as a reference point and transform all observations to that new origin.
static double getPseudoDriftLengthVariance(double driftLength, double driftLengthVariance)
Gets the pseudo variance.
double getX(int iObservation) const
Getter for the x value of the observation at the given index.
double getY(int iObservation) const
Getter for the y value of the observation at the given index.
std::size_t append(const TrackingUtilities::CDCWireHit &wireHit, TrackingUtilities::ERightLeft rlInfo=TrackingUtilities::ERightLeft::c_Unknown)
Appends the hit circle at wire reference position without a right left passage hypotheses.
std::size_t appendRange(const TrackingUtilities::CDCSegment2D &segment2D)
Appends all reconstructed hits from the two dimensional segment.
double getDriftLength(int iObservation) const
Getter for the signed drift radius of the observation at the given index.
std::size_t fill(double x, double y, double signedRadius=0.0, double weight=1.0)
Appends the observed position.
double getTotalPerpS(const TrackingUtilities::CDCTrajectory2D &trajectory2D) const
Calculate the total transverse travel distance traversed by these observations comparing the travel d...
void passiveMoveBy(const ROOT::Math::XYVector &origin)
Moves all observations passively such that the given vector becomes to origin of the new coordinate s...
EFitVariance m_fitVariance
Indicator which variance information should preferably be extracted from hits in calls to append.
std::size_t size() const
Returns the number of observations stored.
std::size_t getNObservationsWithDriftRadius() const
Returns the number of observations having a drift radius radius.
ROOT::Math::XYVector getCentralPoint() const
Extracts the observation center that is at the index in the middle.
std::vector< double > m_observations
Memory for the individual observations.
Class representing a pair of reconstructed axial segments in adjacent superlayer.
const CDCAxialSegment2D * getEndSegment() const
Getter for the end segment.
const CDCAxialSegment2D * getStartSegment() const
Getter for the start segment.
Class representing a triple of neighboring oriented wire with additional trajectory information.
Definition CDCFacet.h:33
CDCRecoHit2D getEndRecoHit2D() const
Getter for the third reconstructed hit.
Definition CDCFacet.cc:121
CDCRecoHit2D getMiddleRecoHit2D() const
Getter for the second reconstructed hit.
Definition CDCFacet.cc:116
CDCRecoHit2D getStartRecoHit2D() const
Getter for the first reconstructed hit.
Definition CDCFacet.cc:111
CDCRLWireHit & getToRLWireHit()
Getter for the second oriented wire hit.
CDCRLWireHit & getFromRLWireHit()
Getter for the first oriented wire hit.
Class representing a triple of neighboring wire hits.
CDCRLWireHit & getStartRLWireHit()
Getter for the first oriented wire hit.
CDCRLWireHit & getEndRLWireHit()
Getter for the third oriented wire hit.
CDCRLWireHit & getMiddleRLWireHit()
Getter for the second oriented wire hit.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
double getRefDriftLengthVariance() const
Getter for the variance of the drift length at the reference position of the wire.
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
const ROOT::Math::XYVector & getRefPos2D() const
The two dimensional reference position of the underlying wire.
ERightLeft getRLInfo() const
Getter for the right left passage information.
Class representing a two dimensional reconstructed hit in the central drift chamber.
double getRefDriftLengthVariance() const
Getter for the uncertainty in the drift length at the wire reference position.
double getRefDriftLength() const
Getter for the drift length at the wire reference position.
ROOT::Math::XYVector getRecoPos2D() const
Getter for the position in the reference plane.
const CDC::CDCWire & getWire() const
Getter for the wire the reconstructed hit associated to.
double getSignedRefDriftLength() const
Getter for the drift length at the wire reference position signed with the right left passage hypothe...
ERightLeft getRLInfo() const
Getter for the right left passage information.
Class representing a three dimensional reconstructed hit.
ROOT::Math::XYVector getRecoWirePos2D() const
Returns the position of the wire in the xy plain the reconstructed position is located in.
double getSignedRecoDriftLength() const
Returns the drift length next to the reconstructed position.
double getRecoDriftLengthVariance() const
Returns the drift length variance next to the reconstructed position.
const ROOT::Math::XYVector getRecoPos2D() const
Getter for the 2d position of the hit.
ERightLeft getRLInfo() const
Getter for the right left passage information.
A reconstructed sequence of two dimensional hits in one super layer.
A segment consisting of three dimensional reconstructed hits.
Class representing a sequence of three dimensional reconstructed hits.
Definition CDCTrack.h:37
Particle trajectory as it is seen in xy projection represented as a circle.
double calcArcLength2DBetween(const ROOT::Math::XYVector &fromPoint, const ROOT::Math::XYVector &toPoint) const
Calculate the travel distance between the two given positions Returns the travel distance on the traj...
A segment consisting of two dimensional reconstructed hits.
Class representing a hit wire in the central drift chamber.
Definition CDCWireHit.h:56
double getRefDriftLengthVariance() const
Getter for the variance of the drift length at the reference position of the wire.
Definition CDCWireHit.h:231
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition CDCWireHit.h:225
const ROOT::Math::XYVector & getRefPos2D() const
The two dimensional reference position (z=0) of the underlying wire.
Abstract base class for different kinds of events.