ATLAS Offline Software
RatesTrigger.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 '''
6 @file RatesTrigger.py
7 @brief Accumulator class to buffer data for a single trigger and export this to JSON or CSV
8 '''
9 
10 import math
11 from enum import Enum
12 from AthenaCommon.Logging import logging
13 log = logging.getLogger('RatesTrigger')
14 
15 class RatesBins(Enum):
16  ACTIVE_RAW_BIN = 1
17  ACTIVE_WEIGHTED_BIN = 2
18  PASS_RAW_BIN = 3
19  PASS_WEIGHTED_OR_BIN = 4
20  PASS_WEIGHTED_AND_BIN = 5
21  EXPRESS_BIN = 6
22  UNIQUE_BIN = 7
23 
25  def __init__(self, name, metadata, data, masterGroup):
26  self.name = name
27  # Total weighted events passing the trigger
28  self.passWeighted = data.GetBinContent(RatesBins.PASS_WEIGHTED_OR_BIN.value)
29  self.passWeightedErr = data.GetBinError(RatesBins.PASS_WEIGHTED_OR_BIN.value)
30 
31  # Total un-weighted events passing the trigger
32  self.passRaw = data.GetBinContent(RatesBins.PASS_RAW_BIN.value)
33 
34  # Total weighted events passing the trigger, using the express prescale
35  self.passExpressWeighted = data.GetBinContent(RatesBins.EXPRESS_BIN.value)
36  self.passExpressWeightedErr = data.GetBinError(RatesBins.EXPRESS_BIN.value)
37 
38  # Total weighted events passing a full hypothetical menu which *excluded* this trigger
39  self.passUniqueWeighted = data.GetBinContent(RatesBins.UNIQUE_BIN.value)
40  self.passUniqueWeightedErr = data.GetBinError(RatesBins.UNIQUE_BIN.value)
41 
42  # Total weighted events passing the full menu (full L1 for L1 chains, full HLT for HLT chains)
43  self.passMasterWeighted = masterGroup.GetBinContent(RatesBins.PASS_WEIGHTED_OR_BIN.value)
44 
45  # Total un-weighted number of events in which the trigger was active (always active if L1)
46  self.activeRaw = data.GetBinContent(RatesBins.ACTIVE_RAW_BIN.value)
47 
48  # Total weighted number of events in which the trigger was active
49  self.activeWeighted = data.GetBinContent(RatesBins.ACTIVE_WEIGHTED_BIN.value)
50  self.activeWeightedErr = data.GetBinError(RatesBins.ACTIVE_WEIGHTED_BIN.value)
51 
52  # Wall-time in seconds. No error on this.
53  self.rateDenominator = metadata['normalisation']
54  if not self.rateDenominator:
55  log.error("Normalisation factor not found in the input ntuple! Check if it's not corrupted")
56  raise ValueError
57 
58  # Trigger's rate is total weighted passing events normalised to wall-time
59  self.rate = self.passWeighted / self.rateDenominator
61 
62  # Trigger's efficiency is the fraction of active events which are passed. Error propagated.
63  self.efficiency = self.passWeighted / self.activeWeighted if self.activeWeighted > 0.0 else 0.0
64  self.efficiencyErr = 0
65  if self.passWeighted != 0 and self.activeWeighted != 0:
66  fracErr = math.sqrt( math.pow(self.passWeightedErr/self.passWeighted,2) + math.pow(self.activeWeightedErr/self.activeWeighted,2) )
67  self.efficiencyErr = self.efficiency * fracErr
68 
69  # Rate using express prescales
72 
73  # Some menu-derived metadata
74  prescales = metadata['prescales']
75  lowers = metadata['lowers']
76  express = metadata['express']
77  self.prescale = prescales.get(name, 1)
78  self.lower = lowers.get(name)
79  self.expressPrescale = express.get(name)
80 
81  # Unique rate requires the subtraction of the (all minus this trigger) total from the (all triggers) total
82  # The error is taken as a fractional error on the main rate calc
83  # Disabled items should have unique rate = 0
84  if self.prescale != "Multiple" and float(self.prescale) <= 0:
85  self.rateUnique = 0
86  self.rateUniqueErr = 0
87  else:
89  self.rateUniqueErr = 0
90  if self.passWeighted != 0:
91  self.rateUniqueErr = (self.passWeightedErr / self.passWeighted) * self.rateUnique
92 
93  # The total rate of all triggers
95 
96  # What fraction of the total rate is unique to this trigger
97  self.uniqueFraction = 0 if self.masterRate == 0 else self.rateUnique / self.masterRate
98 
99 
100  def export(self, exportDict):
101  myDict = {}
102  myDict['express_stream'] = self.rateExpress
103  myDict['chain_prescale'] = self.prescale
104  myDict['lower_chain_name'] = self.lower
105  myDict['evts_passed'] = self.passRaw
106  myDict['evts_passed_weighted'] = self.passWeighted
107  myDict['efficiency'] = self.efficiency
108  myDict['efficiency_err'] = self.efficiencyErr
109  myDict['rate'] = self.rate
110  myDict['rate_err'] = self.rateErr
111  myDict['unique_fraction'] = self.uniqueFraction
112  myDict['unique_rate'] = self.rateUnique
113  exportDict[self.name] = myDict
python.RatesTrigger.RatesTrigger.passWeightedErr
passWeightedErr
Definition: RatesTrigger.py:29
python.RatesTrigger.RatesTrigger.rateErr
rateErr
Definition: RatesTrigger.py:60
python.RatesTrigger.RatesTrigger.activeWeighted
activeWeighted
Definition: RatesTrigger.py:49
python.RatesTrigger.RatesTrigger.passRaw
passRaw
Definition: RatesTrigger.py:32
python.RatesTrigger.RatesTrigger.activeRaw
activeRaw
Definition: RatesTrigger.py:46
python.RatesTrigger.RatesTrigger.efficiency
efficiency
Definition: RatesTrigger.py:63
python.RatesTrigger.RatesBins
Definition: RatesTrigger.py:15
python.RatesTrigger.RatesTrigger.activeWeightedErr
activeWeightedErr
Definition: RatesTrigger.py:50
python.RatesTrigger.RatesTrigger.efficiencyErr
efficiencyErr
Definition: RatesTrigger.py:64
python.RatesTrigger.RatesTrigger.passWeighted
passWeighted
Definition: RatesTrigger.py:28
python.RatesTrigger.RatesTrigger.rateUnique
rateUnique
Definition: RatesTrigger.py:85
python.RatesTrigger.RatesTrigger.passUniqueWeightedErr
passUniqueWeightedErr
Definition: RatesTrigger.py:40
python.RatesTrigger.RatesTrigger.passUniqueWeighted
passUniqueWeighted
Definition: RatesTrigger.py:39
python.RatesTrigger.RatesTrigger.masterRate
masterRate
Definition: RatesTrigger.py:94
python.RatesTrigger.RatesTrigger
Definition: RatesTrigger.py:24
python.RatesTrigger.RatesTrigger.passMasterWeighted
passMasterWeighted
Definition: RatesTrigger.py:43
python.RatesTrigger.RatesTrigger.uniqueFraction
uniqueFraction
Definition: RatesTrigger.py:97
python.RatesTrigger.RatesTrigger.lower
lower
Definition: RatesTrigger.py:78
python.RatesTrigger.RatesTrigger.passExpressWeighted
passExpressWeighted
Definition: RatesTrigger.py:35
python.RatesTrigger.RatesTrigger.rateUniqueErr
rateUniqueErr
Definition: RatesTrigger.py:86
python.RatesTrigger.RatesTrigger.passExpressWeightedErr
passExpressWeightedErr
Definition: RatesTrigger.py:36
python.RatesTrigger.RatesTrigger.expressPrescale
expressPrescale
Definition: RatesTrigger.py:79
python.RatesTrigger.RatesTrigger.rateDenominator
rateDenominator
Definition: RatesTrigger.py:53
python.RatesTrigger.RatesTrigger.export
def export(self, exportDict)
Definition: RatesTrigger.py:100
python.RatesTrigger.RatesTrigger.name
name
Definition: RatesTrigger.py:26
python.RatesTrigger.RatesTrigger.__init__
def __init__(self, name, metadata, data, masterGroup)
Definition: RatesTrigger.py:25
python.RatesTrigger.RatesTrigger.rateExpress
rateExpress
Definition: RatesTrigger.py:70
python.RatesTrigger.RatesTrigger.rateExpressErr
rateExpressErr
Definition: RatesTrigger.py:71
readCCLHist.float
float
Definition: readCCLHist.py:83
python.RatesTrigger.RatesTrigger.rate
rate
Definition: RatesTrigger.py:59
python.RatesTrigger.RatesTrigger.prescale
prescale
Definition: RatesTrigger.py:77