// @(#)root/roostats:$Id$
// Authors: Sven Kreiss    June 2010
// Authors: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOSTATS_SamplingDistPlot
#define ROOSTATS_SamplingDistPlot

#include "RooList.h"
#include "RooPrintable.h"
#include "TNamed.h"
#include "TIterator.h"
#include "TH1F.h"
#include "TF1.h"
#include "TLegend.h"

#ifndef ROOSTATS_SamplingDistribution
#include "RooStats/SamplingDistribution.h"
#endif

#ifndef ROO_PLOT
#include "RooPlot.h"
#endif


namespace RooStats {

 class SamplingDistPlot : public TNamed, public RooPrintable {

   public:
    // Constructors for SamplingDistribution
    SamplingDistPlot(Int_t nbins = 100);
    SamplingDistPlot(Int_t nbins, Double_t min, Double_t max);
//    SamplingDistPlot(const char* name, const char* title, Int_t nbins, Double_t xmin, Double_t xmax);

    // Destructor of SamplingDistribution
    virtual ~SamplingDistPlot();

    // adds the sampling distribution and returns the scale factor
    Double_t AddSamplingDistribution(const SamplingDistribution *samplingDist, Option_t *drawOptions="NORMALIZE HIST");
    // Like AddSamplingDistribution, but also sets a shaded area in the
    // minShaded and maxShaded boundaries.
    Double_t AddSamplingDistributionShaded(const SamplingDistribution *samplingDist, Double_t minShaded, Double_t maxShaded, Option_t *drawOptions="NORMALIZE HIST");

    // add a line
    void AddLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2, const char* title = NULL);
    // add a TH1
    void AddTH1(TH1* h, Option_t *drawOptions="");
    // add a TF1
    void AddTF1(TF1* f, const char* title = NULL, Option_t *drawOptions="SAME");
    // set legend
    void SetLegend(TLegend* l){ fLegend = l; }
    
    void Draw(Option_t *options=0);

    // Applies a predefined style if fApplyStyle is kTRUE (default).
    void ApplyDefaultStyle(void);

    void SetLineColor(Color_t color, const SamplingDistribution *samplDist = 0);
    void SetLineWidth(Width_t lwidth, const SamplingDistribution *samplDist = 0);
    void SetLineStyle(Style_t style, const SamplingDistribution *samplDist = 0);

    void SetMarkerColor(Color_t color, const SamplingDistribution *samplDist = 0);
    void SetMarkerStyle(Style_t style, const SamplingDistribution *samplDist = 0);
    void SetMarkerSize(Size_t size, const SamplingDistribution *samplDist = 0);

    void RebinDistribution(Int_t rebinFactor, const SamplingDistribution *samplDist = 0);

    void SetAxisTitle(char *varName) { fVarName = TString(varName); }

    // If you do not want SamplingDistPlot to interfere with your style settings, call this
    // function with "false" before Draw().
    void SetApplyStyle(Bool_t s) { fApplyStyle = s; }

    // Returns the TH1F associated with the give SamplingDistribution.
    // Intended use: Access to member functions of TH1F like GetMean(),
    // GetRMS() etc.
    // The return objects is managed by  SamplingDistPlot
    TH1F* GetTH1F(const SamplingDistribution *samplDist = NULL);
    TH1 * GetHistogram(const SamplingDistribution *samplDist = NULL) { return GetTH1F(samplDist); }

    // return plotter class used to draw the sampling distribution histograms
    // object is managed by SamplingDistPlot
    RooPlot * GetPlot() { return fRooPlot; }

    // changes plot to log scale on x axis
    void SetLogXaxis(Bool_t lx) { fLogXaxis = lx; }
    // changes plot to log scale on y axis
    void SetLogYaxis(Bool_t ly) { fLogYaxis = ly; }

    // change x range
    void SetXRange( double mi, double ma ) { fXMin = mi; fXMax = ma; }
    // change y range
    void SetYRange( double mi, double ma ) { fYMin = mi; fYMax = ma; }

    // write to Root file
    void DumpToFile(const char* RootFileName, Option_t *option="", const char *ftitle="", Int_t compress=1);

  private:
    std::vector<Double_t> fSamplingDistr;
    std::vector<Double_t> fSampleWeights;

    Bool_t fIsWeighted;

    Int_t fBins;
    Int_t fMarkerType;
    Int_t fColor;

    TString fVarName;

  protected:

    TH1F* fHist;
    TLegend *fLegend;

    RooList fItems; // holds TH1Fs only
    RooList fOtherItems; // other objects to be drawn like TLine etc.
    TIterator* fIterator; // TODO remove class variable and instantiate locally as necessary
    RooPlot* fRooPlot;
    Bool_t fLogXaxis;
    Bool_t fLogYaxis;

    double fXMin, fXMax, fYMin, fYMax;

    Bool_t fApplyStyle;
    Style_t fFillStyle;

    void SetSampleWeights(const SamplingDistribution *samplingDist);

    void addObject(TObject *obj, Option_t *drawOptions=0); // for TH1Fs only
    void addOtherObject(TObject *obj, Option_t *drawOptions=0);
    void GetAbsoluteInterval(Double_t &theMin, Double_t &theMax, Double_t &theYMax) const;

    ClassDef(SamplingDistPlot,1)  // Class containing the results of the HybridCalculator
  };
}

