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/trackingUtilities/eventdata/tracks/CDCSegmentPair.h>
14#include <tracking/trackingUtilities/eventdata/segments/CDCSegment3D.h>
15#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
16#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory3D.h>
17#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
18#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectorySZ.h>
19
20#include <cdc/topology/CDCWire.h>
21
22using namespace Belle2;
23using namespace CDC;
24using namespace TrackFindingCDC;
25using namespace TrackingUtilities;
26
27namespace {
28 CDCSegment3D reconstruct(const CDCSegment2D& segment2D,
29 const CDCTrajectory3D& trajectory3D)
30 {
31 CDCSegment3D result;
32 CDCTrajectory2D trajectory2D = trajectory3D.getTrajectory2D();
33 CDCTrajectorySZ trajectorySZ = trajectory3D.getTrajectorySZ();
34
35 result.reserve(segment2D.size());
36 for (const CDCRecoHit2D& recoHit2D : segment2D) {
37 result.push_back(CDCRecoHit3D::reconstruct(recoHit2D, trajectory2D, trajectorySZ));
38 }
39 return result;
40 }
41}
42
44{
45 const CDCSegment2D* ptrFromSegment = segmentPair.getFromSegment();
46 const CDCSegment2D* ptrToSegment = segmentPair.getToSegment();
47
48 if (not ptrFromSegment) {
49 B2WARNING("From segment unset.");
50 return;
51 }
52
53 if (not ptrToSegment) {
54 B2WARNING("To segment unset.");
55 return;
56 }
57
58 const CDCSegment2D& fromSegment = *ptrFromSegment;
59 const CDCSegment2D& toSegment = *ptrToSegment;
60
61 CDCTrajectory3D trajectory3D = reconstructFuseTrajectories(fromSegment, toSegment);
62 segmentPair.setTrajectory3D(trajectory3D);
63}
64
66{
67 const CDCSegment2D* ptrFromSegment = segmentPair.getFromSegment();
68 const CDCSegment2D* ptrToSegment = segmentPair.getToSegment();
69
70 if (not ptrFromSegment) {
71 B2WARNING("From segment unset.");
72 return;
73 }
74
75 if (not ptrToSegment) {
76 B2WARNING("To segment unset.");
77 return;
78 }
79 const CDCSegment2D& fromSegment = *ptrFromSegment;
80 const CDCSegment2D& toSegment = *ptrToSegment;
81
82 CDCTrajectory3D trajectory3D = fusePreliminary(fromSegment, toSegment);
83 segmentPair.setTrajectory3D(trajectory3D);
84}
85
86
88 const CDCSegment2D& toSegment2D)
89{
90 CDCTrajectory3D preliminaryTrajectory3D = fusePreliminary(fromSegment2D, toSegment2D);
91 return reconstructFuseTrajectories(fromSegment2D, toSegment2D, preliminaryTrajectory3D);
92}
93
95 const CDCSegment2D& toSegment2D)
96{
97 if (fromSegment2D.empty()) {
98 B2WARNING("From segment is empty.");
99 return CDCTrajectory3D();
100 }
101
102 if (toSegment2D.empty()) {
103 B2WARNING("To segment is empty.");
104 return CDCTrajectory3D();
105 }
106
107 bool fromIsAxial = fromSegment2D.isAxial();
108 const CDCSegment2D& axialSegment2D = fromIsAxial ? fromSegment2D : toSegment2D;
109 const CDCSegment2D& stereoSegment2D = not fromIsAxial ? fromSegment2D : toSegment2D;
110
111 CDCTrajectory2D axialTrajectory2D = axialSegment2D.getTrajectory2D();
112
113 Vector2D localOrigin2D = (fromIsAxial ? fromSegment2D.back() : toSegment2D.front()).getRecoPos2D();
114 axialTrajectory2D.setLocalOrigin(localOrigin2D);
115
116 CDCSegment3D stereoSegment3D = CDCSegment3D::reconstruct(stereoSegment2D, axialTrajectory2D);
117
118 CDCTrajectorySZ trajectorySZ;
119
121 trajectorySZ = szFitter.fit(stereoSegment3D);
122 if (not trajectorySZ.isFitted()) {
123 CDCTrajectory3D result;
124 result.setChi2(NAN);
125 return result;
126 }
127
128 CDCTrajectory3D preliminaryTrajectory3D(axialTrajectory2D, trajectorySZ);
129 Vector3D localOrigin3D(localOrigin2D, 0.0);
130 preliminaryTrajectory3D.setLocalOrigin(localOrigin3D);
131 return preliminaryTrajectory3D;
132}
133
135 const CDCSegment2D& toSegment2D,
136 const CDCTrajectory3D& preliminaryTrajectory3D)
137{
138 Vector3D localOrigin3D = preliminaryTrajectory3D.getLocalOrigin();
139 Vector2D localOrigin2D = localOrigin3D.xy();
140
141 CDCRiemannFitter riemannFitter;
142 //riemannFitter.useOnlyOrientation();
143 riemannFitter.useOnlyPosition();
144
145 CDCSegment3D fromSegment3D = reconstruct(fromSegment2D, preliminaryTrajectory3D);
146 CDCSegment3D toSegment3D = reconstruct(toSegment2D, preliminaryTrajectory3D);
147
149 double tanLambda = preliminaryTrajectory3D.getTanLambda();
150 m_driftLengthEstimator.updateDriftLength(fromSegment3D, tanLambda);
151 m_driftLengthEstimator.updateDriftLength(toSegment3D, tanLambda);
152 }
153
154 CDCTrajectory2D fromTrajectory2D = riemannFitter.fit(fromSegment3D);
155 CDCTrajectory2D toTrajectory2D = riemannFitter.fit(toSegment3D);
156
157 fromTrajectory2D.setLocalOrigin(localOrigin2D);
158 toTrajectory2D.setLocalOrigin(localOrigin2D);
159
160 SZParameters refSZ = preliminaryTrajectory3D.getLocalSZLine().szParameters();
161
162 const UncertainPerigeeCircle& fromCircle = fromTrajectory2D.getLocalCircle();
163 const UncertainPerigeeCircle& toCircle = toTrajectory2D.getLocalCircle();
164
165 JacobianMatrix<3, 5> fromH = calcAmbiguity(fromSegment3D, fromTrajectory2D);
166 JacobianMatrix<3, 5> toH = calcAmbiguity(toSegment3D, toTrajectory2D);
167
168 UncertainHelix resultHelix = UncertainHelix::average(fromCircle, fromH, toCircle, toH, refSZ);
169 return CDCTrajectory3D(localOrigin3D, resultHelix);
170}
171
172PerigeeHelixAmbiguity CDCAxialStereoFusion::calcAmbiguity(const CDCSegment3D& segment3D,
173 const CDCTrajectory2D& trajectory2D)
174{
175 size_t nHits = segment3D.size();
176
177 const Vector2D& localOrigin2D = trajectory2D.getLocalOrigin();
178 const UncertainPerigeeCircle& localCircle = trajectory2D.getLocalCircle();
179
180 double zeta = 0;
181 for (const CDCRecoHit3D& recoHit3D : segment3D) {
182 const Vector2D& recoPos2D = recoHit3D.getRecoPos2D();
183 const Vector2D localRecoPos2D = recoPos2D - localOrigin2D;
184 const Vector2D normal = localCircle->normal(localRecoPos2D);
185 const CDCWire& wire = recoHit3D.getWire();
186 zeta += wire.getWireLine().sagMovePerZ(recoHit3D.getRecoZ()).Dot(normal);
187 }
188 zeta /= nHits;
189
190 PerigeeHelixAmbiguity result = HelixUtil::defaultPerigeeAmbiguity();
191
192 using namespace NHelixParameterIndices;
193 result(c_Curv, c_Curv) = 1.0;
194 result(c_Phi0, c_Phi0) = 1.0;
195 result(c_I, c_I) = 1.0;
196
197 result(c_Phi0, c_TanL) = zeta;
198 result(c_I, c_Z0) = - zeta;
199
200 return result;
201}
Class representing a sense wire in the central drift chamber.
Definition CDCWire.h:50
const WireLine & getWireLine() const
Getter for the wire line representation of the wire.
Definition CDCWire.h:180
ROOT::Math::XYVector 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:83
DriftLengthEstimator m_driftLengthEstimator
Helper object to carry out the drift length estimation.
bool m_reestimateDriftLength
Switch to re-estimate the drift length.
void reconstructFuseTrajectories(const TrackingUtilities::CDCSegmentPair &segmentPair)
Combine the two trajectories of the segments in the pair and assign the resulting three dimensional t...
TrackingUtilities::PerigeeHelixAmbiguity calcAmbiguity(const TrackingUtilities::CDCSegment3D &segment3D, const TrackingUtilities::CDCTrajectory2D &trajectory2D)
Calculate the ambiguity of the helix parameters relative to the three circle parameters given the hit...
void fusePreliminary(const TrackingUtilities::CDCSegmentPair &segmentPair)
Fit the given segment pair using the preliminary helix fit without proper covariance matrix.
TrackingUtilities::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 implementing the Riemann fit for two dimensional trajectory circle.
Class implementing the z coordinate over travel distance line fit.
Definition CDCSZFitter.h:29
TrackingUtilities::CDCTrajectorySZ fit(const TrackingUtilities::CDCSegment2D &stereoSegment, const TrackingUtilities::CDCTrajectory2D &axialTrajectory2D) const
Returns a fitted trajectory.
static const CDCSZFitter & getFitter()
Getter for a standard sz line fitter instance.
Class representing a two dimensional reconstructed hit in the central drift chamber.
Class representing a three dimensional reconstructed hit.
static CDCRecoHit3D reconstruct(const CDCRecoHit2D &recoHit2D, const CDCTrajectory2D &trajectory2D)
Reconstructs the three dimensional hit from the two dimensional and the two dimensional trajectory.
A reconstructed sequence of two dimensional hits in one super layer.
A segment consisting of three dimensional reconstructed hits.
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...
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.
bool isFitted() const
Indicates if the line has been fitted.
Vector2D normal(const Vector2D &point) const
Unit normal vector from the circle to the given point.
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:36
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
Definition Vector3D.h:513
This class represents an ideal helix in perigee parameterization including the covariance matrix of t...
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition Cell.h:34
Namespace to hide the contained enum constants.
Abstract base class for different kinds of events.
static PerigeeAmbiguity defaultPerigeeAmbiguity()
Initialise a default covariance matrix to zero.