Logo ROOT  
Reference Guide
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=0);
38 ~RooAbsRealLValue() override;
39
40 // Parameter value and error accessors
41 /// Set the current value of the object. Needs to be overridden by implementations.
42 virtual void setVal(double value)=0;
43 /// Set the current value of the object. The rangeName is ignored.
44 /// Can be overridden by derived classes to e.g. check if the value fits in the given range.
45 virtual void setVal(double value, const char* /*rangeName*/) {
46 return setVal(value) ;
47 }
48 virtual RooAbsArg& operator=(const RooAbsReal& other) ;
49 virtual RooAbsArg& operator=(double newValue);
50
51 // Implementation of RooAbsLValue
52 void setBin(Int_t ibin, const char* rangeName=0) override ;
53 Int_t getBin(const char* rangeName=0) const override { return getBinning(rangeName).binNumber(getVal()) ; }
54 Int_t numBins(const char* rangeName=0) const override { return getBins(rangeName) ; }
55 double getBinWidth(Int_t i, const char* rangeName=0) const override { return getBinning(rangeName).binWidth(i) ; }
56 double volume(const char* rangeName) const override { return getMax(rangeName)-getMin(rangeName) ; }
57 void randomize(const char* rangeName=0) override;
58
59 const RooAbsBinning* getBinningPtr(const char* rangeName) const override { return &getBinning(rangeName) ; }
60 Int_t getBin(const RooAbsBinning* ptr) const override { return ptr->binNumber(getVal()) ; }
61
62 virtual void setBin(Int_t ibin, const RooAbsBinning& binning) ;
63 virtual Int_t getBin(const RooAbsBinning& binning) const { return binning.binNumber(getVal()) ; }
64 virtual Int_t numBins(const RooAbsBinning& binning) const { return binning.numBins() ; }
65 virtual double getBinWidth(Int_t i, const RooAbsBinning& binning) const { return binning.binWidth(i) ; }
66 virtual double volume(const RooAbsBinning& binning) const { return binning.highBound() - binning.lowBound() ; }
67 virtual void randomize(const RooAbsBinning& binning) ;
68
69
70 virtual void setBinFast(Int_t ibin, const RooAbsBinning& binning) ;
71
72 // Get fit range limits
73
74 /// Retrive binning configuration with given name or default binning.
75 virtual const RooAbsBinning& getBinning(const char* name=0, bool verbose=true, bool createOnTheFly=false) const = 0 ;
76 /// Retrive binning configuration with given name or default binning.
77 virtual RooAbsBinning& getBinning(const char* name=0, bool verbose=true, bool createOnTheFly=false) = 0 ;
78 /// Check if binning with given name has been defined.
79 virtual bool hasBinning(const char* name) const = 0 ;
80 bool inRange(const char* name) const override ;
81 /// Get number of bins of currently defined range.
82 /// \param name Optionally, request number of bins for range with given name.
83 virtual Int_t getBins(const char* name=0) const { return getBinning(name).numBins(); }
84 /// Get minimum of currently defined range.
85 /// \param name Optionally, request minimum of range with given name.
86 virtual double getMin(const char* name=0) const { return getBinning(name).lowBound(); }
87 /// Get maximum of currently defined range.
88 /// \param name Optionally, request maximum of range with given name.
89 virtual double getMax(const char* name=0) const { return getBinning(name).highBound(); }
90 /// Get low and high bound of the variable.
91 /// \param name Optional range name. If not given, the default range will be used.
92 /// \return A pair with [lowerBound, upperBound]
93 std::pair<double, double> getRange(const char* name = 0) const {
94 const auto& binning = getBinning(name);
95 return {binning.lowBound(), binning.highBound()};
96 }
97 /// Check if variable has a lower bound.
98 inline bool hasMin(const char* name=0) const { return !RooNumber::isInfinite(getMin(name)); }
99 /// Check if variable has an upper bound.
100 inline bool hasMax(const char* name=0) const { return !RooNumber::isInfinite(getMax(name)); }
101 /// Check if variable has a binning with given name.
102 bool hasRange(const char* name) const override { return hasBinning(name) ; }
103
104 // Jacobian term management
105 virtual bool isJacobianOK(const RooArgSet& depList) const ;
106 virtual double jacobian() const { return 1 ; }
107
108 inline bool isLValue() const override { return true; }
109
110 // Test a value against our fit range
111 bool inRange(double value, const char* rangeName, double* clippedValue=0) const;
112 void inRange(std::span<const double> values, std::string const& rangeName, std::vector<bool>& out) const;
113 bool isValidReal(double value, bool printError=false) const override ;
114
115 // Constant and Projected flags
116 inline void setConstant(bool value= true) { setAttribute("Constant",value); setValueDirty() ; setShapeDirty() ; }
117
118 // I/O streaming interface (machine readable)
119 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
120 void writeToStream(std::ostream& os, bool compact) const override ;
121
122 // Printing interface (human readable)
123 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
124
125
126 // Build 1-dimensional plots
127 RooPlot* frame(const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg::none(),
128 const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(), const RooCmdArg& arg5=RooCmdArg::none(),
129 const RooCmdArg& arg6=RooCmdArg::none(), const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) const ;
130 RooPlot *frame(const RooLinkedList& cmdList) const ;
131 RooPlot *frame(double lo, double hi, Int_t nbins) const;
132 RooPlot *frame(double lo, double hi) const;
133 RooPlot *frame(Int_t nbins) const;
134 RooPlot *frame() const;
135
136 // Create empty 1,2, and 3D histograms from a list of 1-3 RooAbsReals
137 TH1 *createHistogram(const char *name,
138 const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
139 const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
140 const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
141 const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) const ;
142 TH1 *createHistogram(const char *name, const RooLinkedList& cmdList) const ;
143
144 TH1F *createHistogram(const char *name, const char *yAxisLabel) const ;
145 TH1F *createHistogram(const char *name, const char *yAxisLabel, double xlo, double xhi, Int_t nBins) const ;
146 TH1F *createHistogram(const char *name, const char *yAxisLabel, const RooAbsBinning& bins) const ;
147
148 TH2F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const char *zAxisLabel=0,
149 double* xlo=0, double* xhi=0, Int_t* nBins=0) const ;
150 TH2F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const char *zAxisLabel, const RooAbsBinning** bins) const ;
151
152
153 TH3F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const RooAbsRealLValue &zvar,
154 const char *tAxisLabel, double* xlo=0, double* xhi=0, Int_t* nBins=0) const ;
155 TH3F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const RooAbsRealLValue &zvar, const char* tAxisLabel, const RooAbsBinning** bins) const ;
156
157 static TH1* createHistogram(const char *name, RooArgList &vars, const char *tAxisLabel, double* xlo, double* xhi, Int_t* nBins) ;
158 static TH1* createHistogram(const char *name, RooArgList &vars, const char *tAxisLabel, const RooAbsBinning** bins) ;
159
160protected:
161
162 virtual void setValFast(double value) { setVal(value) ; }
163
164 bool fitRangeOKForPlotting() const ;
165 void copyCache(const RooAbsArg* source, bool valueOnly=false, bool setValDirty=true) override ;
166
167 ClassDefOverride(RooAbsRealLValue,1) // Abstract modifiable real-valued object
168};
169
170#endif
#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 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
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition: RooAbsArg.h:513
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:508
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:278
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
Definition: RooAbsBinning.h:26
Int_t numBins() const
Return number of bins.
Definition: RooAbsBinning.h:38
virtual double highBound() const =0
virtual double lowBound() const =0
virtual Int_t binNumber(double x) const =0
virtual double binWidth(Int_t bin) const =0
Abstract base class for objects that are lvalues, i.e.
Definition: RooAbsLValue.h:26
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual double getMax(const char *name=0) const
Get maximum of currently defined range.
bool isLValue() const override
Is this argument an l-value, i.e., can it appear on the left-hand side of an assignment expression?...
virtual RooAbsBinning & getBinning(const char *name=0, bool verbose=true, bool createOnTheFly=false)=0
Retrive binning configuration with given name or default binning.
Int_t getBin(const RooAbsBinning *ptr) const override
void randomize(const char *rangeName=0) override
Set a new value sampled from a uniform distribution over the fit range.
bool hasMax(const char *name=0) const
Check if variable has an upper bound.
virtual void setValFast(double value)
virtual void setVal(double value, const char *)
Set the current value of the object.
bool hasMin(const char *name=0) const
Check if variable has a lower bound.
bool isValidReal(double value, bool printError=false) const override
Check if given value is valid.
std::pair< double, double > getRange(const char *name=0) const
Get low and high bound of the variable.
void setConstant(bool value=true)
void setBin(Int_t ibin, const char *rangeName=0) override
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
virtual double jacobian() const
virtual const RooAbsBinning & getBinning(const char *name=0, 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
RooPlot * frame() const
Create a new RooPlot on the heap with a drawing frame initialized for this object,...
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 writeToStream(std::ostream &os, bool compact) const override
Write object contents to given stream.
virtual void setVal(double value)=0
Set the current value of the object. Needs to be overridden by implementations.
virtual double getMin(const char *name=0) const
Get minimum of currently defined range.
double getBinWidth(Int_t i, const char *rangeName=0) const override
virtual bool hasBinning(const char *name) const =0
Check if binning with given name has been defined.
Int_t getBin(const char *rangeName=0) const override
double volume(const char *rangeName) const override
virtual Int_t getBin(const RooAbsBinning &binning) const
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from given stream.
~RooAbsRealLValue() override
Destructor.
Int_t numBins(const char *rangeName=0) const override
virtual Int_t getBins(const char *name=0) const
Get number of bins of currently defined range.
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.
RooAbsRealLValue & operator=(const RooAbsRealLValue &)=default
bool hasRange(const char *name) const override
Check if variable has a binning with given name.
virtual double getBinWidth(Int_t i, const RooAbsBinning &binning) const
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
virtual void setBinFast(Int_t ibin, const RooAbsBinning &binning)
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:64
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:94
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:57
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 ...
Definition: RooLinkedList.h:38
static Int_t isInfinite(double x)
Return true if x is infinite by RooNumBer internal specification.
Definition: RooNumber.cxx:57
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:574
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:273
Basic string class.
Definition: TString.h:136