RE: Mixed events from a TChain

From: Christian Holm Christensen <cholm_at_nbi.dk>
Date: Thu, 06 Jan 2005 01:14:01 +0100


Hi Philippe, et al,

On Mon, 2005-01-03 at 16:15 -0600, Philippe Canal wrote:
> Hi Christian,
>
> This is the expected behavior.

Uhm!? OK.

> Hopefully the documentation of
> TTree/Tchain::CloneTree makes it clear that until otherwise request the
> original tree and the clone tree are intimately linked. In particular the
> original tree can feel free to make sure that the connection between the two
> is still present by re-setting the addresses of the clone to its own address
> (For example this is done whenever a new file is open by a Tchain).

OK. I see that I was actually misusing the the TTree::CloneTree member function. I actually wanted to read from the same tree, but a different entry. Doing `tree->CloneTree()' _copies_ the tree entries, which is obviously way too heavy if one has a large tree (at least for mix-event analysis purposes).

So, I ended up doing something different. I present it here in the common interest, but also if someone had a better idea to do the same.

I derived a class from TTree, which contains a pointer to the original TTree. The derived class overloads `GetName', `SetBranchAddress', and `GetEntry'. `SetBranchAddress' doesn't actually set the branch address. Instead, it keeps a list of branch names, and addresses. In `GetEntry' the addresses of the branches in the list, gets there address temporarily assigned to the corresponding address in the list.

> The design of the cloning is to support the following usually case.
> TTree* tree = static_cast<TTree*>(file->Get("T"));
> TTree* clone = tree->CloneTree(0);
> tree->SetBranchAddress("vector", &array);
> while (tree->GetEntry(entry) > 0) {
> ... Do somethine usefull like a selection ...
> Clone->Fill();
> };

Instead of this, I do

	  TTree* clone = new MixTree(tree); 
	  clone->SetBranchAddress("vector", &array);

I have attached my modified script Mixed.C plus the script MixTree.C which contains the TTree derived class, and which is automatically compiled to a shared library when Mixed.C is executed.

This is ofcourse a boiled down example. In the real application, every member function of TTree is overloaded in MixTree, to simply forward the messages to the contained TTree object.

> If you intend on separating the clone from the original, you should call:
>
> tree->GetListOfClones()->Remove(clone);

Not really. I actually wanted to read from the original.

Yours,

-- 
 ___  |  Christian Holm Christensen 
  |_| |  -------------------------------------------------------------
    | |  Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|           DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|            Denmark                    Office: (+45) 353  25 404
 ____|   Email:   cholm_at_nbi.dk               Web:    www.nbi.dk/~cholm
 | |

Received on Thu Jan 06 2005 - 01:14:25 MET

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