Belle II Software  release-05-01-25
OverlapResolver.icc.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/ckf/general/findlets/OverlapResolver.dcl.h>
13 
14 #include <tracking/ckf/general/utilities/CKFFunctors.h>
15 
16 #include <tracking/trackFindingCDC/utilities/Functional.h>
17 #include <tracking/trackFindingCDC/numerics/WeightComperator.h>
18 #include <tracking/trackFindingCDC/utilities/Algorithms.h>
19 #include <tracking/trackFindingCDC/utilities/VectorRange.h>
20 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
21 
22 #include <framework/core/ModuleParam.h>
23 #include <framework/logging/Logger.h>
24 
25 namespace Belle2 {
30  template<class AFilter>
32  {
33  Super::addProcessingSignalListener(&m_filter);
34  }
35 
37  template<class AFilter>
38  void OverlapResolver<AFilter>::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
39  {
40  m_filter.exposeParameters(moduleParamList, prefix);
41 
42  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "enableOverlapResolving"),
43  m_param_enableOverlapResolving,
44  "Enable the overlap resolving.",
45  m_param_enableOverlapResolving);
46  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "useBestNInSeed"),
47  m_param_useBestNInSeed,
48  "In seed mode, use only the best seeds.",
49  m_param_useBestNInSeed);
50  }
51 
52  template<class AFilter>
53  void OverlapResolver<AFilter>::apply(std::vector<typename AFilter::Object>& results,
54  std::vector<typename AFilter::Object>& filteredResults)
55  {
56  if (not m_param_enableOverlapResolving or results.empty()) {
57  std::swap(results, filteredResults);
58  return;
59  }
60 
61  // Sort results by seed, as it makes the next operations faster
62  std::sort(results.begin(), results.end(), TrackFindingCDC::LessOf<SeedGetter>());
63 
64  // resolve overlaps in each seed separately
65  const auto& groupedBySeed = TrackFindingCDC::adjacent_groupby(results.begin(), results.end(), SeedGetter());
66  for (const TrackFindingCDC::VectorRange<Object>& resultsWithSameSeed : groupedBySeed) {
67 
68  m_resultsWithWeight.clear();
69  for (Object& result : resultsWithSameSeed) {
70  TrackFindingCDC::Weight weight = m_filter(result);
71  if (std::isnan(weight)) {
72  continue;
73  }
74  m_resultsWithWeight.emplace_back(&result, weight);
75  }
76 
77  if (not m_resultsWithWeight.empty()) {
78  // sort results so that 'std::max' below picks path with highest weight if multiple paths have same size
79  std::sort(m_resultsWithWeight.begin(), m_resultsWithWeight.end(), TrackFindingCDC::GreaterWeight());
80 
81  const unsigned int useBestNResults = std::min(m_resultsWithWeight.size(), m_param_useBestNInSeed);
82  const auto& lastItemToUse = std::next(m_resultsWithWeight.begin(), useBestNResults);
83  const auto& longestElement = *(std::max_element(m_resultsWithWeight.begin(), lastItemToUse,
84  TrackFindingCDC::LessOf<NumberOfHitsGetter>()));
85  filteredResults.push_back(*(longestElement));
86  }
87  }
88  }
90 }
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
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::OverlapResolver
Simple findlet for searching the best candidate for a given seed aplying the given filter.
Definition: OverlapResolver.dcl.h:35
Belle2::OverlapResolver< Belle2::TrackFindingCDC::ChooseableFilter >::Object
typename Belle2::TrackFindingCDC::ChooseableFilter ::Object Object
The object to filter.
Definition: OverlapResolver.dcl.h:38
Belle2::SeedGetter
Helper Functor to get the Seed of a given result.
Definition: CKFFunctors.h:28
Belle2::TrackFindingCDC::Range
A pair of iterators usable with the range base for loop.
Definition: Range.h:35
Belle2::OverlapResolver::OverlapResolver
OverlapResolver()
Construct this findlet and add the subfindlet as listener.
Definition: OverlapResolver.icc.h:39