Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 ;
36
38public:
39 // Constructors, assignment etc.
40 RooRealVar() ;
41 RooRealVar(const char *name, const char *title,
42 double value, const char *unit= "") ;
43 RooRealVar(const char *name, const char *title, double minValue,
44 double maxValue, const char *unit= "");
45 RooRealVar(const char *name, const char *title, double value,
46 double minValue, double maxValue, const char *unit= "") ;
47 RooRealVar(const RooRealVar& other, const char* name=nullptr);
48 TObject* clone(const char* newname=nullptr) const override { return new RooRealVar(*this,newname); }
49 ~RooRealVar() override;
50
51 // Parameter value and error accessors
52 double getValV(const RooArgSet* nset=nullptr) const override ;
53
54 /// Returns how many times the value of this RooRealVar was reset.
55 std::size_t valueResetCounter() const { return _valueResetCounter; }
56 void setVal(double value) override;
57 void setVal(double value, const char* rangeName) override;
58 static void enableSilentClipping(bool flag = true);
59 inline double getError() const { return _error>=0?_error:0. ; }
60 inline bool hasError(bool allowZero=true) const { return allowZero ? (_error>=0) : (_error>0) ; }
61 inline void setError(double value) { _error= value ; }
62 inline void removeError() { _error = -1 ; }
63 inline double getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
64 inline double getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
65 inline bool hasAsymError(bool allowZero=true) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
66 inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
67 inline void setAsymError(double lo, double hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
68 inline double getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
69 inline double getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
70
71 RooErrorVar* errorVar() const ;
72
73 // Set/get finite fit range limits
74 void setMin(const char* name, double value) ;
75 void setMax(const char* name, double value) ;
76 void setRange(const char* name, double min, double max) ;
77 void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
78 inline void setMin(double value) { setMin(nullptr,value) ; }
79 inline void setMax(double value) { setMax(nullptr,value) ; }
80 /// Set the limits of the default range.
81 inline void setRange(double min, double max) { setRange(nullptr,min,max) ; }
82 /// Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&, RooAbsReal&).
83 inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(nullptr,min,max) ; }
84
85 void setBins(Int_t nBins, const char* name=nullptr);
86 void setBinning(const RooAbsBinning& binning, const char* name=nullptr) ;
87
88 // RooAbsRealLValue implementation
89 bool hasBinning(const char* name) const override ;
90 const RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) const override ;
91 RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) override ;
92 std::list<std::string> getBinningNames() const override ;
93
94 // Set infinite fit range limits
95 /// Remove lower range limit for binning with given name. Empty name means default range.
96 void removeMin(const char* name=nullptr);
97 /// Remove upper range limit for binning with given name. Empty name means default range.
98 void removeMax(const char* name=nullptr);
99 /// Remove range limits for binning with given name. Empty name means default range.
100 void removeRange(const char* name=nullptr);
101
102 // I/O streaming interface (machine readable)
103 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
104 void writeToStream(std::ostream& os, bool compact) const override ;
105
106 // We implement a fundamental type of AbsArg that can be stored in a dataset
107 inline bool isFundamental() const override { return true; }
108
109 // Force to be a leaf-node of any expression tree, even if we have (shape) servers
110 bool isDerived() const override {
111 // Does value or shape of this arg depend on any other arg?
112 return !_serverList.empty() || _proxyList.GetEntries()>0;
113 }
114
115 // Printing interface (human readable)
116 void printValue(std::ostream& os) const override ;
117 void printExtras(std::ostream& os) const override ;
118 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
119 Int_t defaultPrintContents(Option_t* opt) const override ;
120
121
122 std::string format(const RooCmdArg& formatArg) const ;
123 std::string format(Int_t sigDigits, const char *options) const ;
124
125 static void printScientific(bool flag=false) ;
126 static void printSigDigits(Int_t ndig=5) ;
127
128 using RooAbsRealLValue::operator= ;
129
131
132 void copyCacheFast(const RooRealVar& other, bool setValDirty=true) { _value = other._value ; if (setValDirty) setValueDirty() ; }
133
134 static void cleanup() ;
135
136 protected:
137
138 static bool _printScientific ;
140
141 void setValFast(double value) override { _value = value ; setValueDirty() ; }
142
143
144 double evaluate() const override { return _value ; } // dummy because we overloaded getVal()
145 void copyCache(const RooAbsArg* source, bool valueOnly=false, bool setValDirty=true) override ;
146 void attachToTree(TTree& t, Int_t bufSize=32000) override ;
148 void fillTreeBranch(TTree& t) override ;
149
150 double _error; ///< Symmetric error associated with current value
151 double _asymErrLo ; ///< Low side of asymmetric error associated with current value
152 double _asymErrHi ; ///< High side of asymmetric error associated with current value
153 std::unique_ptr<RooAbsBinning> _binning;
154 std::unordered_map<std::string,std::unique_ptr<RooAbsBinning>> _altNonSharedBinning ; ///<! Non-shareable alternative binnings
155
156 std::shared_ptr<RooRealVarSharedProperties> sharedProp() const;
157 void installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop);
158
159 void setExpensiveObjectCache(RooExpensiveObjectCache&) override { ; } ///< variables don't need caches
160 static RooRealVarSharedProperties& _nullProp(); ///< Null property
161
162 using SharedPropertiesMap = std::map<RooSharedProperties::UUID,std::weak_ptr<RooRealVarSharedProperties>>;
163
164 static SharedPropertiesMap* sharedPropList(); ///< List of properties shared among clones of a variable
165
166 std::shared_ptr<RooRealVarSharedProperties> _sharedProp; ///<! Shared binnings associated with this instance
167
168 std::size_t _valueResetCounter = 0; ///<! How many times the value of this variable was reset
169
170 static bool &isSilentClippingEnabled();
171
172 ClassDefOverride(RooRealVar,10); // Real-valued variable
173};
174
175#endif
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
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
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
char name[80]
Definition TGX11.cxx:110
#define hi
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
RooRefArray _proxyList
Definition RooAbsArg.h:569
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:425
RefCountList_t _serverList
Definition RooAbsArg.h:564
Abstract base class for RooRealVar binning definitions.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
double _value
Cache for current value of object.
Definition RooAbsReal.h:539
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
Auxiliary class that represents the error of a RooRealVar as a separate object.
Definition RooErrorVar.h:28
Singleton class that serves as repository for objects that are expensive to calculate.
Implementation of RooSharedProperties that stores the properties of a RooRealVar that are shared amon...
Variable that can be changed from the outside.
Definition RooRealVar.h:37
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 removeMin(const char *name=nullptr)
Remove lower range limit for binning with given name. Empty name means default range.
void setVal(double value) override
Set value of variable to 'value'.
double _error
Symmetric error associated with current value.
Definition RooRealVar.h:150
TObject * clone(const char *newname=nullptr) const override
Definition RooRealVar.h:48
void removeRange(const char *name=nullptr)
Remove range limits for binning with given name. Empty name means default range.
static void printSigDigits(Int_t ndig=5)
Set number of digits to show when printing RooRealVars.
void setError(double value)
Definition RooRealVar.h:61
std::unordered_map< std::string, std::unique_ptr< RooAbsBinning > > _altNonSharedBinning
! Non-shareable alternative binnings
Definition RooRealVar.h:154
static RooRealVarSharedProperties & _nullProp()
Null property.
double getErrorLo() const
Definition RooRealVar.h:68
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::map< RooSharedProperties::UUID, std::weak_ptr< RooRealVarSharedProperties > > SharedPropertiesMap
Definition RooRealVar.h:162
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:144
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:141
void setMax(double value)
Definition RooRealVar.h:79
void printValue(std::ostream &os) const override
Print value of variable.
void printExtras(std::ostream &os) const override
Print extras of variable: (asymmetric) error, constant flag, limits and binning.
std::unique_ptr< RooAbsBinning > _binning
Definition RooRealVar.h:153
void setMin(const char *name, double value)
Set minimum of name range to given value.
bool hasBinning(const char *name) const override
Returns true if variable has a binning named 'name'.
double _asymErrLo
Low side of asymmetric error associated with current value.
Definition RooRealVar.h:151
void installSharedProp(std::shared_ptr< RooRealVarSharedProperties > &&prop)
Install the shared property into the member _sharedProp.
static bool _printScientific
Definition RooRealVar.h:138
bool isFundamental() const override
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition RooRealVar.h:107
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
! Shared binnings associated with this instance
Definition RooRealVar.h:166
void removeAsymError()
Definition RooRealVar.h:66
void setAsymError(double lo, double hi)
Definition RooRealVar.h:67
double getError() const
Definition RooRealVar.h:59
static bool & isSilentClippingEnabled()
double getValV(const RooArgSet *nset=nullptr) const override
Return value of variable.
std::list< std::string > getBinningNames() const override
Get a list of all binning names.
void setExpensiveObjectCache(RooExpensiveObjectCache &) override
variables don't need caches
Definition RooRealVar.h:159
double getErrorHi() const
Definition RooRealVar.h:69
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Detailed printing interface.
std::size_t _valueResetCounter
! How many times the value of this variable was reset
Definition RooRealVar.h:168
~RooRealVar() override
Destructor.
double _asymErrHi
High side of asymmetric error associated with current value.
Definition RooRealVar.h:152
static Int_t _printSigDigits
Definition RooRealVar.h:139
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const override
Return binning definition with name.
static void cleanup()
Explicitly deletes the shared properties list on exit to avoid problems with the initialization order...
Int_t defaultPrintContents(Option_t *opt) const override
Mapping of Print() option string to RooPrintable contents specifications.
void setRange(RooAbsReal &min, RooAbsReal &max)
Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&,...
Definition RooRealVar.h:83
void setBinning(const RooAbsBinning &binning, const char *name=nullptr)
Add given binning under name 'name' with this variable.
bool hasError(bool allowZero=true) const
Definition RooRealVar.h:60
static SharedPropertiesMap * sharedPropList()
List of properties shared among clones of a variable.
void deleteSharedProperties()
Stop sharing properties.
static void enableSilentClipping(bool flag=true)
Enable or disable the silent clipping behavior of RooRealVar::setVal() that was the default in ROOT v...
std::size_t valueResetCounter() const
Returns how many times the value of this RooRealVar was reset.
Definition RooRealVar.h:55
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to given stream.
bool hasAsymError(bool allowZero=true) const
Definition RooRealVar.h:65
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from given stream.
double getAsymErrorHi() const
Definition RooRealVar.h:64
void setRange(const char *name, double min, double max)
Set a fit or plotting range.
void setBins(Int_t nBins, const char *name=nullptr)
Create a uniform binning under name 'name' for this variable.
RooRealVar()
Default constructor.
void removeError()
Definition RooRealVar.h:62
void removeMax(const char *name=nullptr)
Remove upper range limit for binning with given name. Empty name means default range.
void setMax(const char *name, double value)
Set maximum of name range to given value.
void copyCacheFast(const RooRealVar &other, bool setValDirty=true)
Definition RooRealVar.h:132
void setMin(double value)
Definition RooRealVar.h:78
double getAsymErrorLo() const
Definition RooRealVar.h:63
bool isDerived() const override
Does value or shape of this arg depend on any other arg?
Definition RooRealVar.h:110
void setRange(double min, double max)
Set the limits of the default range.
Definition RooRealVar.h:81
Uses std::vector to store data columns.
Int_t GetEntries() const override
Return the number of objects in array (i.e.
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:138
A TTree represents a columnar dataset.
Definition TTree.h:89