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

Public Member Functions

def __init__ (self, tableObj, underflowThreshold, overflowThreshold)
 
def getWarningMsgs (self)
 
def getHistogram (self, name)
 
def cacheHistograms (self, dirName, prefix)
 
def getXWeightedIntegral (self, histName, isLog=True)
 
def saveToFile (self, fileName)
 
def normalizeColumns (self, denominator)
 
def fillTable (self, prefix='')
 
def defineColumns (self)
 
def fillColumns (self, histName='')
 
def postProcessing (self)
 

Public Attributes

 tableObj
 
 columns
 
 histograms
 
 expectedHistograms
 
 underflowThreshold
 
 overflowThreshold
 
 warningMsg
 

Detailed Description

@brief Class representing a single table

Base class trepresenting table. It defines basic behavior common for 
    all the tables like caching histograms or saving table to file. 

Definition at line 61 of file TableConstructorBase.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TableConstructorBase.TableConstructorBase.__init__ (   self,
  tableObj,
  underflowThreshold,
  overflowThreshold 
)
ROOT table directory object, storing subdirs with histograms

Definition at line 68 of file TableConstructorBase.py.

68  def __init__(self, tableObj, underflowThreshold, overflowThreshold):
69  '''ROOT table directory object, storing subdirs with histograms'''
70  self.tableObj = tableObj
71 
72  '''Dictionary storing the columns. Each column is identified by given name (key)'''
73  self.columns = OrderedDict()
74 
75  '''Map to cache expected histograms'''
76  self.histograms = {}
77 
78  '''List with expected histograms'''
79  self.expectedHistograms = []
80 
81  '''Number of underflow bins after which warning will be saved to metadata tree'''
82  self.underflowThreshold = underflowThreshold
83 
84  '''Number of overflow bins after which warning will be saved to metadata tree'''
85  self.overflowThreshold = overflowThreshold
86 
87  '''Overflow log'''
88  self.warningMsg = []
89 
90 

Member Function Documentation

◆ cacheHistograms()

def python.TableConstructorBase.TableConstructorBase.cacheHistograms (   self,
  dirName,
  prefix 
)
@brief Cache histograms in map for given directory

Save histograms in the map by their short name as a key. If the histogram 
with a given name is not found function logs an error.

@param[in] dirName Name of subdirectory to look for histograms
@param[in] prefix Prefix of the histogram name

Definition at line 104 of file TableConstructorBase.py.

104  def cacheHistograms(self, dirName, prefix):
105  ''' @brief Cache histograms in map for given directory
106 
107  Save histograms in the map by their short name as a key. If the histogram
108  with a given name is not found function logs an error.
109 
110  @param[in] dirName Name of subdirectory to look for histograms
111  @param[in] prefix Prefix of the histogram name
112 
113  '''
114  dirKey = [key for key in self.tableObj.GetListOfKeys() if key.GetName() == dirName]
115  if not dirKey:
116  log.error("Subdirectory %s not found", dirName)
117 
118  dirObj = dirKey[0].ReadObj()
119  for histName in self.expectedHistograms:
120  fullHistName = prefix + dirName + '_' + histName
121  hist = dirObj.Get(fullHistName)
122 
123  if not hist:
124  log.debug("Full name %s", fullHistName)
125  log.debug("Directory: %s", dirObj.ls())
126  log.error("Expected histogram %s not found", histName)
127  else:
128  # Check for under and overflows
129  # Under/overflow bin stores weighted value - we cannot base on entries
130  histIntegral = hist.Integral(0, hist.GetNbinsX() + 1) # Integral including overflows
131  overflowThreshold = self.overflowThreshold * histIntegral
132  overflow = hist.GetBinContent(hist.GetNbinsX() + 1)
133  if overflow > overflowThreshold:
134  log.warning("Histogram {0} contains overflow of {1}".format(fullHistName, overflow))
135  self.warningMsg.append("Overflow of {0} ({1} histogram integral) in {2}".format(overflow, histIntegral, fullHistName))
136 
137  underflowThreshold = self.underflowThreshold * histIntegral
138  underflow = hist.GetBinContent(0)
139  if underflow > underflowThreshold and not ignoreUnderflow(fullHistName):
140  log.warning("Histogram {0} contains underflow of {1}".format(fullHistName, underflow))
141  self.warningMsg.append("Underflow of {0} ({1} histogram integral) in {2}".format(underflow, histIntegral, fullHistName))
142 
143  self.histograms[histName] = hist
144 
145 

