Belle II Software  release-05-02-19
StereoHitTrackQuadTreeMatcher< AQuadTree > Class Template Referenceabstract

A matcher algorithm for using a stereo quad tree for matching rl tagged wire hits to tracks. More...

#include <StereoHitTrackQuadTreeMatcher.h>

Inheritance diagram for StereoHitTrackQuadTreeMatcher< AQuadTree >:
Collaboration diagram for StereoHitTrackQuadTreeMatcher< AQuadTree >:

Public Types

using WeightedRelationItem = WeightedRelation< CDCTrack, const CDCRLWireHit >
 Shortcut class name for a weighted relation between a collector item and a collection item.
 
using IOTypes = std::tuple< AIOTypes... >
 Types that should be served to apply on invokation.
 
using IOVectors = std::tuple< std::vector< AIOTypes >... >
 Vector types that should be served to apply on invokation.
 

Public Member Functions

void exposeParameters (ModuleParamList *moduleParamList, const std::string &prefix) override
 Expose the parameters to the module.
 
void initialize () override
 Initialize the filter and the quad tree.
 
void terminate () override
 Terminate the filter and the quad tree.
 
void apply (std::vector< CDCTrack > &collectorItems, const std::vector< CDCRLWireHit > &collectionItems, std::vector< WeightedRelationItem > &weightedRelations) override
 Main function: create weighted relations between collectors and collection items using the implemented functionality overriden in a derived class.
 
virtual void apply (ToVector< AIOTypes > &... ioVectors)=0
 Main function executing the algorithm.
 
virtual std::string getDescription ()
 Brief description of the purpose of the concret findlet.
 
virtual void exposeParameters (ModuleParamList *moduleParamList __attribute__((unused)), const std::string &prefix __attribute__((unused)))
 Forward prefixed parameters of this findlet to the module parameter list.
 
void beginRun () override
 Receive and dispatch signal for the beginning of a new run.
 
void beginEvent () override
 Receive and dispatch signal for the start of a new event.
 
void endRun () override
 Receive and dispatch signal for the end of the run.
 

Protected Types

using ToVector = typename ToVectorImpl< T >::Type
 Short hand for ToRangeImpl.
 

Protected Member Functions

virtual void match (CDCTrack &collectorItem, const std::vector< CDCRLWireHit > &collectionItems, std::vector< WeightedRelationItem > &relationsForCollector)
 Override this function to implement your own matching algorithm between one collector and many collection items. More...
 
virtual Weight match (CDCTrack &collectorItem __attribute__((unused)), const CDCRLWireHit &collectionItem __attribute__((unused)))
 Override this function to implement your own matching algorithm between one collector and one collection items. More...
 
void addProcessingSignalListener (ProcessingSignalListener *psl)
 Register a processing signal listener to be notified.
 
int getNProcessingSignalListener ()
 Get the number of currently registered listeners.
 

Private Types

using Super = MatcherInterface< CDCTrack, CDCRLWireHit >
 The parent class.
 

Private Member Functions

void match (CDCTrack &track, const std::vector< CDCRLWireHit > &rlWireHits, std::vector< Super::WeightedRelationItem > &relationsForCollector) override
 Create a QuadTree and fill with each unused stereo hit (to be exact: twice for each stereo hit - right and left). More...
 
void writeDebugInformation ()
 Use the writeDebugInformation function of the quad tree to write the tree into a root file with a ascending number.
 

Private Attributes

bool m_param_checkForB2BTracks = true
 Parameters Set to false to skip the B2B check (good for curlers).
 
double m_param_checkForInWireBoundsFactor = 1.0
 Set to false to skip the in-wire-bound check (good for second stage).
 
unsigned int m_param_quadTreeLevel = 7
 Maximum level of the quad tree search.
 
unsigned int m_param_minimumNumberOfHits = 5
 Minimal number of hits a quad tree node must have to be called a found bin.
 
bool m_param_writeDebugInformation = false
 Set to true to output debug information.
 
unsigned int m_numberOfPassedDebugCalls = 0
 Store the number of passed calls to the debug function.
 
AQuadTree m_quadTreeInstance
 Quad tree instance.
 
std::vector< ProcessingSignalListener * > m_subordinaryProcessingSignalListeners
 References to subordinary signal processing listener contained in this findlet.
 
bool m_initialized = false
 Flag to keep track whether initialization happend before.
 
bool m_terminated = false
 Flag to keep track whether termination happend before.
 
std::string m_initializedAs
 Name of the type during initialisation.
 

Detailed Description

template<class AQuadTree>
class Belle2::TrackFindingCDC::StereoHitTrackQuadTreeMatcher< AQuadTree >

A matcher algorithm for using a stereo quad tree for matching rl tagged wire hits to tracks.

Definition at line 35 of file StereoHitTrackQuadTreeMatcher.h.

Member Function Documentation

◆ match() [1/3]

virtual Weight match ( CDCTrack &collectorItem  __attribute__(unused),
const CDCRLWireHit &collectionItem  __attribute__(unused) 
)
inlineprotectedvirtualinherited

