ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
EvgenParserTool.evgenParserTool Class Reference
Collaboration diagram for EvgenParserTool.evgenParserTool:

Public Member Functions

def __init__ (self, name='evgenLogParser', **kw)
 
def processLine (self, line)
 
def report (self)
 
def updateMetadata (self, metadata)
 

Public Attributes

 msg
 
 FixHepMCDict
 
 TestHepMCDict
 
 FilterSeqDict
 
 MetadataDict
 
 isMP
 

Detailed Description

Definition at line 12 of file EvgenParserTool.py.

Constructor & Destructor Documentation

◆ __init__()

def EvgenParserTool.evgenParserTool.__init__ (   self,
  name = 'evgenLogParser',
**  kw 
)

Definition at line 14 of file EvgenParserTool.py.

14  def __init__ ( self, name = 'evgenLogParser', **kw ):
15  self.msg = Logging.logging.getLogger(name)
16  # For FixHepMC, keep a list of reasons for rejection, counts, and lines for logging
17  self.FixHepMCDict = {'reasons':{},'denominator':0,'lines':{}}
18  # For TestHepMC, we need summary statistics as well as all the individual numbers
19  # Keep number passing and failing, p/f line (for printing), all the rates with the lines, which ones are(n't) included in the efficiency
20  # the line for the rates, the line for the final efficiency, and the number of events in this log passing/failing (for converting % to count)
21  self.TestHepMCDict = {'p':0,'f':0,'pfline':None,'rate':{},'notinc':[],'rline':None,'effline':None,'lastpf':0}
22  # For the filter sequence, keep the weighted and unweighted numbers and the line
23  self.FilterSeqDict = {'num':0,'den':0,'wnum':0,'wden':0,'line':None,'wline':None}
24  # Process the Metadata as well
25  self.MetadataDict = {'sumOfPosWeights':0.,'sumOfNegWeights':0.,'sumOfSqrWeights':0.,
26  'sumOfPosWeightsNoFilter':0.,'sumOfNegWeightsNoFilter':0.,'sumOfSqrWeightsNoFilter':0.,
27  'xsec_holder':0.,'xsec_weight':0.,'xsec_sum':0.}
28  self.isMP = -1
29 

Member Function Documentation

◆ processLine()

def EvgenParserTool.evgenParserTool.processLine (   self,
  line 
)
Function to process a log line and keep what's needed for final reporting

Definition at line 30 of file EvgenParserTool.py.

30  def processLine( self, line ):
31  ''' Function to process a log line and keep what's needed for final reporting'''
32 
33  # Skip PerfMonMTSvc report
34  if "PerfMonMTSvc" in line:
35  return
36 
37  # First check for lines from FixHepMC
38  if 'FixHepMC' in line and 'INFO Removed' in line:
39  # Use the loops line to count the denominator
40  if 'because of loops' in line:
41  self.FixHepMCDict['denominator'] += int( line.split(' of ')[1].split()[0].strip() )
42  # Grab the reason for failure from the line; they all follow the same formula
43  reason = line.split('particles')[1]
44  # Add to the count for that reason
45  if reason not in self.FixHepMCDict['reasons']:
46  self.FixHepMCDict['reasons'][reason] = 0
47  self.FixHepMCDict['reasons'][reason] += int( line.split('Removed')[1].split()[0].strip() )
48  # Make sure that we also have a log line for printing later if we need it
49  if reason not in self.FixHepMCDict['lines']:
50  self.FixHepMCDict['lines'][reason] = [ line.split('Removed')[0] , line.split('particles')[1] ]
51  # Second up: Filter statistics
52  elif 'Py:EvgenFilterSeq' in line:
53  # First check weighted, then unweighted (one is a substring of the other...)
54  if 'Weighted Filter Efficiency' in line:
55  # Grab all the numbers from the log. The line prints the numerator and denominator explicitly at the end
56  numbers = re.findall(r'[\d.]+',line)
57  self.FilterSeqDict['wnum'] += float( numbers[-2] )
58  self.FilterSeqDict['wden'] += float( numbers[-1] )
59  # Grab the log line to print
60  self.FilterSeqDict['wline'] = line.split('=')[0]
61  elif 'Filter Efficiency' in line:
62  # Grab all the numbers from the log. The line prints the numerator and denominator explicitly at the end
63  numbers = re.findall(r'[\d.]+',line)
64  self.FilterSeqDict['num'] += int( numbers[-2] )
65  self.FilterSeqDict['den'] += int( numbers[-1] )
66  # Grab the log line to print
67  if self.FilterSeqDict['line'] is None:
68  self.FilterSeqDict['line'] = line.split('=')[0]
69  # Third and finally: TestHepMC
70  elif 'TestHepMC' in line and 'Event' in line:
71  if 'Events passed' in line:
72  # Simplest line, just shows the numbers of events passing and failing
73  numbers = re.findall(r'[\d.]+',line)
74  self.TestHepMCDict['p'] += int(numbers[-2])
75  self.TestHepMCDict['f'] += int(numbers[-1])
76  # Save the log line so that we can reproduce it later
77  self.TestHepMCDict['pfline'] = line.split('=')[0]
78  # Keep track of the denominators to ensure we get the percentages right
79  self.TestHepMCDict['lastpf'] = int(numbers[-2]) + int(numbers[-1])
80  else:
81  # Otherwise this is an event rate line. First figure out what the reason in the line is, and index count on that
82  reason = line.split('Event rate')[1].split('=')[0]
83  if reason not in self.TestHepMCDict['rate']:
84  self.TestHepMCDict['rate'][reason] = 0
85  # Some rates are not included in the test efficiency; we should be ready to point that out as well
86  if 'not included in test efficiency' in line:
87  self.TestHepMCDict['notinc'] += [reason]
88  # We have to convert the logged percentage back to counts, and then back to percentage in the report
89  my_perc = float( line.split('=')[1].split('%')[0] )
90  self.TestHepMCDict['rate'][reason] += my_perc * self.TestHepMCDict['lastpf']/100.
91  # And last we just have to get the log format for an event rate line right
92  self.TestHepMCDict['rline'] = line.split('Event rate')[0]
93  # Extra catch for Efficiency line for TestHepMC
94  elif 'TestHepMC' in line and 'Efficiency' in line:
95  # If this is just the efficiency line, all we need is the log line format
96  self.TestHepMCDict['effline'] = line.split('=')[0]
97  # Because this is a unique line, we will also use it to check if we are running MP
98  self.isMP += 1
99  elif 'MetaData:' in line:
100  # If it's a metadata line, we just sum them up, with one exception
101  field = line.split('MetaData:')[1].split('=')[0].strip()
102  if field in self.MetadataDict:
103  self.MetadataDict[field] += float( line.split('=')[1] )
104  # Cross section requires special attention
105  # The cross section field itself comes first, so we have to just stash it
106  if field == 'cross-section (nb)':
107  self.MetadataDict['xsec_holder'] = float( line.split('=')[1] )
108  # The weights fields are also there; we need the 'no filter' versions
109  # Use = here to reset each round
110  elif field == 'sumOfPosWeightsNoFilter':
111  self.MetadataDict['xsec_weight'] = float( line.split('=')[1] )
112  # Sum of negative weights is last, and now we have all the info we need
113  elif field == 'sumOfNegWeightsNoFilter':
114  my_negw = float( line.split('=')[1] )
115  self.MetadataDict['xsec_sum'] += self.MetadataDict['xsec_holder']*(self.MetadataDict['xsec_weight']-my_negw)
116  # We don't need to keep the sum of weights here, because we have it elsewhere
117 

◆ report()

def EvgenParserTool.evgenParserTool.report (   self)
Function to print final statistics grabbed from the logs

Definition at line 118 of file EvgenParserTool.py.

