Directly accessing split branches

Hi,

I’ve created a tree with splitlevel=99, and have added (two) branches of TVector3. I would like to be able to access the coordinates inside the TVector3 directly rather than loading the TVector3 and reading the member variable. The reason for this is that I’m writing a user level function so that the use can pass the variable on the command line without there being a lot of if checks inside.

Example of what I want

making the tree

	//initialise atom 
	Double_t y[6];
	y[0] = 0.0;
	y[1] = 100e-6;
	y[2] = 100e-6;
	y[3] = 1e-4;
	y[4] = 0.;
	y[5] = 0.;
	
	Double_t energy(0.);
	Double_t t(0.);
	
	
	//Setup for output
	TFile* fid = new TFile("data/output2.root", "RECREATE");
	TTree *tree = new TTree();
	TVector3 *pos = new TVector3();
	TVector3 *vel = new TVector3();
	
	
	tree->Branch("r.", "TVector3", &pos);
	tree->Branch("v.", "TVector3", &vel);
	tree->Branch("t", &t, "T/D");
	tree->Branch("energy", &energy, "E/D");
	
	//runge-kutta loop
	Int_t counter(0);
	while(t<1e-2)
	{
		RK4Step(y, t, p->Dt(), p);
		
                 // things happen here....

		energy = Energy(y, t, p);
		pos->SetXYZ(y[0], y[1], y[2]);
		vel->SetXYZ(y[3], y[4], y[5]);

         	tree->Fill();
		
		t+=p->Dt();
  		counter++;
		
	}
	
	fid->WriteObject(tree, "tree");	
	fid->Close();

}

reading the tree

DrawVsT(TString filename, Option_t* varname)
{
	TFile* fid = new TFile(filename);
	
	TTree* tree = (TTree*) fid->Get("tree");
	
	Double_t t;
	Double_t var;
	
	tree->SetBranchAddress("t", &t);
	tree->SetBranchAddress(varname, &var);
	
	TGraph* g = new TGraph(tree->GetEntries());
	
	for(Int_t i=0; i<tree->GetEntries(); i++)
	{
		tree->GetEntry(i);
		printf("%f\t %f\n", t, var);
		g->SetPoint(i,t,var);
		
	}
	
	g->Draw("ALP");
}

In the root file, I can see that the TVectors have been filled. However trying to access them with varname = “r.fX” just gets me zeros. Can I make this work?

Can anyone help me with this?

Hi,

For that you need to manually put the TTree in MakeClass mode (see TTree::SetMakeClass and also see the result of TTree::MakeClass)

Cheers,
Philippe.