◆ defineColumns()

def python.TableConstructorBase.TableConstructorBase.defineColumns (   self)
@brief Define the columns for the table

Columns should be objects of class Column, added to the map self.columns.

Definition at line 226 of file TableConstructorBase.py.

226  def defineColumns(self):
227  ''' @brief Define the columns for the table
228 
229  Columns should be objects of class Column, added to the map self.columns.
230  '''
231  log.error("Should not call defineColumns on base class!")
232 
233 

◆ fillColumns()

def python.TableConstructorBase.TableConstructorBase.fillColumns (   self,
  histName = '' 
)
@brief Fill the columns with values 

Definition at line 234 of file TableConstructorBase.py.

234  def fillColumns(self, histName=''):
235  ''' @brief Fill the columns with values '''
236  log.error("Should not call fillColumns on base class!")
237 
238 

◆ fillTable()

def python.TableConstructorBase.TableConstructorBase.fillTable (   self,
  prefix = '' 
)
@brief Fill the table based on ROOT directory's content.

Definition at line 213 of file TableConstructorBase.py.

213  def fillTable(self, prefix=''):
214  ''' @brief Fill the table based on ROOT directory's content.'''
215 
216  self.defineColumns()
217 
218  # Fill the columns
219  for hist in self.tableObj.GetListOfKeys():
220  self.cacheHistograms(hist.GetName(), prefix)
221  self.fillColumns(hist.GetName())
222 
223  self.postProcessing()
224 
225 

◆ getHistogram()

def python.TableConstructorBase.TableConstructorBase.getHistogram (   self,
  name 
)
@brief Return cached histogram with given name

Definition at line 96 of file TableConstructorBase.py.

96  def getHistogram(self, name):
97  ''' @brief Return cached histogram with given name'''
98  if name not in self.histograms:
99  log.error("Histogram %s not found!", name)
100  return None
101  return self.histograms[name]
102 
103 

◆ getWarningMsgs()

def python.TableConstructorBase.TableConstructorBase.getWarningMsgs (   self)
@brief Raturn warning messages concerning histogram under/over flows 

Definition at line 91 of file TableConstructorBase.py.

91  def getWarningMsgs(self):
92  ''' @brief Raturn warning messages concerning histogram under/over flows '''
93  return self.warningMsg
94 
95 

◆ getXWeightedIntegral()

def python.TableConstructorBase.TableConstructorBase.getXWeightedIntegral (   self,
  histName,
  isLog = True 
)
@brief Get "total" value by integrating over a histogram, weighting every entry by its x-axis mean.

@param[in] histName Histogram name
@param[in] isLog If histogram is log x-axis, modifies how x-axis mean is computed for each bin.

@return Total value of the histogram.

Definition at line 146 of file TableConstructorBase.py.

146  def getXWeightedIntegral(self, histName, isLog = True):
147  ''' @brief Get "total" value by integrating over a histogram, weighting every entry by its x-axis mean.
148 
149  @param[in] histName Histogram name
150  @param[in] isLog If histogram is log x-axis, modifies how x-axis mean is computed for each bin.
151 
152  @return Total value of the histogram.
153  '''
154 
155  hist = self.getHistogram(histName)
156  if not hist:
157  return 0
158 
159  total = 0
160  for i in range(1, hist.GetXaxis().GetNbins()+1):
161  if isLog:
162  total += hist.GetBinContent(i) * hist.GetXaxis().GetBinCenterLog(i)
163  else:
164  total += hist.GetBinContent(i) * hist.GetXaxis().GetBinCenter(i)
165 
166  return total
167 
168 

