Help with reading a TTree

Dear experts,
I have a problem that is probably very easy to solve but I don’t know how to. I will appreciate if you can help me.
In my code, I make a TTree called “CharmoniumTree” and fill it after reading another TTree (saved as a root file). The CharmoniumTree is made and filled successfully. Now I would like to read values from my CharmoniumTree in the same code and do some calculations. The leaves of the Tree are vectors.
I get the entries in a loop using “CharmoniumTree->GetEntry(i);” command. Then I do the following, for example, “CharmoniumTree->PsiMass->at(0)” (at(0) is because the leaves has only one entry).
But I get the following error:
Error in TRint::HandleTermInput(): std::out_of_range caught: vector::_M_range_check
I know the problem is the way I try to read the branch “PsiMass” from the “CharmoniumTree” but I don’t know how to solve it.
Thanks for the help in advance

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

if ( CharmoniumTree &&
     CharmoniumTree->PsiMass &&
     (CharmoniumTree->PsiMass->size() > 0) ) {
  std::cout << CharmoniumTree->PsiMass->at(0) << std::endl;

Hi @Wile_E_Coyote ,
Thank you very much for your quick response. It perfectly solved the problem. Just for my own curiosity, could you please tell me why these conditions are necessary? I assume they are to ensure that there is no empty entry when reading the branch (for example PsiMass) but I know the branches (or its leaves) are not empty since if I just save the Tree and look at it (using TBrowser) I will see the expected number of events.
Thank you

Hi @Natilus ,
for every TTree entry PsiMass is a different vector. For some entries, the vector is empty. TBrowser skips the empty vectors when drawing.

I hope this clarifies it.

Hi @eguiraud ,
Thank you for the explanation. It’s perfectly clear.