Logo ROOT  
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 #include "RunContext.h"
21 
22 #include "TString.h"
23 
24 #include <list>
25 #include <string>
26 #include <map>
27 #include <memory>
28 #include <unordered_map>
29 
30 
31 class RooArgSet ;
32 class RooErrorVar ;
33 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  RooRealVar& operator=(const RooRealVar& other);
49  virtual TObject* clone(const char* newname) const { return new RooRealVar(*this,newname); }
50  virtual ~RooRealVar();
51 
52  // Parameter value and error accessors
53  virtual Double_t getValV(const RooArgSet* nset=0) const ;
54  ////////////////////////////////////////////////////////////////////////////////
55  /// Return batch of data starting at `begin`.
56  /// \param begin First event to return.
57  /// \param batchSize Size of the batch.
58  /// \return Span with event data. If not attached to a data store, empty batch. The batch will be shorter if data store ends.
59  RooSpan<const double> getValBatch(std::size_t begin, std::size_t batchSize, const RooArgSet* = nullptr) const final {
60  return _batchData.getBatch(begin, batchSize);
61  }
62  RooSpan<const double> getValues(BatchHelpers::RunContext& inputData, const RooArgSet*) const final;
63 
64  virtual void setVal(Double_t value);
65  virtual void setVal(Double_t value, const char* rangeName);
66  inline Double_t getError() const { return _error>=0?_error:0. ; }
67  inline Bool_t hasError(Bool_t allowZero=kTRUE) const { return allowZero ? (_error>=0) : (_error>0) ; }
68  inline void setError(Double_t value) { _error= value ; }
69  inline void removeError() { _error = -1 ; }
70  inline Double_t getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
71  inline Double_t getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
72  inline Bool_t hasAsymError(Bool_t allowZero=kTRUE) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
73  inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
74  inline void setAsymError(Double_t lo, Double_t hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
75  inline Double_t getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
76  inline Double_t getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
77 
78  RooErrorVar* errorVar() const ;
79 
80  // Set/get finite fit range limits
81  void setMin(const char* name, Double_t value) ;
82  void setMax(const char* name, Double_t value) ;
83  void setRange(const char* name, Double_t min, Double_t max) ;
84  void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
85  inline void setMin(Double_t value) { setMin(0,value) ; }
86  inline void setMax(Double_t value) { setMax(0,value) ; }
87  /// Set the limits of the default range.
88  inline void setRange(Double_t min, Double_t max) { setRange(0,min,max) ; }
89  /// Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&, RooAbsReal&).
90  inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(0,min,max) ; }
91 
92  void setBins(Int_t nBins, const char* name=0);
93  void setBinning(const RooAbsBinning& binning, const char* name=0) ;
94 
95  // RooAbsRealLValue implementation
96  Bool_t hasBinning(const char* name) const ;
97  const RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const ;
98  RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) ;
99  std::list<std::string> getBinningNames() const ;
100 
101  // Set infinite fit range limits
102  /// Remove lower range limit for binning with given name. Empty name means default range.
103  void removeMin(const char* name=0);
104  /// Remove upper range limit for binning with given name. Empty name means default range.
105  void removeMax(const char* name=0);
106  /// Remove range limits for binning with given name. Empty name means default range.
107  void removeRange(const char* name=0);
108 
109  // I/O streaming interface (machine readable)
110  virtual Bool_t readFromStream(std::istream& is, Bool_t compact, Bool_t verbose=kFALSE) ;
111  virtual void writeToStream(std::ostream& os, Bool_t compact) const ;
112 
113  // We implement a fundamental type of AbsArg that can be stored in a dataset
114  inline virtual Bool_t isFundamental() const { return kTRUE; }
115 
116  // Force to be a leaf-node of any expression tree, even if we have (shape) servers
117  virtual Bool_t isDerived() const {
118  // Does value or shape of this arg depend on any other arg?
119  return !_serverList.empty() || _proxyList.GetEntries()>0;
120  }
121 
122  // Printing interface (human readable)
123  virtual void printValue(std::ostream& os) const ;
124  virtual void printExtras(std::ostream& os) const ;
125  virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
126  virtual Int_t defaultPrintContents(Option_t* opt) const ;
127 
128 
129  TString* format(const RooCmdArg& formatArg) const ;
130  TString* format(Int_t sigDigits, const char *options) const ;
131 
132  static void printScientific(Bool_t flag=kFALSE) ;
133  static void printSigDigits(Int_t ndig=5) ;
134 
135  using RooAbsRealLValue::operator= ;
136 
137  void deleteSharedProperties() ;
138 
139  void copyCacheFast(const RooRealVar& other, Bool_t setValDirty=kTRUE) { _value = other._value ; if (setValDirty) setValueDirty() ; }
140 
141  protected:
142 
145 
146  friend class RooAbsRealLValue ;
147  virtual void setValFast(Double_t value) { _value = value ; setValueDirty() ; }
148 
149 
150  virtual Double_t evaluate() const { return _value ; } // dummy because we overloaded getVal()
151  virtual void copyCache(const RooAbsArg* source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE) ;
152  virtual void attachToTree(TTree& t, Int_t bufSize=32000) ;
153  virtual void attachToVStore(RooVectorDataStore& vstore) ;
154  virtual void fillTreeBranch(TTree& t) ;
155 
156  Double_t chopAt(Double_t what, Int_t where) const ;
157 
158  Double_t _error; // Symmetric error associated with current value
159  Double_t _asymErrLo ; // Low side of asymmetric error associated with current value
160  Double_t _asymErrHi ; // High side of asymmetric error associated with current value
161  std::unique_ptr<RooAbsBinning> _binning;
162  std::unordered_map<std::string,std::unique_ptr<RooAbsBinning>> _altNonSharedBinning ; //! Non-shareable alternative binnings
163 
164  std::shared_ptr<RooRealVarSharedProperties> sharedProp() const;
165  void installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop);
166 
167  virtual void setExpensiveObjectCache(RooExpensiveObjectCache&) { ; } // variables don't need caches
168 
169  static std::map<std::string,std::weak_ptr<RooRealVarSharedProperties>> _sharedPropList; // List of properties shared among clones of a variable
170  static const std::unique_ptr<RooRealVarSharedProperties> _nullProp ; // Null property
171  std::shared_ptr<RooRealVarSharedProperties> _sharedProp; //! Shared binnings associated with this instance
172 
173  ClassDef(RooRealVar,7) // Real-valued variable
174 };
175 
176 
177 
178 
179 #endif
RooRealVar::getAsymErrorHi
Double_t getAsymErrorHi() const
Definition: RooRealVar.h:71
RooRealVar::_asymErrLo
Double_t _asymErrLo
Definition: RooRealVar.h:159
RooCmdArg
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
RooRealVarSharedProperties
Class RooRealVarSharedProperties is an implementation of RooSharedProperties that stores the properti...
Definition: RooRealVarSharedProperties.h:27
RooRealVar::_sharedProp
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
Definition: RooRealVar.h:171
RooRealVar::setVal
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:245
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooRealVar::_altNonSharedBinning
std::unordered_map< std::string, std::unique_ptr< RooAbsBinning > > _altNonSharedBinning
Definition: RooRealVar.h:162
RooRealVar::_sharedPropList
static std::map< std::string, std::weak_ptr< RooRealVarSharedProperties > > _sharedPropList
Definition: RooRealVar.h:169
RooRealVar::installSharedProp
void installSharedProp(std::shared_ptr< RooRealVarSharedProperties > &&prop)
Install the shared property into the member _sharedProp.
Definition: RooRealVar.cxx:1278
Option_t
const char Option_t
Definition: RtypesCore.h:66
RooRealVar::printSigDigits
static void printSigDigits(Int_t ndig=5)
Set number of digits to show when printing RooRealVars.
Definition: RooRealVar.cxx:1328
RooRealVar::setMin
void setMin(const char *name, Double_t value)
Set minimum of name range to given value.
Definition: RooRealVar.cxx:449
RooRealVar::evaluate
virtual Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooRealVar.h:150
RooRealVar::getValBatch
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:59
RooRealVar::_printScientific
static Bool_t _printScientific
Definition: RooRealVar.h:143
RooRealVar::getBinningNames
std::list< std::string > getBinningNames() const
Get a list of all binning names.
Definition: RooRealVar.cxx:364
RooRealVar::format
TString * format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
Definition: RooRealVar.cxx:845
RooAbsArg::_serverList
RefCountList_t _serverList
Definition: RooAbsArg.h:594
TTree
A TTree represents a columnar dataset.
Definition: TTree.h:79
RooRealVar::operator=
RooAbsRealLValue & operator=(const RooAbsRealLValue &)=default
RooRealVar::fillTreeBranch
virtual void fillTreeBranch(TTree &t)
Overload RooAbsReal::fillTreeBranch to also fill tree branches with (asymmetric) errors if requested.
Definition: RooRealVar.cxx:1145
RooRealVar::setMax
void setMax(Double_t value)
Definition: RooRealVar.h:86
RooRealVar::removeAsymError
void removeAsymError()
Definition: RooRealVar.h:73
TObjArray::GetEntries
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:523
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
RooErrorVar
RooErrorVar is an auxilary class that represents the error of a RooRealVar as a seperate object.
Definition: RooErrorVar.h:28
RooRealVar::writeToStream
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
Definition: RooRealVar.cxx:695
RooRealVar::~RooRealVar
virtual ~RooRealVar()
Destructor.
Definition: RooRealVar.cxx:196
RooRealVar::chopAt
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:1043
TString
Basic string class.
Definition: TString.h:136
RooRealVar::copyCache
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...
Definition: RooRealVar.cxx:1183
RooRealVar::setRange
void setRange(const char *name, Double_t min, Double_t max)
Set a fit or plotting range.
Definition: RooRealVar.cxx:514
RooSTLRefCountList::empty
bool empty() const
Check if empty.
Definition: RooSTLRefCountList.h:114
RooRealVar::printValue
virtual void printValue(std::ostream &os) const
Print value of variable.
Definition: RooRealVar.cxx:760
TString.h
RooRealVar::errorVar
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
Definition: RooRealVar.cxx:279
RooExpensiveObjectCache
RooExpensiveObjectCache is a singleton class that serves as repository for objects that are expensive...
Definition: RooExpensiveObjectCache.h:24
bool
BatchHelpers::RunContext
Data that has to be passed around when evaluating functions / PDFs.
Definition: RunContext.h:32
RooRealVar::setRange
void setRange(Double_t min, Double_t max)
Set the limits of the default range.
Definition: RooRealVar.h:88
RooRealVar::readFromStream
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
Definition: RooRealVar.cxx:556
hi
float type_of_call hi(const int &, const int &)
RooRealVar::attachToVStore
virtual void attachToVStore(RooVectorDataStore &vstore)
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
Definition: RooRealVar.cxx:1057
RooRealVar::setMin
void setMin(Double_t value)
Definition: RooRealVar.h:85
RooRealVar::RooRealVar
RooRealVar()
Default constructor.
Definition: RooRealVar.cxx:62
RooRealVar::_asymErrHi
Double_t _asymErrHi
Definition: RooRealVar.h:160
RooRealVar::getError
Double_t getError() const
Definition: RooRealVar.h:66
RooRealVar::getAsymErrorLo
Double_t getAsymErrorLo() const
Definition: RooRealVar.h:70
RooRealVar::getErrorHi
Double_t getErrorHi() const
Definition: RooRealVar.h:76
RooRealVar::removeError
void removeError()
Definition: RooRealVar.h:69
RooRealVar::removeMax
void removeMax(const char *name=0)
Remove upper range limit for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:384
RooRealVar::getValues
RooSpan< const double > getValues(BatchHelpers::RunContext &inputData, const RooArgSet *) const final
Retrieve data column of this variable.
Definition: RooRealVar.cxx:219
RooRealVar::clone
virtual TObject * clone(const char *newname) const
Definition: RooRealVar.h:49
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooRealVar::setError
void setError(Double_t value)
Definition: RooRealVar.h:68
RooRealVar::hasBinning
Bool_t hasBinning(const char *name) const
Returns true if variable has a binning named 'name'.
Definition: RooRealVar.cxx:293
RooAbsBinning
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
Definition: RooAbsBinning.h:26
RooRealVar::isFundamental
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:114
RooRealVar::isDerived
virtual Bool_t isDerived() const
Does value or shape of this arg depend on any other arg?
Definition: RooRealVar.h:117
what
static const char * what
Definition: stlLoader.cc:6
RooAbsReal::_value
Double_t _value
Definition: RooAbsReal.h:454
RooRealVar::attachToTree
virtual void attachToTree(TTree &t, Int_t bufSize=32000)
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
Definition: RooRealVar.cxx:1092
RooAbsReal::_batchData
BatchHelpers::BatchData _batchData
Definition: RooAbsReal.h:455
RooRealVar::printExtras
virtual void printExtras(std::ostream &os) const
Print extras of variable: (asymmetric) error, constant flag, limits and binning.
Definition: RooRealVar.cxx:776
RooRealVar::getBinning
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
Definition: RooRealVar.cxx:306
RooRealVar::defaultPrintContents
virtual Int_t defaultPrintContents(Option_t *opt) const
Mapping of Print() option string to RooPrintable contents specifications.
Definition: RooRealVar.cxx:816
RooRealVar::_nullProp
static const std::unique_ptr< RooRealVarSharedProperties > _nullProp
Definition: RooRealVar.h:170
RooRealVar::getValV
virtual Double_t getValV(const RooArgSet *nset=0) const
Return value of variable.
Definition: RooRealVar.cxx:205
RooRealVar::setMax
void setMax(const char *name, Double_t value)
Set maximum of name range to given value.
Definition: RooRealVar.cxx:479
Double_t
double Double_t
Definition: RtypesCore.h:59
RooAbsArg::_proxyList
RooRefArray _proxyList
Definition: RooAbsArg.h:599
RooRealVar::setRange
void setRange(RooAbsReal &min, RooAbsReal &max)
Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&,...
Definition: RooRealVar.h:90
RooRealVar::copyCacheFast
void copyCacheFast(const RooRealVar &other, Bool_t setValDirty=kTRUE)
Definition: RooRealVar.h:139
RooRealVar::setValFast
virtual void setValFast(Double_t value)
Definition: RooRealVar.h:147
RooRealVar::setBinning
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name 'name' with this variable.
Definition: RooRealVar.cxx:403
RooRealVar::setExpensiveObjectCache
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &)
Definition: RooRealVar.h:167
RooRealVar::printScientific
static void printScientific(Bool_t flag=kFALSE)
If true, contents of RooRealVars will be printed in scientific notation.
Definition: RooRealVar.cxx:1319
RooVectorDataStore
RooVectorDataStore uses std::vectors to store data columns.
Definition: RooVectorDataStore.h:36
RooRealVar::hasAsymError
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:72
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
RooRealVar::sharedProp
std::shared_ptr< RooRealVarSharedProperties > sharedProp() const
Non-shareable alternative binnings.
Definition: RooRealVar.cxx:1264
RooRealVar::removeRange
void removeRange(const char *name=0)
Remove range limits for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:387
name
char name[80]
Definition: TGX11.cxx:110
RooRealVar::removeMin
void removeMin(const char *name=0)
Remove lower range limit for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:381
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RunContext.h
RooRealVar::_binning
std::unique_ptr< RooAbsBinning > _binning
Definition: RooRealVar.h:161
RooRealVar::_printSigDigits
static Int_t _printSigDigits
Definition: RooRealVar.h:144
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooRealVar::_error
Double_t _error
Definition: RooRealVar.h:158
RooAbsArg::setValueDirty
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:488
RooRealVar::setAsymError
void setAsymError(Double_t lo, Double_t hi)
Definition: RooRealVar.h:74
RooRealVar::getErrorLo
Double_t getErrorLo() const
Definition: RooRealVar.h:75
BatchHelpers::BatchData::getBatch
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:84
RooRealVar::setBins
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
Definition: RooRealVar.cxx:396
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooAbsRealLValue
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
Definition: RooAbsRealLValue.h:31
RooAbsRealLValue.h
RooRealVar::deleteSharedProperties
void deleteSharedProperties()
Stop sharing properties.
Definition: RooRealVar.cxx:1302
RooSpan
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
RooRealVar::hasError
Bool_t hasError(Bool_t allowZero=kTRUE) const
Definition: RooRealVar.h:67
int
RooRealVar::printMultiline
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Detailed printing interface.
Definition: RooRealVar.cxx:828