{ // example of macro to read data from an ascii file and // create a root file with an histogram and an ntuple. gROOT->Reset(); FILE *fp = fopen("/home/user/Amani/n-p-alpha-gamma __.txt","r"); Float_t E,Ef,Ep,Ap; Int_t ncols; Int_t nlines = 0; TFile *f = new TFile("file2.root","RECREATE"); TH1F *h1 = new TH1F("h1","x distribution",100,-4,4); TNtuple *data = new TNtuple("data","data from ascii file","E:Ef:Ep:Ap"); data.ReadFile("n-p-alpha-gamma __.txt"); while (1) { ncols = fscanf(fp,"%f %f %f %f",&E,&Ef,&Ep,&Ap); if (ncols < 0) break; if (nlines < 5) printf("E=%8f, Ef=%8f, Ep=%8f, Ap=%8f",E,Ef,Ep,Ap); h1->Fill(E); data->Fill(E,Ef,Ep,Ap); nlines++; } printf(" found %d points\n",nlines); fclose(fp); f->Write(); }