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