I David,
You will find below a simple example using TTree (recommended).
To run it, do
root > .x tree.C
or
root > .x tree.C++ (using the automatic interface to teh compiler)
Rene Brun
#include "TTree.h"
#include "TFile.h"
#include "TRandom.h"
#include "TH2.h"
#include "TCanvas.h"
typedef struct { Float_t a,b,c,d,e,f;} BRANCH;
void treeFill() {
// create a TTree with a simple structure
TRandom r;
BRANCH br;
TFile f("tree.root","recreate");
TTree *ntuple = new TTree("ntuple","demo");
ntuple->Branch("br",&br.a,"a:b:c:d:e:f");
for (Int_t i=0;i<10000;i++ ) {
br.a = r.Rndm();
br.b = r.Gaus(-1,0.1);
br.c = r.Gaus( 1,0.1);
br.d = r.Landau(1,1);
br.e = br.c +br.d;
br.f = i;
ntuple->Fill();
}
ntuple->Write();
}
void treeRead() {
// read ntuple generated above
TFile *f = new TFile("tree.root");
TTree *ntuple = (TTree*)f->Get("ntuple");
TH1F *hb = new TH1F("hb","b",100,-2,0);
TH2F *hcd = new TH2F("hcd","c vs d",40,-5,20,40,0.5,1.5);
BRANCH br;
ntuple->SetBranchAddress("br",&br.a);
Int_t nentries = (Int_t)ntuple->GetEntries();
for (Int_t i=0;i<nentries;i++) {
ntuple->GetEntry(i);
hb->Fill(br.b);
hcd->Fill(br.d,br.c);
}
TCanvas *c1 = new TCanvas("c1","ntuple demo",600,800);
c1->Divide(1,2);
c1->cd(1);
hb->Draw();
c1->cd(2);
hcd->Draw();
}
void tree() {
treeFill();
treeRead();
}
On Tue, 16 Jan 2001, David L Attanasio wrote:
> I am attempting to use root to process a large data set where each entry has
> 8 variables. To do this, I created an ntuple using the TNtuple class and
> wrote it to a file. I am able to read the file back into root. However, I
> cannot figure out how to extract specific values from the TNtuple object.
> I need to access the specific values for each variable, one entry at a time.
> I have searched the ROOT website to no avail. Any assistance you can give
> would be appreciated. Thank you.
>
> David Attanasio
>
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:33 MET