Belle II Software development
SegmentCreatorFacetAutomaton Class Referenceabstract

Findlet that generates segments within clusters based on a cellular automaton on triples of hits. More...

#include <SegmentCreatorFacetAutomaton.h>

Inheritance diagram for SegmentCreatorFacetAutomaton:
Findlet< const TrackingUtilities::CDCFacet, const TrackingUtilities::WeightedRelation< const TrackingUtilities::CDCFacet >, 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 apply (const std::vector< TrackingUtilities::CDCFacet > &inputFacets, const std::vector< TrackingUtilities::WeightedRelation< const TrackingUtilities::CDCFacet > > &inputFacetRelations, std::vector< TrackingUtilities::CDCSegment2D > &outputSegments) final
 Main function of the segment finding by the cellular automaton.
 
virtual void apply (ToVector< AIOTypes > &... ioVectors)=0
 Main function executing the algorithm.
 
void initialize () override
 Receive and dispatch signal before the start of the event processing.
 
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
 Type of the base class.
 

Private Attributes

bool m_param_searchReversed = false
 Parameter : Switch to construct the reversed segment if it is available in the facet graph as well.
 
bool m_param_searchAlias = true
 Parameter : Switch to construct the alias segment if it is available in the facet graph as well.
 
bool m_param_relaxSingleLayerSearch = true
 Parameter : Switch to relax the alias and reverse search for segments contained in a single layer.
 
bool m_param_allSingleAliases = false
 Paraneter : Switch to activate the write out of all available orientations of single facet segments.
 
TrackingUtilities::MultipassCellularPathFinder< const TrackingUtilities::CDCFacetm_cellularPathFinder
 Instance of the cellular automaton path finder.
 
std::vector< TrackingUtilities::Path< const TrackingUtilities::CDCFacet > > m_facetPaths
 Memory for the facet paths generated from the graph.
 
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

Findlet that generates segments within clusters based on a cellular automaton on triples of hits.

Definition at line 32 of file SegmentCreatorFacetAutomaton.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

using Super
private
Initial value:
A reconstructed sequence of two dimensional hits in one super layer.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition Findlet.h:26

Type of the base class.

Definition at line 37 of file SegmentCreatorFacetAutomaton.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.

◆ apply()

void apply ( const std::vector< TrackingUtilities::CDCFacet > & inputFacets,
const std::vector< TrackingUtilities::WeightedRelation< const TrackingUtilities::CDCFacet > > & inputFacetRelations,
std::vector< TrackingUtilities::CDCSegment2D > & outputSegments )
final

Main function of the segment finding by the cellular automaton.

Definition at line 76 of file SegmentCreatorFacetAutomaton.cc.

