Belle II Software development
SegmentAliasResolver Class Referenceabstract

Resolves between the potential alias versions of the segments and contained hits. More...

#include <SegmentAliasResolver.h>

Inheritance diagram for SegmentAliasResolver:
Findlet< TrackingUtilities::CDCSegment2D & > CompositeProcessingSignalListener ProcessingSignalListener

Public Types

using IOTypes
 Types that should be served to apply on invocation.
 
using IOTypes
 Types that should be served to apply on invocation.
 
using IOVectors
 Vector types that should be served to apply on invocation.
 
using IOVectors
 Vector types that should be served to apply on invocation.
 

Public Member Functions

std::string getDescription () final
 Short description of the findlet.
 
void exposeParameters (ModuleParamList *moduleParamList, const std::string &prefix) final
 Expose the parameters to a module.
 
void initialize () final
 Signals the beginning of the event processing.
 
void apply (std::vector< TrackingUtilities::CDCSegment2D > &outputSegments) final
 Main algorithm applying the fit to each segment.
 
virtual void apply (ToVector< AIOTypes > &... ioVectors)=0
 Main function executing the algorithm.
 
void beginRun () override
 Receive and dispatch signal for the beginning of a new run.
 
void beginEvent () override
 Receive and dispatch signal for the start of a new event.
 
void endRun () override
 Receive and dispatch signal for the end of the run.
 
void terminate () override
 Receive and dispatch Signal for termination of the event processing.
 

Protected Types

using ToVector
 Short hand for ToRangeImpl.
 
using ToVector
 Short hand for ToRangeImpl.
 

Protected Member Functions

void addProcessingSignalListener (ProcessingSignalListener *psl)
 Register a processing signal listener to be notified.
 
int getNProcessingSignalListener ()
 Get the number of currently registered listeners.
 

Private Types

using Super = TrackingUtilities::Findlet<TrackingUtilities::CDCSegment2D&>
 Type of the base class.
 

Private Member Functions

void refit (TrackingUtilities::CDCSegment2D &segment, bool reestimate)
 Fit the alias segment.
 

Private Attributes

std::vector< std::string > m_param_investigateAlias = { "cross", "borders", }
 Parameter : Which alias resolutions should be applied.
 
bool m_fullAlias = false
 Switch whether the complete segment should be aliased.
 
bool m_crossAliases = false
 Switch whether the segment should be aliased at the waist where an rl side switch was missed.
 
bool m_borderAliases = false
 Switch whether the border hits at the beginning and the end should be aliased.
 
bool m_middleAliases = false
 Switch whether the hits in the middle with lowest drift radius should be aliased.
 
bool m_param_reestimateDriftLength = true
 Parameter : Switch to reestimate the drift length before each fit.
 
bool m_param_reestimatePositions = false
 Parameter : Switch to restimate the reconstructed positions with a pass of facets.
 
CDCRiemannFitter m_riemannFitter
 Instance of the riemann fitter to be used.
 
DriftLengthEstimator m_driftLengthEstimator
 Instance of the drift length estimator to be used.
 
std::vector< ProcessingSignalListener * > m_subordinaryProcessingSignalListeners
 References to subordinary signal processing listener contained in this findlet.
 
bool m_initialized
 Flag to keep track whether initialization happened before.
 
bool m_terminated
 Flag to keep track whether termination happened before.
 
std::string m_initializedAs
 Name of the type during initialisation.
 

Detailed Description

Resolves between the potential alias versions of the segments and contained hits.

Definition at line 31 of file SegmentAliasResolver.h.

Member Typedef Documentation

◆ IOTypes [1/2]

using IOTypes
inherited

Types that should be served to apply on invocation.

Definition at line 30 of file Findlet.h.

◆ IOTypes [2/2]

using IOTypes
inherited

Types that should be served to apply on invocation.

Definition at line 30 of file Findlet.h.

◆ IOVectors [1/2]

using IOVectors
inherited

Vector types that should be served to apply on invocation.

Definition at line 53 of file Findlet.h.

◆ IOVectors [2/2]

using IOVectors
inherited

Vector types that should be served to apply on invocation.

Definition at line 53 of file Findlet.h.

◆ Super

Type of the base class.

Definition at line 35 of file SegmentAliasResolver.h.

◆ ToVector [1/2]

using ToVector
protectedinherited

Short hand for ToRangeImpl.

