【发布时间】:2019-08-16 07:08:35
【问题描述】:
无法使用 ROOT 从 ntuple 获取/填充直方图。
我一直在寻找以前的答案,他们都使用 ttree,包括根文档。我没有。不是新手,但我在使用它时遇到了很多困难。找到的方法都不适用于我的代码(或者我不知道如何实现它们)。
这或多或少是我在各处发现的:
https://root.cern.ch/root/roottalk/roottalk03/2620.html
但不,我正在做 TH1F,我没有 ttree(见下面的代码)
{
gROOT->Reset();
#include "Riostream.h"
#include <iostream>
#include <fstream>
in.open( "somefile.dat");
TNtuple *ntuple = new TNtuple("ntuple","some data from ascii file","index1:index2:index3");
//declare variables, create histograms
Double_t x,y,Price[215000],Diff[215000],Ret[215000],trend, Data[215000];
TFile *f = new TFile("TrendsCountBove.root","RECREATE");
TH1F *h1 = new TH1F("h1","Retornos",100,-0.3,0.3);
TH1F *histo = new TH1F ("hist_from_ntuple", "some title", nbins, min,max);
//do some stuff (didn't paste all calculations i do, but that works fine)
for (Int_t i = 0; i+1 < nlines-1; i++) {
Diff[i] = Price[i+1]-Price[i];
Ret[i] = TMath::Log(Price[i+1])-TMath::Log(Price[i]);
h1->Fill(Ret[i]);
ntuple->Fill(i*1.0,Ret[i],Price[i+1]);
}
所以,一切正常,完全没有问题。但是,如果有人可以尽可能详细地解释我如何用 index1、2 或 3 填充 histo
我希望有一个漂亮的直方图,我可以在其中设置所有内容,如标题、最大值和最小值、统计框等。默认情况下,root 通过 ntuple 进行设置,但这不是我需要的。
非常感谢。
【问题讨论】:
-
TNtuple 继承自 TTree,所以我可以用 TTree 做的事情也可以用 TNtuple 做。因此,如果您看到带有树的示例,您应该能够使用它们。 IE。
ntuple->Draw("branchname>>histname");. -
如果您不喜欢 C++,为什么不尝试将 Python 与 PyROOT 结合使用 - root.cern.ch/pyroot。或者甚至完全放弃 ROOT 并尝试类似 NumPy / MatPlotlib matplotlib.org?
-
其他不错的python接口:root_numpy和root_pandas。这是有限的,但非常适合将 ROOT 树加载到 Numpy 数组或 Pandas 数据帧中,并且之后大部分情况下都可以在没有 ROOT 的情况下工作。
标签: root-framework