Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TCandle.h
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Georg Troska 2016/04/14
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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_TCandle
13 #define ROOT_TCandle
14 
15 #include "TObject.h"
16 #include "TAttLine.h"
17 #include "TAttFill.h"
18 #include "TAttMarker.h"
19 
20 #include "TH1D.h"
21 #include "TMath.h"
22 
23 const Int_t kNMAXPOINTS = 2010; // Max outliers per candle
24 
25 class TCandle : public TAttLine, public TAttFill, public TAttMarker {
26 public:
27  //Candle Option
28  enum CandleOption: long {
29  kNoOption = 0,
30  kBox = 1,
31  kMedianLine = 10,
32  kMedianNotched = 20,
33  kMedianCircle = 30,
34  kMeanLine = 100,
35  kMeanCircle = 300,
36  kWhiskerAll = 1000,
37  kWhisker15 = 2000,
38  kAnchor = 10000,
39  kPointsOutliers = 100000,
40  kPointsAll = 200000,
41  kPointsAllScat = 300000,
42  kHistoLeft = 1000000,
43  kHistoRight = 2000000,
44  kHistoViolin = 3000000,
45  kHistoZeroIndicator = 10000000,
46  kHorizontal = 100000000 ///< If this bit is not set it is vertical
47  };
48 
49 
50 protected:
51 
52  bool fIsRaw; ///< 0: for TH1 projection, 1: using raw data
53  bool fIsCalculated;
54  TH1D * fProj;
55  bool fDismiss; ///< True if the candle cannot be painted
56 
57  Double_t fPosCandleAxis; ///< x-pos for a vertical candle
58  Double_t fCandleWidth; ///< The candle width
59  Double_t fHistoWidth; ///< The histo width (the height of the max bin)
60 
61  Double_t fMean; ///< Position of the mean
62  Double_t fMedian; ///< Position of the median
63  Double_t fMedianErr; ///< The size of the notch
64  Double_t fBoxUp; ///< Position of the upper box end
65  Double_t fBoxDown; ///< Position of the lower box end
66  Double_t fWhiskerUp; ///< Position of the upper whisker end
67  Double_t fWhiskerDown; ///< Position of the lower whisker end
68 
69  Double_t * fDatapoints; ///< position of all Datapoints within this candle
70  Long64_t fNDatapoints; ///< Number of Datapoints within this candle
71 
72  Double_t fDrawPointsX[kNMAXPOINTS]; ///< x-coord for every outlier, ..
73  Double_t fDrawPointsY[kNMAXPOINTS]; ///< y-coord for every outlier, ..
74  Long64_t fNDrawPoints; ///< max number of outliers or other point to be shown
75 
76  Double_t fHistoPointsX[kNMAXPOINTS]; ///< x-coord for the polyline of the histo
77  Double_t fHistoPointsY[kNMAXPOINTS]; ///< y-coord for the polyline of the histo
78  int fNHistoPoints;
79 
80  CandleOption fOption; ///< Setting the style of the candle
81  char fOptionStr[128]; ///< String to draw the candle
82  int fLogX; ///< make the candle appear logx-like
83  int fLogY; ///< make the candle appear logy-like
84  int fLogZ; ///< make the candle appear logz-like
85 
86  Double_t fAxisMin; ///< The Minimum which is visible by the axis (used by zero indicator)
87  Double_t fAxisMax; ///< The Maximum which is visible by the axis (used by zero indicator)
88 
89  static Double_t fWhiskerRange; ///< The fraction which is covered by the whiskers (0 < x < 1), default 1
90  static Double_t fBoxRange; ///< The fraction which is covered by the box (0 < x < 1), default 0.5
91 
92  static Bool_t fScaledCandle; ///< shall the box-width be scaled to each other by the integral of a box?
93  static Bool_t fScaledViolin; ///< shall the violin or histos be scaled to each other by the maximum height?
94 
95  void Calculate();
96 
97  int GetCandleOption(const int pos) {return (fOption/(long)TMath::Power(10,pos))%10;}
98 
99  void PaintBox(Int_t nPoints, Double_t *x, Double_t *y, Bool_t swapXY);
100  void PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Bool_t swapXY);
101 
102 public:
103 
104  TCandle();
105  TCandle(const char *opt);
106  TCandle(const Double_t candlePos, const Double_t candleWidth, Long64_t n, Double_t * points);
107  TCandle(const Double_t candlePos, const Double_t candleWidth, TH1D *proj);
108  TCandle(const TCandle &candle);
109  virtual ~TCandle();
110 
111  Double_t GetMean() const {return fMean;}
112  Double_t GetMedian() const {return fMedian;}
113  Double_t GetQ1() const {return fBoxUp;}
114  Double_t GetQ2() const {return fMedian;}
115  Double_t GetQ3() const {return fBoxDown;}
116  Bool_t IsHorizontal() {return (IsOption(kHorizontal)); }
117  Bool_t IsVertical() {return (!IsOption(kHorizontal)); }
118  Bool_t IsCandleScaled();
119  Bool_t IsViolinScaled();
120 
121  void SetOption(CandleOption opt) { fOption = opt; }
122  void SetLog(int x, int y, int z) { fLogX = x; fLogY = y; fLogZ = z;}
123  void SetAxisPosition(const Double_t candlePos) { fPosCandleAxis = candlePos; }
124 
125  void SetCandleWidth(const Double_t width) { fCandleWidth = width; }
126  void SetHistoWidth(const Double_t width) { fHistoWidth = width; }
127  void SetHistogram(TH1D *proj) { fProj = proj; fIsCalculated = false;}
128 
129  virtual void Paint(Option_t *option="");
130  void ConvertToPadCoords(Double_t minAxis, Double_t maxAxis, Double_t axisMinCoord, Double_t axisMaxCoord);
131 
132  virtual void SetMean(Double_t mean) { fMean = mean; }
133  virtual void SetMedian(Double_t median) { fMedian = median; }
134  virtual void SetQ1(Double_t q1) { fBoxUp = q1; }
135  virtual void SetQ2(Double_t q2) { fMedian = q2; }
136  virtual void SetQ3(Double_t q3) { fBoxDown = q3; }
137 
138  int ParseOption(char *optin);
139  const char * GetDrawOption() { return fOptionStr; }
140  long GetOption() { return fOption; }
141  bool IsOption(CandleOption opt);
142  static void SetWhiskerRange(const Double_t wRange);
143  static void SetBoxRange(const Double_t bRange);
144  static void SetScaledCandle(const Bool_t cScale = true);
145  static void SetScaledViolin(const Bool_t vScale = true);
146 
147  ClassDef(TCandle,2) //A Candle
148 };
149 #endif