Belle II Software prerelease-11-00-00e
WholeWireHitRelationFilter.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/WholeWireHitRelationFilter.h>
9
10#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
11
12#include <cdc/topology/CDCWireTopology.h>
13#include <cdc/topology/CDCWire.h>
14
15#include <tracking/trackingUtilities/filters/base/RelationFilter.icc.h>
16
17#include <tracking/trackingUtilities/utilities/StringManipulation.h>
18#include <tracking/trackingUtilities/utilities/Functional.h>
19
20#include <framework/core/ModuleParamList.templateDetails.h>
21
22#include <vector>
23#include <string>
24#include <cassert>
25
26using namespace Belle2;
27using namespace CDC;
28using namespace TrackFindingCDC;
29using namespace TrackingUtilities;
30
32
34 : m_param_degree(neighborhoodDegree)
35{
36}
37
39
41 const std::string& prefix)
42{
43 moduleParamList
44 ->addParameter(prefixed(prefix, "degree"),
46 "Neighbor degree which are included. 1 for primary, 2 for secondary, 3 ...",
48}
49
50void WholeWireHitRelationFilter::prepare(const std::vector<CDCWireHit*>& wireHits)
51{
52 m_preparedWires.clear();
53 m_preparedWires.reserve(wireHits.size());
54 for (const CDCWireHit* wireHit : wireHits) {
55 m_preparedWires.push_back(&wireHit->getWire());
56 }
57 m_preparedWireHitsData = wireHits.data();
58 m_preparedWireHitsSize = wireHits.size();
59}
60
62 CDCWireHit* from,
63 const std::vector<CDCWireHit*>& wireHits) const
64{
65 assert(std::is_sorted(wireHits.begin(), wireHits.end(), LessOf<Deref>()) &&
66 "Expected wire hits to be sorted");
67
68 const int nWireNeighbors = 8 + 10 * (m_param_degree - 1);
69 std::vector<const CDCWire*> m_wireNeighbors;
70 m_wireNeighbors.reserve(nWireNeighbors);
71
72 std::vector<CDCWireHit*> m_wireHitNeighbors;
73 m_wireHitNeighbors.reserve(2 * nWireNeighbors);
74
75 const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
76 const CDCWire& wire = from->getWire();
77
78 const CDCWire* ccwSixthSecondWireNeighbor = wireTopology.getSecondNeighborSixOClock(wire);
79 const CDCWire* ccwInWireNeighbor = wireTopology.getNeighborCCWInwards(wire);
80 const CDCWire* ccwWireNeighbor = wireTopology.getNeighborCCW(wire);
81 const CDCWire* ccwOutWireNeighbor = wireTopology.getNeighborCCWOutwards(wire);
82 const CDCWire* ccwTwelvethSecondWireNeighbor = wireTopology.getSecondNeighborTwelveOClock(wire);
83
84 const CDCWire* cwSixthSecondWireNeighbor = ccwSixthSecondWireNeighbor;
85 const CDCWire* cwInWireNeighbor = wireTopology.getNeighborCWInwards(wire);
86 const CDCWire* cwWireNeighbor = wireTopology.getNeighborCW(wire);
87 const CDCWire* cwOutWireNeighbor = wireTopology.getNeighborCWOutwards(wire);
88 const CDCWire* cwTwelvethSecondWireNeighbor = ccwTwelvethSecondWireNeighbor;
89
90 // Insert the neighbors such that they are most likely sorted.
91
92 // Degree 1 neighborhood - only add the six o'clock and the twelve o'clock neighbor once
93 if (m_param_degree > 1 and ccwSixthSecondWireNeighbor)
94 m_wireNeighbors.push_back(ccwSixthSecondWireNeighbor);
95
96 if (cwInWireNeighbor) m_wireNeighbors.push_back(cwInWireNeighbor);
97 if (ccwInWireNeighbor) m_wireNeighbors.push_back(ccwInWireNeighbor);
98
99 if (cwWireNeighbor) m_wireNeighbors.push_back(cwWireNeighbor);
100 if (ccwWireNeighbor) m_wireNeighbors.push_back(ccwWireNeighbor);
101
102 if (cwOutWireNeighbor) m_wireNeighbors.push_back(cwOutWireNeighbor);
103 if (ccwOutWireNeighbor) m_wireNeighbors.push_back(ccwOutWireNeighbor);
104
105 if (m_param_degree > 1 and ccwTwelvethSecondWireNeighbor)
106 m_wireNeighbors.push_back(ccwTwelvethSecondWireNeighbor);
107
108 for (int degree = 1; degree < m_param_degree; ++degree) {
109 if (cwSixthSecondWireNeighbor) {
110 cwSixthSecondWireNeighbor = cwSixthSecondWireNeighbor->getNeighborCW();
111 m_wireNeighbors.push_back(cwSixthSecondWireNeighbor);
112 }
113 if (ccwSixthSecondWireNeighbor) {
114 ccwSixthSecondWireNeighbor = ccwSixthSecondWireNeighbor->getNeighborCCW();
115 m_wireNeighbors.push_back(ccwSixthSecondWireNeighbor);
116 }
117
118 if (cwInWireNeighbor) {
119 cwInWireNeighbor = cwInWireNeighbor->getNeighborCW();
120 m_wireNeighbors.push_back(cwInWireNeighbor);
121 }
122 if (ccwInWireNeighbor) {
123 ccwInWireNeighbor = ccwInWireNeighbor->getNeighborCCW();
124 m_wireNeighbors.push_back(ccwInWireNeighbor);
125 }
126
127 if (cwWireNeighbor) {
128 cwWireNeighbor = cwWireNeighbor->getNeighborCW();
129 m_wireNeighbors.push_back(cwWireNeighbor);
130 }
131 if (ccwWireNeighbor) {
132 ccwWireNeighbor = ccwWireNeighbor->getNeighborCCW();
133 m_wireNeighbors.push_back(ccwWireNeighbor);
134 }
135
136 if (cwOutWireNeighbor) {
137 cwOutWireNeighbor = cwOutWireNeighbor->getNeighborCW();
138 m_wireNeighbors.push_back(cwOutWireNeighbor);
139 }
140 if (ccwOutWireNeighbor) {
141 ccwOutWireNeighbor = ccwOutWireNeighbor->getNeighborCCW();
142 m_wireNeighbors.push_back(ccwOutWireNeighbor);
143 }
144
145 if (cwTwelvethSecondWireNeighbor) {
146 cwTwelvethSecondWireNeighbor = cwTwelvethSecondWireNeighbor->getNeighborCW();
147 m_wireNeighbors.push_back(cwTwelvethSecondWireNeighbor);
148 }
149 if (ccwTwelvethSecondWireNeighbor) {
150 ccwTwelvethSecondWireNeighbor = ccwTwelvethSecondWireNeighbor->getNeighborCCW();
151 m_wireNeighbors.push_back(ccwTwelvethSecondWireNeighbor);
152 }
153 }
154
155 std::sort(std::begin(m_wireNeighbors), std::end(m_wireNeighbors));
156
157 // Use the wires precomputed by prepare() when called with the prepared vector.
158 // The comparison LessOf<Deref>() used below resolves to operator<(CDCWireHit, CDCWire),
159 // which compares the *address* of the wire of the hit with the address of the wire.
160 // Searching the precomputed wire addresses therefore evaluates exactly the same
161 // predicate on exactly the same values, only without dereferencing the wire hits.
162 const bool prepared =
163 wireHits.data() == m_preparedWireHitsData and wireHits.size() == m_preparedWireHitsSize;
164
165 for (const CDCWire* neighborWire : m_wireNeighbors) {
166 ConstVectorRange<CDCWireHit*> neighborWireHits = [&]() -> ConstVectorRange<CDCWireHit*> {
167 if (prepared)
168 {
169 const auto itRange =
170 std::equal_range(m_preparedWires.begin(), m_preparedWires.end(), neighborWire);
171 return {
172 wireHits.begin() + (itRange.first - m_preparedWires.begin()),
173 wireHits.begin() + (itRange.second - m_preparedWires.begin())};
174 }
175 return ConstVectorRange<CDCWireHit*>{
176 std::equal_range(wireHits.begin(), wireHits.end(), neighborWire, LessOf<Deref>())
177 };
178 }();
179
180 m_wireHitNeighbors.insert(m_wireHitNeighbors.end(),
181 neighborWireHits.begin(),
182 neighborWireHits.end());
183 }
184
185 return m_wireHitNeighbors;
186}
Class representing the sense wire arrangement in the whole of the central drift chamber.
TrackingUtilities::MayBePtr< const CDCWire > getNeighborCCW(const WireID &wireID) const
Getter for the nearest counterclockwise neighbor.
TrackingUtilities::MayBePtr< const CDCWire > getSecondNeighborSixOClock(const WireID &wireID) const
Getter for secondary neighbor at the six o'clock position.
TrackingUtilities::MayBePtr< const CDCWire > getNeighborCW(const WireID &wireID) const
Getter for the nearest clockwise neighbor.
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
TrackingUtilities::MayBePtr< const CDCWire > getNeighborCWOutwards(const WireID &wireID) const
Getter for the nearest clockwise neighbor in the next layer outwards.
TrackingUtilities::MayBePtr< const CDCWire > getNeighborCCWInwards(const WireID &wireID) const
Getter for the nearest counterclockwise neighbor in the next layer outwards.
TrackingUtilities::MayBePtr< const CDCWire > getNeighborCCWOutwards(const WireID &wireID) const
Getter for the nearest counterclockwise neighbor in the next layer outwards.
TrackingUtilities::MayBePtr< const CDCWire > getSecondNeighborTwelveOClock(const WireID &wireID) const
Getter for secondary neighbor at the twelve o'clock position.
TrackingUtilities::MayBePtr< const CDCWire > getNeighborCWInwards(const WireID &wireID) const
Getter for the nearest clockwise neighbor in the next layer outwards.
Class representing a sense wire in the central drift chamber.
Definition CDCWire.h:50
TrackingUtilities::MayBePtr< const CDCWire > getNeighborCCW() const
Gives the closest neighbor in the counterclockwise direction - always exists.
Definition CDCWire.cc:159
TrackingUtilities::MayBePtr< const CDCWire > getNeighborCW() const
Gives the closest neighbor in the clockwise direction - always exists.
Definition CDCWire.cc:164
The Module parameter list class.
void prepare(const std::vector< TrackingUtilities::CDCWireHit * > &wireHits)
Precompute the wires of the given wire hits to speed up the searches in the following getPossibleTos ...
WholeWireHitRelationFilter(int neighborhoodDegree=2)
Constructor form the default neighborhood degree.
TrackingUtilities::CDCWireHit *const * m_preparedWireHitsData
Data pointer of the prepared wire hit vector used to recognize it in getPossibleTos.
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...
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
std::vector< const CDC::CDCWire * > m_preparedWires
Memory for the wires of the prepared wire hit vector.
std::size_t m_preparedWireHitsSize
Size of the prepared wire hit vector used to recognize it in getPossibleTos.
Class representing a hit wire in the central drift chamber.
Definition CDCWireHit.h:58
Iterator begin() const
Begin of the range for range based for.
Definition Range.h:64
Iterator end() const
End of the range for range based for.
Definition Range.h:68
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.