ATLAS Offline Software
RatesScanTrigger.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 '''
6 @file RatesScanTrigger.py
7 @brief Accumulator class to buffer data for a single scan trigger and export this to ROOT
8 '''
9 
10 from AthenaCommon.Logging import logging
11 log = logging.getLogger('RatesScanTrigger')
12 
13 
14 def apply_pileup_correction(hist_cumulative, metadata):
15  """Apply pileup correction to cumulative histogram"""
16 
17  BCR = metadata['bunchCrossingRate']
18  pileup = metadata['targetMu']
19 
20  # Create corrected histogram
21  hist_pileup_corrected = hist_cumulative.Clone(f"{hist_cumulative.GetName()}_pileup_corrected")
22 
23  # Apply pileup correction formula to each bin
24  for bin in range(1, hist_pileup_corrected.GetNbinsX() + 1):
25  bin_value = hist_cumulative.GetBinContent(bin)
26  P_scatter = bin_value / BCR / pileup
27  corrected_value = BCR * (1.0 - pow(1.0 - P_scatter, pileup))
28  hist_pileup_corrected.SetBinContent(bin, corrected_value)
29 
30  # Propagate errors
31  bin_error = hist_cumulative.GetBinError(bin)
32  if bin_value > 0:
33  error_scale = corrected_value / bin_value
34  hist_pileup_corrected.SetBinError(bin, bin_error * error_scale)
35  else:
36  hist_pileup_corrected.SetBinError(bin, 0)
37 
38  return hist_pileup_corrected
39 
40 
42  def __init__(self, name, metadata, numerators):
43  self.name = name
44 
45  self.sumHisto = None
46 
47  for key, histo in numerators.items():
48  denominator = 1.0
49  try:
50  if metadata['multiSliceDiJet']:
51  denominator = metadata['n_evts_weighted'+key]
52  else:
53  denominator = metadata['normalisation'+key]
54  except KeyError:
55  log.error(f"Key {key} not found in slice denominator dictionary")
56  histo.Scale(1/denominator)
57  if self.sumHisto is None:
58  self.sumHisto = histo
59  else:
60  self.sumHisto.Add(histo)
61  if metadata['doBinomialCorrection']: self.sumHisto = apply_pileup_correction(self.sumHisto, metadata)
62 
63 
64  def export(self, exportdict):
65  myDict = {}
66  myDict['rate'] = self.sumHisto
67  exportdict[self.name] = myDict
python.RatesScanTrigger.RatesScanTrigger.export
def export(self, exportdict)
Definition: RatesScanTrigger.py:64
python.RatesScanTrigger.RatesScanTrigger.sumHisto
sumHisto
Definition: RatesScanTrigger.py:45
python.RatesScanTrigger.RatesScanTrigger.name
name
Definition: RatesScanTrigger.py:43
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
python.RatesScanTrigger.apply_pileup_correction
def apply_pileup_correction(hist_cumulative, metadata)
Definition: RatesScanTrigger.py:14
python.RatesScanTrigger.RatesScanTrigger
Definition: RatesScanTrigger.py:41
python.RatesScanTrigger.RatesScanTrigger.__init__
def __init__(self, name, metadata, numerators)
Definition: RatesScanTrigger.py:42
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15