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
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:
{
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;
}
}
{
t1->SetBranchAddress(
"px", &px);
t1->SetBranchAddress(
"py", &py);
t1->SetBranchAddress(
"pz", &pz);
t1->SetBranchAddress(
"random", &
random);
t1->SetBranchAddress(
"ev", &
ev);
auto hpx =
new TH1F(
"hpx",
"px distribution", 100, -3, 3);
auto hpxpy =
new TH2F(
"hpxpy",
"py vs px", 30, -3, 3, 30, -3, 3);
}
return;
t1->ResetBranchAddresses();
}
{
}
R__EXTERN TRandom * gRandom
Using a TBrowser one can browse all ROOT objects.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
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)
Double_t Rndm() override
Machine independent random number generator.
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
A TTree represents a columnar dataset.
- Author
- Rene Brun
Definition in file tree104_tree.C.