ROOT
Version v6.32
master
v6.34
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
hsimpleReader.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_tree
3
/// \notebook
4
/// TTreeReader simplest example.
5
///
6
/// Read data from hsimple.root (written by hsimple.C)
7
///
8
/// \macro_code
9
///
10
/// \author Anders Eie, 2013
11
12
#include "
TFile.h
"
13
#include "
TH1F.h
"
14
#include "
TTreeReader.h
"
15
#include "
TTreeReaderValue.h
"
16
17
void
hsimpleReader
() {
18
// Create a histogram for the values we read.
19
auto
myHist
=
new
TH1F
(
"h1"
,
"ntuple"
,100,-4,4);
20
21
// Open the file containing the tree.
22
auto
myFile
=
TFile::Open
(
"hsimple.root"
);
23
if
(!
myFile
||
myFile
->IsZombie()) {
24
return
;
25
}
26
// Create a TTreeReader for the tree, for instance by passing the
27
// TTree's name and the TDirectory / TFile it is in.
28
TTreeReader
myReader
(
"ntuple"
,
myFile
);
29
30
// The branch "px" contains floats; access them as myPx.
31
TTreeReaderValue<Float_t>
myPx
(
myReader
,
"px"
);
32
// The branch "py" contains floats, too; access those as myPy.
33
TTreeReaderValue<Float_t>
myPy
(
myReader
,
"py"
);
34
35
// Loop over all entries of the TTree or TChain.
36
while
(
myReader
.Next()) {
37
// Just access the data as if myPx and myPy were iterators (note the '*'
38
// in front of them):
39
myHist
->Fill(*
myPx
+ *
myPy
);
40
}
41
42
myHist
->Draw();
43
}
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
TFile.h
TH1F.h
TTreeReaderValue.h
TTreeReader.h
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TFile::Open
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:4094
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:621
TTreeReader
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition
TTreeReader.h:44
tutorials
tree
hsimpleReader.C
ROOT v6-32 - Reference Guide Generated on Sun Apr 6 2025 05:41:37 (GVA Time) using Doxygen 1.10.0