Re: Problem in reading root file

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Thu, 09 Nov 2006 09:08:03 +0100


There are many errors in your code. See a working version in the attachment. TTree::MakeClass works for your Tree. Because you have created a subdirectory (why?) you have to change one line in the generated code

      tree = (TTree*)gDirectory->Get("TreeK"); to

      tree = (TTree*)gDirectory->Get("Event0/TreeK");

Rene Brun

SUDHIR BHARDWAJ wrote:
> Hi rooters,
>
> I have a root file "Kinematics.root" The file contains following
> informations.
> (1) A folder: Event0
> (2) Tree: TreeK
> (3) Branch: Particles
> (4) Varibles: e.g. fPx,fPy etc.
>
> I want to read this file and cout following informations
> e.g.
> cout<<"fPx = "<<fPx<<endl;
>
> I tried Using TTree::MakeClass for reading this tree but failed.
> I am attaching my file " Kinematics.root" file and "TestCode.C"
> with this mail. Please help me in reading this file.
>
> Thanks in advance.
> ----------------------------------------------------
> I am using Linux Fedora core 1.
> Root Version 5.13/04
> ----------------------------------------------------
> best regards,
> sudhir bhardwaj
>
> --
> Sudhir Bhardwaj
> ------------------------------------------------------------------------
>
> {
> //Reset ROOT and connect tree file
> gROOT->Reset();
> TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("Kinematics.root");
> if (!f) {
> f = new TFile("Kinematics.root");
> }
> TFolder *folder = (TFolder*)f->FindObject("Event0");//Folder
> TTree *tree = (TTree*)Event0->Get("TreeK");//Tree
> TBranch *branch = tree->GetBranch("Particles");//Branch
>
> //Declaration of leaves types
> const Int_t kMaxPar = 100;
> Double_t fPx[kMaxPar];
>
> // Set Address
>
> tree->SetBranchAddress("Particles.fPx",fPx);
> branch->Print();
>
> Long64_t nentries = branch->GetEntries();
> cout<<"Entries = "<<nentries<<endl;
> Long64_t nbytes = 0;
>
> for (Long64_t i=0; i<nentries;i++)
> {
> branch->GetEntry(i);
> cout<<"Px = "<<fPx<<endl;
> }
> }
>

Received on Thu Nov 09 2006 - 09:08:09 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:01 MET