#endif
 SamplingDistPlot.h:1
 SamplingDistPlot.h:2
 SamplingDistPlot.h:3
 SamplingDistPlot.h:4
 SamplingDistPlot.h:5
 SamplingDistPlot.h:6
 SamplingDistPlot.h:7
 SamplingDistPlot.h:8
 SamplingDistPlot.h:9
 SamplingDistPlot.h:10
 SamplingDistPlot.h:11
 SamplingDistPlot.h:12
 SamplingDistPlot.h:13
 SamplingDistPlot.h:14
 SamplingDistPlot.h:15
 SamplingDistPlot.h:16
 SamplingDistPlot.h:17
 SamplingDistPlot.h:18
 SamplingDistPlot.h:19
 SamplingDistPlot.h:20
 SamplingDistPlot.h:21
 SamplingDistPlot.h:22
 SamplingDistPlot.h:23
 SamplingDistPlot.h:24
 SamplingDistPlot.h:25
 SamplingDistPlot.h:26
 SamplingDistPlot.h:27
 SamplingDistPlot.h:28
 SamplingDistPlot.h:29
 SamplingDistPlot.h:30
 SamplingDistPlot.h:31
 SamplingDistPlot.h:32
 SamplingDistPlot.h:33
 SamplingDistPlot.h:34
 SamplingDistPlot.h:35
 SamplingDistPlot.h:36
 SamplingDistPlot.h:37
 SamplingDistPlot.h:38
 SamplingDistPlot.h:39
 SamplingDistPlot.h:40
 SamplingDistPlot.h:41
 SamplingDistPlot.h:42
 SamplingDistPlot.h:43
 SamplingDistPlot.h:44
 SamplingDistPlot.h:45
 SamplingDistPlot.h:46
 SamplingDistPlot.h:47
 SamplingDistPlot.h:48
 SamplingDistPlot.h:49
 SamplingDistPlot.h:50
 SamplingDistPlot.h:51
 SamplingDistPlot.h:52
 SamplingDistPlot.h:53
 SamplingDistPlot.h:54
 SamplingDistPlot.h:55
 SamplingDistPlot.h:56
 SamplingDistPlot.h:57
 SamplingDistPlot.h:58
 SamplingDistPlot.h:59
 SamplingDistPlot.h:60
 SamplingDistPlot.h:61
 SamplingDistPlot.h:62
 SamplingDistPlot.h:63
 SamplingDistPlot.h:64
 SamplingDistPlot.h:65
 SamplingDistPlot.h:66
 SamplingDistPlot.h:67
 SamplingDistPlot.h:68
 SamplingDistPlot.h:69
 SamplingDistPlot.h:70
 SamplingDistPlot.h:71
 SamplingDistPlot.h:72
 SamplingDistPlot.h:73
 SamplingDistPlot.h:74
 SamplingDistPlot.h:75
 SamplingDistPlot.h:76
 SamplingDistPlot.h:77
 SamplingDistPlot.h:78
 SamplingDistPlot.h:79
 SamplingDistPlot.h:80
 SamplingDistPlot.h:81
 SamplingDistPlot.h:82
 SamplingDistPlot.h:83
 SamplingDistPlot.h:84
 SamplingDistPlot.h:85
 SamplingDistPlot.h:86
 SamplingDistPlot.h:87
 SamplingDistPlot.h:88
 SamplingDistPlot.h:89
 SamplingDistPlot.h:90
 SamplingDistPlot.h:91
 SamplingDistPlot.h:92
 SamplingDistPlot.h:93
 SamplingDistPlot.h:94
 SamplingDistPlot.h:95
 SamplingDistPlot.h:96
 SamplingDistPlot.h:97
 SamplingDistPlot.h:98
 SamplingDistPlot.h:99
 SamplingDistPlot.h:100
 SamplingDistPlot.h:101
 SamplingDistPlot.h:102
 SamplingDistPlot.h:103
 SamplingDistPlot.h:104
 SamplingDistPlot.h:105
 SamplingDistPlot.h:106
 SamplingDistPlot.h:107
 SamplingDistPlot.h:108
 SamplingDistPlot.h:109
 SamplingDistPlot.h:110
 SamplingDistPlot.h:111
 SamplingDistPlot.h:112
 SamplingDistPlot.h:113
 SamplingDistPlot.h:114
 SamplingDistPlot.h:115
 SamplingDistPlot.h:116
 SamplingDistPlot.h:117
 SamplingDistPlot.h:118
 SamplingDistPlot.h:119
 SamplingDistPlot.h:120
 SamplingDistPlot.h:121
 SamplingDistPlot.h:122
 SamplingDistPlot.h:123
 SamplingDistPlot.h:124
 SamplingDistPlot.h:125
 SamplingDistPlot.h:126
 SamplingDistPlot.h:127
 SamplingDistPlot.h:128
 SamplingDistPlot.h:129
 SamplingDistPlot.h:130
 SamplingDistPlot.h:131
 SamplingDistPlot.h:132
 SamplingDistPlot.h:133
 SamplingDistPlot.h:134
 SamplingDistPlot.h:135
 SamplingDistPlot.h:136
 SamplingDistPlot.h:137
 SamplingDistPlot.h:138
 SamplingDistPlot.h:139
 SamplingDistPlot.h:140
 SamplingDistPlot.h:141
 SamplingDistPlot.h:142
 SamplingDistPlot.h:143
 SamplingDistPlot.h:144