ATLAS Offline Software
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 
23 namespace TrigVSI{
24 
25 //========================================================================
29 class IWrkVrt
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 //========================================================================
55 template<typename WrkVrt>
56 class 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)) {};
64  VtxPack(){};
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 
116 template<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
TrigVSI::VtxPack::m_selTrkIndices
std::unordered_set< size_t > m_selTrkIndices
Definition: IWrkVrt.h:101
TrigVSI::VtxPack::m_isUpToDate
bool m_isUpToDate
Definition: IWrkVrt.h:99
TrigVSI::VtxPack::getIncompIndices
std::vector< std::pair< size_t, size_t > > getIncompIndices()
Return copy of incompatible track pair list.
Definition: IWrkVrt.h:80
TrigVSI::VtxPack::emplace_back
void emplace_back(const WrkVrt *vtx_ptr)
Emplace vertex pointer to vertex list.
Definition: IWrkVrt.h:67
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
TrigVSI::VtxPack
Base class of local vertex container in VtxMap.
Definition: IWrkVrt.h:56
TrigVSI::IWrkVrt::x
virtual double x() const =0
TrigVSI::VtxPack::m_incompIndices
std::vector< std::pair< size_t, size_t > > m_incompIndices
Definition: IWrkVrt.h:103
TrigVSI::VtxPack::m_compIndices
std::unordered_set< std::pair< size_t, size_t >, PairHash< size_t, size_t > > m_compIndices
Definition: IWrkVrt.h:102
TrigVSI::VtxPack::incompIndices
const std::vector< std::pair< size_t, size_t > > & incompIndices()
Return reference to incompatible track pair list.
Definition: IWrkVrt.h:82
TrigVSI::VtxPack::getVtxList
std::vector< const WrkVrt * > getVtxList()
Return a copy of vertex list.
Definition: IWrkVrt.h:85
protected
#define protected
Definition: DetDescrConditionsDict_dict_fixes.cxx:14
TrigVSI::VtxPack::nVtx
size_t nVtx()
Return the number of vertices.
Definition: IWrkVrt.h:91
TrigVSI::VtxPack::getWeight
double getWeight()
Return the weight of the container.
Definition: IWrkVrt.h:93
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
TrigVSI::VtxPack::checkUpdate
void checkUpdate()
Check if lists are up to date. If not, update them.
Definition: IWrkVrt.h:106
TrigVSI::IWrkVrt::selectedTrackIndices
virtual const std::deque< size_t > & selectedTrackIndices() const =0
Return indices of tracks associated with the vertex.
TrigVSI::VtxPack::getVtx
const WrkVrt * getVtx(size_t ivtx)
Return a copy of i-th vertex.
Definition: IWrkVrt.h:89
TrigVSI::IWrkVrt::z
virtual double z() const =0
TrigVSI::VtxPack::selectedTrackIndices
const std::unordered_set< size_t > & selectedTrackIndices()
Return reference to selected track indices list.
Definition: IWrkVrt.h:78
TrigVSI::VtxPack::VtxPack
VtxPack(std::vector< const WrkVrt * > &&v)
Definition: IWrkVrt.h:63
TrigVSI::IWrkVrt::~IWrkVrt
virtual ~IWrkVrt()=default
TrigVSI::PairHash
Definition: HashTools.h:41
HashTools.h
Hash functions for std::pair.
TrigVSI::VtxPack::vtxList
const std::vector< const WrkVrt * > & vtxList()
Return a reference to vertex list.
Definition: IWrkVrt.h:87
TrigVSI::VtxPack::getSelectedTrackIndices
std::unordered_set< size_t > getSelectedTrackIndices()
Definition: IWrkVrt.h:76
TrigVSI::IWrkVrt::y
virtual double y() const =0
TrigVSI::IWrkVrt::selectedTrackIndices
virtual std::deque< size_t > & selectedTrackIndices()=0
Return indices of tracks associated with the vertex.
TrigVSI::VtxPack::m_vtxLists
std::vector< const WrkVrt * > m_vtxLists
Definition: IWrkVrt.h:100
KDPoint.h
point classes for clustering
python.PyAthena.v
v
Definition: PyAthena.py:157
TrigVSI::VtxPack::VtxPack
VtxPack()
Definition: IWrkVrt.h:64
TrigVSI::VtxPack::updateLists
void updateLists()
Update set of tracks and incompatible track pair list.
Definition: IWrkVrt.h:117
TrigVSI::IWrkVrt
Interface for vertex classes processed in VtxMap.
Definition: IWrkVrt.h:30
TrigVSI
Definition: TrigVrtSecInclusive.cxx:27
TrigVSI::VtxPack::VtxPack
VtxPack(std::vector< const WrkVrt * > &v)
Constructor.
Definition: IWrkVrt.h:62