80{
81 std::vector<ConstVectorRange<CDCFacet>> facetsByICluster =
82 adjacent_groupby(inputFacets.begin(), inputFacets.end(), std::mem_fn(&CDCFacet::getICluster));
83
84 for (const ConstVectorRange<CDCFacet>& facetsInCluster : facetsByICluster) {
85 if (facetsInCluster.empty()) continue;
86
87 B2ASSERT("Expect the facets to be sorted",
88 std::is_sorted(std::begin(facetsInCluster), std::end(facetsInCluster)));
89
90 // Obtain the facets as pointers
91 std::vector<const CDCFacet*> facetPtrsInCluster = as_pointers<const CDCFacet>(facetsInCluster);
92
93 // Cut out the chunk of relevant facet relations
94 const CDCFacet& firstFacet = facetsInCluster.front();
95 auto beginFacetRelationInCluster =
96 std::lower_bound(inputFacetRelations.begin(), inputFacetRelations.end(), &firstFacet);
97
98 const CDCFacet& lastFacet = facetsInCluster.back();
99 auto endFacetRelationInCluster =
100 std::upper_bound(inputFacetRelations.begin(), inputFacetRelations.end(), &lastFacet);
101
102 const int iCluster = firstFacet.getICluster();
103
104 std::vector<WeightedRelation<const CDCFacet>>
105 facetRelationsInCluster(beginFacetRelationInCluster,
106 endFacetRelationInCluster);
107
108 // Apply the cellular automaton in a multipass manner
109 m_facetPaths.clear();
110 m_cellularPathFinder.apply(facetPtrsInCluster, facetRelationsInCluster, m_facetPaths);
111
112 // Helper function to check if a given reverse or alias segment is
113 // also present in the graph of facets. Used in the search for
114 // aliasing segments.
115 auto getFacetPath = [&facetsInCluster,
116 &facetRelationsInCluster,
117 &iCluster](const CDCSegment2D & segment, bool checkRelations = true) {
118 CDCRLWireHitSegment rlWireHitSegment = segment.getRLWireHitSegment();
119 CDCFacetSegment aliasFacetSegment = CDCFacetSegment::create(rlWireHitSegment);
120 std::vector<const CDCFacet*> facetPath;
121 for (CDCRLWireHitTriple& rlWireHitTriple : aliasFacetSegment) {
122 // Do not forget to set the cluster id as it is a sorting criterion
123 rlWireHitTriple.setICluster(iCluster);
124
125 // Check whether the facet is a node in the graph
126 auto itFacet = std::lower_bound(facetsInCluster.begin(), facetsInCluster.end(), rlWireHitTriple);
127 if (itFacet == facetsInCluster.end()) break;
128 if (not(*itFacet == rlWireHitTriple)) break;
129 const CDCFacet* facet = &*itFacet;
130
131 // Check whether there is a relation to this new facet
132 if (not facetPath.empty() and checkRelations) {
133 const CDCFacet* fromFacet = facetPath.back();
134 auto relationsFromFacet = std::equal_range(facetRelationsInCluster.begin(),
135 facetRelationsInCluster.end(),
136 fromFacet);
137 if (std::count_if(relationsFromFacet.first, relationsFromFacet.second, Second() == facet) == 0) break;
138 }
139 facetPath.push_back(facet);
140 }
141 return facetPath;
142 };
143
144 // Reserve enough space to prevent reallocation and invalidated references
145 size_t additionalSpace = m_facetPaths.size();
146 if (m_param_searchReversed) additionalSpace *= 2;
147 if (m_param_searchAlias) additionalSpace *= 2;
148 outputSegments.reserve(outputSegments.size() + additionalSpace);
149
150 for (const std::vector<const CDCFacet*>& facetPath : m_facetPaths) {
151 // If path is only a single facet long - forward all viable orientations if requested
152 if (m_param_allSingleAliases and facetPath.size() == 1) {
153 const CDCFacet& originalSingleFacet = *facetPath.front();
154
155 int nSingleFacets = 0;
156
157 // Helper object to construct other single facet paths
158 std::vector<const CDCFacet*> singleFacetPath;
159 singleFacetPath.reserve(1);
160
161 std::array<int, 3> permIndices{0, 1, 2};
162 CDCRLWireHitTriple rlWireHitTriple = originalSingleFacet;
163
164 for (int iPerm = 0; iPerm < 6; ++iPerm) {
165 setRLWireHit(rlWireHitTriple, permIndices[0], originalSingleFacet.getStartRLWireHit());
166 setRLWireHit(rlWireHitTriple, permIndices[1], originalSingleFacet.getMiddleRLWireHit());
167 setRLWireHit(rlWireHitTriple, permIndices[2], originalSingleFacet.getEndRLWireHit());
168 std::next_permutation(permIndices.begin(), permIndices.end()); // Prepare for next round
169
170 for (ERightLeft startRLInfo : {ERightLeft::c_Left, ERightLeft::c_Right}) {
171 rlWireHitTriple.setStartRLInfo(startRLInfo);
172 for (ERightLeft middleRLInfo : {ERightLeft::c_Left, ERightLeft::c_Right}) {
173 rlWireHitTriple.setMiddleRLInfo(middleRLInfo);
174 for (ERightLeft endRLInfo : {ERightLeft::c_Left, ERightLeft::c_Right}) {
175 rlWireHitTriple.setEndRLInfo(endRLInfo);
176
177 auto itFacet = std::lower_bound(facetsInCluster.begin(),
178 facetsInCluster.end(),
179 rlWireHitTriple);
180
181 if (itFacet == facetsInCluster.end())continue;
182 if (not(*itFacet == rlWireHitTriple)) continue;
183
184 const CDCFacet* singleFacet = &*itFacet;
185 singleFacetPath.clear();
186 singleFacetPath.push_back(singleFacet);
187 outputSegments.push_back(CDCSegment2D::condense(singleFacetPath));
188 outputSegments.back()->setReverseFlag();
189 outputSegments.back()->setAliasFlag();
190 ++nSingleFacets;
191 }
192 }
193 }
194 }
195 B2ASSERT("At least one single facet added", nSingleFacets > 0);
196
197 // Skip the reset of the alias searches
198 continue;
199 }
200
201 outputSegments.reserve(outputSegments.size() + 4);
202 outputSegments.push_back(CDCSegment2D::condense(facetPath));
203 const CDCSegment2D* segment = &outputSegments.back();
204
205
206 // Check for the special situation where the segment is confined to one layer
207 // Relax the alias search a bit to better capture the situation
208 bool checkRelations = true;
210 auto differentILayer = [](const CDCRecoHit2D & lhs, const CDCRecoHit2D & rhs) {
211 return lhs.getWire().getILayer() != rhs.getWire().getILayer();
212 };
213 auto itLayerSwitch = std::adjacent_find(segment->begin(), segment->end(), differentILayer);
214 const bool onlyOneLayer = itLayerSwitch == segment->end();
215 checkRelations = not onlyOneLayer;
216 }
217
218 const CDCSegment2D* reverseSegment = nullptr;
220 std::vector<const CDCFacet*> reverseFacetPath = getFacetPath(segment->reversed(), checkRelations);
221 if (reverseFacetPath.size() == facetPath.size()) {
222 B2DEBUG(25, "Successful constructed REVERSE");
223 outputSegments.push_back(CDCSegment2D::condense(reverseFacetPath));
224 reverseSegment = &outputSegments.back();
225
226 (*segment)->setReverseFlag(true);
227 (*reverseSegment)->setReverseFlag(true);
228 }
229 }
230
231 if (not m_param_searchAlias) continue;
232
233 // Search for aliasing segment in the facet graph
234 int nRLSwitches = segment->getNRLSwitches();
235 if (nRLSwitches > 2) continue; // Segment is stable against aliases
236
237 const CDCSegment2D* aliasSegment = nullptr;
238 std::vector<const CDCFacet*> aliasFacetPath = getFacetPath(segment->getAlias(), checkRelations);
239 if (aliasFacetPath.size() == facetPath.size()) {
240 B2DEBUG(25, "Successful constructed alias");
241 outputSegments.push_back(CDCSegment2D::condense(aliasFacetPath));
242 aliasSegment = &outputSegments.back();
243
244 (*segment)->setAliasFlag(true);
245 (*aliasSegment)->setAliasFlag(true);
246 }
247
248 const CDCSegment2D* reverseAliasSegment = nullptr;
250 std::vector<const CDCFacet*> reverseAliasFacetPath =
251 getFacetPath(segment->reversed().getAlias(), checkRelations);
252 if (reverseAliasFacetPath.size() == facetPath.size()) {
253 B2DEBUG(25, "Successful constructed REVERSE alias");
254 outputSegments.push_back(CDCSegment2D::condense(reverseAliasFacetPath));
255 reverseAliasSegment = &outputSegments.back();
256 if (aliasSegment != nullptr) {
257 (*aliasSegment)->setReverseFlag(true);
258 (*reverseAliasSegment)->setReverseFlag(true);
259 }
260 }
261 }
262
263 if (reverseSegment != nullptr and reverseAliasSegment != nullptr) {
264 (*reverseSegment)->setAliasFlag(true);
265 (*reverseAliasSegment)->setAliasFlag(true);
266 }
267 }
268 }
269}
ILayer getILayer() const
Getter for the layer id within its superlayer Gives the layer id within its superlayer ranging from ...
Definition CDCWire.h:151
bool m_param_relaxSingleLayerSearch
Parameter : Switch to relax the alias and reverse search for segments contained in a single layer.
bool m_param_allSingleAliases
Paraneter : Switch to activate the write out of all available orientations of single facet segments.
bool m_param_searchReversed
Parameter : Switch to construct the reversed segment if it is available in the facet graph as well.
TrackingUtilities::MultipassCellularPathFinder< const TrackingUtilities::CDCFacet > m_cellularPathFinder
Instance of the cellular automaton path finder.
bool m_param_searchAlias
Parameter : Switch to construct the alias segment if it is available in the facet graph as well.
std::vector< TrackingUtilities::Path< const TrackingUtilities::CDCFacet > > m_facetPaths
Memory for the facet paths generated from the graph.
static CDCFacetSegment create(const CDCRLWireHitSegment &rlWireHitSegment)
Construct a train of facets from the given oriented wire hits.
void setEndRLInfo(const ERightLeft endRLInfo)
Setter for the right left passage information of the third oriented wire hit.
CDCRLWireHit & getStartRLWireHit()
Getter for the first oriented wire hit.
void setMiddleRLInfo(const ERightLeft middleRLInfo)
Setter for the right left passage information of the second oriented wire hit.
int getICluster() const
Getter for the cluster id.
CDCRLWireHit & getEndRLWireHit()
Getter for the third oriented wire hit.
CDCRLWireHit & getMiddleRLWireHit()
Getter for the second oriented wire hit.
void setStartRLInfo(const ERightLeft startRLInfo)
Setter for the right left passage information of the first oriented wire hit.
const CDC::CDCWire & getWire() const
Getter for the wire the reconstructed hit associated to.
static CDCSegment2D condense(const CDCTangentSegment &tangentSegment)
Averages the reconstructed positions from hits that overlap in adjacent tangents in the given tangent...

