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