ATLAS Offline Software
ParseTrkSummary.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 
4 def getCollectionName(line):
5  begin = line.find("=")
6  collection = line[begin+2:]
7  #print ("Line:", line)
8  #print ("collection: '%s'" % collection.strip())
9  return collection.strip()
10 
11 # To use this, do e.g.
12 # summary = ParseTrkSummary.parseSummaryFile()
13 # summary.get('MooreTracks').get('Trk/Evt')
14 def parseSummaryFile(filename='trkSummary.txt', makePlots=False):
15  import os
16  filename=os.path.expanduser(filename)
17  if filename.endswith('.gz'):
18  import gzip
19  fh = gzip.open(filename,'r')
20  else:
21  fh = open(filename,'r')
22 
23  collectionName=""
24  lineIt = iter(fh)
25  summary = dict()
26  while True:
27  try:
28  line = lineIt.next()
29  if line[0]!='>' and line[0]!='|':#Ignore most lines with minimal overhead (safe since empty lines still have '\n')
30  continue
31  if line[0:4]==">>>>":
32  collectionName = getCollectionName(line)
33  #print ("collection: '%s'" % collectionName)
34  continue
35 
36  if line[0:2]=="||":
37  firstline=line.strip().removeprefix("||")
38  # get rid of spaces around each 'key', where we get the keys by splitting the line at the '||' boundaries
39  keys = [key.strip() for key in firstline.split("||")]
40  nextLine = lineIt.next()
41  secondline=nextLine.strip().removeprefix("||")
42  # get rid of spaces around each 'value', where we get the values by splitting the line at the '||' boundaries
43  values = [float(value.strip()) for value in secondline.split("||")]
44  info = dict(zip(keys,values))
45  summary[collectionName]=info
46 
47  except StopIteration:
48  break
49  print ("Found data for the following collections: ", summary.keys())
50  if makePlots:
51  from PmbUtils.ValuePerDomainCalcUtils import PlottableResult, JobListPlotter, TimeLabel
52  title = 'MooreTracks ( %s events)' % int(summary['MooreTracks'].get('Events'))
53  result = PlottableResult(summary['MooreTracks'].keys(), title=title)
54  # We don't want the large values of the following to dominate the results (and anyway, they're redundant)
55  exclusions = ["Events", "Tracks"]
56  for key in summary['MooreTracks'].keys():
57  if (key not in exclusions):
58  result.addPoint(colname=key, value=summary['MooreTracks'].get(key), time=TimeLabel(label="Now",sortvalue=0))
59  JobListPlotter().produceTimeDevelopmentPlot(result,"test.png")
60  return summary
61 
62 def plotSummariesForCollection(filename='test.png', collection='MooreTracks', summaries=[], times=[]):
63  from PmbUtils.ValuePerDomainCalcUtils import PlottableResult, JobListPlotter, TimeLabel
64  firstSummary = summaries[0]
65 
66  title = '%s ( %s events)' % (collection, int(firstSummary[collection].get('Events')) )
67  print ('Making plot for %s with %s summaries' % (title, len(summaries)))
68  result = PlottableResult(firstSummary[collection].keys(), title=title)
69  i=0
70  for summary in summaries:
71  i+=1
72  # We don't want the large values of the following to dominate the results (and anyway, they're redundant)
73  exclusions = ["Events", "Tracks"]
74  for key in summary[collection].keys():
75  if (key not in exclusions):
76  print (i)
77  result.addPoint(colname=key, value=summary[collection].get(key), time=TimeLabel(label=times[i],sortvalue=i))
78  print ("result.getNColumns()", result.getNColumns())
79  print ("result.getTimes()", result.getTimes())
80  JobListPlotter().produceTimeDevelopmentPlot(result,filename)
createLinkingScheme.iter
iter
Definition: createLinkingScheme.py:62
ParseTrkSummary.plotSummariesForCollection
def plotSummariesForCollection(filename='test.png', collection='MooreTracks', summaries=[], times=[])
Definition: ParseTrkSummary.py:62
ParseTrkSummary.getCollectionName
def getCollectionName(line)
Definition: ParseTrkSummary.py:4
Trk::open
@ open
Definition: BinningType.h:40
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
ParseTrkSummary.parseSummaryFile
def parseSummaryFile(filename='trkSummary.txt', makePlots=False)
Definition: ParseTrkSummary.py:14
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65