Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
25 class TArrayF;
26 class TArrayD;
27 
28 class TGraphMultiErrors : public TGraph {
29 
30 protected:
31  Int_t fNYErrors; ///< The amount of different y-errors
32  Int_t fSumErrorsMode; ///< How y errors are summed: kOnlyFirst = Only First; kSquareSum = Squared Sum; kSum =
33  ///< Absolute Addition
34  Double_t *fExL; ///<[fNpoints] array of X low errors
35  Double_t *fExH; ///<[fNpoints] array of X high errors
36  std::vector<TArrayD> fEyL; ///< two dimensional array of Y low errors
37  std::vector<TArrayD> fEyH; ///< two dimensional array of Y high errors
38  mutable Double_t *fEyLSum = nullptr; ///<! array of summed Y low errors for fitting
39  mutable Double_t *fEyHSum = nullptr; ///<! array of summed Y high errors for fitting
40  std::vector<TAttFill> fAttFill; ///< the AttFill attributes of the different errors
41  std::vector<TAttLine> fAttLine; ///< the AttLine attributes of the different errors
42 
43  virtual Double_t **Allocate(Int_t size);
44  Bool_t CtorAllocate();
45 
46  virtual void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin);
47  virtual Bool_t CopyPoints(Double_t **arrays, Int_t ibegin, Int_t iend, Int_t obegin);
48  virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor = kTRUE);
49 
50  void CalcYErrorsSum() const;
51  virtual Bool_t DoMerge(const TGraph *tg);
52  virtual void SwapPoints(Int_t pos1, Int_t pos2);
53 
54 public:
55  enum ESummationModes {
56  kOnlyFirst = 0, ///< Only take errors from first dimension
57  kSquareSum = 1, ///< Calculate the square sum of all errors
58  kAbsSum = 2 ///< Calculate the absolute sum of all errors
59  };
60 
61  TGraphMultiErrors();
62  TGraphMultiErrors(const Char_t *name, const Char_t *title);
63  TGraphMultiErrors(Int_t np, Int_t ne = 1);
64  TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne = 1);
65 
66  TGraphMultiErrors(Int_t np, const Float_t *x, const Float_t *y, const Float_t *exL = nullptr,
67  const Float_t *exH = nullptr, const Float_t *eyL = nullptr, const Float_t *eyH = nullptr,
68  Int_t m = kOnlyFirst);
69  TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, const Float_t *x, const Float_t *y,
70  const Float_t *exL = nullptr, const Float_t *exH = nullptr, const Float_t *eyL = nullptr,
71  const Float_t *eyH = nullptr, Int_t m = kOnlyFirst);
72  TGraphMultiErrors(Int_t np, const Double_t *x, const Double_t *y, const Double_t *exL = nullptr,
73  const Double_t *exH = nullptr, const Double_t *eyL = nullptr, const Double_t *eyH = nullptr,
74  Int_t m = kOnlyFirst);
75  TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, const Double_t *x, const Double_t *y,
76  const Double_t *exL = nullptr, const Double_t *exH = nullptr, const Double_t *eyL = nullptr,
77  const Double_t *eyH = nullptr, Int_t m = kOnlyFirst);
78 
79  TGraphMultiErrors(Int_t np, Int_t ne, const Float_t *x, const Float_t *y, const Float_t *exL, const Float_t *exH,
80  std::vector<std::vector<Float_t>> eyL, std::vector<std::vector<Float_t>> eyH,
81  Int_t m = kOnlyFirst);
82  TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne, const Float_t *x, const Float_t *y,
83  const Float_t *exL, const Float_t *exH, std::vector<std::vector<Float_t>> eyL,
84  std::vector<std::vector<Float_t>> eyH, Int_t m = kOnlyFirst);
85  TGraphMultiErrors(Int_t np, Int_t ne, const Double_t *x, const Double_t *y, const Double_t *exL, const Double_t *exH,
86  std::vector<std::vector<Double_t>> eyL, std::vector<std::vector<Double_t>> eyH,
87  Int_t m = kOnlyFirst);
88  TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne, const Double_t *x, const Double_t *y,
89  const Double_t *exL, const Double_t *exH, std::vector<std::vector<Double_t>> eyL,
90  std::vector<std::vector<Double_t>> eyH, Int_t m = kOnlyFirst);
91 
92  TGraphMultiErrors(Int_t np, Int_t ne, const Float_t *x, const Float_t *y, const Float_t *exL, const Float_t *exH,
93  std::vector<TArrayF> eyL, std::vector<TArrayF> eyH, Int_t m = kOnlyFirst);
94  TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne, const Float_t *x, const Float_t *y,
95  const Float_t *exL, const Float_t *exH, std::vector<TArrayF> eyL, std::vector<TArrayF> eyH,
96  Int_t m = kOnlyFirst);
97  TGraphMultiErrors(Int_t np, Int_t ne, const Double_t *x, const Double_t *y, const Double_t *exL, const Double_t *exH,
98  std::vector<TArrayD> eyL, std::vector<TArrayD> eyH, Int_t m = kOnlyFirst);
99  TGraphMultiErrors(const Char_t *name, const Char_t *title, Int_t np, Int_t ne, const Double_t *x, const Double_t *y,
100  const Double_t *exL, const Double_t *exH, std::vector<TArrayD> eyL, std::vector<TArrayD> eyH,
101  Int_t m = kOnlyFirst);
102 
103  TGraphMultiErrors(const TVectorF &tvX, const TVectorF &tvY, const TVectorF &tvExL, const TVectorF &tvExH,
104  const TVectorF &tvEyL, const TVectorF &tvEyH, Int_t m = kOnlyFirst);
105  TGraphMultiErrors(const TVectorD &tvX, const TVectorD &tvY, const TVectorD &tvExL, const TVectorD &tvExH,
106  const TVectorD &tvEyL, const TVectorD &tvEyH, Int_t m = kOnlyFirst);
107 
108  TGraphMultiErrors(Int_t ne, const TVectorF &tvX, const TVectorF &tvY, const TVectorF &tvExL, const TVectorF &tvExH,
109  const TVectorF *tvEyL, const TVectorF *tvEyH, Int_t m = kOnlyFirst);
110  TGraphMultiErrors(Int_t ne, const TVectorD &tvX, const TVectorD &tvY, const TVectorD &tvExL, const TVectorD &tvExH,
111  const TVectorD *tvEyL, const TVectorD *tvEyH, Int_t m = kOnlyFirst);
112 
113  TGraphMultiErrors(const TGraphMultiErrors &tgme);
114  TGraphMultiErrors &operator=(const TGraphMultiErrors &tgme);
115 
116  TGraphMultiErrors(const TH1 *th, Int_t ne = 1);
117  TGraphMultiErrors(const TH1 *pass, const TH1 *total, Int_t ne = 1, Option_t *option = "");
118 
119  virtual ~TGraphMultiErrors();
120 
121  virtual void AddYError(Int_t np, const Double_t *eyL = nullptr, const Double_t *eyH = nullptr);
122  virtual void Apply(TF1 *f);
123  virtual void BayesDivide(const TH1 *pass, const TH1 *total, Option_t *opt = "");
124  void Divide(const TH1 *pass, const TH1 *total, Option_t *opt = "cp");
125  virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const;
126  virtual void DeleteYError(Int_t e);
127 
128  virtual Double_t GetErrorX(Int_t i) const;
129  virtual Double_t GetErrorY(Int_t i) const;
130  virtual Double_t GetErrorY(Int_t i, Int_t e) const;
131 
132  virtual Double_t GetErrorXlow(Int_t i) const;
133  virtual Double_t GetErrorXhigh(Int_t i) const;
134  virtual Double_t GetErrorYlow(Int_t i) const;
135  virtual Double_t GetErrorYhigh(Int_t i) const;
136  virtual Double_t GetErrorYlow(Int_t i, Int_t e) const;
137  virtual Double_t GetErrorYhigh(Int_t i, Int_t e) const;
138 
139  virtual Double_t *GetEXlow() const { return fExL; }
140  virtual Double_t *GetEXhigh() const { return fExH; }
141  virtual Double_t *GetEYlow() const;
142  virtual Double_t *GetEYhigh() const;
143  virtual Double_t *GetEYlow(Int_t e);
144  virtual Double_t *GetEYhigh(Int_t e);
145 
146  virtual TAttFill *GetAttFill(Int_t e);
147  virtual TAttLine *GetAttLine(Int_t e);
148 
149  using TAttFill::GetFillColor;
150  using TAttFill::GetFillStyle;
151 
152  virtual Color_t GetFillColor(Int_t e) const;
153  virtual Style_t GetFillStyle(Int_t e) const;
154 
155  using TAttLine::GetLineColor;
156  using TAttLine::GetLineStyle;
157  using TAttLine::GetLineWidth;
158 
159  virtual Color_t GetLineColor(Int_t e) const;
160  virtual Style_t GetLineStyle(Int_t e) const;
161  virtual Width_t GetLineWidth(Int_t e) const;
162 
163  Int_t GetSumErrorsMode() const { return fSumErrorsMode; }
164  Int_t GetNYErrors() const { return fNYErrors; }
165 
166  virtual void Print(Option_t *chopt = "") const;
167  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
168 
169  virtual void SetPointError(Double_t exL, Double_t exH, Double_t eyL1, Double_t eyH1, Double_t eyL2 = 0.,
170  Double_t eyH2 = 0., Double_t eyL3 = 0., Double_t eyH3 = 0.); // *MENU*
171  virtual void SetPointError(Int_t i, Int_t ne, Double_t exL, Double_t exH, const Double_t *eyL, const Double_t *eyH);
172 
173  virtual void SetPointEX(Int_t i, Double_t exL, Double_t exH);
174  virtual void SetPointEXlow(Int_t i, Double_t exL);
175  virtual void SetPointEXhigh(Int_t i, Double_t exH);
176  virtual void SetPointEY(Int_t i, Int_t ne, const Double_t *eyL, const Double_t *eyH);
177  virtual void SetPointEYlow(Int_t i, Int_t ne, const Double_t *eyL);
178  virtual void SetPointEYhigh(Int_t i, Int_t ne, const Double_t *eyH);
179  virtual void SetPointEY(Int_t i, Int_t e, Double_t eyL, Double_t eyH);
180  virtual void SetPointEYlow(Int_t i, Int_t e, Double_t eyL);
181  virtual void SetPointEYhigh(Int_t i, Int_t e, Double_t eyH);
182 
183  virtual void SetEY(Int_t e, Int_t np, const Double_t *eyL, const Double_t *eyH);
184  virtual void SetEYlow(Int_t e, Int_t np, const Double_t *eyL);
185  virtual void SetEYhigh(Int_t e, Int_t np, const Double_t *eyH);
186 
187  virtual void SetSumErrorsMode(Int_t m);
188 
189  virtual void SetAttFill(Int_t e, TAttFill *taf);
190  virtual void SetAttLine(Int_t e, TAttLine *tal);
191 
192  using TAttFill::SetFillColor;
193  using TAttFill::SetFillColorAlpha;
194  using TAttFill::SetFillStyle;
195 
196  virtual void SetFillColor(Int_t e, Color_t fcolor);
197  virtual void SetFillColorAlpha(Int_t e, Color_t fcolor, Float_t falpha);
198  virtual void SetFillStyle(Int_t e, Style_t fstyle);
199 
200  using TAttLine::SetLineColor;
201  using TAttLine::SetLineColorAlpha;
202  using TAttLine::SetLineStyle;
203  using TAttLine::SetLineWidth;
204 
205  virtual void SetLineColor(Int_t e, Color_t lcolor);
206  virtual void SetLineColorAlpha(Int_t e, Color_t lcolor, Float_t lalpha);
207  virtual void SetLineStyle(Int_t e, Style_t lstyle);
208  virtual void SetLineWidth(Int_t e, Width_t lwidth);
209 
210  ClassDef(TGraphMultiErrors, 1) // A Graph with asymmetric error bars and multiple y error dimensions
211 };
212 
213 #endif // ROOT_TGraphMultiErrors