So I have a tree from a data file that I want to create a histogram from this data. The following is my code:
TTree *T = new TTree("ntuple","csv file data");
Long64_t nlines = T->ReadFile(TString::Format("%sdata%d.csv",dir.Data(), i),"a:b:c:d:e");
printf(" found %lld points\n",nlines);
TH1F *H = new TH1F("H", "signal distribution", 100000, -1, 1);
T->Draw("a","b");
I have this inside a for loop, looping over several data files in the directory.
I have no trouble drawing the tree, it works perfectly. But I want to fill the histogram with this data and plot it so that I can use its drawing and fitting options.
I tried
H->Fill(nlines);
and then drawing it, but it didn’t work.
I’m sure it’s a relatively simple step that I am missing, but it’s tripping me up.
Hi,
if you have access to ROOT 6.10, this is also the perfect use case for TDataFrame:
TTree t("ntuple","csv file data");
t.ReadFile(TString::Format("%sdata%d.csv",dir.Data(), i),"a:b:c:d:e");
ROOT::Experimental::TDataFrame d(t);
auto h = d.Histo1D("a", "b"); // create histogram of column a using b as weights
h->Draw();