Logo ROOT   6.14/05
Reference Guide
basic2.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tree
3 /// \notebook -js
4 /// Create can ntuple reading data from an ascii file.
5 /// This macro is a variant of basic.C
6 ///
7 /// \macro_image
8 /// \macro_code
9 ///
10 /// \author Rene Brun
11 
12 void basic2() {
13  TString dir = gROOT->GetTutorialDir();
14  dir.Append("/tree/");
15  dir.ReplaceAll("/./","/");
16 
17  TFile *f = new TFile("basic2.root","RECREATE");
18  TH1F *h1 = new TH1F("h1","x distribution",100,-4,4);
19  TTree *T = new TTree("ntuple","data from ascii file");
20  Long64_t nlines = T->ReadFile(Form("%sbasic.dat",dir.Data()),"x:y:z");
21  printf(" found %lld points\n",nlines);
22  T->Draw("x","z>2");
23  T->Write();
24 }
long long Long64_t
Definition: RtypesCore.h:69
double T(double x)
Definition: ChebyshevPol.h:34
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:285
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:47
#define gROOT
Definition: TROOT.h:410
Basic string class.
Definition: TString.h:131
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:567
#define f(i)
Definition: RSha256.hxx:104
TString & Append(const char *cs)
Definition: TString.h:559
TH1F * h1
Definition: legend1.C:5
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TTree.cxx:9298
char * Form(const char *fmt,...)
virtual Long64_t ReadFile(const char *filename, const char *branchDescriptor="", char delimiter=' ')
Create or simply read branches from filename.
Definition: TTree.cxx:7234
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:357
A TTree object has a header with a name and a title.
Definition: TTree.h:70
const char * Data() const
Definition: TString.h:364