This example writes a tree with objects of the class Event.
It is a simplified version of $ROOTSYS/test/MainEvent.cxx to write the tree, and $ROOTSYS/test/eventb.C It shows:
- how to fill a Tree with an event class containing these data members:
- the difference in splitting or not splitting a branch
- how to read selected branches of the tree, and print the first entry with less than 587 tracks.
- how to browse and analyze the Tree via the TBrowser and TTreeViewer
This example can be run in many different ways:
- way1 using the Cling interpreter:
- way2 using the Cling interpreter:
- way3 using ACLIC:
.L ../test/libEvent.so
.x tree4.C++
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:
#include "../test/Event.h"
void tree4w()
{
TFile f(
"tree4.root",
"RECREATE");
TTree t4(
"t4",
"A Tree with Events");
Event *event = new Event();
t4.Branch(
"event_split", &event,16000,99);
t4.Branch(
"event_not_split", &event,16000,0);
char etype[20];
for (
Int_t ev = 0; ev <100; ev++) {
sprintf(etype,"type%d",ev%5);
event->SetType(etype);
event->SetHeader(ev, 200, 960312, random);
event->SetNseg(
Int_t(10*ntrack+20*sigmas));
event->SetFlag(
UInt_t(random+0.5));
event->SetTemperature(random+20.);
}
for(
UChar_t i0 = 0; i0 < 4; i0++) {
for(
UChar_t i1 = 0; i1 < 4; i1++) {
}
}
for (
Int_t t = 0; t < ntrack; t++) event->AddTrack(random);
}
}
void tree4r()
{
}
Event *event = new Event();
if (event->GetNtrack() > 587)continue;
nselected++;
if (nselected == 1) t4->
Show();
event->Clear();
}
if (
gROOT->IsBatch())
return;
}
void tree4() {
tree4w();
tree4r();
}
- Author
- Rene Brun
Definition in file tree4.C.