◆ 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 53 of file SegmentCreatorFacetAutomaton.cc.

54{
55 moduleParamList->addParameter(prefixed(prefix, "searchReversed"),
57 "Switch to construct the reversed segment if it is available in the facet graph as well.",
59
60 moduleParamList->addParameter(prefixed(prefix, "searchAlias"),
62 "Switch to construct the alias segment if it is available in the facet graph as well.",
64
65 moduleParamList->addParameter(prefixed(prefix, "relaxSingleLayerSearch"),
67 "Switch to relax the alias and reverse search for segments contained in a single layer.",
69
70 moduleParamList->addParameter(prefixed(prefix, "allSingleAliases"),
72 "Switch to activate the write out of all available orientations of single facet segments.",
74}
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< const TrackingUtilities::CDCFacet, const TrackingUtilities::WeightedRelation< const TrackingUtilities::CDCFacet >, TrackingUtilities::CDCSegment2D >.

Definition at line 48 of file SegmentCreatorFacetAutomaton.cc.

49{
50 return "Constructs segments by extraction of facet paths in a cellular automaton.";
51}

◆ getNProcessingSignalListener()

int getNProcessingSignalListener ( )
protectedinherited

Get the number of currently registered listeners.

Definition at line 56 of file CompositeProcessingSignalListener.cc.

61{
63}

◆ initialize()

void initialize ( )
overrideinherited

Receive and dispatch signal before the start of the event processing.

Definition at line 30 of file CompositeProcessingSignalListener.cc.

16{
19 psl->initialize();
20 }
21}
void initialize() override
Receive and dispatch signal before the start of the event processing.
virtual void initialize()
Receive signal before the start of the event processing.

◆ 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_cellularPathFinder

Instance of the cellular automaton path finder.

Definition at line 67 of file SegmentCreatorFacetAutomaton.h.

◆ m_facetPaths

std::vector< TrackingUtilities::Path<const TrackingUtilities::CDCFacet> > m_facetPaths
private

Memory for the facet paths generated from the graph.

Definition at line 71 of file SegmentCreatorFacetAutomaton.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_param_allSingleAliases

bool m_param_allSingleAliases = false
private

Paraneter : Switch to activate the write out of all available orientations of single facet segments.

Definition at line 63 of file SegmentCreatorFacetAutomaton.h.

◆ m_param_relaxSingleLayerSearch

bool m_param_relaxSingleLayerSearch = true
private

Parameter : Switch to relax the alias and reverse search for segments contained in a single layer.

Definition at line 60 of file SegmentCreatorFacetAutomaton.h.

◆ m_param_searchAlias

bool m_param_searchAlias = true
private

Parameter : Switch to construct the alias segment if it is available in the facet graph as well.

Definition at line 57 of file SegmentCreatorFacetAutomaton.h.

◆ m_param_searchReversed

bool m_param_searchReversed = false
private

Parameter : Switch to construct the reversed segment if it is available in the facet graph as well.

Definition at line 54 of file SegmentCreatorFacetAutomaton.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: