Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMultiGraph Class Reference

A TMultiGraph is a collection of TGraph (or derived) objects.

Introduction

A TMultiGraph 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 number of graphs in a multigraph can be retrieve with:

mg->GetListOfGraphs()->GetEntries();

MultiGraphs' Drawing

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:

TGraph *gr1 = new TGraph(...
TGraphErrors *gr2 = new TGraphErrors(...
mg->Add(gr1,"lp");
mg->Add(gr2,"cp");
mg->Draw("a");
A TGraphErrors is a TGraph with error bars.
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition TMultiGraph.h:36
TMultiGraph()
TMultiGraph default constructor.
virtual void Add(TGraph *graph, Option_t *chopt="")
Add a new graph to the list of graphs.

Setting drawing options

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

Titles setting

The global title and the axis titles can be modified the following way:

[...]
auto mg = new TMultiGraph;
mg->SetTitle("title;xaxis title; yaxis title");
mg->Add(g1);
mg->Add(g2);
mg->Draw("apl");

The option "3D"

A special option 3D allows to draw the graphs in a 3D space. See the following example:

{
auto c0 = new TCanvas("c1","multigraph L3",200,10,700,500);
auto mg = new TMultiGraph();
auto gr1 = new TGraph(); gr1->SetLineColor(kBlue);
auto gr2 = new TGraph(); gr2->SetLineColor(kRed);
auto gr3 = new TGraph(); gr3->SetLineColor(kGreen);
auto gr4 = new TGraph(); gr4->SetLineColor(kOrange);
Double_t dx = 6.28/1000;
Double_t x = -3.14;
for (int i=0; i<=1000; i++) {
x = x+dx;
gr1->SetPoint(i,x,2.*TMath::Sin(x));
gr2->SetPoint(i,x,TMath::Cos(x));
gr3->SetPoint(i,x,TMath::Cos(x*x));
gr4->SetPoint(i,x,TMath::Cos(x*x*x));
}
mg->Add(gr4); gr4->SetTitle("Cos(x*x*x)"); gr4->SetLineWidth(3);
mg->Add(gr3); gr3->SetTitle("Cos(x*x)") ; gr3->SetLineWidth(3);
mg->Add(gr2); gr2->SetTitle("Cos(x)") ; gr2->SetLineWidth(3);
mg->Add(gr1); gr1->SetTitle("2*Sin(x)") ; gr1->SetLineWidth(3);
mg->SetTitle("Multi-graph Title; X-axis Title; Y-axis Title");
mg->Draw("a fb l3d");
mg->GetHistogram()->GetXaxis()->SetRangeUser(0.,2.5);
gPad->Modified();
gPad->Update();
}
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
@ kOrange
Definition Rtypes.h:67
@ kGreen
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
#define gPad
The Canvas class.
Definition TCanvas.h:23
Double_t x[n]
Definition legend1.C:17
Double_t Cos(Double_t)
Definition TMath.h:593
Double_t Sin(Double_t)
Definition TMath.h:589

Legend drawing

The method TPad::BuildLegend is able to extract the graphs inside a multigraph. The following example demonstrate this.

{
auto c3 = new TCanvas("c3","c3",600, 400);
auto mg = new TMultiGraph("mg","mg");
const Int_t size = 10;
double px[size];
double py1[size];
double py2[size];
double py3[size];
for ( int i = 0; i < size ; ++i ) {
px[i] = i;
py1[i] = size - i;
py2[i] = size - 0.5 * i;
py3[i] = size - 0.6 * i;
}
auto gr1 = new TGraph( size, px, py1 );
gr1->SetName("gr1");
gr1->SetTitle("graph 1");
gr1->SetMarkerStyle(21);
gr1->SetDrawOption("AP");
gr1->SetLineColor(2);
gr1->SetLineWidth(4);
gr1->SetFillStyle(0);
auto gr2 = new TGraph( size, px, py2 );
gr2->SetName("gr2");
gr2->SetTitle("graph 2");
gr2->SetMarkerStyle(22);
gr2->SetMarkerColor(2);
gr2->SetDrawOption("P");
gr2->SetLineColor(3);
gr2->SetLineWidth(4);
gr2->SetFillStyle(0);
auto gr3 = new TGraph( size, px, py3 );
gr3->SetName("gr3");
gr3->SetTitle("graph 3");
gr3->SetMarkerStyle(23);
gr3->SetLineColor(4);
gr3->SetLineWidth(4);
gr3->SetFillStyle(0);
mg->Add( gr1 );
mg->Add( gr2 );
gr3->Draw("ALP");
mg->Draw("LP");
c3->BuildLegend();
}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
return c3
Definition legend3.C:15

Automatic coloring

Automatic coloring according to the current palette is available as shown in the following example:

void multigraphpalettecolor()
{
auto mg = new TMultiGraph();
auto gr1 = new TGraph(); gr1->SetMarkerStyle(20);
auto gr2 = new TGraph(); gr2->SetMarkerStyle(21);
auto gr3 = new TGraph(); gr3->SetMarkerStyle(23);
auto gr4 = new TGraph(); gr4->SetMarkerStyle(24);
Double_t dx = 6.28/100;
Double_t x = -3.14;
for (int i=0; i<=100; i++) {
x = x+dx;
gr1->SetPoint(i,x,2.*TMath::Sin(x));
gr2->SetPoint(i,x,TMath::Cos(x));
gr3->SetPoint(i,x,TMath::Cos(x*x));
gr4->SetPoint(i,x,TMath::Cos(x*x*x));
}
mg->Add(gr4,"PL");
mg->Add(gr3,"PL");
mg->Add(gr2,"*L");
mg->Add(gr1,"PL");
mg->Draw("A pmc plc");
}

Reverse axis

Since
ROOT version 6.19/02

When a TMultiGraph is drawn, the X-axis is drawn with increasing values from left to right and the Y-axis from bottom to top. The two options RX and RY allow to change this order. The option RX allows to draw the X-axis with increasing values from right to left and the RY option allows to draw the Y-axis with increasing values from top to bottom. The following example illustrate how to use these options.

{
auto *c = new TCanvas();
c->Divide(2,1);
auto *g1 = new TGraphErrors();
g1->SetPoint(0,-4,-3);
g1->SetPoint(1,1,1);
g1->SetPoint(2,2,1);
g1->SetPoint(3,3,4);
g1->SetPoint(4,5,5);
g1->SetPointError(0,1.,2.);
g1->SetPointError(1,2,1);
g1->SetPointError(2,2,3);
g1->SetPointError(3,3,2);
g1->SetPointError(4,4,5);
g1->SetMarkerStyle(21);
auto *g2 = new TGraph();
g2->SetPoint(0,4,8);
g2->SetPoint(1,5,9);
g2->SetPoint(2,6,10);
g2->SetPoint(3,10,11);
g2->SetPoint(4,15,12);
g2->SetLineColor(kRed);
g2->SetLineWidth(5);
auto mg = new TMultiGraph();
mg->Add(g1,"P");
mg->Add(g2,"L");
c->cd(1); gPad->SetGrid(1,1);
mg->Draw("A");
c->cd(2); gPad->SetGrid(1,1);
mg->Draw("A RX RY");
}
#define c(i)
Definition RSha256.hxx:101

MultiGraphs' fitting

The following example shows how to fit a TMultiGraph.

{
auto c1 = new TCanvas("c1","c1",600,400);
Double_t px1[2] = {2.,4.};
Double_t dx1[2] = {0.1,0.1};
Double_t py1[2] = {2.1,4.0};
Double_t dy1[2] = {0.3,0.2};
Double_t px2[2] = {3.,5.};
Double_t dx2[2] = {0.1,0.1};
Double_t py2[2] = {3.2,4.8};
Double_t dy2[2] = {0.3,0.2};
gStyle->SetOptFit(0001);
auto g1 = new TGraphErrors(2,px1,py1,dx1,dy1);
g1->SetMarkerStyle(21);
g1->SetMarkerColor(2);
auto g2 = new TGraphErrors(2,px2,py2,dx2,dy2);
g2->SetMarkerStyle(22);
g2->SetMarkerColor(3);
auto g = new TMultiGraph();
g->Add(g1);
g->Add(g2);
g->Draw("AP");
g->Fit("pol1","FQ");
}
#define g(i)
Definition RSha256.hxx:105
R__EXTERN TStyle * gStyle
Definition TStyle.h:413
void SetOptFit(Int_t fit=1)
The type of information about fit parameters printed in the histogram statistics box can be selected ...
Definition TStyle.cxx:1541
return c1
Definition legend1.C:41

Fit box position

When the graphs in a TMultiGraph are fitted, the fit parameters boxes overlap. The following example shows how to make them all visible.

void multigraph()
{
auto c1 = new TCanvas("c1","multigraph",700,500);
c1->SetGrid();
// draw a frame to define the range
auto mg = new TMultiGraph();
// create first graph
const Int_t n1 = 10;
Double_t px1[] = {-0.1, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
Double_t py1[] = {-1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
Double_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
Double_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
auto gr1 = new TGraphErrors(n1,px1,py1,ex1,ey1);
gr1->SetMarkerColor(kBlue);
gr1->SetMarkerStyle(21);
gr1->Fit("pol6","q");
mg->Add(gr1);
// create second graph
const Int_t n2 = 10;
Float_t x2[] = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01};
Float_t y2[] = {2.1,3.86,7,9,10,10.55,9.64,7.26,5.42,2};
Float_t ex2[] = {.04,.12,.08,.06,.05,.04,.07,.06,.08,.04};
Float_t ey2[] = {.6,.8,.7,.4,.3,.3,.4,.5,.6,.7};
auto gr2 = new TGraphErrors(n2,x2,y2,ex2,ey2);
gr2->SetMarkerColor(kRed);
gr2->SetMarkerStyle(20);
gr2->Fit("pol5","q");
mg->Add(gr2);
mg->Draw("ap");
//force drawing of canvas to generate the fit TPaveStats
c1->Update();
auto stats1 = (TPaveStats*)gr1->GetListOfFunctions()->FindObject("stats");
auto stats2 = (TPaveStats*)gr2->GetListOfFunctions()->FindObject("stats");
stats1->SetTextColor(kBlue);
stats2->SetTextColor(kRed);
stats1->SetX1NDC(0.12); stats1->SetX2NDC(0.32); stats1->SetY1NDC(0.75);
stats2->SetX1NDC(0.72); stats2->SetX2NDC(0.92); stats2->SetY1NDC(0.78);
c1->Modified();
}
static const double x2[5]
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
The histogram statistics painter class.
Definition TPaveStats.h:18

Axis' limits setting

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.

{
auto c2 = new TCanvas("c2","c2",600,400);
TGraph *g[3];
Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
Double_t y[10] = {1,2,3,4,5,5,4,3,2,1};
auto mg = new TMultiGraph();
for (int i=0; i<3; i++) {
g[i] = new TGraph(10, x, y);
g[i]->SetMarkerStyle(20);
g[i]->SetMarkerColor(i+2);
for (int j=0; j<10; j++) y[j] = y[j]-1;
mg->Add(g[i]);
}
mg->Draw("APL");
mg->GetXaxis()->SetTitle("E_{#gamma} (GeV)");
mg->GetYaxis()->SetTitle("Coefficients");
// Change the axis limits
gPad->Modified();
mg->GetXaxis()->SetLimits(1.5,7.5);
mg->SetMinimum(0.);
mg->SetMaximum(10.);
}
Double_t y[n]
Definition legend1.C:17
return c2
Definition legend2.C:14

Definition at line 36 of file TMultiGraph.h.

Public Member Functions

 TMultiGraph ()
 TMultiGraph default constructor.
 
 TMultiGraph (const char *name, const char *title)
 Constructor with name and title.
 
virtual ~TMultiGraph ()
 TMultiGraph destructor.
 
virtual void Add (TGraph *graph, Option_t *chopt="")
 Add a new graph to the list of graphs.
 
virtual void Add (TMultiGraph *multigraph, Option_t *chopt="")
 Add all the graphs in "multigraph" to the list of graphs.
 
TIter begin () const
 Get iterator over internal graphs list.
 
virtual void Browse (TBrowser *b)
 Browse multigraph.
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 Compute distance from point px,py to each graph.
 
virtual void Draw (Option_t *chopt="")
 Draw this multigraph with its current attributes.
 
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.
 
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.
 
virtual void FitPanel ()
 Display a panel with all histogram fit options.
 
TF1GetFunction (const char *name) const
 Return pointer to function with name.
 
virtual Option_tGetGraphDrawOption (const TGraph *gr) const
 Return the draw option for the TGraph gr in this TMultiGraph.
 
TH1FGetHistogram ()
 Returns a pointer to the histogram used to draw the axis.
 
TListGetListOfFunctions ()
 Return pointer to list of functions.
 
const TListGetListOfFunctions () const
 
TListGetListOfGraphs () const
 
TAxisGetXaxis ()
 Get x axis of the graph.
 
TAxisGetYaxis ()
 Get y axis of the graph.
 
virtual void InitExpo (Double_t xmin, Double_t xmax)
 Compute Initial values of parameters for an exponential.
 
virtual void InitGaus (Double_t xmin, Double_t xmax)
 Compute Initial values of parameters for a gaussian.
 
virtual void InitPolynom (Double_t xmin, Double_t xmax)
 Compute Initial values of parameters for a polynom.
 
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.
 
virtual void LeastSquareFit (Int_t m, Double_t *a, Double_t xmin, Double_t xmax)
 Least squares lpolynomial fitting without weights.
 
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.
 
virtual void Paint (Option_t *chopt="")
 Paint all the graphs of this multigraph.
 
void PaintPads (Option_t *chopt="")
 Divides the active pad and draws all Graphs in the Multigraph separately.
 
void PaintPolyLine3D (Option_t *chopt="")
 Paint all the graphs of this multigraph as 3D lines.
 
void PaintReverse (Option_t *chopt="")
 Paint all the graphs of this multigraph reverting values along X and/or Y axis.
 
virtual void Print (Option_t *chopt="") const
 Print the list of graphs.
 
virtual void RecursiveRemove (TObject *obj)
 Recursively remove this object from a list.
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 Save primitive as a C++ statement(s) on output stream out.
 
virtual void SetMaximum (Double_t maximum=-1111)
 Set multigraph maximum.
 
virtual void SetMinimum (Double_t minimum=-1111)
 Set multigraph minimum.
 
- Public Member Functions inherited from TNamed
 TNamed ()
 
 TNamed (const char *name, const char *title)
 
 TNamed (const TNamed &named)
 TNamed copy ctor.
 
 TNamed (const TString &name, const TString &title)
 
virtual ~TNamed ()
 TNamed destructor.
 
virtual void Clear (Option_t *option="")
 Set name and title to empty strings ("").
 
virtual TObjectClone (const char *newname="") const
 Make a clone of an object using the Streamer facility.
 
virtual Int_t Compare (const TObject *obj) const
 Compare two TNamed objects.
 
virtual void Copy (TObject &named) const
 Copy this to obj.
 
virtual void FillBuffer (char *&buffer)
 Encode TNamed into output buffer.
 
virtual const char * GetName () const
 Returns name of object.
 
virtual const char * GetTitle () const
 Returns title of object.
 
virtual ULong_t Hash () const
 Return hash value for this object.
 
virtual Bool_t IsSortable () const
 
virtual void ls (Option_t *option="") const
 List TNamed name and title.
 
TNamedoperator= (const TNamed &rhs)
 TNamed assignment operator.
 
virtual void SetName (const char *name)
 Set the name of the TNamed.
 
virtual void SetNameTitle (const char *name, const char *title)
 Set all the TNamed parameters (name and title).
 
virtual void SetTitle (const char *title="")
 Set the title of the TNamed.
 
virtual Int_t Sizeof () const
 Return size of the TNamed part of the TObject.
 
- Public Member Functions inherited from TObject
 TObject ()
 TObject constructor.
 
 TObject (const TObject &object)
 TObject copy ctor.
 
virtual ~TObject ()
 TObject destructor.
 
void AbstractMethod (const char *method) const
 Use this method to implement an "abstract" method that you don't want to leave purely abstract.
 
virtual void AppendPad (Option_t *option="")
 Append graphics object to current pad.
 
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.
 
virtual const char * ClassName () const
 Returns name of class to which the object belongs.
 
virtual void Delete (Option_t *option="")
 Delete this object.
 
virtual void DrawClass () const
 Draw class inheritance tree of the class to which this object belongs.
 
virtual TObjectDrawClone (Option_t *option="") const
 Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad).
 
virtual void Dump () const
 Dump contents of object on stdout.
 
virtual void Error (const char *method, const char *msgfmt,...) const
 Issue error message.
 
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.
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=0)
 Execute method on this object with parameters stored in the TObjArray.
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 Execute action corresponding to an event at (px,py).
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 Issue fatal error message.
 
virtual TObjectFindObject (const char *name) const
 Must be redefined in derived classes.
 
virtual TObjectFindObject (const TObject *obj) const
 Must be redefined in derived classes.
 
virtual Option_tGetDrawOption () const
 Get option used by the graphics system to draw this object.
 
virtual const char * GetIconName () const
 Returns mime type name of object.
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 Returns string containing info about the object at position (px,py).
 
virtual Option_tGetOption () const
 
virtual UInt_t GetUniqueID () const
 Return the unique object id.
 
virtual Bool_t HandleTimer (TTimer *timer)
 Execute action in response of a timer timing out.
 
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.
 
virtual void Info (const char *method, const char *msgfmt,...) const
 Issue info message.
 
virtual Bool_t InheritsFrom (const char *classname) const
 Returns kTRUE if object inherits from class "classname".
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 Returns kTRUE if object inherits from TClass cl.
 
virtual void Inspect () const
 Dump contents of this object in a graphics canvas.
 
void InvertBit (UInt_t f)
 
Bool_t IsDestructed () const
 IsDestructed.
 
virtual Bool_t IsEqual (const TObject *obj) const
 Default equal comparison (objects are equal if they have the same address in memory).
 
virtual Bool_t IsFolder () const
 Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
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).
 
