/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooPlot.h,v 1.37 2007/06/18 11:52:41 wouter Exp $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_PLOT
#define ROO_PLOT

#include <float.h>
#include "RooList.h"
#include "RooPrintable.h"
#include "TNamed.h"

class TH1 ;

class RooAbsReal;
class RooAbsRealLValue;
class RooArgSet ;
class RooHist;
class RooCurve ;
class RooPlotable;
class TDirectory ;
class TAttLine;
class TAttFill;
class TAttMarker;
class TAttText;
class TClass ;
class TAxis;
class TBrowser ;

class RooPlot : public TNamed, public RooPrintable {
public:
  RooPlot() ;
  RooPlot(const char* name, const char* title, const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins) ;
  RooPlot(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins);
  RooPlot(Double_t xmin, Double_t xmax);
  RooPlot(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax);
  RooPlot(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2);
  RooPlot(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2,
	  Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax);
  virtual ~RooPlot();

  RooPlot* emptyClone(const char* name) ;

  // implement the TH1 interface
  virtual Stat_t GetBinContent(Int_t) const;
  virtual Stat_t GetBinContent(Int_t, Int_t) const;
  virtual Stat_t GetBinContent(Int_t, Int_t, Int_t) const;
  virtual void Draw(Option_t *options= 0);

  // forwarding of relevant TH1 interface
  TAxis* GetXaxis() const ;
  TAxis* GetYaxis() const ;
  Int_t GetNbinsX() const ;
  Int_t GetNdivisions(Option_t* axis = "X") const ;
  Double_t GetMinimum(Double_t minval = -FLT_MAX) const ;
  Double_t GetMaximum(Double_t maxval = FLT_MAX) const ;

  void SetAxisColor(Color_t color = 1, Option_t* axis = "X") ;
  void SetAxisRange(Double_t xmin, Double_t xmax, Option_t* axis = "X") ;
  void SetBarOffset(Float_t offset = 0.25) ;
  void SetBarWidth(Float_t width = 0.5) ;
  void SetContour(Int_t nlevels, const Double_t* levels = 0) ; 
  void SetContourLevel(Int_t level, Double_t value) ; 
  void SetDrawOption(Option_t* option = "") ; 
  void SetFillAttributes() ; 
  void SetFillColor(Color_t fcolor) ; 
  void SetFillStyle(Style_t fstyle) ; 
  void SetLabelColor(Color_t color = 1, Option_t* axis = "X") ; 
  void SetLabelFont(Style_t font = 62, Option_t* axis = "X") ; 
  void SetLabelOffset(Float_t offset = 0.005, Option_t* axis = "X") ; 
  void SetLabelSize(Float_t size = 0.02, Option_t* axis = "X") ; 
  void SetLineAttributes() ; 
  void SetLineColor(Color_t lcolor) ; 
  void SetLineStyle(Style_t lstyle) ; 
  void SetLineWidth(Width_t lwidth) ; 
  void SetMarkerAttributes() ; 
  void SetMarkerColor(Color_t tcolor = 1) ; 
  void SetMarkerSize(Size_t msize = 1) ; 
  void SetMarkerStyle(Style_t mstyle = 1) ; 
  void SetName(const char *name) ;
  void SetTitle(const char *name) ;
  void SetNameTitle(const char *name, const char* title) ;
  void SetNdivisions(Int_t n = 510, Option_t* axis = "X") ; 
  void SetOption(Option_t* option = " ") ; 
  void SetStats(Bool_t stats = kTRUE) ; 
  void SetTickLength(Float_t length = 0.02, Option_t* axis = "X") ; 
  void SetTitleFont(Style_t font = 62, Option_t* axis = "X") ; 
  void SetTitleOffset(Float_t offset = 1, Option_t* axis = "X") ; 
  void SetTitleSize(Float_t size = 0.02, Option_t* axis = "X") ; 
  void SetXTitle(const char* title) ; 
  void SetYTitle(const char* title) ; 
  void SetZTitle(const char* title) ; 

