#include "Riostream.h" void basic() { // 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 //Author: Rene Brun // read file $ROOTSYS/tutorials/tree/basic.dat // this file has 3 columns of float data TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName()); dir.ReplaceAll("basic.C",""); dir.ReplaceAll("/./","/"); ifstream in; in.open(Form("%sCo_source.dat",dir.Data())); Float_t x,y; Int_t nlines = 0; TFile *f = new TFile("Co.root","RECREATE"); TH1F *h1 = new TH1F("h1","x distribution",200,-4,4); TNtuple *ntuple = new TNtuple("ntuple","data from ascii file","x:y"); while (1) { in >> x >> y; if (!in.good()) break; if (nlines < 5) printf("x=%f, y=%f",x,y); h1->Fill(x); ntuple->Fill(x,y); nlines++; } printf(" found %d points\n",nlines); in.close(); f->Write(); }