RE: Mixed events from a TChain

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Mon, 03 Jan 2005 16:15:33 -0600


Hi Christian,

This is the expected behavior. 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).

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();
        };

If you intend on separating the clone from the original, you should call:

  tree->GetListOfClones()->Remove(clone);

Cheers,
Philippe.         

-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Christian Holm Christensen
Sent: Sunday, January 02, 2005 8:37 AM
To: roottalk_at_pcroot.cern.ch
Subject: [ROOT] Mixed events from a TChain

Hi all,

I think there's a problem with TChain::CloneTree or something like that.

If I create a TTree, and read it back so that each time a read an entry, I also read the previous entry (if available), then it works fine using TTree::CloneTree:

	TTree* tree  = static_cast<TTree*>(file->Get("T"));
	TTree* clone = tree->CloneTree();
	tree->SetBranchAddress("vector", &array);
	clone->SetBranchAddress("vector", &other);
	Int_t entry = 0;
	while (tree->GetEntry(entry) > 0) { 
	  cout << "Got " << array->GetEntries() << " vectors" << endl;
	  if (entry > 0) { 
	    clone->GetEntry(entry - 1);
	    cout << "Got " << other->GetEntries() << " vectors" << endl;
	  }
	  entry++;
        }

However, If I do the same thing with a TChain, the `clone' tree never fills the `other' array:

	TChain* tree = new TChain("T");
	tree->Add("*.root");
	Tree*  clone = tree->CloneTree();
	// Rest as above 

The weird thing is, that the `clone' tree reads the right number of bytes, but never fills the `other' array.

I have attached a small script as well as the output of running that script. Note, that the script first creates 3 files with a TTree in each. Then it reads back (as explained above) one of the files using a TTree, which works fine. Finally, it reads back all three files using a TChain, which fails miserably.

Am I doing something wrong, or does the CloneTree facility not work with a TChain?

I'm using

	ROOT Version 4.01/05 (CVS head around 14 December 2004) 
	Debian GNU/Linux unstable (sid) 
	G++ (GCC) 3.3.5 (Debian 1:3.3.5-5)
	

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 Mon Jan 03 2005 - 23:17:11 MET

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