|
def | __init__ (self, name, SequenceGens=None, chainDicts=None, comboHypoCfg=ComboHypoCfg, comboToolConfs=None, isEmpty=False, createsGhostLegs=False) |
|
def | createSequences (self) |
|
def | relabelLegIdsForJets (self) |
|
def | setChainPartIndices (self) |
|
def | getLegIds (self) |
|
def | addComboHypoTools (self, tool) |
|
def | getComboHypoFncName (self) |
|
def | makeCombo (self) |
|
def | createComboHypoTools (self, flags, chainName) |
|
def | getChainLegs (self) |
|
def | getChainNames (self) |
|
def | __repr__ (self) |
|
Class to describe one step of a chain; if multiplicity is greater than 1, the step is combo/combined. Set one multiplicity value per sequence
Definition at line 613 of file MenuComponents.py.
◆ __init__()
def MenuComponents.ChainStep.__init__ |
( |
|
self, |
|
|
|
name, |
|
|
|
SequenceGens = None , |
|
|
|
chainDicts = None , |
|
|
|
comboHypoCfg = ComboHypoCfg , |
|
|
|
comboToolConfs = None , |
|
|
|
isEmpty = False , |
|
|
|
createsGhostLegs = False |
|
) |
| |
Definition at line 616 of file MenuComponents.py.
616 def __init__(self, name, SequenceGens = None, chainDicts = None, comboHypoCfg = ComboHypoCfg , comboToolConfs = None, isEmpty = False, createsGhostLegs = False):
619 if SequenceGens
is None: SequenceGens = []
620 if comboToolConfs
is None: comboToolConfs = []
622 assert chainDicts
is not None,
"Error building a ChainStep without a chainDicts"
626 self.sequenceGens = SequenceGens
627 self.comboHypoCfg = comboHypoCfg
628 self.comboToolConfs =
list(comboToolConfs)
629 self.stepDicts = chainDicts
631 self.isEmpty = isEmpty
633 self.multiplicity = []
635 self.multiplicity = [1
for seq
in self.sequenceGens]
636 log.debug(
"Building step %s for chain %s: len=%d multiplicty=%s", name, chainDicts[0][
'chainName'], len(chainDicts),
' '.
join(map(str,[mult
for mult
in self.multiplicity])))
638 if len(chainDicts) != len(self.multiplicity)
and 'Jet' not in chainDicts[0][
'signatures']:
639 log.error(
"[ChainStep] SequenceGens: %s",self.sequenceGens)
640 log.error(
"[ChainStep] chainDicts: %s",chainDicts)
641 log.error(
"[ChainStep] multiplicity: %s",self.multiplicity)
642 raise RuntimeError(
"[ChainStep] Tried to configure a ChainStep %s with %i multiplicity and %i dictionaries. These lists must have the same size" % (name, len(self.multiplicity), len(chainDicts)) )
645 for iseq, seq
in enumerate(self.sequenceGens):
646 if not isinstance(seq, functools.partial):
647 log.error(
"[ChainStep] %s SequenceGens verification failed, sequence %d is not partial function, likely ChainBase.getStep function was not used", self.name, iseq)
648 log.error(
"[ChainStep] It rather seems to be of type %s trying to print it",
type(seq))
649 raise RuntimeError(
"Sequence is not packaged in a tuple, see error message above" )
651 self.onlyJets =
False
653 if len(chainDicts) > 0
and 'signature' in chainDicts[0]:
654 leg_signatures = [step[
'signature']
for step
in chainDicts
if step[
'signature'] !=
'Bjet']
655 if (len(self.multiplicity) > 0
and leg_signatures.count(
'Jet') == 1)
and (len(
set(leg_signatures)) > 1
and chainDicts[0][
'signatures'].
count(
'Jet') > 1)
and (len(leg_signatures) != 2
or leg_signatures.count(
'MET') == 0):
656 index_jetLeg = leg_signatures.index(
'Jet')
657 self.multiplicity[index_jetLeg:index_jetLeg] = [1] * (len(chainDicts[0][
'chainMultiplicities']) - len(self.multiplicity))
658 sig_set =
set([step[
'signature']
for step
in chainDicts])
659 if len(sig_set) == 1
and (
'Jet' in sig_set
or 'Bjet' in sig_set):
661 if len(sig_set) == 2
and (
'Jet' in sig_set
and 'Bjet' in sig_set):
668 self.setChainPartIndices()
669 self.legIds = self.getLegIds()
◆ __repr__()
def MenuComponents.ChainStep.__repr__ |
( |
|
self | ) |
|
Definition at line 797 of file MenuComponents.py.
798 if len(self.sequenceGens) == 0:
799 return "\n--- ChainStep %s ---\n is Empty, ChainDict = %s "%(self.name,
' '.
join(map(str, [dic[
'chainName']
for dic
in self.stepDicts])) )
801 repr_string=
"\n--- ChainStep %s ---\n , multiplicity = %s ChainDict = %s \n + MenuSequenceGens = %s "%\
802 (self.name,
' '.
join(map(str,[mult
for mult
in self.multiplicity])),
803 ' '.
join(map(str, [dic[
'chainName']
for dic
in self.stepDicts])),
804 ' '.
join(map(str, [seq.func.__name__
for seq
in self.sequenceGens]) ))
806 if self.combo
is not None:
807 repr_string +=
"\n + ComboHypo = %s" % self.combo.Alg.name
808 if len(self.comboToolConfs)>0:
809 repr_string +=
", ComboHypoTools = %s" %(
' '.
join(map(str, [tool.__name__
for tool
in self.comboToolConfs])))
◆ addComboHypoTools()
def MenuComponents.ChainStep.addComboHypoTools |
( |
|
self, |
|
|
|
tool |
|
) |
| |
◆ createComboHypoTools()
def MenuComponents.ChainStep.createComboHypoTools |
( |
|
self, |
|
|
|
flags, |
|
|
|
chainName |
|
) |
| |
Definition at line 783 of file MenuComponents.py.
783 def createComboHypoTools(self, flags, chainName):
784 chainDict = HLTMenuConfig.getChainDictFromChainName(chainName)
785 self.combo.createComboHypoTools(flags, chainDict, self.comboToolConfs)
◆ createSequences()
def MenuComponents.ChainStep.createSequences |
( |
|
self | ) |
|
creation of this step sequences with instantiation of the CAs
Definition at line 672 of file MenuComponents.py.
672 def createSequences(self):
673 """ creation of this step sequences with instantiation of the CAs"""
674 log.debug(
"creating sequences for step %s", self.name)
675 for seq
in self.sequenceGens:
◆ getChainLegs()
def MenuComponents.ChainStep.getChainLegs |
( |
|
self | ) |
|
This is extrapolating the chain legs from the step dictionaries
Definition at line 787 of file MenuComponents.py.
787 def getChainLegs(self):
788 """ This is extrapolating the chain legs from the step dictionaries"""
789 legs = [part[
'chainName']
for part
in self.stepDicts]
◆ getChainNames()
def MenuComponents.ChainStep.getChainNames |
( |
|
self | ) |
|
Definition at line 792 of file MenuComponents.py.
792 def getChainNames(self):
793 if self.combo
is not None:
795 return self.getChainLegs()
◆ getComboHypoFncName()
def MenuComponents.ChainStep.getComboHypoFncName |
( |
|
self | ) |
|
Definition at line 756 of file MenuComponents.py.
756 def getComboHypoFncName(self):
757 return self.comboHypoCfg.func.__name__
if isinstance(self.comboHypoCfg, functools.partial)
else self.comboHypoCfg
◆ getLegIds()
def MenuComponents.ChainStep.getLegIds |
( |
|
self | ) |
|
get the gelId from the step dictionary for multi-leg chains
Definition at line 736 of file MenuComponents.py.
737 """ get the gelId from the step dictionary for multi-leg chains"""
738 if len(self.multiplicity) <= 1:
741 for istep,step_dict
in enumerate(self.stepDicts):
742 if step_dict[
'chainName'][0:3] !=
'leg':
746 log.error(
"[getLegIds] chain %s has multiplicities %s but no legs? ",step_dict[
'chainName'], self.multiplicity)
747 raise Exception(
"[getLegIds] cannot extract leg IDs, exiting.")
749 leg_ids += [
int(step_dict[
'chainName'][3:6])]
◆ makeCombo()
def MenuComponents.ChainStep.makeCombo |
( |
|
self | ) |
|
Configure the Combo Hypo Alg and generate the corresponding function, without instantiation which is done in createSequences()
Definition at line 759 of file MenuComponents.py.
760 """ Configure the Combo Hypo Alg and generate the corresponding function, without instantiation which is done in createSequences() """
762 if self.isEmpty
or self.comboHypoCfg
is None:
764 comboNameFromStep = CFNaming.comboHypoName(self.name)
765 funcName = self.getComboHypoFncName()
766 key =
hash((comboNameFromStep, funcName))
767 if key
not in _ComboHypoPool:
768 tmpCombo = ComboHypoNode(comboNameFromStep, self.comboHypoCfg)
771 if comboNameFromStep+
"Node" != tmpCombo.name:
772 log.info(
"WARNING Created ComboHypo with name %s, expected from the step is instead %s. This is accepted only for allowed custom ComboHypos", tmpCombo.name, comboNameFromStep)
773 key =
hash((tmpCombo.name, funcName))
774 _ComboHypoPool[key] = tmpCombo
775 self.combo = _ComboHypoPool[key]
776 log.debug(
"Created combo %s with name %s, step comboName %s, key %s", funcName, self.combo.name, comboNameFromStep,key)
◆ relabelLegIdsForJets()
def MenuComponents.ChainStep.relabelLegIdsForJets |
( |
|
self | ) |
|
Definition at line 678 of file MenuComponents.py.
678 def relabelLegIdsForJets(self):
682 for step_dict
in self.stepDicts:
683 if 'Jet' in step_dict[
'signatures']
or 'Bjet' in step_dict[
'signatures']:
685 leg_counter += [len(step_dict[
'chainParts'])]
686 elif len(step_dict[
'chainParts']) > 1:
687 log.error(
"[relabelLegIdsForJets] this should only happen for jet chains, but the signatures are %s",step_dict[
'signatures'])
688 raise Exception(
"[relabelLegIdsForJets] leg labelling is probably wrong...")
692 self.onlyJets =
False
693 if len(leg_counter) == len(self.multiplicity):
696 log.debug(
"[relabelLegIdsForJets] leg_counter: %s , onlyjets: %s, multiplicity: %s...",leg_counter, self.onlyJets, self.multiplicity)
698 if not has_jets
or len(leg_counter) == len(self.multiplicity):
701 if len(leg_counter) == 1
or (len(
set(leg_counter)) == 1
and leg_counter[0] == 1):
704 elif len(
set(leg_counter[:-1])) == 1
and leg_counter[0] == 1:
709 for i,nLegParts
in enumerate(leg_counter):
710 oldLegName = self.stepDicts[i][
'chainName']
711 if re.search(
'^leg[0-9]{3}_',oldLegName):
712 oldLegName = oldLegName[7:]
714 log.error(
"[relabelLegIdsForJets] you told me to relabel the legs for %s",self.stepDicts)
715 raise Exception(
"[relabelLegIdsForJets] you told me to relabel the legs but this leg doesn't have a legXXX_ name!")
716 self.stepDicts[i][
'chainName'] =
legName(oldLegName,nLegs)
◆ setChainPartIndices()
def MenuComponents.ChainStep.setChainPartIndices |
( |
|
self | ) |
|
Definition at line 721 of file MenuComponents.py.
721 def setChainPartIndices(self):
723 lists_of_chainPartNames = []
724 for step_dict
in self.stepDicts:
725 if len(lists_of_chainPartNames) == 0:
726 lists_of_chainPartNames += [[cp[
'chainPartName']
for cp
in step_dict[
'chainParts']]]
728 new_list_of_chainPartNames = [cp[
'chainPartName']
for cp
in step_dict[
'chainParts']]
729 if new_list_of_chainPartNames == lists_of_chainPartNames[-1]:
730 leg_counter -= len(new_list_of_chainPartNames)
731 for chainPart
in step_dict[
'chainParts']:
732 chainPart[
'chainPartIndex'] = leg_counter
◆ combo
MenuComponents.ChainStep.combo |
◆ comboHypoCfg
MenuComponents.ChainStep.comboHypoCfg |
◆ comboToolConfs
MenuComponents.ChainStep.comboToolConfs |
◆ isEmpty
MenuComponents.ChainStep.isEmpty |
◆ legIds
MenuComponents.ChainStep.legIds |
◆ multiplicity
MenuComponents.ChainStep.multiplicity |
◆ name
MenuComponents.ChainStep.name |
◆ onlyJets
MenuComponents.ChainStep.onlyJets |
◆ sequenceGens
MenuComponents.ChainStep.sequenceGens |
◆ sequences
MenuComponents.ChainStep.sequences |
◆ stepDicts
MenuComponents.ChainStep.stepDicts |
The documentation for this class was generated from the following file:
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.