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