ATLAS Offline Software
Loading...
Searching...
No Matches
JetEfficiencyMonitorAlgorithm.py
Go to the documentation of this file.
2# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3#
5 '''Function to configure LVL1 JetEfficiency algorithm in the monitoring system.'''
6
7 # get the component factory - used for getting the algorithms
8 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
9 from AthenaConfiguration.ComponentFactory import CompFactory
10 from TrigConfigSvc.TriggerConfigAccess import getL1MenuAccess
11 result = ComponentAccumulator()
12 l1menu = getL1MenuAccess(flags)
13
14
15 from AthenaConfiguration.Enums import Format
16
18 if flags.Input.Format is Format.POOL and not flags.Input.isMC and not any(["AOD" in a for a in flags.Input.ProcessingTags]):
19 from JetRecConfig.JetRecConfig import JetRecCfg
20 from JetRecConfig.StandardSmallRJets import AntiKt4EMPFlow
21 result.merge( JetRecCfg(flags,AntiKt4EMPFlow) )
22
23 from eflowRec.PFCfg import PFGlobalFlowElementLinkingCfg
24 if flags.DQ.Environment == "AOD":
25 result.merge(PFGlobalFlowElementLinkingCfg(flags, useMuonTopoClusters=True))
26 else:
27 result.merge(PFGlobalFlowElementLinkingCfg(flags))
28 from eflowRec.PFCfg import PFGlobalFlowElementLinkingCfg
29 result.merge(PFGlobalFlowElementLinkingCfg(flags))
30 from METReconstruction.METAssociatorCfg import METAssociatorCfg
31 result.merge(METAssociatorCfg(flags, 'AntiKt4EMPFlow'))
32 from METUtilities.METMakerConfig import METMakerCfg
33 result.merge(METMakerCfg(flags, 'AntiKt4EMPFlow'))
34
35
36 # make the athena monitoring helper
37 from TrigT1CaloMonitoring.LVL1CaloMonitoringConfig import L1CaloMonitorCfgHelper
38 helper = L1CaloMonitorCfgHelper(flags,CompFactory.JetEfficiencyMonitorAlgorithm,'JetEfficiencyMonAlg')
39 groupName = 'JetEfficiencyMonitor' # the monitoring group name is also used for the package name
40 JetEfficiencyMonAlg = helper.alg
41 JetEfficiencyMonAlg.PackageName = groupName
42
43
44
48
49 # We can choose if we want to use pass before prescale, or not when defining our trigger efficiency
50 # generally only want to use pass before prescale when considering the efficiency of a trigger for
51 # internal evaluation of how triggers are behaving
52 # the prescaling is an important feature of real utility if a
53 passedb4Prescale = True
54 JetEfficiencyMonAlg.PassedBeforePrescale = passedb4Prescale
55
56
60
61 #define the various reference triggers
62 hltRandom_reference_triggers = ['HLT_j0_perf_L1RD0_FILLED', 'HLT_j0_perf_pf_ftf_L1RD0_FILLED']
63 JetEfficiencyMonAlg.HLTRandomReferenceTriggers = hltRandom_reference_triggers
64
65 muon_reference_triggers = ["L1_MU14FCH", "L1_MU18VFCH", "L1_2MU8F", "L1_MU8VF_2MU5VF", "L1_3MU3VF", "L1_MU5VF_3MU3VF", "L1_4MU3V", "L1_2MU5VF_3MU3V"]
66 JetEfficiencyMonAlg.MuonReferenceTriggers = muon_reference_triggers
67
68 JetEfficiencyMonAlg.BootstrapReferenceTrigger='L1_J15'
69
70 trigPath = 'Developer/JetEfficiency/'
71 ExpertTrigPath = 'Expert/Efficiency/'
72 distributionPath = 'Distributions/'
73 noRefPath = 'NoReferenceTrigger/'
74 muonRefPath = 'MuonReferenceTrigger/'
75 randomRefPath = 'RandomHLTReferenceTrigger/'
76 bsRefPath = 'BootstrapReferenceTrigger/'
77 GeV = 1000
78
79 # add monitoring algorithm to group, with group name and main directory
80 gfex_SR_triggers = ['L1_gJ20p0ETA25', 'L1_gJ50p0ETA25', 'L1_gJ100p0ETA25', 'L1_gJ400p0ETA25']
81 gfex_LR_triggers = ['L1_gLJ80p0ETA25', 'L1_gLJ100p0ETA25', 'L1_gLJ140p0ETA25', 'L1_gLJ160p0ETA25']
82
83 jfex_SR_triggers = ['L1_jJ30','L1_jJ40','L1_jJ50', 'L1_jJ60', 'L1_jJ80','L1_jJ90', 'L1_jJ125','L1_jJ140','L1_jJ160', 'L1_jJ180']
84 jfex_LR_triggers = ['L1_SC175-SCjJ10']
85
86 all_SR_triggers = gfex_SR_triggers + jfex_SR_triggers
87 all_LR_triggers = gfex_LR_triggers + jfex_LR_triggers
88
89 # if the trigger isnt included in the menu, then we dont actually want to fill anything into the histograms (it looks weird)
90 JetEfficiencyMonAlg.SmallRadiusJetTriggers_phase1 = [trigger for trigger in all_SR_triggers if trigger in l1menu]
91 JetEfficiencyMonAlg.LargeRadiusJetTriggers_phase1 = [trigger for trigger in all_LR_triggers if trigger in l1menu]
92 # if a trigger isnt in the menu, but its a gfex trigger so we can emulate the efficiemcy using the gFEX TOBs
93 JetEfficiencyMonAlg.SmallRadiusJetTriggers_gFEX = [trigger for trigger in gfex_SR_triggers if trigger not in l1menu]
94 JetEfficiencyMonAlg.LargeRadiusJetTriggers_gFEX = [trigger for trigger in gfex_LR_triggers if trigger not in l1menu]
95
96 # if there are no gFEX triggers in our list that aren't present in the menu, then we don't need to even look at them, so lets just not open them
97 if len(JetEfficiencyMonAlg.SmallRadiusJetTriggers_gFEX ) == 0: JetEfficiencyMonAlg.mygFexSRJetRoIContainer = ""
98 if len(JetEfficiencyMonAlg.LargeRadiusJetTriggers_gFEX ) == 0: JetEfficiencyMonAlg.mygFexLRJetRoIContainer = ""
99
100
101 reference_paths = {"Muon" : muonRefPath, "RandomHLT": randomRefPath, "No": noRefPath, "Bootstrap": bsRefPath}
102 references = ["Muon", "No", "Bootstrap"] #"RandomHLT"
103
104 # if we want to make the eta efficiencies, can add in SReta and LReta
105 sr_props = ["SRpt"] #SReta
106 lr_props = ["LRpt"] #LReta
107 trigger_group_list = {"gfex_SR_triggers" : gfex_SR_triggers,
108 "gfex_LR_triggers" : gfex_LR_triggers,
109 "jfex_SR_triggers" : jfex_SR_triggers,
110 "jfex_LR_triggers" : jfex_LR_triggers }
111 properties_per_trigger_group = {"gfex_SR_triggers" : sr_props, "jfex_SR_triggers" : sr_props,
112 "gfex_LR_triggers" : lr_props, "jfex_LR_triggers" : lr_props }
113 pathadd_per_trigger_group = {"gfex_SR_triggers" : "gFEX/", "jfex_SR_triggers" : "jFEX/",
114 "gfex_LR_triggers" : "gFEX/", "jfex_LR_triggers" : "jFEX/" }
115 trigger_groups = list(trigger_group_list.keys())
116
117 xlabel_for_prop = { "SRpt" :'pT [MeV]', "SReta" : '#eta', "LRpt" :'pT [MeV]', "LReta" : '#eta'}
118 nbins = {"SRpt": 220, "SReta" :32, "LRpt": 220, "LReta" :32}
119 binmin = {"SRpt": -50, "SReta" :-3.3, "LRpt": -50, "LReta" :-3.3}
120 binmax = {"SRpt": 1800*GeV, "SReta" :3.3, "LRpt": 1800*GeV, "LReta" :3.3}
121
122
123 plotDistrubutions = False
124 if plotDistrubutions:
125 helper.defineHistogram('raw_pt',title='pT for all leading offline jets (with no trigger requirments);PT [MeV];Events', fillGroup=groupName, path=trigPath + distributionPath, xbins=nbins["SRpt"], xmin=binmin["SRpt"], xmax=binmax["SRpt"])
126
127 helper.defineHistogram('raw_eta', title='Eta Distribution for all leading offline jets (with no trigger requirments);#eta; Count', fillGroup=groupName, path=trigPath + distributionPath, xbins=nbins["SReta"], xmin=binmin["SReta"], xmax=binmax["SReta"])
128
129
130 for tgroup in trigger_groups: #iterate through the trigger groups (gFEX SR & LR, jFEX SR & LR)
131 for t in trigger_group_list[tgroup]: #iterate through the triggers within subgroups
132 #add algorithm that flags if the efficiency is not reaching 100%
133 # assemble thresholdConfig dict
134 thresholdConfig = {"Plateau":plateau_dict.get(t,[0.99,0.95])}
135 thresholdConfig["Threshold"] = get_or_estimate_thresholds(t)
136 xMaxConfig = min(thresholdConfig["Threshold"][1]*2.5, binmax["SRpt"]) #set the x maximum of the fit to be 6 times the upper limit, to help the fit work better
137 # if t in threshold_dict: thresholdConfig["Threshold"] = threshold_dict[t]
138 helper.defineDQAlgorithm("JetEfficiency_"+t,
139 hanConfig={"libname":"libdqm_algorithms.so","name":"Simple_fermi_Fit_TEff", "xmax":xMaxConfig, "ImproveFit":1}, # this line is always the same
140 thresholdConfig=thresholdConfig
141 )
142 for p in properties_per_trigger_group[tgroup]:
143 for r in references: #iteratate through the refernce trigger options
144
145 # if trigger not included in the menu, then lets modify the hist title to make that clear!
146 if t in l1menu: eff_plot_title = t+';'+xlabel_for_prop[p]+'; Efficiency '
147 elif t not in l1menu and t in (gfex_SR_triggers + gfex_LR_triggers): eff_plot_title = t+' Emulated;'+xlabel_for_prop[p]+'; Efficiency '
148 else: eff_plot_title = t+' NOT in Menu;'+xlabel_for_prop[p]+'; Efficiency '
149
150 #Using the muon reference trigger selection, as our least biased trigger selection inside the web displkay. Others still exist in the HIST file for now
151 if r == "Muon" and p in ["SRpt", "LRpt"]:
152 helper.defineHistogram(f"bool_{r}_{t}, val_{p};{p}_{t}", type='TEfficiency', title=eff_plot_title, fillGroup=groupName, path=ExpertTrigPath + pathadd_per_trigger_group[tgroup]+ reference_paths[r], xbins=nbins[p], xmin=binmin[p], xmax=binmax[p], hanConfig={"algorithm":"JetEfficiency_"+t}, opt='kAlwaysCreate')
153 else:
154 helper.defineHistogram(f"bool_{r}_{t}, val_{p};{p}_{t}", type='TEfficiency', title=eff_plot_title, fillGroup=groupName, path=trigPath + pathadd_per_trigger_group[tgroup]+ reference_paths[r], xbins=nbins[p], xmin=binmin[p], xmax=binmax[p], opt='kAlwaysCreate')
155
156
157
158 acc = helper.result()
159 result.merge(acc)
160 print("flags.DQ.Environment = " + flags.DQ.Environment )
161 return result
162
163def get_closest_threshold(trigger_value, extracted_values, lower_bounds, upper_bounds):
164 """
165 Finds and returns the threshold values of the closest existing trigger.
166 """
167 import numpy as np
168 closest_index = np.abs(extracted_values - trigger_value).argmin()
169 return [lower_bounds[closest_index], upper_bounds[closest_index]]
170
171def estimate_thresold(trigger_name):
172 """
173 Estimates the DQ monitoring threshold range for a given trigger name based on given threshold_dict,
174 treating jet types (gJ, gLJ, jJ, and jLJ) as separate for extrapolation.
175 If interpolation fails, it returns the closest existing trigger values.
176 """
177 import re
178 import numpy as np
179 # Extract the numeric portion and type from the trigger name
180 match = re.search(r'(gJ|gLJ|jJ|jLJ)(\d+)', trigger_name)
181 if not match:
182 return None
183
184 trigger_type, trigger_value = match.groups()
185 trigger_value = int(trigger_value)
186
187 # Gather existing numeric values and their thresholds for the same type
188 extracted_values = []
189 lower_bounds = []
190 upper_bounds = []
191
192 for key, (low, high) in threshold_dict.items():
193 key_match = re.search(r'(gJ|gLJ|jJ|jLJ)(\d+)', key)
194 if key_match and key_match.group(1) == trigger_type:
195 extracted_values.append(int(key_match.group(2)))
196 lower_bounds.append(low)
197 upper_bounds.append(high)
198
199 if not extracted_values:
200 return None # No matching trigger types found
201
202 extracted_values = np.array(extracted_values)
203 lower_bounds = np.array(lower_bounds)
204 upper_bounds = np.array(upper_bounds)
205
206 # Try interpolation/extrapolation
207 lower_pred = np.interp(trigger_value, extracted_values, lower_bounds, left=lower_bounds[0], right=lower_bounds[-1])
208 upper_pred = np.interp(trigger_value, extracted_values, upper_bounds, left=upper_bounds[0], right=upper_bounds[-1])
209
210 return [lower_pred, upper_pred]
211
213 """
214 Returns the threshold from threshold_dict if it exists.
215 Otherwise, predicts the thresholds using estimate_thresold.
216 """
217 if trigger_name in threshold_dict:
218 return threshold_dict[trigger_name] # Return stored values if available
219 else:
220 print("WARNING, trigger " + trigger_name + " doesn't have predifined thresholds for DQ Algorithm. Estimating thresholds with a fit, or using thresholds from closest exisiting trigger.")
221 print("Please add thresholds to the threshold_dict for trigger " + trigger_name)
222 print(estimate_thresold(trigger_name))
223 return estimate_thresold(trigger_name) # Predict or use closest match
224
225
226plateau_dict = {} #in case there are low stats for some of the triggers, we could modify the threshold ranges for some triggers
227threshold_dict = {"L1_gJ20p0ETA25" : [55e3, 75e3], #hits 50% at 50 for a good run, 100% around 75
228 "L1_gJ50p0ETA25" : [110e3, 180e3], #hits 50% at 109 for a good run, 100% around 180
229 "L1_gJ100p0ETA25" : [195e3, 3000e3],#hits 50% at 185 for a good run, 100% around 300
230 "L1_gJ400p0ETA25" : [620e3, 900e3],#hits 50% at 611 for a good run, 100% around 900
231 "L1_gLJ80p0ETA25" : [125e3, 200e3],#hits 50% at 113 for a good run, 100% around 200
232 "L1_gLJ100p0ETA25" : [150e3, 240e3],#hits 50% at 137 for a good run, 100% around 240
233 "L1_gLJ140p0ETA25" : [210e3, 315e3],#hits 50% at 197 for a good run, 100% around 315
234 "L1_gLJ160p0ETA25" : [240e3, 260e3],#hits 50% at 225 for a good run, 100% around 350
235 "L1_jJ30" : [50e3, 85e3],#hits 50% at 46 for a good run, 100% around 85
236 "L1_jJ40" : [55e3, 90e3],#hits 50% at 47 for a good run, 100% around 90
237 "L1_jJ50" : [60e3, 100e3],#hits 50% at 53 for a good run, 100% around 100
238 "L1_jJ60" : [90e3, 130e3],#hits 50% at 85 for a good run, 100% around 130
239 "L1_jJ80" : [90e3, 155e3],#hits 50% at 86 for a good run, 100% around 155
240 "L1_jJ90" : [110e3, 185e3],#hits 50% at 105 for a good run, 100% around 185
241 "L1_jJ125" : [145e3, 230e3],#hits 50% at 140 for a good run, 100% around 230
242 "L1_jJ140" : [160e3, 225e3],#hits 50% at 150 for a good run, 100% around 255
243 "L1_jJ160" : [180e3, 260e3],#hits 50% at 170 for a good run, 100% around 260
244 "L1_jJ180" : [235e3, 320e3],#hits 50% at 223 for a good run, 100% around 320
245 "L1_SC175-SCjJ10": [195e3, 300e3],#hits 50% at 190 for a good run, 100% around 300
246}
247
248
249if __name__=='__main__':
250 # set debug level for whole job
251 from AthenaCommon.Logging import log
252 from AthenaCommon.Constants import INFO #DEBUG
253 log.setLevel(INFO)
254
255 # set input file and config options
256 from AthenaConfiguration.AllConfigFlags import initConfigFlags
257 flags = initConfigFlags()
258
259 import glob
260
261 inputs = glob.glob('/eos/atlas/atlastier0/rucio/data18_13TeV/physics_Main/00354311/data18_13TeV.00354311.physics_Main.recon.ESD.f1129/data18_13TeV.00354311.physics_Main.recon.ESD.f1129._lb0013._SFO-8._0001.1')
262
263
264 flags.Input.Files = inputs
265 flags.Output.HISTFileName = 'ExampleMonitorOutput_LVL1.root'
266
267 flags.lock()
268
269 flags.dump() # print all the configs
270
271 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
272 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
273 cfg = MainServicesCfg(flags)
274 cfg.merge(PoolReadCfg(flags))
275
276 JetEfficiencyMonitorCfg = JetEfficiencyMonitoringConfig(flags)
277 cfg.merge(JetEfficiencyMonitorCfg)
278
279
280 # message level for algorithm
281 JetEfficiencyMonitorCfg.getEventAlgo('JetEfficiencyMonAlg').OutputLevel = 1 # 1/2 INFO/DEBUG
282 # options - print all
void print(char *figname, TCanvas *c1)
#define min(a, b)
Definition cfImp.cxx:40
get_closest_threshold(trigger_value, extracted_values, lower_bounds, upper_bounds)