Revision 5a21da3b72efd44377f9d4b1a214c8186bac5df3 authored by Rene Brun on 05 March 2004, 07:47:40 UTC, committed by Rene Brun on 05 March 2004, 07:47:40 UTC

git-svn-id: http://root.cern.ch/svn/root/trunk@8328 27541ba8-7e3a-0410-8455-c3a389f83636
1 parent ddc68ca
Raw File
basic.C
{
//   example of macro to read data from an ascii file and
//   create a root file with an histogram and an ntuple.
   gROOT->Reset();
#include "Riostream.h"

   ifstream in;
// we assume a file basic.dat in the current directory
// this file has 3 columns of float data
   in.open("basic.dat");

   Float_t x,y,z;
   Int_t nlines = 0;
   TFile *f = new TFile("basic.root","RECREATE");
   TH1F *h1 = new TH1F("h1","x distribution",100,-4,4);
   TNtuple *ntuple = new TNtuple("ntuple","data from ascii file","x:y:z");

   while (1) {
      in >> x >> y >> z;
      if (!in.good()) break;
      if (nlines < 5) printf("x=%8f, y=%8f, z=%8f\n",x,y,z);
      h1->Fill(x);
      ntuple->Fill(x,y,z);
      nlines++;
   }
   printf(" found %d points\n",nlines);

   in.close();

   f->Write();
}
back to top