Reading a tree

Rudolf Wedenig (wedenig@qhepu3.oeaw.ac.at)
Mon, 31 May 1999 09:58:22 +0200 (MET DST)


Hello,

I want to read the content of a variable from a tree without using the
T->Draw("var");
option since for complex selections I get a strange behavior (i.e. the
result of
t->Draw("x:y","a>2 && b>3 && etc. ")
depends on the order of the selection criteria.
t->Draw("x:y","b>3 && a>2 && etc. ")
leads to a different result).

So I created a small test tree

************************************************************************
#include <iostream.h>
#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"

TROOT simple("simple","tree");
int i;
//______________________________________________________________________________
int main ()
{
TFile *hfile =new TFile ("htree.root","RECREATE","tree");

TTree *Tr;
Tr = new TTree("T","ROOT tree ");
struct test_struc {Float_t x,y,z;} obj;
float var;
Tr->Branch("vectors",&obj,"x:y:z");

Tr->Branch("variable",&var,"var");
for (i=0;i<10000;i++){
obj.x=i+1.5;
obj.y=i+1.5;
obj.z=i*i;
var=i;
Tr->Fill();
}
Tr->Print();
hfile->Write();

cout <<"wrote file "<<obj.x<<" "<<obj.y<<" "<<obj.z<<endl;
hfile->Close();

return 0;
}
********************************************************************
and try to read i.e. for i= 9000 the value of "var".
The only way I found is:

TFile *mf = new TFile("htree.root");
TTree *T=(TTree*) mf-> Get("T");
T->Scan("var","",,1,9000);

but this not want I really want, I would rather prefer a statement like

float test ;
test= T->Scan("var","",,1,9000);
cout<<test<<endl;

but this returns only zero (not surprising, but I am looking for
something similar).

Does anybody know how to do this?

Rudi