42def trigJetHypoToolFromDict(flags, chain_dict):
43
44 from DecisionHandling.TrigCompositeUtils import isLegId, getLegIndexInt
45 chain_name = chain_dict['chainName']
46 chain_mg = chain_dict['monGroups']
47 jet_signature_identifiers = ['Jet:Jet', 'Bjet:Bjet', 'Tau:Ditau']
48
50
51
52
53
54
55
56
57
58
59 leg_id = getLegIndexInt(chain_name)
60 chain_sig_w_sub_sig = [f'{sig}:{subsig}' for sig, subsigs in chain_dict['sigDicts'].items() for subsig in subsigs]
61
62 if not any(signature in chain_sig_w_sub_sig for signature in jet_signature_identifiers):
63 raise Exception("[trigJetHypoToolFromDict] No {} in {} for chain {}. Please update this list of jet signatures.".format(tuple(jet_signature_identifiers),tuple(chain_sig_w_sub_sig),chain_name))
64
65
66
67 status = 0
68 for entry in chain_sig_w_sub_sig:
69 if status == 0 and entry in jet_signature_identifiers:
70 status = 1
71 elif status == 1 and entry not in jet_signature_identifiers:
72 status = 2
73 elif status == 2 and entry in jet_signature_identifiers:
74 raise Exception("[trigJetHypoToolFromDict] All {} legs should be contiguous in the signatures list, modify the ordering of the chain {}. Signatures:{}.".format(tuple(jet_signature_identifiers),chain_name, tuple(chain_sig_w_sub_sig)))
75
76
77
78 if not any(signature in chain_sig_w_sub_sig[leg_id] for signature in jet_signature_identifiers):
79 raise Exception("[trigJetHypoToolFromDict] For this code to work for chain {}, the signature at index {} must be one of {}. But the signature list is: {}".format(chain_name,leg_id,tuple(jet_signature_identifiers),tuple(chain_sig_w_sub_sig)))
80
81
82 first_leg_index = 999
83 for signature in jet_signature_identifiers:
84 if signature in chain_sig_w_sub_sig:
85 first_leg_index =
min(first_leg_index, chain_sig_w_sub_sig.index(signature))
86
87 if leg_id > first_leg_index:
88 logger.debug("Not returning a HypoTool for %s as this is not the first leg "
89 "with any of %s (leg signatures are %s)",
90 chain_name, tuple(jet_signature_identifiers), tuple(chain_sig_w_sub_sig))
91 raise NoHypoToolCreated("No HypoTool created for %s" % chain_name)
92
93 logger.debug("Returning a HypoTool for %s as this is the first leg with any of %s (leg signatures are %s)",
94 chain_name, tuple(jet_signature_identifiers), tuple(chain_dict['signatures']))
95
96 hypo_tool = hypotool_from_chaindict(chain_dict, debug)
97
98
99 if any('jetMon:online' in group for group in chain_mg):
100 cpl = chain_dict["chainParts"]
101 histFlags = []
102 for cp in cpl:
103 histFlags += [ cp['recoAlg'] ] + [ cp['hypoScenario']]
104 hypo_tool.MonTool = TrigJetHypoToolMonitoring(flags, "HLTJetHypo/"+chain_name, histFlags)
105 return hypo_tool
106
107