Logo ROOT  
Reference Guide
No Matches
Go to the documentation of this file.
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
19#include "RooAbsRealLValue.h"
21#include "TString.h"
23#include <list>
24#include <string>
25#include <map>
26#include <memory>
27#include <unordered_map>
30class RooArgSet ;
31class RooErrorVar ;
35namespace RooBatchCompute{
36struct RunContext;
41 // Constructors, assignment etc.
42 RooRealVar() ;
43 RooRealVar(const char *name, const char *title,
44 Double_t value, const char *unit= "") ;
45 RooRealVar(const char *name, const char *title, Double_t minValue,
46 Double_t maxValue, const char *unit= "");
47 RooRealVar(const char *name, const char *title, Double_t value,
48 Double_t minValue, Double_t maxValue, const char *unit= "") ;
49 RooRealVar(const RooRealVar& other, const char* name=0);
50 RooRealVar& operator=(const RooRealVar& other);
51 virtual TObject* clone(const char* newname) const { return new RooRealVar(*this,newname); }
52 virtual ~RooRealVar();
54 // Parameter value and error accessors
55 virtual Double_t getValV(const RooArgSet* nset=0) const ;
56 RooSpan<const double> getValues(RooBatchCompute::RunContext& inputData, const RooArgSet* = nullptr) const final;
58 virtual void setVal(Double_t value);
59 virtual void setVal(Double_t value, const char* rangeName);
60 inline Double_t getError() const { return _error>=0?_error:0. ; }
61 inline Bool_t hasError(Bool_t allowZero=kTRUE) const { return allowZero ? (_error>=0) : (_error>0) ; }
62 inline void setError(Double_t value) { _error= value ; }
63 inline void removeError() { _error = -1 ; }
64 inline Double_t getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
65 inline Double_t getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
66 inline Bool_t hasAsymError(Bool_t allowZero=kTRUE) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
67 inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
68 inline void setAsymError(Double_t lo, Double_t hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
69 inline Double_t getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
70 inline Double_t getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
72 RooErrorVar* errorVar() const ;
74 // Set/get finite fit range limits
75 void setMin(const char* name, Double_t value) ;
76 void setMax(const char* name, Double_t value) ;
77 void setRange(const char* name, Double_t min, Double_t max) ;
78 void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
79 inline void setMin(Double_t value) { setMin(0,value) ; }
80 inline void setMax(Double_t value) { setMax(0,value) ; }
81 /// Set the limits of the default range.
82 inline void setRange(Double_t min, Double_t max) { setRange(0,min,max) ; }
83 /// Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&, RooAbsReal&).
84 inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(0,min,max) ; }
86 void setBins(Int_t nBins, const char* name=0);
87 void setBinning(const RooAbsBinning& binning, const char* name=0) ;
89 // RooAbsRealLValue implementation
90 Bool_t hasBinning(const char* name) const ;
91 const RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const ;
92 RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) ;
93 std::list<std::string> getBinningNames() const ;
95 // Set infinite fit range limits
96 /// Remove lower range limit for binning with given name. Empty name means default range.
97 void removeMin(const char* name=0);
98 /// Remove upper range limit for binning with given name. Empty name means default range.
99 void removeMax(const char* name=0);
100 /// Remove range limits for binning with given name. Empty name means default range.
101 void removeRange(const char* name=0);
103 // I/O streaming interface (machine readable)
104 virtual Bool_t readFromStream(std::istream& is, Bool_t compact, Bool_t verbose=kFALSE) ;
105 virtual void writeToStream(std::ostream& os, Bool_t compact) const ;
107 // We implement a fundamental type of AbsArg that can be stored in a dataset
108 inline virtual Bool_t isFundamental() const { return kTRUE; }
110 // Force to be a leaf-node of any expression tree, even if we have (shape) servers
111 virtual Bool_t isDerived() const {
112 // Does value or shape of this arg depend on any other arg?
113 return !_serverList.empty() || _proxyList.GetEntries()>0;
114 }
116 // Printing interface (human readable)
117 virtual void printValue(std::ostream& os) const ;
118 virtual void printExtras(std::ostream& os) const ;
119 virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
120 virtual Int_t defaultPrintContents(Option_t* opt) const ;
123 TString* format(const RooCmdArg& formatArg) const ;
124 TString* format(Int_t sigDigits, const char *options) const ;
126 static void printScientific(Bool_t flag=kFALSE) ;
127 static void printSigDigits(Int_t ndig=5) ;
129 using RooAbsRealLValue::operator= ;
133 void copyCacheFast(const RooRealVar& other, Bool_t setValDirty=kTRUE) { _value = other._value ; if (setValDirty) setValueDirty() ; }
135 static void cleanup() ;
137 protected:
142 friend class RooAbsRealLValue ;
143 virtual void setValFast(Double_t value) { _value = value ; setValueDirty() ; }
146 virtual Double_t evaluate() const { return _value ; } // dummy because we overloaded getVal()
147 virtual void copyCache(const RooAbsArg* source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE) ;
148 virtual void attachToTree(TTree& t, Int_t bufSize=32000) ;
149 virtual void attachToVStore(RooVectorDataStore& vstore) ;
150 virtual void fillTreeBranch(TTree& t) ;
152 Double_t chopAt(Double_t what, Int_t where) const ;
154 Double_t _error; // Symmetric error associated with current value
155 Double_t _asymErrLo ; // Low side of asymmetric error associated with current value
156 Double_t _asymErrHi ; // High side of asymmetric error associated with current value
157 std::unique_ptr<RooAbsBinning> _binning;
158 std::unordered_map<std::string,std::unique_ptr<RooAbsBinning>> _altNonSharedBinning ; //! Non-shareable alternative binnings
160 std::shared_ptr<RooRealVarSharedProperties> sharedProp() const;
161 void installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop);
163 virtual void setExpensiveObjectCache(RooExpensiveObjectCache&) { ; } // variables don't need caches
164 static RooRealVarSharedProperties& _nullProp(); // Null property
165 static std::map<std::string,std::weak_ptr<RooRealVarSharedProperties>>* sharedPropList(); // List of properties shared among clones of a variable
167 std::shared_ptr<RooRealVarSharedProperties> _sharedProp; //! Shared binnings associated with this instance
169 ClassDef(RooRealVar,7) // Real-valued variable
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:110
#define hi
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:72
RooRefArray _proxyList
Definition RooAbsArg.h:619
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:508
RefCountList_t _serverList
Definition RooAbsArg.h:614
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:61
Double_t _value
Definition RooAbsReal.h:475
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition RooCmdArg.h:27
RooErrorVar is an auxilary class that represents the error of a RooRealVar as a seperate object.
Definition RooErrorVar.h:28
RooExpensiveObjectCache is a singleton class that serves as repository for objects that are expensive...
Class RooRealVarSharedProperties is an implementation of RooSharedProperties that stores the properti...
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
void setMin(Double_t value)
Definition RooRealVar.h:79
Double_t getAsymErrorLo() const
Definition RooRealVar.h:64
static std::map< std::string, std::weak_ptr< RooRealVarSharedProperties > > * sharedPropList()
Return a reference to a map of weak pointers to RooRealVarSharedProperties.
static void printSigDigits(Int_t ndig=5)
Set number of digits to show when printing RooRealVars.
RooSpan< const double > getValues(RooBatchCompute::RunContext &inputData, const RooArgSet *=nullptr) const final
Retrieve data column of this variable.
Double_t _error
Definition RooRealVar.h:154
void setRange(Double_t min, Double_t max)
Set the limits of the default range.
Definition RooRealVar.h:82
Bool_t hasBinning(const char *name) const
Returns true if variable has a binning named 'name'.
std::unordered_map< std::string, std::unique_ptr< RooAbsBinning > > _altNonSharedBinning
Definition RooRealVar.h:158
static RooRealVarSharedProperties & _nullProp()
Return a dummy object to use when properties are not initialised.
Double_t getErrorHi() const
Definition RooRealVar.h:70
Bool_t hasAsymError(Bool_t allowZero=kTRUE) const
Definition RooRealVar.h:66
std::shared_ptr< RooRealVarSharedProperties > sharedProp() const
Non-shareable alternative binnings.
virtual void printValue(std::ostream &os) const
Print value of variable.
static void printScientific(Bool_t flag=kFALSE)
If true, contents of RooRealVars will be printed in scientific notation.
virtual void setValFast(Double_t value)
Definition RooRealVar.h:143
Double_t _asymErrHi
Definition RooRealVar.h:156
virtual Int_t defaultPrintContents(Option_t *opt) const
Mapping of Print() option string to RooPrintable contents specifications.
Double_t getErrorLo() const
Definition RooRealVar.h:69
void setMin(const char *name, Double_t value)
Set minimum of name range to given value.
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
std::unique_ptr< RooAbsBinning > _binning
Definition RooRealVar.h:157
void installSharedProp(std::shared_ptr< RooRealVarSharedProperties > &&prop)
Install the shared property into the member _sharedProp.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
Definition RooRealVar.h:167
void removeAsymError()
Definition RooRealVar.h:67
void setError(Double_t value)
Definition RooRealVar.h:62
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Detailed printing interface.
virtual void printExtras(std::ostream &os) const
Print extras of variable: (asymmetric) error, constant flag, limits and binning.
void setMax(Double_t value)
Definition RooRealVar.h:80
Double_t chopAt(Double_t what, Int_t where) const
Utility to calculate number of decimals to show based on magnitude of error.
static Int_t _printSigDigits
Definition RooRealVar.h:140
void setRange(const char *name, Double_t min, Double_t max)
Set a fit or plotting range.
static void cleanup()
Explicitely deletes the shared properties list on exit to avoid problems with the initialization orde...
std::list< std::string > getBinningNames() const
Get a list of all binning names.
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:108
virtual void attachToVStore(RooVectorDataStore &vstore)
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
void removeRange(const char *name=0)
Remove range limits for binning with given name. Empty name means default range.
Double_t getAsymErrorHi() const
Definition RooRealVar.h:65
void setMax(const char *name, Double_t value)
Set maximum of name range to given value.
void setRange(RooAbsReal &min, RooAbsReal &max)
Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&,...
Definition RooRealVar.h:84
virtual Double_t getValV(const RooArgSet *nset=0) const
Return value of variable.
void setAsymError(Double_t lo, Double_t hi)
Definition RooRealVar.h:68
void deleteSharedProperties()
Stop sharing properties.
virtual void fillTreeBranch(TTree &t)
Overload RooAbsReal::fillTreeBranch to also fill tree branches with (asymmetric) errors if requested.
Bool_t hasError(Bool_t allowZero=kTRUE) const
Definition RooRealVar.h:61
virtual ~RooRealVar()
Double_t _asymErrLo
Definition RooRealVar.h:155
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
Double_t getError() const
Definition RooRealVar.h:60
void removeMax(const char *name=0)
Remove upper range limit for binning with given name. Empty name means default range.
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...
virtual Bool_t isDerived() const
Does value or shape of this arg depend on any other arg?
Definition RooRealVar.h:111
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
void removeMin(const char *name=0)
Remove lower range limit for binning with given name. Empty name means default range.
static Bool_t _printScientific
Definition RooRealVar.h:139
TString * format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
void copyCacheFast(const RooRealVar &other, Bool_t setValDirty=kTRUE)
Definition RooRealVar.h:133
Default constructor.
virtual void attachToTree(TTree &t, Int_t bufSize=32000)
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
void removeError()
Definition RooRealVar.h:63
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name 'name' with this variable.
virtual TObject * clone(const char *newname) const
Definition RooRealVar.h:51
virtual void setVal(Double_t value)
Set value of variable to 'value'.
RooRealVar & operator=(const RooRealVar &other)
Assign the values of another RooRealVar to this instance.
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &)
Definition RooRealVar.h:163
virtual Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition RooRealVar.h:146
bool empty() const
Check if empty.
A simple container to hold a batch of data values.
Definition RooSpan.h:34
RooVectorDataStore uses std::vectors to store data columns.
Int_t GetEntries() const
Return the number of objects in array (i.e.
Mother of all ROOT objects.
Definition TObject.h:37
Basic string class.
Definition TString.h:136
A TTree represents a columnar dataset.
Definition TTree.h:79
Namespace for dispatching RooFit computations to various backends.
static const char * what
Definition stlLoader.cc:6
This struct enables passing computation data around between elements of a computation graph.
Definition RunContext.h:31