How to simply make a histogram from .dat file

Hi,

this is the modern way to achieve this:

auto df = ROOT::Experimental::TDF::MakeCsvDataFrame("data.txt", false, ' ');
auto h = df.Histo1D("Col1")
h->Draw();

It has plenty of advantages, besides being the suggested way to code:

  1. You can easily convert your dataset to ROOT:
auto df = ROOT::Experimental::TDF::MakeCsvDataFrame("data.txt", false, ' ');
df.Snapshot("data", "data.root"); // <- one line is enough
auto h = df.Histo1D("Col1")
h->Draw();
  1. You can run using all the cores of your machine (not mutually exclusive with 1.)
ROOT::EnableImplicitMT(); // <- just adding this line is enough
auto df = ROOT::Experimental::TDF::MakeCsvDataFrame("data.txt", false, ' ');
df.Snapshot("data", "data.root");
auto h = df.Histo1D("Col1")
h->Draw();
  1. You can create several histograms in the same event loop, therewith limiting the disk access:
ROOT::EnableImplicitMT(); // <- just adding this line is enough
auto df = ROOT::Experimental::TDF::MakeCsvDataFrame("data.txt", false, ' ');
df.Snapshot("data", "data.root");
auto h = df.Histo1D("Col1");
auto h1 = df.Histo1D("Col0");
auto hWeighted = df.Histo1D("Col1", "Col0");
auto h2 = df.Histo2D("Col0", "Col1");
// ...

See all different options in these examples.

Best,
D