virtual Bool_t Notify ()
 This method must be overridden to handle object notification.
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 Use this method to declare a method obsolete.
 
void operator delete (void *ptr)
 Operator delete.
 
void operator delete[] (void *ptr)
 Operator delete [].
 
voidoperator new (size_t sz)
 
voidoperator new (size_t sz, void *vp)
 
voidoperator new[] (size_t sz)
 
voidoperator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 TObject assignment operator.
 
virtual void Pop ()
 Pop on object drawn in a pad to the top of the display list.
 
virtual Int_t Read (const char *name)
 Read contents of object with specified name from the current directory.
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 Save this object in the file specified by filename.
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 Set or unset the user status bits as specified in f.
 
virtual void SetDrawOption (Option_t *option="")
 Set drawing option for object.
 
virtual void SetUniqueID (UInt_t uid)
 Set the unique object id.
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 Issue system error message.
 
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.
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 Issue warning message.
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0)
 Write this object to the current directory.
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0) const
 Write this object to the current directory.
 

Protected Member Functions

 TMultiGraph (const TMultiGraph &)
 Copy constructor.
 
TMultiGraphoperator= (const TMultiGraph &)
 Assignment operator.
 
- 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).
 
void MakeZombie ()
 

Protected Attributes

TListfFunctions
 Pointer to list of functions (fits and user)
 
