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
22#include <Math/Vector3D.h>
23#include <Math/Vector2D.h>
24
25using namespace Belle2;
26using namespace CDC;
27using namespace TrackFindingCDC;
28using namespace TrackingUtilities;
29
30namespace {
31 CDCSegment3D reconstruct(const CDCSegment2D& segment2D,
32 const CDCTrajectory3D& trajectory3D)
33 {
34 CDCSegment3D result;
35 CDCTrajectory2D trajectory2D = trajectory3D.getTrajectory2D();
36 CDCTrajectorySZ trajectorySZ = trajectory3D.getTrajectorySZ();
37
38 result.reserve(segment2D.size());
39 for (const CDCRecoHit2D& recoHit2D : segment2D) {
40 result.push_back(CDCRecoHit3D::reconstruct(recoHit2D, trajectory2D, trajectorySZ));
41 }
42 return result;
43 }
44}
45
47{
48 const CDCSegment2D* ptrFromSegment = segmentPair.getFromSegment();
49 const CDCSegment2D* ptrToSegment = segmentPair.getToSegment();
50
51 if (not ptrFromSegment) {
52 B2WARNING("From segment unset.");
53 return;
54 }
55
56 if (not ptrToSegment) {
57 B2WARNING("To segment unset.");
58 return;
59 }
60
61 const CDCSegment2D& fromSegment = *ptrFromSegment;
62 const CDCSegment2D& toSegment = *ptrToSegment;
63
64 CDCTrajectory3D trajectory3D = reconstructFuseTrajectories(fromSegment, toSegment);
65 segmentPair.setTrajectory3D(trajectory3D);
66}
67
69{
70 const CDCSegment2D* ptrFromSegment = segmentPair.getFromSegment();
71 const CDCSegment2D* ptrToSegment = segmentPair.getToSegment();
72
73 if (not ptrFromSegment) {
74 B2WARNING("From segment unset.");
75 return;
76 }
77
78 if (not ptrToSegment) {
79 B2WARNING("To segment unset.");
80 return;
81 }
82 const CDCSegment2D& fromSegment = *ptrFromSegment;
83 const CDCSegment2D& toSegment = *ptrToSegment;
84
85 CDCTrajectory3D trajectory3D = fusePreliminary(fromSegment, toSegment);
86 segmentPair.setTrajectory3D(trajectory3D);
87}
88
89
91 const CDCSegment2D& toSegment2D)
92{
93 CDCTrajectory3D preliminaryTrajectory3D = fusePreliminary(fromSegment2D, toSegment2D);
94 return reconstructFuseTrajectories(fromSegment2D, toSegment2D, preliminaryTrajectory3D);
95}
96
98 const CDCSegment2D& toSegment2D)
99{
100 if (fromSegment2D.empty()) {
101 B2WARNING("From segment is empty.");
102 return CDCTrajectory3D();
103 }
104
105 if (toSegment2D.empty()) {
106 B2WARNING("To segment is empty.");
107 return CDCTrajectory3D();
108 }
109
110 bool fromIsAxial = fromSegment2D.isAxial();
111 const CDCSegment2D& axialSegment2D = fromIsAxial ? fromSegment2D : toSegment2D;
112 const CDCSegment2D& stereoSegment2D = not fromIsAxial ? fromSegment2D : toSegment2D;
113
114 CDCTrajectory2D axialTrajectory2D = axialSegment2D.getTrajectory2D();
115
116 ROOT::Math::XYVector localOrigin2D = (fromIsAxial ? fromSegment2D.back() : toSegment2D.front()).getRecoPos2D();
117 axialTrajectory2D.setLocalOrigin(localOrigin2D);
118
119 CDCSegment3D stereoSegment3D = CDCSegment3D::reconstruct(stereoSegment2D, axialTrajectory2D);
120
121 CDCTrajectorySZ trajectorySZ;
122
124 trajectorySZ = szFitter.fit(stereoSegment3D);
125 if (not trajectorySZ.isFitted()) {
126 CDCTrajectory3D result;
127 result.setChi2(NAN);
128 return result;
129 }
130
131 CDCTrajectory3D preliminaryTrajectory3D(axialTrajectory2D, trajectorySZ);
132 ROOT::Math::XYZVector localOrigin3D(localOrigin2D.X(), localOrigin2D.Y(), 0.0);
133 preliminaryTrajectory3D.setLocalOrigin(localOrigin3D);
134 return preliminaryTrajectory3D;
135}
136
138 const CDCSegment2D& toSegment2D,
139 const CDCTrajectory3D& preliminaryTrajectory3D)
140{
141 ROOT::Math::XYZVector localOrigin3D = preliminaryTrajectory3D.getLocalOrigin();
142 ROOT::Math::XYVector localOrigin2D = VectorUtil::getXYVector(localOrigin3D);
143
144 CDCRiemannFitter riemannFitter;
145 //riemannFitter.useOnlyOrientation();
146 riemannFitter.useOnlyPosition();
147
148 CDCSegment3D fromSegment3D = reconstruct(fromSegment2D, preliminaryTrajectory3D);
149 CDCSegment3D toSegment3D = reconstruct(toSegment2D, preliminaryTrajectory3D);
150
152 double tanLambda = preliminaryTrajectory3D.getTanLambda();
153 m_driftLengthEstimator.updateDriftLength(fromSegment3D, tanLambda);
154 m_driftLengthEstimator.updateDriftLength(toSegment3D, tanLambda);
155 }
156
157 CDCTrajectory2D fromTrajectory2D = riemannFitter.fit(fromSegment3D);
158 CDCTrajectory2D toTrajectory2D = riemannFitter.fit(toSegment3D);
159
160 fromTrajectory2D.setLocalOrigin(localOrigin2D);
161 toTrajectory2D.setLocalOrigin(localOrigin2D);
162
163 SZParameters refSZ = preliminaryTrajectory3D.getLocalSZLine().szParameters();
164
165 const UncertainPerigeeCircle& fromCircle = fromTrajectory2D.getLocalCircle();
166 const UncertainPerigeeCircle& toCircle = toTrajectory2D.getLocalCircle();
167
168 JacobianMatrix<3, 5> fromH = calcAmbiguity(fromSegment3D, fromTrajectory2D);
169 JacobianMatrix<3, 5> toH = calcAmbiguity(toSegment3D, toTrajectory2D);
170
171 UncertainHelix resultHelix = UncertainHelix::average(fromCircle, fromH, toCircle, toH, refSZ);
172 return CDCTrajectory3D(localOrigin3D, resultHelix);
173}
174
175PerigeeHelixAmbiguity CDCAxialStereoFusion::calcAmbiguity(const CDCSegment3D& segment3D,
176 const CDCTrajectory2D& trajectory2D)
177{
178 size_t nHits = segment3D.size();
179
180 const ROOT::Math::XYVector& localOrigin2D = trajectory2D.getLocalOrigin();
181 const UncertainPerigeeCircle& localCircle = trajectory2D.getLocalCircle();
182
183 double zeta = 0;
184 for (const CDCRecoHit3D& recoHit3D : segment3D) {
185 const ROOT::Math::XYVector& recoPos2D = recoHit3D.getRecoPos2D();
186 const ROOT::Math::XYVector localRecoPos2D = recoPos2D - localOrigin2D;
187 const ROOT::Math::XYVector normal = localCircle->normal(localRecoPos2D);
188 const CDCWire& wire = recoHit3D.getWire();
189 zeta += wire.getWireLine().sagMovePerZ(recoHit3D.getRecoZ()).Dot(normal);
190 }
191 zeta /= nHits;
192
193 PerigeeHelixAmbiguity result = HelixUtil::defaultPerigeeAmbiguity();
194
195 using namespace NHelixParameterIndices;
196 result(c_Curv, c_Curv) = 1.0;
197 result(c_Phi0, c_Phi0) = 1.0;
198 result(c_I, c_I) = 1.0;
199
200 result(c_Phi0, c_TanL) = zeta;
201 result(c_I, c_Z0) = - zeta;
202
203 return result;
204}
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 ROOT::Math::XYVector &localOrigin)
Setter for the origin of the local coordinate system.
const ROOT::Math::XYVector & 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.
double setLocalOrigin(const ROOT::Math::XYZVector &localOrigin)
Setter for the origin of the local coordinate system.
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.
const ROOT::Math::XYZVector & getLocalOrigin() const
Getter for the origin of the local coordinate system.
bool isFitted() const
Indicates if the line has been fitted.
ROOT::Math::XYVector normal(const ROOT::Math::XYVector &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.
This class represents an ideal helix in perigee parameterization including the covariance matrix of t...
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.