Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-24 09:25:00

0001 // @(#)root/graf:$Id$
0002 // Author: Georg Troska 2016/04/14
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TCandle
0013 #define ROOT_TCandle
0014 
0015 #include "TObject.h"
0016 #include "TAttLine.h"
0017 #include "TAttFill.h"
0018 #include "TAttMarker.h"
0019 #include "TString.h"
0020 
0021 #include "TMath.h"
0022 
0023 class TH1D;
0024 
0025 const Int_t kNMAXPOINTS = 2010;  // Max outliers per candle
0026 
0027 class TCandle : public TAttLine, public TAttFill, public TAttMarker {
0028 public:
0029    //Candle Option
0030    enum CandleOption: long {
0031       kNoOption           = 0,
0032 // clang++ <v20 (-Wshadow) complains about shadowing Buttons.h global enum EEditMode. Let's silence warning:
0033 #if defined(__clang__) && __clang_major__ < 20
0034 #pragma clang diagnostic push
0035 #pragma clang diagnostic ignored "-Wshadow"
0036 #endif
0037       kBox                = 1,
0038 #if defined(__clang__) && __clang_major__ < 20
0039 #pragma clang diagnostic pop
0040 #endif
0041       kMedianLine         = 10,
0042       kMedianNotched      = 20,
0043       kMedianCircle       = 30,
0044       kMeanLine           = 100,
0045       kMeanCircle         = 300,
0046       kWhiskerAll         = 1000,
0047       kWhisker15          = 2000,
0048       kAnchor             = 10000,
0049       kPointsOutliers     = 100000,
0050       kPointsAll          = 200000,
0051       kPointsAllScat      = 300000,
0052       kHistoLeft          = 1000000,
0053       kHistoRight         = 2000000,
0054       kHistoViolin        = 3000000,
0055       kHistoZeroIndicator = 10000000,
0056       kHorizontal         = 100000000     ///< If this bit is not set it is vertical
0057    };
0058 
0059 
0060 protected:
0061 
0062    bool fIsRaw;                           ///< 0: for TH1 projection, 1: using raw data
0063    bool fIsCalculated;
0064    TH1D *fProj{nullptr};
0065    bool fDismiss;                         ///< True if the candle cannot be painted
0066 
0067    Double_t fPosCandleAxis;               ///< x-pos for a vertical candle
0068    Double_t fCandleWidth;                 ///< The candle width
0069    Double_t fHistoWidth;                  ///< The histo width (the height of the max bin)
0070 
0071    Double_t fMean;                        ///< Position of the mean
0072    Double_t fMedian;                      ///< Position of the median
0073    Double_t fMedianErr;                   ///< The size of the notch
0074    Double_t fBoxUp;                       ///< Position of the upper box end
0075    Double_t fBoxDown;                     ///< Position of the lower box end
0076    Double_t fWhiskerUp;                   ///< Position of the upper whisker end
0077    Double_t fWhiskerDown;                 ///< Position of the lower whisker end
0078 
0079    Double_t *fDatapoints{nullptr};        ///< position of all Datapoints within this candle
0080    Long64_t fNDatapoints;                 ///< Number of Datapoints within this candle
0081 
0082    Double_t fDrawPointsX[kNMAXPOINTS];    ///< x-coord for every outlier, ..
0083    Double_t fDrawPointsY[kNMAXPOINTS];    ///< y-coord for every outlier, ..
0084    Long64_t fNDrawPoints;                 ///< max number of outliers or other point to be shown
0085 
0086    Double_t fHistoPointsX[kNMAXPOINTS];   ///< x-coord for the polyline of the histo
0087    Double_t fHistoPointsY[kNMAXPOINTS];   ///< y-coord for the polyline of the histo
0088    int  fNHistoPoints;
0089 
0090    CandleOption fOption;                  ///< Setting the style of the candle
0091    TString fOptionStr;                    ///< String to draw the candle
0092    int fLogX;                             ///< make the candle appear logx-like
0093    int fLogY;                             ///< make the candle appear logy-like
0094    int fLogZ;                             ///< make the candle appear logz-like
0095 
0096    Double_t fAxisMin;                     ///< The Minimum which is visible by the axis (used by zero indicator)
0097    Double_t fAxisMax;                     ///< The Maximum which is visible by the axis (used by zero indicator)
0098 
0099    void Calculate();
0100 
0101    int  GetCandleOption(const int pos) const {return (fOption/(long)TMath::Power(10,pos))%10;}
0102 
0103    void PaintBox(Int_t nPoints, Double_t *x, Double_t *y, Bool_t swapXY);
0104    void PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Bool_t swapXY);
0105 
0106 public:
0107 
0108    TCandle();
0109    TCandle(const char *opt);
0110    TCandle(const Double_t candlePos, const Double_t candleWidth, Long64_t n, Double_t * points);
0111    TCandle(const Double_t candlePos, const Double_t candleWidth, TH1D *proj);
0112    TCandle(const TCandle &candle);
0113    ~TCandle() override;
0114 
0115    Double_t       GetMean() const {return fMean;}
0116    Double_t       GetMedian() const {return fMedian;}
0117    Double_t       GetQ1() const {return fBoxUp;}
0118    Double_t       GetQ2() const {return fMedian;}
0119    Double_t       GetQ3() const {return fBoxDown;}
0120    Bool_t         IsHorizontal() const {return IsOption(kHorizontal); }
0121    Bool_t         IsVertical() const {return !IsOption(kHorizontal); }
0122    Bool_t         IsCandleScaled() const;
0123    Bool_t         IsViolinScaled() const;
0124 
0125    void           SetOption(CandleOption opt) { fOption = opt; }
0126    void           SetLog(int x, int y, int z) { fLogX = x; fLogY = y; fLogZ = z;}
0127    void           SetAxisPosition(const Double_t candlePos) { fPosCandleAxis = candlePos; }
0128 
0129    void           SetCandleWidth(const Double_t width) { fCandleWidth = width; }
0130    void           SetHistoWidth(const Double_t width) { fHistoWidth = width; }
0131    void           SetHistogram(TH1D *proj) { fProj = proj; fIsCalculated = false;}
0132 
0133    virtual void   Paint(Option_t *option="");
0134    void           ConvertToPadCoords(Double_t minAxis, Double_t maxAxis, Double_t axisMinCoord, Double_t axisMaxCoord);
0135 
0136    virtual void   SetMean(Double_t mean) { fMean = mean; }
0137    virtual void   SetMedian(Double_t median) { fMedian = median; }
0138    virtual void   SetQ1(Double_t q1) { fBoxUp = q1; }
0139    virtual void   SetQ2(Double_t q2) { fMedian = q2; }
0140    virtual void   SetQ3(Double_t q3) { fBoxDown = q3; }
0141 
0142    int            ParseOption(char *optin);
0143    const char    *GetDrawOption() const { return fOptionStr.Data(); }
0144    long           GetOption() const { return fOption; }
0145    bool           IsOption(CandleOption opt) const;
0146    static void    SetWhiskerRange(const Double_t wRange);
0147    static void    SetBoxRange(const Double_t bRange);
0148    static void    SetScaledCandle(const Bool_t cScale = true);
0149    static void    SetScaledViolin(const Bool_t vScale = true);
0150 
0151    ClassDefOverride(TCandle,2)  //A Candle
0152 };
0153 #endif