TListfGraphs
 Pointer to list of TGraphs.
 
TH1FfHistogram
 Pointer to histogram used for drawing axis.
 
Double_t fMaximum
 Maximum value for plotting along y.
 
Double_t fMinimum
 Minimum value for plotting along y.
 
- 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 Longptr_t GetDtorOnly ()
 Return destructor only flag.
 
static Bool_t GetObjectStat ()
 Get status of object stat flag.
 
static void SetDtorOnly (void *obj)
 Set destructor only flag.
 
static void SetObjectStat (Bool_t stat)
 Turn on/off tracking of objects in the TObjectTable.
 
- Protected Types inherited from TObject
enum  { kOnlyPrepStep = BIT(3) }
 

#include <TMultiGraph.h>

Inheritance diagram for TMultiGraph:
[legend]

Constructor & Destructor Documentation

◆ TMultiGraph() [1/3]

TMultiGraph::TMultiGraph ( const TMultiGraph mg)
protected

Copy constructor.

Definition at line 396 of file TMultiGraph.cxx.

◆ TMultiGraph() [2/3]

TMultiGraph::TMultiGraph ( )

TMultiGraph default constructor.

Definition at line 369 of file TMultiGraph.cxx.

◆ TMultiGraph() [3/3]

TMultiGraph::TMultiGraph ( const char *  name,
const char *  title 
)

