Belle II Software prerelease-11-00-00a
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
34CDCSegmentPair::CDCSegmentPair(const CDCSegment2D* fromSegment, const CDCSegment2D* toSegment)
35 : m_fromSegment(fromSegment)
36 , m_toSegment(toSegment)
37{
38 B2ASSERT("CDCSegmentPair initialized with nullptr as from segment", fromSegment);
39 B2ASSERT("CDCSegmentPair initialized with nullptr as to segment", toSegment);
40}
41
43 const CDCSegment2D* toSegment,
44 const CDCTrajectory3D& trajectory3D)
45 : m_fromSegment(fromSegment)
46 , m_toSegment(toSegment)
47 , m_trajectory3D(trajectory3D)
48{
49 B2ASSERT("CDCSegmentPair initialized with nullptr as from segment", fromSegment);
50 B2ASSERT("CDCSegmentPair initialized with nullptr as to segment", toSegment);
51}
52
53
55{
56 return getFromSegment() == nullptr ? EStereoKind::c_Invalid
57 : getFromSegment()->back().getStereoKind();
58}
59
61{
62 return getToSegment() == nullptr ? EStereoKind::c_Invalid
63 : getToSegment()->front().getStereoKind();
64}
65
67{
68 return getFromSegment() == nullptr ? ISuperLayerUtil::c_Invalid
69 : getFromSegment()->back().getISuperLayer();
70}
71
73{
74 return getToSegment() == nullptr ? ISuperLayerUtil::c_Invalid
75 : getToSegment()->front().getISuperLayer();
76}
77
78std::size_t CDCSegmentPair::size() const
79{
80 return getFromSegment()->size() + getToSegment()->size();
81}
82
87
92
94{
96 const bool toHits = true;
97 getFromSegment()->unsetAndForwardMaskedFlag(toHits);
98 getToSegment()->unsetAndForwardMaskedFlag(toHits);
99}
100
102{
104 const bool toHits = true;
105 getFromSegment()->setAndForwardMaskedFlag(toHits);
106 getToSegment()->setAndForwardMaskedFlag(toHits);
107}
108
110{
111 const bool fromHits = true;
112 getFromSegment()->receiveMaskedFlag(fromHits);
113 getToSegment()->receiveMaskedFlag(fromHits);
114
115 if (getFromSegment()->getAutomatonCell().hasMaskedFlag() or
116 getToSegment()->getAutomatonCell().hasMaskedFlag()) {
118 }
119}
120
122{
123 const CDCSegment2D* ptrFromSegment = getFromSegment();
124 const CDCSegment2D* ptrToSegment = getToSegment();
125
126 if (not ptrFromSegment) {
127 return NAN;
128 }
129
130 if (not ptrToSegment) {
131 return NAN;
132 }
133
134 const CDCSegment2D& fromSegment = *ptrFromSegment;
135 const CDCSegment2D& toSegment = *ptrToSegment;
136
137 if (fromSegment.empty() or toSegment.empty()) {
138 return NAN;
139 }
140
141 const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
142 const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
143
144 const Vector2D lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
145 const Vector2D firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
146
147 return lastPos2D_fromSegment.angleWith(firstPos2D_toSegment);
148}
149
151{
152 const CDCSegment2D* ptrFromSegment = getFromSegment();
153 const CDCSegment2D* ptrToSegment = getToSegment();
154
155 if (not ptrFromSegment) {
156 return NAN;
157 }
158
159 if (not ptrToSegment) {
160 return NAN;
161 }
162
163 const CDCSegment2D& fromSegment = *ptrFromSegment;
164 const CDCSegment2D& toSegment = *ptrToSegment;
165
166 if (fromSegment.empty() or toSegment.empty()) {
167 return NAN;
168 }
169
170 const CDCRecoHit2D& firstRecoHit_fromSegment = fromSegment.front();
171 const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
172
173 const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
174
175 const Vector2D firstPos2D_fromSegment = firstRecoHit_fromSegment.getRecoPos2D();
176 const Vector2D lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
177 const Vector2D firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
178
179 Vector2D firstToLast_fromSegment = lastPos2D_fromSegment - firstPos2D_fromSegment;
180 Vector2D firstToFirst = firstPos2D_toSegment - firstPos2D_fromSegment;
181
182 return firstToLast_fromSegment.angleWith(firstToFirst);
183}
184
186{
187 const CDCSegment2D* ptrFromSegment = getFromSegment();
188 const CDCSegment2D* ptrToSegment = getToSegment();
189
190 if (not ptrFromSegment) {
191 return NAN;
192 }
193
194 if (not ptrToSegment) {
195 return NAN;
196 }
197
198 const CDCSegment2D& fromSegment = *ptrFromSegment;
199 const CDCSegment2D& toSegment = *ptrToSegment;
200
201 if (fromSegment.empty() or toSegment.empty()) {
202 return NAN;
203 }
204
205 const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
206
207 const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
208 const CDCRecoHit2D& lastRecoHit_toSegment = toSegment.back();
209
210 const Vector2D lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
211 const Vector2D firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
212 const Vector2D lastPos2D_toSegment = lastRecoHit_toSegment.getRecoPos2D();
213
214 Vector2D firstToLast_toSegment = lastPos2D_toSegment - firstPos2D_toSegment;
215 Vector2D lastToLast = lastPos2D_toSegment - lastPos2D_fromSegment;
216
217 return firstToLast_toSegment.angleWith(lastToLast);
218}
219
221{
222 const CDCSegment2D* ptrFromSegment = getFromSegment();
223 const CDCSegment2D* ptrToSegment = getToSegment();
224
225 if (not ptrFromSegment) {
226 return NAN;
227 }
228
229 if (not ptrToSegment) {
230 return NAN;
231 }
232
233 const CDCSegment2D& fromSegment = *ptrFromSegment;
234 const CDCSegment2D& toSegment = *ptrToSegment;
235
236 if (fromSegment.empty() or toSegment.empty()) {
237 return NAN;
238 }
239
240 const CDCRecoHit2D& firstRecoHit_fromSegment = fromSegment.front();
241 const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
242
243 const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
244 const CDCRecoHit2D& lastRecoHit_toSegment = toSegment.back();
245
246 const Vector2D firstPos2D_fromSegment = firstRecoHit_fromSegment.getRecoPos2D();
247 const Vector2D lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
248
249 const Vector2D firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
250 const Vector2D lastPos2D_toSegment = lastRecoHit_toSegment.getRecoPos2D();
251
252 Vector2D firstToLast_fromSegment = lastPos2D_fromSegment - firstPos2D_fromSegment;
253 Vector2D firstToLast_toSegment = lastPos2D_toSegment - firstPos2D_toSegment;
254
255 return firstToLast_fromSegment.angleWith(firstToLast_toSegment);
256}
257
258EForwardBackward CDCSegmentPair::isCoaligned(const CDCTrajectory2D& trajectory2D) const
259{
260 EForwardBackward fromIsCoaligned = trajectory2D.isForwardOrBackwardTo(*(getFromSegment()));
261 EForwardBackward toIsCoaligned = trajectory2D.isForwardOrBackwardTo(*(getToSegment()));
262
263 if (fromIsCoaligned == EForwardBackward::c_Forward and
264 toIsCoaligned == EForwardBackward::c_Forward) {
265 return EForwardBackward::c_Forward;
266 } else if (fromIsCoaligned == EForwardBackward::c_Backward and
267 toIsCoaligned == EForwardBackward::c_Backward) {
268 return EForwardBackward::c_Backward;
269 } else {
270 return EForwardBackward::c_Invalid;
271 }
272}
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.
CDCSegmentPair()=default
Default constructor - for ROOT compatibility.
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.
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:224
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