118  def report(self):
119  ''' Function to print final statistics grabbed from the logs'''
120  # If we aren't running MP, then forget it
121  if self.isMP<1:
122  self.msg.debug('Not running MP, nothing to do')
123  return
124  # Now we are going to print updated statistics for all the handlers
125  # Because in an MP job we get a primary worker report as well, the number of workers is just self.isMP
126  self.msg.info(f'Printing final summary statistics from {self.isMP} MP workers')
127  # First print all the FixHepMC stuff - just rates for each reason we remove particles
128  for reason in self.FixHepMCDict['reasons']:
129  print(f"{self.FixHepMCDict['lines'][reason][0]}Removed {self.FixHepMCDict['reasons'][reason]} of {self.FixHepMCDict['denominator']} particles {self.FixHepMCDict['lines'][reason][1]}")
130  # Next print all the information from TestHepMC, starting with the pass/fail summary
131  print(f"{self.TestHepMCDict['pfline']}= {self.TestHepMCDict['p']}, Events Failed = {self.TestHepMCDict['f']}")
132  # We will have the same denominator for all the ratios that we print next
133  denom = self.TestHepMCDict['p'] + self.TestHepMCDict['f']
134  # Now go through all the TestHepMC checks, and for each one recreate the log line
135  for rate in self.TestHepMCDict['rate']:
136  # Again, have to handle zero denominators correctly
137  pct = 0.
138  if denom>0:
139  pct = (self.TestHepMCDict['rate'][rate] / denom)*100.
140  print(f"{self.TestHepMCDict['rline']}Event rate {rate} = {pct}%{' (not included in test efficiency)' if rate in self.TestHepMCDict['notinc'] else ''}")
141  # Now print the final efficiency; make sure we handle zeroes correctly
142  final_eff = 1.
143  if denom:
144  final_eff = self.TestHepMCDict['p']/denom
145  print(f"{self.TestHepMCDict['effline']}= {final_eff*100.}%")
146  # Now print our filter sequence summary - again, make sure we handle zeroes correctly
147  eff = (self.FilterSeqDict['num']/self.FilterSeqDict['den']) if self.FilterSeqDict['den'] > 0 else 1.
148  print(f"{self.FilterSeqDict['line']} = {eff} [{self.FilterSeqDict['num']} / {self.FilterSeqDict['den']}]")
149  eff = (self.FilterSeqDict['wnum']/self.FilterSeqDict['wden']) if self.FilterSeqDict['wden'] >0 else 1.
150  print(f"{self.FilterSeqDict['wline']} = {eff} [{self.FilterSeqDict['wnum']} / {self.FilterSeqDict['wden']}]")
151  # Done!
152 

◆ updateMetadata()

def EvgenParserTool.evgenParserTool.updateMetadata (   self,
  metadata 
)
Update the metadata based on the logfile information

Definition at line 153 of file EvgenParserTool.py.

153  def updateMetadata(self, metadata):
154  ''' Update the metadata based on the logfile information'''
155  # If we aren't running MP, then forget it
156  if self.isMP<1:
157  self.msg.debug('Not running MP, nothing to do')
158  return metadata
159  # Print the updated metadata as we go, as well as updating the dictionary
160  # First by convention is the cross-section, which we have to calculate
161  denom = self.MetadataDict['sumOfPosWeightsNoFilter']-self.MetadataDict['sumOfNegWeightsNoFilter']
162  my_xsec = 0.
163  if denom > 0.:
164  my_xsec = self.MetadataDict['xsec_sum'] / denom
165  self.msg.info(f'cross-section (nb)= {my_xsec:e}')
166  metadata['cross-section (nb)'] = f'{my_xsec:e}'
167  # Now come all the fields that we had saved
168  self.msg.info('Updated metadata:')
169  for field in self.MetadataDict:
170  # Need to skip the cross section related fields
171  if field in metadata:
172  self.msg.info(f'{field} = {self.MetadataDict[field]:e}')
173  metadata[field] = f'{self.MetadataDict[field]:e}'
174  # Generator filter efficiency needs some special handling
175  geneff = 1.
176  if denom>0:
177  geneff = (self.MetadataDict['sumOfPosWeights']-self.MetadataDict['sumOfNegWeights'])/denom
178  self.msg.info(f'GenFiltEff = {geneff:e}')
179  if 'GenFiltEff' in metadata:
180  metadata['GenFiltEff'] = f'{geneff:e}'
181  return metadata
182 

Member Data Documentation

◆ FilterSeqDict

EvgenParserTool.evgenParserTool.FilterSeqDict

Definition at line 23 of file EvgenParserTool.py.

◆ FixHepMCDict

EvgenParserTool.evgenParserTool.FixHepMCDict

Definition at line 17 of file EvgenParserTool.py.

◆ isMP

EvgenParserTool.evgenParserTool.isMP

Definition at line 28 of file EvgenParserTool.py.

◆ MetadataDict

EvgenParserTool.evgenParserTool.MetadataDict

Definition at line 25 of file EvgenParserTool.py.

◆ msg

EvgenParserTool.evgenParserTool.msg

Definition at line 15 of file EvgenParserTool.py.

◆ TestHepMCDict

EvgenParserTool.evgenParserTool.TestHepMCDict

Definition at line 21 of file EvgenParserTool.py.


The documentation for this class was generated from the following file:
checkTP.report
report
Definition: checkTP.py:125
python.processes.powheg.ZZj_MiNNLO.ZZj_MiNNLO.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZj_MiNNLO.py:18
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65