ATLAS Offline Software
Loading...
Searching...
No Matches
IWrkVrt.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef TRIGTOOLS_TRIG_VSI_IWRKVTX
5#define TRIGTOOLS_TRIG_VSI_IWRKVTX
6
15
16#include "TMath.h"
17#include "TVector3.h"
18
19#include <deque>
20#include <unordered_set>
21#include <vector>
22
23namespace TrigVSI{
24
25//========================================================================
30{
31 public:
32 virtual ~IWrkVrt() = default;
33
34 virtual std::deque<size_t>& selectedTrackIndices() = 0;
35 virtual const std::deque<size_t>& selectedTrackIndices() const = 0;
36
39 virtual double x() const = 0;
40 virtual double y() const = 0;
41 virtual double z() const = 0;
43};
44
45
46//========================================================================
55template<typename WrkVrt>
56class VtxPack {
57 public :
62 VtxPack(std::vector<const WrkVrt*>& v) : m_vtxLists(v) {};
63 VtxPack(std::vector<const WrkVrt*>&& v) : m_vtxLists(std::move(v)) {};
65
67 inline void emplace_back(const WrkVrt* vtx_ptr)
68 {
69 m_isUpToDate = false;
70 m_vtxLists.emplace_back(vtx_ptr);
71 };
72
76 inline std::unordered_set<size_t> getSelectedTrackIndices(){ checkUpdate(); return m_selTrkIndices; };
78 inline const std::unordered_set<size_t>& selectedTrackIndices(){ checkUpdate(); return m_selTrkIndices; };
80 inline std::vector<std::pair<size_t, size_t>> getIncompIndices(){ checkUpdate(); return m_incompIndices; };
82 inline const std::vector<std::pair<size_t, size_t>>& incompIndices(){ checkUpdate(); return m_incompIndices; };
83
85 inline std::vector<const WrkVrt*> getVtxList() { checkUpdate(); return m_vtxLists; };
87 inline const std::vector<const WrkVrt*>& vtxList() { checkUpdate(); return m_vtxLists; };
89 inline const WrkVrt* getVtx(size_t ivtx) { checkUpdate(); return m_vtxLists[ivtx]; };
91 inline size_t nVtx() { checkUpdate(); return m_vtxLists.size(); };
93 inline double getWeight() { checkUpdate(); return static_cast<double>(m_vtxLists.size()); };
95
96 void updateLists();
97
98 protected :
99 bool m_isUpToDate = false;
100 std::vector<const WrkVrt*> m_vtxLists;
101 std::unordered_set<size_t> m_selTrkIndices;
102 std::unordered_set<std::pair<size_t, size_t>, PairHash<size_t,size_t>> m_compIndices;
103 std::vector<std::pair<size_t, size_t>> m_incompIndices;
104
106 inline void checkUpdate() { if( !m_isUpToDate ) updateLists(); return; };
107};
108
109
116template<typename WrkVrt>
118{
119 // Update Selected Track list
120 m_selTrkIndices.clear();
121 m_compIndices.clear();
122 for (const WrkVrt* vrt : m_vtxLists) {
123 m_selTrkIndices.emplace( vrt->selectedTrackIndices().at(0) );
124 m_selTrkIndices.emplace( vrt->selectedTrackIndices().at(1) );
125 std::pair<size_t, size_t> p_tmp_ = std::minmax( vrt->selectedTrackIndices().at(0),vrt->selectedTrackIndices().at(1) );
126 m_compIndices.emplace( std::move(p_tmp_) );
127 }
128
129 // Update incompatible track pair lists
130 m_incompIndices.clear();
131 for ( auto i_itr = m_selTrkIndices.begin(); i_itr != m_selTrkIndices.end(); ++i_itr ) {
132 for ( auto j_itr = std::next(i_itr); j_itr != m_selTrkIndices.end(); ++j_itr ) {
133 std::pair<size_t, size_t> p_tmp_ = std::minmax(*i_itr,*j_itr);
134 auto tmp_itr = std::find(m_compIndices.begin(), m_compIndices.end(), p_tmp_ );
135 if ( tmp_itr != m_compIndices.end() ) continue; // When the pair found in compatible pair list, skip and continue loop
136 m_incompIndices.emplace_back( std::make_pair(*i_itr, *j_itr) );
137 }
138 }
139 //
140 m_isUpToDate = true; // Set up to date flag true
141}
142
143} // end of namespave TrigVSI
144
145#endif
#define protected
Hash functions for std::pair.
point classes for clustering
Interface for vertex classes processed in VtxMap.
Definition IWrkVrt.h:30
virtual double z() const =0
virtual const std::deque< size_t > & selectedTrackIndices() const =0
Return indices of tracks associated with the vertex.
virtual double y() const =0
virtual ~IWrkVrt()=default
virtual std::deque< size_t > & selectedTrackIndices()=0
Return indices of tracks associated with the vertex.
virtual double x() const =0
const std::vector< const WrkVrt * > & vtxList()
Return a reference to vertex list.
Definition IWrkVrt.h:87
bool m_isUpToDate
Definition IWrkVrt.h:99
std::vector< const WrkVrt * > m_vtxLists
Definition IWrkVrt.h:100
std::vector< const WrkVrt * > getVtxList()
Return a copy of vertex list.
Definition IWrkVrt.h:85
const std::vector< std::pair< size_t, size_t > > & incompIndices()
Return reference to incompatible track pair list.
Definition IWrkVrt.h:82
VtxPack(std::vector< const WrkVrt * > &v)
Constructor.
Definition IWrkVrt.h:62
const std::unordered_set< size_t > & selectedTrackIndices()
Return reference to selected track indices list.
Definition IWrkVrt.h:78
std::vector< std::pair< size_t, size_t > > getIncompIndices()
Return copy of incompatible track pair list.
Definition IWrkVrt.h:80
size_t nVtx()
Return the number of vertices.
Definition IWrkVrt.h:91
std::unordered_set< size_t > getSelectedTrackIndices()
Definition IWrkVrt.h:76
const WrkVrt * getVtx(size_t ivtx)
Return a copy of i-th vertex.
Definition IWrkVrt.h:89
std::vector< std::pair< size_t, size_t > > m_incompIndices
Definition IWrkVrt.h:103
VtxPack(std::vector< const WrkVrt * > &&v)
Definition IWrkVrt.h:63
void emplace_back(const WrkVrt *vtx_ptr)
Emplace vertex pointer to vertex list.
Definition IWrkVrt.h:67
std::unordered_set< size_t > m_selTrkIndices
Definition IWrkVrt.h:101
void updateLists()
Update set of tracks and incompatible track pair list.
Definition IWrkVrt.h:117
double getWeight()
Return the weight of the container.
Definition IWrkVrt.h:93
void checkUpdate()
Check if lists are up to date. If not, update them.
Definition IWrkVrt.h:106
std::unordered_set< std::pair< size_t, size_t >, PairHash< size_t, size_t > > m_compIndices
Definition IWrkVrt.h:102
STL namespace.