RE: [ROOT] reading from trees once more

From: Philippe Canal (pcanal@fnal.gov)
Date: Wed Nov 21 2001 - 00:52:24 MET


>As point out by Pasha:
>	tv__tree->SetBranchAddress("_1.nhitcot",&nhitcot2);
> will work.

Oups I spoke a little to fast.  It will NOT work.

You actually need to define a struct containing the full
content of the branch (which has the odd name "_1") by doing
something like:

class mystruct {
public:
	int alg;
	int charge;
	float d0;
	float eta;
	int event;
	int nhitax;
	int nhitcot;
	int nhitsil;
	int nhitsilphi;
	int nhitsilst;
	int nhitsilz;
	int nhitst;
	float pT;
	int paralg;
	float phi0;
	int run;
	int trknum;
	float z0;
}
mystruct object;
tv__tree->SetBranchAddress("_1",&object);

However, you might actually benefit from taking a look
at ROOT's MakeSelector facility or at D0's SEED facility
(http://www-d0.fnal.gov/nikhef/?seed).

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Anne-Sylvie
Nicollerat
Sent: Tuesday, November 20, 2001 4:49 PM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] reading from trees once more


Hello !

I am trying to read the variables from a tree (named Tracks), using the
following macro (that I start after having started the tree viewer):

{
tv__tree = (TTree *) gROOT->FindObject("Tracks");
tv__tree_list->Add(tv__tree);

Int_t nhitcot2;
Int_t nhitax2;
Int_t nhitst2;

tv__tree->SetBranchAddress("nhitcot",&nhitcot2);
tv__tree->SetBranchAddress("nhitax",&nhitax2);
tv__tree->SetBranchAddress("nhitst",&nhitst2);
....
}

Then root returns me the following error message :

Error in <TTree::SetBranchAddress>: unknown branch -> nhitcot
Error in <TTree::SetBranchAddress>: unknown branch -> nhitax
Error in <TTree::SetBranchAddress>: unknown branch -> nhitst

When I look in the contents of my tree, doing tv__tree->Print(), I get
the following:

root [1] tv__tree->Print()
******************************************************************************

*Tree    :Tracks    :
Tracks                                                 *
*Entries :    48820 : Total =         3536541 bytes  File  Size =
3536541 *
*        :          : Tree compression factor =
1.00                       *
******************************************************************************

*Br    0 :_1        :
alg/I:charge/I:d0/F:eta/F:event/I:nhitax/I:nhitcot/I:  *
*         |
nhitsil/I:nhitsilphi/I:nhitsilst/I:nhitsilz/I:nhitst/I:pT/F:     *
*         |
paralg/I:phi0/F:run/I:trknum/I:z0/F                              *
*Entries :    48820 : Total  Size=    3515490 bytes  File Size  =
3515490 *
*Baskets :      110 : Basket Size=      32000 bytes  Compression=
1.00     *

I think the suspicious thing is the 0:_1 thing. It look as the variables
are not directly accessible. Actually when I try to access the tree
variables from the browser, I first come to a _1 leave that I have to
open to access the tree variables.

Just another thing: I can for instance plot an histogram directly from
the viewer and then root executes the following command :
tv__tree->Draw("_1.nhitcot","","hist", 48820, 0);

Do you know how I could acces the arguments of the tree in my macro ?

Thanks a lot

Anne-Sylvie

--
-----------------------------------
Anne-Sylvie Nicollerat
office 327-52-56, phone 1-630-840-3899
Fermilab/CDF MS 223 PO box 500,
Batavia, IL 60510 USA

"Pour le croyant Dieu se trouve au debut, pour le physicien au terme de toute pensee." (Planck)



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:09 MET