ATLAS Offline Software
Loading...
Searching...
No Matches
JetGroupProduct.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "./JetGroupProduct.h"
6#include "./JetStreamer.h"
7#include "./make_jetstream.h"
9
10#include <set>
11#include <string>
12
13JetGroupProduct::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
24void 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);
47 m_jetEnd = std::max(m_jetEnd,
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(std::move(condIndices), std::move(repeats), 0);
57 m_jetstreamer.reset(new JetStreamer(std::move(streamer)));
58}
59
60std::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,
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
127bool JetGroupProduct::valid() const {return m_valid;}
128
std::map< int, std::vector< std::size_t > > CondInd2JetGroupsInds
std::map< int, std::vector< std::size_t > > JetGroupInd2ElemInds
std::unique_ptr< ITrigJetHypoInfoCollector > Collector
virtual void collect(const std::string &, const std::string &)=0
std::vector< bool > m_jetMask
std::unique_ptr< JetStreamer > m_jetstreamer
JetGroupProduct(const std::vector< std::size_t > &siblings, const CondInd2JetGroupsInds &satisfiedBy, const std::vector< std::size_t > &condMult, const JetGroupInd2ElemInds &)
JetGroupInd2ElemInds m_jg2elemjgs
virtual std::vector< std::size_t > next(const Collector &) override
void init(const std::vector< std::size_t > &siblings, const CondInd2JetGroupsInds &satisfiedBy, const std::vector< std::size_t > &condMult)
std::vector< std::vector< std::size_t > > m_seenIndices
virtual bool valid() const override
std::size_t m_jetEnd
std::vector< std::size_t > elementalJetGroups(const std::vector< std::size_t > &non_elemental, const JetGroupInd2ElemInds &jg2elemjg)
std::unique_ptr< IJetStream > make_jetstream(std::vector< std::vector< std::size_t > > indices, std::vector< std::size_t > repeats, std::size_t sid)