This example is a variant of hsimple.C but using a TTree instead of a TNtuple.
It shows:
- how to fill a Tree with a few simple variables.
- how to read this Tree
- how to browse and analyze the Tree via the TBrowser and TTreeViewer This example can be run in many different ways:
- Using the Cling interpreter
- Using the automatic compiler interface
.L tree104_tree.C or .L tree104_tree.C++
tree1()
One can also run the write and read parts in two separate sessions. For example following one of the sessions above, one can start the session: .L tree104_tree.C
read_tree();
void tree104_write()
{
TFile f(
"tree104.root",
"recreate");
TTree t1(
"t1",
"a simple Tree with simple variables");
t1.Branch(
"px", &px,
"px/F");
t1.Branch(
"py", &py,
"py/F");
t1.Branch(
"pz", &pz,
"pz/F");
t1.Branch(
"random", &random,
"random/D");
t1.Branch(
"ev", &ev,
"ev/I");
for (
Int_t i=0; i<10000; i++) {
pz = px * px + py * py;
ev = i;
}
}
void tree104_read()
{
t1->SetBranchAddress(
"px", &px);
t1->SetBranchAddress(
"py", &py);
t1->SetBranchAddress(
"pz", &pz);
t1->SetBranchAddress(
"random", &random);
t1->SetBranchAddress(
"ev", &ev);
auto hpxpy =
new TH2F(
"hpxpy",
"py vs px", 30, -3, 3, 30, -3, 3);
hpx->Fill(px);
hpxpy->Fill(px, py);
}
return;
t1->ResetBranchAddresses();
}
void tree104_tree()
{
tree104_write();
tree104_read();
}
int Int_t
Signed integer 4 bytes (int).
double Double_t
Double 8 bytes.
long long Long64_t
Portable signed long integer 8 bytes.
float Float_t
Float 4 bytes (float).
Using a TBrowser one can browse all ROOT objects.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
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.
1-D histogram with a float per channel (see TH1 documentation)
2-D histogram with a float per channel (see TH1 documentation)
A TTree represents a columnar dataset.
- Author
- Rene Brun
Definition in file tree104_tree.C.