Belle II Software development
CDCAxialStereoFusion.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/CDCAxialStereoFusion.h>
9
10#include <tracking/trackFindingCDC/fitting/CDCSZFitter.h>
11#include <tracking/trackFindingCDC/fitting/CDCRiemannFitter.h>
12
13#include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentPair.h>
14#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment3D.h>
15#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
16#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory3D.h>
17#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
18#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
19
20#include <tracking/trackFindingCDC/topology/CDCWire.h>
21
22using namespace Belle2;
23using namespace TrackFindingCDC;
24
25namespace {
26 CDCSegment3D reconstruct(const CDCSegment2D& segment2D,
27 const CDCTrajectory3D& trajectory3D)
28 {
29 CDCSegment3D result;
30 CDCTrajectory2D trajectory2D = trajectory3D.getTrajectory2D();
31 CDCTrajectorySZ trajectorySZ = trajectory3D.getTrajectorySZ();
32
33 result.reserve(segment2D.size());
34 for (const CDCRecoHit2D& recoHit2D : segment2D) {
35 result.push_back(CDCRecoHit3D::reconstruct(recoHit2D, trajectory2D, trajectorySZ));
36 }
37 return result;
38 }
39}
40
42{
43 const CDCSegment2D* ptrFromSegment = segmentPair.getFromSegment();
44 const CDCSegment2D* ptrToSegment = segmentPair.getToSegment();
45
46 if (not ptrFromSegment) {
47 B2WARNING("From segment unset.");
48 return;
49 }
50
51 if (not ptrToSegment) {
52 B2WARNING("To segment unset.");
53 return;
54 }
55
56 const CDCSegment2D& fromSegment = *ptrFromSegment;
57 const CDCSegment2D& toSegment = *ptrToSegment;
58
59 CDCTrajectory3D trajectory3D = reconstructFuseTrajectories(fromSegment, toSegment);
60 segmentPair.setTrajectory3D(trajectory3D);
61}
62
64{
65 const CDCSegment2D* ptrFromSegment = segmentPair.getFromSegment();
66 const CDCSegment2D* ptrToSegment = segmentPair.getToSegment();
67
68 if (not ptrFromSegment) {
69 B2WARNING("From segment unset.");
70 return;
71 }
72
73 if (not ptrToSegment) {
74 B2WARNING("To segment unset.");
75 return;
76 }
77 const CDCSegment2D& fromSegment = *ptrFromSegment;
78 const CDCSegment2D& toSegment = *ptrToSegment;
79
80 CDCTrajectory3D trajectory3D = fusePreliminary(fromSegment, toSegment);
81 segmentPair.setTrajectory3D(trajectory3D);
82}
83
84
86 const CDCSegment2D& toSegment2D)
87{
88 CDCTrajectory3D preliminaryTrajectory3D = fusePreliminary(fromSegment2D, toSegment2D);
89 return reconstructFuseTrajectories(fromSegment2D, toSegment2D, preliminaryTrajectory3D);
90}
91
93 const CDCSegment2D& toSegment2D)
94{
95 if (fromSegment2D.empty()) {
96 B2WARNING("From segment is empty.");
97 return CDCTrajectory3D();
98 }
99
100 if (toSegment2D.empty()) {
101 B2WARNING("To segment is empty.");
102 return CDCTrajectory3D();
103 }
104
105 bool fromIsAxial = fromSegment2D.isAxial();
106 const CDCSegment2D& axialSegment2D = fromIsAxial ? fromSegment2D : toSegment2D;
107 const CDCSegment2D& stereoSegment2D = not fromIsAxial ? fromSegment2D : toSegment2D;
108
109 CDCTrajectory2D axialTrajectory2D = axialSegment2D.getTrajectory2D();
110
111 Vector2D localOrigin2D = (fromIsAxial ? fromSegment2D.back() : toSegment2D.front()).getRecoPos2D();
112 axialTrajectory2D.setLocalOrigin(localOrigin2D);
113
114 CDCSegment3D stereoSegment3D = CDCSegment3D::reconstruct(stereoSegment2D, axialTrajectory2D);
115
116 CDCTrajectorySZ trajectorySZ;
117
119 trajectorySZ = szFitter.fit(stereoSegment3D);
120 if (not trajectorySZ.isFitted()) {
121 CDCTrajectory3D result;
122 result.setChi2(NAN);
123 return result;
124 }
125
126 CDCTrajectory3D preliminaryTrajectory3D(axialTrajectory2D, trajectorySZ);
127 Vector3D localOrigin3D(localOrigin2D, 0.0);
128 preliminaryTrajectory3D.setLocalOrigin(localOrigin3D);
129 return preliminaryTrajectory3D;
130}
131
133 const CDCSegment2D& toSegment2D,
134 const CDCTrajectory3D& preliminaryTrajectory3D)
135{
136 Vector3D localOrigin3D = preliminaryTrajectory3D.getLocalOrigin();
137 Vector2D localOrigin2D = localOrigin3D.xy();
138
139 CDCRiemannFitter riemannFitter;
140 //riemannFitter.useOnlyOrientation();
141 riemannFitter.useOnlyPosition();
142
143 CDCSegment3D fromSegment3D = reconstruct(fromSegment2D, preliminaryTrajectory3D);
144 CDCSegment3D toSegment3D = reconstruct(toSegment2D, preliminaryTrajectory3D);
145
147 double tanLambda = preliminaryTrajectory3D.getTanLambda();
148 m_driftLengthEstimator.updateDriftLength(fromSegment3D, tanLambda);
149 m_driftLengthEstimator.updateDriftLength(toSegment3D, tanLambda);
150 }
151
152 CDCTrajectory2D fromTrajectory2D = riemannFitter.fit(fromSegment3D);
153 CDCTrajectory2D toTrajectory2D = riemannFitter.fit(toSegment3D);
154
155 fromTrajectory2D.setLocalOrigin(localOrigin2D);
156 toTrajectory2D.setLocalOrigin(localOrigin2D);
157
158 SZParameters refSZ = preliminaryTrajectory3D.getLocalSZLine().szParameters();
159
160 const UncertainPerigeeCircle& fromCircle = fromTrajectory2D.getLocalCircle();
161 const UncertainPerigeeCircle& toCircle = toTrajectory2D.getLocalCircle();
162
163 JacobianMatrix<3, 5> fromH = calcAmbiguity(fromSegment3D, fromTrajectory2D);
164 JacobianMatrix<3, 5> toH = calcAmbiguity(toSegment3D, toTrajectory2D);
165
166 UncertainHelix resultHelix = UncertainHelix::average(fromCircle, fromH, toCircle, toH, refSZ);
167 return CDCTrajectory3D(localOrigin3D, resultHelix);
168}
169
171 const CDCTrajectory2D& trajectory2D)
172{
173 size_t nHits = segment3D.size();
174
175 const Vector2D& localOrigin2D = trajectory2D.getLocalOrigin();
176 const UncertainPerigeeCircle& localCircle = trajectory2D.getLocalCircle();
177
178 double zeta = 0;
179 for (const CDCRecoHit3D& recoHit3D : segment3D) {
180 const Vector2D& recoPos2D = recoHit3D.getRecoPos2D();
181 const Vector2D localRecoPos2D = recoPos2D - localOrigin2D;
182 const Vector2D normal = localCircle->normal(localRecoPos2D);
183 const CDCWire& wire = recoHit3D.getWire();
184 zeta += wire.getWireLine().sagMovePerZ(recoHit3D.getRecoZ()).dot(normal);
185 }
186 zeta /= nHits;
187
189
190 using namespace NHelixParameterIndices;
191 result(c_Curv, c_Curv) = 1.0;
192 result(c_Phi0, c_Phi0) = 1.0;
193 result(c_I, c_I) = 1.0;
194
195 result(c_Phi0, c_TanL) = zeta;
196 result(c_I, c_Z0) = - zeta;
197
198 return result;
199}
DriftLengthEstimator m_driftLengthEstimator
Helper object to carry out the drift length estimation.
void fusePreliminary(const CDCSegmentPair &segmentPair)
Fit the given segment pair using the preliminary helix fit without proper covariance matrix.
void reconstructFuseTrajectories(const CDCSegmentPair &segmentPair)
Combine the two trajectories of the segments in the pair and assign the resulting three dimensional t...
bool m_reestimateDriftLength
Switch to re-estimate the drift length.
PerigeeHelixAmbiguity calcAmbiguity(const CDCSegment3D &segment3D, const CDCTrajectory2D &trajectory2D)
Calculate the ambiguity of the helix parameters relative to the three circle parameters given the hit...
CDCTrajectory2D fit(const CDCObservations2D &observations2D) const
Fits a collection of observation drift circles.
void useOnlyPosition()
Setup the fitter to use only the reconstructed positions of the hits.
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:47
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:52
static CDCRecoHit3D reconstruct(const CDCRecoHit2D &recoHit2D, const CDCTrajectory2D &trajectory2D)
Reconstructs the three dimensional hit from the two dimensional and the two dimensional trajectory.
Definition: CDCRecoHit3D.cc:56
Class implementing the Riemann fit for two dimensional trajectory circle.
Class implementing the z coordinate over travel distance line fit.
Definition: CDCSZFitter.h:27
static const CDCSZFitter & getFitter()
Getter for a standard sz line fitter instance.
Definition: CDCSZFitter.cc:36
CDCTrajectorySZ fit(const CDCSegment2D &stereoSegment, const CDCTrajectory2D &axialTrajectory2D) const
Returns a fitted trajectory.
Definition: CDCSZFitter.cc:139
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
A segment consisting of three dimensional reconstructed hits.
Definition: CDCSegment3D.h:26
static CDCSegment3D reconstruct(const CDCSegment2D &segment2D, const CDCTrajectory2D &trajectory2D)
Reconstructs a two dimensional stereo segment by shifting each hit onto the given two dimensional tra...
Definition: CDCSegment3D.cc:20
Class representing a pair of one reconstructed axial segment and one stereo segment in adjacent super...
const CDCSegment2D * getToSegment() const
Getter for the to segment.
void setTrajectory3D(const CDCTrajectory3D &trajectory3D) const
Setter for the three dimensional trajectory.
const CDCSegment2D * getFromSegment() const
Getter for the from segment.
bool isAxial() const
Indicator if the underlying wires are axial.
Definition: CDCSegment.h:45
CDCTrajectory2D & getTrajectory2D() const
Getter for the two dimensional trajectory fitted to the segment.
Definition: CDCSegment.h:69
Particle trajectory as it is seen in xy projection represented as a circle.
double setLocalOrigin(const Vector2D &localOrigin)
Setter for the origin of the local coordinate system.
const Vector2D & getLocalOrigin() const
Getter for the origin of the local coordinate system.
const UncertainPerigeeCircle & getLocalCircle() const
Getter for the circle in local coordinates.
Particle full three dimensional trajectory.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
UncertainSZLine getLocalSZLine() const
Getter for the sz line starting from the local origin.
CDCTrajectorySZ getTrajectorySZ() const
Getter for the sz trajectory.
double getTanLambda() const
Getter for the slope of z over the transverse travel distance s.
double setLocalOrigin(const Vector3D &localOrigin)
Setter for the origin of the local coordinate system.
const Vector3D & getLocalOrigin() const
Getter for the origin of the local coordinate system.
Linear trajectory in sz space.
bool isFitted() const
Indicates if the line has been fitted.
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:58
const WireLine & getWireLine() const
Getter for the wire line representation of the wire.
Definition: CDCWire.h:188
Vector2D normal(const Vector2D &point) const
Unit normal vector from the circle to the given point.
A matrix implementation to be used as an interface typ through out the track finder.
Definition: PlainMatrix.h:40
A general helix class including a covariance matrix.
static UncertainHelix average(const UncertainHelix &fromHelix, const UncertainHelix &toHelix)
Construct the averages of the two given helices by properly considering their covariance matrix.
Adds an uncertainty matrix to the circle in perigee parameterisation.
SZParameters szParameters() const
Getter for the sz parameters in the order defined by ESZParameter.h.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
Definition: Vector2D.h:32
double dot(const Vector2D &rhs) const
Calculates the two dimensional dot product.
Definition: Vector2D.h:158
A three dimensional vector.
Definition: Vector3D.h:33
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
Definition: Vector3D.h:508
Vector2D sagMovePerZ(const double z) const
Gives the two dimensional position with wire sag effect of the line at the given z value.
Definition: WireLine.h:75
Abstract base class for different kinds of events.
double updateDriftLength(CDCRecoHit2D &recoHit2D)
Update the drift length of the reconstructed hit in place.
static PerigeeAmbiguity defaultPerigeeAmbiguity()
Initialise a default covariance matrix to zero.