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