Belle II Software  release-08-01-10
BaseSegmentRelationFilter.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/segmentRelation/BaseSegmentRelationFilter.h>
9 
10 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
11 #include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit2D.h>
12 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
13 
14 #include <tracking/trackFindingCDC/filters/base/RelationFilter.icc.h>
15 
16 #include <tracking/trackFindingCDC/numerics/Weight.h>
17 
18 #include <tracking/trackFindingCDC/utilities/Relation.h>
19 #include <tracking/trackFindingCDC/utilities/VectorRange.h>
20 
21 #include <tracking/trackFindingCDC/utilities/Functional.h>
22 
23 #include <vector>
24 #include <algorithm>
25 #include <cassert>
26 
27 using namespace Belle2;
28 using namespace TrackFindingCDC;
29 
31 
33 
35 
36 std::vector<const CDCSegment2D*> BaseSegmentRelationFilter::getPossibleTos(
37  const CDCSegment2D* from,
38  const std::vector<const CDCSegment2D*>& segments) const
39 {
40  assert(std::is_sorted(segments.begin(), segments.end(), LessOf<Deref>()) &&
41  "Expected segments to be sorted");
42 
44  std::equal_range(segments.begin(), segments.end(), from, LessOf<Deref>())};
45 
46  return {tos.begin(), tos.end()};
47 }
48 
50 {
51  const CDCSegment2D* from = relation.getFrom();
52  const CDCSegment2D* to = relation.getTo();
53  if (from == to) return NAN; // Prevent relation to same.
54  if ((from == nullptr) or (to == nullptr)) return NAN;
55 
56  // Make an overlap check to prevent aliases and reverse segments to be linked
57  std::vector<const CDCWireHit*> fromWireHits;
58  fromWireHits.reserve(from->size());
59  for (const CDCRecoHit2D& recoHit2D : *from) {
60  fromWireHits.push_back(&recoHit2D.getWireHit());
61  }
62  std::sort(fromWireHits.begin(), fromWireHits.end());
63  int nOverlap = 0;
64  for (const CDCRecoHit2D& recoHit2D : *to) {
65  if (std::binary_search(fromWireHits.begin(), fromWireHits.end(), &recoHit2D.getWireHit())) {
66  ++nOverlap;
67  }
68  }
69 
70  if (1.0 * nOverlap / from->size() > 0.8) {
71  return NAN;
72  }
73 
74  return this->operator()(*from, *to);
75 }
virtual ~BaseSegmentRelationFilter()
Default destructor.
Weight operator()(const Relation< const CDCSegment2D > &relation) override
Main filter method overriding the filter interface method.
std::vector< const CDCSegment2D * > getPossibleTos(const CDCSegment2D *from, const std::vector< const CDCSegment2D * > &segments) const final
Returns all equivalent segment in the range.
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:47
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
A pair of iterators usable with the range base for loop.
Definition: Range.h:25
Iterator begin() const
Begin of the range for range based for.
Definition: Range.h:64
Type for two related objects.
Definition: Relation.h:21
To * getTo() const
Getter for the pointer to the to side object.
Definition: Relation.h:65
From * getFrom() const
Getter for the pointer to the from side object.
Definition: Relation.h:59
Abstract base class for different kinds of events.
Functor factory turning a binary functor and two functors into a new functor which executes the binar...
Definition: Functional.h:127