ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
basic2.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tree
3 ///
4 /// Create can ntuple reading data from an ascii file.
5 /// This macro is a variant of basic.C
6 /// \macro_image
7 /// \macro_code
8 /// \author Rene Brun
9 
10 void basic2() {
11  TString dir = gSystem->UnixPathName(__FILE__);
12  dir.ReplaceAll("basic2.C","");
13  dir.ReplaceAll("/./","/");
14 
15  TFile *f = new TFile("basic2.root","RECREATE");
16  TH1F *h1 = new TH1F("h1","x distribution",100,-4,4);
17  TTree *T = new TTree("ntuple","data from ascii file");
18  Long64_t nlines = T->ReadFile(Form("%sbasic.dat",dir.Data()),"x:y:z");
19  printf(" found %lld points\n",nlines);
20  T->Draw("x","z>2");
21  T->Write();
22 }
long long Long64_t
Definition: RtypesCore.h:69
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Basic string class.
Definition: TString.h:137
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1020
const char * Data() const
Definition: TString.h:349
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:8780
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
char * Form(const char *fmt,...)
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:360
virtual Long64_t ReadFile(const char *filename, const char *branchDescriptor="", char delimiter= ' ')
Create or simply read branches from filename.
Definition: TTree.cxx:6801
A TTree object has a header with a name and a title.
Definition: TTree.h:98