Package madgraph :: Package various :: Module histograms :: Class HwU
[hide private]
[frames] | no frames]

Class HwU

source code

object --+    
         |    
 Histogram --+
             |
            HwU

A concrete implementation of an histogram plots using the HwU format for reading/writing histogram content.

Nested Classes [hide private]
  ParseError
a class for histogram data parsing errors
Instance Methods [hide private]
 
__init__(self, file_path=None, weight_header=None, raw_labels=False, consider_reweights='ALL', selected_central_weight=None, **opts)
Read one plot from a file_path or a stream.
source code
 
addEvent(self, x_value, weights=1.0)
Add an event to the current plot.
source code
 
get(self, name) source code
 
add_line(self, names)
add a column to the HwU.
source code
 
get_uncertainty_band(self, selector, mode=0)
return two list of entry one with the minimum and one with the maximum value.
source code
 
get_formatted_header(self)
Return a HwU formatted header for the weight label definition.
source code
 
get_HwU_source(self, print_header=True)
Returns the string representation of this histogram using the HwU standard.
source code
 
output(self, path=None, format='HwU', print_header=True)
Ouput this histogram to a file, stream or string if path is kept to None.
source code
 
test_plot_compability(self, other, consider_type=True, consider_unknown_weight_labels=True)
Test whether the defining attributes of self are identical to histo, typically to make sure that they are the same plots but from different runs, and they can be summed safely.
source code
 
process_histogram_name(self, histogram_name)
Parse the histogram name for tags which would set its various attributes.
source code
 
get_HwU_histogram_name(self, format='human')
Returns the histogram name in the HwU syntax or human readable.
source code
 
parse_one_histo_from_stream(self, stream, all_weight_header, consider_reweights='ALL', raw_labels=False, selected_central_weight=None)
Reads *one* histogram from a stream, with the mandatory specification of the ordered list of weight names.
source code
 
trim_auxiliary_weights(self)
Remove all weights which are auxiliary (whose name end with '@aux') so that they are not included (they will be regenerated anyway).
source code
 
set_uncertainty(self, type='all_scale', lhapdfconfig='lhapdf-config')
Adds a weight to the bins which is the envelope of the scale uncertainty, for the scale specified which can be either 'mur', 'muf', 'all_scale' or 'PDF'.
source code
 
select_central_weight(self, selected_label)
Select a specific merging scale for the central value of this Histogram.
source code
 
rebin(self, n_rebin)
Rebin the x-axis so as to merge n_rebin consecutive bins into a single one.
source code

Inherited from Histogram: __add__, __div__, __mul__, __setattr__, __sub__, __truediv__, alter_weights, nice_string

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
get_HwU_wgt_label_type(cls, wgt_label)
From the format of the weight label given in argument, it returns a string identifying the type of standard weight it is.
source code
 
parse_weight_header(cls, stream, raw_labels=False)
Read a given stream until it finds a header specifying the weights and then returns them.
source code
 
get_x_optimal_range(cls, histo_list, weight_labels=None)
Function to determine the optimal x-axis range when plotting together the histos in histo_list and considering the weights weight_labels
source code
 
get_y_optimal_range(cls, histo_list, labels=None, scale='LOG', Kratio=False)
Function to determine the optimal y-axis range when plotting together the histos in histo_list and considering the weights weight_labels.
source code

Inherited from Histogram: combine

Static Methods [hide private]

Inherited from Histogram: ADD, DIVIDE, MULTIPLY, OFFSET, OPERATION, RESCALE, SINGLEHISTO_OPERATION, SUBTRACT

Class Variables [hide private]
  allowed_dimensions = [2]
