Belle II Software  release-05-01-25
BridgingWireHitRelationFilter.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/filters/wireHitRelation/BridgingWireHitRelationFilter.h>
11 
12 #include <tracking/trackFindingCDC/filters/base/RelationFilter.icc.h>
13 
14 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
15 
16 #include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
17 #include <tracking/trackFindingCDC/topology/CDCWire.h>
18 
19 #include <tracking/trackFindingCDC/utilities/Relation.h>
20 #include <tracking/trackFindingCDC/utilities/VectorRange.h>
21 #include <tracking/trackFindingCDC/utilities/Functional.h>
22 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
23 
24 #include <framework/core/ModuleParamList.templateDetails.h>
25 
26 #include <vector>
27 #include <string>
28 #include <cassert>
29 
30 using namespace Belle2;
31 using namespace TrackFindingCDC;
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 }
Belle2::TrackFindingCDC::RelationFilter
Base class for filtering the neighborhood of objects.
Definition: RelationFilter.dcl.h:37
Belle2::TrackFindingCDC::BridgingWireHitRelationFilter::m_missingPrimaryNeighborThresholds
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.
Definition: BridgingWireHitRelationFilter.h:82
Belle2::TrackFindingCDC::BridgingWireHitRelationFilter::m_consideredSecondaryNeighbors
std::vector< short > m_consideredSecondaryNeighbors
Indices of the considered o'clock positions of the secondary neighborhood.
Definition: BridgingWireHitRelationFilter.h:85
Belle2::TrackFindingCDC::BinaryJoin
Functor factory turning a binary functor and two functors into a new functor which executes the binar...
Definition: Functional.h:137
Belle2::TrackFindingCDC::BridgingWireHitRelationFilter::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the set of parameters of the filter to the module parameter list.
Definition: BridgingWireHitRelationFilter.cc:39
Belle2::TrackFindingCDC::CDCWireTopology::getInstance
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
Definition: CDCWireTopology.cc:22
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::initialize
void initialize() override
Receive and dispatch signal before the start of the event processing.
Definition: CompositeProcessingSignalListener.cc:17
Belle2::TrackFindingCDC::CDCWireTopology::getPrimaryNeighbor
MayBePtr< const CDCWire > getPrimaryNeighbor(short oClockDirection, const WireID &wireID) const
Getter for the primary neighbor of the given wire id.
Definition: CDCWireTopology.h:219
Belle2::ModuleParamList::addParameter
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Definition: ModuleParamList.templateDetails.h:38
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::CDCWireTopology::getSecondaryNeighbor
MayBePtr< const CDCWire > getSecondaryNeighbor(short oClockDirection, const WireID &wireID) const
Getter for the secondary neighbor of the given wire id.
Definition: CDCWireTopology.h:335
Belle2::TrackFindingCDC::BridgingWireHitRelationFilter::BridgingWireHitRelationFilter
BridgingWireHitRelationFilter()
Default constructor.
Belle2::TrackFindingCDC::BridgingWireHitRelationFilter::initialize
void initialize() override
Receive signal at the begin of the event processing and prepare some parameters.
Definition: BridgingWireHitRelationFilter.cc:51
Belle2::TrackFindingCDC::BridgingWireHitRelationFilter::m_param_missingPrimaryNeighborThresholdMap
std::map< int, int > m_param_missingPrimaryNeighborThresholdMap
Parameter: A map from o'clock direction to the number of missing primary drift cells.
Definition: BridgingWireHitRelationFilter.h:78
Belle2::TrackFindingCDC::Range
A pair of iterators usable with the range base for loop.
Definition: Range.h:35
Belle2::TrackFindingCDC::BridgingWireHitRelationFilter::getPossibleTos
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...
Definition: BridgingWireHitRelationFilter.cc:70
Belle2::TrackFindingCDC::CDCWire
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:60
Belle2::TrackFindingCDC::BridgingWireHitRelationFilter::~BridgingWireHitRelationFilter
~BridgingWireHitRelationFilter()
Default destructor.
Belle2::TrackFindingCDC::CDCWireHit
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:65
Belle2::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46
Belle2::TrackFindingCDC::CDCWireTopology
Class representating the sense wire arrangement in the whole of the central drift chamber.
Definition: CDCWireTopology.h:54