Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
hsimpleReader.C File Reference

Detailed Description

View in nbviewer Open in SWAN
TTreeReader simplest example.

Read data from hsimple.root (written by hsimple.C)

#include "TFile.h"
#include "TH1F.h"
#include "TTreeReader.h"
void hsimpleReader() {
// Create a histogram for the values we read.
auto myHist = new TH1F("h1","ntuple",100,-4,4);
// Open the file containing the tree.
auto myFile = TFile::Open("hsimple.root");
if (!myFile || myFile->IsZombie()) {
return;
}
// Create a TTreeReader for the tree, for instance by passing the
// TTree's name and the TDirectory / TFile it is in.
// The branch "px" contains floats; access them as myPx.
// The branch "py" contains floats, too; access those as myPy.
// Loop over all entries of the TTree or TChain.
while (myReader.Next()) {
// Just access the data as if myPx and myPy were iterators (note the '*'
// in front of them):
myHist->Fill(*myPx + *myPy);
}
myHist->Draw();
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:4130
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:647
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:46
Author
Anders Eie, 2013

Definition in file hsimpleReader.C.