Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGraphMultiErrors.h
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Simon Spies 18/02/19
3
4/*************************************************************************
5 * Copyright (C) 2018-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TGraphMultiErrors
13#define ROOT_TGraphMultiErrors
14
15//////////////////////////////////////////////////////////////////////////
16// //
17// TGraphMultiErrors //
18// //
19// a Graph with asymmetric error bars and multiple y errors //
20// //
21//////////////////////////////////////////////////////////////////////////
22
23#include "TGraph.h"
24#include <vector>
25
26class TArrayF;
27class TArrayD;
28
29class TGraphMultiErrors : public TGraph {
30
31protected:
32 Int_t fNYErrors; ///< The amount of different y-errors
33 Int_t fSumErrorsMode; ///< How y errors are summed: kOnlyFirst = Only First; kSquareSum = Squared Sum; kSum =
34 ///< Absolute Addition
35 Double_t *fExL; ///<[fNpoints] array of X low errors
36 Double_t *fExH; ///<[fNpoints] array of X high errors
37 std::vector<TArrayD> fEyL; ///< Two dimensional array of Y low errors
38 std::vector<TArrayD> fEyH; ///< Two dimensional array of Y high errors
39 mutable Double_t *fEyLSum = nullptr; ///<! Array of summed Y low errors for fitting
40 mutable Double_t *fEyHSum = nullptr; ///<! Array of summed Y high errors for fitting
41 std::vector<TAttFill> fAttFill; ///< The AttFill attributes of the different errors
42 std::vector<TAttLine> fAttLine; ///< The AttLine attributes of the different errors
43
44 Double_t **Allocate(Int_t size) override;
46
47 void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin) override;
48 Bool_t CopyPoints(Double_t **arrays, Int_t ibegin, Int_t iend, Int_t obegin) override;
49 void FillZero(Int_t begin, Int_t end, Bool_t from_ctor = kTRUE) override;
50
51 void CalcYErrorsSum() const;
52 Bool_t DoMerge(const TGraph *tg) override;
53 void SwapPoints(Int_t pos1, Int_t pos2) override;
54 void UpdateArrays(const std::vector<Int_t> &sorting_indices, Int_t numSortedPoints, Int_t low) override;
55
56public:
58 kOnlyFirst = 0, ///< Only take errors from first dimension
59 kSquareSum = 1, ///< Calculate the square sum of all errors
60 kAbsSum = 2 ///< Calculate the absolute sum of all errors
61 };
62
64 TGraphMultiErrors(const Char_t *name, const Char_t *title);
66 TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne = 1);
67
68 TGraphMultiErrors(Int_t np, const Float_t *x, const Float_t *y, const Float_t *exL = nullptr,
69 const Float_t *exH = nullptr, const Float_t *eyL = nullptr, const Float_t *eyH = nullptr,
71 TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, const Float_t *x, const Float_t *y,
72 const Float_t *exL = nullptr, const Float_t *exH = nullptr, const Float_t *eyL = nullptr,
73 const Float_t *eyH = nullptr, Int_t m = kOnlyFirst);
74 TGraphMultiErrors(Int_t np, const Double_t *x, const Double_t *y, const Double_t *exL = nullptr,
75 const Double_t *exH = nullptr, const Double_t *eyL = nullptr, const Double_t *eyH = nullptr,
77 TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, const Double_t *x, const Double_t *y,
78 const Double_t *exL = nullptr, const Double_t *exH = nullptr, const Double_t *eyL = nullptr,
79 const Double_t *eyH = nullptr, Int_t m = kOnlyFirst);
80
81 TGraphMultiErrors(Int_t np, Int_t ne, const Float_t *x, const Float_t *y, const Float_t *exL, const Float_t *exH,
82 std::vector<std::vector<Float_t>> eyL, std::vector<std::vector<Float_t>> eyH,
84 TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne, const Float_t *x, const Float_t *y,
85 const Float_t *exL, const Float_t *exH, std::vector<std::vector<Float_t>> eyL,
86 std::vector<std::vector<Float_t>> eyH, Int_t m = kOnlyFirst);
87 TGraphMultiErrors(Int_t np, Int_t ne, const Double_t *x, const Double_t *y, const Double_t *exL, const Double_t *exH,
88 std::vector<std::vector<Double_t>> eyL, std::vector<std::vector<Double_t>> eyH,
90 TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne, const Double_t *x, const Double_t *y,
91 const Double_t *exL, const Double_t *exH, std::vector<std::vector<Double_t>> eyL,
92 std::vector<std::vector<Double_t>> eyH, Int_t m = kOnlyFirst);
93
94 TGraphMultiErrors(Int_t np, Int_t ne, const Float_t *x, const Float_t *y, const Float_t *exL, const Float_t *exH,
95 std::vector<TArrayF> eyL, std::vector<TArrayF> eyH, Int_t m = kOnlyFirst);
96 TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne, const Float_t *x, const Float_t *y,
97 const Float_t *exL, const Float_t *exH, std::vector<TArrayF> eyL, std::vector<TArrayF> eyH,
99 TGraphMultiErrors(Int_t np, Int_t ne, const Double_t *x, const Double_t *y, const Double_t *exL, const Double_t *exH,
100 std::vector<TArrayD> eyL, std::vector<TArrayD> eyH, Int_t m = kOnlyFirst);
101 TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne, const Double_t *x, const Double_t *y,
102 const Double_t *exL, const Double_t *exH, std::vector<TArrayD> eyL, std::vector<TArrayD> eyH,
103 Int_t m = kOnlyFirst);
104
105 TGraphMultiErrors(const TVectorF &tvX, const TVectorF &tvY, const TVectorF &tvExL, const TVectorF &tvExH,
106 const TVectorF &tvEyL, const TVectorF &tvEyH, Int_t m = kOnlyFirst);
107 TGraphMultiErrors(const TVectorD &tvX, const TVectorD &tvY, const TVectorD &tvExL, const TVectorD &tvExH,
108 const TVectorD &tvEyL, const TVectorD &tvEyH, Int_t m = kOnlyFirst);
109
110 TGraphMultiErrors(Int_t ne, const TVectorF &tvX, const TVectorF &tvY, const TVectorF &tvExL, const TVectorF &tvExH,
111 const TVectorF *tvEyL, const TVectorF *tvEyH, Int_t m = kOnlyFirst);
112 TGraphMultiErrors(Int_t ne, const TVectorD &tvX, const TVectorD &tvY, const TVectorD &tvExL, const TVectorD &tvExH,
113 const TVectorD *tvEyL, const TVectorD *tvEyH, Int_t m = kOnlyFirst);
114
117
118 TGraphMultiErrors(const TH1 *th, Int_t ne = 1);
119 TGraphMultiErrors(const TH1 *pass, const TH1 *total, Int_t ne = 1, Option_t *option = "");
120
121 ~TGraphMultiErrors() override;
122
123 virtual void AddYError(Int_t np, const Double_t *eyL = nullptr, const Double_t *eyH = nullptr);
124 void Apply(TF1 *f) override;
125 virtual void BayesDivide(const TH1 *pass, const TH1 *total, Option_t *opt = "");
126 void Divide(const TH1 *pass, const TH1 *total, Option_t *opt = "cp");
127 void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override;
128 virtual void DeleteYError(Int_t e);
129
130 Double_t GetErrorX(Int_t i) const override;
131 Double_t GetErrorY(Int_t i) const override;
132 virtual Double_t GetErrorY(Int_t i, Int_t e) const;
133
134 Double_t GetErrorXlow(Int_t i) const override;
135 Double_t GetErrorXhigh(Int_t i) const override;
136 Double_t GetErrorYlow(Int_t i) const override;
137 Double_t GetErrorYhigh(Int_t i) const override;
138 virtual Double_t GetErrorYlow(Int_t i, Int_t e) const;
139 virtual Double_t GetErrorYhigh(Int_t i, Int_t e) const;
140
141 Double_t *GetEXlow() const override { return fExL; }
142 Double_t *GetEXhigh() const override { return fExH; }
143 Double_t *GetEYlow() const override;
144 Double_t *GetEYhigh() const override;
145 virtual Double_t *GetEYlow(Int_t e);
146 virtual Double_t *GetEYhigh(Int_t e);
147
148 virtual TAttFill *GetAttFill(Int_t e);
149 virtual TAttLine *GetAttLine(Int_t e);
150
153
154 virtual Color_t GetFillColor(Int_t e) const;
155 virtual Style_t GetFillStyle(Int_t e) const;
156
160
161 virtual Color_t GetLineColor(Int_t e) const;
162 virtual Style_t GetLineStyle(Int_t e) const;
163 virtual Width_t GetLineWidth(Int_t e) const;
164
166 Int_t GetNYErrors() const { return fNYErrors; }
167
168 void Print(Option_t *chopt = "") const override;
169 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
170 void Scale(Double_t c1=1., Option_t *option="y") override; // *MENU*
171
172 virtual void SetPointError(Double_t exL, Double_t exH, Double_t eyL1, Double_t eyH1, Double_t eyL2 = 0.,
173 Double_t eyH2 = 0., Double_t eyL3 = 0., Double_t eyH3 = 0.); // *MENU*
174 virtual void SetPointError(Int_t i, Int_t ne, Double_t exL, Double_t exH, const Double_t *eyL, const Double_t *eyH);
175
176 virtual void SetPointEX(Int_t i, Double_t exL, Double_t exH);
177 virtual void SetPointEXlow(Int_t i, Double_t exL);
178 virtual void SetPointEXhigh(Int_t i, Double_t exH);
179 virtual void SetPointEY(Int_t i, Int_t ne, const Double_t *eyL, const Double_t *eyH);
180 virtual void SetPointEYlow(Int_t i, Int_t ne, const Double_t *eyL);
181 virtual void SetPointEYhigh(Int_t i, Int_t ne, const Double_t *eyH);
182 virtual void SetPointEY(Int_t i, Int_t e, Double_t eyL, Double_t eyH);
183 virtual void SetPointEYlow(Int_t i, Int_t e, Double_t eyL);
184 virtual void SetPointEYhigh(Int_t i, Int_t e, Double_t eyH);
185
186 virtual void SetEY(Int_t e, Int_t np, const Double_t *eyL, const Double_t *eyH);
187 virtual void SetEYlow(Int_t e, Int_t np, const Double_t *eyL);
188 virtual void SetEYhigh(Int_t e, Int_t np, const Double_t *eyH);
189
190 virtual void SetSumErrorsMode(Int_t m);
191
192 virtual void SetAttFill(Int_t e, TAttFill *taf);
193 virtual void SetAttLine(Int_t e, TAttLine *tal);
194
198
199 virtual void SetFillColor(Int_t e, Color_t fcolor);
200 virtual void SetFillColorAlpha(Int_t e, Color_t fcolor, Float_t falpha);
201 virtual void SetFillStyle(Int_t e, Style_t fstyle);
202
207
208 virtual void SetLineColor(Int_t e, Color_t lcolor);
209 virtual void SetLineColorAlpha(Int_t e, Color_t lcolor, Float_t lalpha);
210 virtual void SetLineStyle(Int_t e, Style_t lstyle);
211 virtual void SetLineWidth(Int_t e, Width_t lwidth);
212
213 ClassDefOverride(TGraphMultiErrors, 1) // A Graph with asymmetric error bars and multiple y error dimensions
214};
215
216#endif // ROOT_TGraphMultiErrors
#define f(i)
Definition RSha256.hxx:104
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Style_t
Definition RtypesCore.h:82
int Int_t
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:85
char Char_t
Definition RtypesCore.h:37
short Width_t
Definition RtypesCore.h:84
float Float_t
Definition RtypesCore.h:57
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
static unsigned int total
Option_t Option_t option
Option_t Option_t SetLineWidth
Option_t Option_t SetFillStyle
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t SetLineColor
Option_t Option_t SetFillColor
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
Array of doubles (64 bits per element).
Definition TArrayD.h:27
Array of floats (32 bits per element).
Definition TArrayF.h:27
Fill Area Attributes class.
Definition TAttFill.h:19
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:30
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:31
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetFillColorAlpha(Color_t fcolor, Float_t falpha)
Set a transparent fill color.
Definition TAttFill.cxx:265
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:39
Line Attributes class.
Definition TAttLine.h:18
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:33
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:42
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:35
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColorAlpha(Color_t lcolor, Float_t lalpha)
Set a transparent line color.
Definition TAttLine.cxx:305
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:34
1-Dim function class
Definition TF1.h:233
TGraph with asymmetric error bars and multiple y error dimensions.
Double_t * fEyLSum
! Array of summed Y low errors for fitting
Int_t GetSumErrorsMode() const
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:30
Double_t * GetEYhigh() const override
Get all high errors on y coordinates as an array summed according to fSumErrorsMode.
Double_t GetErrorX(Int_t i) const override
Get error on x coordinate for point i.
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:31
Double_t GetErrorXhigh(Int_t i) const override
Get high error on x coordinate for point i.
virtual void SetPointError(Double_t exL, Double_t exH, Double_t eyL1, Double_t eyH1, Double_t eyL2=0., Double_t eyH2=0., Double_t eyL3=0., Double_t eyH3=0.)
Set ex and ey values for point pointed by the mouse.
virtual TAttLine * GetAttLine(Int_t e)
Get AttLine pointer for specified error dimension.
virtual void SetFillColorAlpha(Int_t e, Color_t fcolor, Float_t falpha)
Set Fill Color and Alpha of error e (-1 = Global and x errors).
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:33
Double_t GetErrorYlow(Int_t i) const override
Get low error on y coordinate for point i.
void Divide(const TH1 *pass, const TH1 *total, Option_t *opt="cp")
This function was adapted from the TGraphAsymmErrors class.
std::vector< TAttLine > fAttLine
The AttLine attributes of the different errors.
virtual void AddYError(Int_t np, const Double_t *eyL=nullptr, const Double_t *eyH=nullptr)
Add a new y error to the graph and fill it with the values from eyL and eyH
Double_t GetErrorXlow(Int_t i) const override
Get low error on x coordinate for point i.
TGraphMultiErrors()
TGraphMultiErrors default constructor.
virtual void SetEY(Int_t e, Int_t np, const Double_t *eyL, const Double_t *eyH)
Set error e ey values.
virtual void SetSumErrorsMode(Int_t m)
Set the sum errors mode and recalculate summed errors.
virtual void BayesDivide(const TH1 *pass, const TH1 *total, Option_t *opt="")
This function is only kept for backward compatibility.
void Print(Option_t *chopt="") const override
Print graph and errors values.
TGraphMultiErrors & operator=(const TGraphMultiErrors &tgme)
TGraphMultiErrors assignment operator.
void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin) override
Copy and release.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Int_t fSumErrorsMode
How y errors are summed: kOnlyFirst = Only First; kSquareSum = Squared Sum; kSum = Absolute Addition.
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:35
Double_t * GetEXhigh() const override
@ kAbsSum
Calculate the absolute sum of all errors.
@ kSquareSum
Calculate the square sum of all errors.
@ kOnlyFirst
Only take errors from first dimension.
virtual TAttFill * GetAttFill(Int_t e)
Get AttFill pointer for specified error dimension.
virtual void SetLineStyle(Int_t e, Style_t lstyle)
Set Line Style of error e (-1 = Global and x errors).
Bool_t CopyPoints(Double_t **arrays, Int_t ibegin, Int_t iend, Int_t obegin) override
Copy errors from fE*** to arrays[***] or to f*** Copy points.
virtual void SetPointEXhigh(Int_t i, Double_t exH)
Set exH value for point i.
Double_t * fExL
[fNpoints] array of X low errors
void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE) override
Set zero values for point arrays in the range [begin, end].
std::vector< TArrayD > fEyH
Two dimensional array of Y high errors.
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:34
virtual void SetPointEX(Int_t i, Double_t exL, Double_t exH)
Set ex values for point i.
virtual void SetPointEYlow(Int_t i, Int_t ne, const Double_t *eyL)
Set eyL values for point i.
void Scale(Double_t c1=1., Option_t *option="y") override
Multiply the values and errors of a TGraphMultiErrors by a constant c1.
virtual void SetLineColorAlpha(Int_t e, Color_t lcolor, Float_t lalpha)
Set Line Color and Alpha of error e (-1 = Global and x errors).
Double_t * GetEXlow() const override
void CalcYErrorsSum() const
Recalculates the summed y error arrays.
~TGraphMultiErrors() override
TGraphMultiErrors default destructor.
virtual void SetAttLine(Int_t e, TAttLine *tal)
Set TAttLine parameters of error e by copying from another TAttLine (-1 = Global and x errors).
Double_t * fEyHSum
! Array of summed Y high errors for fitting
Double_t * GetEYlow() const override
Get all low errors on y coordinates as an array summed according to fSumErrorsMode.
virtual void DeleteYError(Int_t e)
Deletes the y error with the index e.
void Apply(TF1 *f) override
Apply a function to all data points .
virtual void SetEYhigh(Int_t e, Int_t np, const Double_t *eyH)
Set error e eyH values.
Int_t GetNYErrors() const
void SwapPoints(Int_t pos1, Int_t pos2) override
Swap points.
virtual void SetAttFill(Int_t e, TAttFill *taf)
Set TAttFill parameters of error e by copying from another TAttFill (-1 = Global and x errors).
virtual void SetEYlow(Int_t e, Int_t np, const Double_t *eyL)
Set error e eyL values.
std::vector< TAttFill > fAttFill
The AttFill attributes of the different errors.
void UpdateArrays(const std::vector< Int_t > &sorting_indices, Int_t numSortedPoints, Int_t low) override
Update the fX, fY, fExL, fExH, fEyL and fEyH arrays with the sorted values.
Bool_t CtorAllocate()
Should be called from ctors after fNpoints has been set Note: This function should be called only fro...
Double_t * fExH
[fNpoints] array of X high errors
virtual void SetPointEY(Int_t i, Int_t ne, const Double_t *eyL, const Double_t *eyH)
Set ey values for point i.
virtual void SetPointEXlow(Int_t i, Double_t exL)
Set exL value for point i.
virtual void SetPointEYhigh(Int_t i, Int_t ne, const Double_t *eyH)
Set eyH values for point i.
void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override
Compute Range.
Int_t fNYErrors
The amount of different y-errors.
std::vector< TArrayD > fEyL
Two dimensional array of Y low errors.
Double_t GetErrorY(Int_t i) const override
Get error on y coordinate for point i.
Double_t ** Allocate(Int_t size) override
Allocate internal data structures for size points.
Bool_t DoMerge(const TGraph *tg) override
Protected function to perform the merge operation of a graph with multiple asymmetric errors.
Double_t GetErrorYhigh(Int_t i) const override
Get high error on y coordinate for point i.
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
TVectorT.
Definition TVectorT.h:27
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
TMarker m
Definition textangle.C:8