Import dataset from a ROOT file with cut using zfit

119 Views Asked by At

I am trying to perform a fit to a tree. But I need to add some cut to the branches which are not the observables of the fit. Website https://zfit.readthedocs.io/en/latest/getting_started/intro/data.html tells me that I can include cuts in the dataset by specifying the root_dir_options. But I don't know how to operate it.

For example, I want to open a ROOT file "test.root" with tree "ntuple". The observables of the fit is x.

I can write

data = zfit.Data.from_root("tese.root","ntuple","x")

If I need to set cut of two other branches in the tree y>1 and z>1, how can I write the code?

1

There are 1 best solutions below

0
On

There are actually two ways as of today:

Using pandas

The most general way is to load the data first into a pandas dataframe (using uproot) and then load into zfit with from_pandas, there you can give an obs. So you will need to first create a space with obs = zfit.Space('obsname', (lower, upper)). Then you can use that in zfit.Data.from_pandas(...)

Loading with uproot can be (as an example):

branches = ["pt1", "pt2"]
with uproot.open(path_root) as f:
    tree = f["events"]
    true_data = tree.arrays(branches, library="pd")

Cutting edge

The cutting edge way is to give the limits directly in from_root; this is cutting edge development and will be available soon: https://github.com/zfit/zfit/pull/396