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
20#include <tracking/trackingUtilities/ca/AutomatonCell.h>
21
22#include <tracking/trackingUtilities/numerics/EForwardBackward.h>
23
24#include <framework/logging/Logger.h>
25
26#include <Math/Vector2D.h>
27#include <Math/VectorUtil.h>
28
29#include <memory>
30#include <cmath>
31
32using namespace Belle2;
33using namespace CDC;
34using namespace TrackingUtilities;
35
36CDCSegmentPair::CDCSegmentPair(const CDCSegment2D* fromSegment, const CDCSegment2D* toSegment)
37 : m_fromSegment(fromSegment)
38 , m_toSegment(toSegment)
39{
40 B2ASSERT("CDCSegmentPair initialized with nullptr as from segment", fromSegment);
41 B2ASSERT("CDCSegmentPair initialized with nullptr as to segment", toSegment);
42}
43
45 const CDCSegment2D* toSegment,
46 const CDCTrajectory3D& trajectory3D)
47 : m_fromSegment(fromSegment)
48 , m_toSegment(toSegment)
49 , m_trajectory3D(trajectory3D)
50{
51 B2ASSERT("CDCSegmentPair initialized with nullptr as from segment", fromSegment);
52 B2ASSERT("CDCSegmentPair initialized with nullptr as to segment", toSegment);
53}
54
55
57{
58 return getFromSegment() == nullptr ? EStereoKind::c_Invalid
59 : getFromSegment()->back().getStereoKind();
60}
61
63{
64 return getToSegment() == nullptr ? EStereoKind::c_Invalid
65 : getToSegment()->front().getStereoKind();
66}
67
69{
70 return getFromSegment() == nullptr ? ISuperLayerUtil::c_Invalid
71 : getFromSegment()->back().getISuperLayer();
72}
73
75{
76 return getToSegment() == nullptr ? ISuperLayerUtil::c_Invalid
77 : getToSegment()->front().getISuperLayer();
78}
79
80std::size_t CDCSegmentPair::size() const
81{
82 return getFromSegment()->size() + getToSegment()->size();
83}
84
89
94
96{
98 const bool toHits = true;
99 getFromSegment()->unsetAndForwardMaskedFlag(toHits);
100 getToSegment()->unsetAndForwardMaskedFlag(toHits);
101}
102
104{
106 const bool toHits = true;
107 getFromSegment()->setAndForwardMaskedFlag(toHits);
108 getToSegment()->setAndForwardMaskedFlag(toHits);
109}
110
112{
113 const bool fromHits = true;
114 getFromSegment()->receiveMaskedFlag(fromHits);
115 getToSegment()->receiveMaskedFlag(fromHits);
116
117 if (getFromSegment()->getAutomatonCell().hasMaskedFlag() or
118 getToSegment()->getAutomatonCell().hasMaskedFlag()) {
120 }
121}
122
124{
125 const CDCSegment2D* ptrFromSegment = getFromSegment();
126 const CDCSegment2D* ptrToSegment = getToSegment();
127
128 if (not ptrFromSegment) {
129 return NAN;
130 }
131
132 if (not ptrToSegment) {
133 return NAN;
134 }
135
136 const CDCSegment2D& fromSegment = *ptrFromSegment;
137 const CDCSegment2D& toSegment = *ptrToSegment;
138
139 if (fromSegment.empty() or toSegment.empty()) {
140 return NAN;
141 }
142
143 const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
144 const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
145
146 const ROOT::Math::XYVector lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
147 const ROOT::Math::XYVector firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
148
149 return ROOT::Math::VectorUtil::DeltaPhi(lastPos2D_fromSegment, firstPos2D_toSegment);
150}
151
153{
154 const CDCSegment2D* ptrFromSegment = getFromSegment();
155 const CDCSegment2D* ptrToSegment = getToSegment();
156
157 if (not ptrFromSegment) {
158 return NAN;
159 }
160
161 if (not ptrToSegment) {
162 return NAN;
163 }
164
165 const CDCSegment2D& fromSegment = *ptrFromSegment;
166 const CDCSegment2D& toSegment = *ptrToSegment;
167
168 if (fromSegment.empty() or toSegment.empty()) {
169 return NAN;
170 }
171
172 const CDCRecoHit2D& firstRecoHit_fromSegment = fromSegment.front();
173 const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
174
175 const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
176
177 const ROOT::Math::XYVector firstPos2D_fromSegment = firstRecoHit_fromSegment.getRecoPos2D();
178 const ROOT::Math::XYVector lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
179 const ROOT::Math::XYVector firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
180
181 ROOT::Math::XYVector firstToLast_fromSegment = lastPos2D_fromSegment - firstPos2D_fromSegment;
182 ROOT::Math::XYVector firstToFirst = firstPos2D_toSegment - firstPos2D_fromSegment;
183
184 return ROOT::Math::VectorUtil::DeltaPhi(firstToLast_fromSegment, firstToFirst);
185}
186
188{
189 const CDCSegment2D* ptrFromSegment = getFromSegment();
190 const CDCSegment2D* ptrToSegment = getToSegment();
191
192 if (not ptrFromSegment) {
193 return NAN;
194 }
195
196 if (not ptrToSegment) {
197 return NAN;
198 }
199
200 const CDCSegment2D& fromSegment = *ptrFromSegment;
201 const CDCSegment2D& toSegment = *ptrToSegment;
202
203 if (fromSegment.empty() or toSegment.empty()) {
204 return NAN;
205 }
206
207 const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
208
209 const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
210 const CDCRecoHit2D& lastRecoHit_toSegment = toSegment.back();
211
212 const ROOT::Math::XYVector lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
213 const ROOT::Math::XYVector firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
214 const ROOT::Math::XYVector lastPos2D_toSegment = lastRecoHit_toSegment.getRecoPos2D();
215
216 ROOT::Math::XYVector firstToLast_toSegment = lastPos2D_toSegment - firstPos2D_toSegment;
217 ROOT::Math::XYVector lastToLast = lastPos2D_toSegment - lastPos2D_fromSegment;
218
219 return ROOT::Math::VectorUtil::DeltaPhi(firstToLast_toSegment, lastToLast);
220}
221
223{
224 const CDCSegment2D* ptrFromSegment = getFromSegment();
225 const CDCSegment2D* ptrToSegment = getToSegment();
226
227 if (not ptrFromSegment) {
228 return NAN;
229 }
230
231 if (not ptrToSegment) {
232 return NAN;
233 }
234
235 const CDCSegment2D& fromSegment = *ptrFromSegment;
236 const CDCSegment2D& toSegment = *ptrToSegment;
237
238 if (fromSegment.empty() or toSegment.empty()) {
239 return NAN;
240 }
241
242 const CDCRecoHit2D& firstRecoHit_fromSegment = fromSegment.front();
243 const CDCRecoHit2D& lastRecoHit_fromSegment = fromSegment.back();
244
245 const CDCRecoHit2D& firstRecoHit_toSegment = toSegment.front();
246 const CDCRecoHit2D& lastRecoHit_toSegment = toSegment.back();
247
248 const ROOT::Math::XYVector firstPos2D_fromSegment = firstRecoHit_fromSegment.getRecoPos2D();
249 const ROOT::Math::XYVector lastPos2D_fromSegment = lastRecoHit_fromSegment.getRecoPos2D();
250
251 const ROOT::Math::XYVector firstPos2D_toSegment = firstRecoHit_toSegment.getRecoPos2D();
252 const ROOT::Math::XYVector lastPos2D_toSegment = lastRecoHit_toSegment.getRecoPos2D();
253
254 ROOT::Math::XYVector firstToLast_fromSegment = lastPos2D_fromSegment - firstPos2D_fromSegment;
255 ROOT::Math::XYVector firstToLast_toSegment = lastPos2D_toSegment - firstPos2D_toSegment;
256
257 return ROOT::Math::VectorUtil::DeltaPhi(firstToLast_fromSegment, firstToLast_toSegment);
258}
259
260EForwardBackward CDCSegmentPair::isCoaligned(const CDCTrajectory2D& trajectory2D) const
261{
262 EForwardBackward fromIsCoaligned = trajectory2D.isForwardOrBackwardTo(*(getFromSegment()));
263 EForwardBackward toIsCoaligned = trajectory2D.isForwardOrBackwardTo(*(getToSegment()));
264
265 if (fromIsCoaligned == EForwardBackward::c_Forward and
266 toIsCoaligned == EForwardBackward::c_Forward) {
267 return EForwardBackward::c_Forward;
268 } else if (fromIsCoaligned == EForwardBackward::c_Backward and
269 toIsCoaligned == EForwardBackward::c_Backward) {
270 return EForwardBackward::c_Backward;
271 } else {
272 return EForwardBackward::c_Invalid;
273 }
274}
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.
ROOT::Math::XYVector 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.
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