Definition at line 49 of file Findlet.h.

◆ ToVector [2/2]

using ToVector
protectedinherited

Short hand for ToRangeImpl.

Definition at line 49 of file Findlet.h.

Member Function Documentation

◆ addProcessingSignalListener()

void addProcessingSignalListener ( ProcessingSignalListener * psl)
protectedinherited

Register a processing signal listener to be notified.

Definition at line 53 of file CompositeProcessingSignalListener.cc.

56{
58}
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition Findlet.h:26

◆ apply()

void apply ( std::vector< TrackingUtilities::CDCSegment2D > & outputSegments)
final

Main algorithm applying the fit to each segment.

Definition at line 83 of file SegmentAliasResolver.cc.

84{
85 if (m_fullAlias) {
86 for (CDCSegment2D& segment : outputSegments) {
87 if (segment->hasAliasFlag()) continue; // A full alias has been found in the facet ca.
88 int nRLSwitches = segment.getNRLSwitches();
89 // Sufficiently right left constrained that the alias is already fixed.
90 bool aliasStable = nRLSwitches > 2;
91 if (aliasStable) continue;
92
93 CDCSegment2D aliasSegment = segment.getAlias();
94 refit(aliasSegment, true);
95 swapBetterChi2(segment, aliasSegment);
96 } // end alias loop
97 }
98
99 // Detect whether the segment has a waist and flip the rest of the segment to right
100 if (m_crossAliases) {
101 for (CDCSegment2D& segment : outputSegments) {
102 int nRLSwitches = segment.getNRLSwitches();
103 // Sufficiently right left constrained that the alias is already fixed.
104 bool aliasStable = nRLSwitches > 2;
105 if (aliasStable) continue;
106
107 if (nRLSwitches == 1) {
108 // One RL switch. Try the all left and all right aliases
109 CDCSegment2D rightSegment = segment;
110 CDCSegment2D leftSegment = segment;
111 for (CDCRecoHit2D& recoHit2D : rightSegment) {
112 if (recoHit2D.getRLInfo() == ERightLeft::c_Left) {
113 recoHit2D = recoHit2D.getAlias();
114 }
115 }
116
117 for (CDCRecoHit2D& recoHit2D : leftSegment) {
118 if (recoHit2D.getRLInfo() == ERightLeft::c_Right) {
119 recoHit2D = recoHit2D.getAlias();
120 }
121 }
122 refit(rightSegment, true);
123 refit(leftSegment, true);
124 swapBetterChi2(segment, rightSegment);
125 swapBetterChi2(segment, leftSegment);
126
127 } else if (nRLSwitches == 0) {
128 // No RL switch. Try to introduce one at the smallest drift length
129 CDCSegment2D frontCrossSegment = segment;
130 CDCSegment2D backCrossSegment = segment;
131
132 auto lessDriftLength = [](const CDCRecoHit2D & lhs, const CDCRecoHit2D & rhs) {
133 return lhs.getRefDriftLength() < rhs.getRefDriftLength();
134 };
135
136 // Alias before the minimal drift length
137 {
138 auto itMinLRecoHit2D =
139 std::min_element(frontCrossSegment.begin(), frontCrossSegment.end(), lessDriftLength);
140 for (CDCRecoHit2D& recoHit2D : asRange(frontCrossSegment.begin(), itMinLRecoHit2D)) {
141 recoHit2D = recoHit2D.getAlias();
142 }
143 }
144
145 // Alias after the minimal drift length
146 {
147 auto itMinLRecoHit2D =
148 std::min_element(backCrossSegment.begin(), backCrossSegment.end(), lessDriftLength);
149 for (CDCRecoHit2D& recoHit2D : asRange(itMinLRecoHit2D, backCrossSegment.end())) {
150 recoHit2D = recoHit2D.getAlias();
151 }
152 }
153 refit(frontCrossSegment, true);
154 refit(backCrossSegment, true);
155 swapBetterChi2(segment, frontCrossSegment);
156 swapBetterChi2(segment, backCrossSegment);
157 }
158 }
159 }
160
161 if (m_borderAliases) {
162 for (CDCSegment2D& segment : outputSegments) {
163 // Check aliasing last hit
164 CDCSegment2D aliasSegment = segment;
165 CDCRecoHit2D& aliasHit = aliasSegment.back();
166 aliasHit.reverse();
167 aliasHit.setRecoPos2D(ROOT::Math::XYVector(NAN, NAN));
168 if (aliasHit.getRefDriftLength() < 0.2) {
169 refit(aliasSegment, false);
170 ROOT::Math::XYVector recoPos2D = aliasSegment.getTrajectory2D().getClosest(aliasHit.getRefPos2D());
171 ERightLeft rlInfo = aliasSegment.getTrajectory2D().isRightOrLeft(aliasHit.getRefPos2D());
172 aliasHit.setRecoPos2D(recoPos2D);
173 aliasHit.setRLInfo(rlInfo);
174 swapBetterChi2(segment, aliasSegment);
175 }
176 }
177
178 for (CDCSegment2D& segment : outputSegments) {
179 // Check aliasing first hit
180 CDCSegment2D aliasSegment = segment;
181 CDCRecoHit2D& aliasHit = aliasSegment.front();
182 aliasHit.reverse();
183 aliasHit.setRecoPos2D(ROOT::Math::XYVector(NAN, NAN));
184 if (aliasHit.getRefDriftLength() < 0.2) {
185 refit(aliasSegment, false);
186 ROOT::Math::XYVector recoPos2D = aliasSegment.getTrajectory2D().getClosest(aliasHit.getRefPos2D());
187 ERightLeft rlInfo = aliasSegment.getTrajectory2D().isRightOrLeft(aliasHit.getRefPos2D());
188 aliasHit.setRecoPos2D(recoPos2D);
189 aliasHit.setRLInfo(rlInfo);
190 swapBetterChi2(segment, aliasSegment);
191 }
192 }
193 }// end if (m_borderAliases)
194
195 if (m_middleAliases) {
196 for (CDCSegment2D& segment : outputSegments) {
197 // Check aliasing hit with lowest drift length
198 CDCSegment2D aliasSegment = segment;
199
200 // Find hit with minimal drift length
201 double minimalDriftLength = 0.1;
202 CDCRecoHit2D* minimalHit = nullptr;
203 for (CDCRecoHit2D& aliasHit : aliasSegment) {
204 if (aliasHit.getRefDriftLength() < minimalDriftLength) {
205 minimalHit = &aliasHit;
206 minimalDriftLength = aliasHit.getRefDriftLength();
207 }
208 }
209 if (minimalHit) {
210 CDCRecoHit2D& aliasHit = *minimalHit;
211 aliasHit.reverse();
212 aliasHit.setRecoPos2D(ROOT::Math::XYVector(NAN, NAN));
213 refit(aliasSegment, false);
214 ROOT::Math::XYVector recoPos2D = aliasSegment.getTrajectory2D().getClosest(aliasHit.getRefPos2D());
215 ERightLeft rlInfo = aliasSegment.getTrajectory2D().isRightOrLeft(aliasHit.getRefPos2D());
216 aliasHit.setRecoPos2D(recoPos2D);
217 aliasHit.setRLInfo(rlInfo);
218 swapBetterChi2(segment, aliasSegment);
219 }
220 }
221 }
222
223 std::sort(outputSegments.begin(), outputSegments.end());
224}
bool m_middleAliases
Switch whether the hits in the middle with lowest drift radius should be aliased.
void refit(TrackingUtilities::CDCSegment2D &segment, bool reestimate)
Fit the alias segment.
bool m_fullAlias
Switch whether the complete segment should be aliased.
bool m_borderAliases
Switch whether the border hits at the beginning and the end should be aliased.
bool m_crossAliases
Switch whether the segment should be aliased at the waist where an rl side switch was missed.
void setRLInfo(ERightLeft &rlInfo)
Setter the right left passage information.
void reverse()
Turns the orientation in place.
double getRefDriftLength() const
Getter for the drift length at the wire reference position.
const ROOT::Math::XYVector & getRefPos2D() const
Getter for the reference position of the wire.
void setRecoPos2D(const ROOT::Math::XYVector &recoPos2D)
Setter for the position in the reference plane.
CDCTrajectory2D & getTrajectory2D() const
Getter for the two dimensional trajectory fitted to the segment.
Definition CDCSegment.h:69
ROOT::Math::XYVector getClosest(const ROOT::Math::XYVector &point) const
Calculates the closest approach on the trajectory to the given point.
ERightLeft isRightOrLeft(const ROOT::Math::XYVector &point) const
Checks if the given point is to the right or to the left of the trajectory.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition ERightLeft.h:25

