20def trigJetHypoToolFromDict(flags, chain_dict):
21
22 from DecisionHandling.TrigCompositeUtils import isLegId, getLegIndexInt
23 chain_name = chain_dict['chainName']
24 chain_mg = chain_dict['monGroups']
25 jet_signature_identifiers = ['Jet:Jet', 'Bjet:Bjet', 'Tau:Ditau']
26
28
29
30
31
32
33
34
35
36
37 leg_id = getLegIndexInt(chain_name)
38 chain_sig_w_sub_sig = [f'{sig}:{subsig}' for sig, subsigs in chain_dict['sigDicts'].items() for subsig in subsigs]
39
40 if not any(signature in chain_sig_w_sub_sig for signature in jet_signature_identifiers):
41 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))
42
43
44
45 status = 0
46 for entry in chain_sig_w_sub_sig:
47 if status == 0 and entry in jet_signature_identifiers:
48 status = 1
49 elif status == 1 and entry not in jet_signature_identifiers:
50 status = 2
51 elif status == 2 and entry in jet_signature_identifiers:
52 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)))
53
54
55
56 if not any(signature in chain_sig_w_sub_sig[leg_id] for signature in jet_signature_identifiers):
57 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)))
58
59
60 first_leg_index = 999
61 for signature in jet_signature_identifiers:
62 if signature in chain_sig_w_sub_sig:
63 first_leg_index =
min(first_leg_index, chain_sig_w_sub_sig.index(signature))
64
65 if leg_id > first_leg_index:
66 logger.debug("Not returning a HypoTool for %s as this is not the first leg "
67 "with any of %s (leg signatures are %s)",
68 chain_name, tuple(jet_signature_identifiers), tuple(chain_sig_w_sub_sig))
69 raise NoHypoToolCreated("No HypoTool created for %s" % chain_name)
70
71 logger.debug("Returning a HypoTool for %s as this is the first leg with any of %s (leg signatures are %s)",
72 chain_name, tuple(jet_signature_identifiers), tuple(chain_dict['signatures']))
73
74 hypo_tool = hypotool_from_chaindict(chain_dict, debug)
75
76
77 if any('jetMon:online' in group for group in chain_mg):
78 cpl = chain_dict["chainParts"]
79 histFlags = []
80 for cp in cpl:
81 histFlags += [ cp['recoAlg'] ] + [ cp['hypoScenario']]
82 hypo_tool.MonTool = TrigJetHypoToolMonitoring(flags, "HLTJetHypo/"+chain_name, histFlags)
83 return hypo_tool
84
85