Belle II Software development
CDCSZObservations.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/CDCSZObservations.h>
9
10#include <tracking/trackFindingCDC/fitting/EigenObservationMatrix.h>
11
12#include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
13#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment3D.h>
14#include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit3D.h>
15
16#include <tracking/trackFindingCDC/topology/CDCWire.h>
17
18#include <framework/logging/Logger.h>
19
20using namespace Belle2;
21using namespace TrackFindingCDC;
22
23std::size_t CDCSZObservations::fill(double s, double z, double weight)
24{
25 if (std::isnan(s)) return 0;
26 if (std::isnan(z)) return 0;
27 if (std::isnan(weight)) {
28 B2WARNING("Weight is nan. Skipping observation");
29 return 0;
30 }
31
32 m_szObservations.push_back(s);
33 m_szObservations.push_back(z);
34 m_szObservations.push_back(weight);
35 return 1;
36}
37
38std::size_t CDCSZObservations::append(const CDCRecoHit3D& recoHit3D)
39{
40 if (m_onlyStereo and recoHit3D.isAxial()) return 0;
41
42 const double s = recoHit3D.getArcLength2D();
43 const double z = recoHit3D.getRecoPos3D().z();
44
45 double weight = 1.0;
46 if (m_fitVariance == EFitVariance::c_Unit) {
47 weight = 1;
48 } else {
49 // Translate the drift length uncertainty to a uncertainty in z
50 // by the taking the projected wire vector part parallel to the displacement
51 // as a proportionality factor to the z direction.
52 const CDCWire& wire = recoHit3D.getWire();
53 const Vector3D& wireVector = wire.getWireVector();
54 const Vector2D disp2D = recoHit3D.getRecoDisp2D();
55 const double driftlengthVariance = recoHit3D.getRecoDriftLengthVariance();
56
57 double dispNorm = disp2D.norm();
58
59 double zeta = 1.0;
60 if (dispNorm == 0.0) {
61 zeta = wireVector.xy().norm() / wireVector.z();
62 } else {
63 zeta = wireVector.xy().dot(disp2D) / wireVector.z() / dispNorm;
64 }
65
66 weight = zeta * zeta / driftlengthVariance;
67 }
68
69 size_t appendedHit = fill(s, z, weight);
70 return appendedHit;
71}
72
73std::size_t CDCSZObservations::appendRange(const std::vector<CDCRecoHit3D>& recoHit3Ds)
74{
75 std::size_t nAppendedHits = 0;
76 for (const CDCRecoHit3D& recoHit3D : recoHit3Ds) {
77 nAppendedHits += append(recoHit3D);
78 }
79 return nAppendedHits;
80}
81
82std::size_t CDCSZObservations::appendRange(const CDCSegment3D& segment3D)
83{
84 const std::vector<CDCRecoHit3D> recoHit3Ds = segment3D;
85 return this->appendRange(recoHit3Ds);
86}
87
89{
90 const std::vector<CDCRecoHit3D> recoHit3Ds = track;
91 return this->appendRange(recoHit3Ds);
92}
93
95{
96 std::size_t n = size();
97 if (n == 0) return Vector2D(NAN, NAN);
98 std::size_t i = n / 2;
99
100 if (isEven(n)) {
101 // For even number of observations use the middle one with the bigger distance from IP
102 Vector2D center1(getS(i), getZ(i));
103 Vector2D center2(getS(i - 1), getZ(i - 1));
104 return center1.normSquared() > center2.normSquared() ? center1 : center2;
105 } else {
106 Vector2D center1(getS(i), getZ(i));
107 return center1;
108 }
109}
110
112{
113 Eigen::Matrix<double, 1, 2> eigenOrigin(origin.x(), origin.y());
114 EigenObservationMatrix eigenObservations = getEigenObservationMatrix(this);
115 eigenObservations.leftCols<2>().rowwise() -= eigenOrigin;
116}
117
119{
120 // Pick an observation at the center
121 Vector2D centralPoint = getCentralPoint();
122 passiveMoveBy(centralPoint);
123 return centralPoint;
124}
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:52
const Vector3D & getRecoPos3D() const
Getter for the 3d position of the hit.
Definition: CDCRecoHit3D.h:285
bool isAxial() const
Indicator if the underlying wire is axial.
Definition: CDCRecoHit3D.h:214
const CDCWire & getWire() const
Getter for the wire.
Definition: CDCRecoHit3D.h:226
double getRecoDriftLengthVariance() const
Returns the drift length variance next to the reconstructed position.
Definition: CDCRecoHit3D.h:358
double getArcLength2D() const
Getter for the travel distance in the xy projection.
Definition: CDCRecoHit3D.h:370
Vector2D getRecoDisp2D() const
Gets the displacement from the wire position in the xy plain at the reconstructed position.
std::size_t appendRange(const std::vector< CDCRecoHit3D > &recoHit3Ds)
Appends all reconstructed hits from the three dimensional track.
bool m_onlyStereo
Switch to only use information from stereo hits.
std::size_t fill(double s, double z, double weight=1.0)
Appends the observed position.
Vector2D centralize()
Picks one observation as a reference point and transform all observations to that new origin.
Vector2D getCentralPoint() const
Extracts the observation center that is at the index in the middle.
double getZ(int iObservation) const
Getter for the z value of the observation at the given index.
std::size_t append(const CDCRecoHit3D &recoHit3D)
Appends the observed position.
std::vector< double > m_szObservations
Memory for the individual observations.
void passiveMoveBy(const Vector2D &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.
double getS(int iObservation) const
Getter for the arc length value of the observation at the given index.
A segment consisting of three dimensional reconstructed hits.
Definition: CDCSegment3D.h:26
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:41
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:58
Vector3D getWireVector() const
Getter for the vector pointing from the back end of the wire to the front end of the wire.
Definition: CDCWire.h:248
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
double x() const
Getter for the x coordinate.
Definition: Vector2D.h:595
double normSquared() const
Calculates .
Definition: Vector2D.h:169
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:605
double norm() const
Calculates the length of the vector.
Definition: Vector2D.h:175
A three dimensional vector.
Definition: Vector3D.h:33
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
Definition: Vector3D.h:508
double z() const
Getter for the z coordinate.
Definition: Vector3D.h:496
Abstract base class for different kinds of events.