Problem reading sub branch from tree

I am new to root and I am having problems reading sub branches information out
of a root tree. Say I want to read the branch “fE” which is in the branch “brem.Pbrem”,
what I am doing is the following:

Float_t myvar;
TFile *inpfile = new TFile(fullname);
TTree inptree = (TTree) inpfile->Get(“EGAMMA”);
TBranch * branch=inptree->GetBranch(“brem.Pbrem.fE”);
branch -> SetAddress(&myvar);

Int_t nentries = (Int_t) inptree->GetEntries();
for (Int_t i=0;i<nentries;i++) {
cout << "myvar = "<< myvar << endl;


This code crashes at the line:

TBranch * branch=inptree->GetBranch(“brem.Pbrem.fE”);

because it does not see “fE”. The closest example I found on the manual is tree4r
but there, it seems one has to implement its own class Event. Do I have to do something similar or there is a simple way to get the data?
I included in attchm. some of the sub-branches I want to read as they are returned by:
“inptree -> Print();”.
branches.txt (2.78 KB)

When you do:

Float_t myvar; TFile *inpfile = new TFile(fullname); TTree *inptree = (TTree*) inpfile->Get("EGAMMA"); TBranch * branch=inptree->GetBranch("brem.Pbrem.fE"); branch -> SetAddress(&myvar);
you tell ROOT to read the variable length array in the
branch “brem.Pbrem.fE” into one single variable “myvar”.
Instead myvar should be an array with the maximum dimension
in the branch.

In the attachement you will find a small example to read
the tree4.root file generated by the tutorial tree4.C
without using a class.

tree4r.C (663 Bytes)

Sorry if I am not done asking…
Is there a way to clone a branch into a new tree? Say that I want to copy all the sub-branches brem.Pbrem.whatever into my new tree. Do I have to read out
each branch and fill the branch in the new tree or there is a way to copy it in one move?

thanks in advance,

see tutorials copytree.C, copytree2.C and copytree3.C