Belle II Software development
CDCRecoHit3D.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/trackingUtilities/eventdata/hits/CDCRecoHit3D.h>
9
10#include <tracking/trackingUtilities/eventdata/hits/CDCRecoHit2D.h>
11#include <tracking/trackingUtilities/eventdata/hits/CDCRLWireHit.h>
12#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
13
14#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory3D.h>
15#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
16#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectorySZ.h>
17
18#include <cdc/topology/CDCWire.h>
19#include <cdc/topology/EStereoKind.h>
20
21#include <tracking/trackingUtilities/geometry/VectorUtil.h>
22
23#include <tracking/trackingUtilities/numerics/ERightLeft.h>
24
25#include <tracking/trackingUtilities/numerics/ESign.h>
26
27#include <cdc/dataobjects/CDCSimHit.h>
28
29#include <framework/logging/Logger.h>
30
31#include <cmath>
32
33using namespace Belle2;
34using namespace CDC;
35using namespace TrackingUtilities;
36
38 const ROOT::Math::XYZVector& recoPos3D,
39 double arcLength2D)
40 : m_rlWireHit(rlWireHit)
41 , m_recoPos3D(recoPos3D)
42 , m_arcLength2D(arcLength2D)
43{
44}
45
47{
48 // arc length cannot be deduced from the flightTime in this context
49 double arcLength2D = std::numeric_limits<double>::quiet_NaN();
50
51 return CDCRecoHit3D(CDCRLWireHit::fromSimHit(wireHit, simHit),
52 ROOT::Math::XYZVector{simHit.getPosTrack()},
53 arcLength2D);
54}
55
57 const CDCTrajectory2D& trajectory2D)
58{
59 ROOT::Math::XYZVector recoPos3D = recoHit2D.reconstruct3D(trajectory2D);
60 double arcLength2D = trajectory2D.calcArcLength2D(VectorUtil::getXYVector(recoPos3D));
61 return CDCRecoHit3D(recoHit2D.getRLWireHit(), recoPos3D, arcLength2D);
62}
63
65 ERightLeft rlInfo,
66 const CDCTrajectory2D& trajectory2D)
67{
68 ROOT::Math::XYZVector recoPos3D = wireHit->reconstruct3D(trajectory2D, rlInfo);
69 double arcLength2D = trajectory2D.calcArcLength2D(VectorUtil::getXYVector(recoPos3D));
70 CDCRLWireHit rlWireHit(wireHit, rlInfo);
71 return CDCRecoHit3D(rlWireHit, recoPos3D, arcLength2D);
72}
73
75 const CDCTrajectory2D& trajectory2D)
76{
77 ROOT::Math::XYZVector recoPos3D = rlWireHit.reconstruct3D(trajectory2D);
78 double arcLength2D = trajectory2D.calcArcLength2D(VectorUtil::getXYVector(recoPos3D));
79 return CDCRecoHit3D(rlWireHit, recoPos3D, arcLength2D);
80}
81
83 const CDCTrajectory3D& trajectory3D)
84{
85 // This this is quite legacy behaviour - do something smarter.
86 CDCTrajectory2D trajectory2D = trajectory3D.getTrajectory2D();
87 CDCTrajectorySZ trajectorySZ = trajectory3D.getTrajectorySZ();
88
89 return reconstruct(recoHit, trajectory2D, trajectorySZ);
90}
91
93 const CDCTrajectory2D& trajectory2D,
94 const CDCTrajectorySZ& trajectorySZ)
95{
96 EStereoKind stereoKind = recoHit2D.getStereoKind();
97
98 double arcLength2D = 0;
99 if (stereoKind == EStereoKind::c_StereoU or stereoKind == EStereoKind::c_StereoV) {
100 //the closest approach of a wire line to a helix
101 //( in this case represented by the two trajectories )
102 //can not be solved as a closed expression
103 //in the common case the z fit has been derived from the reconstructed points generated
104 //with the reconstruct method above in the other reconstruct method.
105 //sticking to that method but using the average z from the sz fit
106 ROOT::Math::XYZVector recoPos3D = recoHit2D.reconstruct3D(trajectory2D);
107 arcLength2D = trajectory2D.calcArcLength2D(VectorUtil::getXYVector(recoPos3D));
108
109 } else { /* if (stereoKind == EStereoKind::c_Axial)*/
110 ROOT::Math::XYVector recoPos2D = trajectory2D.getClosest(recoHit2D.getRecoPos2D());
111 arcLength2D = trajectory2D.calcArcLength2D(recoPos2D);
112
113 }
114
115 const double z = trajectorySZ.mapSToZ(arcLength2D);
116
117 // Reevaluating the z position eventually accounts for wire sag.
118 const CDCWire& wire = recoHit2D.getWire();
119 const ROOT::Math::XYVector recoWirePos2D = wire.getWirePos2DAtZ(z);
120 const ROOT::Math::XYVector correctedRecoPos2D = trajectory2D.getClosest(recoWirePos2D);
121 const double correctedPerpS = trajectory2D.calcArcLength2D(correctedRecoPos2D);
122 const double correctedZ = trajectorySZ.mapSToZ(correctedPerpS);
123 const ROOT::Math::XYZVector correctedRecoPos3D(correctedRecoPos2D.X(), correctedRecoPos2D.Y(), correctedZ);
124
125 CDCRecoHit3D result(recoHit2D.getRLWireHit(), correctedRecoPos3D, correctedPerpS);
126 result.snapToDriftCircle();
127 return result;
128}
129
131 const CDCTrajectory2D& trajectory2D)
132{
133 B2ASSERT("This function can only be used with axial hits.", axialWireHit->isAxial());
134 ERightLeft rlInfo = trajectory2D.isRightOrLeft(axialWireHit->getRefPos2D());
135 CDCRLWireHit rlWireHit(axialWireHit, rlInfo);
136 return CDCRecoHit3D::reconstruct(rlWireHit, trajectory2D);
137}
138
140{
141 if (first.getRLWireHit() == second.getRLWireHit()) {
142 return CDCRecoHit3D(first.getRLWireHit(),
143 VectorUtil::average(first.getRecoPos3D(), second.getRecoPos3D()),
144 (first.getArcLength2D() + second.getArcLength2D()) / 2);
145 } else {
146 B2ERROR("Averaging three dimensional hits which are on different oriented wire hits. Return "
147 "first one unchanged");
148 return first;
149 }
150}
151
152ROOT::Math::XYVector CDCRecoHit3D::getRecoDisp2D() const
153{
154 const CDCWire& wire = getWire();
155 const double recoPosZ = getRecoPos3D().z();
156
157 ROOT::Math::XYVector wirePos = wire.getWirePos2DAtZ(recoPosZ);
158 ROOT::Math::XYVector disp2D = VectorUtil::getXYVector(getRecoPos3D()) - wirePos;
159 return disp2D;
160}
161
163{
164 m_rlWireHit.reverse();
165}
166
171
173{
174 const CDCWire& wire = getWire();
175 const double recoPosZ = getRecoPos3D().z();
176
177 ROOT::Math::XYVector wirePos = wire.getWirePos2DAtZ(recoPosZ);
178 ROOT::Math::XYVector disp2D = VectorUtil::getXYVector(getRecoPos3D()) - wirePos;
179
180 if (disp2D.R() != 0.0) {
181 disp2D *= (std::fabs(getSignedRecoDriftLength()) / disp2D.R());
182 }
183 if (switchSide) {
184 disp2D = -disp2D;
185 }
186 const auto& tmp = wirePos + disp2D;
187 m_recoPos3D = ROOT::Math::XYZVector(tmp.X(), tmp.Y(), recoPosZ);
188}
189
190void CDCRecoHit3D::setRecoDriftLength(double driftLength, bool snapRecoPos)
191{
192 double oldDriftLength = m_rlWireHit.getRefDriftLength();
193 m_rlWireHit.setRefDriftLength(driftLength);
194 if (snapRecoPos) {
195 bool switchSide = sign(oldDriftLength) != sign(driftLength);
196 snapToDriftCircle(switchSide);
197 }
198}
199
204
209
210ROOT::Math::XYVector CDCRecoHit3D::getRecoWirePos2D() const
211{
212 return getWire().getWirePos2DAtZ(getRecoZ());
213}
214
215bool CDCRecoHit3D::isInCellZBounds(const double factor) const
216{
217 return getWire().isInCellZBounds(getRecoPos3D(), factor);
218}
Example Detector.
Definition CDCSimHit.h:21
B2Vector3D getPosTrack() const
The method to get position on the track.
Definition CDCSimHit.h:216
Class representing a sense wire in the central drift chamber.
Definition CDCWire.h:50
ROOT::Math::XYVector getWirePos2DAtZ(const double z) const
Gives the xy projected position of the wire at the given z coordinate.
Definition CDCWire.h:184
bool isInCellZBounds(const ROOT::Math::XYZVector &pos3D, const double factor=1) const
Checks whether the position is in the z bounds of the drift cell (scaled by the factor) surrounding t...
Definition CDCWire.h:287
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
static CDCRLWireHit fromSimHit(const CDCWireHit *wirehit, const CDCSimHit &simhit)
Constructs an oriented wire hit from a CDCSimHit and the associated wirehit.
ROOT::Math::XYZVector reconstruct3D(const CDCTrajectory2D &trajectory2D, double z=0) const
Attempts to reconstruct a three dimensional position (especially of stereo hits).
Class representing a two dimensional reconstructed hit in the central drift chamber.
const CDCRLWireHit & getRLWireHit() const
Getter for the oriented wire hit associated with the reconstructed hit.
ROOT::Math::XYVector getRecoPos2D() const
Getter for the position in the reference plane.
const CDC::CDCWire & getWire() const
Getter for the wire the reconstructed hit associated to.
ROOT::Math::XYZVector reconstruct3D(const CDCTrajectory2D &trajectory2D, const double z=0) const
Reconstruct the three dimensional position (especially of stereo hits) by determining the z coordinat...
CDC::EStereoKind getStereoKind() const
Getter for the stereo type of the underlying wire.
static CDCRecoHit3D average(const CDCRecoHit3D &first, const CDCRecoHit3D &second)
Constructs the average of two reconstructed hit positions.
ROOT::Math::XYVector getRecoWirePos2D() const
Returns the position of the wire in the xy plain the reconstructed position is located in.
const ROOT::Math::XYZVector & getRecoPos3D() const
Getter for the 3d position of the hit.
double m_arcLength2D
Memory for the travel distance as see in the xy projection.
const CDCRLWireHit & getRLWireHit() const
Getter for the oriented wire hit.
CDCRecoHit3D()=default
Default constructor for ROOT.
void reverse()
Turns the orientation in place.
double getSignedRecoDriftLength() const
Returns the drift length next to the reconstructed position.
ROOT::Math::XYZVector m_recoPos3D
Memory for the reconstructed hit position.
static CDCRecoHit3D reconstruct(const CDCRecoHit2D &recoHit2D, const CDCTrajectory2D &trajectory2D)
Reconstructs the three dimensional hit from the two dimensional and the two dimensional trajectory.
const CDC::CDCWire & getWire() const
Getter for the wire.
CDCRecoHit2D getRecoHit2D() const
Constructs a two dimensional reconstructed hit by carrying out the stereo !
static CDCRecoHit3D fromSimHit(const CDCWireHit *wireHit, const CDCSimHit &simHit)
Constructs a three dimensional reconstructed hit from a sim hit and the associated wirehit.
void snapToDriftCircle(bool switchSide=false)
Scales the displacement vector in place to lie on the drift circle.
double getRecoZ() const
Getter for the z coordinate of the reconstructed position.
ROOT::Math::XYVector getRecoDisp2D() const
Gets the displacement from the wire position in the xy plain at the reconstructed position.
double getArcLength2D() const
Getter for the travel distance in the xy projection.
CDCRecoHit2D stereoProjectToRef() const
Constructs a two dimensional reconstructed hit by carrying out the stereo !
CDCRLWireHit m_rlWireHit
Memory for the oriented wire hit reference.
CDCRecoHit3D reversed() const
Returns the recohit with the opposite right left information.
void setRecoDriftLength(double driftLength, bool snapRecoPos)
Setter to update the drift length of the hit.
static CDCRecoHit3D reconstructNearest(const CDCWireHit *axialWireHit, const CDCTrajectory2D &trajectory2D)
Reconstruct a three dimensional hit from a wire hit (as in reconstruct(rlWireHit, trajectory2D)),...
bool isInCellZBounds(const double factor=1) const
Indicator if the hit is in the cdc (scaled by the factor) or already outside its boundaries.
Particle trajectory as it is seen in xy projection represented as a circle.
ROOT::Math::XYVector getClosest(const ROOT::Math::XYVector &point) const
Calculates the closest approach on the trajectory to the given point.
double calcArcLength2D(const ROOT::Math::XYVector &point) const
Calculate the travel distance from the start position of the trajectory.
ERightLeft isRightOrLeft(const ROOT::Math::XYVector &point) const
Checks if the given point is to the right or to the left of the trajectory.
Particle full three dimensional trajectory.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
CDCTrajectorySZ getTrajectorySZ() const
Getter for the sz trajectory.
double mapSToZ(const double s=0) const
Translates the travel distance to the z coordinate.
Class representing a hit wire in the central drift chamber.
Definition CDCWireHit.h:56
EStereoKind
Type for the stereo property of the wire.
Definition EStereoKind.h:20
Abstract base class for different kinds of events.