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