Getting entries from a TTree

I am new to ROOT, so this is a very basic question. I have a tree called D0Tree, and it has a branch called “NV0”. There are 50 entries in D0Tree, and NV0 is an integer for each entry. I want to store these integers in an array so I can do some analysis, but I am getting errors. I did something like this:

int nevents = D0Tree->GetEntries();
int NV0array[nevents];

for(int j=0; j<nevents; j++) {
D0Tree->GetEntry(j);
NV0array[j] = D0Tree->NV0;
}

I get the following error:
Error: Failed to evaluate class member ‘NV0’ (D0Tree->NV0)
The problem is somewhere in the for loop, but I don’t know the right way to do it. Thanks for the help.

You have several solutions depending if you simply want to read one single variable or more

1- Use TTree::MakeClass to generate a skeleton analysis code.
do:

D0Tree->MakeClass("T"); //this generates T.h and T.C edit T.C with inside the loop NV-Array[j] = NVO;
2- Set the branch address

[code] int nevents = D0Tree->GetEntries();
int NV0array[nevents];
int NVO;
D0Tree->SetBranchAddress(“NV0”,&NV0);
TBranch *bNVO = DOTree->GetBranch(“NVO”);

for(int j=0; j<nevents; j++) {
D0Tree->GetEntry(j); or better bNVO->GetEntry(j)
NV0array[j] = NV0;
}

[/code]3- Use TLeaf::GetValue

[code] int nevents = D0Tree->GetEntries();
int NV0array[nevents];
TLeaf *leafNVO = D0Tree->GetLeaf(“NVO”);

for(int j=0; j<nevents; j++) {
leafNVO->GetBranch()->GetEntry(j);
NV0array[j] = (int)leafNVO->GetValue();
}
[/code]
4- Use TTree::Draw

D0Tree->Draw("NVO","","goff"); int nevents = D0Tree->GetEntries(); int NV0array[nevents]; for(int j=0; j<nevents; j++) { NV0array[j] = D0Tree->GetV1()[j]; }
Please read the tutorials and Users Guide
$ROOTSYS/tutorials/tree/*.C

Rene

Thank you!