ATLAS Offline Software
Loading...
Searching...
No Matches
TrigTauMonitoringConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from AthenaConfiguration.ComponentFactory import CompFactory
4from AthenaMonitoring.DQConfigFlags import DQDataType
5
6import functools
7
9 # Configuration flags
10 # Can be accessed in the --preExec with e.g.:
11 # --preExec 'from TrigTauMonitoring.TrigTauMonitoringConfig import TrigTauMonAlgBuilder; TrigTauMonAlgBuilder.do_total_efficiency=True'
12 # But be careful! Changing settings in this way will affect all instances of the TrigTauMonitoring (although you should normally have only 1)
13
14 #=============================================
15 # Monitoring modules
16 #=============================================
17 do_single_tau = True
18 do_L1 = True
19 do_ditau = True
20 do_boosted_ditau = True
21 do_tag_and_probe = True
22 do_truth = True # Truth monitoring will only be used when running on MC data
23
24 #=============================================
25 # Configuration
26 #=============================================
27 do_total_efficiency = False # Enable total efficiency plots (HLT vs Offline, without the L1 matching as in the normal HLT Efficiency plots)
28
29 require_offline_taus = True # Require at least 1 offline good-quality tau (regardless of p_T) on ALL events (except in the Truth monitoring).
30 # This will bias the background events variable distributions of online objects, but will better represent the signal events (the events included in the efficiency numerators)
31
32 do_duplicate_var_plots_without_offline_taus = True # Duplicate variable distribution plots without the requirement of at least 1 offline good-quality tau (regardless of p_T) on ALL events (except in the Truth monitoring).
33 do_duplicate_with_offline_gntau = True # Duplicate all plots with offline GNTaus (except in the Truth monitoring).
34
35 #=============================================
36 # TauID monitoring
37 #=============================================
38 hlt_tauid_scores = {
39 'tracktwoMVA': {
40 'GNTau': ('GNTau_Score', 'GNTau_ScoreSigTrans'),
41 'DeepSet': ('RNNJetScore', 'RNNJetScoreSigTrans'),
42 },
43 'tracktwoLLP': {
44 'RNNLLP': ('RNNJetScore', 'RNNJetScoreSigTrans'),
45 },
46 'trackLRT': {
47 'RNNLLP': ('RNNJetScore', 'RNNJetScoreSigTrans'),
48 },
49
50 # Archive:
51 'tracktwoMVABDT': { 'RNN': ('RNNJetScore', 'RNNJetScoreSigTrans') }, # Deprecated
52 }
53
54 offline_tauid_scores = {
55 'RNN': ('RNNJetScore', 'RNNJetScoreSigTrans'),
56 'GNTau': ('GNTauScore_v0prune', 'GNTauScoreSigTrans_v0prune'),
57 }
58 offline_taujets = 'TauJets'
59 offline_GNTau_WP = ''
60
61 #=============================================
62 # Setup for L1Calo monitoring
63 #=============================================
64 do_alternative_eTAU_monitoring = False # Run the L1 monitoring again, for the Alt (heuristic) eTAU simulation
65
66 def __init__(self, helper):
67 from AthenaCommon.Logging import logging
68 self.logger = logging.getLogger('TrigTauMonAlgBuilder')
69
70 self.base_path = 'HLT/TauMon'
71 self.helper = helper
72
73 # Threshold information for all Phase 1 items
74 self.L1_Phase1_thresholds = {} # E_T cuts
75 self.L1_Phase1_threshold_mappings = {} # thresholdMappings bit masks
76
77 # Monitoring algorithms, and lists of items to monitor (will be filled on configure())
79 self.mon_alg_single = None
81
83 self.mon_alg_ditau = None
85
89
93
95 self.mon_alg_truth = None
97
98 self.activate_L1 = self.do_L1
99 self.mon_alg_L1 = None
100 self.L1_items = []
101
102 self.configureMode()
103
104
105 def configureMode(self):
106 self.is_mc = False
107
108 self.data_type = self.helper.flags.DQ.DataType
109 self.logger.debug('Configuring for %s', self.data_type)
110
111 if self.data_type is DQDataType.MC:
112 self.is_mc = True
113 self.logger.debug('Enabling Truth monitoring')
114 else:
115 self.activate_truth = False
116 self.logger.debug('Using default monitoring configuration for collisions')
117
118 if self.helper.flags.DQ.Environment == "tier0":
120 # We don't have any configuration specific for Cosmics or HI (the HLT Tau Monitoring is disabled for this one)
121 # If we did, we could specify it here
122
123
124 def configure(self):
125 # First load and classify the list of triggers
126 self.configureTriggers()
127
128 # Now create, configure, and book the histograms for all the individual algorithms
129 self.logger.info('Creating the Tau monitoring algorithms...')
130
131 if self.activate_single_tau:
133
134 if self.activate_ditau:
136
139
142
143 if self.activate_truth:
145
146 if self.activate_L1:
148
149 @functools.cached_property
151 import ROOT
152 m = ROOT.std.map[ROOT.std.string, ROOT.float]()
153 for item, thr in self.L1_Phase1_thresholds.items():
154 m[item] = thr
155 return m
156
157 @functools.cached_property
159 import ROOT
160 m = ROOT.std.map[ROOT.std.string, ROOT.uint64_t]()
161 for item, thr in self.L1_Phase1_threshold_mappings.items():
162 m[item] = thr
163 return m
164
165 @functools.lru_cache(maxsize=1000)
166 def getTriggerInfo(self, trigger: str, use_thresholds=True):
167 from TrigTauMonitoring.TrigTauInfo import TrigTauInfo
168 if use_thresholds:
170 else:
171 return TrigTauInfo(trigger)
172
173
175 self.logger.info('Configuring triggers')
176
177 from TrigConfigSvc.TriggerConfigAccess import getL1MenuAccess, getHLTMenuAccess, getHLTMonitoringAccess
178 # The L1 and HLT menus should always be available
179 L1_menu = getL1MenuAccess(self.helper.flags)
180 HLT_menu = getHLTMenuAccess(self.helper.flags)
181
182 # Try to load the monitoring groups
183 HLT_monitoring = getHLTMonitoringAccess(self.helper.flags)
184 all_items = HLT_monitoring.monitoredChains(signatures='tauMon', monLevels=['shifter', 't0', 'val'])
185 # If the mon groups are not available, fallback to the hard-coded trigger monitoring list
186 if not all_items:
187 from TrigTauMonitoring.ManualChains import monitored_chains
188 self.logger.info('Could not find any monitored tau chains in the HLTMonitoring information. Will use the available items from the fallback trigger list')
189 all_items = monitored_chains
190
191 # Classify HLT trigger chains:
192 for trigger in all_items:
193 # Skip items not included in the menu. This is needed if e.g. using the fallback list on new files without Legacy triggers, or old files
194 # without PhI triggers. Also some old SMKs have broken HLTMonitoring DB links, with chains that are not in the Trigger Menu
195 if trigger not in HLT_menu: continue
196
197 info = self.getTriggerInfo(trigger, use_thresholds=False)
198
199 if self.activate_single_tau and info.isHLTSingleTau():
200 self.HLT_single_items.append(trigger)
201 elif self.activate_ditau and info.isHLTDiTau():
202 self.HLT_ditau_items.append(trigger)
203 elif self.activate_boosted_ditau and info.isHLTBoostedDiTau():
204 self.HLT_boosted_ditau_items.append(trigger)
205 elif self.activate_tag_and_probe and info.isHLTTandP():
206 self.HLT_tag_and_probe_items.append(trigger)
207
208 if len(info.getL1TauItems()):
209 for l1_tau_item in map(str, info.getL1TauItems()): # The objects are of type std::string by default, and 'in' doesn't work properly on them
210 is_phase_1 = 'eTAU' in l1_tau_item or 'jTAU' in l1_tau_item or 'cTAU' in l1_tau_item
211 if is_phase_1 and l1_tau_item not in self.L1_Phase1_thresholds:
212 # We have only one threshold entry, because we don't use eta-dependent thresholds for Phase 1 TAU items:
213 self.L1_Phase1_thresholds[l1_tau_item] = float(L1_menu.thresholds()[l1_tau_item]['thrValues'][0]['value'])
214
215 self.L1_Phase1_threshold_mappings[l1_tau_item] = 1 << int(L1_menu.thresholds()[l1_tau_item]['mapping']) # thresholdPatterns property mask
216
217 if self.activate_L1 and f'L1{l1_tau_item}' not in self.L1_items:
218 self.L1_items.append(f'L1{l1_tau_item}')
219
220 if self.activate_single_tau:
222 self.logger.info(f'Configuring HLT single-tau monitored chains: {self.HLT_single_items}')
223 if not self.HLT_single_items:
224 self.logger.warning('Empty trigger list, disabling the single-tau monitoring')
225 self.activate_single_tau = False
226
227 if self.activate_ditau:
228 self.HLT_ditau_items.sort()
229 self.logger.info(f'Configuring HLT di-tau monitored chains: {self.HLT_ditau_items}')
230 if not self.HLT_ditau_items:
231 self.logger.warning('Empty trigger list, disabling the di-tau monitoring')
232 self.activate_ditau = False
233
236 self.logger.info(f'Configuring HLT Boosted di-tau monitored chains: {self.HLT_boosted_ditau_items}')
237 if not self.HLT_boosted_ditau_items:
238 self.logger.warning('Empty trigger list, disabling the boosted di-tau monitoring')
239 self.activate_boosted_ditau = False
240
243 self.logger.info(f'Configuring HLT Tag and Probe tau monitored chains: {self.HLT_tag_and_probe_items}')
244 if not self.HLT_tag_and_probe_items:
245 self.logger.warning('Empty trigger list, disabling the tag and probe monitoring')
246 self.activate_tag_and_probe = False
247
248 if self.activate_truth:
249 # We add all chains to the Truth monitoring
251 self.logger.info(f'Configuring HLT truth tau monitored chains: {self.HLT_truth_items}')
252 if not self.HLT_truth_items:
253 self.logger.warning('Empty trigger list, disabling the truth tau monitoring')
254 self.activate_truth = False
255
256 if self.activate_L1:
257 self.L1_items.sort()
258 self.logger.info(f'Configuring L1 tau monitored items: {self.L1_items}')
259 if not self.L1_items:
260 self.logger.warning('Empty trigger list, disabling the L1 tau monitoring')
261 self.activate_L1 = False
262
263
264 def _configureAlgorithm(self, algorithm_factory, name):
265 self.logger.info(f'Creating the monitoring algorithm: {name}')
266 mon_alg = self.helper.addAlgorithm(algorithm_factory, name)
267 mon_alg.L1Phase1Thresholds = self.L1_Phase1_thresholds
268 mon_alg.L1Phase1ThresholdPatterns = self.L1_Phase1_threshold_mappings
269 mon_alg.OfflineTauJetKey = self.offline_taujets
270 mon_alg.OfflineGNTauDecorKey = self.offline_GNTau_WP
271 return mon_alg
272
273
275 self.mon_alg_single = self._configureAlgorithm(CompFactory.TrigTauMonitorSingleAlgorithm, 'TrigTauMonAlgSingle')
276 self.mon_alg_single.TriggerList = self.HLT_single_items
277 self.mon_alg_single.DoTotalEfficiency = self.do_total_efficiency
278 self.mon_alg_single.RequireOfflineTaus = self.require_offline_taus
279 self.mon_alg_single.HLTTauIDScores = self.hlt_tauid_scores
280 self.mon_alg_single.OfflineTauIDScores = self.offline_tauid_scores
281
282 self.logger.info(' |- Booking all histograms')
283 for trigger in self.HLT_single_items:
284 # Efficiencies
285 for p in ('1P', '3P'):
286 self.bookHLTEffHistograms(self.mon_alg_single, self.base_path, trigger, n_prong=p)
287
288 # Online distributions
289 for p in ('0P', '1P', 'MP'):
290 self.bookBasicVars(self.mon_alg_single, self.base_path, trigger, n_prong=p, online=True)
291 self.bookIDScores(self.mon_alg_single, self.base_path, trigger, n_prong=p, online=True)
292 self.bookIDInputScalar(self.mon_alg_single, self.base_path, trigger, n_prong=p, online=True)
293 self.bookIDInputTrack(self.mon_alg_single, self.base_path, trigger, online=True)
294 self.bookIDInputCluster(self.mon_alg_single, self.base_path, trigger, online=True)
295
296 # Offline distributions
297 for p in ('1P', '3P'):
298 self.bookBasicVars(self.mon_alg_single, self.base_path, trigger, p, online=False)
299 self.bookIDScores(self.mon_alg_single, self.base_path, trigger, p, online=False)
300 self.bookIDInputScalar(self.mon_alg_single, self.base_path, trigger, n_prong=p, online=False)
301 self.bookIDInputTrack(self.mon_alg_single, self.base_path, trigger, online=False)
302 self.bookIDInputCluster(self.mon_alg_single, self.base_path, trigger, online=False)
303
305 self.mon_alg_single_no_offline = self._configureAlgorithm(CompFactory.TrigTauMonitorSingleAlgorithm, 'TrigTauMonAlgSingleNoOffline')
306 self.mon_alg_single_no_offline.TriggerList = self.HLT_single_items
307 self.mon_alg_single_no_offline.RequireOfflineTaus = False
308 self.mon_alg_single_no_offline.DoOfflineTausDistributions = False
309 self.mon_alg_single_no_offline.DoEfficiencyPlots = False
310 self.mon_alg_single_no_offline.HLTTauIDScores = self.hlt_tauid_scores
311
312 self.logger.info(' |- Booking all histograms')
313 path = f'{self.base_path}/OnlineOnlyVars'
314 for trigger in self.HLT_single_items:
315 for p in ('0P', '1P', 'MP'):
316 self.bookBasicVars(self.mon_alg_single_no_offline, path, trigger, n_prong=p, online=True)
317 self.bookIDScores(self.mon_alg_single_no_offline, path, trigger, n_prong=p, online=True)
318 self.bookIDInputScalar(self.mon_alg_single_no_offline, path, trigger, n_prong=p, online=True)
319 self.bookIDInputTrack(self.mon_alg_single_no_offline, path, trigger, online=True)
320 self.bookIDInputCluster(self.mon_alg_single_no_offline, path, trigger, online=True)
321
323 self.mon_alg_single_gntau = self._configureAlgorithm(CompFactory.TrigTauMonitorSingleAlgorithm, 'TrigTauMonAlgSingleGNTau')
324 self.mon_alg_single_gntau.TriggerList = self.HLT_single_items
325 self.mon_alg_single_gntau.DoTotalEfficiency = self.do_total_efficiency
326 self.mon_alg_single_gntau.RequireOfflineTaus = self.require_offline_taus
327 self.mon_alg_single_gntau.HLTTauIDScores = self.hlt_tauid_scores
328 self.mon_alg_single_gntau.OfflineTauIDScores = self.offline_tauid_scores
329 self.mon_alg_single_gntau.OfflineTauID = 2
330
331 self.logger.info(' |- Booking all histograms')
332 path = f'{self.base_path}/OfflineGNTau'
333 for trigger in self.HLT_single_items:
334 # Efficiencies
335 for p in ('1P', '3P'):
336 self.bookHLTEffHistograms(self.mon_alg_single_gntau, path, trigger, n_prong=p)
337
338 # Online distributions
339 for p in ('0P', '1P', 'MP'):
340 self.bookBasicVars(self.mon_alg_single_gntau, path, trigger, n_prong=p, online=True)
341 self.bookIDScores(self.mon_alg_single_gntau, path, trigger, n_prong=p, online=True)
342 self.bookIDInputScalar(self.mon_alg_single_gntau, path, trigger, n_prong=p, online=True)
343 self.bookIDInputTrack(self.mon_alg_single_gntau, path, trigger, online=True)
344 self.bookIDInputCluster(self.mon_alg_single_gntau, path, trigger, online=True)
345
346 # Offline distributions
347 for p in ('1P', '3P'):
348 self.bookBasicVars(self.mon_alg_single_gntau, path, trigger, p, online=False)
349 self.bookIDScores(self.mon_alg_single_gntau, path, trigger, p, online=False)
350 self.bookIDInputScalar(self.mon_alg_single_gntau, path, trigger, n_prong=p, online=False)
351 self.bookIDInputTrack(self.mon_alg_single_gntau, path, trigger, online=False)
352 self.bookIDInputCluster(self.mon_alg_single_gntau, path, trigger, online=False)
353
354
355
357 self.mon_alg_ditau = self._configureAlgorithm(CompFactory.TrigTauMonitorDiTauAlgorithm, 'TrigTauMonAlgDiTau')
358 self.mon_alg_ditau.TriggerList = self.HLT_ditau_items
359 self.mon_alg_ditau.DoTotalEfficiency = self.do_total_efficiency
360 self.mon_alg_ditau.RequireOfflineTaus = self.require_offline_taus
361
362 self.logger.info(' |- Booking all histograms')
363 for trigger in self.HLT_ditau_items:
364 self.bookDiTauHLTEffHistograms(self.mon_alg_ditau, self.base_path, trigger)
365 self.bookDiTauVars(self.mon_alg_ditau, self.base_path, trigger)
366
367
369 self.mon_alg_ditau_gntau = self._configureAlgorithm(CompFactory.TrigTauMonitorDiTauAlgorithm, 'TrigTauMonAlgDiTauGNTau')
370 self.mon_alg_ditau_gntau.TriggerList = self.HLT_ditau_items
371 self.mon_alg_ditau_gntau.DoTotalEfficiency = self.do_total_efficiency
372 self.mon_alg_ditau_gntau.RequireOfflineTaus = self.require_offline_taus
373 self.mon_alg_ditau_gntau.OfflineTauID = 2
374
375 self.logger.info(' |- Booking all histograms')
376 path = f'{self.base_path}/OfflineGNTau'
377 for trigger in self.HLT_ditau_items:
378 self.bookDiTauHLTEffHistograms(self.mon_alg_ditau_gntau, path, trigger)
379 self.bookDiTauVars(self.mon_alg_ditau_gntau, path, trigger)
380
382 self.mon_alg_boosted_ditau = self._configureAlgorithm(CompFactory.TrigTauMonitorBoostedDiTauAlgorithm, 'TrigTauMonAlgBoostedDiTau')
383 self.mon_alg_boosted_ditau.TriggerList = self.HLT_boosted_ditau_items
384
385 self.logger.info(' |- Booking all histograms')
386 for trigger in self.HLT_boosted_ditau_items:
388
390 self.mon_alg_tag_and_probe = self._configureAlgorithm(CompFactory.TrigTauMonitorTandPAlgorithm, 'TrigTauMonAlgTandP')
391 self.mon_alg_tag_and_probe.TriggerList = self.HLT_tag_and_probe_items
392 self.mon_alg_tag_and_probe.RequireOfflineTaus = self.require_offline_taus
393
394 self.logger.info(' |- Booking all histograms')
395 for trigger in self.HLT_tag_and_probe_items:
397 self.bookTAndPVars(self.mon_alg_tag_and_probe, self.base_path, trigger)
398
399
401 self.mon_alg_tag_and_probe_gntau = self._configureAlgorithm(CompFactory.TrigTauMonitorTandPAlgorithm, 'TrigTauMonAlgTandPGNTau')
403 self.mon_alg_tag_and_probe_gntau.RequireOfflineTaus = self.require_offline_taus
404
405 self.logger.info(' |- Booking all histograms')
406 path = f'{self.base_path}/OfflineGNTau'
407 for trigger in self.HLT_tag_and_probe_items:
409 self.bookTAndPVars(self.mon_alg_tag_and_probe_gntau, path, trigger)
410
411
413 self.mon_alg_truth = self._configureAlgorithm(CompFactory.TrigTauMonitorTruthAlgorithm, 'TrigTauMonAlgTruth')
414 self.mon_alg_truth.TriggerList = self.HLT_truth_items
415
416 self.logger.info(' |- Booking all histograms')
417 for trigger in self.HLT_truth_items:
418 for p in ('1P', '3P'):
419 self.bookTruthEfficiency(self.mon_alg_truth, self.base_path, trigger, n_prong=p)
420 self.bookTruthVars(self.mon_alg_truth, self.base_path, trigger, n_prong=p)
421
422
424 has_xtob_etau_rois = 'L1_eTauxRoI' in self.helper.flags.Input.Collections or self.helper.flags.DQ.Environment == "tier0"
425
426 self.mon_alg_L1 = self._configureAlgorithm(CompFactory.TrigTauMonitorL1Algorithm, 'TrigTauMonAlgL1')
427 self.mon_alg_L1.TriggerList = self.L1_items
428 self.mon_alg_L1.RequireOfflineTaus = self.require_offline_taus
429 if not has_xtob_etau_rois:
430 self.logger.info(' |- No L1_eTauxRoI container is available: e/cTAU BDT scores will be set to 0')
431 self.mon_alg_L1.Phase1L1eTauxRoIKey = ''
432
433 self.logger.info(' |- Booking all histograms')
434 for trigger in self.L1_items:
435 for p in ('1P', '3P'):
436 self.bookL1EffHistograms(self.mon_alg_L1, self.base_path, trigger, n_prong=p)
437 self.bookL1Vars(self.mon_alg_L1, self.base_path, trigger)
438
440 self.mon_alg_L1_no_offline = self._configureAlgorithm(CompFactory.TrigTauMonitorL1Algorithm, 'TrigTauMonAlgL1NoOffline')
441 self.mon_alg_L1_no_offline.TriggerList = self.L1_items
442 self.mon_alg_L1_no_offline.RequireOfflineTaus = False
443 self.mon_alg_L1_no_offline.DoEfficiencyPlots = False
444 if not has_xtob_etau_rois:
445 self.logger.info(' |- No L1_eTauxRoI container is available: e/cTAU BDT scores will be set to 0')
446 self.mon_alg_L1_no_offline.Phase1L1eTauxRoIKey = ''
447
448 self.logger.info(' |- Booking all histograms')
449 path = f'{self.base_path}/OnlineOnlyVars'
450 for trigger in self.L1_items:
451 self.bookL1Vars(self.mon_alg_L1_no_offline, path, trigger)
452
454 self.mon_alg_L1_alt = self._configureAlgorithm(CompFactory.TrigTauMonitorL1Algorithm, 'TrigTauMonAlgL1eTAUAlt')
455 self.mon_alg_L1_alt.Phase1L1eTauRoIKey = 'L1_eTauRoIAltSim' # Use alternative RoIs (with heuristic eTAU algorithm simulation)
456 self.mon_alg_L1_alt.SelectL1ByETOnly = True # We don't have threshold patterns for the Alt RoIs, so we match by ET only
457 self.mon_alg_L1_alt.RequireOfflineTaus = False
458 self.mon_alg_L1_alt.Phase1L1eTauxRoIKey = ''
459
460 l1_items = [item for item in self.L1_items if 'eTAU' in item and not self.getTriggerInfo(item).isL1TauIsolated()] # Only non-isolated eTAU items
461 self.mon_alg_L1_alt.TriggerList = l1_items
462
463 self.logger.info(' |- Booking all histograms')
464 path = f'{self.base_path}/L1eTAUAlt'
465 for trigger in l1_items:
466 for p in ('1P', '3P'):
467 self.bookL1EffHistograms(self.mon_alg_L1_alt, path, trigger, n_prong=p)
468 self.bookL1Vars(self.mon_alg_L1_alt, path, trigger)
469
471 self.mon_alg_L1_gntau = self._configureAlgorithm(CompFactory.TrigTauMonitorL1Algorithm, 'TrigTauMonAlgL1GNTau')
472 self.mon_alg_L1_gntau.TriggerList = self.L1_items
473 self.mon_alg_L1_gntau.RequireOfflineTaus = self.require_offline_taus
474 if not has_xtob_etau_rois:
475 self.logger.info(' |- No L1_eTauxRoI container is available: e/cTAU BDT scores will be set to 0')
476 self.mon_alg_L1_gntau.Phase1L1eTauxRoIKey = ''
477
478 self.logger.info(' |- Booking all histograms')
479 path = f'{self.base_path}/OfflineGNTau'
480 for trigger in self.L1_items:
481 for p in ('1P', '3P'):
482 self.bookL1EffHistograms(self.mon_alg_L1_gntau, path, trigger, n_prong=p)
483 self.bookL1Vars(self.mon_alg_L1_gntau, path, trigger)
484
485
486 def bookHLTEffHistograms(self, mon_alg, base_path, trigger, n_prong):
487 mon_group_name = f'{trigger}_HLT_Efficiency_{n_prong}'
488 mon_group_path = f'{base_path}/HLT_Efficiency/{trigger}/HLT_Efficiency_{n_prong}'
489 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
490
491 def defineEachStepHistograms(xvariable, xlabel, xbins, xmin, xmax, eff='HLT', high_pt=False, coarse=False):
492 pass_flag = f'{eff}_pass'
493 sfx = ''
494
495 if high_pt:
496 pass_flag += '_highPt'
497 sfx += '_highPt'
498 xlabel += ' (p_{T} > p_{T}^{thr} + 20 GeV)'
499 elif coarse: sfx = '_coarse'
500
501 mon_group.defineHistogram(f'{pass_flag},{xvariable};Eff{eff}_{xvariable}{sfx}_wrt_Offline',
502 title=f'{eff} Efficiency {trigger} {n_prong}; {xlabel}; Efficiency',
503 type='TEfficiency', xbins=xbins, xmin=xmin, xmax=xmax, opt='kAlwaysCreate')
504
505 coarse_binning = self.getCustomPtBinning(trigger)
506
507 eff_list = ['HLT'] + (['Total'] if self.do_total_efficiency else [])
508 for eff in eff_list:
509 defineEachStepHistograms('tauPt', 'p_{T} [GeV]', 60, 0.0, 300., eff)
510 defineEachStepHistograms('tauPt', 'p_{T} [GeV]', coarse_binning, coarse_binning[0], coarse_binning[-1], eff, coarse=True)
511 defineEachStepHistograms('tauEta', '#eta', 13, -2.6, 2.6, eff)
512 defineEachStepHistograms('tauPhi', '#phi', 16, -3.2, 3.2, eff)
513 defineEachStepHistograms('tauEta', '#eta', 13, -2.6, 2.6, eff, high_pt=True)
514 defineEachStepHistograms('tauPhi', '#phi', 16, -3.2, 3.2, eff, high_pt=True)
515 defineEachStepHistograms('averageMu', '#LT#mu#GT', 10, 0, 80, eff)
516
517 # Save quantities in TTree for offline analysis
518 mon_group.defineTree('tauPt,tauEta,tauPhi,averageMu,HLT_pass;HLTEffTree',
519 treedef='tauPt/F:tauEta/F:tauPhi/F:averageMu/F:HLT_pass/I')
520
521
522 def bookIDInputScalar(self, mon_alg, base_path, trigger, n_prong, online):
523 type_str = 'HLT' if online else 'Offline'
524 mon_group_name = f'{trigger}_ID_{type_str}_InputScalar_{n_prong}'
525 mon_group_path = f'{base_path}/TauIDVars/InputScalar_{n_prong}/{trigger}/{type_str}'
526 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
527
528 mon_group.defineHistogram('centFrac', title=f'Centrality Fraction ({n_prong}); centFrac; Events', xbins=50, xmin=-0.05, xmax=1.2, opt='kAlwaysCreate')
529 mon_group.defineHistogram('etOverPtLeadTrk', title=f'etOverPtLeadTrk log ({n_prong}); etOverPtLeadTrk_log; Events', xbins=60, xmin=-3, xmax=3, opt='kAlwaysCreate')
530 mon_group.defineHistogram('dRmax', title=f'max dR of associated tracks ({n_prong}); dRmax; Events', xbins=50, xmin=-0.1, xmax=0.3, opt='kAlwaysCreate')
531 mon_group.defineHistogram('absipSigLeadTrk', title=f'AbsIpSigLeadTrk ({n_prong}); absipSigLeadTrk; Events', xbins=25, xmin=0.0, xmax=20.0, opt='kAlwaysCreate')
532 mon_group.defineHistogram('sumPtTrkFrac', title=f'SumPtTrkFrac ({n_prong}); SumPtTrkFrac; Events', xbins=50, xmin=-0.5, xmax=1.1, opt='kAlwaysCreate')
533 mon_group.defineHistogram('emPOverTrkSysP', title=f'EMPOverTrkSysP log ({n_prong}); EMPOverTrkSysP_log; Events', xbins=50, xmin=-5, xmax=3, opt='kAlwaysCreate')
534 mon_group.defineHistogram('ptRatioEflowApprox', title=f'ptRatioEflowApprox ({n_prong}); ptRatioEflowApprox; Events', xbins=50, xmin=0.0, xmax=2.0, opt='kAlwaysCreate')
535 mon_group.defineHistogram('mEflowApprox', title=f'mEflowApprox log ({n_prong}); mEflowApprox_log; Events', xbins=50, xmin=0, xmax=5, opt='kAlwaysCreate')
536 mon_group.defineHistogram('ptDetectorAxis', title=f'ptDetectorAxis log ({n_prong}); ptDetectorAxis_log; Events', xbins=50, xmin=0, xmax=5, opt='kAlwaysCreate')
537 if n_prong == 'MP' or n_prong == '3P':
538 mon_group.defineHistogram('massTrkSys', title=f'massTrkSys log ({n_prong}); massTrkSys_log; Events', xbins=50, xmin=0, xmax=3, opt='kAlwaysCreate')
539 mon_group.defineHistogram('trFlightPathSig', title=f'trFlightPathSig ({n_prong}); trFlightPathSig; Events', xbins=100, xmin=-20, xmax=40, opt='kAlwaysCreate')
540
541
542 def bookIDInputTrack(self, mon_alg, base_path, trigger, online):
543 type_str = 'HLT' if online else 'Offline'
544 mon_group_name = f'{trigger}_ID_{type_str}_InputTrack'
545 mon_group_path = f'{base_path}/TauIDVars/InputTrack/{trigger}/{type_str}'
546 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
547
548 mon_group.defineHistogram('n_track', title='Number of tracks; N_{track}; Events', xbins=15, xmin=0, xmax=15, opt='kAlwaysCreate')
549 mon_group.defineHistogram('track_pt_log', title='track_pt_log; track_pt_log; Events', xbins=20, xmin=2, xmax=7, opt='kAlwaysCreate')
550 mon_group.defineHistogram('track_pt_jetseed_log', title='track_pt_jetseed_log; track_pt_jetseed_log; Events', xbins=50, xmin=2, xmax=7, opt='kAlwaysCreate')
551 mon_group.defineHistogram('track_eta', title='Track #eta; #eta; Events', xbins=26, xmin=-2.6, xmax=2.6, opt='kAlwaysCreate')
552 mon_group.defineHistogram('track_phi', title='Track #phi; #phi; Events', xbins=16, xmin=-3.2, xmax=3.2, opt='kAlwaysCreate')
553 mon_group.defineHistogram('track_dEta', title='Track #Delta#eta; #Delta#eta; Events', xbins=100, xmin=-0.5, xmax=0.5, opt='kAlwaysCreate')
554 mon_group.defineHistogram('track_dPhi', title='Track #Delta#phi; #Delta#phi; Events', xbins=100, xmin=-0.5, xmax=0.5, opt='kAlwaysCreate')
555 mon_group.defineHistogram('track_d0_abs_log', title='track_d0_abs_log; track_d0_abs_log; Events', xbins=50, xmin=-7, xmax=2, opt='kAlwaysCreate')
556 mon_group.defineHistogram('track_z0sinthetaTJVA_abs_log', title='track_z0sinthetaTJVA_abs_log; track_z0sinthetaTJVA_abs_log; Events', xbins=50, xmin=-10, xmax=4, opt='kAlwaysCreate')
557 mon_group.defineHistogram('track_nIBLHitsAndExp', title='track_nIBLHitsAndExp; track_nIBLHitsAndExp; Events', xbins=3, xmin=0, xmax=3, opt='kAlwaysCreate')
558 mon_group.defineHistogram('track_nPixelHitsPlusDeadSensors', title='track_nPixelHitsPlusDeadSensors; track_nPixelHitsPlusDeadSensors; Events', xbins=11, xmin=0, xmax=11, opt='kAlwaysCreate')
559 mon_group.defineHistogram('track_nSCTHitsPlusDeadSensors', title='track_nSCTHitsPlusDeadSensors; track_nSCTHitsPlusDeadSensors; Events', xbins=20, xmin=0, xmax=20, opt='kAlwaysCreate')
560 mon_group.defineHistogram('track_eta,track_phi', type='TH2F', title='Track #eta vs #phi; #eta; #phi', xbins=26, xmin=-2.6, xmax=2.6, ybins=16, ymin=-3.2, ymax=3.2, opt='kAlwaysCreate')
561 mon_group.defineHistogram('track_dEta,track_dPhi', type='TH2F', title='Track #Delta#eta vs #Delta#phi; #Delta#eta; #Delta#phi', xbins=100, xmin=-0.5, xmax=0.5, ybins=100, ymin=-0.5, ymax=0.5, opt='kAlwaysCreate')
562
563
564 def bookIDInputCluster(self, mon_alg, base_path, trigger, online):
565 type_str = 'HLT' if online else 'Offline'
566 mon_group_name = f'{trigger}_ID_{type_str}_InputCluster'
567 mon_group_path = f'{base_path}/TauIDVars/InputCluster/{trigger}/{type_str}'
568 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
569
570 mon_group.defineHistogram('n_cluster', title='Number of clusters; N_{cluster}; Events', xbins=30, xmin=0, xmax=30, opt='kAlwaysCreate')
571 mon_group.defineHistogram('cluster_et_log', title='cluster_et_log; cluster_et_log; Events', xbins=30, xmin=0, xmax=6, opt='kAlwaysCreate')
572 mon_group.defineHistogram('cluster_pt_jetseed_log', title='cluster_pt_jetseed_log; cluster_pt_jetseed_log; Events', xbins=50, xmin=2, xmax=7, opt='kAlwaysCreate')
573 mon_group.defineHistogram('cluster_eta', title='Cluster #eta; #eta; Events', xbins=26, xmin=-2.6, xmax=2.6, opt='kAlwaysCreate')
574 mon_group.defineHistogram('cluster_phi', title='Cluster #phi; #phi; Events', xbins=16, xmin=-3.2, xmax=3.2, opt='kAlwaysCreate')
575 mon_group.defineHistogram('cluster_dEta', title='Cluster #Delta#eta; #Delta#eta; Events', xbins=100, xmin=-0.5, xmax=0.5, opt='kAlwaysCreate')
576 mon_group.defineHistogram('cluster_dPhi', title='Cluster #Delta#phi; #Delta#phi; Events', xbins=100, xmin=-0.5, xmax=0.5, opt='kAlwaysCreate')
577 mon_group.defineHistogram('cluster_SECOND_R_log10', title='cluster_SECOND_R_log10; cluster_SECOND_R_log10; Events', xbins=50, xmin=-3, xmax=7, opt='kAlwaysCreate')
578 mon_group.defineHistogram('cluster_SECOND_LAMBDA_log10', title='cluster_SECOND_LAMBDA_log10; cluster_SECOND_LAMBDA_log10; Events', xbins=50, xmin=-3, xmax=7, opt='kAlwaysCreate')
579 mon_group.defineHistogram('cluster_CENTER_LAMBDA_log10', title='cluster_CENTER_LAMBDA_log10; cluster_CENTER_LAMBDA_log10; Events', xbins=50, xmin=-2, xmax=5, opt='kAlwaysCreate')
580 mon_group.defineHistogram('cluster_eta,cluster_phi', type='TH2F', title='Cluster #eta vs #phi; #eta; #phi', xbins=26, xmin=-2.6, xmax=2.6, ybins=16, ymin=-3.2, ymax=3.2, opt='kAlwaysCreate')
581 mon_group.defineHistogram('cluster_dEta,cluster_dPhi', type='TH2F', title='Cluster #Delta#eta vs #Delta#phi; #Delta#eta; #Delta#phi', xbins=100, xmin=-0.5, xmax=0.5, ybins=100, ymin=-0.5, ymax=0.5, opt='kAlwaysCreate')
582
583
584 def bookIDScores(self, mon_alg, base_path, trigger, n_prong, online):
585 info = self.getTriggerInfo(trigger)
586 store_all = info.getHLTTauID() in ['idperf', 'perf']
587
588 if online:
589 if info.getHLTTauType() not in self.hlt_tauid_scores: return
590 variables = {
591 tau_id: p
592 for tau_id, p in self.hlt_tauid_scores[info.getHLTTauType()].items()
593 if tau_id == info.getHLTTauID() or store_all
594 }
595 else:
596 variables = self.offline_tauid_scores
597
598 type_str = 'HLT' if online else 'Offline'
599 mon_group_name = f'{trigger}_{type_str}_IDScores_{n_prong}'
600 mon_group_path = f'{base_path}/basicVars/{trigger}/{type_str}_{n_prong}'
601 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
602
603 for tau_id, (score, score_sig_trans) in variables.items():
604 if online and tau_id in ['RNN', 'DeepSet', 'RNNLLP', 'GNTau'] or not online and tau_id in ['RNN']: xbins, xmax = 20, 1
605 else: xbins, xmax = 100, 7
606
607 mon_group.defineHistogram(f'{tau_id}_TauIDScore', title=f'{type_str} {tau_id} TauID score; TauID score; Events', xbins=xbins, xmin=0, xmax=xmax, opt='kAlwaysCreate')
608 mon_group.defineHistogram(f'{tau_id}_TauIDScoreSigTrans', title=f'{type_str} {tau_id} TauID score sig. transformed; TauID score sig. transformed; Events', xbins=xbins, xmin=0, xmax=1, opt='kAlwaysCreate')
609
610
611 def bookBasicVars(self, mon_alg, base_path, trigger, n_prong, online):
612 type_str = 'HLT' if online else 'Offline'
613 mon_group_name = f'{trigger}_{type_str}_basicVars_{n_prong}'
614 mon_group_path = f'{base_path}/basicVars/{trigger}/{type_str}_{n_prong}'
615 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
616
617 binning = self.getCustomPtBinning(trigger, fine=True)
618
619 mon_group.defineHistogram('Pt', title=f'{type_str} p_{{T}}; p_{{T}} [GeV]; Events', xbins=binning, opt='kAlwaysCreate')
620 mon_group.defineHistogram('Eta', title=f'{type_str} #eta; #eta; Events', xbins=26, xmin=-2.6, xmax=2.6, opt='kAlwaysCreate')
621 mon_group.defineHistogram('Phi', title=f'{type_str} #phi; #phi; Events', xbins=16, xmin=-3.2, xmax=3.2, opt='kAlwaysCreate')
622 mon_group.defineHistogram('nTrack', title=f'{type_str} Number of tracks; N_{{track}}; Events', xbins=10, xmin=0, xmax=10, opt='kAlwaysCreate')
623 mon_group.defineHistogram('Eta,Phi', type='TH2F', title=f'{type_str} #eta vs #phi; #eta; #phi', xbins=26, xmin=-2.6, xmax=2.6, ybins=16, ymin=-3.2, ymax=3.2, opt='kAlwaysCreate')
624 mon_group.defineHistogram('Pt,Phi', type='TH2F', title=f'{type_str} p_{{T}} vs #phi; p_{{T}} [GeV]; #phi', xbins=binning, ybins=16, ymin=-3.2, ymax=3.2, opt='kAlwaysCreate')
625 mon_group.defineHistogram('Pt,Eta', type='TH2F', title=f'{type_str} p_{{T}} vs #eta; p_{{T}} [GeV]; #eta', xbins=binning, ybins=26, ymin=-2.6, ymax=2.6, opt='kAlwaysCreate')
626 mon_group.defineHistogram('nIsoTrack', title=f'{type_str} Number of isolation tracks; N_{{track}}^{{iso}}; Events', xbins=10, xmin=0, xmax=10, opt='kAlwaysCreate')
627 mon_group.defineHistogram('averageMu', title=f'{type_str} Average #mu; #LT#mu$GT; Events', xbins=20, xmin=0, xmax=80, opt='kAlwaysCreate')
628 mon_group.defineHistogram('TauVertexX', title=f'{type_str} Tau Vertex X; x [mm]; Events', xbins=100, xmin=-1, xmax=1, opt='kAlwaysCreate')
629 mon_group.defineHistogram('TauVertexY', title=f'{type_str} Tau Vertex Y; y [mm]; Events', xbins=100, xmin=-2, xmax=0, opt='kAlwaysCreate')
630 mon_group.defineHistogram('TauVertexZ', title=f'{type_str} Tau Vertex Z; z [mm]; Events', xbins=120, xmin=-120, xmax=120, opt='kAlwaysCreate')
631
632
633 def bookDiTauHLTEffHistograms(self, mon_alg, base_path, trigger):
634 mon_group_name = f'{trigger}_DiTauHLT_Efficiency'
635 mon_group_path = f'{base_path}/DiTauHLT_Efficiency/{trigger}/DiTauHLT_Efficiency'
636 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
637
638 def defineEachStepHistograms(xvariable, xlabel, xbins, xmin, xmax, eff='HLT', high_pt=False):
639 pass_flag = f'{eff}_pass'
640 sfx = ''
641
642 if high_pt:
643 pass_flag += '_highPt'
644 sfx += '_highPt'
645 xlabel += ' (p_{T}^{1,2} > p_{T}^{thr 1,2} + 20 GeV)'
646
647 mon_group.defineHistogram(f'{pass_flag},{xvariable};EffDiTau{eff}_{xvariable}{sfx}_wrt_Offline',
648 title=f'DiTau {eff} Efficiency {trigger};{xlabel};Efficiency',
649 type='TEfficiency', xbins=xbins, xmin=xmin, xmax=xmax, opt='kAlwaysCreate')
650
651 eff_list = ['HLT'] + (['Total'] if self.do_total_efficiency else [])
652 for eff in eff_list:
653 defineEachStepHistograms('dR', '#Delta R(#tau,#tau)', 20, 0, 4, eff)
654 defineEachStepHistograms('dEta', '#Delta#eta(#tau,#tau)', 20, 0, 4, eff)
655 defineEachStepHistograms('dPhi', '#Delta#phi(#tau,#tau)', 8, -3.2, 3.2, eff)
656
657 defineEachStepHistograms('dR', '#Delta R(#tau,#tau)', 20, 0, 4, eff, high_pt=True)
658 defineEachStepHistograms('dEta', '#Delta#eta(#tau,#tau)', 20, 0, 4, eff, high_pt=True)
659 defineEachStepHistograms('dPhi', '#Delta#phi(#tau,#tau)', 8, -3.2, 3.2, eff, high_pt=True)
660 defineEachStepHistograms('averageMu', '#LT#mu#GT', 10, 0, 80, eff)
661
662 # Save quantities in TTree for offline analysis
663 mon_group.defineTree('dR,dEta,dPhi,averageMu,HLT_pass;DiTauHLTEffTree',
664 treedef='dR/F:dEta/F:dPhi/F:averageMu/F:HLT_pass/I')
665
666
667 def bookDiTauVars(self, mon_alg, base_path, trigger):
668 mon_group_name = f'{trigger}_DiTauVars'
669 mon_group_path = f'{base_path}/DiTauVars/{trigger}'
670 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
671
672 mon_group.defineHistogram('leadHLTEt,subleadHLTEt', type='TH2F', title='p_{T}^{lead} vs p_{T}^{sublead}; p_{T}^{lead} [GeV]; p_{T}^{sublead} [GeV]',
673 xbins=50, xmin=0, xmax=250, ybins=50, ymin=0, ymax=250, opt='kAlwaysCreate')
674 mon_group.defineHistogram('leadHLTEta,subleadHLTEta', type='TH2F', title='#eta_{lead} vs #eta_{sublead}; #eta_{lead}; #eta_{sublead}',
675 xbins=26, xmin=-2.6, xmax=2.6, ybins=26, ymin=-2.6, ymax=2.6, opt='kAlwaysCreate')
676 mon_group.defineHistogram('leadHLTPhi,subleadHLTPhi', type='TH2F', title='#phi_{lead} vs #phi_{sublead}; #phi_{lead}; #phi_{sublead}',
677 xbins=16, xmin=-3.2, xmax=3.2, ybins=16, ymin=-3.2, ymax=3.2, opt='kAlwaysCreate')
678 mon_group.defineHistogram('dR', title='#Delta R(#tau,#tau); #Delta R(#tau,#tau); Events', xbins=40, xmin=0, xmax=4, opt='kAlwaysCreate')
679 mon_group.defineHistogram('dEta', title='#Delta#eta(#tau,#tau); #Delta#eta(#tau,#tau); Events', xbins=40, xmin=0, xmax=4, opt='kAlwaysCreate')
680 mon_group.defineHistogram('dPhi', title='#Delta#phi(#tau,#tau); #Delta#phi(#tau,#tau); Events', xbins=16, xmin=-3.2, xmax=3.2, opt='kAlwaysCreate')
681
682 mon_group.defineHistogram('Pt', title='p_{T}(#tau,#tau); p_{T} [GeV]; Events', xbins=50, xmin=0, xmax=250, opt='kAlwaysCreate')
683 mon_group.defineHistogram('Eta', title='#eta(#tau,#tau); #eta(#tau,#tau); Events', xbins=26, xmin=-2.6, xmax=2.6, opt='kAlwaysCreate')
684 mon_group.defineHistogram('Phi', title='#phi(#tau,#tau); #phi(#tau,#tau); Events', xbins=16, xmin=-3.2, xmax=3.2, opt='kAlwaysCreate')
685 mon_group.defineHistogram('M', title='m(#tau,#tau); m_{#tau,#tau}; Events', xbins=50, xmin=0, xmax=250, opt='kAlwaysCreate')
686 mon_group.defineHistogram('dPt', title='#Delta p_{T}(#tau, #tau); p_{T} [GeV]; Events', xbins=20, xmin=0, xmax=200, opt='kAlwaysCreate')
687
688 mon_group.defineTree('leadHLTEt,subleadHLTEt,leadHLTEta,subleadHLTEta,leadHLTPhi,subleadHLTPhi,dR,dEta,dPhi,Pt,Eta,Phi,M,dPt;DiTauVarsTree',
689 treedef='leadHLTEt/F:subleadHLTEt/F:leadHLTEta/F:subleadHLTEta/F:leadHLTPhi/F:subleadHLTPhi/F:dR/F:dEta/F:dPhi/F:Pt/F:Eta/F:Phi/F:M/F:dPt/F')
690
691# def bookBoostedDiTauHLTEffHistograms(self, mon_alg, base_path, trigger):
692 # mon_group_name = f'{trigger}_BoostedDiTauHLT_Efficiency'
693 # mon_group_path = f'{base_path}/BoostedDiTauHLT_Efficiency/{trigger}
694 # mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
695
696
697 def bookBoostedDiTauVars(self, mon_alg, base_path, trigger):
698 mon_group_name = f'{trigger}_BoostedDiTauVars'
699 mon_group_path = f'{base_path}/BoostedDiTauVars/{trigger}'
700 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
701
702 mon_group.defineHistogram('omni_score', title='omni_score; omni_score; Events', xbins=50, xmin=0, xmax=1, opt='kAlwaysCreate')
703 mon_group.defineHistogram('R_tracks_lead', title='R_tracks_lead; R_tracks_lead; Events', xbins=50, xmin=0, xmax=0.2, opt='kAlwaysCreate')
704 mon_group.defineHistogram('R_tracks_subl', title='R_tracks_subl; R_tracks_subl; Events', xbins=50, xmin=0, xmax=0.2, opt='kAlwaysCreate')
705 mon_group.defineHistogram('f_core_lead', title='f_core_lead; f_core_lead; Events', xbins=50, xmin=0, xmax=1, opt='kAlwaysCreate')
706 mon_group.defineHistogram('f_core_subl', title='f_core_subl; f_core_subl; Events', xbins=50, xmin=0, xmax=1, opt='kAlwaysCreate')
707 mon_group.defineHistogram('n_track', title='Number of tracks; n_tracks; Events', xbins=51, xmin=-0.5, xmax=50.5, opt='kAlwaysCreate')
708 mon_group.defineHistogram('n_tracks_lead', title='Number of Lead tracks; n_tracks_lead; Events', xbins=11, xmin=-0.5, xmax=10.5, opt='kAlwaysCreate')
709 mon_group.defineHistogram('n_tracks_subl', title='Number of Sub-Lead tracks; n_tracks_subl; Events', xbins=11, xmin=-0.5, xmax=10.5, opt='kAlwaysCreate')
710 mon_group.defineHistogram('Pt', title='p_{T}(#tau,#tau); p_{T} [GeV]; Events', xbins=50, xmin=160, xmax=1300, opt='kAlwaysCreate')
711 mon_group.defineHistogram('Eta', title='#eta(#tau,#tau); #eta(#tau,#tau); Events', xbins=26, xmin=-2.6, xmax=2.6, opt='kAlwaysCreate')
712 mon_group.defineHistogram('Phi', title='#phi(#tau,#tau); #phi(#tau,#tau); Events', xbins=16, xmin=-3.2, xmax=3.2, opt='kAlwaysCreate')
713 mon_group.defineHistogram('M', title='m(#tau,#tau); m_{#tau,#tau}; Events', xbins=50, xmin=0, xmax=250, opt='kAlwaysCreate')
714
715 def bookTAndPHLTEffHistograms(self, mon_alg, base_path, trigger):
716 mon_group_name = f'{trigger}_TAndPHLT_Efficiency'
717 mon_group_path = f'{base_path}/TAndPHLT_Efficiency/{trigger}/TAndPHLT_Efficiency'
718 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
719
720 def defineEachStepHistograms(xvariable, xlabel, xbins, xmin, xmax, high_pt=False, coarse=False):
721 pass_flag = 'HLT_pass'
722 sfx = ''
723
724 if high_pt:
725 pass_flag += '_highPt'
726 sfx += '_highPt'
727 xlabel += ' (p_{T}^{#tau} > p_{T}^{#tau thr} + 20 GeV)'
728 elif coarse:
729 sfx += '_coarse'
730
731 mon_group.defineHistogram(f'{pass_flag},{xvariable};EffTAndPHLT_{xvariable}{sfx}_wrt_Offline',
732 title=f'TAndP HLT Efficiency {trigger}; {xlabel}; Efficiency',
733 type='TEfficiency', xbins=xbins, xmin=xmin, xmax=xmax, opt='kAlwaysCreate')
734
735 coarse_binning = self.getCustomPtBinning(trigger)
736
737 defineEachStepHistograms('tauPt', 'p_{T}^{#tau} [GeV]', 60, 0.0, 300)
738 defineEachStepHistograms('tauPt', 'p_{T}^{#tau} [GeV]', coarse_binning, coarse_binning[0], coarse_binning[-1], coarse=True)
739 defineEachStepHistograms('tauEta', '#eta_{#tau}', 13, -2.6, 2.6)
740 defineEachStepHistograms('tauPhi', '#phi_{#tau}', 16, -3.2, 3.2)
741 defineEachStepHistograms('tauEta', '#eta_{#tau}', 13, -2.6, 2.6, high_pt=True)
742 defineEachStepHistograms('tauPhi', '#phi_{#tau}', 16, -3.2, 3.2, high_pt=True)
743 defineEachStepHistograms('dR', '#Delta R(#tau,lep)', 20, 0, 4)
744 defineEachStepHistograms('dEta', '#Delta#eta(#tau,lep)', 20, 0,4)
745 defineEachStepHistograms('dPhi', '#Delta#phi(#tau,lep)', 8, -3.2, 3.2)
746 defineEachStepHistograms('averageMu', '#LT#mu#GT', 10, 0, 80)
747
748 # Save quantities in TTree for offline analysis
749 mon_group.defineTree('tauPt,tauEta,tauPhi,dR,dEta,dPhi,averageMu,HLT_pass;TAndPHLTEffTree',
750 treedef='tauPt/F:tauEta/F:tauPhi/F:dR/F:dEta/F:dPhi/F:averageMu/F:HLT_pass/I')
751
752
753 def bookTAndPVars(self, mon_alg, base_path, trigger):
754 mon_group_name = f'{trigger}_TAndPVars'
755 mon_group_path = f'{base_path}/TAndPVars/{trigger}'
756 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
757
758 mon_group.defineHistogram('dR', title='#Delta R(#tau,lep); #Delta R(#tau,lep); Events', xbins=40, xmin=0, xmax=4, opt='kAlwaysCreate')
759 mon_group.defineHistogram('dEta', title='#Delta#eta(#tau,lep); #Delta#eta(#tau,lep); Events', xbins=40, xmin=0, xmax=4, opt='kAlwaysCreate')
760 mon_group.defineHistogram('dPhi', title='#Delta#phi(#tau,lep); #Delta#phi(#tau,lep); Events', xbins=16, xmin=-3.2, xmax=3.2, opt='kAlwaysCreate')
761
762 mon_group.defineHistogram('Pt', title='p_{T}(#tau,lep); p_{T} [GeV]; Events', xbins=50, xmin=0, xmax=250, opt='kAlwaysCreate')
763 mon_group.defineHistogram('Eta', title='#eta(#tau,lep); #eta; Events', xbins=26, xmin=-2.6, xmax=2.6, opt='kAlwaysCreate')
764 mon_group.defineHistogram('Phi', title='#phi(#tau,lep); #phi; Events', xbins=16, xmin=-3.2, xmax=3.2, opt='kAlwaysCreate')
765 mon_group.defineHistogram('M', title='m(#tau,lep); m_{#tau,lep}; Events', xbins=50, xmin=0, xmax=250, opt='kAlwaysCreate')
766 mon_group.defineHistogram('dPt', title='#Delta p_{T}(#tau,lep); p_{T} [GeV]; Events', xbins=20, xmin=0, xmax=200, opt='kAlwaysCreate')
767
768
769 def bookTruthEfficiency(self, mon_alg, base_path, trigger, n_prong):
770 mon_group_name = f'{trigger}_Truth_Efficiency_{n_prong}'
771 mon_group_path = f'{base_path}/Truth_Efficiency/{trigger}/Truth_Efficiency_{n_prong}'
772 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
773
774 info = self.getTriggerInfo(trigger)
775
776 def defineEachStepHistograms(xvariable, xlabel, xbins, xmin, xmax, high_pt=False, coarse=False):
777 pass_flag = 'HLT_pass'
778 sfx = ''
779
780 if high_pt:
781 pass_flag += '_highPt'
782 sfx += '_highPt'
783 if info.isHLTDiTau():
784 xlabel += ' (p_{T}^{#tau} > p_{T}^{#tau min thr} + 20 GeV)'
785 else:
786 xlabel += ' (p_{T}^{#tau} > p_{T}^{#tau thr} + 20 GeV)'
787 elif coarse:
788 sfx += '_coarse'
789
790 mon_group.defineHistogram(f'{pass_flag},{xvariable};EffHLT_{xvariable}{sfx}_wrt_Truth',
791 title=f'HLT Efficiency {trigger} {n_prong}; {xlabel}; Efficiency',
792 type='TEfficiency', xbins=xbins, xmin=xmin, xmax=xmax)
793
794 coarse_binning = self.getCustomPtBinning(trigger)
795
796 defineEachStepHistograms('pt_vis', 'p_{T, vis} [GeV]', 60, 0.0, 300)
797 if info.isHLTSingleTau() or info.isHLTTandP(): defineEachStepHistograms('pt_vis', 'p_{T, vis} [GeV]', coarse_binning, coarse_binning[0], coarse_binning[-1], coarse=True)
798 defineEachStepHistograms('eta_vis', '#eta_{vis}', 13, -2.6, 2.6)
799 defineEachStepHistograms('phi_vis', '#phi_{vis}', 16, -3.2, 3.2)
800 defineEachStepHistograms('eta_vis', '#eta_{vis}', 13, -2.6, 2.6, high_pt=True)
801 defineEachStepHistograms('phi_vis', '#phi_{vis}', 16, -3.2, 3.2, high_pt=True)
802
803
804 def bookTruthVars(self, mon_alg, base_path, trigger, n_prong):
805 mon_group_name = f'{trigger}_TruthVars_{n_prong}'
806 mon_group_path = f'{base_path}/TruthVars/{trigger}/TruthVars_{n_prong}'
807 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
808
809 mon_group.defineHistogram('pt_vis,PtRatio', title='p_{T} ratio vs p_{T, vis}; p_{T, vis} [GeV]; (p_{T}^{reco} - p_{T, vis}^{truth})/p_{T, vis}^{truth}', type='TProfile', xbins=21, xmin=20, xmax=250)
810 mon_group.defineHistogram('eta_vis,PtRatio', title='p_{T} ratio vs #eta_{vis}; #eta_{vis}; (p_{T}^{reco} - p_{T, vis}^{truth})/p_{T, vis}^{truth}', type='TProfile', xbins=21, xmin=-3, xmax=3)
811 mon_group.defineHistogram('phi_vis,PtRatio', title='p_{T} ratio vs #phi_{vis}; #phi_{vis}; (p_{T}^{reco} - p_{T, vis}^{truth})/p_{T, vis}^{truth}', type='TProfile', xbins=21, xmin=-3, xmax=3)
812
813 mon_group.defineHistogram('pt_vis', title='p_{T, vis}; p_{T, vis}; Events', xbins=50, xmin=0, xmax=250)
814 mon_group.defineHistogram('eta_vis', title='#eta_{vis}; #eta_{vis}; Events', xbins=26, xmin=-2.6, xmax=2.6)
815 mon_group.defineHistogram('phi_vis', title='#phi_{vis}; #phi_{vis}; Events', xbins=16, xmin=-3.2, xmax=3.2)
816
817
818 def bookL1EffHistograms(self, mon_alg, base_path, trigger, n_prong):
819 mon_group_name = f'{trigger}_L1_Efficiency_{n_prong}'
820 mon_group_path = f'{base_path}/L1_Efficiency/{trigger}/L1_Efficiency_{n_prong}'
821 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
822
823 def defineEachStepHistograms(xvariable, xlabel, xbins, xmin, xmax, high_pt=False, coarse=False):
824 pass_flag = 'L1_pass'
825 sfx = ''
826
827 if high_pt:
828 pass_flag += '_highPt'
829 sfx += '_highPt'
830 xlabel += ' (p_{T}^{#tau} > p_{T}^{#tau thr} + 20 GeV)'
831 elif coarse:
832 sfx += '_coarse'
833
834 mon_group.defineHistogram(f'{pass_flag},{xvariable};EffL1_{xvariable}{sfx}_wrt_Offline',
835 title=f'L1 Efficiency {trigger} {n_prong}; {xlabel}; Efficiency',
836 type='TEfficiency', xbins=xbins, xmin=xmin, xmax=xmax, opt='kAlwaysCreate')
837
838 coarse_binning = self.getCustomPtBinning(trigger)
839
840 defineEachStepHistograms('tauPt', 'p_{T} [GeV]', 60, 0, 300)
841 defineEachStepHistograms('tauPt', 'p_{T} [GeV]', coarse_binning, coarse_binning[0], coarse_binning[-1], coarse=True)
842 defineEachStepHistograms('tauEta', '#eta', 13, -2.6, 2.6)
843 defineEachStepHistograms('tauPhi', '#phi', 16, -3.2, 3.2)
844 defineEachStepHistograms('tauEta', '#eta', 13, -2.6, 2.6, high_pt=True)
845 defineEachStepHistograms('tauPhi', '#phi', 16, -3.2, 3.2, high_pt=True)
846 defineEachStepHistograms('averageMu', '#LT#mu#GT', 10, 0, 80)
847
848
849 def bookL1Vars(self, mon_alg, base_path, trigger):
850 mon_group_name = f'{trigger}_L1Vars'
851 mon_group_path = f'{base_path}/L1Vars/{trigger}'
852 mon_group = self.helper.addGroup(mon_alg, mon_group_name, mon_group_path)
853
854 mon_group.defineHistogram('L1RoIEt,L1RoIEta', type='TH2F', title='L1 RoI E_{T} vs #eta; E_{T} [GeV]; #eta',
855 xbins=60, xmin=0, xmax=300,
856 ybins=60, ymin=-2.6, ymax=2.6, opt='kAlwaysCreate')
857 mon_group.defineHistogram('L1RoIEt,L1RoIPhi', type='TH2F', title='L1 RoI E_{T} vs #phi; E_{T} [GeV]; #phi',
858 xbins=60, xmin=0, xmax=300,
859 ybins=60, ymin=-3.2, ymax=3.2, opt='kAlwaysCreate')
860 mon_group.defineHistogram('L1RoIEta,L1RoIPhi', type='TH2F', title='L1 RoI #eta vs #phi; #eta; #phi',
861 xbins=60, xmin=-2.6, xmax=2.6,
862 ybins=60, ymin=-3.2, ymax=3.2, opt='kAlwaysCreate')
863 mon_group.defineHistogram('L1RoIEta', title='L1 RoI #eta; #eta; RoIs', xbins=60, xmin=-2.6, xmax=2.6, opt='kAlwaysCreate')
864 mon_group.defineHistogram('L1RoIPhi', title='L1 RoI #phi; #phi; RoIs', xbins=60, xmin=-3.2, xmax=3.2, opt='kAlwaysCreate')
865 mon_group.defineHistogram('L1RoIEt', title='L1 RoI E_{T}; E_{T} [GeV]; RoIs', xbins=60, xmin=0, xmax=300, opt='kAlwaysCreate')
866
867 if 'eTAU' in trigger:
868 mon_group.defineHistogram('L1eFexRoIRCore', title='L1 eTAU RoI rCore Isolation; rCore Isolation; RoIs', xbins=250, xmin=0, xmax=1, opt='kAlwaysCreate')
869 mon_group.defineHistogram('L1eFexRoIRHad' , title='L1 eTAU RoI rHad Isolation; rHad Isolation; RoIs', xbins=250, xmin=0, xmax=1, opt='kAlwaysCreate')
870 mon_group.defineHistogram('L1eFexRoIBDTScore' , title='L1 eTAU RoI BDT score; BDT Score; RoIs', xbins=128, xmin=512, xmax=1024, opt='kAlwaysCreate')
871
872 elif 'cTAU' in trigger:
873 mon_group.defineHistogram('L1eFexRoIRCore', title='L1 eTAU RoI rCore Isolation; eTAU rCore Isolation; RoIs', xbins=250, xmin=0, xmax=1, opt='kAlwaysCreate')
874 mon_group.defineHistogram('L1eFexRoIRHad', title='L1 eTAU RoI rHad Isolation; eTAU rHad Isolation; RoIs', xbins=250, xmin=0, xmax=1, opt='kAlwaysCreate')
875 mon_group.defineHistogram('L1cTauRoITopoMatch', title='L1Topo match between eTAU and jTAU RoI; Match; RoIs', xbins=2, xmin=0, xmax=2, opt='kAlwaysCreate')
876 mon_group.defineHistogram('L1jFexRoIIso', title='L1 jTAU RoI Isolation; E_{T}^{jTAU Iso} [GeV]; RoIs', xbins=25, xmin=0, xmax=50, opt='kAlwaysCreate')
877 mon_group.defineHistogram('L1cTauMatchedRoIIso', title='L1 cTAU Isolation score; E_{T}^{jTAU Iso}/E_{T}^{eTAU}; RoIs', xbins=50, xmin=0, xmax=5, opt='kAlwaysCreate')
878 mon_group.defineHistogram('L1RoIcTauMatchedEtRatio', title='Et ratio between matched eTAU and jTAU RoIs; E_{T}^{jTAU}/E_{T}^{eTAU}; RoIs', xbins=40, xmin=0, xmax=4, opt='kAlwaysCreate')
879 mon_group.defineHistogram('L1eFexRoIBDTScore' , title='L1 eTAU RoI BDT score; BDT Score; RoIs', xbins=128, xmin=512, xmax=1024, opt='kAlwaysCreate')
880
881 elif 'jTAU' in trigger:
882 mon_group.defineHistogram('L1jFexRoIIso', title='L1 jTAU RoI Isolation; jTAU Isolation [GeV]; N RoI', xbins=25, xmin=0, xmax=50, opt='kAlwaysCreate')
883
884 def getCustomPtBinning(self, trigger, fine=False):
885 info = self.getTriggerInfo(trigger)
886
887 def getList(ranges, others=[250]):
888 ret = set(others + [500]) # The upper end of the x-axis will always be 500
889 for jump, interval in ranges.items():
890 ret.update(range(interval[0], interval[1], jump), interval)
891 return sorted(list(ret))
892
893 if info.isL1TauOnly():
894 thr = info.getL1TauThreshold()
895
896 if thr <= 8: return getList({5:(0, 30), 50:(50, 150)})
897 elif thr <= 12: return getList({5:(0, 30), 50:(50, 150)})
898 elif thr <= 20: return getList({5:(5, 40), 10:(40, 70), 50:(100, 150)})
899 elif thr <= 30: return getList({5:(15, 50), 10:(50, 70), 50:(100, 150)})
900 elif thr <= 35: return getList({5:(20, 55), 10:(60, 80), 50:(100, 150)})
901 elif thr <= 40: return getList({5:(25, 60), 10:(60, 80), 50:(100, 150)})
902 elif thr <= 60: return getList({5:(45, 80), 10:(80, 100), 50:(100, 150)})
903 elif thr <= 100: return getList({5:(85, 120), 10:(120, 140), 20:(140, 180), 50:(200, 250)})
904 else: return getList({50:(0, 200)})
905
906 else: # HLT triggers
907 thr = info.getHLTTauThreshold()
908
909 if fine:
910 if thr == 0: return getList({5:(0, 80), 10:(80, 120), 20:(120, 160), 40:(160, 240), 60:(240, 420)}, [])
911 elif thr <= 20: return getList({5:(15, 80), 10:(80, 120), 20:(120, 160), 40:(160, 240), 60:(240, 420)}, [])
912 elif thr <= 25: return getList({5:(20, 80), 10:(80, 120), 20:(120, 160), 40:(160, 240), 60:(240, 420)}, [])
913 elif thr <= 30: return getList({5:(25, 80), 10:(80, 120), 20:(120, 160), 40:(160, 240), 60:(240, 420)}, [])
914 elif thr <= 35: return getList({5:(30, 80), 10:(80, 120), 20:(120, 160), 40:(160, 240), 60:(240, 420)}, [])
915 elif thr <= 60: return getList({5:(55, 80), 10:(80, 120), 20:(120, 160), 40:(160, 240), 60:(240, 420)}, [])
916 elif thr <= 80: return getList({5:(75, 80), 10:(80, 120), 20:(120, 160), 40:(160, 240), 60:(240, 420)}, [])
917 elif thr <= 160: return getList({5:(155, 160), 40:(160, 240), 60:(240, 420)}, [])
918 elif thr <= 180: return getList({5:(175, 180), 40:(180, 260), 60:(260, 380)}, [])
919 else: return getList({5:(195, 200), 40:(200, 240), 60:(240, 420)}, [])
920
921 else:
922 if thr == 0:
923 if info.getL1TauItems(): return self.getCustomPtBinning(f'L1{info.getL1TauItem()}')
924 else: return getList({5:(0, 30), 50:(50, 150)})
925 elif thr <= 20: return getList({5:(10, 40), 10:(40, 60), 20:(60, 80)}, [150, 250])
926 elif thr <= 25: return getList({5:(15, 40), 10:(40, 60), 20:(60, 80)}, [150, 250])
927 elif thr <= 30: return getList({5:(20, 50), 10:(50, 60), 20:(60, 80)}, [150, 250])
928 elif thr <= 35: return getList({5:(25, 50), 10:(50, 60), 20:(60, 80)}, [150, 250])
929 elif thr <= 60: return getList({5:(50, 70), 10:(70, 80)}, [110, 150, 250])
930 elif thr <= 80: return getList({5:(70, 90)}, [110, 150, 250])
931 elif thr <= 160: return getList({5:(150, 170), 10:(170, 180), 20:(180, 200)}, [240, 300])
932 elif thr <= 180: return getList({5:(170, 180), 10:(180, 200)}, [240, 300])
933 else: return getList({5:(190, 200), 10:(200, 210)}, [240, 300])
const bool debug
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
STL class.
bookIDInputScalar(self, mon_alg, base_path, trigger, n_prong, online)
getTriggerInfo(self, str trigger, use_thresholds=True)
bookBasicVars(self, mon_alg, base_path, trigger, n_prong, online)
bookTruthEfficiency(self, mon_alg, base_path, trigger, n_prong)
bookIDInputTrack(self, mon_alg, base_path, trigger, online)
bookIDInputCluster(self, mon_alg, base_path, trigger, online)
bookIDScores(self, mon_alg, base_path, trigger, n_prong, online)
bookTruthVars(self, mon_alg, base_path, trigger, n_prong)
bookL1EffHistograms(self, mon_alg, base_path, trigger, n_prong)
bookHLTEffHistograms(self, mon_alg, base_path, trigger, n_prong)
STL class.