ATLAS Offline Software
JetGroupProduct.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "./JetGroupProduct.h"
6 #include "./JetStreamer.h"
7 #include "./make_jetstream.h"
8 #include "./elementalJetGroups.h"
9 
10 #include <set>
11 #include <string>
12 
13 JetGroupProduct::JetGroupProduct(const std::vector<std::size_t>& siblings,
14  const CondInd2JetGroupsInds& satisfiedBy,
15  const std::vector<std::size_t>& condMult,
16  const JetGroupInd2ElemInds& jg2elemjgs):
17  m_jg2elemjgs{jg2elemjgs}
18 {
19 
20  m_valid = !siblings.empty() or satisfiedBy.size() != condMult.size();
21  if (m_valid) {init(siblings, satisfiedBy, condMult);}
22 }
23 
24 void JetGroupProduct::init(const std::vector<std::size_t>& siblings,
25  const CondInd2JetGroupsInds& satisfiedBy,
26  const std::vector<std::size_t>& condMult) {
27 
28  // create a jetstreamer object to cycle through the
29  // possoble combinations. The streamer may form
30  // vectors of indices by performing external products, and
31  // these may have duplicates, and vectors that differ only in
32  // order, which will need to be removed.
33 
34 
35  std::vector<std::vector<std::size_t>> condIndices;
36  condIndices.reserve(siblings.size());
37  std::vector<std::size_t> repeats;
38  condIndices.reserve(siblings.size());
39 
40  for(const auto& isib : siblings){
41  auto mult = condMult[isib]; // jet groups indices of satisying jgs.
42  repeats.push_back(mult);
43  condIndices.push_back(satisfiedBy.at(isib));
44 
45  // find the greatest jet index we will deal with
46  const auto& sibjets = satisfiedBy.at(isib);
48  *std::max_element(sibjets.begin(),
49  sibjets.end()));
50  ++m_jetEnd;; // to be used as an end marker
51  m_jetMask.reserve(m_jetEnd);
52 
53  }
54 
55 
56  auto streamer = make_jetstream(condIndices, repeats, 0);
57  m_jetstreamer.reset(new JetStreamer(std::move(streamer)));
58 }
59 
60 std::vector<std::size_t> JetGroupProduct::next(const Collector& collector){
61  // Produce an ordered set sequence of jet indices, one from each Condition
62  // with no duplicate indices.
63  //
64  // Ask ProductGen for the next set of indices into the condIndices arrays
65  // use these to create a sequences of jet indices. The process is blocked
66  // if there is a duplicate jet index using m_jetMask
67  //
68  // finally, m_seenIndices keeps track of jet index seqiences that have
69  // already been generated. If this is the first time the sequece has
70  // been generated, it will be added to m_seenJetIndices, and then requrned
71  // to the caller. If it has already been seen, it will be abandoned.
72 
73  if (!m_valid) {return std::vector<std::size_t>();}
74 
75  unsigned int ipass{0};
76  std::vector<std::size_t> jg_indices;
77  while(true){
78 
79  m_jetMask.assign(m_jetEnd, false);
80 
81  if(collector){
82  collector->collect("JetGroupProduct::next()",
83  "loop start pass " + std::to_string(ipass++));
84  }
85 
86 
87  bool blocked{false};
88  auto jet_indices = m_jetstreamer->next();
89  if (jet_indices.empty()) {
90  if(collector){
91  collector->collect("JetGroupProduct::next()",
92  "end of iteration ");
93  }
94  return jet_indices;
95  }
96  for (const auto& ind : jet_indices) {
97  if (m_jetMask[ind]) {
98  blocked = true;
99  break;
100  }
101  m_jetMask[ind] = true;
102  }
103 
104  if (blocked){continue;}
105 
106  jg_indices.clear();
107  for(std::size_t i = 0; i != m_jetEnd; ++i) {
108  if (m_jetMask[i]) {
109  jg_indices.push_back(i);
110  }
111  }
112 
113  auto elem_indices = elementalJetGroups(jg_indices,
114  m_jg2elemjgs);
115  if (elem_indices.empty()) {continue;}
116 
117  if (std::find(m_seenIndices.begin(),
118  m_seenIndices.end(),
119  elem_indices) == m_seenIndices.end()){
120  m_seenIndices.push_back(elem_indices);
121  return elem_indices;
122  }
123  }
124 }
125 
126 
127 bool JetGroupProduct::valid() const {return m_valid;}
128 
JetGroupProduct.h
CondInd2JetGroupsInds
std::map< int, std::vector< std::size_t > > CondInd2JetGroupsInds
Definition: JetGroupProduct.h:15
max
#define max(a, b)
Definition: cfImp.cxx:41
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
JetGroupProduct::m_seenIndices
std::vector< std::vector< std::size_t > > m_seenIndices
Definition: JetGroupProduct.h:50
JetGroupProduct::init
void init(const std::vector< std::size_t > &siblings, const CondInd2JetGroupsInds &satisfiedBy, const std::vector< std::size_t > &condMult)
Definition: JetGroupProduct.cxx:24
JetGroupProduct::JetGroupProduct
JetGroupProduct(const std::vector< std::size_t > &siblings, const CondInd2JetGroupsInds &satisfiedBy, const std::vector< std::size_t > &condMult, const JetGroupInd2ElemInds &)
Definition: JetGroupProduct.cxx:13
JetStreamer.h
JetGroupProduct::valid
virtual bool valid() const override
Definition: JetGroupProduct.cxx:127
JetGroupProduct::m_jetstreamer
std::unique_ptr< JetStreamer > m_jetstreamer
Definition: JetGroupProduct.h:51
elementalJetGroups
std::vector< std::size_t > elementalJetGroups(const std::vector< std::size_t > &non_elemental, const JetGroupInd2ElemInds &jg2elemjg)
Definition: elementalJetGroups.cxx:9
make_jetstream.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
JetGroupInd2ElemInds
std::map< int, std::vector< std::size_t > > JetGroupInd2ElemInds
Definition: elementalJetGroups.h:11
JetGroupProduct::m_jg2elemjgs
JetGroupInd2ElemInds m_jg2elemjgs
Definition: JetGroupProduct.h:45
Collector
std::unique_ptr< ITrigJetHypoInfoCollector > Collector
Definition: FastReducer.h:22
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
python.PyKernel.init
def init(v_theApp, v_rootStream=None)
Definition: PyKernel.py:45
JetGroupProduct::m_jetEnd
std::size_t m_jetEnd
Definition: JetGroupProduct.h:48
JetGroupProduct::m_valid
bool m_valid
Definition: JetGroupProduct.h:52
JetStreamer
Definition: JetStreamer.h:25
elementalJetGroups.h
JetGroupProduct::next
virtual std::vector< std::size_t > next(const Collector &) override
Definition: JetGroupProduct.cxx:60
make_jetstream
std::unique_ptr< IJetStream > make_jetstream(std::vector< std::vector< std::size_t >> indices, std::vector< std::size_t > repeats, std::size_t sid)
Definition: make_jetstream.h:28
JetGroupProduct::m_jetMask
std::vector< bool > m_jetMask
Definition: JetGroupProduct.h:47
checkFileSG.ind
list ind
Definition: checkFileSG.py:118