Exemple #1
0
def test_new_histogram_in_histomanager(test_histogram):
    _, histogram = test_histogram
    histoname = histogram.title
    histogram_manager = HistoManager()
    histogram_manager.new_histogram(histogram)

    assert_histogram_equality(histogram, histogram_manager[histoname])
Exemple #2
0
def create_histomanager_from_dicts(histobins_dict,
                                   histolabels_dict,
                                   histoscales_dict,
                                   init_fill_dict=None):
    """Creates and returns a HistoManager from a dict of bins
    and a given of labels with identical keys.

    Parameters
    ----------
    histobins_dict   : dict
    Dictionary with keys equal to histogram names
    and values equal to the binning.
    histolabels_dict : dict
    Dictionary with keys equal to histogram names 
    and values equal to the axis labels.
    histoscales_dict : dict
    Dictionary with keys equal to histogram names 
    and values equal to the y axis scale.
    init_fill_dict   : dict, optional
    Dictionary with keys equal to histogram names 
    and values equal to an initial filling.
    """
    histo_manager = HistoManager()
    if init_fill_dict is None:
        init_fill_dict = dict()

    for title, bins in histobins_dict.items():
        histo_manager.new_histogram(Histogram(title, bins,
                                              histolabels_dict [title],
                                              histoscales_dict [title],
                                              init_fill_dict.get(title, None)))
    return histo_manager
Exemple #3
0
def join_histo_managers(histo_manager1, histo_manager2):
    """Joins two HistoManager.
    If they share histograms, the histograms are sumed.

    Parameters
    ----------
    histo_manager1, histo_manager2 : HistoManager objects to be joined.
    """
    new_histogram_manager = HistoManager()
    list_of_histograms    = set(histo_manager1.histos) | set(histo_manager2.histos)
    for histoname in list_of_histograms:
        histo1 = histo_manager1.histos.get(histoname, None)
        histo2 = histo_manager2.histos.get(histoname, None)
        try:
            new_histogram_manager.new_histogram(histo1 + histo2)
        except ValueError:
            print(f"Histograms with name {histoname} have not been added due to"
                    " incompatible binning.")
    return new_histogram_manager