def mergeHistsFromMapping(hists, mapping, fillcolors=None): """ merge histograms from mappping. e.g. - hists {'a_1': Hist(), 'a_2': Hist(), ... , 'b_1': Hist(), 'b_2': Hist()} - mapping {'a': ['a_1', 'a_2',], 'b': ['b_1', 'b_2']} - fillcolors [optional] {'a': 'green', 'b': 'red'} - returns OrderedDict('a': Hist(), 'b': Hist()) sorted by Integral() """ from collections import OrderedDict CatHists = {} for cat, ds in mapping.items(): output = None for d in ds: if output is None: output = hists[d].Clone() ROOT.SetOwnership(output, False) else: output.Add(hists[d]) if fillcolors: output.fillcolor = fillcolors[cat] output.SetTitle(cat) CatHists[cat] = output return OrderedDict(sorted(CatHists.items(), key=lambda x: x[1].Integral()))
def ErrorBandFromHistStack(hstack, **kwargs): """ possion error band (TGraphAsymmError) from sum of `hstack` kwargs are forwarded for TGraphAsymmError property setting """ _sumStack = sumHistStack(hstack) stackError = asrootpy(_sumStack) #.poisson_errors() ROOT.SetOwnership(stackError, False) kwDefaults = { 'fillstyle': 3244, 'fillcolor': 'gray', 'drawstyle': 'e2', 'markersize': 0, 'legendstyle': 'F', 'title': 'stat. unc', } kwDefaults.update(kwargs) for k, v in kwDefaults.items(): setattr(stackError, k, v) return stackError