◆ beginEvent()

void beginEvent ( )
overrideinherited

Receive and dispatch signal for the start of a new event.

Definition at line 36 of file CompositeProcessingSignalListener.cc.

32{
35 psl->beginEvent();
36 }
37}
void beginEvent() override
Receive and dispatch signal for the start of a new event.
virtual void beginEvent()
Receive signal for the start of a new event.

◆ beginRun()

void beginRun ( )
overrideinherited

Receive and dispatch signal for the beginning of a new run.

Definition at line 33 of file CompositeProcessingSignalListener.cc.

24{
27 psl->beginRun();
28 }
29}
void beginRun() override
Receive and dispatch signal for the beginning of a new run.
virtual void beginRun()
Receive signal for the beginning of a new run.

◆ endRun()

void endRun ( )
overrideinherited

Receive and dispatch signal for the end of the run.

Definition at line 39 of file CompositeProcessingSignalListener.cc.

40{
42 psl->endRun();
43 }
45}
void endRun() override
Receive and dispatch signal for the end of the run.
virtual void endRun()
Receive signal for the end of the run.

◆ exposeParameters()

void exposeParameters ( ModuleParamList * moduleParamList,
const std::string & prefix )
finalvirtual

Expose the parameters to a module.

Reimplemented from CompositeProcessingSignalListener.

