Example of a Tree where branches are variable length arrays A second Tree is created and filled in parallel.
Run this script with
In the function treer, the first Tree is open. The second Tree is declared friend of the first tree. TTree::Draw is called with variables from both Trees.
void tree3w() {
const Int_t kMaxTrack = 500;
TFile f(
"tree3.root",
"recreate");
t3->
Branch(
"ntrack",&ntrack,
"ntrack/I");
t3->
Branch(
"stat",stat,
"stat[ntrack]/I");
t3->
Branch(
"sign",sign,
"sign[ntrack]/I");
t3->
Branch(
"px",px,
"px[ntrack]/F");
t3->
Branch(
"py",py,
"py[ntrack]/F");
t3->
Branch(
"pz",pz,
"pz[ntrack]/F");
t3->
Branch(
"zv",zv,
"zv[ntrack]/F");
t3->
Branch(
"chi2",chi2,
"chi2[ntrack]/F");
TFile fr(
"tree3f.root",
"recreate");
t3f->
Branch(
"ntrack",&ntrack,
"ntrack/I");
t3f->
Branch(
"sumstat",&sumstat,
"sumstat/D");
t3f->
Branch(
"pt",pt,
"pt[ntrack]/F");
for (
Int_t i=0;i<1000;i++) {
Int_t nt = gRandom->Rndm()*(kMaxTrack-1);
ntrack = nt;
sumstat = 0;
for (
Int_t n=0;n<nt;n++) {
px[
n] = gRandom->Gaus(0,1);
py[
n] = gRandom->Gaus(0,2);
pz[
n] = gRandom->Gaus(10,5);
zv[
n] = gRandom->Gaus(100,2);
chi2[
n] = gRandom->Gaus(0,.01);
}
}
fr.cd();
}
void tree3r()
{
}
void tree3r2()
{
TPad *p =
new TPad(
"p",
"p",0.6, 0.4, 0.98, 0.8);
}
void tree3()
{
tree3w();
tree3r();
tree3r2();
}
- Author
- Rene Brun
Definition in file tree3.C.