MPF.histProjector module

MPF.histProjector.HP

alias of MPF.histProjector.HPDefaults

class MPF.histProjector.HPDefaults[source]
aliases = None
autoBinning = False
binLowEdges = None
cut = '1'
nbins = 1
varexp = '1'
weight = '1'
xmax = 1.5
xmin = 0.5
class MPF.histProjector.HistProjector[source]

Helper class for projecting histograms from trees. Will mostly be used by ProcessProjector() and classes inheriting from it.

fillHists(compile=False)[source]

Fill registered histograms using MultiHistDrawer()

static getHash(**kwargs)[source]

Returns a hash of the given kwargs. Only takes kwargs - to be independend of how exactly the functions are called (the kwargs are sorted)

static getMHDKwargs(**kwargs)[source]

Returns only the kwargs which are supposed to be put into multihistdrawer. Also applies defaults to have a unique description.

getTH1Path(**kwargs)[source]

Projects a TTree from a path or multiple paths (ROOT file(s)) into a histogram. Returns a prefilled histogram if it exists (see registerTH1Path()).

Parameters:
  • treeName – name of the TTree inside the ROOT file(s)
  • cut – selection expression
  • paths – path(s) to the ROOT file(s) containing the TTree
  • varexp – expression to be filled into the histogram, default “1”
  • weight – additional expression, to be multiplied with cut, default “1”
  • xmin – minimum value to be filled into the histogram, default 0.5
  • xmax – maximum value to be filled into the histogram, default 1.5
  • nbins – number of bins between xmin and xmax, default 1
  • binLowEdges – list of low edges for variable binning, the first value is the lower bound of the first bin, the last value the upper bound of the last bin. If given, xmin, xmax and nbins are ignored.
  • autoBinning – use “free” TTree::Draw instead of fixed binning. If set True, all other binning options are ignored, default False
getTH1PathTrees(paths_treeNames, cut, **kwargs)[source]

Returns a merged hist for list of different trees in different files. The list is expected in the following format:

[
  (path1, treeName1),
  (path2, treeName2),
  ...
]

See getTH1Path() for parameters.

getYieldPath(**kwargs)[source]

Projects a TTree from a path and returns a tuple of selected entries, the weighted entries and the quadratically summed error

Parameters:
  • paths – path(s) to the ROOT file(s) containing the TTree
  • treeName – name of the TTree inside the ROOT file(s)
  • cut – selection expression
  • weight – additional expression, to be multiplied with cut, default “1”
getYieldsDict(treeName, cutsDict, *paths, **kwargs)[source]

Fetches yields for each selection in cutsDict and returns a dictionary containing the unweighted, weighted yields and the error.

Parameters:weight – if given, apply this weight for all selections
getYieldsHist(treeName, cutsDict, *paths, **kwargs)[source]

Fetches yields for each selection in cutsDict and fills a histogram with one bin per selection - carrying the dict key as label.

Parameters:weight – if given, apply this weight for all selections
static projectTH1PathStatic(*args, **kwargs)[source]

Projects a TTree from a path or multiple paths (ROOT file(s)) into a histogram. Recommended usage via getTH1Path()

static projectTH1Static(tree, cut='1', weight='1', xmin=0.5, xmax=1.5, nbins=1, binLowEdges=None, autoBinning=False, varexp='1', aliases=None)[source]

Base functon to project from a TTree into a histogram Recommended usage via getTH1Path()

static projectTH2Static(tree, cut, weight, **kwargs)[source]
registerTH1Path(treeName, cut, *paths, **kwargs)[source]

Register a histogram to be projected later. See getTH1Path() for parameters.

All registered histograms are filled when fillHists() is called.

registerYieldPath(treeName, cut, *paths, **kwargs)[source]

Register a histogram for a treeName and path(s) to be prefilled later (for retrieving a yield). Can be fetched later by calling getYieldPath

registerYieldsDict(treeName, cutsDict, *paths, **kwargs)[source]

Register a yields dict. Can be fetched later by calling getYieldsDict() or getYieldsHist()

registerYieldsHist(treeName, cutsDict, *paths, **kwargs)

Register a yields dict. Can be fetched later by calling getYieldsDict() or getYieldsHist()

setAlias(aliasName, aliasFormula)[source]

Define an alias that is added to each tree that is drawn. Currently not working for multiHistDraw (fillHists()).

exception MPF.histProjector.TTreeProjectException[source]

Bases: exceptions.Exception

exception MPF.histProjector.noTreeException[source]

Bases: exceptions.Exception