How to create ROOT histograms out of a 3 column .dat file?

久未见 提交于 2019-12-12 04:25:26

问题


I currently have a .dat file with format:

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

-4 0 0.098127

-4 4 0.093642

-4 8 0.089323

-4 12 0.085185

-4 16 0.081242 ....

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


回答1:


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","","");


来源:https://stackoverflow.com/questions/42474991/how-to-create-root-histograms-out-of-a-3-column-dat-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!