TTRees with custom objects

Hi,
I want to make, in a C++ program, a TTree of objects I have defined “PhysicsObjects” which inherit from TLorentzVector. I have some thing like:

//myTree is defined in the constructor 
//myTree = new TTree("myTree","Analysis Tree");
//as a pointer private member
//TTree *myTree;

PhysicsObject *obj();
myTree->Bronch("jets.","PhysicsObject",&obj,32000,2);
		
for (jet = theJetCollection.begin(); jet != theJetCollection.end(); jet++){
	//Chuck it into the root tree in a PhysicsObject for the time being
	obj->setValues(
		jet->getLorentzVector().et(),
		jet->getMass(),
		jet->getLorentzVector().getX(),
		jet->getLorentzVector().getY(),
		jet->getLorentzVector().getZ(),
		jet->getLorentzVector().getT()
	);
myTree->Fill();

Which is basically from following chapter 12 of the root manual.
However when I compile I get:

[quote]no matching function for call to `TTree::Bronch(const char[6], const char[14], PhysicsObject*()(), int, int)’
/root/include/TTree.h:152: candidates are: virtual TBranch
TTree::Bronch(const char*, const char*, void*, int = 32000, int = 99) [/quote]

I’ve also tried using myTree->Branch to the same effect. Am I missing something obvious? As far as I can make out from the documentation this should be trivial…

Replace

PhysicsObject *obj(); myTree->Bronch("jets.","PhysicsObject",&obj,32000,2);
by

PhysicsObject *obj=0; myTree->Branch("jets.","PhysicsObject",&obj,32000,2);

Rene

Brilliant! Thanks Rene!

Ok so now I have a root tree but instead of containing a leaf (or branch, depending on split level) for each physics object it contains one branch (“jets”) which contains the values of the PhysicsObjects member variables (two ints and a TLorentzVector). How do I get the tree to contain the PhysicsObject’s and not the values they are made of?

[code]PhysicsObject *obj = new PhysicsObject();
myTree->Branch(“jets”,“PhysicsObject”,&obj,32000,10);

for (jet = theJetCollection.begin(); jet != theJetCollection.end(); jet++){
obj = new PhysicsObject(
jet->getLorentzVector().et(),
jet->getMass(),
jet->getLorentzVector().getX(),
jet->getLorentzVector().getY(),
jet->getLorentzVector().getZ(),
jet->getLorentzVector().getT()
);
myTree->Fill();
delete obj;
}[/code]

It is not clear to see what you want to do.
If you want to produce events where each event has a list of tracks (TLorentzVector) and you want to group the tracks into jets, you can see
an example at the tutorial jets.C

Rene

Hi Rene,
It turns out what I had was working but TBrowser didn’t show it as I expected. Thanks again for your help!
Simon