RE: copying a TChain

From: Philippe Canal <>
Date: Tue, 12 Jul 2005 16:22:04 -0500

Hi Christopher,

There are 2 issues. One is that SetBranchStatus is soly working on a name basis when selecting the branches (and since you did not use a trailing period in the branchname, none of the sub-branch contains their top level branch name in their own name). This means that

    fChain->SetBranchStatus("myQCDEvent",1); //read only this branch only activate the top level branch of the myQCDEvent hierarchy of branches.

The second issue is that the writing code is not designed (especially for the older branch type that you have in your file) to write TClonesArray without the shared library of the classes held in the TClonesArray.

Hence to copy your tree, you'll first need to load the library for the various object in the TTree.


-----Original Message-----
Sent: Monday, July 11, 2005 4:06 PM
Subject: [ROOT] copying a TChain

Hello all,
I've got a bunch of files I'm chaining together and my goal is to output a file that has essentially the same structure as the original, minus several subbranches that I don't want. I was trying to follow the instructions that Rene laid out in an old thread called "filter out the chain," but I can't seem to get it to work correctly for my case. I am running 3.05/07. I attached screenshots of the tree to show the structure I'm working with, because I think my problem might have to do with the multiple levels of branches.

Here is a sample of the code I'm using. In this case, I am just trying to activate and fill a couple selected branches:

void jetFill::Loop()
// assume files already loaded into fChain correctly

   if (fChain == 0) return;
   Int_t nentries = Int_t(fChain->GetEntries());

   fChain->SetBranchStatus("*",0);   // disable all branches
   fChain->SetBranchStatus("myQCDEvent",1);   //read only this branch
   fChain->SetBranchStatus("nVertex",1);   //read only this branch
   fChain->SetBranchStatus("vertex_",1);   //read only this branch
   fChain->SetBranchStatus("vertex.Vz",1);   //read only this branch

   cout << " Creating new root-file ..."<< endl;    TFile *newFile = new TFile("small.root","recreate");    cout << " Creating new tree ..."<< endl;

   TTree *tree = (TTree*)fChain->GetTree()->CloneTree(0);

   Int_t nbytes = 0, nb = 0;
   for (Int_t jentry=0; jentry<nentries;jentry++) {

      Int_t ientry = LoadTree(jentry); //in case of a TChain,
      nb = fChain->GetEntry(jentry);

      nbytes += nb;


   }// end loop over events    


   newFile = tree->GetCurrentFile();

When I run this, all of the leaves immediately underneath "myQCDEvent" (technically branches, in this case) are filled, not just nVertex (see snapshot4.png). However, I can see from Print() that vertex_ doesn't contain any events at all, and neither does vertex.Vz or any of the other leaves/branches beneath vertex_ (see snapshot5.png). Can anyone give me an idea about how to fix this so that the branches I choose are actually filled? Thanks a lot! :)

-Chris Doran
 SULI intern, FNAL
 DePauw University Received on Tue Jul 12 2005 - 23:23:19 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:10 MET