Belle II Software development
SVDHoughTrackingTreeSearcher.icc.h
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#pragma once
9
10#include <tracking/vxdHoughTracking/findlets/SVDHoughTrackingTreeSearcher.dcl.h>
11#include <framework/core/ModuleParamList.templateDetails.h>
12#include <framework/logging/Logger.h>
13#include <tracking/trackFindingCDC/utilities/Algorithms.h>
14#include <tracking/trackFindingCDC/utilities/Functional.h>
15#include <tracking/trackFindingCDC/utilities/Range.h>
16#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
17
18namespace Belle2 {
23 namespace vxdHoughTracking {
24
25 template <class AHit, class APathFilter, class AResult>
27 {
29 };
30
31 template <class AHit, class APathFilter, class AResult>
33 const std::string& prefix)
34 {
35 m_pathFilter.exposeParameters(moduleParamList, prefix);
36
37 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "twoHitFilterLimit"),
38 m_applyTwoHitFilterIfMoreChildStates,
39 "Use the TwoHitFilter (path length == 1) if there are more child states than this value.",
40 m_applyTwoHitFilterIfMoreChildStates);
41 }
42
43 template <class AHit, class APathFilter, class AResult>
45 const std::vector<TrackFindingCDC::WeightedRelation<AHit>>& relations,
46 std::vector<AResult>& results)
47 {
48 B2ASSERT("Expected relation to be sorted", std::is_sorted(relations.begin(), relations.end()));
49
50 m_automaton.applyTo(hits, relations);
51
52 std::vector<const AHit*> seedHits;
53 for (const AHit* hit : hits) {
54 if (hit->getDataCache().layer >= 5) {
55 seedHits.emplace_back(hit);
56 }
57 }
58
59 std::vector<TrackFindingCDC::WithWeight<const AHit*>> path;
60 for (const AHit* seedHit : seedHits) {
61 B2DEBUG(29, "Starting with new seed...");
63 path.emplace_back(seedHit, 0);
64 traverseTree(path, relations, results);
65 path.pop_back();
66 B2ASSERT("Something went wrong during the path traversal", path.empty());
67
68 B2DEBUG(29, "... finished with seed");
69 }
70 }
71
72 template <class AHit, class APathFilter, class AResult>
74 path,
75 const std::vector<TrackFindingCDC::WeightedRelation<AHit>>& relations,
76 std::vector<AResult>& results)
77 {
78 // Implement only graph traversal logic and leave the extrapolation and selection to the
79 // rejecter.
80 const AHit* currentHit = path.back();
81 auto continuations =
82 TrackFindingCDC::asRange(std::equal_range(relations.begin(), relations.end(), currentHit));
83
84 std::vector<TrackFindingCDC::WithWeight<AHit*>> childHits;
85 for (const TrackFindingCDC::WeightedRelation<AHit>& continuation : continuations) {
86 AHit* childHit = continuation.getTo();
87 TrackFindingCDC::Weight weight = continuation.getWeight();
88 // the state may still include information from an other round of processing, so lets set it back
89
90 if (std::count(path.begin(), path.end(), childHit)) {
91 // Cycle detected -- is this the best handling?
92 // Other options: Raise an exception and bail out of this seed
93 B2FATAL("Cycle detected!");
94 }
95
96 childHits.emplace_back(childHit, weight);
97 }
98
99 // Do everything with child states, linking, extrapolation, teaching, discarding, what have you.
100 const std::vector<TrackFindingCDC::WithWeight<const AHit*>>& constPath = path;
101 if (path.size() > 1 or childHits.size() > m_applyTwoHitFilterIfMoreChildStates) {
102 m_pathFilter.apply(constPath, childHits);
103 }
104
105 if (childHits.empty()) {
106 B2DEBUG(29, "Terminating this route, as there are no possible child states.");
107 if (path.size() >= 3) {
108 results.emplace_back(path);
109 }
110 return;
111 }
112
113 // Traverse the tree from each new state on
114 std::sort(childHits.begin(), childHits.end(), TrackFindingCDC::GreaterOf<TrackFindingCDC::GetWeight>());
115
116 B2DEBUG(29, "Having found " << childHits.size() << " child states.");
117
118 for (const TrackFindingCDC::WithWeight<AHit*>& childHit : childHits) {
119 path.emplace_back(childHit, childHit.getWeight());
120 traverseTree(path, relations, results);
121 path.pop_back();
122 }
123 }
124 }
126}
The Module parameter list class.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Type for two related objects with a weight.
A mixin class to attach a weight to an object.
Definition: WithWeight.h:24
APathFilter m_pathFilter
State rejecter to decide which available continuations should be traversed next.
SVDHoughTrackingTreeSearcher()
Construct this findlet and add the subfindlet as listener.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters of the subfindlet.
void traverseTree(std::vector< TrackFindingCDC::WithWeight< const AHit * > > &path, const std::vector< TrackFindingCDC::WeightedRelation< AHit > > &relations, std::vector< AResult > &results)
Implementation of the traverseTree function.
void apply(std::vector< AHit * > &hits, const std::vector< TrackFindingCDC::WeightedRelation< AHit > > &relations, std::vector< AResult > &results) final
Main function of this findlet: traverse a tree starting from a given seed hits.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.
Functor factory turning a binary functor and two functors into a new functor which executes the binar...
Definition: Functional.h:127