/// \file /// \ingroup tutorial_tree /// \notebook -nodraw /// Read data from an ascii file and create a root file with an histogram and an ntuple. /// See a variant of this macro in basic2.C. /// /// \macro_code /// /// \author Rene Brun #include "Riostream.h" void basic() { // read file $ROOTSYS/tutorials/tree/basic.dat // this file has 3 columns of float data TString dir = gROOT->GetTutorialDir(); dir.Append("/tree/"); dir.ReplaceAll("/./","/"); ifstream in; in.open(Form("%signal.dat",dir.Data())); Float_t x,y,z,a,b,c; Int_t nlines = 0; auto f = TFile::Open("signal.root","RECREATE"); TH1F h1("h1","x distribution",100,-4,4); TNtuple ntuple("ntuple","data from ascii file","x:y:z:a:b:c"); while (1) { in >> x >> y >> z >> a >> b >> c; if (!in.good()) break; if (nlines < 6) printf("x=%8f, y=%8f, z=%8f, a=%8f, b=%8f, c=%8f\n",x,y,z,a,b,c); h1.Fill(x); ntuple.Fill(x,y,z,a,b,c); nlines++; } printf(" found %d points\n",nlines); in.close(); f->Write(); }