Definition at line 46 of file SegmentAliasResolver.cc.

47{
48 moduleParamList->addParameter(prefixed(prefix, "investigateAlias"),
50 "Which alias resolutions should be applied. "
51 "Options are trailing_hit, last_hit, full.",
53
54 moduleParamList->addParameter(prefixed(prefix, "reestimateDriftLength"),
56 "Switch to reestimate the drift length in the alias resolver",
58
59 moduleParamList->addParameter(prefixed(prefix, "reestimatePositions"),
61 "Switch to reestimate the reconstructed positions in the alias resolver",
63}
bool m_param_reestimatePositions
Parameter : Switch to restimate the reconstructed positions with a pass of facets.
std::vector< std::string > m_param_investigateAlias
Parameter : Which alias resolutions should be applied.
bool m_param_reestimateDriftLength
Parameter : Switch to reestimate the drift length before each fit.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.

◆ getDescription()

std::string getDescription ( )
finalvirtual

Short description of the findlet.

Reimplemented from Findlet< TrackingUtilities::CDCSegment2D & >.

Definition at line 41 of file SegmentAliasResolver.cc.

42{
43 return "Resolves the rl aliasing of segments in various scenarios";
44}

◆ getNProcessingSignalListener()

int getNProcessingSignalListener ( )
protectedinherited

Get the number of currently registered listeners.

Definition at line 56 of file CompositeProcessingSignalListener.cc.

61{
63}

◆ initialize()

void initialize ( )
finalvirtual

Signals the beginning of the event processing.

Reimplemented from CompositeProcessingSignalListener.

Definition at line 65 of file SegmentAliasResolver.cc.

66{
68 for (const std::string& investigatedAlias : m_param_investigateAlias) {
69 if (investigatedAlias == "full") {
70 m_fullAlias = true;
71 } else if (investigatedAlias == "cross") {
72 m_crossAliases = true;
73 } else if (investigatedAlias == "borders") {
74 m_borderAliases = true;
75 } else if (investigatedAlias == "middle") {
76 m_middleAliases = true;
77 } else {
78 B2ERROR("Unknown alias to investigate " << investigatedAlias);
79 }
80 }
81}

◆ refit()

void refit ( TrackingUtilities::CDCSegment2D & segment,
bool reestimate )
private

Fit the alias segment.

Definition at line 226 of file SegmentAliasResolver.cc.

227{
228 if (reestimate) {
230 CDCRLWireHitSegment rlWireHitSegment = segment.getRLWireHitSegment();
231 // Reset the drift length to the default values.
232 for (CDCRLWireHit& rlWireHit : rlWireHitSegment) {
233 rlWireHit.setRefDriftLength(rlWireHit.getWireHit().getRefDriftLength());
234 }
235 CDCFacetSegment facetSegment = CDCFacetSegment::create(rlWireHitSegment);
236 for (CDCFacet& facet : facetSegment) {
237 facet.adjustFitLine();
239 m_driftLengthEstimator.updateDriftLength(facet);
240 }
241 }
242 CDCSegment2D replacement = CDCSegment2D::condense(facetSegment);
243 segment = replacement;
244 }
245
247 m_driftLengthEstimator.updateDriftLength(segment);
248 }
249 }
250
251 const EFitPos fitPos = EFitPos::c_RecoPos;
252 const EFitVariance fitVariance = EFitVariance::c_Proper;
253 CDCObservations2D observations2D(fitPos, fitVariance);
254 observations2D.appendRange(segment);
255 if (observations2D.size() < 4) {
256 segment.getTrajectory2D().clear();
257 } else {
258 CDCTrajectory2D trajectory2D = m_riemannFitter.fit(observations2D);
259 segment.setTrajectory2D(trajectory2D);
260 }
261
262}
DriftLengthEstimator m_driftLengthEstimator
Instance of the drift length estimator to be used.
CDCRiemannFitter m_riemannFitter
Instance of the riemann fitter to be used.
static CDCFacetSegment create(const CDCRLWireHitSegment &rlWireHitSegment)
Construct a train of facets from the given oriented wire hits.
static CDCSegment2D condense(const CDCTangentSegment &tangentSegment)
Averages the reconstructed positions from hits that overlap in adjacent tangents in the given tangent...

