使用 CERN ROOT 的 ntuple 直方图

Histogram with ntuple using CERN ROOT

不能obtain/fill 使用 ROOT 从 ntuple 开始直方图。

我一直在寻找以前的答案,他们都使用 ttree,包括 root 文档。我没有。对 root 并不陌生,但我在使用它时遇到了很多困难。 None 找到的方法适用于我的代码(或者我不知道如何实现它们)。

这或多或少是我在各处发现的:

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。我很讨厌 C++,我真的不喜欢它,也不理解它。

我期待一个漂亮的直方图,我可以在其中设置所有内容,例如标题、最大值和最小值、统计框等。默认情况下,root 通过 ntuple 执行此操作,但这不是我需要的。

非常感谢。

非常感谢你们,第一个答案很有效。 现在,我喜欢使用 python 而不是 ROOT。问题是,我的论文指导者(都是物理学家,都来自粒子)从来不想这样做。结果,用 c++ 和 ROOT 折磨了大约六个月。好拖沓。

再次感谢!