Reading vectors from a tree

Hi! I am a begginer using trees, I have .root file with a lot of variables, I have just declared all of them in my .C document, I declared them like:

vector<double> *Station=0;

after that I do:


I want to work with this variable as a vector, so I do:
Double_t *sig = new Double_t [n]; //n is the number of entries in the tree
sig =Station->data();

After that I do a cout to check that everything is correct but it isn’t because it doesn’t show me nothing.

Could you tell me where is the problem?
Thank you very much.

Do you mean you want to retrieve a tree variable in a C++ vector ?
If that’s the case the following tutorial may help you:

Thank you very much!!
Variables 0, 5 and 6 are x, y and z? Why they are that name??

GetVal works with Variables Number.

Please note that TTree::GetVal retrieves the results of the most recent TTree::Draw and nothing else.

Something like this should work:

vector<double> *Station = 0;
t->SetBranchAddress("Station", &Station);
Long64_t n = t->GetEntries();
for (Long64_t i = 0; i < n; i++) {
  ULong_t nsig = Station->size(); // MUST be done for every tree entry
  double *sig = Station->data(); // MUST be done for every tree entry
  for (ULong_t j = 0; j < nsig; j++) {
    std::cout << i << " : " << j << " : " << sig[j] << std::endl;
t->ResetBranchAddresses(); // disconnect from local variables
delete Station; // cleanup

Yes, it is interesting if you want to get the values corresponding to combination of variables.