swh:1:snp:af87cd67498ef4fe47c76ed3e7caffe5b61facaf
Raw File
Tip revision: b604d25f6fae57dca2b25814d36b078b31da26c4 authored by Unknown Author on 23 August 2002, 12:10:17 UTC
This commit was manufactured by cvs2svn to create tag 'v3-03-08'.
Tip revision: b604d25
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 <iostream.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", ios::in);

   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