RE:filling TGraph with TNtuple ?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Aug 06 1998 - 08:41:09 MEST


This feature could be introduced in TTree::Draw.
Meanwhile, you can use a variant of the example below:
{
   gROOT->Reset();
   TFile *file = new TFile("hsimple.root");
   TTree *tree = (TTree*)file->Get("ntuple");
   TCanvas *c1 = new TCanvas("c1");
   //to get one single TPolyMarker object, force Root
   //to make one buffer only
   tree->SetEstimate(tree->GetEntries());
   tree->Draw("py:pz","px>0");

   //Get a pointer to the TPolyMarker object in the current pad
   TPolyMarker *pm = (TPolyMarker*)c1->GetPrimitive("TPolyMarker");

   //copy TPolyMarker to a TGraph
   TGraph *gr = new TGraph(pm->GetN(),pm->GetX(),pm->GetY());
   c1->Clear();
   gr->Draw();
}

Rene Brun

>I like very much the feature of ntuple->Draw("x-2y:z","z>0")
>But as far as I can tell this clever code in TTree.cxx is underused.
>OK, I can fill a histogram, I can fill a TPolyMarker, but I would like
to be
>able to fill a TGraph class and then use TGraph:Fit. I some cases
points
>would need to be sorted.

>I just think that TNtuple(TTree) is the most convinient class for me to
store
>my spectra which consist of wavelength, and then several data channels
>recorded. Various functions of them need to be plotted to get
meaningful
>information, but they are not to be treated as histograms. I have
noticed the
>same weakness in PAW: there was no easy way to get functions of ntuple
>fields as vectors.

>What I am in fact asking for is the simplest way to fit e.g. pol4

>x*(1+2*z) = pol4 (3*y+x)  for z>x  where x,y,z are TNtuple fields.


>Another problem is that ROOT's most developed objects are histograms,
but my
>data represents value AT some point, not mean value in some range. I
can
>probably construct histograms in such a way that bin centers correspond
to my
>data points, but is there any cleaner solution?

>I would like to develop solutions for above mentioned problems, but
please
>tell me if this is not already done.

>Best regards,
>--
>Tomasz Motylewski



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET