ROOT
6.30.04
Reference Guide
All
Namespaces
Files
Pages
basic.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_tree
3
/// \notebook -nodraw
4
/// Read data from an ascii file and create a root file with an histogram and an ntuple.
5
/// See a variant of this macro in basic2.C.
6
///
7
/// \macro_code
8
///
9
/// \author Rene Brun
10
11
#include "
Riostream.h
"
12
void
basic() {
13
// read file $ROOTSYS/tutorials/tree/basic.dat
14
// this file has 3 columns of float data
15
TString dir = gROOT->GetTutorialDir();
16
dir.Append(
"/tree/"
);
17
dir.ReplaceAll(
"/./"
,
"/"
);
18
ifstream in;
19
in.open(Form(
"%sbasic.dat"
,dir.Data()));
20
21
Float_t x,y,z;
22
Int_t nlines = 0;
23
auto
f = TFile::Open(
"basic.root"
,
"RECREATE"
);
24
TH1F h1(
"h1"
,
"x distribution"
,100,-4,4);
25
TNtuple ntuple(
"ntuple"
,
"data from ascii file"
,
"x:y:z"
);
26
27
while
(1) {
28
in >> x >> y >> z;
29
if
(!in.good())
break
;
30
if
(nlines < 5) printf(
"x=%8f, y=%8f, z=%8f\n"
,x,y,z);
31
h1.Fill(x);
32
ntuple.Fill(x,y,z);
33
nlines++;
34
}
35
printf(
" found %d points\n"
,nlines);
36
37
in.close();
38
39
f->Write();
40
}
Riostream.h
tutorials
tree
basic.C
Generated on Tue May 5 2020 14:03:51 for ROOT by
1.8.5