Skip to content
Snippets Groups Projects
Commit 08316e1e authored by Peter Sherwood's avatar Peter Sherwood Committed by Walter Lampl
Browse files

Main theme: dividing jet vector inot jet groups now done in FastReducer...

Main theme: dividing jet vector inot jet groups now done in FastReducer according to the leaf node capacity.

Fix IJetGrouper interface: next() to return HypoJetVector,not HypoJetGroupVector
    AllJetsGrouper.h, cxx
    CombinationsGrouper.h, cxx
    IJetGrouper.h, cxx
    IndexedJetsGrouper.h, cxx
    SingleJetGrouper.h, cxx

New Helper class, with no Grouper (gorupsers now in the Matcher)
     python/ConditionsToolSetterFastReduction.py

Refactoring to aid debugging
	    python/ConditionsToolSetterFastReduction.py

testChainDictMaker.py
	add node tree dump

Jet Groupers now are instantiated according to leaf Condition cap ni FasdtReducer
    ITrigJetHypoToolNoGrouperConfig.h
    FastReducer.cxx

Clean up keeping track of index <-> job groups
      FastReducer.cxx
      new class: GrouperByCapacityFactory.h, cxx
      new class: JetGroupRegister.h, cxx
parent b57205f9
No related branches found
No related tags found
5 merge requests!58791DataQualityConfigurations: Modify L1Calo config for web display,!46784MuonCondInterface: Enable thread-safety checking.,!46776Updated LArMonitoring config file for WD to match new files produced using MT,!45405updated ART test cron job,!42417Draft: DIRE and VINCIA Base Fragments for Pythia 8.3
Showing
with 533 additions and 159 deletions
......@@ -10,13 +10,13 @@
class AllJetsGrouper: public IJetGrouper{
public:
AllJetsGrouper();
AllJetsGrouper(const HypoJetIter& b, const HypoJetIter& e);
AllJetsGrouper(const HypoJetCIter& b, const HypoJetCIter& e);
AllJetsGrouper(const HypoJetVector&);
std::vector<HypoJetGroupVector> group(HypoJetIter&,
HypoJetIter&) const override;
virtual std::optional<HypoJetGroupVector> next() override;
virtual std::optional<HypoJetVector> next() override;
std::string getName() const override;
std::string toString() const override;
......
......@@ -22,7 +22,7 @@ class CombinationsGrouper: public IJetGrouper{
std::vector<HypoJetGroupVector> group(HypoJetIter&,
HypoJetIter&) const override;
std::optional<HypoJetGroupVector> next() override;
std::optional<HypoJetVector> next() override;
std::string getName() const override;
std::string toString() const override;
......
......@@ -25,7 +25,7 @@ class IJetGrouper{
*/
virtual std::vector<HypoJetGroupVector> group(HypoJetIter&,
HypoJetIter&) const = 0;
virtual std::optional<HypoJetGroupVector> next() = 0;
virtual std::optional<HypoJetVector> next() = 0;
virtual std::string toString() const = 0;
virtual std::string getName() const = 0;
};
......
......@@ -36,7 +36,7 @@ public:
std::vector<HypoJetGroupVector>
group(HypoJetIter&, HypoJetIter&) const override;
std::optional<HypoJetGroupVector> next() override;
std::optional<HypoJetVector> next() override;
std::string getName() const override;
std::string toString() const override;
......
......@@ -16,13 +16,13 @@ class SingleJetGrouper: public IJetGrouper{
std::vector<HypoJetGroupVector> group(HypoJetIter&,
HypoJetIter&) const override;
std::optional<HypoJetGroupVector> next() override;
std::optional<HypoJetVector> next() override;
std::string getName() const override;
std::string toString() const override;
private:
HypoJetVector m_jets;
std::size_t m_size;
HypoJetVector m_jets{};
std::size_t m_size{0};
std::size_t m_index{0};
};
#endif
......@@ -14,7 +14,7 @@ from AthenaCommon.Logging import logging
log = logging.getLogger( 'ConditionsToolSetterFastReduction' )
def is_leaf(node):
return node.scenario in ('simple', 'etaet', 'dijet', 'qjet')
return node.scenario in ('simple', 'etaet', 'dijet', 'qjet', 'agg')
def is_inner(node):
......@@ -46,11 +46,12 @@ class ConditionsToolSetterFastReduction(object):
'qjmass': [CompFactory.TrigJetConditionConfig_qjet_mass, 0],
'smc': [CompFactory.TrigJetConditionConfig_smc, 0],
'jvt': [CompFactory.TrigJetConditionConfig_jvt, 0],
'ht': [CompFactory.TrigJetConditionConfig_htfr, 0],
'all': [CompFactory.TrigJetConditionConfig_acceptAll, 0],
'capacitychecked':
[CompFactory.TrigJetConditionConfig_capacitychecked, 0],
'fastreduction': [CompFactory.TrigJetHypoToolConfig_fastreduction, 0],
'helper': [CompFactory.TrigJetHypoToolHelperMT, 0],
'helper': [CompFactory.TrigJetHypoToolHelperNoGrouper, 0],
}
for var in self.JetMoments:
self.tool_factories['mom'+var] = [CompFactory.TrigJetConditionConfig_moment, 0]
......@@ -82,7 +83,63 @@ class ConditionsToolSetterFastReduction(object):
self.tool_factories[key][1] += 1
return tool
def _make_el_condition_tools(self, conf_dict):
"""conf_dict: a dict containing names of elemental conditions
and min, max valies. These will be used to instantiate
conditon building AlgTools, one for eac conditon
for 2j80_2j60, the dictionaries are:
{'et': {'min': '80000.0', 'max': 'inf'},
'eta': {'min': '0.0', 'max': '3.2'}}
and
{'et': {'min': '60000.0', 'max': 'inf'},
'eta': {'min': '0.0', 'max': '3.2'}})
"""
condition_tools = [] # a list of AlgTools that build elemental Conds.
for k, v in conf_dict.items(): # loop over elemental conditions
# k in the condition name, v contains its min, max values.
# create the AlgTool that will build the elemental condition
condition_tool = self._get_tool_instance(k)
for lim, val in v.items(): # lim: min, max
setattr(condition_tool, lim, val)
# SPECIAL CASE: Moment tool needs the name of the
# moment as well as the min. max cuts:
if (k.startswith ('mom')):
moment = k[len('mom'):]
if moment in self.JetMoments:
condition_tool.moment = self.JetMoments[moment]
else: raise RuntimeError('%s not supported' % (moment))
# END SPECIAL CASE
condition_tools.append(condition_tool)
return condition_tools
def _make_compound_condition_tools(self, node):
"""For each element of node.conf_attrs, construct a
CapacityChecledCondition. Example for chain HLT_2j80_3j60_L1J15:
First leaf node has
conf_attrs [1]:
(defaultdict(<class 'dict'>, {
'et': {'min': '80000.0', 'max': 'inf'},
'eta': {'min': '0.0', 'max': '3.2'}}), 2)
Second leaf node has
conf_attrs [1]:
(defaultdict(<class 'dict'>, {'et': {'min': '60000.0', 'max': 'inf'},
'eta': {'min': '0.0', 'max': '3.2'}}), 3)
"""
# compound_condition_tools:
# elemental condition maker AlgToolshelper by the compound condition
......@@ -99,25 +156,9 @@ class ConditionsToolSetterFastReduction(object):
cpi = node.chainpartinds[i][0]
assert mult == node.chainpartinds[i][1]
condition_tools = [] # elemental conditions for this compounnd ct.
for k, v in c.items(): # loop over elemental conditions
condition_tool = self._get_tool_instance(k)
for lim, val in v.items(): # lim: min, max
setattr(condition_tool, lim, val)
# SPECIAL CASE: Moment tool needs the name of the
# moment as well as the min. max cuts:
if (k.startswith ('mom')):
moment = k[len('mom'):]
if moment in self.JetMoments:
condition_tool.moment = self.JetMoments[moment]
else: raise RuntimeError('%s not supported' % (moment))
# END SPECIAL CASE
condition_tools.append(condition_tool)
el_condition_tools = self._make_el_condition_tools(c)
# create capacitychecked condition from elemental condition
condition_tool =self._get_tool_instance('capacitychecked')
......@@ -126,16 +167,38 @@ class ConditionsToolSetterFastReduction(object):
# convert label from string to int for more efficient
# processing in C++ land.
condition_tool.chainPartInd = int(cpi[len('leg'):])
else:
condition_tool.chainPartInd = 0
condition_tool.conditionMakers = condition_tools
condition_tool.conditionMakers = el_condition_tools
condition_tool.multiplicity = mult
# add capacitychecked condition to list
outer_condition_tools.append(condition_tool)
return outer_condition_tools
def _make_filter_tool(self, node):
"""Condtion filters use a list of CompoundCondition containing
single jet elemental conditions select a subset of the reco
jets to send to the a Condition"""
el_condition_tools = []
for fc, mult in node.filter_conditions:
assert len(fc) == 1 # 1 elemental condition
assert mult == 1
el_condition_tools.extend(self._make_el_condition_tools(fc))
if not el_condition_tools:
el_condition_tools.append(self._get_tool_instance('all'))
capacitychecked_condition_tool = self._get_tool_instance(
'capacitychecked')
capacitychecked_condition_tool.conditionMakers = el_condition_tools
capacitychecked_condition_tool.multiplicity = 1
return capacitychecked_condition_tool
def _mod_leaf(self, node):
""" Add Condition tools to For a leaf node."""
......@@ -155,6 +218,17 @@ class ConditionsToolSetterFastReduction(object):
node.compound_condition_tools = self._make_compound_condition_tools(
node)
# make condition builder AlgTools for the condition filters.
# condition filters select subsets of the input jets to present
# to a condition,
node.filter_tool = self._make_filter_tool(node)
# if node.scenario == 'agg':
# print (node)
# assert False
def report(self):
wid = max(len(k) for k in self.tool_factories.keys())
rep = '\n%s: ' % self.__class__.__name__
......@@ -171,20 +245,27 @@ class ConditionsToolSetterFastReduction(object):
self._fill_tree_map(cn, tmap)
def _fill_conditions_map(self, node, cmap):
def _fill_conditions_map(self, node, cmap, fmap):
if is_leaf(node):
assert (len(node.compound_condition_tools) == 1)
cmap[node.node_id] = node.compound_condition_tools[0]
fmap[node.node_id] = node.filter_tool
else:
# must have a tool for Gaudi to instantiate in
cmap[node.node_id] = self._get_tool_instance('capacitychecked')
cmap[node.node_id].conditionMakers = [self._get_tool_instance('all')]
cmap[node.node_id].multiplicity = 1
fmap[node.node_id] = self._get_tool_instance('capacitychecked')
fmap[node.node_id].conditionMakers = [self._get_tool_instance('all')]
fmap[node.node_id].multiplicity = 1
for cn in node.children:
self._fill_conditions_map(cn, cmap)
self._fill_conditions_map(cn, cmap, fmap)
def _map_2_vec(self, amap):
......@@ -230,14 +311,17 @@ class ConditionsToolSetterFastReduction(object):
treeVec = self._map_2_vec(tree_map)
conditionsMap = {}
self._fill_conditions_map(tree, conditionsMap)
filterConditionsMap = {}
self._fill_conditions_map(tree, conditionsMap, filterConditionsMap)
conditionsVec = self._map_2_vec(conditionsMap)
filterConditionsVec = self._map_2_vec(filterConditionsMap)
# make a config tool and provide it with condition makers
config_tool = self._get_tool_instance('fastreduction')
config_tool.conditionMakers = conditionsVec
config_tool.filtConditionsMakers = filterConditionsVec
config_tool.treeVector = treeVec
nodestr = 'n%dp%d' % (tree.node_id, tree.parent_id)
helper_tool = self._get_tool_instance('helper', extra=nodestr)
helper_tool.HypoConfigurer = config_tool
......
......@@ -8,8 +8,6 @@ from TrigHLTJetHypo.ConditionsToolSetterFastReduction import (
ConditionsToolSetterFastReduction,
)
from TrigHLTJetHypo.ConditionsToolSetterHT import ConditionsToolSetterHT
from TrigHLTJetHypo.chainDict2jetLabel import chainDict2jetLabel
from TrigHLTJetHypo.ChainLabelParser import ChainLabelParser
......@@ -20,10 +18,10 @@ from TrigHLTJetHypo.NodeSplitterVisitor import NodeSplitterVisitor
from AthenaCommon.Logging import logging
log = logging.getLogger( 'TrigJetHypoToolConfig' )
def trigJetHypoToolHelperFromDict_(
def nodeTreeFromChainLabel(
chain_label, # simple([(260et,320eta490, leg000)])
chain_name, # HLT_j260_320eta490_L1J75_31ETA49
toolSetter=None):
toolSetter):
parser = ChainLabelParser(chain_label, debug=False)
......@@ -59,12 +57,23 @@ def trigJetHypoToolHelperFromDict_(
log.info('trigJetHypoToolFromDict chain_name %s', chain_name)
toolSetter.mod(tree)
tool = toolSetter.tool
return tree
log.debug(toolSetter.report())
return tool
def trigJetHypoToolHelperFromDict_(
chain_label, # simple([(260et,320eta490, leg000)])
chain_name, # HLT_j260_320eta490_L1J75_31ETA49
toolSetter):
nodeTreeFromChainLabel(
chain_label,
chain_name,
toolSetter)
tool = toolSetter.tool
log.debug(toolSetter.report())
return tool
def trigJetHypoToolHelperFromDict(chain_dict):
"""Produce a jet trigger hypo tool helper from a chainDict
......@@ -91,11 +100,7 @@ def trigJetHypoToolHelperFromDict(chain_dict):
chain_name = chain_dict['chainName']
toolSetter = None
if 'agg' in chain_name:
toolSetter=ConditionsToolSetterHT()
else:
toolSetter=ConditionsToolSetterFastReduction()
toolSetter = ConditionsToolSetterFastReduction()
return trigJetHypoToolHelperFromDict_(chain_label,
chain_name,
......
......@@ -297,9 +297,9 @@ def _make_agg_label(chain_parts, leg_label):
argvals['leg_label'] = leg_label
result = """
ht([(%(htlo).0fht, %(leg_label)s)
agg([(%(htlo).0fht, %(leg_label)s)
(%(etlo).0fet)
(%(etalo).0feta%(etahi).0f)
(%(etalo).0feta%(etahi).0f)
])""" % argvals
print (result)
return result
......
......@@ -29,11 +29,14 @@ class Node(object):
# filled in by a CondtionsTollSetter:
self.compound_condition_tools = []
# self.tool = None
# self.compound_condition_tools = []
# self.tree_top kludge carensure top level tools get chain name
# as Tool name
self.chainpartinds = []
# Condition objects may have filters
# eg HT may have an et filter. Filters are made up of conditions
# and are used to form jet subsets.
self.filter_conditions = []
self.filter_tool = None
self.tree_top = False
self.tool = None
......@@ -91,11 +94,17 @@ class Node(object):
for ca in self.conf_attrs:
s.append(indent + str(ca))
# this attribute added by flow network setter tool
s.append(indent + 'compound_condition_tools [%d]' % len(
self.compound_condition_tools))
s.append(indent + 'filter_conditions [%d]:' % (
len(self.filter_conditions),))
for fc in self.filter_conditions:
s.append(indent + str(fc))
s.append(indent + 'compoundConditionTools [%d]:' % len(
self.compound_condition_tools))
s.append(indent + 'filter_tool :' + str(self.filter_tool))
s.append(indent + 'AlgTool: %s' % str(self.tool))
s.append(indent + 'No of children: %d\n' % len(self.children))
return s
......
......@@ -11,7 +11,13 @@ from TriggerMenuMT.HLTMenuConfig.Menu.ChainDefInMenu import ChainProp
from TriggerMenuMT.HLTMenuConfig.Menu.DictFromChainName import dictFromChainName
from chainDict2jetLabel import chainDict2jetLabel
from TrigJetHypoToolConfig import trigJetHypoToolFromDict
from TrigJetHypoToolConfig import (trigJetHypoToolFromDict,
nodeTreeFromChainLabel)
from TrigHLTJetHypo.ConditionsToolSetterFastReduction import (
ConditionsToolSetterFastReduction,
)
def testChainDictMaker():
......@@ -43,7 +49,7 @@ def testChainDictMaker():
ChainProp(name='HLT_j0_aggSEP1000htSEP30etSEP0eta320_L1J20',
groups=SingleJetGroup),
# ChainProp(name='HLT_j70_j50 _0eta490_invm1000j50_dphi20_deta40_L1J20',
# l1SeedThresholds=['FSNOSEED']*2,
# groups=MultiJetGroup),
......@@ -70,6 +76,22 @@ if __name__ == '__main__':
print (chainDict2jetLabel(d[1]))
print ()
print ('\n node trees:\n')
for d in dicts:
print (d[0])
label = chainDict2jetLabel(d[1])
chain_name = d[1]['chainName']
toolSetter=ConditionsToolSetterFastReduction()
print (nodeTreeFromChainLabel(chain_name=d[0],
chain_label=label,
toolSetter=toolSetter).dump())
print ()
print ('\nMaking TrigJetHypoTool for each dictiomary\n')
for d in dicts:
print (d[0])
......
......@@ -34,13 +34,15 @@ def defaultParameters(parameter, default=''): # default if parameter unknown
'smchi': 'inf',
'jvtlo': '0',
'jvthi': 'inf',
'htlo' : '1000.',
'hthi' : 'inf',
}
if parameter.startswith('mom'):
parameter = 'momCuts'
if parameter not in defaults:
print ('defaultParameters: unknown parameter, tryurning default ',
print ('defaultParameters: unknown parameter, returning default ',
parameter)
return defaults.get(parameter, default)
......@@ -284,6 +286,47 @@ class TreeParameterExpander_simple(object):
return '%s: ' % self.__class__.__name__ + '\n'.join(self.msgs)
class TreeParameterExpander_agg(object):
"""Convert parameter string into duction holding low, high window
cut vals, as for the 'simple' scenario. Then place conditions
not in the agg list in the filters dict. These conditions wil be used
to select the subset of the jet collection to be presented to the agg
conditions."""
agg_conditions = ('ht',)
def __init__(self):
self.msgs = []
def mod(self, node):
simple_expander = TreeParameterExpander_simple()
simple_expander.mod(node)
# example conf_attrs:
# conf_attrs [3]:
# (defaultdict(<class 'dict'>,
# {'ht': {'min': '1000000.0', 'max': 'inf'}}), 1)
# (defaultdict(<class 'dict'>,
# {'et': {'min': '30000.0', 'max': 'inf'}}), 1)
# (defaultdict(<class 'dict'>,
# {'eta': {'min': '0.0', 'max': '3.2'}}), 1)
for ca in node.conf_attrs:
assert len(ca) == 2 # (dict, mult)
assert len(ca[0]) == 1 # one entry in dict
ca_keys = ca[0].keys()
cond_name = list(ca_keys)[0]
if cond_name not in self.agg_conditions:
node.filter_conditions.append(ca)
for fc in node.filter_conditions:
node.conf_attrs.remove(fc)
def report(self):
return '%s: ' % self.__class__.__name__ + '\n'.join(self.msgs)
class TreeParameterExpander_dijet(object):
"""Convert parameter string into tuples holding low, high window
cut vals. Specialistaion for the dijet scenario
......@@ -360,7 +403,7 @@ class TreeParameterExpander(object):
'z': TreeParameterExpander_null,
'root': TreeParameterExpander_null,
'simple': TreeParameterExpander_simple,
'ht': TreeParameterExpander_simple,
'agg': TreeParameterExpander_agg,
'dijet': TreeParameterExpander_dijet,
'qjet': TreeParameterExpander_simple,
'all': TreeParameterExpander_all,
......
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#include <algorithm>
#include "./ConditionFilter.h"
ConditionFilter::ConditionFilter(ConditionPtrs& conditions):
m_conditions(std::move(conditions)) {
}
struct FilterPred{
FilterPred(const ConditionPtr& cptr,
const std::unique_ptr<ITrigJetHypoInfoCollector>& collector):
m_cptr(cptr), m_collector(collector) {
}
bool operator() (pHypoJet pjet) {
auto hjv = HypoJetVector{pjet};
return m_cptr->isSatisfied(hjv, m_collector);
}
const ConditionPtr& m_cptr;
const std::unique_ptr<ITrigJetHypoInfoCollector>& m_collector;
};
HypoJetVector
ConditionFilter::filter (const HypoJetCIter& begin,
const HypoJetCIter& end,
const std::unique_ptr<ITrigJetHypoInfoCollector>& collector) const {
HypoJetVector in (begin, end);
auto new_end = in.end();
for (const auto& cptr : m_conditions) {
new_end = std::partition(in.begin(),
new_end,
FilterPred(cptr, collector));
}
return HypoJetVector(in.begin(), new_end);
}
std::string ConditionFilter::toString() const {
std::stringstream ss;
const void* address = static_cast<const void*>(this);
ss << "ConditionFilter: (" << address << ")\n"
<< "Conditions [" << m_conditions.size() << "]:\n";
for (const auto& c : m_conditions) {
ss << " " << c->toString() << "\n\n";
}
return ss.str();
}
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRIGHLTJETHYPO_CONDITIONFILTER_H
#define TRIGHLTJETHYPO_CONDITIONFILTER_H
#include "./CapacityCheckedConditionsDefs.h"
class ConditionFilter {
public:
ConditionFilter(ConditionPtrs&);
// find the subset of jets which satisfy a sequence of conditions
HypoJetVector filter (const HypoJetCIter& b,
const HypoJetCIter& e,
const std::unique_ptr<ITrigJetHypoInfoCollector>&
) const;
std::string toString() const;
private:
ConditionPtrs m_conditions;
};
#endif
......@@ -3,6 +3,7 @@
*/
#include "./FastReducer.h"
#include "./GrouperByCapacityFactory.h"
#include "./ITrigJetHypoInfoCollector.h"
#include <map>
......@@ -36,13 +37,14 @@ struct IndexVecComp{
};
FastReducer::FastReducer(const HypoJetGroupCIter& groups_b,
const HypoJetGroupCIter& groups_e,
FastReducer::FastReducer(const HypoJetCIter& jets_b,
const HypoJetCIter& jets_e,
const ConditionPtrs& conditions,
const ConditionFilters& filters,
const Tree& tree,
xAODJetCollector& jetCollector,
const Collector& collector):
m_conditions(conditions), m_tree(tree) {
m_conditions(conditions), m_conditionFilters(filters), m_tree(tree) {
// create an empty vector of indices of satisfying jet groups
// for each Condition.
......@@ -52,8 +54,8 @@ FastReducer::FastReducer(const HypoJetGroupCIter& groups_b,
}
if(!findInitialJetGroups(groups_b,
groups_e,
if(!findInitialJetGroups(jets_b,
jets_e,
collector)){
if(collector){
collector->collect("FastReducer early return",
......@@ -162,57 +164,57 @@ void FastReducer::collectLeafJets(xAODJetCollector& jetCollector,
}
bool FastReducer::findInitialJetGroups(const HypoJetGroupCIter& groups_b,
const HypoJetGroupCIter& groups_e,
bool FastReducer::findInitialJetGroups(const HypoJetCIter& jets_b,
const HypoJetCIter& jets_e,
const Collector& collector) {
/*
Will now test the incoming jet groups against the leaf conditions.
Will now test the incoming jets against the leaf conditions.
*/
std::size_t ijg{0};
auto leaves = m_tree.leaves();
for(auto iter = groups_b; iter != groups_e; ++iter){
auto jg = *iter;
if(jg.size() != 1){
collector->collect("FastReducer", "Initial jet group size != 1");
return false;
}
// if a jet group satisfies a condition, note the fact,
// and store it by index
bool jg_used{false};
// if a jet group satisfies a condition, note the fact,
// and store it by index
for(const auto& leaf: leaves){
auto& filter = m_conditionFilters[leaf];
auto filtered_jets = filter->filter(jets_b, jets_e, collector);
recordFiltering(leaf, jets_e-jets_b, filtered_jets.size(), collector);
auto cur_jg = m_jgIndAllocator(std::vector<std::size_t>{ijg});
for(const auto& leaf: leaves){
m_testedBy[leaf].insert(cur_jg);
auto grouper = grouperByCapacityFactory(m_conditions[leaf]->capacity(),
filtered_jets.begin(),
filtered_jets.end());
while(true){
auto ojg = grouper->next();
if (!ojg.has_value()) {break;}
auto jg = *ojg;
auto jg_ind = m_jgRegister.record(jg);
m_testedBy[leaf].insert(jg_ind);
if (m_conditions[leaf]->isSatisfied(jg, collector)){
jg_used= true;
if(collector){recordJetGroup(cur_jg, jg, collector);}
if(collector){recordJetGroup(jg_ind, jg, collector);}
// do the following for each satisfied condition ...
m_satisfiedBy[leaf].push_back(cur_jg);
m_satisfiedBy[leaf].push_back(jg_ind);
m_jg2elemjgs[jg_ind] = std::vector<std::size_t>{jg_ind};
m_indJetGroup.emplace(jg_ind, jg);
++ijg;
}
}
if(jg_used){
m_jg2elemjgs[cur_jg] = std::vector<std::size_t>{cur_jg};
m_indJetGroup.emplace(cur_jg, jg);
++ijg;
}
}
if(collector){
for(const auto& p : m_indJetGroup){
recordJetGroup(p.first, p.second, collector);
}
}
// check all leaf conditions are satisfied
for (const auto& i : leaves) {
if (!capacitySatisfied(i, collector)) {
......@@ -220,47 +222,9 @@ bool FastReducer::findInitialJetGroups(const HypoJetGroupCIter& groups_b,
}
}
/*
For the special but important case where all leaf nodes have
the root node as a parent, check that there are enough jets
to pass the hypo. This prevents doing a long calculation
to discover that the hypo will fail. For example, if the chain
requires 10j40, and there are 5 jets that pass the condition,
each condition will be satisfied by th 5 jets, and 5^10 combinations
will be attempted in th seach for a successful combination. As there
are only 5 jets involved, such a combination does not exist.
Such trees have a tree vector with all entries == 0.
This check cannot be applied in the general case. For example,
if the root condition requires 4 jets, and has three children,
two of which are leaf nodes, while the other is not, then the
check will fail the event as no jets have yet ben assigned to the
second child, while the full popagation through the tree may pass the
event.
A possible way to tighten the chck would be to forbid children to be
separated from thir parent by more than 1 generation.
*/
if (std::all_of(m_tree.cbegin(),
m_tree.cend(),
[](std::size_t i){return i == 0;})) {
if (m_conditions[0]->capacity() > ijg) {
if (collector){
collector->collect("FastReducer", "too few children. root capacity "
+ std::to_string(m_conditions[0]->capacity()) +
" no of children: " + std::to_string(ijg));
}
return false;
}
}
return true;
}
bool FastReducer::propagateJetGroups(const Collector& collector){
......@@ -395,18 +359,20 @@ bool FastReducer::propagate_(std::size_t child,
}
HypoJetVector jg;
for(const auto& i : elem_jgs){
jg.push_back(m_indJetGroup.at(i)[0]); // why [0]? assume elemental jg has size 1
}
// obtain an index for the new jet group.
auto cur_jg = m_jgIndAllocator(elem_jgs);
// auto cur_jg = m_jgIndAllocator(elem_jgs);
auto cur_jg = m_jgRegister.record(jg);
if(m_testedBy[par].find(cur_jg) != m_testedBy[par].end()){
next = jg_product.next(collector);
continue;
}
m_testedBy[par].insert(cur_jg);
for(const auto& i : elem_jgs){
jg.push_back(m_indJetGroup.at(i)[0]); // why [0]? assume elemental jg has size 1
}
if (m_conditions[par]->isSatisfied(jg, collector)){// par is a tree ind.
......@@ -526,6 +492,22 @@ void FastReducer::recordJetGroup(std::size_t ind,
collector->collect(ss0.str(), ss1.str());
}
void FastReducer::recordFiltering(std::size_t leaf_ind,
std::size_t n_injets,
int n_filteredjets,
const Collector& collector) const {
if(!collector) {return;}
std::stringstream ss0;
ss0 << "FastReducer filtering Condition index: " << leaf_ind;
std::stringstream ss1;
ss1 << "n jets. in: " << n_injets << " filtered: " << n_filteredjets << '\n';
collector->collect(ss0.str(), ss1.str());
}
bool FastReducer::pass() const { return m_pass; }
......
......@@ -11,7 +11,10 @@
#include "./JetGroupIndAllocator.h"
#include "./xAODJetCollector.h"
#include "./ITrigJetHypoInfoCollector.h"
#include "./JetGroupRegister.h"
#include "./ConditionFilter.h"
#include <string>
#include <map>
using TreeVec = std::vector<std::size_t>;
using IDJetGroup = std::map<std::size_t, HypoJetVector>;
......@@ -22,14 +25,16 @@ typedef std::unique_ptr<ITrigJetHypoInfoCollector> Collector;
*/
using JetGroupInd2ElemInds = std::map<int, std::vector<std::size_t>>;
using ConditionFilters = std::vector<std::unique_ptr<ConditionFilter>>;
class FastReducer {
public:
FastReducer(const HypoJetGroupCIter& groups_b,
const HypoJetGroupCIter& groups_e,
FastReducer(const HypoJetCIter& jets_b,
const HypoJetCIter& jets_e,
const ConditionPtrs& conditionObjects,
const ConditionFilters& conditionFilters,
const Tree& conditionsTree,
xAODJetCollector& jetCollector,
const Collector& collector);
......@@ -45,8 +50,12 @@ class FastReducer {
private:
// conditions owned by the matcher
const ConditionPtrs& m_conditions;
// conditionFilters owned by the matcher
const ConditionFilters& m_conditionFilters;
/** tree structure for Conditions objects.
The conditions tree gives relations among conditions (eg parent-child
and siblings-of)
......@@ -75,15 +84,16 @@ class FastReducer {
HypoJetVector m_passingJets;
JetGroupIndAllocator m_jgIndAllocator;
// JetGroupIndAllocator m_jgIndAllocator;
JetGroupRegister m_jgRegister;
/** set up the data structures for propagation. Propagation is the
act of combining jet groups satisfying children
in preparration for testing against parent conditions.
*/
bool findInitialJetGroups(const HypoJetGroupCIter& groups_b,
const HypoJetGroupCIter& groups_e,
bool findInitialJetGroups(const HypoJetCIter& jets_b,
const HypoJetCIter& jets_e,
const Collector& collector);
......@@ -102,6 +112,11 @@ class FastReducer {
const HypoJetVector& jg,
const Collector& collector) const;
void recordFiltering(std::size_t leaf_ind,
std::size_t n_inputjets,
int n_filteredjets,
const Collector& collector) const;
void collectLeafJets(xAODJetCollector& jetCollector,
const Collector& collector) const;
......
......@@ -10,9 +10,11 @@
#include <algorithm>
#include <sstream>
FastReductionMatcher::FastReductionMatcher(ConditionPtrs conditions,
FastReductionMatcher::FastReductionMatcher(ConditionPtrs& conditions,
ConditionFilters& filters,
const Tree& tree):
m_conditions(std::move(conditions)),
m_conditionFilters(std::move(filters)),
m_tree(tree){
for (const auto& il : m_tree.leaves()){
......@@ -20,12 +22,16 @@ FastReductionMatcher::FastReductionMatcher(ConditionPtrs conditions,
throw std::runtime_error("Tree leaf condition but not from ChainPart");
}
}
if (filters.size() != conditions.size()) {
throw std::runtime_error("Conditions and ConditionFilters sequence sizes differ");
}
}
std::optional<bool>
FastReductionMatcher::match(const HypoJetGroupCIter& groups_b,
const HypoJetGroupCIter& groups_e,
FastReductionMatcher::match(const HypoJetCIter& jets_b,
const HypoJetCIter& jets_e,
xAODJetCollector& jetCollector,
const std::unique_ptr<ITrigJetHypoInfoCollector>& collector,
bool) const {
......@@ -43,9 +49,10 @@ FastReductionMatcher::match(const HypoJetGroupCIter& groups_b,
*/
FastReducer reducer(groups_b,
groups_e,
FastReducer reducer(jets_b,
jets_e,
m_conditions,
m_conditionFilters,
m_tree,
jetCollector,
collector);
......@@ -68,5 +75,17 @@ std::string FastReductionMatcher::toString() const {
ss << sc <<": "<< c->toString() + '\n';
}
ss << "FastReductionMatcher ConditionFilters ["
<< m_conditionFilters.size() << "]: \n";
count = 0;
for(const auto& c : m_conditionFilters){
auto sc = std::to_string(count++);
sc.insert(sc.begin(), 3-sc.length(), ' ');
ss << sc <<": "<< c->toString() + '\n';
}
return ss.str();
}
......@@ -6,17 +6,21 @@
#define TRIGHLTJETHYPO_FASTREDUCTIONMATCHER_H
#include "./IGroupsMatcherMT.h"
#include "./IJetsMatcherMT.h"
#include "./CapacityCheckedConditionsDefs.h"
#include "./ConditionFilter.h"
#include "./Tree.h"
using TreeVec = std::vector<std::size_t>;
class ITrigJetHypoInfoCollector;
class FastReductionMatcher: public IGroupsMatcherMT {
using ConditionFilters = std::vector<std::unique_ptr<ConditionFilter>>;
class FastReductionMatcher: public IJetsMatcherMT {
public:
FastReductionMatcher(ConditionPtrs,
FastReductionMatcher(ConditionPtrs&,
ConditionFilters&,
const Tree&);
......@@ -30,8 +34,8 @@ class FastReductionMatcher: public IGroupsMatcherMT {
*/
virtual std::optional<bool>
match(const HypoJetGroupCIter& groups_b,
const HypoJetGroupCIter& groups_e,
match(const HypoJetCIter& jets_b,
const HypoJetCIter& jets_e,
xAODJetCollector&,
const std::unique_ptr<ITrigJetHypoInfoCollector>& collector,
bool
......@@ -42,7 +46,7 @@ class FastReductionMatcher: public IGroupsMatcherMT {
private:
ConditionPtrs m_conditions;
std::vector<std::unique_ptr<ConditionFilter>> m_conditionFilters;
/** tree structure for Conditions objects.
The conditions tree gives relations among conditions (eg parent-child
and siblings-of)
......
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#include "GrouperByCapacityFactory.h"
#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/AllJetsGrouper.h"
#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/SingleJetGrouper.h"
#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/CombinationsGrouper.h"
std::unique_ptr<IJetGrouper> grouperByCapacityFactory(unsigned int cap,
const HypoJetCIter& b,
const HypoJetCIter& e){
std::unique_ptr<IJetGrouper> pGrouper(nullptr);
if (cap == 0) {
throw std::runtime_error("groupByMultFactory - attempting ctrct grouper with mult == 0");
} else if (cap == 1) {
pGrouper.reset(new SingleJetGrouper(b, e));
} else if (cap == std::numeric_limits<int>::max()) {
pGrouper.reset(new AllJetsGrouper(b, e));
} else {
pGrouper.reset(new CombinationsGrouper(cap, b, e));
}
return pGrouper;
}
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRIGHLTJETHYPO_GROUPERBYCAPACITYFACTORY_H
#define TRIGHLTJETHYPO_GROUPERBYCAPACITYFACTORY_H
#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/IJetGrouper.h"
#include <memory>
std::unique_ptr<IJetGrouper> grouperByCapacityFactory(unsigned int capacity,
const HypoJetCIter& b,
const HypoJetCIter& e);
#endif
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#include "./HTConditionFastReduction.h"
#include "./ITrigJetHypoInfoCollector.h"
#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/HypoJetDefs.h"
#include <sstream>
#include <cmath>
#include <algorithm>
#include <numeric>
HTConditionFastReduction::HTConditionFastReduction(double ht_min,
double ht_max):
m_htMin(ht_min), m_htMax(ht_max) {
}
bool
HTConditionFastReduction::isSatisfied(const HypoJetVector& ips,
const std::unique_ptr<ITrigJetHypoInfoCollector>& collector) const {
auto htsum = std::accumulate(ips.begin(),
ips.end(),
0.0,
[](double sum, const pHypoJet& jp){
return sum + jp->et();});
bool pass = htsum > m_htMin;
if(collector){
std::stringstream ss0;
const void* address = static_cast<const void*>(this);
ss0 << "HTCondition: (" << address << ") Sum(et) "
<< htsum << " "
<< std::boolalpha << pass << " jet group: \n";
std::stringstream ss1;
for(const auto& ip : ips){
address = static_cast<const void*>(ip.get());
ss1 << " " << address << " " << ip->eta() << " e " << ip->e() << '\n';
}
ss1 << '\n';
collector -> collect(ss0.str(), ss1.str());
}
return pass;
}
std::string HTConditionFastReduction::toString() const {
std::stringstream ss;
ss << "HTConditionFastReduction: htMin: "
<< m_htMin;
ss <<'\n';
return ss.str();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment