Belle II Software  release-05-02-19
SuperClusterCreator.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/findlets/minimal/SuperClusterCreator.h>
11 
12 #include <tracking/trackFindingCDC/eventdata/segments/CDCWireHitCluster.h>
13 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
14 
15 #include <tracking/trackFindingCDC/topology/CDCWireLayer.h>
16 #include <tracking/trackFindingCDC/topology/CDCWire.h>
17 
18 #include <tracking/trackFindingCDC/filters/base/RelationFilterUtil.h>
19 
20 #include <tracking/trackFindingCDC/utilities/Functional.h>
21 #include <tracking/trackFindingCDC/utilities/Algorithms.h>
22 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
23 
24 #include <framework/core/ModuleParamList.templateDetails.h>
25 
26 using namespace Belle2;
27 using namespace TrackFindingCDC;
28 
30 {
32 }
33 
35 {
36  return "Groups the wire hits into super cluster by expanding the secondary wire "
37  "neighborhood";
38 }
39 
40 void SuperClusterCreator::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
41 {
42  moduleParamList->addParameter(prefixed(prefix, "expandOverApogeeGap"),
44  "Expand the super clusters over the typical gap at the apogee of the trajectory",
46 
47  m_wireHitRelationFilter.exposeParameters(moduleParamList, prefix);
48 }
49 
50 void SuperClusterCreator::apply(std::vector<CDCWireHit>& inputWireHits,
51  std::vector<CDCWireHitCluster>& outputSuperClusters)
52 {
53  m_wireHitRelations.clear();
54 
56  auto wireHitsByLayer =
57  adjacent_groupby(inputWireHits.begin(), inputWireHits.end(), [](const CDCWireHit & wireHit) {
58  return wireHit.getWireID().getILayer();
59  });
60 
61  for (const auto& wireHitsInLayer : wireHitsByLayer) {
62  const CDCWireLayer& wireLayer = wireHitsInLayer.front().getWire().getWireLayer();
63  const int nWires = wireLayer.size();
64 
65  auto sameWireHitChain = [](const CDCWireHit & lhs, const CDCWireHit & rhs) {
66  return rhs.getWireID().getIWire() - lhs.getWireID().getIWire() == 1;
67  };
68 
69  auto wireHitChains =
70  unique_ranges(wireHitsInLayer.begin(), wireHitsInLayer.end(), sameWireHitChain);
71 
72  size_t nWireHits = 0;
73  for (const VectorRange<CDCWireHit>& wireHitChain : wireHitChains) {
74  nWireHits += wireHitChain.size();
75  }
76  assert(nWireHits == wireHitsInLayer.size());
77 
78  // Special treatment for the first and last wireHitChain as they might wrap around as one
79  VectorRange<CDCWireHit> frontWrapChain(wireHitsInLayer.begin(), wireHitsInLayer.begin());
80  VectorRange<CDCWireHit> backWrapChain(wireHitsInLayer.end(), wireHitsInLayer.end());
81  if (wireHitChains.size() > 1) {
82  if (wireHitChains.front().front().getWire().isPrimaryNeighborWith(
83  wireHitChains.back().back().getWire())) {
84  // Chains are touching
85  // Keep their information around but eliminate them from the regular chains
86  int wrapAroundChainSize = wireHitChains.front().size() + wireHitChains.back().size();
87  if (wrapAroundChainSize >= 5) {
88  // Warning reach over the local wire hit layer / outside the memory of the wire hit
89  // vector to transport the size.
90  frontWrapChain = wireHitChains.front();
91  frontWrapChain.first = frontWrapChain.end() - wrapAroundChainSize;
92 
93  backWrapChain = wireHitChains.back();
94  backWrapChain.second = backWrapChain.begin() + wrapAroundChainSize;
95 
96  wireHitChains.erase(wireHitChains.begin());
97  wireHitChains.pop_back();
98  }
99  }
100  }
101 
102  auto itLastChain = std::remove_if(wireHitChains.begin(), wireHitChains.end(), Size() < 5u);
103  wireHitChains.erase(itLastChain, wireHitChains.end());
104  if (wireHitChains.empty()) continue;
105 
106  auto connectWireHitChains = [this, nWires](const VectorRange<CDCWireHit>& lhs,
107  const VectorRange<CDCWireHit>& rhs) {
108  int iWireDelta = rhs.front().getWireID().getIWire() - lhs.back().getWireID().getIWire();
109  if (iWireDelta < 0) iWireDelta += nWires;
110  if (iWireDelta < static_cast<int>(lhs.size() + rhs.size())) {
111  m_wireHitRelations.push_back({&rhs.front(), 0, &lhs.back()});
112  m_wireHitRelations.push_back({&lhs.back(), 0, &rhs.front()});
113  }
114  return false;
115  };
116  // the return value is not needed
117  // cppcheck-suppress ignoredReturnValue
118  std::adjacent_find(wireHitChains.begin(), wireHitChains.end(), connectWireHitChains);
119 
120  if (not frontWrapChain.empty()) {
121  connectWireHitChains(frontWrapChain, wireHitChains.front());
122  }
123  if (not backWrapChain.empty()) {
124  connectWireHitChains(wireHitChains.back(), backWrapChain);
125  }
126  if (backWrapChain.empty() and frontWrapChain.empty()) {
127  connectWireHitChains(wireHitChains.back(), wireHitChains.front());
128  }
129  }
130  }
131 
133  const std::vector<CDCWireHit*> wireHitPtrs = as_pointers<CDCWireHit>(inputWireHits);
134 
137 
138  B2ASSERT("Expect wire hit neighborhood to be symmetric ",
140 
141  m_wirehitClusterizer.apply(wireHitPtrs, m_wireHitRelations, outputSuperClusters);
142 
143  int iSuperCluster = -1;
144  for (CDCWireHitCluster& superCluster : outputSuperClusters) {
145  ++iSuperCluster;
146  superCluster.setISuperCluster(iSuperCluster);
147  for (CDCWireHit* wireHit : superCluster) {
148  wireHit->setISuperCluster(iSuperCluster);
149  }
150  std::sort(superCluster.begin(), superCluster.end());
151  }
152 }
Belle2::TrackFindingCDC::Range::back
Reference back() const
Returns the derefenced iterator before end()
Definition: Range.h:94
Belle2::TrackFindingCDC::SuperClusterCreator::m_wirehitClusterizer
Clusterizer< CDCWireHit, CDCWireHitCluster > m_wirehitClusterizer
Instance of the hit cluster generator.
Definition: SuperClusterCreator.h:68
Belle2::TrackFindingCDC::CDCWireHit::getWireID
const WireID & getWireID() const
Getter for the WireID of the wire the hit is located on.
Definition: CDCWireHit.h:193
Belle2::TrackFindingCDC::Range::size
std::size_t size() const
Returns the total number of objects in this range.
Definition: Range.h:86
Belle2::TrackFindingCDC::Range::begin
Iterator begin() const
Begin of the range for range based for.
Definition: Range.h:74
Belle2::TrackFindingCDC::WeightedRelationUtil
Utility structure with functions related to weighted relations.
Definition: WeightedRelation.h:140
Belle2::TrackFindingCDC::Range::end
Iterator end() const
End of the range for range based for.
Definition: Range.h:78
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::addProcessingSignalListener
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Definition: CompositeProcessingSignalListener.cc:57
Belle2::TrackFindingCDC::SuperClusterCreator::getDescription
std::string getDescription() final
Short description of the findlet.
Definition: SuperClusterCreator.cc:34
Belle2::TrackFindingCDC::SuperClusterCreator::SuperClusterCreator
SuperClusterCreator()
Constructor.
Definition: SuperClusterCreator.cc:29
Belle2::TrackFindingCDC::RelationFilterUtil::appendUsing
static void appendUsing(ARelationFilter &relationFilter, const std::vector< AObject * > &froms, const std::vector< AObject * > &tos, std::vector< WeightedRelation< AObject >> &weightedRelations, unsigned int maximumNumberOfRelations=std::numeric_limits< unsigned int >::max())
Appends relations between elements in the given AItems using the ARelationFilter.
Definition: RelationFilterUtil.h:71
Belle2::TrackFindingCDC::SuperClusterCreator::m_wireHitRelations
std::vector< WeightedRelation< CDCWireHit > > m_wireHitRelations
Memory for the wire hit neighborhood in a cluster.
Definition: SuperClusterCreator.h:71
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::SuperClusterCreator::m_param_expandOverApogeeGap
bool m_param_expandOverApogeeGap
Parameter : Expand the super clusters over the typical gap at the apogee of the trajectory.
Definition: SuperClusterCreator.h:64
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::Size
Functor to get the .size() from an abitrary objects.
Definition: Functional.h:328
Belle2::TrackFindingCDC::SuperClusterCreator::m_wireHitRelationFilter
WholeWireHitRelationFilter m_wireHitRelationFilter
Wire hit neighborhood relation filter.
Definition: SuperClusterCreator.h:74
Belle2::TrackFindingCDC::Range
A pair of iterators usable with the range base for loop.
Definition: Range.h:35
Belle2::TrackFindingCDC::CDCWireLayer
Class representating a sense wire layer in the central drift chamber.
Definition: CDCWireLayer.h:51
Belle2::TrackFindingCDC::CDCWireHitCluster
An aggregation of CDCWireHits.
Definition: CDCWireHitCluster.h:31
Belle2::TrackFindingCDC::SuperClusterCreator::apply
void apply(std::vector< CDCWireHit > &inputWireHits, std::vector< CDCWireHitCluster > &outputSuperClusters) final
Main algorithm applying the cluster refinement.
Definition: SuperClusterCreator.cc:50
Belle2::TrackFindingCDC::SuperClusterCreator::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
Definition: SuperClusterCreator.cc:40
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::WireID::getIWire
unsigned short getIWire() const
Getter for wire within the layer.
Definition: WireID.h:155
Belle2::TrackFindingCDC::Range::empty
bool empty() const
Checks if the begin equals the end iterator, hence if the range is empty.
Definition: Range.h:82
Belle2::TrackFindingCDC::Range::front
Reference front() const
Returns the derefenced iterator at begin()
Definition: Range.h:90