Belle II Software  release-05-01-25
CDCSegmentPair.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2014 - 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/tracks/CDCSegmentPair.h>
11 
12 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
13 #include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit2D.h>
14 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory3D.h>
15 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
16 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
17 
18 #include <tracking/trackFindingCDC/topology/EStereoKind.h>
19 #include <tracking/trackFindingCDC/topology/ISuperLayer.h>
20 
21 #include <tracking/trackFindingCDC/geometry/Vector2D.h>
22 
23 #include <tracking/trackFindingCDC/ca/AutomatonCell.h>
24 
25 #include <tracking/trackFindingCDC/numerics/EForwardBackward.h>
26 
27 #include <framework/logging/Logger.h>
28 
29 #include <memory>
30 #include <cmath>
31 
32 using namespace Belle2;
33 using namespace TrackFindingCDC;
34 
36  : m_fromSegment(nullptr)
37  , m_toSegment(nullptr)
38 {
39 }
40 
41 CDCSegmentPair::CDCSegmentPair(const CDCSegment2D* fromSegment, const CDCSegment2D* toSegment)
42  : m_fromSegment(fromSegment)
43  , m_toSegment(toSegment)
44 {
45  B2ASSERT("CDCSegmentPair initialized with nullptr as from segment", fromSegment);
46  B2ASSERT("CDCSegmentPair initialized with nullptr as to segment", toSegment);
47 }
48 
50  const CDCSegment2D* toSegment,
51  const CDCTrajectory3D& trajectory3D)
52  : m_fromSegment(fromSegment)
53  , m_toSegment(toSegment)
54  , m_trajectory3D(trajectory3D)
55 {
56  B2ASSERT("CDCSegmentPair initialized with nullptr as from segment", fromSegment);
57  B2ASSERT("CDCSegmentPair initialized with nullptr as to segment", toSegment);
58 }
59 
60 
62 {
63  return getFromSegment() == nullptr ? EStereoKind::c_Invalid
64  : getFromSegment()->back().getStereoKind();
65 }
66 
68 {
69  return getToSegment() == nullptr ? EStereoKind::c_Invalid
70  : getToSegment()->front().getStereoKind();
71 }
72 
74 {
75  return getFromSegment() == nullptr ? ISuperLayerUtil::c_Invalid
76  : getFromSegment()->back().getISuperLayer();
77 }
78 
80 {
81  return getToSegment() == nullptr ? ISuperLayerUtil::c_Invalid
82  : getToSegment()->front().getISuperLayer();
83 }
84 
85 std::size_t CDCSegmentPair::size() const
86 {
87  return getFromSegment()->size() + getToSegment()->size();
88 }
89 
91 {
93 }
94 
96 {
98 }
99 
101 {
103  const bool toHits = true;
104  getFromSegment()->unsetAndForwardMaskedFlag(toHits);
105  getToSegment()->unsetAndForwardMaskedFlag(toHits);
106 }
107 
109 {
111  const bool toHits = true;
112  getFromSegment()->setAndForwardMaskedFlag(toHits);
113  getToSegment()->setAndForwardMaskedFlag(toHits);
114 }
115 
117 {
118  const bool fromHits = true;
119  getFromSegment()->receiveMaskedFlag(fromHits);
120  getToSegment()->receiveMaskedFlag(fromHits);
121 
122  if (getFromSegment()->getAutomatonCell().hasMaskedFlag() or
123  getToSegment()->getAutomatonCell().hasMaskedFlag()) {
125  }
126 }
127 
129 {
130  const CDCSegment2D* ptrFromSegment = getFromSegment();
131  const CDCSegment2D* ptrToSegment = getToSegment();
132 
133  if (not ptrFromSegment) {
134  return NAN;
135  }
136 
137  if (not ptrToSegment) {
138  return NAN;
139  }
140 
141  const CDCSegment2D& fromSegment = *ptrFromSegment;
142  const CDCSegment2D& toSegment = *ptrToSegment;
143 
144  if (fromSegment.empty() or toSegment.empty()) {
145  return NAN;
146  }
147 
148  const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
149  const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
150 
151  const Vector2D lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
152  const Vector2D firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
153 
154  return lastPos2D_fromSegment.angleWith(firstPos2D_toSegment);
155 }
156 
158 {
159  const CDCSegment2D* ptrFromSegment = getFromSegment();
160  const CDCSegment2D* ptrToSegment = getToSegment();
161 
162  if (not ptrFromSegment) {
163  return NAN;
164  }
165 
166  if (not ptrToSegment) {
167  return NAN;
168  }
169 
170  const CDCSegment2D& fromSegment = *ptrFromSegment;
171  const CDCSegment2D& toSegment = *ptrToSegment;
172 
173  if (fromSegment.empty() or toSegment.empty()) {
174  return NAN;
175  }
176 
177  const CDCRecoHit2D& firstRecoHit_fromSegment = fromSegment.front();
178  const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
179 
180  const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
181 
182  const Vector2D firstPos2D_fromSegment = firstRecoHit_fromSegment.getRecoPos2D();
183  const Vector2D lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
184  const Vector2D firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
185 
186  Vector2D firstToLast_fromSegment = lastPos2D_fromSegment - firstPos2D_fromSegment;
187  Vector2D firstToFirst = firstPos2D_toSegment - firstPos2D_fromSegment;
188 
189  return firstToLast_fromSegment.angleWith(firstToFirst);
190 }
191 
193 {
194  const CDCSegment2D* ptrFromSegment = getFromSegment();
195  const CDCSegment2D* ptrToSegment = getToSegment();
196 
197  if (not ptrFromSegment) {
198  return NAN;
199  }
200 
201  if (not ptrToSegment) {
202  return NAN;
203  }
204 
205  const CDCSegment2D& fromSegment = *ptrFromSegment;
206  const CDCSegment2D& toSegment = *ptrToSegment;
207 
208  if (fromSegment.empty() or toSegment.empty()) {
209  return NAN;
210  }
211 
212  const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
213 
214  const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
215  const CDCRecoHit2D& lastRecoHit_toSegment = toSegment.back();
216 
217  const Vector2D lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
218  const Vector2D firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
219  const Vector2D lastPos2D_toSegment = lastRecoHit_toSegment.getRecoPos2D();
220 
221  Vector2D firstToLast_toSegment = lastPos2D_toSegment - firstPos2D_toSegment;
222  Vector2D lastToLast = lastPos2D_toSegment - lastPos2D_fromSegment;
223 
224  return firstToLast_toSegment.angleWith(lastToLast);
225 }
226 
228 {
229  const CDCSegment2D* ptrFromSegment = getFromSegment();
230  const CDCSegment2D* ptrToSegment = getToSegment();
231 
232  if (not ptrFromSegment) {
233  return NAN;
234  }
235 
236  if (not ptrToSegment) {
237  return NAN;
238  }
239 
240  const CDCSegment2D& fromSegment = *ptrFromSegment;
241  const CDCSegment2D& toSegment = *ptrToSegment;
242 
243  if (fromSegment.empty() or toSegment.empty()) {
244  return NAN;
245  }
246 
247  const CDCRecoHit2D& firstRecoHit_fromSegment = fromSegment.front();
248  const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
249 
250  const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
251  const CDCRecoHit2D& lastRecoHit_toSegment = toSegment.back();
252 
253  const Vector2D firstPos2D_fromSegment = firstRecoHit_fromSegment.getRecoPos2D();
254  const Vector2D lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
255 
256  const Vector2D firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
257  const Vector2D lastPos2D_toSegment = lastRecoHit_toSegment.getRecoPos2D();
258 
259  Vector2D firstToLast_fromSegment = lastPos2D_fromSegment - firstPos2D_fromSegment;
260  Vector2D firstToLast_toSegment = lastPos2D_toSegment - firstPos2D_toSegment;
261 
262  return firstToLast_fromSegment.angleWith(firstToLast_toSegment);
263 }
264 
266 {
267  EForwardBackward fromIsCoaligned = trajectory2D.isForwardOrBackwardTo(*(getFromSegment()));
268  EForwardBackward toIsCoaligned = trajectory2D.isForwardOrBackwardTo(*(getToSegment()));
269 
270  if (fromIsCoaligned == EForwardBackward::c_Forward and
271  toIsCoaligned == EForwardBackward::c_Forward) {
272  return EForwardBackward::c_Forward;
273  } else if (fromIsCoaligned == EForwardBackward::c_Backward and
274  toIsCoaligned == EForwardBackward::c_Backward) {
275  return EForwardBackward::c_Backward;
276  } else {
277  return EForwardBackward::c_Invalid;
278  }
279 }
Belle2::TrackFindingCDC::Vector2D
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:37
Belle2::TrackFindingCDC::CDCRecoHit2D::getRecoPos2D
Vector2D getRecoPos2D() const
Getter for the position in the reference plane.
Definition: CDCRecoHit2D.h:248
Belle2::TrackFindingCDC::ISuperLayerUtil::c_Invalid
static const ISuperLayer c_Invalid
Constant making an invalid superlayer id.
Definition: ISuperLayer.h:75
Belle2::TrackFindingCDC::CDCSegmentPair::CDCSegmentPair
CDCSegmentPair()
Default constructor - for ROOT compatability.
Definition: CDCSegmentPair.cc:35
Belle2::TrackFindingCDC::CDCSegmentPair::size
std::size_t size() const
Getter for the total number of hits in this segment pair.
Definition: CDCSegmentPair.cc:85
Belle2::TrackFindingCDC::CDCSegmentPair::computeFromIsBeforeToFitless
double computeFromIsBeforeToFitless() const
Indicator if the from segment lies before the to segment, build without using the trajectories,...
Definition: CDCSegmentPair.cc:157
Belle2::TrackFindingCDC::AutomatonCell::unsetMaskedFlag
void unsetMaskedFlag()
Resets the masked flag to false.
Definition: AutomatonCell.h:222
Belle2::TrackFindingCDC::CDCSegmentPair::computeIsCoalignedFitless
double computeIsCoalignedFitless() const
Indicator if the from segment and the to segment have roughly the same travel direction without using...
Definition: CDCSegmentPair.cc:227
Belle2::TrackFindingCDC::CDCTrajectorySZ
Linear trajectory in sz space.
Definition: CDCTrajectorySZ.h:41
Belle2::TrackFindingCDC::NForwardBackward::EForwardBackward
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.
Definition: EForwardBackward.h:35
Belle2::TrackFindingCDC::CDCSegmentPair::getAutomatonCell
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Definition: CDCSegmentPair.h:243
Belle2::TrackFindingCDC::CDCSegmentPair::isCoaligned
EForwardBackward isCoaligned(const CDCTrajectory2D &trajectory2D) const
Checks if the last entity in the vector lies greater or lower travel distance than the last entity.
Definition: CDCSegmentPair.cc:265
Belle2::TrackFindingCDC::CDCTrajectory2D
Particle trajectory as it is seen in xy projection represented as a circle.
Definition: CDCTrajectory2D.h:46
Belle2::TrackFindingCDC::CDCSegmentPair::getToStereoKind
EStereoKind getToStereoKind() const
Getter for the stereo type of the second segment.
Definition: CDCSegmentPair.cc:67
Belle2::TrackFindingCDC::CDCSegmentPair::getToSegment
const CDCSegment2D * getToSegment() const
Getter for the to segment.
Definition: CDCSegmentPair.h:132
Belle2::TrackFindingCDC::CDCSegmentPair::getFromISuperLayer
ISuperLayer getFromISuperLayer() const
Getter for the superlayer id of the from segment.
Definition: CDCSegmentPair.cc:73
Belle2::TrackFindingCDC::CDCSegmentPair::getTrajectorySZ
CDCTrajectorySZ getTrajectorySZ() const
Getter for the sz projection of the common three dimensional trajectory.
Definition: CDCSegmentPair.cc:95
Belle2::TrackFindingCDC::AutomatonCell::setMaskedFlag
void setMaskedFlag(bool setTo=true)
Sets the masked flag to the given value. Default value true.
Definition: AutomatonCell.h:216
Belle2::TrackFindingCDC::CDCSegmentPair::computeToIsAfterFromFitless
double computeToIsAfterFromFitless() const
Indicator if the from segment lies before the to segment, build without using the trajectories,...
Definition: CDCSegmentPair.cc:192
Belle2::TrackFindingCDC::CDCTrajectory3D::getTrajectory2D
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
Definition: CDCTrajectory3D.cc:336
Belle2::TrackFindingCDC::CDCSegmentPair::computeDeltaPhiAtSuperLayerBound
double computeDeltaPhiAtSuperLayerBound() const
Determines the angle between the last reconstructed position of the from segment and the first recons...
Definition: CDCSegmentPair.cc:128
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::CDCSegmentPair::unsetAndForwardMaskedFlag
void unsetAndForwardMaskedFlag() const
Unsets the masked flag of the segment triple's automaton cell and of the three contained segments.
Definition: CDCSegmentPair.cc:100
Belle2::TrackFindingCDC::CDCSegmentPair::setAndForwardMaskedFlag
void setAndForwardMaskedFlag() const
Sets the masked flag of the segment triple's automaton cell and of the three contained segments.
Definition: CDCSegmentPair.cc:108
Belle2::TrackFindingCDC::CDCSegmentPair::getFromStereoKind
EStereoKind getFromStereoKind() const
Getter for the stereo type of the first segment.
Definition: CDCSegmentPair.cc:61
Belle2::TrackFindingCDC::CDCSegmentPair::receiveMaskedFlag
void receiveMaskedFlag() const
If one of the contained segments is marked as masked this segment triple is set be masked as well.
Definition: CDCSegmentPair.cc:116
Belle2::TrackFindingCDC::CDCSegment2D
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:40
Belle2::TrackFindingCDC::CDCSegmentPair::getTrajectory3D
CDCTrajectory3D & getTrajectory3D() const
Getter for the three dimensional trajectory.
Definition: CDCSegmentPair.h:213
Belle2::TrackFindingCDC::Vector2D::angleWith
double angleWith(const Vector2D &rhs) const
The angle between this and rhs.
Definition: Vector2D.h:211
Belle2::TrackFindingCDC::CDCSegmentPair::getToISuperLayer
ISuperLayer getToISuperLayer() const
Getter for the superlayer id of the to segment.
Definition: CDCSegmentPair.cc:79
Belle2::TrackFindingCDC::CDCTrajectory2D::isForwardOrBackwardTo
EForwardBackward isForwardOrBackwardTo(const AHits &hits) const
Calculates if this trajectory and the hits are coaligned Returns:
Definition: CDCTrajectory2D.h:210
Belle2::TrackFindingCDC::CDCSegmentPair::getFromSegment
const CDCSegment2D * getFromSegment() const
Getter for the from segment.
Definition: CDCSegmentPair.h:120
Belle2::TrackFindingCDC::CDCTrajectory3D
Particle full three dimensional trajectory.
Definition: CDCTrajectory3D.h:47
Belle2::TrackFindingCDC::CDCSegmentPair::getTrajectory2D
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional projection of the common three dimensional trajectory.
Definition: CDCSegmentPair.cc:90