Override this function to implement your own matching algorithm between one collector and one collection items.

If you override this function, you just have to return a weight - the rest of the logic is handled by the MatcherInterface class.

Definition at line 92 of file MatcherInterface.h.

◆ match() [2/3]

virtual void match ( CDCTrack collectorItem,
const std::vector< CDCRLWireHit > &  collectionItems,
std::vector< WeightedRelationItem > &  relationsForCollector 
)
inlineprotectedvirtualinherited

Override this function to implement your own matching algorithm between one collector and many collection items.

A reason to override this instead of the other match function could be, if you want to apply some sort of caching for each collector item.

Definition at line 78 of file MatcherInterface.h.

◆ match() [3/3]

void match ( CDCTrack track,
const std::vector< CDCRLWireHit > &  rlWireHits,
std::vector< Super::WeightedRelationItem > &  relationsForCollector 
)
overrideprivate

Create a QuadTree and fill with each unused stereo hit (to be exact: twice for each stereo hit - right and left).

The QuadTree has two dimensions: inverse slope in z-direction and z0. Each bin with a high number of items (= stereo hits) in it is stored. Later, the one node with the highest number of items in it is taken and each hit is assigned to the track.

Definition at line 84 of file StereoHitTrackQuadTreeMatcher.cc.

86 {
87  // TODO: Extract this into smaller steps
88  // TODO: Split the filtering from the rest.
89  // This means this method would output WeightedRelations based on the quad tree decision and a second filter step
90  // can be applied on these weighted relations
91 
92  // Reconstruct the hits to the track
93  const CDCTrajectory2D& trajectory2D = track.getStartTrajectory3D().getTrajectory2D();
94  const bool isCurler = trajectory2D.isCurler();
95 
96  using CDCRecoHitWithRLPointer = std::pair<CDCRecoHit3D, const CDCRLWireHit*>;
97  std::vector<CDCRecoHitWithRLPointer> recoHits;
98  recoHits.reserve(rlWireHits.size() + track.size());
99 
100  /*
101  * Use the given trajectory to reconstruct the 2d hits in the vector in z direction
102  * to match the trajectory perfectly. Then add the newly created reconstructed 3D hit to the given list.
103  */
104  for (const CDCRLWireHit& rlWireHit : rlWireHits) {
105  if (rlWireHit.getWireHit().getAutomatonCell().hasTakenFlag()) continue;
106 
107  const CDCWire& wire = rlWireHit.getWire();
108  const WireLine& wireLine = wire.getWireLine();
109  double signedDriftLength = rlWireHit.getSignedRefDriftLength();
110  for (const Vector3D& recoPos3D : trajectory2D.reconstructBoth3D(wireLine, signedDriftLength)) {
111  // Skip hits out of CDC
112  if (not wire.isInCellZBounds(recoPos3D, m_param_checkForInWireBoundsFactor)) {
113  continue;
114  }
115 
116  // If the track is a curler, shift all perpS values to positive ones.
117  // Else do not use this hit if m_param_checkForB2BTracks is enabled.
118  double perpS = trajectory2D.calcArcLength2D(recoPos3D.xy());
119  if (perpS < 0) {
120  if (isCurler) {
121  perpS += trajectory2D.getArcLength2DPeriod();
122  } else if (m_param_checkForB2BTracks) {
123  continue;
124  }
125  }
126  recoHits.emplace_back(CDCRecoHit3D(rlWireHit, recoPos3D, perpS), &rlWireHit);
127  }
128  }
129 
130  // Also add already found stereo hits of the track
131  for (const CDCRecoHit3D& recoHit : track) {
132  if (not recoHit.isAxial()) {
133  recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
134  const CDCRLWireHit& rlWireHit = recoHit.getRLWireHit();
135  recoHits.emplace_back(recoHit, &rlWireHit);
136  }
137  }
138 
139  // Do the tree finding
140  m_quadTreeInstance.seed(recoHits);
141 
144  }
145 
146  const auto& foundStereoHitsWithNode = m_quadTreeInstance.findSingleBest(m_param_minimumNumberOfHits);
147  m_quadTreeInstance.fell();
148 
149  if (foundStereoHitsWithNode.size() != 1) {
150  return;
151  }
152 
153  // There is the possibility that we have added one cdc hits twice (as left and right one). We search for those cases here:
154  auto foundStereoHits = foundStereoHitsWithNode[0].second;
155  const auto& node = foundStereoHitsWithNode[0].first;
156 
158  std::vector<CDCRecoHit3D> allHits;
159  std::vector<CDCRecoHit3D> foundHits;
160  // Turn vector of pairs into vector of first items
161  for (const CDCRecoHitWithRLPointer recoHitWithRL : recoHits) {
162  const CDCRecoHit3D& recoHit3D = recoHitWithRL.first;
163  allHits.push_back(recoHit3D);
164  }
165  for (const CDCRecoHitWithRLPointer recoHitWithRL : foundStereoHits) {
166  const CDCRecoHit3D& recoHit3D = recoHitWithRL.first;
167  foundHits.push_back(recoHit3D);
168  }
169  m_quadTreeInstance.drawDebugPlot(allHits, foundHits, node);
170  }
171 
172  // Remove all assigned hits, which where already found before (and do not need to be added again)
173  const auto& isAssignedHit = [](const CDCRecoHitWithRLPointer & recoHitWithRLPointer) {
174  const CDCRecoHit3D& recoHit3D = recoHitWithRLPointer.first;
175  const auto& automatonCell = recoHit3D.getWireHit().getAutomatonCell();
176  return automatonCell.hasAssignedFlag();
177  };
178 
179  foundStereoHits.erase(std::remove_if(foundStereoHits.begin(),
180  foundStereoHits.end(),
181  isAssignedHit),
182  foundStereoHits.end());
183 
184  // Sort the found stereo hits by same CDCHit and smaller distance to the node
185  auto sortByHitAndNodeCenterDistance = [node](const CDCRecoHitWithRLPointer & lhs,
186  const CDCRecoHitWithRLPointer & rhs) {
187 
188 
189  const CDCRecoHit3D& rhsRecoHit = rhs.first;
190  const CDCRecoHit3D& lhsRecoHit = lhs.first;
191 
192  const CDCWireHit& rhsWireHit = rhsRecoHit.getWireHit();
193  const CDCWireHit& lhsWireHit = lhsRecoHit.getWireHit();
194 
195  if (lhsWireHit < rhsWireHit) {
196  return true;
197  } else if (rhsWireHit < lhsWireHit) {
198  return false;
199  } else {
200  return AQuadTree::DecisionAlgorithm::BoxAlgorithm::compareDistances(node, lhsRecoHit, rhsRecoHit); //returns true if lhs < rhs
201  }
202  };
203 
204  const auto& sameHitComparer = [](const CDCRecoHitWithRLPointer & lhs,
205  const CDCRecoHitWithRLPointer & rhs) {
206  const CDCRecoHit3D& rhsRecoHit = rhs.first;
207  const CDCRecoHit3D& lhsRecoHit = lhs.first;
208 
209  return lhsRecoHit.getWireHit() == rhsRecoHit.getWireHit();
210  };
211 
212  std::sort(foundStereoHits.begin(),
213  foundStereoHits.end(),
214  sortByHitAndNodeCenterDistance);
215 
216  // If the same hit is added as right and left hypothesis, do only use the one with the smaller distance to the node.
217  foundStereoHits.erase(std::unique(foundStereoHits.begin(),
218  foundStereoHits.end(),
219  sameHitComparer),
220  foundStereoHits.end());
221 
222  // Add the found stereo hits to the relation vector. In the moment, all hits get the same weight (may change later).
223  for (const CDCRecoHitWithRLPointer& recoHitWithRLPointer : foundStereoHits) {
224  const CDCRLWireHit* rlWireHit = recoHitWithRLPointer.second;
225  relationsForCollector.emplace_back(&track, foundStereoHits.size(), rlWireHit);
226  }
227 }

