Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tree102_basic.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 tree101_basic.C
6///
7/// \macro_image
8/// \macro_code
9///
10/// \author Rene Brun
11
12void tree102_basic()
13{
14 TString dir = gROOT->GetTutorialDir();
15 dir.Append("/io/tree/");
16 dir.ReplaceAll("/./", "/");
17
18 auto f = TFile::Open("tree102.root", "RECREATE");
19 auto h1 = new TH1F("h1", "x distribution", 100, -4, 4);
20 auto T = new TTree("ntuple", "data from ascii file");
21 Long64_t nlines = T->ReadFile(TString::Format("%sbasic.dat", dir.Data()), "x:y:z");
22 printf(" found %lld points\n", nlines);
23 T->Draw("x", "z>2");
24 T->Write();
25}
#define f(i)
Definition RSha256.hxx:104
long long Long64_t
Definition RtypesCore.h:69
#define gROOT
Definition TROOT.h:406
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4086
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
TString & Append(const char *cs)
Definition TString.h:572
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
A TTree represents a columnar dataset.
Definition TTree.h:79
TH1F * h1
Definition legend1.C:5
double T(double x)