Belle II Software  release-05-01-25
CDCRecoHit3D.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit3D.h>
11 
12 #include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit2D.h>
13 #include <tracking/trackFindingCDC/eventdata/hits/CDCRLWireHit.h>
14 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
15 
16 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory3D.h>
17 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
18 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
19 
20 #include <tracking/trackFindingCDC/topology/CDCWire.h>
21 #include <tracking/trackFindingCDC/topology/EStereoKind.h>
22 
23 #include <tracking/trackFindingCDC/geometry/Vector3D.h>
24 #include <tracking/trackFindingCDC/geometry/Vector2D.h>
25 
26 #include <tracking/trackFindingCDC/numerics/ERightLeft.h>
27 
28 #include <tracking/trackFindingCDC/numerics/ESign.h>
29 
30 #include <cdc/dataobjects/CDCSimHit.h>
31 
32 #include <framework/logging/Logger.h>
33 
34 #include <cmath>
35 
36 using namespace Belle2;
37 using namespace TrackFindingCDC;
38 
39 CDCRecoHit3D::CDCRecoHit3D(const CDCRLWireHit& rlWireHit,
40  const Vector3D& recoPos3D,
41  double arcLength2D)
42  : m_rlWireHit(rlWireHit)
43  , m_recoPos3D(recoPos3D)
44  , m_arcLength2D(arcLength2D)
45 {
46 }
47 
49 {
50  // arc length cannot be deduced from the flightTime in this context
51  double arcLength2D = std::numeric_limits<double>::quiet_NaN();
52 
53  return CDCRecoHit3D(CDCRLWireHit::fromSimHit(wireHit, simHit),
54  Vector3D{simHit.getPosTrack()},
55  arcLength2D);
56 }
57 
59  const CDCTrajectory2D& trajectory2D)
60 {
61  Vector3D recoPos3D = recoHit2D.reconstruct3D(trajectory2D);
62  double arcLength2D = trajectory2D.calcArcLength2D(recoPos3D.xy());
63  return CDCRecoHit3D(recoHit2D.getRLWireHit(), recoPos3D, arcLength2D);
64 }
65 
67  ERightLeft rlInfo,
68  const CDCTrajectory2D& trajectory2D)
69 {
70  Vector3D recoPos3D = wireHit->reconstruct3D(trajectory2D, rlInfo);
71  double arcLength2D = trajectory2D.calcArcLength2D(recoPos3D.xy());
72  CDCRLWireHit rlWireHit(wireHit, rlInfo);
73  return CDCRecoHit3D(rlWireHit, recoPos3D, arcLength2D);
74 }
75 
77  const CDCTrajectory2D& trajectory2D)
78 {
79  Vector3D recoPos3D = rlWireHit.reconstruct3D(trajectory2D);
80  double arcLength2D = trajectory2D.calcArcLength2D(recoPos3D.xy());
81  return CDCRecoHit3D(rlWireHit, recoPos3D, arcLength2D);
82 }
83 
85  const CDCTrajectory3D& trajectory3D)
86 {
87  // This this is quite legacy behaviour - do something smarter.
88  CDCTrajectory2D trajectory2D = trajectory3D.getTrajectory2D();
89  CDCTrajectorySZ trajectorySZ = trajectory3D.getTrajectorySZ();
90 
91  return reconstruct(recoHit, trajectory2D, trajectorySZ);
92 }
93 
95  const CDCTrajectory2D& trajectory2D,
96  const CDCTrajectorySZ& trajectorySZ)
97 {
98  EStereoKind stereoKind = recoHit2D.getStereoKind();
99 
100  double arcLength2D = 0;
101  if (stereoKind == EStereoKind::c_StereoU or stereoKind == EStereoKind::c_StereoV) {
102  //the closest approach of a wire line to a helix
103  //( in this case representated by the two trajectories )
104  //can not be solved as a closed expression
105  //in the common case the z fit has been derived from the reconstructed points generated
106  //with the reconstruct methode above in the other reconstruct method.
107  //sticking to that method but using the average z from the sz fit
108  Vector3D recoPos3D = recoHit2D.reconstruct3D(trajectory2D);
109  arcLength2D = trajectory2D.calcArcLength2D(recoPos3D.xy());
110 
111  } else { /* if (stereoKind == EStereoKind::c_Axial)*/
112  Vector2D recoPos2D = trajectory2D.getClosest(recoHit2D.getRecoPos2D());
113  arcLength2D = trajectory2D.calcArcLength2D(recoPos2D);
114 
115  }
116 
117  const double z = trajectorySZ.mapSToZ(arcLength2D);
118 
119  // Reevaluating the z position eventually accounts for wire sag.
120  const CDCWire& wire = recoHit2D.getWire();
121  const Vector2D recoWirePos2D = wire.getWirePos2DAtZ(z);
122  const Vector2D correctedRecoPos2D = trajectory2D.getClosest(recoWirePos2D);
123  const double correctedPerpS = trajectory2D.calcArcLength2D(correctedRecoPos2D);
124  const double correctedZ = trajectorySZ.mapSToZ(correctedPerpS);
125  const Vector3D correctedRecoPos3D(correctedRecoPos2D, correctedZ);
126 
127  CDCRecoHit3D result(recoHit2D.getRLWireHit(), correctedRecoPos3D, correctedPerpS);
128  result.snapToDriftCircle();
129  return result;
130 }
131 
133  const CDCTrajectory2D& trajectory2D)
134 {
135  B2ASSERT("This function can only be used with axial hits.", axialWireHit->isAxial());
136  ERightLeft rlInfo = trajectory2D.isRightOrLeft(axialWireHit->getRefPos2D());
137  CDCRLWireHit rlWireHit(axialWireHit, rlInfo);
138  return CDCRecoHit3D::reconstruct(rlWireHit, trajectory2D);
139 }
140 
142 {
143  if (first.getRLWireHit() == second.getRLWireHit()) {
144  return CDCRecoHit3D(first.getRLWireHit(),
145  Vector3D::average(first.getRecoPos3D(), second.getRecoPos3D()),
146  (first.getArcLength2D() + second.getArcLength2D()) / 2);
147  } else {
148  B2ERROR("Averaging three dimensional hits which are on different oriented wire hits. Return "
149  "first one unchanged");
150  return first;
151  }
152 }
153 
155 {
156  const CDCWire& wire = getWire();
157  const double recoPosZ = getRecoPos3D().z();
158 
159  Vector2D wirePos = wire.getWirePos2DAtZ(recoPosZ);
160  Vector2D disp2D = getRecoPos3D().xy() - wirePos;
161  return disp2D;
162 }
163 
165 {
167 }
168 
170 {
172 }
173 
174 void CDCRecoHit3D::snapToDriftCircle(bool switchSide)
175 {
176  const CDCWire& wire = getWire();
177  const double recoPosZ = getRecoPos3D().z();
178 
179  Vector2D wirePos = wire.getWirePos2DAtZ(recoPosZ);
180  Vector2D disp2D = getRecoPos3D().xy() - wirePos;
181 
182  disp2D.normalizeTo(fabs(getSignedRecoDriftLength()));
183  if (switchSide) {
184  disp2D = -disp2D;
185  }
186  m_recoPos3D = Vector3D(wirePos + disp2D, recoPosZ);
187 }
188 
189 void CDCRecoHit3D::setRecoDriftLength(double driftLength, bool snapRecoPos)
190 {
191  double oldDriftLength = m_rlWireHit.getRefDriftLength();
192  m_rlWireHit.setRefDriftLength(driftLength);
193  if (snapRecoPos) {
194  bool switchSide = sign(oldDriftLength) != sign(driftLength);
195  snapToDriftCircle(switchSide);
196  }
197 }
198 
200 {
202 }
203 
205 {
206  return getRecoHit2D();
207 }
208 
210 {
211  return getWire().getWirePos2DAtZ(getRecoZ());
212 }
213 
214 bool CDCRecoHit3D::isInCellZBounds(const double factor) const
215 {
216  return getWire().isInCellZBounds(getRecoPos3D(), factor);
217 }
Belle2::TrackFindingCDC::CDCRecoHit3D::getRecoDisp2D
Vector2D getRecoDisp2D() const
Gets the displacement from the wire position in the xy plain at the reconstructed position.
Definition: CDCRecoHit3D.cc:154
Belle2::TrackFindingCDC::CDCRecoHit3D::getWire
const CDCWire & getWire() const
Getter for the wire.
Definition: CDCRecoHit3D.h:236
Belle2::Vector3D
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition: Cell.h:35
Belle2::TrackFindingCDC::CDCRecoHit3D
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:62
Belle2::TrackFindingCDC::CDCRecoHit3D::m_recoPos3D
Vector3D m_recoPos3D
Memory for the reconstructed hit position.
Definition: CDCRecoHit3D.h:402
Belle2::TrackFindingCDC::Vector2D::normalizeTo
double normalizeTo(const double toLength)
Normalizes the vector to the given length.
Definition: Vector2D.h:327
Belle2::TrackFindingCDC::CDCRecoHit3D::CDCRecoHit3D
CDCRecoHit3D()=default
Default constructor for ROOT.
Belle2::TrackFindingCDC::CDCRecoHit3D::getRecoWirePos2D
Vector2D getRecoWirePos2D() const
Returns the position of the wire in the xy plain the reconstructed position is located in.
Definition: CDCRecoHit3D.cc:209
Belle2::CDCSimHit::getPosTrack
TVector3 getPosTrack() const
The method to get position on the track.
Definition: CDCSimHit.h:234
Belle2::TrackFindingCDC::Vector2D
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:37
Belle2::TrackFindingCDC::CDCRecoHit3D::reversed
CDCRecoHit3D reversed() const
Returns the recohit with the opposite right left information.
Definition: CDCRecoHit3D.cc:169
Belle2::TrackFindingCDC::CDCRecoHit2D::getRecoPos2D
Vector2D getRecoPos2D() const
Getter for the position in the reference plane.
Definition: CDCRecoHit2D.h:248
Belle2::TrackFindingCDC::CDCRecoHit2D::getRLWireHit
const CDCRLWireHit & getRLWireHit() const
Getter for the oriented wire hit assoziated with the reconstructed hit.
Definition: CDCRecoHit2D.h:291
Belle2::TrackFindingCDC::CDCRLWireHit::getRefDriftLength
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
Definition: CDCRLWireHit.h:214
Belle2::TrackFindingCDC::CDCRecoHit3D::fromSimHit
static CDCRecoHit3D fromSimHit(const CDCWireHit *wireHit, const CDCSimHit &simHit)
Constructs a three dimensional reconstructed hit from a sim hit and the assoziated wirehit.
Definition: CDCRecoHit3D.cc:48
Belle2::TrackFindingCDC::CDCRecoHit3D::getRecoZ
double getRecoZ() const
Getter for the z coordinate of the reconstructed position.
Definition: CDCRecoHit3D.h:313
Belle2::TrackFindingCDC::CDCRecoHit3D::snapToDriftCircle
void snapToDriftCircle(bool switchSide=false)
Scales the displacement vector in place to lie on the dirft circle.
Definition: CDCRecoHit3D.cc:174
Belle2::TrackFindingCDC::CDCRecoHit3D::reverse
void reverse()
Turns the orientation in place.
Definition: CDCRecoHit3D.cc:164
Belle2::TrackFindingCDC::CDCWire::isInCellZBounds
bool isInCellZBounds(const Vector3D &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:297
Belle2::TrackFindingCDC::CDCTrajectorySZ
Linear trajectory in sz space.
Definition: CDCTrajectorySZ.h:41
Belle2::TrackFindingCDC::CDCRecoHit3D::getArcLength2D
double getArcLength2D() const
Getter for the travel distance in the xy projection.
Definition: CDCRecoHit3D.h:380
Belle2::TrackFindingCDC::CDCTrajectory2D::getClosest
Vector2D getClosest(const Vector2D &point) const
Calculates the closest approach on the trajectory to the given point.
Definition: CDCTrajectory2D.cc:173
Belle2::CDCSimHit
Example Detector.
Definition: CDCSimHit.h:33
Belle2::TrackFindingCDC::CDCTrajectory2D
Particle trajectory as it is seen in xy projection represented as a circle.
Definition: CDCTrajectory2D.h:46
Belle2::TrackFindingCDC::CDCWire::getWirePos2DAtZ
Vector2D getWirePos2DAtZ(const double z) const
Gives the xy projected position of the wire at the given z coordinate.
Definition: CDCWire.h:194
Belle2::TrackFindingCDC::CDCRecoHit3D::reconstructNearest
static CDCRecoHit3D reconstructNearest(const CDCWireHit *axialWireHit, const CDCTrajectory2D &trajectory2D)
Reconstruct a three dimensional hit from a wire hit (as in reconstruct(rlWireHit, trajectory2D)),...
Definition: CDCRecoHit3D.cc:132
Belle2::TrackFindingCDC::CDCTrajectorySZ::mapSToZ
double mapSToZ(const double s=0) const
Translates the travel distance to the z coordinate.
Definition: CDCTrajectorySZ.h:65
Belle2::TrackFindingCDC::CDCRecoHit3D::average
static CDCRecoHit3D average(const CDCRecoHit3D &first, const CDCRecoHit3D &second)
Constructs the average of two reconstructed hit positions.
Definition: CDCRecoHit3D.cc:141
Belle2::TrackFindingCDC::CDCRecoHit2D::getWire
const CDCWire & getWire() const
Getter for the wire the reconstructed hit assoziated to.
Definition: CDCRecoHit2D.h:185
Belle2::TrackFindingCDC::Vector3D::average
static Vector3D average(const Vector3D &one, const Vector3D &two)
Constructs the average of two vectors.
Definition: Vector3D.h:82
Belle2::TrackFindingCDC::CDCTrajectory3D::getTrajectory2D
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
Definition: CDCTrajectory3D.cc:336
Belle2::TrackFindingCDC::CDCTrajectory2D::isRightOrLeft
ERightLeft isRightOrLeft(const Vector2D &point) const
Checks if the given point is to the right or to the left of the trajectory.
Definition: CDCTrajectory2D.h:425
Belle2::TrackFindingCDC::CDCTrajectory3D::getTrajectorySZ
CDCTrajectorySZ getTrajectorySZ() const
Getter for the sz trajectory.
Definition: CDCTrajectory3D.cc:343
Belle2::TrackFindingCDC::CDCRecoHit2D
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:57
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::CDCRLWireHit
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Definition: CDCRLWireHit.h:51
Belle2::TrackFindingCDC::CDCRecoHit3D::getRLWireHit
const CDCRLWireHit & getRLWireHit() const
Getter for the oriented wire hit.
Definition: CDCRecoHit3D.h:260
Belle2::TrackFindingCDC::Vector3D
A three dimensional vector.
Definition: Vector3D.h:34
Belle2::TrackFindingCDC::CDCRLWireHit::reverse
void reverse()
Swiches the right left passage to its opposite inplace.
Definition: CDCRLWireHit.h:108
Belle2::TrackFindingCDC::NRightLeft::ERightLeft
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:35
Belle2::TrackFindingCDC::CDCRecoHit3D::stereoProjectToRef
CDCRecoHit2D stereoProjectToRef() const
Constructs a two dimensional reconstructed hit by carrying out the stereo ! projection to the wire re...
Definition: CDCRecoHit3D.cc:204
Belle2::TrackFindingCDC::CDCRLWireHit::setRefDriftLength
void setRefDriftLength(double driftLength)
Setter for the drift length at the reference position of the wire.
Definition: CDCRLWireHit.h:220
Belle2::TrackFindingCDC::CDCRecoHit3D::isInCellZBounds
bool isInCellZBounds(const double factor=1) const
Indicator if the hit is in the cdc (scaled by the factor) or already outside its boundaries.
Definition: CDCRecoHit3D.cc:214
Belle2::TrackFindingCDC::Vector3D::xy
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
Definition: Vector3D.h:500
Belle2::TrackFindingCDC::CDCWire
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:60
Belle2::TrackFindingCDC::CDCRecoHit2D::getStereoKind
EStereoKind getStereoKind() const
Getter for the stereo type of the underlying wire.
Definition: CDCRecoHit2D.h:167
Belle2::TrackFindingCDC::CDCRecoHit3D::getSignedRecoDriftLength
double getSignedRecoDriftLength() const
Returns the drift length next to the reconstructed position.
Definition: CDCRecoHit3D.h:356
Belle2::TrackFindingCDC::CDCRecoHit3D::setRecoDriftLength
void setRecoDriftLength(double driftLength, bool snapRecoPos)
Setter to update the drift length of the hit.
Definition: CDCRecoHit3D.cc:189
Belle2::TrackFindingCDC::Vector3D::z
double z() const
Getter for the z coordinate.
Definition: Vector3D.h:488
Belle2::TrackFindingCDC::CDCWireHit
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:65
Belle2::TrackFindingCDC::CDCRecoHit3D::reconstruct
static CDCRecoHit3D reconstruct(const CDCRecoHit2D &recoHit2D, const CDCTrajectory2D &trajectory2D)
Reconstructs the three dimensional hit from the two dimensional and the two dimensional trajectory.
Definition: CDCRecoHit3D.cc:58
Belle2::TrackFindingCDC::CDCRecoHit3D::getRecoPos3D
const Vector3D & getRecoPos3D() const
Getter for the 3d position of the hit.
Definition: CDCRecoHit3D.h:295
Belle2::TrackFindingCDC::CDCRLWireHit::reconstruct3D
Vector3D reconstruct3D(const CDCTrajectory2D &trajectory2D, double z=0) const
Attempts to reconstruct a three dimensional position (especially of stereo hits).
Definition: CDCRLWireHit.cc:183
Belle2::TrackFindingCDC::CDCTrajectory2D::calcArcLength2D
double calcArcLength2D(const Vector2D &point) const
Calculate the travel distance from the start position of the trajectory.
Definition: CDCTrajectory2D.h:270
Belle2::TrackFindingCDC::CDCRecoHit2D::reconstruct3D
Vector3D reconstruct3D(const CDCTrajectory2D &trajectory2D, const double z=0) const
Reconstruct the three dimensional position (especially of stereo hits) by determinating the z coordin...
Definition: CDCRecoHit2D.cc:133
Belle2::TrackFindingCDC::CDCTrajectory3D
Particle full three dimensional trajectory.
Definition: CDCTrajectory3D.h:47
Belle2::TrackFindingCDC::CDCRecoHit3D::m_rlWireHit
CDCRLWireHit m_rlWireHit
Memory for the oriented wire hit reference.
Definition: CDCRecoHit3D.h:399
Belle2::TrackFindingCDC::CDCRecoHit3D::getRecoHit2D
CDCRecoHit2D getRecoHit2D() const
Constructs a two dimensional reconstructed hit by carrying out the stereo ! projection to the wire re...
Definition: CDCRecoHit3D.cc:199
Belle2::TrackFindingCDC::CDCRLWireHit::fromSimHit
static CDCRLWireHit fromSimHit(const CDCWireHit *wirehit, const CDCSimHit &simhit)
Constructs an oriented wire hit from a CDCSimHit and the associated wirehit.
Definition: CDCRLWireHit.cc:114