50using std::endl, std::ostream, std::istream;
62 RooSentinel::activate();
65 return staticSharedPropList;
88 static const std::unique_ptr<RooRealVarSharedProperties> nullProp(
new RooRealVarSharedProperties(
"00000000-0000-0000-0000-000000000000"));
105 double value,
const char *unit) :
122 double minValue,
double maxValue,
143 _value= 0.5*(minValue + maxValue);
157 double value,
double minValue,
double maxValue,
166 inRange(value,
nullptr,&clipValue) ;
184 _binning.reset(other._binning->clone());
185 _binning->insertHook(*this) ;
190 std::unique_ptr<RooAbsBinning> abc( item.second->clone() );
191 abc->insertHook(*this) ;
192 _altNonSharedBinning[item.first] = std::move(abc);
232 <<
"Silent clipping of values to range in `RooRealVar::setVal()` enabled." << std::endl;
238 static bool isEnabled =
false;
244inline void throwOutOfRangeError(
RooRealVar const &var,
double value,
const char *rangeName)
246 std::stringstream ss;
247 ss <<
"Value " << value;
249 ss <<
" is outside the range \"" << rangeName <<
"\" ";
251 ss <<
" is outside the default range ";
253 ss <<
"[" << var.
getMin() <<
", " << var.
getMax() <<
"] of the variable \"";
255 ss <<
"\nTo restore the dangerous old behavior of silently clipping the value to the range,"
256 <<
" call `RooRealVar::enableSilentClipping()`.";
257 throw std::invalid_argument(ss.str());
260void printOutOfRangeWarning(
RooRealVar const &var,
double value,
const char *rangeName)
262 std::stringstream ss;
263 ss <<
"Value " << value;
265 ss <<
" is slightly outside the range \"" << rangeName <<
"\" ";
267 ss <<
" is slightly outside the default range ";
269 ss <<
"[" << var.
getMin() <<
", " << var.
getMax() <<
"] of the variable \"";
271 ss <<
"\nThe value will be clipped. To restore the dangerous old behavior of silently clipping the value to the "
273 <<
" call `RooRealVar::enableSilentClipping()`.";
274 oocoutW(&var, InputArguments) << ss.str() << std::endl;
287 bool isInRange =
inRange(value,0,&clipValue) ;
290 if (std::abs(clipValue - value) > std::numeric_limits<double>::epsilon()) {
291 throwOutOfRangeError(*
this, value,
nullptr);
293 printOutOfRangeWarning(*
this, value,
nullptr);
297 if (clipValue !=
_value) {
312 bool isInRange =
inRange(value,rangeName,&clipValue) ;
315 if (std::abs(clipValue - value) > std::numeric_limits<double>::epsilon()) {
316 throwOutOfRangeError(*
this, value, rangeName);
318 printOutOfRangeWarning(*
this, value, rangeName);
322 if (clipValue !=
_value) {
341 title.Append(
" Error") ;
384 if (strchr(
name,
',')) {
385 coutW(InputArguments) <<
"Asking variable " <<
GetName() <<
"for binning '" <<
name
386 <<
"', but comma in binning names is not supported." << std::endl;
392 return *item->second;
397 if (item2 !=
sharedProp()->_altBinning.end()) {
398 return *item2->second;
403 if (!createOnTheFly) {
410 coutI(Eval) <<
"RooRealVar::getBinning(" <<
GetName() <<
") new range named '"
411 <<
name <<
"' created with default bounds" << std::endl ;
428 std::list<std::string> binningNames;
430 binningNames.push_back(
"");
434 binningNames.push_back(item.first);
436 for (
const auto& item :
sharedProp()->_altBinning) {
437 binningNames.push_back(item.first);
449 auto item = sharedProps->_altBinning.find(
name);
450 if (item != sharedProps->_altBinning.end()) {
451 item->second->removeHook(*
this);
452 if (sharedProps->_ownBinnings)
455 sharedProps->_altBinning.erase(item);
459 item2->second->removeHook(*
this);
486 std::unique_ptr<RooAbsBinning> newBinning( binning.
clone() );
493 newBinning->insertHook(*
this) ;
500 newBinning->SetName(
name) ;
501 newBinning->SetTitle(
name) ;
502 newBinning->insertHook(*
this) ;
503 if (newBinning->isShareable() && shared) {
524 coutW(InputArguments) <<
"RooRealVar::setMin(" <<
GetName()
525 <<
"): Proposed new fit min. larger than max., setting min. to max." << std::endl ;
554 coutW(InputArguments) <<
"RooRealVar::setMax(" <<
GetName()
555 <<
"): Proposed new fit max. smaller than min., setting max. to min." << std::endl ;
591 coutW(InputArguments) <<
"RooRealVar::setRange(" <<
GetName()
592 <<
"): Proposed new fit max. smaller than min., setting max. to min." << std::endl ;
600 <<
") new range named '" <<
name <<
"' created with bounds ["
601 << min <<
"," << max <<
"]" << std::endl ;
627 TString errorPrefix(
"RooRealVar::readFromStream(");
635 if (parser.
readDouble(value,verbose))
return true ;
645 bool haveValue(
false) ;
646 bool haveConstant(
false) ;
650 bool reprocessToken = false ;
654 if (!reprocessToken) {
657 reprocessToken = false ;
678 double asymErrLo = 0.;
679 double asymErrHi = 0.;
691 haveConstant = true ;
707 coutW(Eval) <<
"RooRealVar::readFromStream(" <<
GetName()
708 <<
") WARNING: plot range deprecated, removed P(...) token" << std::endl ;
725 coutW(Eval) <<
"RooRealVar::readFromStream(" <<
GetName()
726 <<
") WARNING: F(lo-hi:bins) token deprecated, use L(lo-hi) B(bins)" << std::endl ;
759 if (haveValue)
setVal(value) ;
778 std::stringstream
text;
783 text << std::scientific;
787 text << std::setprecision(nDigitsVal) <<
_value;
789 text << std::setprecision(nDigitsErr) <<
" +/- ";
796 os <<
text.str() <<
" ";
813 os <<
" - " <<
getMax() <<
") ";
819 os <<
"B(" <<
getBins() <<
") ";
824 os <<
"// [" <<
getUnit() <<
"]";
872 os <<
"B(" <<
getBins() <<
") " ;
877 os <<
"// [" <<
getUnit() <<
"]" ;
890 if (opt &&
TString(opt)==
"I") {
903 os <<
indent <<
"--- RooRealVar ---" << std::endl;
924 pc.
defineInt(
"autop",
"FormatArgs::AutoPrecision",0,2) ;
925 pc.
defineInt(
"fixedp",
"FormatArgs::FixedPrecision",0,2) ;
926 pc.
defineInt(
"tlatex",
"FormatArgs::TLatexStyle",0,0) ;
927 pc.
defineInt(
"latex",
"FormatArgs::LatexStyle",0,0) ;
928 pc.
defineInt(
"latext",
"FormatArgs::LatexTableStyle",0,0) ;
929 pc.
defineInt(
"verbn",
"FormatArgs::VerbatimName",0,0) ;
930 pc.
defineMutex(
"FormatArgs::TLatexStyle",
"FormatArgs::LatexStyle",
"FormatArgs::LatexTableStyle") ;
931 pc.
defineMutex(
"FormatArgs::AutoPrecision",
"FormatArgs::FixedPrecision") ;
943 if (pc.
getInt(
"tlatex")) {
945 }
else if (pc.
getInt(
"latex")) {
947 }
else if (pc.
getInt(
"latext")) {
951 if (pc.
getInt(
"verbn")) options +=
"V" ;
952 Int_t sigDigits = 2 ;
955 sigDigits = pc.
getInt(
"autop") ;
956 }
else if (pc.
hasProcessed(
"FormatArgs::FixedPrecision")) {
958 sigDigits = pc.
getInt(
"fixedp") ;
961 return format(sigDigits,options) ;
994 bool showTitle = opts.
Contains(
"t");
998 bool tlatexMode= opts.
Contains(
"l");
1000 bool latexTableMode = opts.
Contains(
"y") ;
1001 bool latexVerbatimName = opts.
Contains(
"v") ;
1009 if (latexTableMode) latexMode = true ;
1010 bool asymError= opts.
Contains(
"a") ;
1013 if(sigDigits < 1) sigDigits= 1;
1014 Int_t leadingDigitVal = 0;
1015 if (useErrorForPrecision) {
1016 leadingDigitVal = (
Int_t)floor(log10(std::abs(
_error+1
e-10)));
1019 leadingDigitVal = (
Int_t)floor(log10(std::abs(
_value+1
e-10)));
1020 if (
_value==0) leadingDigitVal=0 ;
1023 Int_t whereVal= leadingDigitVal - sigDigits + 1;
1024 Int_t whereErr = leadingDigitErr - sigDigits + 1;
1026 if (
_value<0) whereVal -= 1 ;
1027 int nDigitsVal = whereVal < 0 ? -whereVal : 0;
1028 int nDigitsErr = whereErr < 0 ? -whereErr : 0;
1030 std::stringstream
text;
1035 if(showName || showTitle) {
1036 if (latexTableMode && latexVerbatimName) {
1040 if (latexVerbatimName)
1043 if (!latexTableMode) {
1057 text << std::setprecision(nDigitsVal) <<
_value;
1059 text << std::setprecision(nDigitsErr);
1075 else if(latexMode) {
1085 if(!
_unit.IsNull() && showUnit) {
1155 loName.
Append(
"_aerr_lo") ;
1166 hiName.
Append(
"_aerr_hi") ;
1190 coutE(Eval) <<
"RooAbsReal::fillTreeBranch(" <<
GetName() <<
") ERROR: not attached to tree" << std::endl ;
1199 if (errBranch) errBranch->
Fill() ;
1204 loName.
Append(
"_aerr_lo") ;
1206 if (loBranch) loBranch->
Fill() ;
1209 hiName.
Append(
"_aerr_hi") ;
1211 if (hiBranch) hiBranch->
Fill() ;
1257 coutI(Eval) <<
"RooRealVar::Streamer(" <<
GetName() <<
") converting version 1 data format" << std::endl ;
1264 _binning = std::make_unique<RooUniformBinning>(fitMin,fitMax,fitBins);
1282 auto tmpProp = std::make_shared<RooRealVarSharedProperties>();
1283 tmpProp->Streamer(R__b);
1324 if (prop ==
nullptr || (*prop ==
_nullProp())) {
1331 std::shared_ptr<RooRealVarSharedProperties> existingProp;
1332 if ( (existingProp = weakPtr.lock()) ) {
1336 prop->disownBinnings();
1367 if(iter->second.expired()) {
static bool staticSharedPropListCleanedUp
int Int_t
Signed integer 4 bytes (int).
char Text_t
General string (char).
short Version_t
Class version identifier (short).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
const char Option_t
Option string (const char).
static void indent(ostringstream &buf, int indent_level)
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
bool isConstant() const
Check if the "Constant" attribute is set.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
TString cleanBranchName() const
Construct a mangled name from the actual name that is free of any math symbols that might be interpre...
RooAbsArg()
Default constructor.
Abstract base class for RooRealVar binning definitions.
virtual void setRange(double xlo, double xhi)=0
virtual void setMin(double xlo)
Change lower bound to xlo.
virtual void setMax(double xhi)
Change upper bound to xhi.
virtual RooAbsBinning * clone(const char *name=nullptr) const =0
virtual Int_t getBins(const char *name=nullptr) const
Get number of bins of currently defined range.
bool isValidReal(double value, bool printError=false) const override
Check if given value is valid.
void setConstant(bool value=true)
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
bool hasMax(const char *name=nullptr) const
Check if variable has an upper bound.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
bool inRange(const char *name) const override
Check if current value is inside range with given name.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Structure printing.
void Streamer(TBuffer &) override
Stream an object of class RooAbsArg.
bool hasMin(const char *name=nullptr) const
Check if variable has a lower bound.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooAbsReal()
coverity[UNINIT_CTOR] Default constructor
friend class RooVectorDataStore
TString _unit
Unit for objects value.
void attachToVStore(RooVectorDataStore &vstore) override
void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true) override
Copy the cached value of another RooAbsArg to our cache.
double _value
Cache for current value of object.
void attachToTree(TTree &t, Int_t bufSize=32000) override
Attach object to a branch of given TTree.
const char * getPlotLabel() const
Get the label associated with the variable.
const Text_t * getUnit() const
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Named container for two doubles, two integers two object points and three string pointers that can be...
void setProcessRecArgs(bool flag, bool prefix=true)
Configurable parser for RooCmdArg named arguments.
void defineMutex(const char *head, Args_t &&... tail)
Define arguments where any pair is mutually exclusive.
bool process(const RooCmdArg &arg)
Process given RooCmdArg.
bool hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name 'cmdName' has been processed.
bool ok(bool verbose) const
Return true of parsing was successful.
const char * getString(const char *name, const char *defaultValue="", bool convEmptyToNull=false) const
Return string property registered with name 'name'.
bool defineString(const char *name, const char *argName, int stringNum, const char *defValue="", bool appendMode=false)
Define double property name 'name' mapped to double in slot 'stringNum' in RooCmdArg with name argNam...
bool defineInt(const char *name, const char *argName, int intNum, int defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
int getInt(const char *name, int defaultValue=0) const
Return integer property registered with name 'name'.
Auxiliary class that represents the error of a RooRealVar as a separate object.
static constexpr double infinity()
Return internal infinity representation.
static constexpr int isInfinite(double x)
Return true if x is infinite by RooNumber internal specification.
Implementation of RooAbsBinning that constructs a binning with a range definition that depends on ext...
Binning/range definition that only defines a range but no binning.
Implementation of RooSharedProperties that stores the properties of a RooRealVar that are shared amon...
void Streamer(TBuffer &) override
Stream an object of class TObject.
Variable that can be changed from the outside.
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.
void removeBinning(const char *name)
remove a named binning (or a named range, which are stored internally as binnings)
static void printSigDigits(Int_t ndig=5)
Set number of digits to show when printing RooRealVars.
void setError(double value)
std::unordered_map< std::string, std::unique_ptr< RooAbsBinning > > _altNonSharedBinning
! Non-shareable alternative binnings
static RooRealVarSharedProperties & _nullProp()
Null property.
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
std::shared_ptr< RooRealVarSharedProperties > sharedProp() const
Hand out our shared property, create on the fly and register in shared map if necessary.
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 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
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.
void installSharedProp(std::shared_ptr< RooRealVarSharedProperties > &&prop)
Install the shared property into the member _sharedProp.
void setMin(const char *name, double value, bool shared=true)
Set minimum of name range to given value.
static bool _printScientific
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
! Shared binnings associated with this instance
void setAsymError(double lo, double hi)
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 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
~RooRealVar() override
Destructor.
double _asymErrHi
High side of asymmetric error associated with current value.
static Int_t _printSigDigits
static void cleanup()
Explicitly deletes the shared properties list on exit to avoid problems with the initialization order...
void setRange(const char *name, double min, double max, bool shared=true)
Set a fit or plotting range.
void setBins(Int_t nBins, const char *name=nullptr, bool shared=true)
Create a uniform binning under name 'name' for this variable.
Int_t defaultPrintContents(Option_t *opt) const override
Mapping of Print() option string to RooPrintable contents specifications.
bool hasError(bool allowZero=true) const
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...
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to given stream.
void Streamer(TBuffer &) override
Stream an object of class RooRealVar.
bool hasAsymError(bool allowZero=true) const
void setBinning(const RooAbsBinning &binning, const char *name=nullptr, bool shared=true)
Add given binning under name 'name' with this variable.
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
void setMax(const char *name, double value, bool shared=true)
Set maximum of name range to given value.
RooRealVar()
Default constructor.
void removeMax(const char *name=nullptr)
Remove upper range limit for binning with given name. Empty name means default range.
std::string format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false, bool shared=true) const override
Return binning definition with name.
TClass * IsA() const override
double getAsymErrorLo() const
bool expectToken(const TString &expected, bool zapOnError=false)
Read the next token and return true if it is identical to the given 'expected' token.
bool convertToDouble(const TString &token, double &value)
Convert given string to a double. Throws exceptions if the conversion fails.
bool atEOL()
If true, parser is at end of line in stream.
bool readDouble(double &value, bool zapOnError=false)
Read the next token and convert it to a double.
TString readToken()
Read one token separated by any of the know punctuation characters This function recognizes and handl...
bool readInteger(Int_t &value, bool zapOnError=false)
Read a token and convert it to an Int_t.
void zapToEnd(bool inclContLines=false)
Eat all characters up to and including then end of the current line.
void setErrorBuffer(double *newBuf)
void setAsymErrorBuffer(double *newBufL, double *newBufH)
void setBuffer(RooAbsReal *real, double *newBuf)
RealFullVector * addRealFull(RooAbsReal *real)
bool isFullReal(RooAbsReal *real)
bool hasError(RooAbsReal *real)
bool hasAsymError(RooAbsReal *real)
A TTree is a list of TBranches.
Buffer base class used for serializing objects.
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Mother of all ROOT objects.
void ToLower()
Change string to lower-case.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
TString & Prepend(const char *cs)
TString & Append(const char *cs)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
A TTree represents a columnar dataset.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.