Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsRealLValue.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooAbsRealLValue.h,v 1.37 2007/07/13 21:50:24 wouter 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_ABS_REAL_LVALUE
17#define ROO_ABS_REAL_LVALUE
18
19#include <cmath>
20#include <cfloat>
21#include <utility>
22#include "TString.h"
23
24#include "RooAbsReal.h"
25#include "RooNumber.h"
26#include "RooAbsLValue.h"
27#include "RooAbsBinning.h"
28
29class RooArgSet ;
30
32public:
33 // Constructors, assignment etc.
34 inline RooAbsRealLValue() { }
35 RooAbsRealLValue(const char *name, const char *title, const char *unit= "") ;
36 RooAbsRealLValue(const RooAbsRealLValue& other, const char* name=nullptr);
37 ~RooAbsRealLValue() override;
38
39 // Parameter value and error accessors
40 /// Set the current value of the object. Needs to be overridden by implementations.
41 virtual void setVal(double value)=0;
42 /// Set the current value of the object. The rangeName is ignored.
43 /// Can be overridden by derived classes to e.g. check if the value fits in the given range.
44 virtual void setVal(double value, const char* /*rangeName*/) {
45 return setVal(value) ;
46 }
47 virtual RooAbsArg& operator=(double newValue);
48
49 // Implementation of RooAbsLValue
50 void setBin(Int_t ibin, const char* rangeName=nullptr) override ;
51 Int_t getBin(const char* rangeName=nullptr) const override { return getBinning(rangeName).binNumber(getVal()) ; }
52 Int_t numBins(const char* rangeName=nullptr) const override { return getBins(rangeName) ; }
53 double getBinWidth(Int_t i, const char* rangeName=nullptr) const override { return getBinning(rangeName).binWidth(i) ; }
54 double volume(const char* rangeName) const override { return getMax(rangeName)-getMin(rangeName) ; }
55 void randomize(const char* rangeName=nullptr) override;
56
57 const RooAbsBinning* getBinningPtr(const char* rangeName) const override { return &getBinning(rangeName) ; }
58 Int_t getBin(const RooAbsBinning* ptr) const override { return ptr->binNumber(getVal()) ; }
59
60 virtual void setBin(Int_t ibin, const RooAbsBinning& binning) ;
61 virtual Int_t getBin(const RooAbsBinning& binning) const { return binning.binNumber(getVal()) ; }
62 virtual Int_t numBins(const RooAbsBinning& binning) const { return binning.numBins() ; }
63 virtual double getBinWidth(Int_t i, const RooAbsBinning& binning) const { return binning.binWidth(i) ; }
64 virtual double volume(const RooAbsBinning& binning) const { return binning.highBound() - binning.lowBound() ; }
65 virtual void randomize(const RooAbsBinning& binning) ;
66
67
68 // Get fit range limits
69
70 /// Retrive binning configuration with given name or default binning.
71 virtual const RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) const = 0 ;
72 /// Retrive binning configuration with given name or default binning.
73 virtual RooAbsBinning& getBinning(const char* name=nullptr, bool verbose=true, bool createOnTheFly=false) = 0 ;
74 /// Check if binning with given name has been defined.
75 virtual bool hasBinning(const char* name) const = 0 ;
76 bool inRange(const char* name) const override ;
77 /// Get number of bins of currently defined range.
78 /// \param name Optionally, request number of bins for range with given name.
79 virtual Int_t getBins(const char* name=nullptr) const { return getBinning(name).numBins(); }
80 /// Get minimum of currently defined range.
81 /// \param name Optionally, request minimum of range with given name.
82 virtual double getMin(const char* name=nullptr) const { return getBinning(name).lowBound(); }
83 /// Get maximum of currently defined range.
84 /// \param name Optionally, request maximum of range with given name.
85 virtual double getMax(const char* name=nullptr) const { return getBinning(name).highBound(); }
86 /// Get low and high bound of the variable.
87 /// \param name Optional range name. If not given, the default range will be used.
88 /// \return A pair with [lowerBound, upperBound]
89 std::pair<double, double> getRange(const char* name = nullptr) const {
90 const auto& binning = getBinning(name);
91 return {binning.lowBound(), binning.highBound()};
92 }
93 /// Check if variable has a lower bound.
94 inline bool hasMin(const char* name=nullptr) const { return !RooNumber::isInfinite(getMin(name)); }
95 /// Check if variable has an upper bound.
96 inline bool hasMax(const char* name=nullptr) const { return !RooNumber::isInfinite(getMax(name)); }
97 /// Check if variable has a binning with given name.
98 bool hasRange(const char* name) const override { return hasBinning(name) ; }
99
100 // Jacobian term management
101 virtual bool isJacobianOK(const RooArgSet& depList) const ;
102 virtual double jacobian() const { return 1 ; }
103
104 inline bool isLValue() const override { return true; }
105
106 // Test a value against our fit range
107 bool inRange(double value, const char* rangeName, double* clippedValue=nullptr) const;
108 void inRange(std::span<const double> values, std::string const& rangeName, std::vector<bool>& out) const;
109 bool isValidReal(double value, bool printError=false) const override ;
110
111 // Constant and Projected flags
112 inline void setConstant(bool value= true) { setAttribute("Constant",value); setValueDirty() ; setShapeDirty() ; }
113
114 // I/O streaming interface (machine readable)
115 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
116 void writeToStream(std::ostream& os, bool compact) const override ;
117
118 // Printing interface (human readable)
119 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
120
121
122 // Build 1-dimensional plots
123 RooPlot* frame(const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg::none(),
124 const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(), const RooCmdArg& arg5=RooCmdArg::none(),
125 const RooCmdArg& arg6=RooCmdArg::none(), const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) const ;
126 RooPlot *frame(const RooLinkedList& cmdList) const ;
127 RooPlot *frame(double lo, double hi, Int_t nbins) const;
128 RooPlot *frame(double lo, double hi) const;
129 RooPlot *frame(Int_t nbins) const;
130 RooPlot *frame() const;
131
132 // Create empty 1,2, and 3D histograms from a list of 1-3 RooAbsReals
133 TH1 *createHistogram(const char *name,
134 const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
135 const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
136 const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
137 const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) const ;
138 TH1 *createHistogram(const char *name, const RooLinkedList& cmdList) const ;
139
140 TH1F *createHistogram(const char *name, const char *yAxisLabel) const ;
141 TH1F *createHistogram(const char *name, const char *yAxisLabel, double xlo, double xhi, Int_t nBins) const ;
142 TH1F *createHistogram(const char *name, const char *yAxisLabel, const RooAbsBinning& bins) const ;
143
144 TH2F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const char *zAxisLabel=nullptr,
145 double* xlo=nullptr, double* xhi=nullptr, Int_t* nBins=nullptr) const ;
146 TH2F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const char *zAxisLabel, const RooAbsBinning** bins) const ;
147
148
149 TH3F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const RooAbsRealLValue &zvar,
150 const char *tAxisLabel, double* xlo=nullptr, double* xhi=nullptr, Int_t* nBins=nullptr) const ;
151 TH3F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const RooAbsRealLValue &zvar, const char* tAxisLabel, const RooAbsBinning** bins) const ;
152
153 static TH1* createHistogram(const char *name, RooArgList &vars, const char *tAxisLabel, double* xlo, double* xhi, Int_t* nBins) ;
154 static TH1* createHistogram(const char *name, RooArgList &vars, const char *tAxisLabel, const RooAbsBinning** bins) ;
155
156 RooFit::OwningPtr<RooAbsReal> createIntegral(const RooArgSet& iset, const RooArgSet* nset=nullptr, const RooNumIntConfig* cfg=nullptr, const char* rangeName=nullptr) const override;
157
158protected:
159
160 virtual void setValFast(double value) { setVal(value) ; }
161
162 bool fitRangeOKForPlotting() const ;
163 void copyCache(const RooAbsArg* source, bool valueOnly=false, bool setValDirty=true) override ;
164
165 ClassDefOverride(RooAbsRealLValue,1) // Abstract modifiable real-valued object
166};
167
168#endif
#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 value
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
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition RooAbsArg.h:492
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:487
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
int binNumber(double x) const
Returns the bin number corresponding to the value x.
Int_t numBins() const
Return number of bins.
virtual double highBound() const =0
virtual double lowBound() const =0
virtual double binWidth(Int_t bin) const =0
Abstract base class for objects that are lvalues, i.e.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
bool isLValue() const override
Is this argument an l-value, i.e., can it appear on the left-hand side of an assignment expression?...
Int_t numBins(const char *rangeName=nullptr) const override
Int_t getBin(const RooAbsBinning *ptr) const override
virtual Int_t getBins(const char *name=nullptr) const
Get number of bins of currently defined range.
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooArgSet *nset=nullptr, const RooNumIntConfig *cfg=nullptr, const char *rangeName=nullptr) const override
Create an object that represents the integral of the function over one or more observables std::liste...
virtual void setValFast(double value)
virtual void setVal(double value, const char *)
Set the current value of the object.
bool isValidReal(double value, bool printError=false) const override
Check if given value is valid.
void setConstant(bool value=true)
virtual double jacobian() const
virtual const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const =0
Retrive binning configuration with given name or default binning.
virtual bool isJacobianOK(const RooArgSet &depList) const
virtual double volume(const RooAbsBinning &binning) const
Int_t getBin(const char *rangeName=nullptr) const override
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
RooPlot * frame() const
Create a new RooPlot on the heap with a drawing frame initialized for this object,...
bool hasMax(const char *name=nullptr) const
Check if variable has an upper bound.
void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true) override
Copy cache of another RooAbsArg to our cache.
bool fitRangeOKForPlotting() const
Check if fit range is usable as plot range, i.e.
void setBin(Int_t ibin, const char *rangeName=nullptr) override
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
double getBinWidth(Int_t i, const char *rangeName=nullptr) const override
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to given stream.
void randomize(const char *rangeName=nullptr) override
Set a new value sampled from a uniform distribution over the fit range.
virtual void setVal(double value)=0
Set the current value of the object. Needs to be overridden by implementations.
virtual bool hasBinning(const char *name) const =0
Check if binning with given name has been defined.
double volume(const char *rangeName) const override
virtual Int_t getBin(const RooAbsBinning &binning) const
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from given stream.
~RooAbsRealLValue() override
Destructor.
bool inRange(const char *name) const override
Check if current value is inside range with given name.
const RooAbsBinning * getBinningPtr(const char *rangeName) const override
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Structure printing.
virtual RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false)=0
Retrive binning configuration with given name or default binning.
bool hasRange(const char *name) const override
Check if variable has a binning with given name.
std::pair< double, double > getRange(const char *name=nullptr) const
Get low and high bound of the variable.
virtual double getBinWidth(Int_t i, const RooAbsBinning &binning) const
virtual RooAbsArg & operator=(double newValue)
Assignment operator from a double.
virtual Int_t numBins(const RooAbsBinning &binning) const
TH1 * createHistogram(const char *name, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
bool hasMin(const char *name=nullptr) const
Check if variable has a lower bound.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
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
static const RooCmdArg & none()
Return reference to null argument.
Definition RooCmdArg.cxx:51
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
static constexpr int isInfinite(double x)
Return true if x is infinite by RooNumber internal specification.
Definition RooNumber.h:34
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:577
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:257
3-D histogram with a float per channel (see TH1 documentation)}
Definition TH3.h:268
Basic string class.
Definition TString.h:139
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:43