ROOT 6.16/01 Reference Guide |
A TMultiGraph is a collection of TGraph (or derived) objects.
It allows to manipulate a set of graphs as a single entity. In particular, when drawn, the X and Y axis ranges are automatically computed such as all the graphs will be visible.
TMultiGraph::Add
should be used to add a new graph to the list.
The TMultiGraph owns the objects in the list.
The drawing options are the same as for TGraph. Like for TGraph, the painting is performed thanks to the TGraphPainter class. All details about the various painting options are given in this class.
Example:
A special option 3D
allows to draw the graphs in a 3D space. See the following example:
The number of graphs in a multigraph can be retrieve with:
The drawing option for each TGraph may be specified as an optional second argument of the Add
function.
If a draw option is specified, it will be used to draw the graph, otherwise the graph will be drawn with the option specified in TMultiGraph::Draw
.
The following example shows how to fit a TMultiGraph.
The axis titles can be modified the following way:
When the graphs in a TMultiGraph are fitted, the fit parameters boxes overlap. The following example shows how to make them all visible.
The axis limits can be changed the like for TGraph. The same methods apply on the multigraph. Note the two differents ways to change limits on X and Y axis.
The method TPad::BuildLegend is able to extract the graphs inside a multigraph. The following example demonstrate this.
Automatic coloring according to the current palette is available as shown in the following example:
Definition at line 35 of file TMultiGraph.h.
Public Member Functions | |
TMultiGraph () | |
TMultiGraph default constructor. More... | |
TMultiGraph (const char *name, const char *title) | |
Constructor with name and title. More... | |
virtual | ~TMultiGraph () |
TMultiGraph destructor. More... | |
virtual void | Add (TGraph *graph, Option_t *chopt="") |
Add a new graph to the list of graphs. More... | |
virtual void | Add (TMultiGraph *multigraph, Option_t *chopt="") |
Add all the graphs in "multigraph" to the list of graphs. More... | |
TIter | begin () const |
Get iterator over internal graphs list. More... | |
virtual void | Browse (TBrowser *b) |
Browse multigraph. More... | |
virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
Compute distance from point px,py to each graph. More... | |
virtual void | Draw (Option_t *chopt="") |
Draw this multigraph with its current attributes. More... | |
TIter | end () const |
virtual TFitResultPtr | Fit (const char *formula, Option_t *option="", Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0) |
Fit this graph with function with name fname. More... | |
virtual TFitResultPtr | Fit (TF1 *f1, Option_t *option="", Option_t *goption="", Axis_t rxmin=0, Axis_t rxmax=0) |
Fit this multigraph with function f1. More... | |
virtual void | FitPanel () |
Display a panel with all histogram fit options. More... | |
TF1 * | GetFunction (const char *name) const |
Return pointer to function with name. More... | |
virtual Option_t * | GetGraphDrawOption (const TGraph *gr) const |
Return the draw option for the TGraph gr in this TMultiGraph. More... | |
TH1F * | GetHistogram () |
Returns a pointer to the histogram used to draw the axis. More... | |
TList * | GetListOfFunctions () |
Return pointer to list of functions. More... | |
const TList * | GetListOfFunctions () const |
TList * | GetListOfGraphs () const |
TAxis * | GetXaxis () |
Get x axis of the graph. More... | |
TAxis * | GetYaxis () |
Get y axis of the graph. More... | |
virtual void | InitExpo (Double_t xmin, Double_t xmax) |
Compute Initial values of parameters for an exponential. More... | |
virtual void | InitGaus (Double_t xmin, Double_t xmax) |
Compute Initial values of parameters for a gaussian. More... | |
virtual void | InitPolynom (Double_t xmin, Double_t xmax) |
Compute Initial values of parameters for a polynom. More... | |
virtual Int_t | IsInside (Double_t x, Double_t y) const |
Return 1 if the point (x,y) is inside one of the graphs 0 otherwise. More... | |
virtual void | LeastSquareFit (Int_t m, Double_t *a, Double_t xmin, Double_t xmax) |
Least squares lpolynomial fitting without weights. More... | |
virtual void | LeastSquareLinearFit (Int_t ndata, Double_t &a0, Double_t &a1, Int_t &ifail, Double_t xmin, Double_t xmax) |
Least square linear fit without weights. More... | |
virtual void | Paint (Option_t *chopt="") |
Paint all the graphs of this multigraph. More... | |
void | PaintPads (Option_t *chopt="") |
Divides the active pad and draws all Graphs in the Multigraph separately. More... | |
void | PaintPolyLine3D (Option_t *chopt="") |
Paint all the graphs of this multigraph as 3D lines. More... | |
virtual void | Print (Option_t *chopt="") const |
Print the list of graphs. More... | |
virtual void | RecursiveRemove (TObject *obj) |
Recursively remove this object from a list. More... | |
virtual void | SavePrimitive (std::ostream &out, Option_t *option="") |
Save primitive as a C++ statement(s) on output stream out. More... | |
virtual void | SetMaximum (Double_t maximum=-1111) |
Set multigraph maximum. More... | |
virtual void | SetMinimum (Double_t minimum=-1111) |
Set multigraph minimum. More... | |
Public Member Functions inherited from TNamed | |
TNamed () | |
TNamed (const char *name, const char *title) | |
TNamed (const TNamed &named) | |
TNamed copy ctor. More... | |
TNamed (const TString &name, const TString &title) | |
virtual | ~TNamed () |
TNamed destructor. More... | |
virtual void | Clear (Option_t *option="") |
Set name and title to empty strings (""). More... | |
virtual TObject * | Clone (const char *newname="") const |
Make a clone of an object using the Streamer facility. More... | |
virtual Int_t | Compare (const TObject *obj) const |
Compare two TNamed objects. More... | |
virtual void | Copy (TObject &named) const |
Copy this to obj. More... | |
virtual void | FillBuffer (char *&buffer) |
Encode TNamed into output buffer. More... | |
virtual const char * | GetName () const |
Returns name of object. More... | |
virtual const char * | GetTitle () const |
Returns title of object. More... | |
virtual ULong_t | Hash () const |
Return hash value for this object. More... | |
virtual Bool_t | IsSortable () const |
virtual void | ls (Option_t *option="") const |
List TNamed name and title. More... | |
TNamed & | operator= (const TNamed &rhs) |
TNamed assignment operator. More... | |
virtual void | Print (Option_t *option="") const |
Print TNamed name and title. More... | |
virtual void | SetName (const char *name) |
Set the name of the TNamed. More... | |
virtual void | SetNameTitle (const char *name, const char *title) |
Set all the TNamed parameters (name and title). More... | |
virtual void | SetTitle (const char *title="") |
Set the title of the TNamed. More... | |
virtual Int_t | Sizeof () const |
Return size of the TNamed part of the TObject. More... | |
Public Member Functions inherited from TObject | |
TObject () | |
TObject constructor. More... | |
TObject (const TObject &object) | |
TObject copy ctor. More... | |
virtual | ~TObject () |
TObject destructor. More... | |
void | AbstractMethod (const char *method) const |
Use this method to implement an "abstract" method that you don't want to leave purely abstract. More... | |
virtual void | AppendPad (Option_t *option="") |
Append graphics object to current pad. More... | |
virtual void | Browse (TBrowser *b) |
Browse object. May be overridden for another default action. More... | |
ULong_t | CheckedHash () |
Check and record whether this class has a consistent Hash/RecursiveRemove setup (*) and then return the regular Hash value for this object. More... | |
virtual const char * | ClassName () const |
Returns name of class to which the object belongs. More... | |
virtual void | Clear (Option_t *="") |
virtual TObject * | Clone (const char *newname="") const |
Make a clone of an object using the Streamer facility. More... | |
virtual Int_t | Compare (const TObject *obj) const |
Compare abstract method. More... | |
virtual void | Copy (TObject &object) const |
Copy this to obj. More... | |
virtual void | Delete (Option_t *option="") |
Delete this object. More... | |
virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
Computes distance from point (px,py) to the object. More... | |
virtual void | Draw (Option_t *option="") |
Default Draw method for all objects. More... | |
virtual void | DrawClass () const |
Draw class inheritance tree of the class to which this object belongs. More... | |
virtual TObject * | DrawClone (Option_t *option="") const |
Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad) . More... | |
virtual void | Dump () const |
Dump contents of object on stdout. More... | |
virtual void | Error (const char *method, const char *msgfmt,...) const |
Issue error message. More... | |
virtual void | Execute (const char *method, const char *params, Int_t *error=0) |
Execute method on this object with the given parameter string, e.g. More... | |
virtual void | Execute (TMethod *method, TObjArray *params, Int_t *error=0) |
Execute method on this object with parameters stored in the TObjArray. More... | |
virtual void | ExecuteEvent (Int_t event, Int_t px, Int_t py) |
Execute action corresponding to an event at (px,py). More... | |
virtual void | Fatal (const char *method, const char *msgfmt,...) const |
Issue fatal error message. More... | |
virtual TObject * | FindObject (const char *name) const |
Must be redefined in derived classes. More... | |
virtual TObject * | FindObject (const TObject *obj) const |
Must be redefined in derived classes. More... | |
virtual Option_t * | GetDrawOption () const |
Get option used by the graphics system to draw this object. More... | |
virtual const char * | GetIconName () const |
Returns mime type name of object. More... | |
virtual const char * | GetName () const |
Returns name of object. More... | |
virtual char * | GetObjectInfo (Int_t px, Int_t py) const |
Returns string containing info about the object at position (px,py). More... | |
virtual Option_t * | GetOption () const |
virtual const char * | GetTitle () const |
Returns title of object. More... | |
virtual UInt_t | GetUniqueID () const |
Return the unique object id. More... | |
virtual Bool_t | HandleTimer (TTimer *timer) |
Execute action in response of a timer timing out. More... | |
virtual ULong_t | Hash () const |
Return hash value for this object. More... | |
Bool_t | HasInconsistentHash () const |
Return true is the type of this object is known to have an inconsistent setup for Hash and RecursiveRemove (i.e. More... | |
virtual void | Info (const char *method, const char *msgfmt,...) const |
Issue info message. More... | |
virtual Bool_t | InheritsFrom (const char *classname) const |
Returns kTRUE if object inherits from class "classname". More... | |
virtual Bool_t | InheritsFrom (const TClass *cl) const |
Returns kTRUE if object inherits from TClass cl. More... | |
virtual void | Inspect () const |
Dump contents of this object in a graphics canvas. More... | |
void | InvertBit (UInt_t f) |
virtual Bool_t | IsEqual (const TObject *obj) const |
Default equal comparison (objects are equal if they have the same address in memory). More... | |
virtual Bool_t | IsFolder () const |
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects). More... | |
R__ALWAYS_INLINE Bool_t | IsOnHeap () const |
virtual Bool_t | IsSortable () const |
R__ALWAYS_INLINE Bool_t | IsZombie () const |
virtual void | ls (Option_t *option="") const |
The ls function lists the contents of a class on stdout. More... | |
void | MayNotUse (const char *method) const |
Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary). More... | |
virtual Bool_t | Notify () |
This method must be overridden to handle object notification. More... | |
void | Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const |
Use this method to declare a method obsolete. More... | |
void | operator delete (void *ptr) |
Operator delete. More... | |
void | operator delete[] (void *ptr) |
Operator delete []. More... | |
void * | operator new (size_t sz) |
void * | operator new (size_t sz, void *vp) |
void * | operator new[] (size_t sz) |
void * | operator new[] (size_t sz, void *vp) |
TObject & | operator= (const TObject &rhs) |
TObject assignment operator. More... | |
virtual void | Paint (Option_t *option="") |
This method must be overridden if a class wants to paint itself. More... | |
virtual void | Pop () |
Pop on object drawn in a pad to the top of the display list. More... | |
virtual void | Print (Option_t *option="") const |
This method must be overridden when a class wants to print itself. More... | |
virtual Int_t | Read (const char *name) |
Read contents of object with specified name from the current directory. More... | |
virtual void | RecursiveRemove (TObject *obj) |
Recursively remove this object from a list. More... | |
void | ResetBit (UInt_t f) |
virtual void | SaveAs (const char *filename="", Option_t *option="") const |
Save this object in the file specified by filename. More... | |
virtual void | SavePrimitive (std::ostream &out, Option_t *option="") |
Save a primitive as a C++ statement(s) on output stream "out". More... | |
void | SetBit (UInt_t f) |
void | SetBit (UInt_t f, Bool_t set) |
Set or unset the user status bits as specified in f. More... | |
virtual void | SetDrawOption (Option_t *option="") |
Set drawing option for object. More... | |
virtual void | SetUniqueID (UInt_t uid) |
Set the unique object id. More... | |
virtual void | SysError (const char *method, const char *msgfmt,...) const |
Issue system error message. More... | |
R__ALWAYS_INLINE Bool_t | TestBit (UInt_t f) const |
Int_t | TestBits (UInt_t f) const |
virtual void | UseCurrentStyle () |
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyle or TROOT::ForceStyle have been invoked. More... | |
virtual void | Warning (const char *method, const char *msgfmt,...) const |
Issue warning message. More... | |
virtual Int_t | Write (const char *name=0, Int_t option=0, Int_t bufsize=0) |
Write this object to the current directory. More... | |
virtual Int_t | Write (const char *name=0, Int_t option=0, Int_t bufsize=0) const |
Write this object to the current directory. More... | |
Protected Member Functions | |
TMultiGraph (const TMultiGraph &) | |
Copy constructor. More... | |
TMultiGraph & | operator= (const TMultiGraph &) |
Assignment operator. More... | |
Protected Member Functions inherited from TObject | |
virtual void | DoError (int level, const char *location, const char *fmt, va_list va) const |
Interface to ErrorHandler (protected). More... | |
void | MakeZombie () |
Protected Attributes | |
TList * | fFunctions |
TList * | fGraphs |
TH1F * | fHistogram |
Double_t | fMaximum |
Double_t | fMinimum |
Protected Attributes inherited from TNamed | |
TString | fName |
TString | fTitle |
Additional Inherited Members | |
Public Types inherited from TObject | |
enum | { kIsOnHeap = 0x01000000 , kNotDeleted = 0x02000000 , kZombie = 0x04000000 , kInconsistent = 0x08000000 , kBitMask = 0x00ffffff } |
enum | { kSingleKey = BIT(0) , kOverwrite = BIT(1) , kWriteDelete = BIT(2) } |
enum | EDeprecatedStatusBits { kObjInCanvas = BIT(3) } |
enum | EStatusBits { kCanDelete = BIT(0) , kMustCleanup = BIT(3) , kIsReferenced = BIT(4) , kHasUUID = BIT(5) , kCannotPick = BIT(6) , kNoContextMenu = BIT(8) , kInvalidObject = BIT(13) } |
Static Public Member Functions inherited from TObject | |
static Long_t | GetDtorOnly () |
Return destructor only flag. More... | |
static Bool_t | GetObjectStat () |
Get status of object stat flag. More... | |
static void | SetDtorOnly (void *obj) |
Set destructor only flag. More... | |
static void | SetObjectStat (Bool_t stat) |
Turn on/off tracking of objects in the TObjectTable. More... | |
#include <TMultiGraph.h>
|
protected |
Copy constructor.
Definition at line 306 of file TMultiGraph.cxx.
TMultiGraph::TMultiGraph | ( | ) |
TMultiGraph default constructor.
Definition at line 279 of file TMultiGraph.cxx.
TMultiGraph::TMultiGraph | ( | const char * | name, |
const char * | title | ||
) |
Constructor with name and title.
Definition at line 292 of file TMultiGraph.cxx.
|
virtual |
TMultiGraph destructor.
Definition at line 337 of file TMultiGraph.cxx.
Add a new graph to the list of graphs.
Note that the graph is now owned by the TMultigraph. Deleting the TMultiGraph object will automatically delete the graphs. You should not delete the graphs when the TMultigraph is still active.
Definition at line 372 of file TMultiGraph.cxx.
|
virtual |
Add all the graphs in "multigraph" to the list of graphs.
Definition at line 388 of file TMultiGraph.cxx.
TIter TMultiGraph::begin | ( | ) | const |
Get iterator over internal graphs list.
Definition at line 1552 of file TMultiGraph.cxx.
Compute distance from point px,py to each graph.
Reimplemented from TObject.
Definition at line 425 of file TMultiGraph.cxx.
Draw this multigraph with its current attributes.
Options to draw a graph are described in TGraphPainter.
The drawing option for each TGraph may be specified as an optional second argument of the Add function. You can use GetGraphDrawOption to return this option.
If a draw option is specified, it will be used to draw the graph, otherwise the graph will be drawn with the option specified in TMultiGraph::Draw. Use GetDrawOption to return the option specified when drawing the TMultiGraph.
Reimplemented from TObject.
Definition at line 462 of file TMultiGraph.cxx.
|
inline |
Definition at line 71 of file TMultiGraph.h.
|
virtual |
Fit this graph with function with name fname.
interface to TF1::Fit(TF1 *f1...
Definition at line 480 of file TMultiGraph.cxx.
|
virtual |
Fit this multigraph with function f1.
In this function all graphs of the multigraph are fitted simultaneously
f1 is an already predefined function created by TF1. Predefined functions such as gaus, expo and poln are automatically created by ROOT.
The list of fit options is given in parameter option
which may takes the following values:
When the fit is drawn (by default), the parameter goption may be used to specify a list of graphics options. See TGraph::Paint for a complete list of these options.
In order to use the Range option, one must first create a function with the expression to be fitted. For example, if your graph has a defined range between -4 and 4 and you want to fit a gaussian only in the interval 1 to 3, you can do:
Note that this function is called when calling TGraphErrors::Fit or TGraphAsymmErrors::Fit ot TGraphBentErrors::Fit see the discussion below on the errors calculation.
Parameters must be initialized before invoking the Fit function. The setting of the parameter initial values is automatic for the predefined functions : poln, expo, gaus, landau. One can however disable this automatic computation by specifying the option "B". You can specify boundary limits for some or all parameters via
if parmin>=parmax
, the parameter is fixed Note that you are not forced to fix the limits for all parameters. For example, if you fit a function with 6 parameters, you can do:
With this setup, parameters 0->3 can vary freely Parameter 4 has boundaries [-10,-4] with initial value -8 Parameter 5 is fixed to 100.
The fit range can be specified in two ways:
By default a chi2 fitting function is used for fitting the TGraphs's. The function is implemented in FitUtil::EvaluateChi2
. In case of TGraphErrors an effective chi2 is used (see TGraphErrors fit in TGraph::Fit) and is implemented in FitUtil::EvaluateChi2Effective
To specify a User defined fitting function, specify option "U" and call the following function:
where MyFittingFunction is of type:
The function returns a TFitResultPtr which can hold a pointer to a TFitResult object. By default the TFitResultPtr contains only the status of the fit and it converts automatically to an integer. If the option "S" is instead used, TFitResultPtr contains the TFitResult and behaves as a smart pointer to it. For example one can do:
The fit parameters, error and chi2 (but not covariance matrix) can be retrieved also from the fitted function.
One or more object (typically a TF1*) can be added to the list of functions (fFunctions) associated to each graph. When TGraph::Fit is invoked, the fitted function is added to this list. Given a graph gr, one can retrieve an associated function with:
If the graph is made persistent, the list of associated functions is also persistent. Given a pointer (see above) to an associated function myfunc, one can retrieve the function/fit parameters with calls such as:
You can change the statistics box to display the fit parameters with the TStyle::SetOptFit(mode) method. This mode has four digits. mode = pcev (default = 0111)
For example: gStyle->SetOptFit(1011);
prints the fit probability, parameter names/values, and errors. You can change the position of the statistics box with these lines (where g is a pointer to the TGraph):
Definition at line 655 of file TMultiGraph.cxx.
|
virtual |
Display a panel with all histogram fit options.
See class TFitPanel for example
Definition at line 672 of file TMultiGraph.cxx.
TF1 * TMultiGraph::GetFunction | ( | const char * | name | ) | const |
Return pointer to function with name.
Functions such as TGraph::Fit store the fitted function in the list of functions of this graph.
Definition at line 1020 of file TMultiGraph.cxx.
Return the draw option for the TGraph gr
in this TMultiGraph.
The return option is the one specified when calling TMultiGraph::Add(gr,option).
Definition at line 696 of file TMultiGraph.cxx.
TH1F * TMultiGraph::GetHistogram | ( | ) |
Returns a pointer to the histogram used to draw the axis.
Takes into account following cases.
fHistogram
exists it is returnedfHistogram
doesn't exists and gPad
exists gPad
is updated. That may trigger the creation of fHistogram
. If fHistogram
still does not exit but hframe
does (if user called TPad::DrawFrame
) the pointer to hframe
histogram is returnedfHistogram
still doesn't exist then it is created. Definition at line 971 of file TMultiGraph.cxx.
TList * TMultiGraph::GetListOfFunctions | ( | ) |
Return pointer to list of functions.
If pointer is null create the list
Definition at line 1030 of file TMultiGraph.cxx.
|
inline |
Definition at line 73 of file TMultiGraph.h.
|
inline |
Definition at line 69 of file TMultiGraph.h.
TAxis * TMultiGraph::GetXaxis | ( | ) |
Get x axis of the graph.
This method returns a valid axis only after the TMultigraph has been drawn.
Definition at line 1041 of file TMultiGraph.cxx.
TAxis * TMultiGraph::GetYaxis | ( | ) |
Get y axis of the graph.
This method returns a valid axis only after the TMultigraph has been drawn.
Definition at line 1053 of file TMultiGraph.cxx.
Compute Initial values of parameters for an exponential.
Definition at line 756 of file TMultiGraph.cxx.
Compute Initial values of parameters for a gaussian.
Definition at line 711 of file TMultiGraph.cxx.
Compute Initial values of parameters for a polynom.
Definition at line 773 of file TMultiGraph.cxx.
Return 1 if the point (x,y) is inside one of the graphs 0 otherwise.
Definition at line 945 of file TMultiGraph.cxx.
Least squares lpolynomial fitting without weights.
based on CERNLIB routine LSQ: Translated to C++ by Rene Brun
Definition at line 797 of file TMultiGraph.cxx.
|
virtual |
Least square linear fit without weights.
Fit a straight line (a0 + a1*x) to the data in this graph.
extracted from CERNLIB LLSQ: Translated to C++ by Rene Brun
Definition at line 892 of file TMultiGraph.cxx.
|
protected |
Assignment operator.
Definition at line 320 of file TMultiGraph.cxx.
Paint all the graphs of this multigraph.
Reimplemented from TObject.
Definition at line 1064 of file TMultiGraph.cxx.
Divides the active pad and draws all Graphs in the Multigraph separately.
Definition at line 1312 of file TMultiGraph.cxx.
Paint all the graphs of this multigraph as 3D lines.
Definition at line 1361 of file TMultiGraph.cxx.
Print the list of graphs.
Reimplemented from TNamed.
Definition at line 1464 of file TMultiGraph.cxx.
Recursively remove this object from a list.
Typically implemented by classes that can contain multiple references to a same object.
Reimplemented from TObject.
Definition at line 1480 of file TMultiGraph.cxx.
Save primitive as a C++ statement(s) on output stream out.
Reimplemented from TObject.
Definition at line 1493 of file TMultiGraph.cxx.
Set multigraph maximum.
Definition at line 1533 of file TMultiGraph.cxx.
Set multigraph minimum.
Definition at line 1543 of file TMultiGraph.cxx.
|
protected |
Definition at line 39 of file TMultiGraph.h.
|
protected |
Definition at line 38 of file TMultiGraph.h.
|
protected |
Definition at line 40 of file TMultiGraph.h.
|
protected |
Definition at line 41 of file TMultiGraph.h.
|
protected |
Definition at line 42 of file TMultiGraph.h.