Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
gr008_multierrors.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook -js
4/// \preview Draw a graph with multiple errors. Multi errors can be usefull for distinguishing different type of errors,
5/// for example statistical and systematic errors.
6///
7/// \macro_image
8/// \macro_code
9///
10/// \author Simon Spies
11
12void gr008_multierrors() {
13 TCanvas *c1 = new TCanvas("c1", "A Simple Graph with multiple y-errors", 200, 10, 700, 500);
14 c1->SetGrid();
15 c1->GetFrame()->SetBorderSize(12);
16
17 const Int_t np = 5;
18 Double_t x[np] = {0, 1, 2, 3, 4};
19 Double_t y[np] = {0, 2, 4, 1, 3};
20 Double_t exl[np] = {0.3, 0.3, 0.3, 0.3, 0.3}; //Lower x errors
21 Double_t exh[np] = {0.3, 0.3, 0.3, 0.3, 0.3}; //Higher x errors
22 Double_t eylstat[np] = {1, 0.5, 1, 0.5, 1}; //Lower y statistical errors
23 Double_t eyhstat[np] = {0.5, 1, 0.5, 1, 0.5}; //Higher y statistical errors
24 Double_t eylsys[np] = {0.5, 0.4, 0.8, 0.3, 1.2}; //Lower y systematic errors
25 Double_t eyhsys[np] = {0.6, 0.7, 0.6, 0.4, 0.8}; //Higher y systematic errors
26
27 TGraphMultiErrors *gme = new TGraphMultiErrors("gme", "TGraphMultiErrors Example", np, x, y, exl, exh, eylstat, eyhstat); //Create the TGraphMultiErrors object
28 gme->AddYError(np, eylsys, eyhsys); //Add the systematic y-errors to the graph
29 gme->SetMarkerStyle(20);
30 gme->SetLineColor(kRed);
31 gme->GetAttLine(0)->SetLineColor(kRed); //Color for statistical error bars
32 gme->GetAttLine(1)->SetLineColor(kBlue); //Color for systematic error bars
33 gme->GetAttFill(1)->SetFillStyle(0);
34
35 //Graph is drawn with the option "APS": "A" draw axes, "P" draw points and "S" draw symmetric horizontal error bars (x-errors)
36 //Statistical y-errors are drawn with the option "Z" vertical error bars.
37 //Systematic y-errors are drawn with the option "5 s=0.5":
38 //"5" draw rectangles to represent the systematic y-error bars.
39 //"s=0.5" scale the rectangles horizontally (along the x-axis) by a factor of 0.5.
40 gme->Draw("APS ; Z ; 5 s=0.5");
41
42
43 c1->Update();
44}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
@ kRed
Definition Rtypes.h:67
@ kBlue
Definition Rtypes.h:67
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:42
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:43
The Canvas class.
Definition TCanvas.h:23
virtual TAttFill * GetAttFill(Int_t e)
virtual TAttLine * GetAttLine(Int_t e)
virtual void AddYError(Int_t np, const Double_t *eyL=nullptr, const Double_t *eyH=nullptr)
virtual void SetLineColor(Int_t e, Color_t lcolor)
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
return c1
Definition legend1.C:41
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17