  // container management
  const char* nameOf(Int_t idx) const ;
  TObject *findObject(const char *name, const TClass* clas=0) const;
  TObject* getObject(Int_t idx) const ;
  Stat_t numItems() const {return _items.GetSize();}

  void addPlotable(RooPlotable *plotable, Option_t *drawOptions= "", Bool_t invisible=kFALSE, Bool_t refreshNorm=kFALSE);
  void addObject(TObject* obj, Option_t* drawOptions= "", Bool_t invisible=kFALSE);
  void addTH1(TH1 *hist, Option_t* drawOptions= "", Bool_t invisible=kFALSE);

  void remove(const char* name=0, Bool_t deleteToo=kTRUE) ;

  // ascii printing
  virtual void printName(std::ostream& os) const ;
  virtual void printTitle(std::ostream& os) const ;
  virtual void printClassName(std::ostream& os) const ;
  virtual void printArgs(std::ostream& os) const ;
  virtual void printValue(std::ostream& os) const ;
  virtual void printMultiline(std::ostream& os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const ;

  virtual Int_t defaultPrintContents(Option_t* opt) const ;

  inline virtual void Print(Option_t *options= 0) const {
    printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
  }

  // data member get/set methods
  inline RooAbsRealLValue *getPlotVar() const { return _plotVarClone; }
  inline Double_t getFitRangeNEvt() const { return _normNumEvts; }
  Double_t getFitRangeNEvt(Double_t xlo, Double_t xhi) const ;
  inline Double_t getFitRangeBinW() const { return _normBinWidth; }
  inline Double_t getPadFactor() const { return _padFactor; }
  inline void setPadFactor(Double_t factor) { if(factor >= 0) _padFactor= factor; }
  void updateNormVars(const RooArgSet &vars);
  const RooArgSet *getNormVars() const { return _normVars; }

  // get attributes of contained objects
  TAttLine *getAttLine(const char *name=0) const;
  TAttFill *getAttFill(const char *name=0) const;
  TAttMarker *getAttMarker(const char *name=0) const;
  TAttText *getAttText(const char *name=0) const;

  // Convenient type-safe accessors
  RooCurve* getCurve(const char* name=0) const ;
  RooHist* getHist(const char* name=0) const ;


  // rearrange drawing order of contained objects
  Bool_t drawBefore(const char *before, const char *target);
  Bool_t drawAfter(const char *after, const char *target);

  // get/set drawing options for contained objects
  TString getDrawOptions(const char *name) const;
  Bool_t setDrawOptions(const char *name, TString options);

  Bool_t getInvisible(const char* name) const ;
  void setInvisible(const char* name, Bool_t flag=kTRUE) ; 
 
  virtual void SetMaximum(Double_t maximum = -1111) ;
  virtual void SetMinimum(Double_t minimum = -1111) ;

  Double_t chiSquare(int nFitParam=0) const { return chiSquare(0,0,nFitParam) ; } 
  Double_t chiSquare(const char* pdfname, const char* histname, int nFitParam=0) const ;

  RooHist* residHist(const char* histname=0, const char* pdfname=0,bool normalize=false, bool useAverage=kFALSE) const ;
  RooHist* pullHist(const char* histname=0, const char* pdfname=0, bool useAverage=false) const 
    { return residHist(histname,pdfname,true,useAverage); }

  void Browse(TBrowser *b) ;

  static Bool_t addDirectoryStatus() ;
  static Bool_t setAddDirectoryStatus(Bool_t flag) ;

protected:

  RooPlot(const RooPlot& other); // cannot be copied

  class DrawOpt {
    public:

    DrawOpt(const char* _rawOpt=0) : invisible(kFALSE) { drawOptions[0] = 0 ; initialize(_rawOpt) ; }
    void initialize(const char* _rawOpt) ;
    const char* rawOpt() const ;

    char drawOptions[128] ;
    Bool_t invisible ;
  } ;


  void initialize();
  TString histName() const ; 
  TString caller(const char *method) const;
  void updateYAxis(Double_t ymin, Double_t ymax, const char *label= "");
  void updateFitRangeNorm(const TH1* hist);
  void updateFitRangeNorm(const RooPlotable* rp, Bool_t refeshNorm=kFALSE);

  TH1* _hist ;               // Histogram that we uses as basis for drawing the content

  RooList _items;            // A list of the items we contain.
  Double_t _padFactor;       // Scale our y-axis to _padFactor of our maximum contents.
  RooAbsRealLValue *_plotVarClone; // A clone of the variable we are plotting.
  RooArgSet *_plotVarSet;    // A list owning the cloned tree nodes of the plotVarClone
  RooArgSet *_normVars;      // Variables that PDF plots should be normalized over

  const RooPlotable* _normObj ;    //! Pointer to normalization object ;
  Double_t _normNumEvts;     // Number of events in histogram (for normalization)
  Double_t _normBinWidth;    // Histogram bin width (for normalization)

  TIterator *_iterator;      //! non-persistent

  Double_t _defYmin ;        // Default minimum for Yaxis (as calculated from contents)
  Double_t _defYmax ;        // Default maximum for Yaxis (as calculated from contents)

  TDirectory* _dir ;         //! non-persistent

  static Bool_t _addDirStatus ; // static flag controlling AutoDirectoryAdd feature

  ClassDef(RooPlot,2)        // Plot frame and container for graphics objects
};

#endif
 RooPlot.h:1
 RooPlot.h:2
 RooPlot.h:3
 RooPlot.h:4
 RooPlot.h:5
 RooPlot.h:6
 RooPlot.h:7
 RooPlot.h:8
 RooPlot.h:9
 RooPlot.h:10
 RooPlot.h:11
 RooPlot.h:12
 RooPlot.h:13
 RooPlot.h:14
 RooPlot.h:15
 RooPlot.h:16
 RooPlot.h:17
 RooPlot.h:18
 RooPlot.h:19
 RooPlot.h:20
 RooPlot.h:21
 RooPlot.h:22
 RooPlot.h:23
 RooPlot.h:24
 RooPlot.h:25
 RooPlot.h:26
 RooPlot.h:27
 RooPlot.h:28
 RooPlot.h:29
 RooPlot.h:30
 RooPlot.h:31
 RooPlot.h:32
 RooPlot.h:33
 RooPlot.h:34
 RooPlot.h:35
 RooPlot.h:36
 RooPlot.h:37
 RooPlot.h:38
 RooPlot.h:39
 RooPlot.h:40
 RooPlot.h:41
 RooPlot.h:42
 RooPlot.h:43
 RooPlot.h:44
 RooPlot.h:45
 RooPlot.h:46
 RooPlot.h:47
 RooPlot.h:48
 RooPlot.h:49
 RooPlot.h:50
 RooPlot.h:51
 RooPlot.h:52
 RooPlot.h:53
 RooPlot.h:54
 RooPlot.h:55
 RooPlot.h:56
 RooPlot.h:57
 RooPlot.h:58
 RooPlot.h:59
 RooPlot.h:60
 RooPlot.h:61
 RooPlot.h:62
 RooPlot.h:63
 RooPlot.h:64
 RooPlot.h:65
 RooPlot.h:66
 RooPlot.h:67
 RooPlot.h:68
 RooPlot.h:69
 RooPlot.h:70
 RooPlot.h:71
 RooPlot.h:72
 RooPlot.h:73
 RooPlot.h:74
 RooPlot.h:75
 RooPlot.h:76
 RooPlot.h:77
 RooPlot.h:78
 RooPlot.h:79
 RooPlot.h:80
 RooPlot.h:81
 RooPlot.h:82
 RooPlot.h:83
 RooPlot.h:84
 RooPlot.h:85
 RooPlot.h:86
 RooPlot.h:87
 RooPlot.h:88
 RooPlot.h:89
 RooPlot.h:90
 RooPlot.h:91
 RooPlot.h:92
 RooPlot.h:93
 RooPlot.h:94
 RooPlot.h:95
 RooPlot.h:96
 RooPlot.h:97
 RooPlot.h:98
 RooPlot.h:99
 RooPlot.h:100
 RooPlot.h:101
 RooPlot.h:102
 RooPlot.h:103
 RooPlot.h:104
 RooPlot.h:105
 RooPlot.h:106
 RooPlot.h:107
 RooPlot.h:108
 RooPlot.h:109
 RooPlot.h:110
 RooPlot.h:111
 RooPlot.h:112
 RooPlot.h:113
 RooPlot.h:114
 RooPlot.h:115
 RooPlot.h:116
 RooPlot.h:117
 RooPlot.h:118
 RooPlot.h:119
 RooPlot.h:120
 RooPlot.h:121
 RooPlot.h:122
 RooPlot.h:123
 RooPlot.h:124
 RooPlot.h:125
 RooPlot.h:126
 RooPlot.h:127
 RooPlot.h:128
 RooPlot.h:129
 RooPlot.h:130
 RooPlot.h:131
 RooPlot.h:132
 RooPlot.h:133
 RooPlot.h:134
 RooPlot.h:135
 RooPlot.h:136
 RooPlot.h:137
 RooPlot.h:138
 RooPlot.h:139
 RooPlot.h:140
 RooPlot.h:141
 RooPlot.h:142
 RooPlot.h:143
 RooPlot.h:144
 RooPlot.h:145
 RooPlot.h:146
 RooPlot.h:147
 RooPlot.h:148
 RooPlot.h:149
 RooPlot.h:150
 RooPlot.h:151
 RooPlot.h:152
 RooPlot.h:153
 RooPlot.h:154
 RooPlot.h:155
 RooPlot.h:156
 RooPlot.h:157
 RooPlot.h:158
 RooPlot.h:159
 RooPlot.h:160
 RooPlot.h:161
 RooPlot.h:162
 RooPlot.h:163
 RooPlot.h:164
 RooPlot.h:165
 RooPlot.h:166
 RooPlot.h:167
 RooPlot.h:168
 RooPlot.h:169
 RooPlot.h:170
 RooPlot.h:171
 RooPlot.h:172
 RooPlot.h:173
 RooPlot.h:174
 RooPlot.h:175
 RooPlot.h:176
 RooPlot.h:177
 RooPlot.h:178
 RooPlot.h:179
 RooPlot.h:180
 RooPlot.h:181
 RooPlot.h:182
 RooPlot.h:183
 RooPlot.h:184
 RooPlot.h:185
 RooPlot.h:186
 RooPlot.h:187
 RooPlot.h:188
 RooPlot.h:189
 RooPlot.h:190
 RooPlot.h:191
 RooPlot.h:192
 RooPlot.h:193
 RooPlot.h:194
 RooPlot.h:195
 RooPlot.h:196
 RooPlot.h:197
 RooPlot.h:198
 RooPlot.h:199
 RooPlot.h:200
 RooPlot.h:201
 RooPlot.h:202
 RooPlot.h:203
 RooPlot.h:204
 RooPlot.h:205
 RooPlot.h:206
 RooPlot.h:207
 RooPlot.h:208
 RooPlot.h:209
 RooPlot.h:210
 RooPlot.h:211
 RooPlot.h:212
 RooPlot.h:213
 RooPlot.h:214
 RooPlot.h:215
 RooPlot.h:216
 RooPlot.h:217
 RooPlot.h:218
 RooPlot.h:219
 RooPlot.h:220
 RooPlot.h:221
 RooPlot.h:222
 RooPlot.h:223
 RooPlot.h:224
 RooPlot.h:225