ATLAS Offline Software
Loading...
Searching...
No Matches
ComboIterator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <iostream>
6
7#include <algorithm>
8
11
13using namespace std;
14
15HLT::ComboIterator::ComboIterator(const std::vector<TEVec>& tes, const HLT::TrigNavStructure* nav)
16 : m_valid(true),
17 m_nav(nav)
18
19{
20 for (unsigned int i = 0; i < tes.size(); i++)
21 m_tes.push_back(tes[i]);
22
23 rewind();
24}
25
26
28{
29 m_comb.clear();
30 m_idx.clear();
31
32 // cout << "Construct" << endl;
33
34 for (unsigned int i = 0; i < m_tes.size(); i++) {
35
36 if (m_tes[i].size() == 0) {
37 invalidate();
38 return 0;
39 }
40
41 m_comb.push_back(0);
42 m_idx.push_back(-1);
43
44 if (!reset(i) || !increment(i)) {
45 invalidate();
46 return 0;
47 }
48 }
49
50 // cout << "After setup: " << endl;
51 // cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" << endl;
52 // print();
53 // cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
54 return isValid();
55}
56
57
59{
60 if (!increment((int)m_comb.size() - 1)) invalidate();
61 // cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" << endl;
62 // print();
63 // cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
64
65 return *this;
66}
67
68
70{
71 if (!isValid()) return false;
72
73 bool ok = false;
74 while (!ok) if (!incrementByOne(pos, ok)) return false;
75
76 return ok;
77}
78
79
81{
82 // cout << "increment1 " << pos << endl;
83
84 if (pos >= (int)m_comb.size() || pos < 0) return false;
85
86 ok = false;
87
88 // If we're at the end of the vector for this element, ...
89 if (m_idx[pos] == (int)m_tes[pos].size() - 1) {
90
91 // ... if it's the first (innermost-loop) one, we're done...
92 if (pos == 0) return false;
93
94 // ... otherwise increment the previous element by one...
95 if (!increment(pos - 1)) return false;
96
97 // ... reset this one...
98 if (!reset(pos)) return false;
99
100 // ... and increment it (from reset to valid).
101 if (!increment(pos)) return false;
102 }
103 else {
104 // else it's just the normal case,
105
106 m_idx [pos]++;
107 m_comb[pos] = m_tes[pos][m_idx[pos]];
108 }
109
110 ok = !overlaps(m_comb[pos], m_comb, pos);
111 // cout << "after increment (pos=" << pos << ", ok=" << ok << ")" << endl; print();
112
113 return true;
114}
115
116
118{
119 // cout << "Reset : " << pos << endl;
120
121 if (pos >= (int)m_comb.size() || pos < 0) return false;
122
123 m_comb[pos] = 0;
124 m_idx [pos] = -1;
125
126
127 // Find the previous element of the same type (if any), and get its index
128 // in the vector of TEs of this type...
129
130 for (unsigned int j = pos; j > 0; j--) {
131
132 if (!m_comb[j - 1]) continue;
133
134 // Find the TE of the same type with the highest index
135 if (m_comb[j - 1]->getId() == m_tes[pos][0]->getId()) {
136 m_idx[pos] = m_idx[j - 1];
137 break;
138 }
139 }
140
141 // cout << "reset to index = " << m_idx[pos] << endl;
142 return 1;
143}
144
145
147 const TEVec& teVec, int idx) const
148{
149 if (idx < 0) idx = teVec.size();
150
151 for (int i = 0; i < idx; i++) {
152 if (!teVec[i]) return false;
153 if (overlaps(te1, teVec[i])) return true;
154 }
155
156 return false;
157}
158
159
161 const TriggerElement* te2) const
162{
163 if (te1 == te2) return true;
164 if (m_nav && m_nav->haveCommonRoI(te1, te2)) return true;
165
166 return false;
167}
168
169
171{
172 cout << endl;
173 cout << "TEs:" << endl;
174 cout << "{" << endl;
175 for (unsigned int i = 0; i < m_tes.size(); i++) {
176 cout << " [ ";
177 for (unsigned int j = 0; j < m_tes[i].size(); j++) cout << m_tes[i][j] << " ";
178 cout << "]" << endl;
179 }
180 cout << "}" << endl << endl << "Comb = [ ";
181 for (unsigned int i = 0; i < m_comb.size(); i++) cout << m_comb[i] << " ";
182 cout << "]" << endl << "Idxs = [ ";
183 for (unsigned int i = 0; i < m_idx.size(); i++) cout << m_idx[i] << " ";
184 cout << "]" << endl;
185 cout << (isValid() ? "Valid" : "Invalid") << endl << endl;
186}
187
188
190{
191 // cout << "-------------------------------" << endl;
192 // cout << "Invalidate!" << endl;
193 // cout << "-------------------------------" << endl;
194 m_valid = false;
195 m_comb.clear();
196}
197
198
199HLT::ComboIteratorTopo::ComboIteratorTopo(const std::vector<TEVec>& tes, const TrigNavStructure* nav,
200 HLT::te_id_type topoSpan)
201 : ComboIterator(tes, nav),
202 m_spanId(topoSpan) {
203 rewind();
204}
205
206void HLT::ComboIteratorTopo::traverseUntilSeedsTopo(const HLT::TriggerElement* start, std::set<const TriggerElement*>& topos) const {
207
208 auto & successors = HLT::TrigNavStructure::getDirectSuccessors(start);
209 for ( auto successor : successors ) {
210 if ( successor->getActiveState() == true and successor->getId() == m_spanId ) {
211 topos.insert(successor);
212 }
213 }
214 if ( not topos.empty() )
215 return;
216
217 // we need to digg deeper
218 auto & predecessors = HLT::TrigNavStructure::getDirectPredecessors(start);
219 for ( auto predecessor : predecessors ) {
220 // this next line is disabled because the predecessors of the L1Topo simulation output TE are exactly of type RoI-node (after discussion with Tomasz)
221 // if ( HLT::TrigNavStructure::isRoINode(predecessor) ) continue;
222 traverseUntilSeedsTopo(predecessor, topos);
223 if ( not topos.empty() )
224 return;
225 }
226}
227
229 if ( HLT::ComboIterator::overlaps(t1, t2) == true ) return true;
230
231 // if above returned true it means TEs are from the same RoI, combiation is uninteresting
232 // if false it may still be uninteresting because it is joined by topo TE
233
234 std::set<const TriggerElement*> te1span;
235 traverseUntilSeedsTopo(t1, te1span);
236 if ( te1span.empty() ) // empty set can not be from the same combination
237 return true;
238
239 std::set<const TriggerElement*> te2span;
240 traverseUntilSeedsTopo(t2, te2span);
241 if ( te2span.empty() )
242 return true;
243 /*
244 for ( auto te : te1span )
245 cout << " t1 span TES " << te << " " << te->getId() << endl;
246 cout << endl;
247 for ( auto te : te2span )
248 cout << " t2 span TES " << te << " " << te->getId() << endl;
249 */
250 std::vector<const TriggerElement*> intersection;
251 std::set_intersection(te1span.begin(), te1span.end(), te2span.begin(), te2span.end(),
252 std::back_inserter(intersection));
253
254 if ( not intersection.empty() )
255 return false; // there is genuine topo join, the pair is interesting
256 return true;
257
258}
259
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
HLT::te_id_type m_spanId
virtual bool overlaps(const TriggerElement *t1, const TriggerElement *t2) const
Method used to test overlaps between two TEs.
ComboIteratorTopo(const std::vector< TEVec > &tes, const TrigNavStructure *nav, HLT::te_id_type topoSpan)
void traverseUntilSeedsTopo(const TriggerElement *start, std::set< const TriggerElement * > &topos) const
Iterator used to loop over multi-particle combinations.
std::vector< TEVec > m_tes
Vector of vectors of TEs to be combined.
const TrigNavStructure * m_nav
Pointer to the navigation service.
void invalidate()
Method used to invalidate the current combination.
bool reset(int pos)
Private reset method.
bool m_valid
Validity status variable.
bool incrementByOne(int pos, bool &ok)
Private increment method.
ComboIterator(const std::vector< TEVec > &tes, const TrigNavStructure *nav)
Constructor; gets a vector of TE vectors and a pointer to Navigation as arguments.
bool rewind()
Rewind method, resetting the iterator to the first element.
TEVec m_comb
Current combination of TEs.
std::vector< int > m_idx
Vector of indexes keeping track of the loop over combinations.
virtual bool overlaps(const TriggerElement *t1, const TriggerElement *t2) const
Method used to test overlaps between two TEs.
ComboIterator & operator++()
Pre increment operator.
void print() const
Debug dump to std::cout.
bool increment(int pos)
Private increment method.
static const std::vector< TriggerElement * > & getDirectPredecessors(const TriggerElement *te)
returns list of direct predecessors (nodes seeding me)
static const std::vector< TriggerElement * > & getDirectSuccessors(const TriggerElement *te)
returns list of direct predecessors (nodes I seed)
TriggerElement is the basic ingreedient of the interface between HLT algorithms and the navigation It...
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
std::vector< HLT::TriggerElement * > TEVec
STL namespace.