Merging trees with same structure

Dear rooters,
I’m dealing with a very dumb question but somehow I cannot figure it out.
I have a class (TheClass) which contains a tree as a member (class_tree) and I want to include a method to this class that simply merges the tree from different instances of the same class. I have tried the following:

TTree* TheClass::GetTree(){
   return this->class_tree;
}

Long_t TheClass::AddTree(TheClass *class_inst){
TTree *t = class_inst->GetTree();
if (!t) return 0;
Long_t copied;
return copied= this->class_tree -> CopyEntries(t);
}

also tried:


Long_t TheClass::AddTree(TheClass *class_inst){

 TTree *t = class_inst->GetTree();
 if (!t) return 0;
 Long_t nent = t -> GetEntries();

 for(int i=0; i< nent; i++){
  t->GetEntry(i);
  this->class_tree -> Fill();
 }

Obviously the name of the branches of both trees are the same as are defined in the same class but different instances. I miss on how to connect two trees with same structure from instances of the same class.
thanks

You may have a look at the documentation for TTree::Merge(). There you can click on the link to the implementation in TTree.cxx. I think that you may be missing the CopyAddresses() part to be able to properly merge your trees. Cheers,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.