Re: [ROOT] Plot with Error Bars

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Jun 09 2000 - 10:08:28 MEST


Hello Sean,

Sean Walston wrote:
> 
> Here is what I have:
> 
> 1) A 1-D array of x values
> 2) A 1-D array of errors which correspond to the x values
> 3) A 1-D array of y values
> 4) A 1-D array of errors which correspond to the y values
> 
> Here is what I want to do:
> 
> 1) Make a plot with error bars on the data points
> 2) Save this plot with a plot title, axis titles, and the whole enchilada
> to an output file which also is used to store other plots (TH1Fs) and an
> TNtuple.
> 
> I see how this can be done in principle based on example 23 under Root
> Tutorials, "Example of several graphs with errors in the same pad" and
> example 21, "Example of a Simple Graph with axis titles", but this method
> results in a TCanvas, and I have not yet figured out how to write this
> resulting canvas, lock, stock, and axis titles, to the output file in a
> manner analogous to writing a TH1F or an TNtuple to the output file: i.e.
> canvas->Write() has not worked for me. In short, I can essentially produce
> the graph which I want, but it disappears as soon as the destructor in my
> program is called and I loose the information because I haven't managed to
> save the canvas to the output file. Any suggestions?
> 

Tutorial 23 gerrors2.C is a good example to start. You can do:

Root > .x gerrors2.C
Root > TFile f("myfile.root","recreate")
Root > c1.Write()

then, in a new seRoot session, do
Root > Tfile f("myfile.root")
Root > c1.Draw()

For a more detailed diagnostic of your problems, I would need a copy of your
macro. I suspect the usual scoping problem. If you use a named macro
and create objects in the stack instead of using new, these objects are
automatically deleted when you leave the scope of the function.

> I have looked at the documentation on TProfile, and am mystified by
> 
> virtual Int_t Fill(Axis_t, Stat_t)
> 
> I think I understand Axis_t just fine, but so far I have found very little
> on the nature of Stat_t. Could I simply feed this Stat_t the elements of
> my error array?

TProfile derives from TH1 where several Fill functions are declared.
In case of derived classes, TProfile, TH2 and TH3, some of the Fill functions
must be protected as it does not make sense to call them. In the case
of TProfile, you will see 4 Fill functions. Two are declared private, so you
cannot
call them (eg the one you mention) and two are public. Use the public functions
only.

Rene Brun


> 
> Thank you for your help -- Sean
> 
> __________________________________________________________________________
> 
>                                Sean Walston
> --------------------------------------------------------------------------
> Willamette Hall, Office 317      SLD, Central Lab Annex, Office B-153
> Department of Physics            Stanford Linear Accelerator Center, MS-94
> University of Oregon             P.O. Box 4349
> Eugene, OR 97403                 Stanford, CA 94309
> walston@ampere.uoregon.edu       walston@SLAC.stanford.edu
> Office:  541-346-4847            Office:  650-926-8768
> Home:    541-686-9969            Mobile:  541-912-5456
> __________________________________________________________________________



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:27 MET