ATLAS Offline Software
RatesAnalysisPostProcessing.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 #
5 
6 '''
7 @file RatesPostProcessing.py
8 @author T. Martin
9 @date 2020-02-04
10 @brief Script to consume merged rates histograms from the RatesAnalysis package and produce structured CSV, JSON output.
11 '''
12 
13 import ROOT
14 from RatesAnalysis.Util import getTableName, getMetadata, populateTriggers, getGlobalGroup, toJson, toCSV
15 from AthenaCommon.Logging import logging
16 
17 
18 
19 def main():
20  from argparse import ArgumentParser
21  parser = ArgumentParser()
22  parser.add_argument('--file', default='RatesHistograms.root',
23  help='Input ROOT file to generate output from, run hadd first if you have more than one')
24  parser.add_argument('--outputTag', default='LOCAL',
25  help='Tag identifying this processing to be used in the output folder name (any underscores will be removed)')
26  parser.add_argument('--outputJSONFile', default='rates.json',
27  help='JSON file of rates for use with the RuleBook')
28  parser.add_argument('--userDetails',
29  help='User supplied metadata string giving any extra details about this run.')
30  parser.add_argument('--jira',
31  help='Related jira ticket number')
32  parser.add_argument('--amiTag',
33  help='AMI tag used for data reprocessing')
34 
35  args = parser.parse_args()
36  log = logging.getLogger('RatesPostProcessing')
37 
38  inputFile = ROOT.TFile(args.file, 'READ')
39 
40  metadata = getMetadata(inputFile)
41  normHist = inputFile.Get('normalisation')
42 
43  if normHist is None or metadata is None:
44  log.error('Cannot locate normHist, or metadata in top level of ntuple.')
45  exit()
46 
47  metadata['normalisation'] = normHist.GetBinContent(1)
48  metadata['n_evts'] = normHist.GetBinContent(2)
49  metadata['details'] = args.userDetails
50  metadata['JIRA'] = args.jira
51  metadata['amiTag'] = args.amiTag
52 
53  HLTGlobalGroup = getGlobalGroup(inputFile, 'RATE_GLOBAL_HLT')
54  L1GlobalGroup = getGlobalGroup(inputFile, 'RATE_GLOBAL_L1')
55 
56  L1Triggers = populateTriggers(inputFile, metadata, L1GlobalGroup, 'ChainL1')
57  HLTTriggers = populateTriggers(inputFile, metadata, HLTGlobalGroup, 'ChainHLT')
58  AllGlobalGroups = populateTriggers(inputFile, metadata, HLTGlobalGroup, 'Group')
59 
60  if not L1Triggers or not HLTTriggers or not AllGlobalGroups:
61  log.error("Failed to populate triggers")
62  return
63 
64  L1Table = getTableName("L1")
65  HLTTable = getTableName("HLT")
66  GroupTable = getTableName("Group")
67 
68  log.info("Exporting " + args.outputJSONFile)
69  toJson(args.outputJSONFile, metadata, L1Triggers, HLTTriggers)
70  log.info("Exporting " + HLTTable)
71  toCSV(HLTTable, metadata, HLTTriggers)
72  log.info("Exporting " + L1Table)
73  toCSV(L1Table, metadata, L1Triggers)
74  log.info("Exporting " + GroupTable)
75  toCSV(GroupTable, metadata, AllGlobalGroups)
76 
77 if __name__== "__main__":
78  main()
python.Util.toCSV
def toCSV(fileName, metadata, HLTTriggers, readL1=False)
Definition: RatesAnalysis/python/Util.py:26
python.Util.getGlobalGroup
def getGlobalGroup(inputFile, filter)
Definition: RatesAnalysis/python/Util.py:203
getMetadata
Definition: getMetadata.py:1
calibdata.exit
exit
Definition: calibdata.py:236
python.Util.getTableName
def getTableName(name)
Definition: RatesAnalysis/python/Util.py:14
python.Util.toJson
def toJson(fileName, metadata, L1Triggers, HLTTriggers)
Definition: RatesAnalysis/python/Util.py:65
python.Util.populateTriggers
def populateTriggers(inputFile, metadata, globalGroup, filter)
Definition: RatesAnalysis/python/Util.py:178
RatesAnalysisPostProcessing.main
def main()
Definition: RatesAnalysisPostProcessing.py:19