如何从3列.dat文件中创建ROOT直方图? [英] How to create ROOT histograms out of a 3 column .dat file?

查看:203
本文介绍了如何从3列.dat文件中创建ROOT直方图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个.dat文件,格式为:

I currently have a .dat file with format:

格式:Log(10,s22th13)deltacp chi ^ 2

Format: Log(10,s22th13) deltacp chi^2

-4 0 0.098127

-4 0 0.098127

-4 4 0.093642

-4 4 0.093642

-4 8 0.089323

-4 8 0.089323

-4 12 0.085185

-4 12 0.085185

-4 16 0.081242 ....

-4 16 0.081242 ....

我如何使用ROOT创建一个绘图,同时将指定的标签保留在.dat文件的顶部?

How would I create a plot using ROOT, keeping the labels specified at the top of the .dat file?

推荐答案

最简单的方法是使用TTree class读取文件:

The easiest way would be to read your file using TTree class:

    TTree *T = new TTree("ntuple","data from csv file");
    Long64_t nlines = T->ReadFile("data.csv");
    printf("found %lld points\n",nlines);

您的标题将用作分支的名称.然后,您可以使用以下方式绘制/保存直方图:

Your header will be used as names for branches. Then you can draw/save histograms using something like that:

    TH1F *hist = new TH1F("name","title", nbinsx,xlow,xup);
    T->Draw("branch>>name","","");

这篇关于如何从3列.dat文件中创建ROOT直方图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