Belle II Software development
BridgingWireHitRelationFilter.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/trackFindingCDC/filters/wireHitRelation/BridgingWireHitRelationFilter.h>
9
10#include <tracking/trackFindingCDC/filters/base/RelationFilter.icc.h>
11
12#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
13
14#include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
15#include <tracking/trackFindingCDC/topology/CDCWire.h>
16
17#include <tracking/trackFindingCDC/utilities/Relation.h>
18#include <tracking/trackFindingCDC/utilities/VectorRange.h>
19#include <tracking/trackFindingCDC/utilities/Functional.h>
20#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
21
22#include <framework/core/ModuleParamList.templateDetails.h>
23
24#include <vector>
25#include <string>
26#include <cassert>
27
28using namespace Belle2;
29using namespace TrackFindingCDC;
30
32
34
36
38 const std::string& prefix)
39{
40 moduleParamList
41 ->addParameter(prefixed(prefix, "missingPrimaryNeighborThresholds"),
43 "Map of o'clock directions to number of missing drift cells "
44 "in the primary neighborhood to trigger the inclusion of secondary neighbors "
45 "in that very o'clock direction",
47}
48
50{
52 for (short oClockDirection = 0; oClockDirection < 12; oClockDirection++) {
53 m_missingPrimaryNeighborThresholds[oClockDirection] = 3;
54 if (m_param_missingPrimaryNeighborThresholdMap.count(oClockDirection)) {
55 m_missingPrimaryNeighborThresholds[oClockDirection] =
57 }
58 }
59
61 for (short oClockDirection : {5, 6, 7, 4, 8, 3, 9, 2, 10, 1, 0, 11}) {
62 if (m_missingPrimaryNeighborThresholds[oClockDirection] < 3) {
63 m_consideredSecondaryNeighbors.push_back(oClockDirection);
64 }
65 }
66}
67
69 CDCWireHit* from,
70 const std::vector<CDCWireHit*>& wireHits) const
71{
72 assert(std::is_sorted(wireHits.begin(), wireHits.end(), LessOf<Deref>()) &&
73 "Expected wire hits to be sorted");
74
75 std::vector<std::pair<const CDCWire*, int>> wireNeighbors;
76 wireNeighbors.reserve(8);
77
78 std::vector<CDCWireHit*> wireHitNeighbors;
79 wireHitNeighbors.reserve(12);
80
81 std::array<short, 12> missingPrimaryNeighbor = {0};
82
83 const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
84
85 const CDCWire& wire = from->getWire();
86
87 // Analyse primary neighborhood - sorted such that the wire hits relations are most likely sorted.
88 for (short oClockDirection : {5, 7, 3, 9, 1, 11}) {
89 MayBePtr<const CDCWire> neighborWire = wireTopology.getPrimaryNeighbor(oClockDirection, wire);
90 if (neighborWire) wireNeighbors.emplace_back(neighborWire, oClockDirection);
91 }
92
93 std::sort(std::begin(wireNeighbors), std::end(wireNeighbors));
94
95 for (std::pair<const CDCWire*, int> wireAndOClockDirection : wireNeighbors) {
96 const CDCWire* neighborWire = wireAndOClockDirection.first;
97 int oClockDirection = wireAndOClockDirection.second;
98
100 std::equal_range(wireHits.begin(), wireHits.end(), neighborWire, LessOf<Deref>())};
101 if (wireHitRange.empty()) {
102 int ccwOClockDirection = oClockDirection - 1;
103 int cwOClockDirection = oClockDirection == 11 ? 0 : oClockDirection + 1;
104 ++missingPrimaryNeighbor[ccwOClockDirection];
105 ++missingPrimaryNeighbor[oClockDirection];
106 ++missingPrimaryNeighbor[cwOClockDirection];
107 }
108 wireHitNeighbors.insert(wireHitNeighbors.end(), wireHitRange.begin(), wireHitRange.end());
109 }
110
111 size_t nPrimaryWireHitNeighbors = wireHitNeighbors.size();
112 wireNeighbors.clear();
113
114 // Analyse secondary neighborhood
115 for (short oClockDirection : m_consideredSecondaryNeighbors) {
116 MayBePtr<const CDCWire> neighborWire = wireTopology.getSecondaryNeighbor(oClockDirection, wire);
117 if (not neighborWire) continue;
118 if (missingPrimaryNeighbor[oClockDirection] <
119 m_missingPrimaryNeighborThresholds[oClockDirection])
120 continue;
121 wireNeighbors.emplace_back(neighborWire, oClockDirection);
122 }
123
124 std::sort(std::begin(wireNeighbors), std::end(wireNeighbors));
125
126 for (std::pair<const CDCWire*, int> wireAndOClockDirection : wireNeighbors) {
127 const CDCWire* neighborWire = wireAndOClockDirection.first;
129 std::equal_range(wireHits.begin(), wireHits.end(), neighborWire, LessOf<Deref>())};
130 wireHitNeighbors.insert(wireHitNeighbors.end(), wireHitRange.begin(), wireHitRange.end());
131 }
132
134 std::inplace_merge(wireHitNeighbors.begin(),
135 wireHitNeighbors.begin() + nPrimaryWireHitNeighbors,
136 wireHitNeighbors.end(),
137 std::less<CDCWireHit*>());
138
139 return wireHitNeighbors;
140}
The Module parameter list class.
std::map< int, int > m_param_missingPrimaryNeighborThresholdMap
Parameter: A map from o'clock direction to the number of missing primary drift cells.
void initialize() override
Receive signal at the begin of the event processing and prepare some parameters.
std::vector< CDCWireHit * > getPossibleTos(CDCWireHit *from, const std::vector< CDCWireHit * > &wireHits) const final
Returns a vector containing the neighboring wire hits of the given wire hit out of the sorted range g...
std::array< short, 12 > m_missingPrimaryNeighborThresholds
Array for the number of primary drift cells to be included for the o'clock position at each index.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the set of parameters of the filter to the module parameter list.
std::vector< short > m_consideredSecondaryNeighbors
Indices of the considered o'clock positions of the secondary neighborhood.
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
Class representating the sense wire arrangement in the whole of the central drift chamber.
MayBePtr< const CDCWire > getSecondaryNeighbor(short oClockDirection, const WireID &wireID) const
Getter for the secondary neighbor of the given wire id.
MayBePtr< const CDCWire > getPrimaryNeighbor(short oClockDirection, const WireID &wireID) const
Getter for the primary neighbor of the given wire id.
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:58
void initialize() override
Receive and dispatch signal before the start of the event processing.
A pair of iterators usable with the range base for loop.
Definition: Range.h:25
std::size_t size() const
Returns the total number of objects in this range.
Definition: Range.h:76
Base class for filtering the neighborhood of objects.
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