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 ;
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=nullptr);
51 TObject* clone(const char* newname) const override { return new RooRealVar(*this,newname); }
52 ~RooRealVar() override;
53
54 // Parameter value and error accessors
55 double getValV(const RooArgSet* nset=nullptr) const override ;
56 RooSpan<const double> getValues(RooBatchCompute::RunContext& inputData, const RooArgSet* = nullptr) const final;
57
58 /// Returns how many times the value of this RooRealVar was reset.
59 std::size_t valueResetCounter() const { return _valueResetCounter; }
60 void setVal(double value) override;
61 void setVal(double value, const char* rangeName) override;
62 inline double getError() const { return _error>=0?_error:0. ; }
63 inline bool hasError(bool allowZero=true) const { return allowZero ? (_error>=0) : (_error>0) ; }
64 inline void setError(double value) { _error= value ; }
65 inline void removeError() { _error = -1 ; }
66 inline double getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
67 inline double getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
68 inline bool hasAsymError(bool allowZero=true) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
69 inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
70 inline void setAsymError(double lo, double hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
71 inline double getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
72 inline double getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
73
74 RooErrorVar* errorVar() const ;
75
76 // Set/get finite fit range limits
77 void setMin(const char* name, double value) ;
78 void setMax(const char* name, double value) ;
79 void setRange(const char* name, double min, double max) ;
80 void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
81 inline void setMin(double value) { setMin(nullptr,value) ; }
82 inline void setMax(double value) { setMax(nullptr,value) ; }
83 /// Set the limits of the default range.
84 inline void setRange(double min, double max) { setRange(nullptr,min,max) ; }
85 /// Set parameterised limits of the default range. See setRange(const char*, RooAbsReal&, RooAbsReal&).
86 inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(nullptr,min,max) ; }
87
88 void setBins(Int_t nBins, const char* name=nullptr);
89 void setBinning(const RooAbsBinning& binning, const char* name=nullptr) ;
90
91 // RooAbsRealLValue implementation
92 bool hasBinning(const char* name) const override ;
93 const RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) const override ;
94 RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) override ;
95 std::list<std::string> getBinningNames() const override ;
96
97 // Set infinite fit range limits
98 /// Remove lower range limit for binning with given name. Empty name means default range.
99 void removeMin(const char* name=nullptr);
100 /// Remove upper range limit for binning with given name. Empty name means default range.
101 void removeMax(const char* name=nullptr);
102 /// Remove range limits for binning with given name. Empty name means default range.
103 void removeRange(const char* name=nullptr);
104
105 // I/O streaming interface (machine readable)
106 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
107 void writeToStream(std::ostream& os, bool compact) const override ;
108
109 // We implement a fundamental type of AbsArg that can be stored in a dataset
110 inline bool isFundamental() const override { return true; }
111
112 // Force to be a leaf-node of any expression tree, even if we have (shape) servers
113 bool isDerived() const override {
114 // Does value or shape of this arg depend on any other arg?
115 return !_serverList.empty() || _proxyList.GetEntries()>0;
116 }
117
118 // Printing interface (human readable)
119 void printValue(std::ostream& os) const override ;
120 void printExtras(std::ostream& os) const override ;
121 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
122 Int_t defaultPrintContents(Option_t* opt) const override ;
123
124
125 TString* format(const RooCmdArg& formatArg) const ;
126 TString* format(Int_t sigDigits, const char *options) const ;
127
128 static void printScientific(bool flag=false) ;
129 static void printSigDigits(Int_t ndig=5) ;
130
131 using RooAbsRealLValue::operator= ;
132
134
135 void copyCacheFast(const RooRealVar& other, bool setValDirty=true) { _value = other._value ; if (setValDirty) setValueDirty() ; }
136
137 static void cleanup() ;
138
139 protected:
140
141 static bool _printScientific ;
143
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 std::size_t _valueResetCounter = 0; ///<! How many times the value of this variable was reset
174
175 ClassDefOverride(RooRealVar,9); // Real-valued variable
176};
177
178#endif
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
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
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:74
RooRefArray _proxyList
Definition RooAbsArg.h:634
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:487
RefCountList_t _serverList
Definition RooAbsArg.h:629
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:62
double _value
Cache for current value of object.
Definition RooAbsReal.h:509
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
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
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:155
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.
RooSpan< const double > getValues(RooBatchCompute::RunContext &inputData, const RooArgSet *=nullptr) const final
Retrieve data column of this variable.
void setError(double value)
Definition RooRealVar.h:64
std::unordered_map< std::string, std::unique_ptr< RooAbsBinning > > _altNonSharedBinning
! Non-shareable alternative binnings
Definition RooRealVar.h:159
static RooRealVarSharedProperties & _nullProp()
Null property.
double getErrorLo() const
Definition RooRealVar.h:71
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 setMax(double value)
Definition RooRealVar.h:82
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:158
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:156
void installSharedProp(std::shared_ptr< RooRealVarSharedProperties > &&prop)
Install the shared property into the member _sharedProp.
static bool _printScientific
Definition RooRealVar.h:141
bool isFundamental() const override
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition RooRealVar.h:110
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
! Shared binnings associated with this instance
Definition RooRealVar.h:171
void removeAsymError()
Definition RooRealVar.h:69
void setAsymError(double lo, double hi)
Definition RooRealVar.h:70
double getError() const
Definition RooRealVar.h:62
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:164
double getErrorHi() const
Definition RooRealVar.h:72
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:173
~RooRealVar() override
Destructor.
double _asymErrHi
High side of asymmetric error associated with current value.
Definition RooRealVar.h:157
static Int_t _printSigDigits
Definition RooRealVar.h:142
TObject * clone(const char *newname) const override
Definition RooRealVar.h:51
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const override
Return binning definition with name.
static void cleanup()
Explicitely deletes the shared properties list on exit to avoid problems with the initialization orde...
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:86
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:63
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:59
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:167
bool hasAsymError(bool allowZero=true) const
Definition RooRealVar.h:68
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:67
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:65
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:135
void setMin(double value)
Definition RooRealVar.h:81
double getAsymErrorLo() const
Definition RooRealVar.h:66
bool isDerived() const override
Does value or shape of this arg depend on any other arg?
Definition RooRealVar.h:113
void setRange(double min, double max)
Set the limits of the default range.
Definition RooRealVar.h:84
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.
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
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