Logo ROOT   6.08/07
Reference Guide
RooRealVar.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooRealVar.h,v 1.54 2007/05/11 09:11:30 verkerke Exp $
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 #ifndef ROO_REAL_VAR
17 #define ROO_REAL_VAR
18 
19 #include <list>
20 #include <string>
21 #include "Riosfwd.h"
22 #include <math.h>
23 #include <float.h>
24 #include "TString.h"
25 
26 #include "RooAbsRealLValue.h"
27 #include "RooUniformBinning.h"
28 #include "RooNumber.h"
31 
32 class RooArgSet ;
33 class RooErrorVar ;
34 class RooVectorDataStore ;
36 
37 class RooRealVar : public RooAbsRealLValue {
38 public:
39  // Constructors, assignment etc.
40  RooRealVar() ;
41  RooRealVar(const char *name, const char *title,
42  Double_t value, const char *unit= "") ;
43  RooRealVar(const char *name, const char *title, Double_t minValue,
44  Double_t maxValue, const char *unit= "");
45  RooRealVar(const char *name, const char *title, Double_t value,
46  Double_t minValue, Double_t maxValue, const char *unit= "") ;
47  RooRealVar(const RooRealVar& other, const char* name=0);
48  virtual TObject* clone(const char* newname) const { return new RooRealVar(*this,newname); }
49  virtual ~RooRealVar();
50 
51  // Parameter value and error accessors
52  virtual Double_t getValV(const RooArgSet* nset=0) const ;
53  virtual void setVal(Double_t value);
54  inline Double_t getError() const { return _error>=0?_error:0. ; }
55  inline Bool_t hasError(Bool_t allowZero=kTRUE) const { return allowZero ? (_error>=0) : (_error>0) ; }
56  inline void setError(Double_t value) { _error= value ; }
57  inline void removeError() { _error = -1 ; }
58  inline Double_t getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
59  inline Double_t getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
60  inline Bool_t hasAsymError(Bool_t allowZero=kTRUE) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
61  inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
62  inline void setAsymError(Double_t lo, Double_t hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
63  inline Double_t getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
64  inline Double_t getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
65 
66  RooErrorVar* errorVar() const ;
67 
68  // Set/get finite fit range limits
69  void setMin(const char* name, Double_t value) ;
70  void setMax(const char* name, Double_t value) ;
71  void setRange(const char* name, Double_t min, Double_t max) ;
72  void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
73  inline void setMin(Double_t value) { setMin(0,value) ; }
74  inline void setMax(Double_t value) { setMax(0,value) ; }
75  inline void setRange(Double_t min, Double_t max) { setRange(0,min,max) ; }
76  inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(0,min,max) ; }
77 
78  void setBins(Int_t nBins, const char* name=0) { setBinning(RooUniformBinning(getMin(name),getMax(name),nBins),name) ; }
79  void setBinning(const RooAbsBinning& binning, const char* name=0) ;
80 
81  // RooAbsRealLValue implementation
82  Bool_t hasBinning(const char* name) const ;
83  const RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const ;
84  RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) ;
85  std::list<std::string> getBinningNames() const ;
86 
87  // Set infinite fit range limits
88  inline void removeMin(const char* name=0) { getBinning(name).setMin(-RooNumber::infinity()) ; }
89  inline void removeMax(const char* name=0) { getBinning(name).setMax(RooNumber::infinity()) ; }
90  inline void removeRange(const char* name=0) { getBinning(name).setRange(-RooNumber::infinity(),RooNumber::infinity()) ; }
91 
92  // I/O streaming interface (machine readable)
93  virtual Bool_t readFromStream(std::istream& is, Bool_t compact, Bool_t verbose=kFALSE) ;
94  virtual void writeToStream(std::ostream& os, Bool_t compact) const ;
95 
96  // We implement a fundamental type of AbsArg that can be stored in a dataset
97  inline virtual Bool_t isFundamental() const { return kTRUE; }
98 
99  // Force to be a leaf-node of any expression tree, even if we have (shape) servers
100  virtual Bool_t isDerived() const {
101  // Does value or shape of this arg depend on any other arg?
102  return (_serverList.GetSize()>0 || _proxyList.GetEntries()>0)?kTRUE:kFALSE;
103  }
104 
105  // Printing interface (human readable)
106  virtual void printValue(std::ostream& os) const ;
107  virtual void printExtras(std::ostream& os) const ;
108  virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
109  virtual Int_t defaultPrintContents(Option_t* opt) const ;
110 
111 
112  TString* format(const RooCmdArg& formatArg) const ;
113  TString* format(Int_t sigDigits, const char *options) const ;
114 
115  static void printScientific(Bool_t flag=kFALSE) ;
116  static void printSigDigits(Int_t ndig=5) ;
117 
118  using RooAbsRealLValue::operator= ;
119 
120  void deleteSharedProperties() ;
121 
122  void copyCacheFast(const RooRealVar& other, Bool_t setValDirty=kTRUE) { _value = other._value ; if (setValDirty) setValueDirty() ; }
123 
124  protected:
125 
128 
129  virtual void setVal(Double_t value, const char* rangeName) ;
130 
131  friend class RooAbsRealLValue ;
132  virtual void setValFast(Double_t value) { _value = value ; setValueDirty() ; }
133 
134 
135  virtual Double_t evaluate() const { return _value ; } // dummy because we overloaded getVal()
136  virtual void copyCache(const RooAbsArg* source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE) ;
137  virtual void attachToTree(TTree& t, Int_t bufSize=32000) ;
138  virtual void attachToVStore(RooVectorDataStore& vstore) ;
139  virtual void fillTreeBranch(TTree& t) ;
140 
141  Double_t chopAt(Double_t what, Int_t where) const ;
142 
143  Double_t _error; // Symmetric error associated with current value
144  Double_t _asymErrLo ; // Low side of asymmetric error associated with current value
145  Double_t _asymErrHi ; // High side of asymmetric error associated with current value
147  RooLinkedList _altNonSharedBinning ; // Non-shareable alternative binnings
148 
150  if (!_sharedProp) {
152  }
153  return _sharedProp ;
154  }
155 
156  virtual void setExpensiveObjectCache(RooExpensiveObjectCache&) { ; } // variables don't need caches
157 
158  static RooSharedPropertiesList _sharedPropList; // List of properties shared among clone sets
159  static RooRealVarSharedProperties _nullProp ; // Null property
160  mutable RooRealVarSharedProperties* _sharedProp ; //! Shared properties associated with this instance
161 
162  ClassDef(RooRealVar,5) // Real-valued variable
163 };
164 
165 
166 
167 
168 #endif
virtual Double_t getMin(const char *name=0) const
static RooRealVarSharedProperties _nullProp
Definition: RooRealVar.h:159
virtual Bool_t isFundamental() const
Definition: RooRealVar.h:97
Bool_t hasBinning(const char *name) const
Returns true if variable has a binning with &#39;name&#39;.
Definition: RooRealVar.cxx:254
RooRealVar()
Default constructor.
Definition: RooRealVar.cxx:64
virtual void setMin(Double_t xlo)
Definition: RooAbsBinning.h:51
virtual Double_t getMax(const char *name=0) const
virtual TObject * clone(const char *newname) const
Definition: RooRealVar.h:48
virtual void attachToTree(TTree &t, Int_t bufSize=32000)
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
const char Option_t
Definition: RtypesCore.h:62
RooExpensiveObjectCache is a singleton class that serves as repository for objects that are expensive...
virtual Bool_t isDerived() const
Definition: RooRealVar.h:100
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
Definition: RooRealVar.cxx:267
void setRange(RooAbsReal &min, RooAbsReal &max)
Definition: RooRealVar.h:76
Basic string class.
Definition: TString.h:137
virtual void setValFast(Double_t value)
Definition: RooRealVar.h:132
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void printExtras(std::ostream &os) const
Print extras of variable: (asymmetric) error, constant flag, limits and binning.
Definition: RooRealVar.cxx:711
virtual Int_t defaultPrintContents(Option_t *opt) const
Mapping of Print() option string to RooPrintable contents specifications.
Definition: RooRealVar.cxx:751
virtual Double_t getValV(const RooArgSet *nset=0) const
Return value of variable.
Definition: RooRealVar.cxx:194
Int_t GetSize() const
Definition: RooLinkedList.h:60
void setMax(const char *name, Double_t value)
Set maximum of name range to given value.
Definition: RooRealVar.cxx:418
void copyCacheFast(const RooRealVar &other, Bool_t setValDirty=kTRUE)
Definition: RooRealVar.h:122
void setValueDirty() const
Definition: RooAbsArg.h:439
static Int_t _printSigDigits
Definition: RooRealVar.h:127
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &)
Definition: RooRealVar.h:156
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name &#39;name&#39; with this variable.
Definition: RooRealVar.cxx:346
Double_t getErrorLo() const
Definition: RooRealVar.h:63
static void printScientific(Bool_t flag=kFALSE)
If true, contents of RooRealVars will be printed in scientific notation.
static RooSharedPropertiesList _sharedPropList
Definition: RooRealVar.h:158
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:60
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void setRange(Double_t xlo, Double_t xhi)=0
void removeRange(const char *name=0)
Definition: RooRealVar.h:90
RooRealVarSharedProperties * _sharedProp
Definition: RooRealVar.h:160
RooVectorDataStore is the abstract base class for data collection that use a TTree as internal storag...
void deleteSharedProperties()
No longer used?
void removeMin(const char *name=0)
Definition: RooRealVar.h:88
RooErrorVar is an auxilary class that represents the error of a RooRealVar as a seperate object...
Definition: RooErrorVar.h:29
Double_t _error
Definition: RooRealVar.h:143
void setAsymError(Double_t lo, Double_t hi)
Definition: RooRealVar.h:62
void setBins(Int_t nBins, const char *name=0)
Definition: RooRealVar.h:78
Bool_t hasError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:55
RooSharedProperties * registerProperties(RooSharedProperties *, Bool_t canDeleteIncoming=kTRUE)
Register property into list and take ownership.
Double_t _asymErrLo
Definition: RooRealVar.h:144
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
static const char * what
Definition: stlLoader.cc:6
virtual void setVal(Double_t value)
Set value of variable to &#39;value&#39;.
Definition: RooRealVar.cxx:205
Double_t getAsymErrorHi() const
Definition: RooRealVar.h:59
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Detailed printing interface.
Definition: RooRealVar.cxx:763
Class RooRealVarSharedProperties is an implementation of RooSharedProperties that stores the properti...
void setMin(const char *name, Double_t value)
Set minimum of name range to given value.
Definition: RooRealVar.cxx:388
virtual Double_t evaluate() const
Definition: RooRealVar.h:135
bool verbose
TString * format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
Definition: RooRealVar.cxx:780
static Double_t infinity()
Return internal infinity representation.
Definition: RooNumber.cxx:49
RooAbsBinning * _binning
Definition: RooRealVar.h:146
static void indent(ostringstream &buf, int indent_level)
static void printSigDigits(Int_t ndig=5)
Set number of digits to show when printing RooRealVars.
std::list< std::string > getBinningNames() const
Get a list of all binning names.
Definition: RooRealVar.cxx:320
virtual void fillTreeBranch(TTree &t)
Overload RooAbsReal::fillTreeBranch to also fill tree branches with (asymmetric) errors if requested...
RooRefArray _proxyList
Definition: RooAbsArg.h:477
static Bool_t _printScientific
Definition: RooRealVar.h:126
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:35
RooAbsBinning is the abstract base class for RooRealVar binning definitions This class defines the in...
Definition: RooAbsBinning.h:26
RooUniformBinning is an implementation of RooAbsBinning that provides a uniform binning in &#39;n&#39; bins b...
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
RooRefCountList _serverList
Definition: RooAbsArg.h:473
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
Definition: RooRealVar.cxx:630
RooRealVarSharedProperties * sharedProp() const
Definition: RooRealVar.h:149
Class RooSharedPropertiesList maintains the properties of RooRealVars and RooCategories that are clon...
void setMax(Double_t value)
Definition: RooRealVar.h:74
Double_t _value
Definition: RooAbsReal.h:389
void setRange(const char *name, Double_t min, Double_t max)
Set range named &#39;name to [min,max].
Definition: RooRealVar.cxx:449
void removeAsymError()
Definition: RooRealVar.h:61
Mother of all ROOT objects.
Definition: TObject.h:37
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
Definition: RooRealVar.cxx:240
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
Double_t chopAt(Double_t what, Int_t where) const
Utility to calculate number of decimals to show based on magnitude of error.
Definition: RooRealVar.cxx:978
RooLinkedList _altNonSharedBinning
Definition: RooRealVar.h:147
virtual ~RooRealVar()
Destructor cout << "RooRealVar::dtor(" << this << ")" << endl ;.
Definition: RooRealVar.cxx:178
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)
Copy the cached value of another RooAbsArg to our cache Warning: This function copies the cached valu...
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:494
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
Definition: RooRealVar.cxx:491
virtual void attachToVStore(RooVectorDataStore &vstore)
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
Definition: RooRealVar.cxx:992
A TTree object has a header with a name and a title.
Definition: TTree.h:98
float type_of_call hi(const int &, const int &)
virtual void printValue(std::ostream &os) const
Print value of variable.
Definition: RooRealVar.cxx:695
void setMin(Double_t value)
Definition: RooRealVar.h:73
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
Double_t getError() const
Definition: RooRealVar.h:54
Double_t _asymErrHi
Definition: RooRealVar.h:145
Double_t getAsymErrorLo() const
Definition: RooRealVar.h:58
void removeError()
Definition: RooRealVar.h:57
void removeMax(const char *name=0)
Definition: RooRealVar.h:89
Double_t getErrorHi() const
Definition: RooRealVar.h:64
void setRange(Double_t min, Double_t max)
Definition: RooRealVar.h:75
char name[80]
Definition: TGX11.cxx:109
virtual void setMax(Double_t xhi)
Definition: RooAbsBinning.h:55
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
void setError(Double_t value)
Definition: RooRealVar.h:56