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 /// Returns how many times the value of this RooRealVar was reset.
60 std::size_t valueResetCounter() const { return _valueResetCounter; }
61 void setVal(double value) override;
62 void setVal(double value, const char* rangeName) override;
63 inline double getError() const { return _error>=0?_error:0. ; }
64 inline bool hasError(bool allowZero=true) const { return allowZero ? (_error>=0) : (_error>0) ; }
65 inline void setError(double value) { _error= value ; }
66 inline void removeError() { _error = -1 ; }
67 inline double getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
68 inline double getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
69 inline bool hasAsymError(bool allowZero=true) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
70 inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
71 inline void setAsymError(double lo, double hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
72 inline double getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
73 inline double getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
74
75 RooErrorVar* errorVar() const ;
76
77 // Set/get finite fit range limits
78 void setMin(const char* name, double value) ;
79 void setMax(const char* name, double value) ;
80 void setRange(const char* name, double min, double max) ;
81 void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
82 inline void setMin(double value) { setMin(0,value) ; }
83 inline void setMax(double value) { setMax(0,value) ; }
84 /// Set the limits of the default range.
85 inline void setRange(double min, double max) { setRange(0,min,max) ; }
86 /// Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&, RooAbsReal&).
87 inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(0,min,max) ; }
88
89 void setBins(Int_t nBins, const char* name=0);
90 void setBinning(const RooAbsBinning& binning, const char* name=0) ;
91
92 // RooAbsRealLValue implementation
93 bool hasBinning(const char* name) const override ;
94 const RooAbsBinning& getBinning(const char* name=0, bool verbose=true, bool createOnTheFly=false) const override ;
95 RooAbsBinning& getBinning(const char* name=0, bool verbose=true, bool createOnTheFly=false) override ;
96 std::list<std::string> getBinningNames() const override ;
97
98 // Set infinite fit range limits
99 /// Remove lower range limit for binning with given name. Empty name means default range.
100 void removeMin(const char* name=0);
101 /// Remove upper range limit for binning with given name. Empty name means default range.
102 void removeMax(const char* name=0);
103 /// Remove range limits for binning with given name. Empty name means default range.
104 void removeRange(const char* name=0);
105
106 // I/O streaming interface (machine readable)
107 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
108 void writeToStream(std::ostream& os, bool compact) const override ;
109
110 // We implement a fundamental type of AbsArg that can be stored in a dataset
111 inline bool isFundamental() const override { return true; }
112
113 // Force to be a leaf-node of any expression tree, even if we have (shape) servers
114 bool isDerived() const override {
115 // Does value or shape of this arg depend on any other arg?
116 return !_serverList.empty() || _proxyList.GetEntries()>0;
117 }
118
119 // Printing interface (human readable)
120 void printValue(std::ostream& os) const override ;
121 void printExtras(std::ostream& os) const override ;
122 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
123 Int_t defaultPrintContents(Option_t* opt) const override ;
124
125
126 TString* format(const RooCmdArg& formatArg) const ;
127 TString* format(Int_t sigDigits, const char *options) const ;
128
129 static void printScientific(bool flag=false) ;
130 static void printSigDigits(Int_t ndig=5) ;
131
132 using RooAbsRealLValue::operator= ;
133
135
136 void copyCacheFast(const RooRealVar& other, bool setValDirty=true) { _value = other._value ; if (setValDirty) setValueDirty() ; }
137
138 static void cleanup() ;
139
140 protected:
141
142 static bool _printScientific ;
144
145 friend class RooAbsRealLValue ;
146 void setValFast(double value) override { _value = value ; setValueDirty() ; }
147
148
149 double evaluate() const override { return _value ; } // dummy because we overloaded getVal()
150 void copyCache(const RooAbsArg* source, bool valueOnly=false, bool setValDirty=true) override ;
151 void attachToTree(TTree& t, Int_t bufSize=32000) override ;
152 void attachToVStore(RooVectorDataStore& vstore) override ;
153 void fillTreeBranch(TTree& t) override ;
154
155 double chopAt(double what, Int_t where) const ;
156
157 double _error; ///< Symmetric error associated with current value
158 double _asymErrLo ; ///< Low side of asymmetric error associated with current value
159 double _asymErrHi ; ///< High side of asymmetric error associated with current value
160 std::unique_ptr<RooAbsBinning> _binning;
161 std::unordered_map<std::string,std::unique_ptr<RooAbsBinning>> _altNonSharedBinning ; ///<! Non-shareable alternative binnings
162
163 std::shared_ptr<RooRealVarSharedProperties> sharedProp() const;
164 void installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop);
165
166 void setExpensiveObjectCache(RooExpensiveObjectCache&) override { ; } ///< variables don't need caches
167 static RooRealVarSharedProperties& _nullProp(); ///< Null property
168
169 using SharedPropertiesMap = std::map<RooSharedProperties::UUID,std::weak_ptr<RooRealVarSharedProperties>>;
170
171 static SharedPropertiesMap* sharedPropList(); ///< List of properties shared among clones of a variable
172
173 std::shared_ptr<RooRealVarSharedProperties> _sharedProp; ///<! Shared binnings associated with this instance
174
175 std::size_t _valueResetCounter = 0; ///<! How many times the value of this variable was reset
176
177 ClassDefOverride(RooRealVar,8) // Real-valued variable
178};
179
180
181
182
183#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:72
RooRefArray _proxyList
Definition: RooAbsArg.h:658
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:653
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:157
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:65
std::unordered_map< std::string, std::unique_ptr< RooAbsBinning > > _altNonSharedBinning
! Non-shareable alternative binnings
Definition: RooRealVar.h:161
static RooRealVarSharedProperties & _nullProp()
Null property.
Definition: RooRealVar.cxx:85
double getErrorLo() const
Definition: RooRealVar.h:72
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:149
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:146
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
Definition: RooRealVar.cxx:434
void setMax(double value)
Definition: RooRealVar.h:83
void printValue(std::ostream &os) const override
Print value of variable.
Definition: RooRealVar.cxx:798
void printExtras(std::ostream &os) const override
Print extras of variable: (asymmetric) error, constant flag, limits and binning.
Definition: RooRealVar.cxx:814
std::unique_ptr< RooAbsBinning > _binning
Definition: RooRealVar.h:160
void setMin(const char *name, double value)
Set minimum of name range to given value.
Definition: RooRealVar.cxx:487
bool hasBinning(const char *name) const override
Returns true if variable has a binning named 'name'.
Definition: RooRealVar.cxx:331
double _asymErrLo
Low side of asymmetric error associated with current value.
Definition: RooRealVar.h:158
void installSharedProp(std::shared_ptr< RooRealVarSharedProperties > &&prop)
Install the shared property into the member _sharedProp.
static bool _printScientific
Definition: RooRealVar.h:142
bool isFundamental() const override
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition: RooRealVar.h:111
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
! Shared binnings associated with this instance
Definition: RooRealVar.h:173
void removeAsymError()
Definition: RooRealVar.h:70
void setAsymError(double lo, double hi)
Definition: RooRealVar.h:71
double getError() const
Definition: RooRealVar.h:63
const RooAbsBinning & getBinning(const char *name=0, bool verbose=true, bool createOnTheFly=false) const override
Return binning definition with name.
Definition: RooRealVar.cxx:344
std::list< std::string > getBinningNames() const override
Get a list of all binning names.
Definition: RooRealVar.cxx:402
void setExpensiveObjectCache(RooExpensiveObjectCache &) override
variables don't need caches
Definition: RooRealVar.h:166
double getErrorHi() const
Definition: RooRealVar.h:73
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Detailed printing interface.
Definition: RooRealVar.cxx:866
std::size_t _valueResetCounter
! How many times the value of this variable was reset
Definition: RooRealVar.h:175
~RooRealVar() override
Destructor.
Definition: RooRealVar.cxx:228
double _asymErrHi
High side of asymmetric error associated with current value.
Definition: RooRealVar.h:159
static Int_t _printSigDigits
Definition: RooRealVar.h:143
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:425
Int_t defaultPrintContents(Option_t *opt) const override
Mapping of Print() option string to RooPrintable contents specifications.
Definition: RooRealVar.cxx:854
void setRange(RooAbsReal &min, RooAbsReal &max)
Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&,...
Definition: RooRealVar.h:87
bool hasError(bool allowZero=true) const
Definition: RooRealVar.h:64
static SharedPropertiesMap * sharedPropList()
List of properties shared among clones of a variable.
Definition: RooRealVar.cxx:61
void deleteSharedProperties()
Stop sharing properties.
std::size_t valueResetCounter() const
Returns how many times the value of this RooRealVar was reset.
Definition: RooRealVar.h:60
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to given stream.
Definition: RooRealVar.cxx:733
std::map< RooSharedProperties::UUID, std::weak_ptr< RooRealVarSharedProperties > > SharedPropertiesMap
Definition: RooRealVar.h:169
bool hasAsymError(bool allowZero=true) const
Definition: RooRealVar.h:69
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
Definition: RooRealVar.cxx:317
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from given stream.
Definition: RooRealVar.cxx:594
void removeMax(const char *name=0)
Remove upper range limit for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:422
void removeMin(const char *name=0)
Remove lower range limit for binning with given name. Empty name means default range.
Definition: RooRealVar.cxx:419
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:883
double getAsymErrorHi() const
Definition: RooRealVar.h:68
void setRange(const char *name, double min, double max)
Set a fit or plotting range.
Definition: RooRealVar.cxx:552
RooRealVar()
Default constructor.
Definition: RooRealVar.cxx:94
void removeError()
Definition: RooRealVar.h:66
void setMax(const char *name, double value)
Set maximum of name range to given value.
Definition: RooRealVar.cxx:517
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name 'name' with this variable.
Definition: RooRealVar.cxx:441
void copyCacheFast(const RooRealVar &other, bool setValDirty=true)
Definition: RooRealVar.h:136
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:82
double getAsymErrorLo() const
Definition: RooRealVar.h:67
bool isDerived() const override
Does value or shape of this arg depend on any other arg?
Definition: RooRealVar.h:114
void setRange(double min, double max)
Set the limits of the default range.
Definition: RooRealVar.h:85
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:32