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/trackingUtilities/filters/base/RelationFilter.icc.h>
11
12#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
13
14#include <cdc/topology/CDCWireTopology.h>
15#include <cdc/topology/CDCWire.h>
16
17#include <tracking/trackingUtilities/utilities/Relation.h>
18#include <tracking/trackingUtilities/utilities/VectorRange.h>
19#include <tracking/trackingUtilities/utilities/Functional.h>
20#include <tracking/trackingUtilities/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 CDC;
30using namespace TrackFindingCDC;
31using namespace TrackingUtilities;
32
34
36
38
40 const std::string& prefix)
41{
42 moduleParamList
43 ->addParameter(prefixed(prefix, "missingPrimaryNeighborThresholds"),
45 "Map of o'clock directions to number of missing drift cells "
46 "in the primary neighborhood to trigger the inclusion of secondary neighbors "
47 "in that very o'clock direction",
49}
50
52{
54 for (short oClockDirection = 0; oClockDirection < 12; oClockDirection++) {
55 m_missingPrimaryNeighborThresholds[oClockDirection] = 3;
56 if (m_param_missingPrimaryNeighborThresholdMap.count(oClockDirection)) {
57 m_missingPrimaryNeighborThresholds[oClockDirection] =
59 }
60 }
61
63 for (short oClockDirection : {5, 6, 7, 4, 8, 3, 9, 2, 10, 1, 0, 11}) {
64 if (m_missingPrimaryNeighborThresholds[oClockDirection] < 3) {
65 m_consideredSecondaryNeighbors.push_back(oClockDirection);
66 }
67 }
68}
69
71 CDCWireHit* from,
72 const std::vector<CDCWireHit*>& wireHits) const
73{
74 assert(std::is_sorted(wireHits.begin(), wireHits.end(), LessOf<Deref>()) &&
75 "Expected wire hits to be sorted");
76
77 std::vector<std::pair<const CDCWire*, int>> wireNeighbors;
78 wireNeighbors.reserve(8);
79
80 std::vector<CDCWireHit*> wireHitNeighbors;
81 wireHitNeighbors.reserve(12);
82
83 std::array<short, 12> missingPrimaryNeighbor = {0};
84
85 const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
86
87 const CDCWire& wire = from->getWire();
88
89 // Analyse primary neighborhood - sorted such that the wire hits relations are most likely sorted.
90 for (short oClockDirection : {5, 7, 3, 9, 1, 11}) {
91 MayBePtr<const CDCWire> neighborWire = wireTopology.getPrimaryNeighbor(oClockDirection, wire);
92 if (neighborWire) wireNeighbors.emplace_back(neighborWire, oClockDirection);
93 }
94
95 std::sort(std::begin(wireNeighbors), std::end(wireNeighbors));
96
97 for (std::pair<const CDCWire*, int> wireAndOClockDirection : wireNeighbors) {
98 const CDCWire* neighborWire = wireAndOClockDirection.first;
99 int oClockDirection = wireAndOClockDirection.second;
100
101 ConstVectorRange<CDCWireHit*> wireHitRange{
102 std::equal_range(wireHits.begin(), wireHits.end(), neighborWire, LessOf<Deref>())};
103 if (wireHitRange.empty()) {
104 int ccwOClockDirection = oClockDirection - 1;
105 int cwOClockDirection = oClockDirection == 11 ? 0 : oClockDirection + 1;
106 ++missingPrimaryNeighbor[ccwOClockDirection];
107 ++missingPrimaryNeighbor[oClockDirection];
108 ++missingPrimaryNeighbor[cwOClockDirection];
109 }
110 wireHitNeighbors.insert(wireHitNeighbors.end(), wireHitRange.begin(), wireHitRange.end());
111 }
112
113 size_t nPrimaryWireHitNeighbors = wireHitNeighbors.size();
114 wireNeighbors.clear();
115
116 // Analyse secondary neighborhood
117 for (short oClockDirection : m_consideredSecondaryNeighbors) {
118 MayBePtr<const CDCWire> neighborWire = wireTopology.getSecondaryNeighbor(oClockDirection, wire);
119 if (not neighborWire) continue;
120 if (missingPrimaryNeighbor[oClockDirection] <
121 m_missingPrimaryNeighborThresholds[oClockDirection])
122 continue;
123 wireNeighbors.emplace_back(neighborWire, oClockDirection);
124 }
125
126 std::sort(std::begin(wireNeighbors), std::end(wireNeighbors));
127
128 for (std::pair<const CDCWire*, int> wireAndOClockDirection : wireNeighbors) {
129 const CDCWire* neighborWire = wireAndOClockDirection.first;
130 ConstVectorRange<CDCWireHit*> wireHitRange{
131 std::equal_range(wireHits.begin(), wireHits.end(), neighborWire, LessOf<Deref>())};
132 wireHitNeighbors.insert(wireHitNeighbors.end(), wireHitRange.begin(), wireHitRange.end());
133 }
134
136 std::inplace_merge(wireHitNeighbors.begin(),
137 wireHitNeighbors.begin() + nPrimaryWireHitNeighbors,
138 wireHitNeighbors.end(),
139 std::less<CDCWireHit*>());
140
141 return wireHitNeighbors;
142}
Class representing the sense wire arrangement in the whole of the central drift chamber.
TrackingUtilities::MayBePtr< const CDCWire > getSecondaryNeighbor(short oClockDirection, const WireID &wireID) const
Getter for the secondary neighbor of the given wire id.
TrackingUtilities::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:50
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< TrackingUtilities::CDCWireHit * > getPossibleTos(TrackingUtilities::CDCWireHit *from, const std::vector< TrackingUtilities::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:58
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.