How to make TChain forget the friends files?

HI all,

I’m trying to “horizontally” merge two TChains, keeping only some of the variables and at the same time applying a TCut.

How I do that:
0) read in data:
TChain *chain1 = new TChain(“Tree1”);
chain1->Add(“inputfile1.root”);
TChain *chain2 = new TChain(“Tree2”);
chain2->Add(“inputfile2.root”);

  1. I add the second TChain to the first using TFriend:
    chain1->AddFriend(chain2)
  2. Then using SetBranchStatus I keep only the branches I want.
  3. Then I copy the tree using the TCut:
    TTree *newTree = chain->CopyTree(myTCut)
  4. I save newTree:
    TFile *fout = new TFile(“outputfile.root”,“recreate”);
    fout->WriteTObject(newTree);
    fout->Close();

So here is the problem: I want to get rid of inputfile2.root, but my final newTree still “knows” about it.
(In fact, the real proble is this: When I read in newTree and I do newTree->SetAlias(“SomeNewName”, “5. * existing_branch_from_chain1”); I get error message that my inputfile2.root is missing.)

How to reproduce:

  1. get the attached files, put them in one directory.
  2. root -q macro.C
  3. remove inputfile2.root
  4. root -r macro_error.C

many thanks for your help. Asen.
macro_error.C (182 Bytes)
macro.C (502 Bytes)
inputfile2.root (5.16 KB)
inputfile1.root (5.27 KB)

anyone?

How about (I’m not sure whether you should use “TList::Clear” or “TList::Delete”) … TFile *fout = new TFile("outputfile.root", "recreate"); TTree *newTree = chain1->CopyTree(myTCut); newTree->GetListOfFriends()->Clear(); // ... or ... ->Delete(); newTree->Write(); delete fout; // automatically deletes "newTree", too