◆ terminate()

void terminate ( )
overrideinherited

Receive and dispatch Signal for termination of the event processing.

Definition at line 42 of file CompositeProcessingSignalListener.cc.

48{
50 psl->terminate();
51 }
53}
void terminate() override
Receive and dispatch Signal for termination of the event processing.
virtual void terminate()
Receive Signal for termination of the event processing.

Member Data Documentation

◆ m_borderAliases

bool m_borderAliases = false
private

Switch whether the border hits at the beginning and the end should be aliased.

Definition at line 66 of file SegmentAliasResolver.h.

◆ m_crossAliases

bool m_crossAliases = false
private

Switch whether the segment should be aliased at the waist where an rl side switch was missed.

Definition at line 63 of file SegmentAliasResolver.h.

◆ m_driftLengthEstimator

DriftLengthEstimator m_driftLengthEstimator
private

Instance of the drift length estimator to be used.

Definition at line 81 of file SegmentAliasResolver.h.

◆ m_fullAlias

bool m_fullAlias = false
private

Switch whether the complete segment should be aliased.

Definition at line 60 of file SegmentAliasResolver.h.

◆ m_initialized

bool m_initialized
privateinherited

Flag to keep track whether initialization happened before.

Definition at line 52 of file ProcessingSignalListener.h.

◆ m_initializedAs

std::string m_initializedAs
privateinherited

Name of the type during initialisation.

Definition at line 58 of file ProcessingSignalListener.h.

◆ m_middleAliases

bool m_middleAliases = false
private

Switch whether the hits in the middle with lowest drift radius should be aliased.

Definition at line 69 of file SegmentAliasResolver.h.

◆ m_param_investigateAlias

std::vector<std::string> m_param_investigateAlias = { "cross", "borders", }
private

Parameter : Which alias resolutions should be applied.

Definition at line 57 of file SegmentAliasResolver.h.

57{ /*"full",*/ "cross", "borders", /*"middle"*/};

◆ m_param_reestimateDriftLength

bool m_param_reestimateDriftLength = true
private

Parameter : Switch to reestimate the drift length before each fit.

Definition at line 72 of file SegmentAliasResolver.h.

◆ m_param_reestimatePositions

bool m_param_reestimatePositions = false
private

Parameter : Switch to restimate the reconstructed positions with a pass of facets.

Definition at line 75 of file SegmentAliasResolver.h.

◆ m_riemannFitter

CDCRiemannFitter m_riemannFitter
private

Instance of the riemann fitter to be used.

Definition at line 78 of file SegmentAliasResolver.h.

◆ m_subordinaryProcessingSignalListeners

std::vector<ProcessingSignalListener*> m_subordinaryProcessingSignalListeners
privateinherited

References to subordinary signal processing listener contained in this findlet.

Definition at line 60 of file CompositeProcessingSignalListener.h.

◆ m_terminated

bool m_terminated
privateinherited

Flag to keep track whether termination happened before.

Definition at line 55 of file ProcessingSignalListener.h.


The documentation for this class was generated from the following files: