简体   繁体   English

使用 zfit 从 ROOT 文件导入数据集

[英]Import dataset from a ROOT file with cut using zfit

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.网站https://zfit.readthedocs.io/en/latest/getting_started/intro/data.html告诉我可以通过指定 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".例如,我想用树“ntuple”打开一个 ROOT 文件“test.root”。 The observables of the fit is x.拟合的可观察量是 x。

I can write我会写

data = zfit.Data.from_root("tese.root","ntuple","x") 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?如果我需要在树y>1和z>1中设置另外两个分支的cut,我该如何编写代码?

There are actually two ways as of today:截至目前,实际上有两种方法:

Using pandas使用 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.最通用的方法是先将数据加载到 pandas dataframe(使用 uproot),然后使用 from_pandas 加载到 zfit,在那里你可以给出一个 obs。 So you will need to first create a space with obs = zfit.Space('obsname', (lower, upper)).所以你需要先用 obs = zfit.Space('obsname', (lower, upper)) 创建一个空间。 Then you can use that in zfit.Data.from_pandas(...)然后你可以在 zfit.Data.from_pandas(...)

Loading with uproot can be (as an example):使用 uproot 加载可以是(作为示例):

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 ;最先进的方法是直接在from_root中给出限制; this is cutting edge development and will be available soon: https://github.com/zfit/zfit/pull/396这是最前沿的开发,即将推出: https://github.com/zfit/zfit/pull/396

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM