Belle II Software  release-05-01-25
WholeWireHitRelationFilter.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/WholeWireHitRelationFilter.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/filters/base/RelationFilter.icc.h>
18 
19 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
20 #include <tracking/trackFindingCDC/utilities/Functional.h>
21 
22 #include <framework/core/ModuleParamList.templateDetails.h>
23 
24 #include <vector>
25 #include <string>
26 #include <cassert>
27 
28 using namespace Belle2;
29 using namespace TrackFindingCDC;
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 
51  CDCWireHit* from,
52  const std::vector<CDCWireHit*>& wireHits) const
53 {
54  assert(std::is_sorted(wireHits.begin(), wireHits.end(), LessOf<Deref>()) &&
55  "Expected wire hits to be sorted");
56 
57  const int nWireNeighbors = 8 + 10 * (m_param_degree - 1);
58  std::vector<const CDCWire*> m_wireNeighbors;
59  m_wireNeighbors.reserve(nWireNeighbors);
60 
61  std::vector<CDCWireHit*> m_wireHitNeighbors;
62  m_wireHitNeighbors.reserve(2 * nWireNeighbors);
63 
64  const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
65  const CDCWire& wire = from->getWire();
66 
67  const CDCWire* ccwSixthSecondWireNeighbor = wireTopology.getSecondNeighborSixOClock(wire);
68  const CDCWire* ccwInWireNeighbor = wireTopology.getNeighborCCWInwards(wire);
69  const CDCWire* ccwWireNeighbor = wireTopology.getNeighborCCW(wire);
70  const CDCWire* ccwOutWireNeighbor = wireTopology.getNeighborCCWOutwards(wire);
71  const CDCWire* ccwTwelvethSecondWireNeighbor = wireTopology.getSecondNeighborTwelveOClock(wire);
72 
73  const CDCWire* cwSixthSecondWireNeighbor = ccwSixthSecondWireNeighbor;
74  const CDCWire* cwInWireNeighbor = wireTopology.getNeighborCWInwards(wire);
75  const CDCWire* cwWireNeighbor = wireTopology.getNeighborCW(wire);
76  const CDCWire* cwOutWireNeighbor = wireTopology.getNeighborCWOutwards(wire);
77  const CDCWire* cwTwelvethSecondWireNeighbor = ccwTwelvethSecondWireNeighbor;
78 
79  // Insert the neighbors such that they are most likely sorted.
80 
81  // Degree 1 neighnborhood - only add the six oclock and the twelve oclock neighbot once
82  if (m_param_degree > 1 and ccwSixthSecondWireNeighbor)
83  m_wireNeighbors.push_back(ccwSixthSecondWireNeighbor);
84 
85  if (cwInWireNeighbor) m_wireNeighbors.push_back(cwInWireNeighbor);
86  if (ccwInWireNeighbor) m_wireNeighbors.push_back(ccwInWireNeighbor);
87 
88  if (cwWireNeighbor) m_wireNeighbors.push_back(cwWireNeighbor);
89  if (ccwWireNeighbor) m_wireNeighbors.push_back(ccwWireNeighbor);
90 
91  if (cwOutWireNeighbor) m_wireNeighbors.push_back(cwOutWireNeighbor);
92  if (ccwOutWireNeighbor) m_wireNeighbors.push_back(ccwOutWireNeighbor);
93 
94  if (m_param_degree > 1 and ccwTwelvethSecondWireNeighbor)
95  m_wireNeighbors.push_back(ccwTwelvethSecondWireNeighbor);
96 
97  for (int degree = 1; degree < m_param_degree; ++degree) {
98  if (cwSixthSecondWireNeighbor) {
99  cwSixthSecondWireNeighbor = cwSixthSecondWireNeighbor->getNeighborCW();
100  m_wireNeighbors.push_back(cwSixthSecondWireNeighbor);
101  }
102  if (ccwSixthSecondWireNeighbor) {
103  ccwSixthSecondWireNeighbor = ccwSixthSecondWireNeighbor->getNeighborCCW();
104  m_wireNeighbors.push_back(ccwSixthSecondWireNeighbor);
105  }
106 
107  if (cwInWireNeighbor) {
108  cwInWireNeighbor = cwInWireNeighbor->getNeighborCW();
109  m_wireNeighbors.push_back(cwInWireNeighbor);
110  }
111  if (ccwInWireNeighbor) {
112  ccwInWireNeighbor = ccwInWireNeighbor->getNeighborCCW();
113  m_wireNeighbors.push_back(ccwInWireNeighbor);
114  }
115 
116  if (cwWireNeighbor) {
117  cwWireNeighbor = cwWireNeighbor->getNeighborCW();
118  m_wireNeighbors.push_back(cwWireNeighbor);
119  }
120  if (ccwWireNeighbor) {
121  ccwWireNeighbor = ccwWireNeighbor->getNeighborCCW();
122  m_wireNeighbors.push_back(ccwWireNeighbor);
123  }
124 
125  if (cwOutWireNeighbor) {
126  cwOutWireNeighbor = cwOutWireNeighbor->getNeighborCW();
127  m_wireNeighbors.push_back(cwOutWireNeighbor);
128  }
129  if (ccwOutWireNeighbor) {
130  ccwOutWireNeighbor = ccwOutWireNeighbor->getNeighborCCW();
131  m_wireNeighbors.push_back(ccwOutWireNeighbor);
132  }
133 
134  if (cwTwelvethSecondWireNeighbor) {
135  cwTwelvethSecondWireNeighbor = cwTwelvethSecondWireNeighbor->getNeighborCW();
136  m_wireNeighbors.push_back(cwTwelvethSecondWireNeighbor);
137  }
138  if (ccwTwelvethSecondWireNeighbor) {
139  ccwTwelvethSecondWireNeighbor = ccwTwelvethSecondWireNeighbor->getNeighborCCW();
140  m_wireNeighbors.push_back(ccwTwelvethSecondWireNeighbor);
141  }
142  }
143 
144  std::sort(std::begin(m_wireNeighbors), std::end(m_wireNeighbors));
145 
146  for (const CDCWire* neighborWire : m_wireNeighbors) {
147  ConstVectorRange<CDCWireHit*> neighborWireHits{
148  std::equal_range(wireHits.begin(), wireHits.end(), neighborWire, LessOf<Deref>())};
149 
150  m_wireHitNeighbors.insert(m_wireHitNeighbors.end(),
151  neighborWireHits.begin(),
152  neighborWireHits.end());
153  }
154 
155  return m_wireHitNeighbors;
156 }
Belle2::TrackFindingCDC::RelationFilter
Base class for filtering the neighborhood of objects.
Definition: RelationFilter.dcl.h:37
Belle2::TrackFindingCDC::CDCWireTopology::getSecondNeighborSixOClock
MayBePtr< const CDCWire > getSecondNeighborSixOClock(const WireID &wireID) const
Getter for secondary neighbor at the six o'clock position.
Definition: CDCWireTopology.h:359
Belle2::TrackFindingCDC::CDCWireTopology::getNeighborCW
MayBePtr< const CDCWire > getNeighborCW(const WireID &wireID) const
Getter for the nearest clockwise neighbor.
Definition: CDCWireTopology.h:243
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::CDCWireTopology::getInstance
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
Definition: CDCWireTopology.cc:22
Belle2::TrackFindingCDC::CDCWireTopology::getNeighborCWInwards
MayBePtr< const CDCWire > getNeighborCWInwards(const WireID &wireID) const
Getter for the nearest clockwise neighbor in the next layer outwards.
Definition: CDCWireTopology.h:251
Belle2::TrackFindingCDC::CDCWire::getNeighborCW
MayBePtr< const CDCWire > getNeighborCW() const
Gives the closest neighbor in the clockwise direction - always exists.
Definition: CDCWire.cc:170
Belle2::TrackFindingCDC::WholeWireHitRelationFilter::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: WholeWireHitRelationFilter.cc:50
Belle2::TrackFindingCDC::CDCWireTopology::getNeighborCCWOutwards
MayBePtr< const CDCWire > getNeighborCCWOutwards(const WireID &wireID) const
Getter for the nearest counterclockwise neighbor in the next layer outwards.
Definition: CDCWireTopology.h:231
Belle2::TrackFindingCDC::WholeWireHitRelationFilter::m_param_degree
int m_param_degree
Degree of the neighbor extend.
Definition: WholeWireHitRelationFilter.h:57
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::getSecondNeighborTwelveOClock
MayBePtr< const CDCWire > getSecondNeighborTwelveOClock(const WireID &wireID) const
Getter for secondary neighbor at the twelve o'clock position.
Definition: CDCWireTopology.h:383
Belle2::TrackFindingCDC::WholeWireHitRelationFilter::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
Definition: WholeWireHitRelationFilter.cc:40
Belle2::TrackFindingCDC::Range
A pair of iterators usable with the range base for loop.
Definition: Range.h:35
Belle2::TrackFindingCDC::CDCWire
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:60
Belle2::TrackFindingCDC::WholeWireHitRelationFilter::~WholeWireHitRelationFilter
~WholeWireHitRelationFilter()
Default destructor.
Belle2::TrackFindingCDC::CDCWireTopology::getNeighborCCW
MayBePtr< const CDCWire > getNeighborCCW(const WireID &wireID) const
Getter for the nearest counterclockwise neighbor.
Definition: CDCWireTopology.h:239
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::WholeWireHitRelationFilter::WholeWireHitRelationFilter
WholeWireHitRelationFilter(int neighborhoodDegree=2)
Constructor form the default neighborhood degree.
Definition: WholeWireHitRelationFilter.cc:33
Belle2::TrackFindingCDC::CDCWireTopology::getNeighborCWOutwards
MayBePtr< const CDCWire > getNeighborCWOutwards(const WireID &wireID) const
Getter for the nearest clockwise neighbor in the next layer outwards.
Definition: CDCWireTopology.h:235
Belle2::TrackFindingCDC::CDCWireTopology
Class representating the sense wire arrangement in the whole of the central drift chamber.
Definition: CDCWireTopology.h:54
Belle2::TrackFindingCDC::CDCWireTopology::getNeighborCCWInwards
MayBePtr< const CDCWire > getNeighborCCWInwards(const WireID &wireID) const
Getter for the nearest counterclockwise neighbor in the next layer outwards.
Definition: CDCWireTopology.h:247
Belle2::TrackFindingCDC::CDCWire::getNeighborCCW
MayBePtr< const CDCWire > getNeighborCCW() const
Gives the closest neighbor in the counterclockwise direction - always exists.
Definition: CDCWire.cc:165