Access TVector3 in Tree

Dear all,
a trivial question: I want to read a TVector3 in my tree, but none of the ways I found with the search function worked so far. My latest attempt:

[code] TVector3 *faxis= new TVector3();
my_tree->SetBranchStatus(“faxis”, 1);
my_tree->SetBranchAddress(“faxis”, &faxis);

for(Int_t i = 0; i <no_of_entries; i++){
my_tree->GetEntry(i);
histo1->Fill(faxis->fX);
}
[/code]

The “fX” is a private data member of the TVector3 class, so you cannot access it directly -> try “faxis->Px()”.

Ok, but I still get only Zeros.

Attach a small ROOT file with your tree so that we can inspect it.

I can only offer this:
dropbox.com/s/7n7demj2froy0 … .root?dl=0

I’m afraid your “event” tree is a bit broken.
You have some branches with the same name which I believe result from three TVector3 objects being written in “decomposed object mode”.
I think you need to recreate your tree and either set “splitlevel=0” for these three TVector3 branches or add a “.” character at the ends of their names.
Search for “identical branch names” and “subbranches with identical names” in the TTree::Branch method description and in the ROOT User’s Guide -> Trees -> Adding a TBranch to Hold an Object -> Identical Branch Names subsection.

I see, thanks :slight_smile: