Re: Reading NTuple from file

Rene Brun (Rene.Brun@cern.ch)
Mon, 02 Jun 1997 18:53:52 +0200


Wouter Hulsbergen wrote:
>
> In my (hera-b) analysis code I define a file, a histogram and an ntuple:
>
> TROOT simple("simple","Test of histogramming and I/O");
> TFile hfile("hsimple.root","RECREATE","Demo ROOT file with histograms");
> TH1F *B0Mass = new TH1F("B0Mass","This is B0 mass distribution",500,0,500);
> TNtuple *eventuple = new TNtuple("eventuple","Ntuple of B0Gold events",
> "B0px:B0py:B0pz");
>
> which I fill on eventbasis with
>
> B0Mass->Fill(M);
> eventuple->Fill(B0px,B0py,B0pz) ;
>
> and somewhere at program termination apply
>
> hfile.Write();
> hfile.Close();
>
> Then I start root and read the file:
>
> Hfile f("hsimple.root")
>
> Plotting the histogram is easy:
>
> TH1F histo = f.Get("B0Mass");
> histo.Draw() ;
>
> Then I create an Ntuple:
>
> TNtuple nt = f.Get("eventuple");
>
> and indeed nt.GetEntries() returns the number of events in "eventuple".
> But even after studying the tutorials etc I don't understand how to
> plot f.e. "px:py". How should I use `GetEvent' and where do I define the
> ntuple floats `px,py,pz'?
>

Reading a TTree is explained at
http://root.cern.ch/root/HowtoReadTree.html

Following your example, you could do:
Root > nt.Draw("B0px")
Root > nt.Draw("B0py:B0px"); produces a scatter plot
Root > nt.Draw("sqrtB0px*B0px+B0py*B0py):B0pz","Bopz>0.2","lego1");
//produces a lego plot and uses a selection

You can also do the following:
Root >nt.MakeCode("nt.C"); //this generates a skeleton analysis file

You can insert statements in the main loop
Root >.x nt.C //to execute the macro file.C

Rene Brun