Constructor with name and title.

Definition at line 382 of file TMultiGraph.cxx.

◆ ~TMultiGraph()

TMultiGraph::~TMultiGraph ( )
virtual

TMultiGraph destructor.

Definition at line 427 of file TMultiGraph.cxx.

Member Function Documentation

◆ Add() [1/2]

void TMultiGraph::Add ( TGraph graph,
Option_t chopt = "" 
)
virtual

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 462 of file TMultiGraph.cxx.

◆ Add() [2/2]

void TMultiGraph::Add ( TMultiGraph multigraph,
Option_t chopt = "" 
)
virtual

Add all the graphs in "multigraph" to the list of graphs.

  • If "chopt" is defined all the graphs in "multigraph" will be added with the "chopt" option.
  • If "chopt" is undefined each graph will be added with the option it had in "multigraph".

Definition at line 478 of file TMultiGraph.cxx.

◆ begin()

TIter TMultiGraph::begin ( ) const

Get iterator over internal graphs list.

Definition at line 1716 of file TMultiGraph.cxx.

◆ Browse()

void TMultiGraph::Browse ( TBrowser b)
virtual

Browse multigraph.

Reimplemented from TObject.

Definition at line 500 of file TMultiGraph.cxx.

◆ DistancetoPrimitive()

Int_t TMultiGraph::DistancetoPrimitive ( Int_t  px,
Int_t  py 
)
virtual

