Belle II Software development
CKFRelationCreator.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/CKFRelationCreator.dcl.h>
11#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
12
13#include <tracking/trackFindingCDC/filters/base/RelationFilterUtil.h>
14#include <tracking/trackFindingCDC/utilities/Algorithms.h>
15
16#include <algorithm>
17
18namespace Belle2 {
23 template<class AState, class ASeedRelationFilter, class AHitRelationFilter>
25
26 template<class AState, class ASeedRelationFilter, class AHitRelationFilter>
28 {
31 }
32
33 template<class AState, class ASeedRelationFilter, class AHitRelationFilter>
35 const std::string& prefix)
36 {
37 m_seedFilter.exposeParameters(moduleParamList, TrackFindingCDC::prefixed("seed", prefix));
38 m_hitFilter.exposeParameters(moduleParamList, TrackFindingCDC::prefixed("hit", prefix));
39
40 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "onlyUseHitStatesRelatedToSeeds"),
41 m_onlyUseHitStatesRelatedToSeeds,
42 "Only use hit states related to seed states to build the inter hit relations to reduce combinatorics. "\
43 "By default, only the \"FromStates\" will be the ones related to seeds. If also the \"ToStates\" should be "\
44 "related to the seeds, also m_onlyCombineRelatedHitStates (name in Python: " + \
45 TrackFindingCDC::prefixed(prefix, "onlyCombineRelatedHitStates") + ") should be set to true.",
46 m_onlyUseHitStatesRelatedToSeeds);
47 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "onlyCombineRelatedHitStates"),
48 m_onlyCombineRelatedHitStates,
49 "Only use hit states related to seed states to build the inter hit relations to reduce combinatorics. "\
50 "If true, both \"FromStates\" and \"ToStates\" will be those that are already related to seeds. "\
51 "Only works if also m_onlyUseHitStatesRelatedToSeeds (name in Python: " + \
52 TrackFindingCDC::prefixed(prefix, "onlyUseHitStatesRelatedToSeeds") + ") is set to true.",
53 m_onlyCombineRelatedHitStates);
54 }
55
56 template<class AState, class ASeedRelationFilter, class AHitRelationFilter>
58 std::vector<AState>& states,
59 std::vector<TrackFindingCDC::WeightedRelation<AState>>& relations)
60 {
61 const std::vector<AState*> seedStatePointers = TrackFindingCDC::as_pointers<AState>(seedStates);
62 const std::vector<AState*> statePointers = TrackFindingCDC::as_pointers<AState>(states);
63
64 // Just some arbitrary number...
65 relations.reserve(10000);
66
67 // relations += seed states -> states
68 TrackFindingCDC::RelationFilterUtil::appendUsing(m_seedFilter, seedStatePointers, statePointers, relations, 1000000);
69
70 // relations += states -> states
71 if (m_onlyUseHitStatesRelatedToSeeds) {
72 // only use subset of hit states for inter hit state relation creation
73 std::vector<AState*> selectedStatePointers;
74 selectedStatePointers.reserve(relations.size());
75
76 for (const auto& relation : relations) {
77 // hit state pointers are the "To"s in the relation, only take those
78 const auto it = std::find(selectedStatePointers.begin(), selectedStatePointers.end(), relation.getTo());
79 if (it == selectedStatePointers.end()) {
80 selectedStatePointers.push_back(relation.getTo());
81 }
82 }
83
84 if (m_onlyCombineRelatedHitStates) {
85 // Reduce combinatorics a lot by only combining selectedStatePointers with other selectedStatePointers
86 TrackFindingCDC::RelationFilterUtil::appendUsing(m_hitFilter, selectedStatePointers, selectedStatePointers, relations, 1000000);
87 } else {
88 // Reduce combinatorics a bit less by only combining selectedStatePointers essentially all statePointers
89 TrackFindingCDC::RelationFilterUtil::appendUsing(m_hitFilter, selectedStatePointers, statePointers, relations, 1000000);
90 }
91 } else {
92 // use all of hit states for inter hit state relation creation
93 TrackFindingCDC::RelationFilterUtil::appendUsing(m_hitFilter, statePointers, statePointers, relations, 1000000);
94 }
95 }
97}
ASeedRelationFilter m_seedFilter
Subfindlet for the relation checking between seed and hits.
AHitRelationFilter m_hitFilter
Subfindlet for the relation checking between hits and hits.
The Module parameter list class.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Type for two related objects with a weight.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
CKFRelationCreator()
Construct this findlet and add the subfindlet as listener.
~CKFRelationCreator()
Default destructor.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters of the subfindlet.
void apply(std::vector< AState > &seedStates, std::vector< AState > &states, std::vector< TrackFindingCDC::WeightedRelation< AState > > &relations) override
Apply both filters for creating state-hit and hit-hit relations.
Abstract base class for different kinds of events.
static void appendUsing(ARelationFilter &relationFilter, const std::vector< AObject * > &froms, const std::vector< AObject * > &tos, std::vector< WeightedRelation< AObject > > &weightedRelations, unsigned int maximumNumberOfRelations=std::numeric_limits< unsigned int >::max())
Appends relations between elements in the given AItems using the ARelationFilter.