hash(x)
  allowed_types = []
  output_formats_implemented = ['HwU', 'gnuplot']
  mandatory_weights = {'central value': 'central', 'dy': 'stat_e...
  weight_header_start_re = re.compile(r'^##.*')
  weight_header_re = re.compile(r'&\s*(?P<wgt_name>(\S|(\s(?!\s*...
  histo_start_re = re.compile(r'^\s*<histogram>\s*(?P<n_bins>\d+...
  a_float_re = '[\\+|-]?\\d+(\\.\\d*)?([EeDd][\\+|-]?\\d+)?'
  histo_bin_weight_re = re.compile(r'(?i)(?P<weight>[\+\|-]?\d+(...
  a_int_re = '[\\+|-]?\\d+'
  histo_end_re = re.compile(r'^\s*<\\histogram>\s*$')
  weight_label_scale = re.compile(r'(?i)^\s*mur\s*=\s*(?P<mur_fa...
  weight_label_PDF = re.compile(r'^\s*PDF\s*=\s*(?P<PDF_set>\d+)...
  weight_label_PDF_XML = re.compile(r'^\s*pdfset\s*=\s*(?P<PDF_s...
  weight_label_TMS = re.compile(r'^\s*TMS\s*=\s*(?P<Merging_scal...
  weight_label_alpsfact = re.compile(r'(?i)^\s*alpsfact\s*=\s*(?...
  weight_label_scale_adv = re.compile(r'(?i)^\s*dyn\s*=\s*(?P<dy...
  weight_label_PDF_adv = re.compile(r'^\s*PDF\s*=\s*(?P<PDF_set>...

Inherited from Histogram: allowed_axis_modes

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, file_path=None, weight_header=None, raw_labels=False, consider_reweights='ALL', selected_central_weight=None, **opts)
(Constructor)

source code 

Read one plot from a file_path or a stream. Notice that this constructor only reads one, and the first one, of the plots specified. If file_path was a path in argument, it would then close the opened stream. If file_path was a stream in argument, it would leave it open. The option weight_header specifies an ordered list of weight names to appear in the file specified. The option 'raw_labels' specifies that one wants to import the histogram data with no treatment of the weight labels at all (this is used for the matplotlib output).

Overrides: object.__init__

add_line(self, names)

source code 

add a column to the HwU. name can be a list

get_uncertainty_band(self, selector, mode=0)

source code 

return two list of entry one with the minimum and one with the maximum value. selector can be:

  • a regular expression on the label name
  • a function returning T/F (applying on the label name)
  • a list of labels
  • a keyword

output(self, path=None, format='HwU', print_header=True)

source code 

Ouput this histogram to a file, stream or string if path is kept to None. The supported format are for now. Chose whether to print the header or not.

test_plot_compability(self, other, consider_type=True, consider_unknown_weight_labels=True)

source code 

Test whether the defining attributes of self are identical to histo, typically to make sure that they are the same plots but from different runs, and they can be summed safely. We however don't want to overload the __eq__ because it is still a more superficial check.

parse_one_histo_from_stream(self, stream, all_weight_header, consider_reweights='ALL', raw_labels=False, selected_central_weight=None)

source code 

Reads *one* histogram from a stream, with the mandatory specification of the ordered list of weight names. Return True or False depending on whether the starting definition of a new plot could be found in this stream.

get_y_optimal_range(cls, histo_list, labels=None, scale='LOG', Kratio=False)
Class Method

source code 

Function to determine the optimal y-axis range when plotting together the histos in histo_list and considering the weights weight_labels. The option Kratio is present to allow for the couple of tweaks necessary for the the K-factor ratio histogram y-range.


Class Variable Details [hide private]

mandatory_weights

Value:
{'central value': 'central',
 'dy': 'stat_error',
 'xmax': 'boundary_xmax',
 'xmin': 'boundary_xmin'}

weight_header_re

Value:
re.compile(r'&\s*(?P<wgt_name>(\S|(\s(?!\s*(&|$))))+)(\s(?!(&|$)))*')

histo_start_re

Value:
re.compile(r'^\s*<histogram>\s*(?P<n_bins>\d+)\s*"\s*(?P<histo_name>(\\
S|(\s(?!\s*")))+)\s*"\s*$')

histo_bin_weight_re

Value:
re.compile(r'(?i)(?P<weight>[\+\|-]?\d+(\.\d*)?([EeDd][\+\|-]?\d+)?|Na\
N)')

weight_label_scale

Value:
re.compile(r'(?i)^\s*mur\s*=\s*(?P<mur_fact>[\+\|-]?\d+(\.\d*)?([EeDd]\
[\+\|-]?\d+)?)\s*muf\s*=\s*(?P<muf_fact>[\+\|-]?\d+(\.\d*)?([EeDd][\+\\
|-]?\d+)?)\s*$')

weight_label_PDF

Value:
re.compile(r'^\s*PDF\s*=\s*(?P<PDF_set>\d+)\s*$')

weight_label_PDF_XML

Value:
re.compile(r'^\s*pdfset\s*=\s*(?P<PDF_set>\d+)\s*$')

weight_label_TMS

Value:
re.compile(r'^\s*TMS\s*=\s*(?P<Merging_scale>[\+\|-]?\d+(\.\d*)?([EeDd\
][\+\|-]?\d+)?)\s*$')

weight_label_alpsfact

Value:
re.compile(r'(?i)^\s*alpsfact\s*=\s*(?P<alpsfact>[\+\|-]?\d+(\.\d*)?([\
EeDd][\+\|-]?\d+)?)\s*$')

weight_label_scale_adv

Value:
re.compile(r'(?i)^\s*dyn\s*=\s*(?P<dyn_choice>[\+\|-]?\d+)\s*mur\s*=\s\
*(?P<mur_fact>[\+\|-]?\d+(\.\d*)?([EeDd][\+\|-]?\d+)?)\s*muf\s*=\s*(?P\
<muf_fact>[\+\|-]?\d+(\.\d*)?([EeDd][\+\|-]?\d+)?)\s*$')

weight_label_PDF_adv

Value:
re.compile(r'^\s*PDF\s*=\s*(?P<PDF_set>\d+)\s+(?P<PDF_set_cen>\S+)\s*$\
')