Belle II Software development
OverlapResolver.icc.h
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#pragma once
9
10#include <tracking/ckf/general/findlets/OverlapResolver.dcl.h>
11
12#include <tracking/ckf/general/utilities/CKFFunctors.h>
13
14#include <tracking/trackFindingCDC/utilities/Functional.h>
15#include <tracking/trackFindingCDC/numerics/WeightComperator.h>
16#include <tracking/trackFindingCDC/utilities/Algorithms.h>
17#include <tracking/trackFindingCDC/utilities/VectorRange.h>
18#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
19
20#include <framework/core/ModuleParam.h>
21#include <framework/logging/Logger.h>
22
23namespace Belle2 {
28 template<class AFilter>
30 {
32 }
33
35 template<class AFilter>
36 void OverlapResolver<AFilter>::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
37 {
38 m_filter.exposeParameters(moduleParamList, prefix);
39
40 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "enableOverlapResolving"),
41 m_param_enableOverlapResolving,
42 "Enable the overlap resolving.",
43 m_param_enableOverlapResolving);
44 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "useBestNInSeed"),
45 m_param_useBestNInSeed,
46 "In seed mode, use only the best seeds.",
47 m_param_useBestNInSeed);
48 }
49
50 template<class AFilter>
51 void OverlapResolver<AFilter>::apply(std::vector<typename AFilter::Object>& results,
52 std::vector<typename AFilter::Object>& filteredResults)
53 {
54 if (not m_param_enableOverlapResolving or results.empty()) {
55 std::swap(results, filteredResults);
56 return;
57 }
58
59 // Sort results by seed, as it makes the next operations faster
60 std::sort(results.begin(), results.end(), TrackFindingCDC::LessOf<SeedGetter>());
61
62 // resolve overlaps in each seed separately
63 const auto& groupedBySeed = TrackFindingCDC::adjacent_groupby(results.begin(), results.end(), SeedGetter());
64 for (const TrackFindingCDC::VectorRange<Object>& resultsWithSameSeed : groupedBySeed) {
65
66 m_resultsWithWeight.clear();
67 for (Object& result : resultsWithSameSeed) {
68 TrackFindingCDC::Weight weight = m_filter(result);
69 if (std::isnan(weight)) {
70 continue;
71 }
72 m_resultsWithWeight.emplace_back(&result, weight);
73 }
74
75 if (not m_resultsWithWeight.empty()) {
76 // sort results so that 'std::max' below picks path with highest weight if multiple paths have same size
77 std::sort(m_resultsWithWeight.begin(), m_resultsWithWeight.end(), TrackFindingCDC::GreaterWeight());
78
79 const unsigned int useBestNResults = std::min(m_resultsWithWeight.size(), m_param_useBestNInSeed);
80 const auto& lastItemToUse = std::next(m_resultsWithWeight.begin(), useBestNResults);
81 const auto& longestElement = *(std::max_element(m_resultsWithWeight.begin(), lastItemToUse,
83 filteredResults.push_back(*(longestElement));
84 }
85 }
86 }
88}
The Module parameter list class.
typename AFilter::Object Object
The object to filter.
AFilter m_filter
Subfindlet for filtering.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition: Findlet.h:26
A pair of iterators usable with the range base for loop.
Definition: Range.h:25
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
OverlapResolver()
Construct this findlet and add the subfindlet as listener.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters of the subfindlet.
void apply(std::vector< Object > &results, std::vector< Object > &filteredResult) override
For each seed, search for the best candidate and return it.
Abstract base class for different kinds of events.
Helper Functor to get the Seed of a given result.
Definition: CKFFunctors.h:18
Functor factory turning a binary functor and two functors into a new functor which executes the binar...
Definition: Functional.h:127