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 "RooSharedProperties.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
31class RooArgSet ;
32class RooErrorVar ;
36namespace RooBatchCompute{
37struct RunContext;
38}
39
41public:
42 // Constructors, assignment etc.
43 RooRealVar() ;
44 RooRealVar(const char *name, const char *title,
45 double value, const char *unit= "") ;
46 RooRealVar(const char *name, const char *title, double minValue,
47 double maxValue, const char *unit= "");
48 RooRealVar(const char *name, const char *title, double value,
49 double minValue, double maxValue, const char *unit= "") ;
50 RooRealVar(const RooRealVar& other, const char* name=0);
51 RooRealVar& operator=(const RooRealVar& other);
52 TObject* clone(const char* newname) const override { return new RooRealVar(*this,newname); }
53 ~RooRealVar() override;
54
55 // Parameter value and error accessors
56 double getValV(const RooArgSet* nset=0) const override ;
57 RooSpan<const double> getValues(RooBatchCompute::RunContext& inputData, const RooArgSet* = nullptr) const final;
58
59 void setVal(double value) override;
60 void setVal(double value, const char* rangeName) override;
61 inline double getError() const { return _error>=0?_error:0. ; }
62 inline bool hasError(bool allowZero=true) const { return allowZero ? (_error>=0) : (_error>0) ; }
63 inline void setError(double value) { _error= value ; }
64 inline void removeError() { _error = -1 ; }
65 inline double getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
66 inline double getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
67 inline bool hasAsymError(bool allowZero=true) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
68 inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
69 inline void setAsymError(double lo, double hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
70 inline double getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
71 inline double getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
72
73 RooErrorVar* errorVar() const ;
74
75 // Set/get finite fit range limits
76 void setMin(const char* name, double value) ;
77 void setMax(const char* name, double value) ;
78 void setRange(const char* name, double min, double max) ;
79 void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
80 inline void setMin(double value) { setMin(0,value) ; }
81 inline void setMax(double value) { setMax(0,value) ; }
82 /// Set the limits of the default range.
83 inline void setRange(double min, double max) { setRange(0,min,max) ; }
84 /// Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&, RooAbsReal&).
85 inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(0,min,max) ; }
86
87 void setBins(Int_t nBins, const char* name=0);
88 void setBinning(const RooAbsBinning& binning, const char* name=0) ;
89
90 // RooAbsRealLValue implementation
91 bool hasBinning(const char* name) const override ;
92 const RooAbsBinning& getBinning(const char* name=0, bool verbose=true, bool createOnTheFly=false) const override ;
93 RooAbsBinning& getBinning(const char* name=0, bool verbose=true, bool createOnTheFly=false) override ;
94 std::list<std::string> getBinningNames() const override ;
95
96 // Set infinite fit range limits
97 /// Remove lower range limit for binning with given name. Empty name means default range.
98 void removeMin(const char* name=0);
99 /// Remove upper range limit for binning with given name. Empty name means default range.
100 void removeMax(const char* name=0);
101 /// Remove range limits for binning with given name. Empty name means default range.
102 void removeRange(const char* name=0);
103
104 // I/O streaming interface (machine readable)
105 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
106 void writeToStream(std::ostream& os, bool compact) const override ;
107
108 // We implement a fundamental type of AbsArg that can be stored in a dataset
109 inline bool isFundamental() const override { return true; }
110
111 // Force to be a leaf-node of any expression tree, even if we have (shape) servers
112 bool isDerived() const override {
113 // Does value or shape of this arg depend on any other arg?
114 return !_serverList.empty() || _proxyList.GetEntries()>0;
115 }
116
117 // Printing interface (human readable)
118 void printValue(std::ostream& os) const override ;
119 void printExtras(std::ostream& os) const override ;
120 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
121 Int_t defaultPrintContents(Option_t* opt) const override ;
122
123
124 TString* format(const RooCmdArg& formatArg) const ;
125 TString* format(Int_t sigDigits, const char *options) const ;
126
127 static void printScientific(bool flag=false) ;
128 static void printSigDigits(Int_t ndig=5) ;
129
130 using RooAbsRealLValue::operator= ;
131
133
134 void copyCacheFast(const RooRealVar& other, bool setValDirty=true) { _value = other._value ; if (setValDirty) setValueDirty() ; }
135
136 static void cleanup() ;
137
138 protected:
139
140 static bool _printScientific ;
142
143 friend class RooAbsRealLValue ;
144 void setValFast(double value) override { _value = value ; setValueDirty() ; }
145
146
147 double evaluate() const override { return _value ; } // dummy because we overloaded getVal()
148 void copyCache(const RooAbsArg* source, bool valueOnly=false, bool setValDirty=true) override ;
149 void attachToTree(TTree& t, Int_t bufSize=32000) override ;
150 void attachToVStore(RooVectorDataStore& vstore) override ;
151 void fillTreeBranch(TTree& t) override ;
152
153 double chopAt(double what, Int_t where) const ;
154
155 double _error; ///< Symmetric error associated with current value
156 double _asymErrLo ; ///< Low side of asymmetric error associated with current value
157 double _asymErrHi ; ///< High side of asymmetric error associated with current value
158 std::unique_ptr<RooAbsBinning> _binning;
159 std::unordered_map<std::string,std::unique_ptr<RooAbsBinning>> _altNonSharedBinning ; ///<! Non-shareable alternative binnings
160
161 std::shared_ptr<RooRealVarSharedProperties> sharedProp() const;
162 void installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop);
163
164 void setExpensiveObjectCache(RooExpensiveObjectCache&) override { ; } ///< variables don't need caches
165 static RooRealVarSharedProperties& _nullProp(); ///< Null property
166
167 using SharedPropertiesMap = std::map<RooSharedProperties::UUID,std::weak_ptr<RooRealVarSharedProperties>>;
168
169 static SharedPropertiesMap* sharedPropList(); ///< List of properties shared among clones of a variable
170
171 std::shared_ptr<RooRealVarSharedProperties> _sharedProp; ///<! Shared binnings associated with this instance
172
173 ClassDefOverride(RooRealVar,8) // Real-valued variable
174};
175
176
177
178
179#endif
const char Option_t
Definition: RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h prop
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition: TGX11.cxx:110
#define hi
Definition: THbookFile.cxx:128
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:77
RooRefArray _proxyList
Definition: RooAbsArg.h:661
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:513
RefCountList_t _serverList
Definition: RooAbsArg.h:656
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
Definition: RooAbsBinning.h:26
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:64
double _value
Cache for current value of object.
Definition: RooAbsReal.h:484
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:26
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:40
double getValV(const RooArgSet *nset=0) const override
Return value of variable.
Definition: RooRealVar.cxx:242
void fillTreeBranch(TTree &t) override
Overload RooAbsReal::fillTreeBranch to also fill tree branches with (asymmetric) errors if requested.
static void printScientific(bool flag=false)
If true, contents of RooRealVars will be printed in scientific notation.
void setVal(double value) override
Set value of variable to 'value'.
Definition: RooRealVar.cxx:281
double _error
Symmetric error associated with current value.
Definition: RooRealVar.h:155
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.
Definition: RooRealVar.cxx:255
void setError(double value)
Definition: RooRealVar.h:63
std::unordered_map< std::string, std::unique_ptr< RooAbsBinning > > _altNonSharedBinning
! Non-shareable alternative binnings
Definition: RooRealVar.h:159
static RooRealVarSharedProperties & _nullProp()
Null property.
Definition: RooRealVar.cxx:85
double getErrorLo() const
Definition: RooRealVar.h:70
void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true) override
Copy the cached value of another RooAbsArg to our cache Warning: This function copies the cached valu...
std::shared_ptr< RooRealVarSharedProperties > sharedProp() const
Hand out our shared property, create on the fly and register in shared map if necessary.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooRealVar.h:147
void attachToTree(TTree &t, Int_t bufSize=32000) override
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
void attachToVStore(RooVectorDataStore &vstore) override
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
void setValFast(double value) override
Definition: RooRealVar.h:144
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
Definition: RooRealVar.cxx:432
void setMax(double value)
Definition: RooRealVar.h:81
void printValue(std::ostream &os) const override
Print value of variable.
Definition: RooRealVar.cxx:796
void printExtras(std::ostream &os) const override
Print extras of variable: (asymmetric) error, constant flag, limits and binning.
Definition: RooRealVar.cxx:812
std::unique_ptr< RooAbsBinning > _binning
Definition: RooRealVar.h:158
void setMin(const char *name, double value)
Set minimum of name range to given value.
Definition: RooRealVar.cxx:485
bool hasBinning(const char *name) const override
Returns true if variable has a binning named 'name'.
Definition: RooRealVar.cxx:329
double _asymErrLo
Low side of asymmetric error associated with current value.
Definition: RooRealVar.h:156
void installSharedProp(std::shared_ptr< RooRealVarSharedProperties > &&prop)
Install the shared property into the member _sharedProp.
static bool _printScientific
Definition: RooRealVar.h:140
bool isFundamental() const override
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition: RooRealVar.h:109
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
! Shared binnings associated with this instance
Definition: RooRealVar.h:171
void removeAsymError()
Definition: RooRealVar.h:68
void setAsymError(double lo, double hi)
Definition: RooRealVar.h:69
double getError() const
Definition: RooRealVar.h:61
const RooAbsBinning & getBinning(const char *name=0, bool verbose=true, bool createOnTheFly=false) const override
Return binning definition with name.
Definition: RooRealVar.cxx:342
std::list< std::string > getBinningNames() const override
Get a list of all binning names.
Definition: RooRealVar.cxx:400
void setExpensiveObjectCache(RooExpensiveObjectCache &) override
variables don't need caches
Definition: RooRealVar.h:164
double getErrorHi() const
Definition: RooRealVar.h:71
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Detailed printing interface.
Definition: RooRealVar.cxx:864
~RooRealVar() override
Destructor.
Definition: RooRealVar.cxx:228
double _asymErrHi
High side of asymmetric error associated with current value.
Definition: RooRealVar.h:157
static Int_t _printSigDigits
Definition: RooRealVar.h:141
TObject * clone(const char *newname) const override
Definition: RooRealVar.h:52
static void cleanup()
Explicitely deletes the shared properties list on exit to avoid problems with the initialization orde...
Definition: RooRealVar.cxx:76
void removeRange(const char *name=0)
Remove range limits for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:423
Int_t defaultPrintContents(Option_t *opt) const override
Mapping of Print() option string to RooPrintable contents specifications.
Definition: RooRealVar.cxx:852
void setRange(RooAbsReal &min, RooAbsReal &max)
Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&,...
Definition: RooRealVar.h:85
bool hasError(bool allowZero=true) const
Definition: RooRealVar.h:62
static SharedPropertiesMap * sharedPropList()
List of properties shared among clones of a variable.
Definition: RooRealVar.cxx:61
void deleteSharedProperties()
Stop sharing properties.
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to given stream.
Definition: RooRealVar.cxx:731
std::map< RooSharedProperties::UUID, std::weak_ptr< RooRealVarSharedProperties > > SharedPropertiesMap
Definition: RooRealVar.h:167
bool hasAsymError(bool allowZero=true) const
Definition: RooRealVar.h:67
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
Definition: RooRealVar.cxx:315
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from given stream.
Definition: RooRealVar.cxx:592
void removeMax(const char *name=0)
Remove upper range limit for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:420
void removeMin(const char *name=0)
Remove lower range limit for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:417
double chopAt(double what, Int_t where) const
Utility to calculate number of decimals to show based on magnitude of error.
TString * format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
Definition: RooRealVar.cxx:881
double getAsymErrorHi() const
Definition: RooRealVar.h:66
void setRange(const char *name, double min, double max)
Set a fit or plotting range.
Definition: RooRealVar.cxx:550
RooRealVar()
Default constructor.
Definition: RooRealVar.cxx:94
void removeError()
Definition: RooRealVar.h:64
void setMax(const char *name, double value)
Set maximum of name range to given value.
Definition: RooRealVar.cxx:515
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name 'name' with this variable.
Definition: RooRealVar.cxx:439
void copyCacheFast(const RooRealVar &other, bool setValDirty=true)
Definition: RooRealVar.h:134
RooRealVar & operator=(const RooRealVar &other)
Assign the values of another RooRealVar to this instance.
Definition: RooRealVar.cxx:198
void setMin(double value)
Definition: RooRealVar.h:80
double getAsymErrorLo() const
Definition: RooRealVar.h:65
bool isDerived() const override
Does value or shape of this arg depend on any other arg?
Definition: RooRealVar.h:112
void setRange(double min, double max)
Set the limits of the default range.
Definition: RooRealVar.h:83
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 override
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:523
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