◆ normalizeColumns()

def python.TableConstructorBase.TableConstructorBase.normalizeColumns (   self,
  denominator 
)
@brief Perform normalization on marked columns 

@param[in] denominator Value to normalize choosen columns

Definition at line 199 of file TableConstructorBase.py.

199  def normalizeColumns(self, denominator):
200  ''' @brief Perform normalization on marked columns
201 
202  @param[in] denominator Value to normalize choosen columns
203  '''
204  for columnName, column in self.columns.items():
205  if column.needNormalizing:
206  if fabs(denominator) < 1e-10:
207  log.error("Normalise denominator is zero. Setting %s to zero.", columnName)
208  column.content = [0] * len(column.content)
209  else:
210  column.content = [entry/denominator for entry in column.content]
211 
212 

◆ postProcessing()

def python.TableConstructorBase.TableConstructorBase.postProcessing (   self)
@brief Additional operations

Normalization in performed separatly!

Definition at line 239 of file TableConstructorBase.py.

239  def postProcessing(self):
240  ''' @brief Additional operations
241 
242  Normalization in performed separatly!
243  '''
244  pass

◆ saveToFile()

def python.TableConstructorBase.TableConstructorBase.saveToFile (   self,
  fileName 
)
@brief Function to save table content to csv file with specified fileName

@param[in] fileName  Name of the file to save the table

Definition at line 169 of file TableConstructorBase.py.

169  def saveToFile(self, fileName):
170  ''' @brief Function to save table content to csv file with specified fileName
171 
172  @param[in] fileName Name of the file to save the table
173  '''
174 
175  from TrigCostAnalysis.Util import convert
176  import csv
177 
178  with open(fileName, mode='w') as csvFile:
179  csvWriter = csv.writer(csvFile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
180 
181  header = []
182  desc = []
183  rows = []
184  for column in self.columns.values():
185  header.append(column.header)
186  desc.append(column.headerDesc)
187  content = [ convert(entry) for entry in column.content ]
188  rows.append(content)
189 
190  csvWriter.writerow(header)
191  csvWriter.writerow(desc)
192 
193  # Transpose columns to rows
194  rows = list(zip(*rows))
195  for row in rows:
196  csvWriter.writerow(row)
197 
198 

Member Data Documentation

◆ columns

python.TableConstructorBase.TableConstructorBase.columns

Definition at line 73 of file TableConstructorBase.py.

◆ expectedHistograms

python.TableConstructorBase.TableConstructorBase.expectedHistograms

Definition at line 79 of file TableConstructorBase.py.

◆ histograms

python.TableConstructorBase.TableConstructorBase.histograms

Definition at line 76 of file TableConstructorBase.py.

◆ overflowThreshold

python.TableConstructorBase.TableConstructorBase.overflowThreshold

Definition at line 85 of file TableConstructorBase.py.

◆ tableObj

python.TableConstructorBase.TableConstructorBase.tableObj

Definition at line 70 of file TableConstructorBase.py.

◆ underflowThreshold

python.TableConstructorBase.TableConstructorBase.underflowThreshold

Definition at line 82 of file TableConstructorBase.py.

◆ warningMsg

python.TableConstructorBase.TableConstructorBase.warningMsg

Definition at line 88 of file TableConstructorBase.py.


The documentation for this class was generated from the following file:
python.CostMetadataUtil.ignoreUnderflow
def ignoreUnderflow(histogramName)
Definition: CostMetadataUtil.py:128
vtune_athena.format
format
Definition: vtune_athena.py:14
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:808
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:71
TMVAToMVAUtils::convert
std::unique_ptr< MVAUtils::BDT > convert(TMVA::MethodBDT *bdt, bool isRegression=true, bool useYesNoLeaf=false)
Definition: TMVAToMVAUtils.h:114
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40