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) 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 inline double getError() const { return _error>=0?_error:0. ; }
59 inline bool hasError(bool allowZero=true) const { return allowZero ? (_error>=0) : (_error>0) ; }
60 inline void setError(double value) { _error= value ; }
61 inline void removeError() { _error = -1 ; }
62 inline double getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
63 inline double getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
64 inline bool hasAsymError(bool allowZero=true) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
65 inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
66 inline void setAsymError(double lo, double hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
67 inline double getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
68 inline double getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
69
70 RooErrorVar* errorVar() const ;
71
72 // Set/get finite fit range limits
73 void setMin(const char* name, double value) ;
74 void setMax(const char* name, double value) ;
75 void setRange(const char* name, double min, double max) ;
76 void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
77 inline void setMin(double value) { setMin(nullptr,value) ; }
78 inline void setMax(double value) { setMax(nullptr,value) ; }
79 /// Set the limits of the default range.
80 inline void setRange(double min, double max) { setRange(nullptr,min,max) ; }
81 /// Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&, RooAbsReal&).
82 inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(nullptr,min,max) ; }
83
84 void setBins(Int_t nBins, const char* name=nullptr);
85 void setBinning(const RooAbsBinning& binning, const char* name=nullptr) ;
86
87 // RooAbsRealLValue implementation
88 bool hasBinning(const char* name) const override ;
89 const RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) const override ;
90 RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) override ;
91 std::list<std::string> getBinningNames() const override ;
92
93 // Set infinite fit range limits
94 /// Remove lower range limit for binning with given name. Empty name means default range.
95 void removeMin(const char* name=nullptr);
96 /// Remove upper range limit for binning with given name. Empty name means default range.
97 void removeMax(const char* name=nullptr);
98 /// Remove range limits for binning with given name. Empty name means default range.
99 void removeRange(const char* name=nullptr);
100
101 // I/O streaming interface (machine readable)
102 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
103 void writeToStream(std::ostream& os, bool compact) const override ;
104
105 // We implement a fundamental type of AbsArg that can be stored in a dataset
106 inline bool isFundamental() const override { return true; }
107
108 // Force to be a leaf-node of any expression tree, even if we have (shape) servers
109 bool isDerived() const override {
110 // Does value or shape of this arg depend on any other arg?
111 return !_serverList.empty() || _proxyList.GetEntries()>0;
112 }
113
114 // Printing interface (human readable)
115 void printValue(std::ostream& os) const override ;
116 void printExtras(std::ostream& os) const override ;
117 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
118 Int_t defaultPrintContents(Option_t* opt) const override ;
119
120
121 TString* format(const RooCmdArg& formatArg) const ;
122 TString* format(Int_t sigDigits, const char *options) const ;
123
124 static void printScientific(bool flag=false) ;
125 static void printSigDigits(Int_t ndig=5) ;
126
127 using RooAbsRealLValue::operator= ;
128
130
131 void copyCacheFast(const RooRealVar& other, bool setValDirty=true) { _value = other._value ; if (setValDirty) setValueDirty() ; }
132
133 static void cleanup() ;
134
135 void translate(RooFit::Detail::CodeSquashContext &ctx) const override;
136
137 protected:
138
139 static bool _printScientific ;
141
142 void setValFast(double value) override { _value = value ; setValueDirty() ; }
143
144
145 double evaluate() const override { return _value ; } // dummy because we overloaded getVal()
146 void copyCache(const RooAbsArg* source, bool valueOnly=false, bool setValDirty=true) override ;
147 void attachToTree(TTree& t, Int_t bufSize=32000) override ;
148 void attachToVStore(RooVectorDataStore& vstore) override ;
149 void fillTreeBranch(TTree& t) override ;
150
151 double chopAt(double what, Int_t where) const ;
152
153 double _error; ///< Symmetric error associated with current value
154 double _asymErrLo ; ///< Low side of asymmetric error associated with current value
155 double _asymErrHi ; ///< High side of asymmetric error associated with current value
156 std::unique_ptr<RooAbsBinning> _binning;
157 std::unordered_map<std::string,std::unique_ptr<RooAbsBinning>> _altNonSharedBinning ; ///<! Non-shareable alternative binnings
158
159 std::shared_ptr<RooRealVarSharedProperties> sharedProp() const;
160 void installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop);
161
162 void setExpensiveObjectCache(RooExpensiveObjectCache&) override { ; } ///< variables don't need caches
163 static RooRealVarSharedProperties& _nullProp(); ///< Null property
164
165 using SharedPropertiesMap = std::map<RooSharedProperties::UUID,std::weak_ptr<RooRealVarSharedProperties>>;
166
167 static SharedPropertiesMap* sharedPropList(); ///< List of properties shared among clones of a variable
168
169 std::shared_ptr<RooRealVarSharedProperties> _sharedProp; ///<! Shared binnings associated with this instance
170
171 std::size_t _valueResetCounter = 0; ///<! How many times the value of this variable was reset
172
173 ClassDefOverride(RooRealVar,10); // Real-valued variable
174};
175
176#endif
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
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:77
RooRefArray _proxyList
Definition RooAbsArg.h:580
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:431
RefCountList_t _serverList
Definition RooAbsArg.h:575
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:59
double _value
Cache for current value of object.
Definition RooAbsReal.h:536
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.
A class to maintain the context for squashing of RooFit models into code.
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:153
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:60
std::unordered_map< std::string, std::unique_ptr< RooAbsBinning > > _altNonSharedBinning
! Non-shareable alternative binnings
Definition RooRealVar.h:157
static RooRealVarSharedProperties & _nullProp()
Null property.
double getErrorLo() const
Definition RooRealVar.h:67
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:145
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:142
void setMax(double value)
Definition RooRealVar.h:78
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:156
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:154
void installSharedProp(std::shared_ptr< RooRealVarSharedProperties > &&prop)
Install the shared property into the member _sharedProp.
static bool _printScientific
Definition RooRealVar.h:139
bool isFundamental() const override
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition RooRealVar.h:106
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
! Shared binnings associated with this instance
Definition RooRealVar.h:169
void removeAsymError()
Definition RooRealVar.h:65
void setAsymError(double lo, double hi)
Definition RooRealVar.h:66
double getError() const
Definition RooRealVar.h:58
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:162
double getErrorHi() const
Definition RooRealVar.h:68
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:171
~RooRealVar() override
Destructor.
double _asymErrHi
High side of asymmetric error associated with current value.
Definition RooRealVar.h:155
static Int_t _printSigDigits
Definition RooRealVar.h:140
TObject * clone(const char *newname) const override
Definition RooRealVar.h:48
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:82
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:59
static SharedPropertiesMap * sharedPropList()
List of properties shared among clones of a variable.
void deleteSharedProperties()
Stop sharing properties.
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.
std::map< RooSharedProperties::UUID, std::weak_ptr< RooRealVarSharedProperties > > SharedPropertiesMap
Definition RooRealVar.h:165
bool hasAsymError(bool allowZero=true) const
Definition RooRealVar.h:64
void translate(RooFit::Detail::CodeSquashContext &ctx) const override
This function defines a translation for each RooAbsReal based object that can be used to express the ...
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 chopAt(double what, Int_t where) const
Utility to calculate number of decimals to show based on magnitude of error.
double getAsymErrorHi() const
Definition RooRealVar.h:63
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:61
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:131
void setMin(double value)
Definition RooRealVar.h:77
double getAsymErrorLo() const
Definition RooRealVar.h:62
bool isDerived() const override
Does value or shape of this arg depend on any other arg?
Definition RooRealVar.h:109
void setRange(double min, double max)
Set the limits of the default range.
Definition RooRealVar.h:80
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:139
A TTree represents a columnar dataset.
Definition TTree.h:79
static const char * what
Definition stlLoader.cc:5