The documentation for this class was generated from the following files:
Belle2::Vector3D
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition: Cell.h:35
Belle2::TrackFindingCDC::StereoHitTrackQuadTreeMatcher::m_param_checkForInWireBoundsFactor
double m_param_checkForInWireBoundsFactor
Set to false to skip the in-wire-bound check (good for second stage).
Definition: StereoHitTrackQuadTreeMatcher.h:67
Belle2::TrackFindingCDC::StereoHitTrackQuadTreeMatcher::writeDebugInformation
void writeDebugInformation()
Use the writeDebugInformation function of the quad tree to write the tree into a root file with a asc...
Definition: StereoHitTrackQuadTreeMatcher.cc:230
Belle2::TrackFindingCDC::StereoHitTrackQuadTreeMatcher::m_param_minimumNumberOfHits
unsigned int m_param_minimumNumberOfHits
Minimal number of hits a quad tree node must have to be called a found bin.
Definition: StereoHitTrackQuadTreeMatcher.h:71
Belle2::TrackFindingCDC::StereoHitTrackQuadTreeMatcher::m_quadTreeInstance
AQuadTree m_quadTreeInstance
Quad tree instance.
Definition: StereoHitTrackQuadTreeMatcher.h:79
Belle2::TrackFindingCDC::StereoHitTrackQuadTreeMatcher::m_param_writeDebugInformation
bool m_param_writeDebugInformation
Set to true to output debug information.
Definition: StereoHitTrackQuadTreeMatcher.h:73
Belle2::TrackFindingCDC::CDCWireHit
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:65
Belle2::TrackFindingCDC::StereoHitTrackQuadTreeMatcher::m_param_checkForB2BTracks
bool m_param_checkForB2BTracks
Parameters Set to false to skip the B2B check (good for curlers).
Definition: StereoHitTrackQuadTreeMatcher.h:65