Logo ROOT   master
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 "RooAbsRealLValue.h"
20 
21 #include "TString.h"
22 
23 #include <list>
24 #include <string>
25 #include <map>
26 #include <memory>
27 
28 
29 class RooArgSet ;
30 class RooErrorVar ;
31 class RooVectorDataStore ;
34 
35 class RooRealVar : public RooAbsRealLValue {
36 public:
37  // Constructors, assignment etc.
38  RooRealVar() ;
39  RooRealVar(const char *name, const char *title,
40  Double_t value, const char *unit= "") ;
41  RooRealVar(const char *name, const char *title, Double_t minValue,
42  Double_t maxValue, const char *unit= "");
43  RooRealVar(const char *name, const char *title, Double_t value,
44  Double_t minValue, Double_t maxValue, const char *unit= "") ;
45  RooRealVar(const RooRealVar& other, const char* name=0);
46  RooRealVar& operator=(const RooRealVar& other);
47  virtual TObject* clone(const char* newname) const { return new RooRealVar(*this,newname); }
48  virtual ~RooRealVar();
49 
50  // Parameter value and error accessors
51  virtual Double_t getValV(const RooArgSet* nset=0) const ;
52  ////////////////////////////////////////////////////////////////////////////////
53  /// Return batch of data starting at `begin`.
54  /// \param begin First event to return.
55  /// \param batchSize Size of the batch.
56  /// \return Span with event data. If not attached to a data store, empty batch. The batch will be shorter if data store ends.
57  RooSpan<const double> getValBatch(std::size_t begin, std::size_t batchSize, const RooArgSet* = nullptr) const final {
58  return _batchData.getBatch(begin, batchSize);
59  }
60 
61  virtual void setVal(Double_t value);
62  inline Double_t getError() const { return _error>=0?_error:0. ; }
63  inline Bool_t hasError(Bool_t allowZero=kTRUE) const { return allowZero ? (_error>=0) : (_error>0) ; }
64  inline void setError(Double_t value) { _error= value ; }
65  inline void removeError() { _error = -1 ; }
66  inline Double_t getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
67  inline Double_t getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
68  inline Bool_t hasAsymError(Bool_t allowZero=kTRUE) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
69  inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
70  inline void setAsymError(Double_t lo, Double_t hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
71  inline Double_t getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
72  inline Double_t getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
73 
74  RooErrorVar* errorVar() const ;
75 
76  // Set/get finite fit range limits
77  void setMin(const char* name, Double_t value) ;
78  void setMax(const char* name, Double_t value) ;
79  void setRange(const char* name, Double_t min, Double_t max) ;
80  void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
81  inline void setMin(Double_t value) { setMin(0,value) ; }
82  inline void setMax(Double_t value) { setMax(0,value) ; }
83  /// Set the limits of the default range.
84  inline void setRange(Double_t min, Double_t max) { setRange(0,min,max) ; }
85  /// Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&, RooAbsReal&).
86  inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(0,min,max) ; }
87 
88  void setBins(Int_t nBins, const char* name=0);
89  void setBinning(const RooAbsBinning& binning, const char* name=0) ;
90 
91  // RooAbsRealLValue implementation
92  Bool_t hasBinning(const char* name) const ;
93  const RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const ;
94  RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) ;
95  std::list<std::string> getBinningNames() const ;
96 
97  // Set infinite fit range limits
98  /// Remove lower range limit for binning with given name. Empty name means default range.
99  void removeMin(const char* name=0);
100  /// Remove upper range limit for binning with given name. Empty name means default range.
101  void removeMax(const char* name=0);
102  /// Remove range limits for binning with given name. Empty name means default range.
103  void removeRange(const char* name=0);
104 
105  // I/O streaming interface (machine readable)
106  virtual Bool_t readFromStream(std::istream& is, Bool_t compact, Bool_t verbose=kFALSE) ;
107  virtual void writeToStream(std::ostream& os, Bool_t compact) const ;
108 
109  // We implement a fundamental type of AbsArg that can be stored in a dataset
110  inline virtual Bool_t isFundamental() const { return kTRUE; }
111 
112  // Force to be a leaf-node of any expression tree, even if we have (shape) servers
113  virtual Bool_t isDerived() const {
114  // Does value or shape of this arg depend on any other arg?
115  return !_serverList.empty() || _proxyList.GetEntries()>0;
116  }
117 
118  // Printing interface (human readable)
119  virtual void printValue(std::ostream& os) const ;
120  virtual void printExtras(std::ostream& os) const ;
121  virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
122  virtual Int_t defaultPrintContents(Option_t* opt) const ;
123 
124 
125  TString* format(const RooCmdArg& formatArg) const ;
126  TString* format(Int_t sigDigits, const char *options) const ;
127 
128  static void printScientific(Bool_t flag=kFALSE) ;
129  static void printSigDigits(Int_t ndig=5) ;
130 
131  using RooAbsRealLValue::operator= ;
132 
133  void deleteSharedProperties() ;
134 
135  void copyCacheFast(const RooRealVar& other, Bool_t setValDirty=kTRUE) { _value = other._value ; if (setValDirty) setValueDirty() ; }
136 
137  protected:
138 
141 
142  virtual void setVal(Double_t value, const char* rangeName) ;
143 
144  friend class RooAbsRealLValue ;
145  virtual void setValFast(Double_t value) { _value = value ; setValueDirty() ; }
146 
147 
148  virtual Double_t evaluate() const { return _value ; } // dummy because we overloaded getVal()
149  virtual void copyCache(const RooAbsArg* source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE) ;
150  virtual void attachToTree(TTree& t, Int_t bufSize=32000) ;
151  virtual void attachToVStore(RooVectorDataStore& vstore) ;
152  virtual void fillTreeBranch(TTree& t) ;
153 
154  Double_t chopAt(Double_t what, Int_t where) const ;
155 
156  Double_t _error; // Symmetric error associated with current value
157  Double_t _asymErrLo ; // Low side of asymmetric error associated with current value
158  Double_t _asymErrHi ; // High side of asymmetric error associated with current value
159  std::unique_ptr<RooAbsBinning> _binning;
160  RooLinkedList _altNonSharedBinning ; // Non-shareable alternative binnings
161 
162  std::shared_ptr<RooRealVarSharedProperties> sharedProp() const;
163  void installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop);
164 
165  virtual void setExpensiveObjectCache(RooExpensiveObjectCache&) { ; } // variables don't need caches
166 
167  static std::map<std::string,std::weak_ptr<RooRealVarSharedProperties>> _sharedPropList; // List of properties shared among clones of a variable
168  static const std::unique_ptr<RooRealVarSharedProperties> _nullProp ; // Null property
169  std::shared_ptr<RooRealVarSharedProperties> _sharedProp; //! Shared binnings associated with this instance
170 
171  ClassDef(RooRealVar,6) // Real-valued variable
172 };
173 
174 
175 
176 
177 #endif
virtual Bool_t isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition: RooRealVar.h:110
Bool_t hasBinning(const char *name) const
Returns true if variable has a binning with &#39;name&#39;.
Definition: RooRealVar.cxx:274
RooRealVar()
Default constructor.
Definition: RooRealVar.cxx:61
A simple container to hold a batch of data values.
Definition: RooSpan.h:32
virtual TObject * clone(const char *newname) const
Definition: RooRealVar.h:47
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:64
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooExpensiveObjectCache is a singleton class that serves as repository for objects that are expensive...
virtual Bool_t isDerived() const
Does value or shape of this arg depend on any other arg?
Definition: RooRealVar.h:113
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
Definition: RooRealVar.cxx:287
static const std::unique_ptr< RooRealVarSharedProperties > _nullProp
Definition: RooRealVar.h:168
void setRange(RooAbsReal &min, RooAbsReal &max)
Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&, RooAbsReal&).
Definition: RooRealVar.h:86
Basic string class.
Definition: TString.h:131
virtual void setValFast(Double_t value)
Definition: RooRealVar.h:145
virtual void printExtras(std::ostream &os) const
Print extras of variable: (asymmetric) error, constant flag, limits and binning.
Definition: RooRealVar.cxx:757
virtual Int_t defaultPrintContents(Option_t *opt) const
Mapping of Print() option string to RooPrintable contents specifications.
Definition: RooRealVar.cxx:797
virtual Double_t getValV(const RooArgSet *nset=0) const
Return value of variable.
Definition: RooRealVar.cxx:214
std::shared_ptr< RooRealVarSharedProperties > sharedProp() const
Hand out our shared property, create on the fly and register in shared map if necessary.
void setMax(const char *name, Double_t value)
Set maximum of name range to given value.
Definition: RooRealVar.cxx:460
void copyCacheFast(const RooRealVar &other, Bool_t setValDirty=kTRUE)
Definition: RooRealVar.h:135
static Int_t _printSigDigits
Definition: RooRealVar.h:140
std::unique_ptr< RooAbsBinning > _binning
Definition: RooRealVar.h:159
RooRealVar & operator=(const RooRealVar &other)
Assign the values of another RooRealVar to this instance.
Definition: RooRealVar.cxx:171
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &)
Definition: RooRealVar.h:165
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name &#39;name&#39; with this variable.
Definition: RooRealVar.cxx:389
Double_t getErrorLo() const
Definition: RooRealVar.h:71
static void printScientific(Bool_t flag=kFALSE)
If true, contents of RooRealVars will be printed in scientific notation.
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:68
#define ClassDef(name, id)
Definition: Rtypes.h:322
void removeRange(const char *name=0)
Remove range limits for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:373
RooVectorDataStore is the abstract base class for data collection that use a TTree as internal storag...
void deleteSharedProperties()
Stop sharing properties.
void removeMin(const char *name=0)
Remove lower range limit for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:367
RooErrorVar is an auxilary class that represents the error of a RooRealVar as a seperate object...
Definition: RooErrorVar.h:24
Double_t _error
Definition: RooRealVar.h:156
void setAsymError(Double_t lo, Double_t hi)
Definition: RooRealVar.h:70
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name &#39;name&#39; for this variable.
Definition: RooRealVar.cxx:382
Bool_t hasError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:63
Double_t _asymErrLo
Definition: RooRealVar.h:157
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
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:225
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
Definition: RooRealVar.h:169
bool empty() const
Check if empty.
Double_t getAsymErrorHi() const
Definition: RooRealVar.h:67
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Detailed printing interface.
Definition: RooRealVar.cxx:809
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:430
RooSpan< const double > getValBatch(std::size_t begin, std::size_t batchSize, const RooArgSet *=nullptr) const final
Return batch of data starting at begin.
Definition: RooRealVar.h:57
virtual Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooRealVar.h:148
TString * format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
Definition: RooRealVar.cxx:826
static std::map< std::string, std::weak_ptr< RooRealVarSharedProperties > > _sharedPropList
Definition: RooRealVar.h:167
void installSharedProp(std::shared_ptr< RooRealVarSharedProperties > &&prop)
Install the shared property into the member _sharedProp.
static void indent(ostringstream &buf, int indent_level)
static void printSigDigits(Int_t ndig=5)
Set number of digits to show when printing RooRealVars.
const Bool_t kFALSE
Definition: RtypesCore.h:90
std::list< std::string > getBinningNames() const
Get a list of all binning names.
Definition: RooRealVar.cxx:345
virtual void fillTreeBranch(TTree &t)
Overload RooAbsReal::fillTreeBranch to also fill tree branches with (asymmetric) errors if requested...
RooRefArray _proxyList
Definition: RooAbsArg.h:592
static Bool_t _printScientific
Definition: RooRealVar.h:139
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
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:60
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
Definition: RooRealVar.cxx:676
void setMax(Double_t value)
Definition: RooRealVar.h:82
Double_t _value
Definition: RooAbsReal.h:449
void setRange(const char *name, Double_t min, Double_t max)
Set a fit or plotting range.
Definition: RooRealVar.cxx:495
void removeAsymError()
Definition: RooRealVar.h:69
Mother of all ROOT objects.
Definition: TObject.h:37
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:505
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
Definition: RooRealVar.cxx:260
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.
RooLinkedList _altNonSharedBinning
Definition: RooRealVar.h:160
virtual ~RooRealVar()
Destructor.
Definition: RooRealVar.cxx:203
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:523
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
Definition: RooRealVar.cxx:537
virtual void attachToVStore(RooVectorDataStore &vstore)
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
A TTree represents a columnar dataset.
Definition: TTree.h:78
float type_of_call hi(const int &, const int &)
virtual void printValue(std::ostream &os) const
Print value of variable.
Definition: RooRealVar.cxx:741
void setMin(Double_t value)
Definition: RooRealVar.h:81
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:73
Double_t getError() const
Definition: RooRealVar.h:62
BatchHelpers::BatchData _batchData
Definition: RooAbsReal.h:450
Double_t _asymErrHi
Definition: RooRealVar.h:158
const Bool_t kTRUE
Definition: RtypesCore.h:89
Double_t getAsymErrorLo() const
Definition: RooRealVar.h:66
void removeError()
Definition: RooRealVar.h:65
void removeMax(const char *name=0)
Remove upper range limit for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:370
Double_t getErrorHi() const
Definition: RooRealVar.h:72
void setRange(Double_t min, Double_t max)
Set the limits of the default range.
Definition: RooRealVar.h:84
char name[80]
Definition: TGX11.cxx:109
RefCountList_t _serverList
Definition: RooAbsArg.h:587
RooSpan< const double > getBatch(std::size_t begin, std::size_t maxSize, const RooArgSet *const normSet=nullptr, Tag_t ownerTag=kUnspecified) const
Retrieve an existing batch.
Definition: BatchData.cxx:80
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:28
void setError(Double_t value)
Definition: RooRealVar.h:64