Filling a TVector3 into a TTree

Hi Rooters

I am running a compiled program in which I have included some Root libraries. I use this program to create a TTree and fill it with data. I then use the TreeViewer in a Root session to view the data. This has worked until I attempted to include a TVector3 object in the tree.

I have tried the following ways of defining the TBranch:

TVector3* drift1 = new TVector3;

AMStree->Branch(“drift1”, drift1, “fX:fY:fZ”); //one way
AMStree->Branch(“drift1”, “TVector3”, drift1); //other way

Neither of these seem to work. The error that occurs is that all the TVector3 entries appear to be zero. I have confirmed that there are in fact values in the vector before it is put in the tree. Can anyone suggest a reason for this?

Regards
Mark Dalton

Replace the line:
AMStree->Branch(“drift1”, “TVector3”, drift1); //other way

by

AMStree->Branch(“drift1”, “TVector3”, &drift1); //other way

Your first method is invalid.

Rene

In both cases you define branches incorrectly. See UserGuide or tutorials/htest.C for examples of defining branch with an object.

AMStree->Branch(“drift1”, drift1, “fX:fY:fZ”); //one way

will not work because drift1 is not struct with fX, fY and fZ.

AMStree->Branch(“drift1”, “TVector3”, drift1); //other way

and here you must replace ‘drift1’ pointer with the pointer to a pointer ‘&drift1’ so

AMStree->Branch(“drift1”, “TVector3”, &drift1); //other way