Read tree and create Graph


I’ve a problem with my programme. It should read a tree and create a Graph. But it seems that it can’t read the data out of the tree or fill the Graph proberly. I can’t see the error…
The branches of the tree are arrays . I want to read the first 2000 Entries of the arrays time and temp and plot afterwards temp vs. time, but it doesn’t work.

Many thanks for any help

Draw.C (1.53 KB)

You haveFloat_t time; ... tree->SetBranchAddress("time",&time);but you say[quote]The branches of the tree are arrays .[/quote]So most likely you did not set the variable correctly and forgot loop over the internal array (temp and time)


Thank you very much for the reply !
I’ve used the Declaration out of the automatically generated class… my arrays are declared as TArrayD when I fill the tree. Is there already a mistake in the filling of the tree ?
How should I set the variables correctly ? is ist possible with
TArrayD time or have I to use double_t time[ ] ?
I’ve tried to read out the tree with the code below, but it still doesn’t work…
(The tree is filled and reat in the last part of the programme)

Many thinks for any support.
Readallc.C (7.06 KB)

You have: TArrayD *ELMBmaparr = new TArrayD(mlines); .... t1->Branch("ELMBarr",ELMBarr, "ELMBarr(nlines)/D"); ... has 2 fatals errors. The correct syntax for a leaflist array (where you pass a struct and describe your self the content) is with a bracket ‘[’ and not a paranthesis:

t1->Branch("ELMBarr",ELMBarr, "ELMBarr[nlines]/D");However TArrayD is not a simple array of double and your description is inaccurate and you also did not create a branch to hold the value of nlines. TArrayD is an object and ROOT already has a directory for it, so you can simply use:

t1->Branch("ELMBarr", &ELMBarr);Then to use it on the read side you need to do: TArrayD *ELMBmaparr = new TArrayD(mlines); // or 0 t1->SetBranchAddress("ELMBarr",&ELMBmaparr);

The I read your code a little further and you have:

for(Int_t i=0; nlines > i ; ++i ) { h -> Fill(); }which results in your tree being filled with nlines times the exact same information (since you do not change the data object in the loop).

So it seems that you want something more like:

Double_t ELMBarr_value; t1->Branch("ELMBarr",&ELMBarr_value, "ELMBarr/D"); for(Int_t i=0; nlines > i; i++) { ELMBarr_value = ELMBarr[i]; h -> Fill(); }Of course in this case you might also be able to completely remove the TArrayD step by reorganizing your loop.