6def trigTauRecMergedPrecisionMVACfg(flags, name, tau_ids=None, input_rois='', input_tracks='', output_name=None):
7 '''
8 Reconstruct the precision TauJet, from the first-step CaloMVA TauJet and precision-refitted tracks.
9
10 :param flags: Config flags.
11 :param name: Suffix for the main TrigTauRecMerged algorithm name.
12 :param tau_ids: List of inference algorithms to execute.
13 The specific configuration will be loaded from the matching ConfigFlags (Trigger.Offline.Tau.<alg-name>)
14 Currently, only the `DeepSet` and `RNNLLP` algorithms will use the LVNN inference setup (json config files);
15 all other ID algorithms will use the ONNX inference setup by default.
16 If the algorithm name (`name` input variable) is `MVA`, `LLP` or `LRT`, and `tau_ids=['DeepSet', 'MesonCuts']` or `tau_ids=['RNNLLP']`,
17 then the default TauJet RNN score and WP `isTau` decorators will be used (for the legacy
18 `mediumRNN/tightRNN_tracktwoMVA/tracktwoLLP/trackLRT` triggers).
19 Otherwise, all scores and WPs will be stored as `{tau_id}_Score`, `{tau_id}_ScoreSigTrans`, and `{tau_id}_{wp_name}`.
20 :param input_rois: RoIs container, where the reconstruction will be run.
21 :param input_tracks: TrackParticle container, with the refitted precision tracks.
22 :param output_name: Suffix for the output TauJet and TauTrack collections. If `None`, `name` will be used.
23
24 :return: CA with the TauJet Precision reconstruction sequence.
25 '''
26
27
28 if output_name is None: output_name = name
29 from TrigEDMConfig.TriggerEDM import recordable
30 trigTauJetOutputContainer = recordable(f'HLT_TrigTauRecMerged_{output_name}')
31 trigTauTrackOutputContainer = recordable(f'HLT_tautrack_{output_name}')
32
33
34 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
35 acc = ComponentAccumulator()
36
37
38
39 vftools = []
40 tools_beforetf = []
41 tftools = []
42 tools = []
43 vvtools = []
44 idtools = []
45
46
47 from TrigTauRec.TrigTauRecToolsConfig import trigTauVertexFinderCfg, trigTauTrackFinderCfg, tauVertexVariablesCfg
48 from AthenaConfiguration.ComponentFactory import CompFactory
49
50
51 vftools.append(acc.popToolsAndMerge(trigTauVertexFinderCfg(flags, name='TrigTau_TauVertexFinder')))
52
53
54 tools_beforetf.append(CompFactory.TauAxisSetter(name='TrigTau_TauAxis', VertexCorrection=False))
55
56
57 tftools.append(acc.popToolsAndMerge(trigTauTrackFinderCfg(flags, name='TrigTauTightDZ_TauTrackFinder', TrackParticlesContainer=input_tracks)))
58
59
60 tools.append(CompFactory.TauClusterFinder(name='TrigTau_TauClusterFinder', UseOriginalCluster=False))
61 tools.append(CompFactory.TauVertexedClusterDecorator(name='TrigTau_TauVertexedClusterDecorator', SeedJet=''))
62
63
64 tools.append(CompFactory.TauCellVariables(name='TrigTau_CellVariables', VertexCorrection=False))
65
66
67 tools.append(CompFactory.MvaTESVariableDecorator(name='TrigTau_MvaTESVariableDecorator', Key_vertexInputContainer='', EventShapeKey='', VertexCorrection=False))
68 acc.addPublicTool(tools[-1])
69 tools.append(CompFactory.MvaTESEvaluator(name='TrigTau_MvaTESEvaluator', WeightFileName=flags.Trigger.Offline.Tau.MvaTESConfig))
70 acc.addPublicTool(tools[-1])
71
72
73 vvtools.append(acc.popToolsAndMerge(tauVertexVariablesCfg(flags, name='TrigTau_TauVertexVariables')))
74
75
76 idtools.append(CompFactory.TauCommonCalcVars(name='TrigTau_TauCommonCalcVars'))
77
78
79 idtools.append(CompFactory.TauSubstructureVariables(name='TrigTau_TauSubstructure', VertexCorrection=False))
80
81
82
83
84
85
86
87
88 tau_ids = sorted(list(
set(tau_ids
if tau_ids
else []) - {
'perf',
'idperf',
'MesonCuts'}))
89
90 from TriggerMenuMT.HLT.Tau.TauConfigurationTools import getTauIDScoreVariables
91 id_score_monitoring = {}
92
93
94 used_builtin_rnnscore = False
95
96 for tau_id in tau_ids:
97
98 try: id_flags = getattr(flags.Trigger.Offline.Tau, tau_id)
99 except NameError: raise ValueError(f'Missing TauID ConfigFlags: Trigger.Offline.Tau.{tau_id}')
100
101
102 is_onnx = hasattr(id_flags, 'ONNXConfig')
103
104 if is_onnx:
105 log.debug('Configuring TrigTauRecMerged with the ONNX Tau ID score inference: %s', tau_id)
106
107 from TrigTauRec.TrigTauRecToolsConfig import trigTauJetONNXEvaluatorCfg, trigTauWPDecoratorCfg
108
109
110 idtools.append(acc.popToolsAndMerge(trigTauJetONNXEvaluatorCfg(flags, tau_id=tau_id)))
111 acc.addPublicTool(idtools[-1])
112
113
114 idtools.append(acc.popToolsAndMerge(trigTauWPDecoratorCfg(flags, tau_id=tau_id, precision_seq_name=name, tauContainerName=trigTauJetOutputContainer)))
115 acc.addPublicTool(idtools[-1])
116
117
118 else:
119 log.debug('Configuring TrigTauRecMerged with the LVNN Tau ID score inference: %s', tau_id)
120
121 from TriggerMenuMT.HLT.Tau.TauConfigurationTools import useBuiltInTauJetRNNScore
122
123
124
125 use_builtin_rnnscore = useBuiltInTauJetRNNScore(tau_id, precision_sequence=name)
126 if use_builtin_rnnscore:
127 if used_builtin_rnnscore:
128 log.error('Cannot store more than one TauID score in the built-in TauJet RNN score variables')
129 raise ValueError()
130 used_builtin_rnnscore = True
131
132
133 from TrigTauRec.TrigTauRecToolsConfig import trigTauJetLVNNEvaluatorCfg
134 idtools.append(acc.popToolsAndMerge(trigTauJetLVNNEvaluatorCfg(flags, tau_id=tau_id, use_taujet_rnnscore=use_builtin_rnnscore)))
135 acc.addPublicTool(idtools[-1])
136
137
138 if use_builtin_rnnscore:
139 from TrigTauRec.TrigTauRecToolsConfig import trigTauWPDecoratorRNNCfg
140 idtools.append(acc.popToolsAndMerge(trigTauWPDecoratorRNNCfg(flags, tau_id=tau_id, precision_seq_name=name)))
141 acc.addPublicTool(idtools[-1])
142 else:
143 from TrigTauRec.TrigTauRecToolsConfig import trigTauWPDecoratorCfg
144 idtools.append(acc.popToolsAndMerge(trigTauWPDecoratorCfg(flags, tau_id=tau_id, precision_seq_name=name, tauContainerName=trigTauJetOutputContainer)))
145 acc.addPublicTool(idtools[-1])
146
147 id_score_monitoring[tau_id] = getTauIDScoreVariables(tau_id, precision_sequence=name)
148
149
150
151 for tool in vftools + tools_beforetf + tftools + tools + vvtools + idtools:
152 tool.inTrigger = True
153 tool.calibFolder = flags.Trigger.Offline.Tau.tauRecToolsCVMFSPath
154
155
156 from TrigTauRec.TrigTauRecMonitoring import tauMonitoringPrecision
157 acc.addEventAlgo(CompFactory.TrigTauRecMerged(
158 name=f'TrigTauRecMerged_Precision_{name}',
159 VertexFinderTools=vftools,
160 CommonToolsBeforeTF=tools_beforetf,
161 TrackFinderTools=tftools,
162 CommonTools=tools,
163 VertexVarsTools=vvtools,
164 IDTools=idtools,
165 MonTool=tauMonitoringPrecision(flags, RoI_name='tauLRT' if 'LRT' in name else 'tauIso', tau_ids=id_score_monitoring.keys(), alg_name=name),
166 MonitoredIDScores=id_score_monitoring,
167 InputRoIs=input_rois,
168 InputVertexContainer=flags.Tracking.ActiveConfig.vertex,
169 InputTauTrackContainer='HLT_tautrack_dummy',
170 InputTauJetContainer='HLT_TrigTauRecMerged_CaloMVAOnly',
171 OutputTauTrackContainer=trigTauTrackOutputContainer,
172 OutputTauJetContainer=trigTauJetOutputContainer,
173 ))
174
175 return acc
176
177