Compute distance from point px,py to each graph.

Reimplemented from TObject.

Definition at line 515 of file TMultiGraph.cxx.

◆ Draw()

void TMultiGraph::Draw ( Option_t option = "")
virtual

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 552 of file TMultiGraph.cxx.

◆ end()

TIter TMultiGraph::end ( ) const
inline

Definition at line 72 of file TMultiGraph.h.

◆ Fit() [1/2]

TFitResultPtr TMultiGraph::Fit ( const char *  fname,
Option_t option = "",
Option_t goption = "",
Axis_t  xmin = 0,
Axis_t  xmax = 0 
)
virtual

Fit this graph with function with name fname.

interface to TF1::Fit(TF1 *f1...

Definition at line 570 of file TMultiGraph.cxx.

◆ Fit() [2/2]

TFitResultPtr TMultiGraph::Fit ( TF1 f1,
Option_t option = "",
Option_t goption = "",
Axis_t  rxmin = 0,
Axis_t  rxmax = 0 
)
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 optionwhich may takes the following values:

  • "W" Ignore all the point errors
  • "U" Use a User specified fitting algorithm (via SetFCN)
  • "Q" Quiet mode (minimum printing)
  • "V" Verbose mode (default is between Q and V)
  • "B" Use this option when you want to fix one or more parameters and the fitting function is like "gaus","expo","poln","landau".
  • "R" Use the Range specified in the function range
  • "N" Do not store the graphics function, do not draw
  • "0" Do not plot the result of the fit. By default the fitted function is drawn unless the option"N" above is specified.
  • "+" Add this new fitted function to the list of fitted functions (by default, any previous function is deleted)
  • "C" In case of linear fitting, not calculate the chisquare (saves time)
  • "F" If fitting a polN, switch to minuit fitter
  • "ROB" In case of linear fitting, compute the LTS regression coefficients (robust(resistant) regression), using the default fraction of good points
  • "ROB=0.x" - compute the LTS regression coefficients, using 0.x as a fraction of good points

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:

TF1 *f1 = new TF1("f1","gaus",1,3);
graph->Fit("f1","R");
1-Dim function class
Definition TF1.h:213
TF1 * f1
Definition legend1.C:11
Definition graph.py:1

Who is calling this function ?

Note that this function is called when calling TGraphErrors::Fit or TGraphAsymmErrors::Fit ot TGraphBentErrors::Fit see the discussion below on the errors calculation.

Setting initial conditions

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

f1->SetParLimits(p_number, parmin, parmax);
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set limits for parameter ipar.
Definition TF1.cxx:3518

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:

func->SetParameters(0,3.1,1.e-6,0.1,-8,100);
func->SetParLimits(4,-10,-4);
func->SetParLimits(5, 1,1);

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.

Fit range

The fit range can be specified in two ways:

  • specify rxmax > rxmin (default is rxmin=rxmax=0)
  • specify the option "R". In this case, the function will be taken instead of the full graph range.

Changing the fitting function

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:

TVirtualFitter::Fitter(mygraph)->SetFCN(MyFittingFunction)
virtual void SetFCN(void(*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
To set the address of the minimization objective function called by the native compiler (see function...
static TVirtualFitter * Fitter(TObject *obj, Int_t maxpar=25)
Static function returning a pointer to the current fitter.

where MyFittingFunction is of type:

extern void MyFittingFunction(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag);
#define f(i)
Definition RSha256.hxx:104

Access to the fit result

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:

TFitResultPtr r = graph->Fit("myFunc","S");
TMatrixDSym cov = r->GetCovarianceMatrix(); // to access the covariance matrix
Double_t par0 = r->Parameter(0); // retrieve the value for the parameter 0
Double_t err0 = r->ParError(0); // retrieve the error for the parameter 0
r->Print("V"); // print full information of fit including covariance matrix
r->Write(); // store the result in a file
ROOT::R::TRInterface & r
Definition Object.C:4
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition TObject.cxx:868
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition TObject.cxx:622

The fit parameters, error and chi2 (but not covariance matrix) can be retrieved also from the fitted function.

Associated functions

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:

TF1 *myfunc = gr->GetFunction("myfunc");
TF1 * GetFunction(const char *name) const
Return pointer to function with name.
Definition TGraph.cxx:1473
TGraphErrors * gr
Definition legend1.C:25

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:

Double_t chi2 = myfunc->GetChisquare();
Double_t par0 = myfunc->GetParameter(0); //value of 1st parameter
Double_t err0 = myfunc->GetParError(0); //error on first parameter
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition TF1.cxx:1926
Double_t GetChisquare() const
Definition TF1.h:444
virtual Double_t GetParameter(Int_t ipar) const
Definition TF1.h:512

Fit Statistics

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)

  • v = 1; print name/values of parameters
  • e = 1; print errors (if e=1, v must be 1)
  • c = 1; print Chisquare/Number of degrees of freedom
  • p = 1; print Probability

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):

Root > TPaveStats *st = (TPaveStats*)g->GetListOfFunctions()->FindObject("stats")
Root > st->SetX1NDC(newx1); //new x start position
Root > st->SetX2NDC(newx2); //new x end position
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:393

Definition at line 744 of file TMultiGraph.cxx.

◆ FitPanel()

void TMultiGraph::FitPanel ( )
virtual

Display a panel with all histogram fit options.

See class TFitPanel for example

Definition at line 761 of file TMultiGraph.cxx.

◆ GetFunction()

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 1124 of file TMultiGraph.cxx.

◆ GetGraphDrawOption()

Option_t * TMultiGraph::GetGraphDrawOption ( const TGraph gr) const
virtual

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 785 of file TMultiGraph.cxx.

◆ GetHistogram()

TH1F * TMultiGraph::GetHistogram ( )

Returns a pointer to the histogram used to draw the axis.

Takes into account following cases.

  1. if fHistogram exists it is returned
  2. if fHistogram 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 returned
  3. after the two previous steps, if fHistogram still doesn't exist, then it is created.

Definition at line 1060 of file TMultiGraph.cxx.

◆ GetListOfFunctions() [1/2]

TList * TMultiGraph::GetListOfFunctions ( )

Return pointer to list of functions.

If pointer is null create the list

Definition at line 1134 of file TMultiGraph.cxx.

◆ GetListOfFunctions() [2/2]

const TList * TMultiGraph::GetListOfFunctions ( ) const
inline

Definition at line 74 of file TMultiGraph.h.

◆ GetListOfGraphs()

TList * TMultiGraph::GetListOfGraphs ( ) const
inline

Definition at line 70 of file TMultiGraph.h.

◆ GetXaxis()

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 1145 of file TMultiGraph.cxx.

◆ GetYaxis()

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 1157 of file TMultiGraph.cxx.

◆ InitExpo()

void TMultiGraph::InitExpo ( Double_t  xmin,
Double_t  xmax 
)
virtual

Compute Initial values of parameters for an exponential.

Definition at line 845 of file TMultiGraph.cxx.

◆ InitGaus()

void TMultiGraph::InitGaus ( Double_t  xmin,
Double_t  xmax 
)
virtual

Compute Initial values of parameters for a gaussian.

Definition at line 800 of file TMultiGraph.cxx.

◆ InitPolynom()

void TMultiGraph::InitPolynom ( Double_t  xmin,
Double_t  xmax 
)
virtual

Compute Initial values of parameters for a polynom.

Definition at line 862 of file TMultiGraph.cxx.

◆ IsInside()

Int_t TMultiGraph::IsInside ( Double_t  x,
Double_t  y 
) const
virtual

Return 1 if the point (x,y) is inside one of the graphs 0 otherwise.

Definition at line 1034 of file TMultiGraph.cxx.

◆ LeastSquareFit()

void TMultiGraph::LeastSquareFit ( Int_t  m,
Double_t a,
Double_t  xmin,
Double_t  xmax 
)
virtual

Least squares lpolynomial fitting without weights.

  • m number of parameters
  • a array of parameters
  • first 1st point number to fit (default =0)
  • last last point number to fit (default=fNpoints-1)

based on CERNLIB routine LSQ: Translated to C++ by Rene Brun

Definition at line 886 of file TMultiGraph.cxx.

◆ LeastSquareLinearFit()

void TMultiGraph::LeastSquareLinearFit ( Int_t  ndata,
Double_t a0,
Double_t a1,
Int_t ifail,
Double_t  xmin,
Double_t  xmax 
)
virtual

Least square linear fit without weights.

Fit a straight line (a0 + a1*x) to the data in this graph.

  • ndata: number of points to fit
  • first: first point number to fit
  • last: last point to fit O(ndata should be last-first
  • ifail: return parameter indicating the status of the fit (ifail=0, fit is OK)

extracted from CERNLIB LLSQ: Translated to C++ by Rene Brun

Definition at line 981 of file TMultiGraph.cxx.

◆ operator=()

TMultiGraph & TMultiGraph::operator= ( const TMultiGraph mg)
protected

Assignment operator.

Definition at line 410 of file TMultiGraph.cxx.

◆ Paint()

void TMultiGraph::Paint ( Option_t chopt = "")
virtual

Paint all the graphs of this multigraph.

Reimplemented from TObject.

Definition at line 1168 of file TMultiGraph.cxx.

◆ PaintPads()

void TMultiGraph::PaintPads ( Option_t chopt = "")

Divides the active pad and draws all Graphs in the Multigraph separately.

Definition at line 1423 of file TMultiGraph.cxx.

◆ PaintPolyLine3D()

void TMultiGraph::PaintPolyLine3D ( Option_t chopt = "")

Paint all the graphs of this multigraph as 3D lines.

Definition at line 1472 of file TMultiGraph.cxx.

◆ PaintReverse()

void TMultiGraph::PaintReverse ( Option_t option = "")

Paint all the graphs of this multigraph reverting values along X and/or Y axis.

New graphs are created.

Definition at line 1576 of file TMultiGraph.cxx.

◆ Print()

void TMultiGraph::Print ( Option_t chopt = "") const
virtual

Print the list of graphs.

Reimplemented from TNamed.

Definition at line 1611 of file TMultiGraph.cxx.

◆ RecursiveRemove()

void TMultiGraph::RecursiveRemove ( TObject obj)
virtual

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 1627 of file TMultiGraph.cxx.

◆ SavePrimitive()

void TMultiGraph::SavePrimitive ( std::ostream &  out,
Option_t option = "" 
)
virtual

Save primitive as a C++ statement(s) on output stream out.

Reimplemented from TObject.

Definition at line 1651 of file TMultiGraph.cxx.

◆ SetMaximum()

void TMultiGraph::SetMaximum ( Double_t  maximum = -1111)
virtual

Set multigraph maximum.

Definition at line 1696 of file TMultiGraph.cxx.

◆ SetMinimum()

void TMultiGraph::SetMinimum ( Double_t  minimum = -1111)
virtual

Set multigraph minimum.

Definition at line 1706 of file TMultiGraph.cxx.

Member Data Documentation

◆ fFunctions

TList* TMultiGraph::fFunctions
protected

Pointer to list of functions (fits and user)

Definition at line 40 of file TMultiGraph.h.

◆ fGraphs

TList* TMultiGraph::fGraphs
protected

Pointer to list of TGraphs.

Definition at line 39 of file TMultiGraph.h.

◆ fHistogram

TH1F* TMultiGraph::fHistogram
protected

Pointer to histogram used for drawing axis.

Definition at line 41 of file TMultiGraph.h.

◆ fMaximum

Double_t TMultiGraph::fMaximum
protected

Maximum value for plotting along y.

Definition at line 42 of file TMultiGraph.h.

◆ fMinimum

Double_t TMultiGraph::fMinimum
protected

Minimum value for plotting along y.

Definition at line 43 of file TMultiGraph.h.

Libraries for TMultiGraph:

The documentation for this class was generated from the following files: