Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooRealVar.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
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
17/**
18\file RooRealVar.cxx
19\class RooRealVar
20\ingroup Roofitcore
21
22Variable that can be changed from the outside.
23For example by the user or a fitter.
24
25It can be written into datasets, can hold a (possibly asymmetric) error, and
26can have several ranges. These can be accessed with names, to e.g. limit fits
27or integrals to sub ranges. The range without any name is used as default range.
28**/
29
30#include "RooRealVar.h"
31
32#include "RooStreamParser.h"
33#include "RooErrorVar.h"
34#include "RooRangeBinning.h"
35#include "RooCmdConfig.h"
36#include "RooMsgService.h"
37#include "RooParamBinning.h"
38#include "RooVectorDataStore.h"
39#include "RooTrace.h"
41#include "RooUniformBinning.h"
42#include "RooSentinel.h"
43
44#include "TTree.h"
45#include "TBuffer.h"
46#include "TBranch.h"
47
48#include <iomanip>
49
50using std::endl, std::ostream, std::istream;
51
52
53
56
58
59/// Return a reference to a map of weak pointers to RooRealVarSharedProperties.
61{
62 RooSentinel::activate();
64 static auto * staticSharedPropList = new SharedPropertiesMap{};
66 }
67 return nullptr;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Explicitly deletes the shared properties list on exit to avoid problems
72/// with the initialization order. Meant to be only used internally in RooFit
73/// by RooSentinel.
74
76{
77 if(sharedPropList()) {
78 delete sharedPropList();
80 }
81}
82
83////////////////////////////////////////////////////////////////////////////////
84
85/// Return a dummy object to use when properties are not initialised.
87{
88 static const std::unique_ptr<RooRealVarSharedProperties> nullProp(new RooRealVarSharedProperties("00000000-0000-0000-0000-000000000000"));
89 return *nullProp;
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Default constructor.
94
95RooRealVar::RooRealVar() : _error(0), _asymErrLo(0), _asymErrHi(0), _binning(new RooUniformBinning())
96{
97 _fast = true ;
99}
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// Create a constant variable with a value and optional unit.
104RooRealVar::RooRealVar(const char *name, const char *title,
105 double value, const char *unit) :
106 RooAbsRealLValue(name, title, unit), _error(-1), _asymErrLo(1), _asymErrHi(-1),
107 _binning(new RooUniformBinning(-1,1,100))
108{
109 _value = value ;
110 _fast = true ;
111 removeMin();
112 removeMax();
113 setConstant(true) ;
115}
116
117
118////////////////////////////////////////////////////////////////////////////////
119/// Create a variable allowed to float in the given range.
120/// The initial value will be set to the center of the range.
121RooRealVar::RooRealVar(const char *name, const char *title,
122 double minValue, double maxValue,
123 const char *unit) :
124 RooAbsRealLValue(name, title, unit), _error(-1), _asymErrLo(1), _asymErrHi(-1),
126{
127 _fast = true ;
128
131 // [-inf,inf]
132 _value = 0 ;
133 } else {
134 // [-inf,X]
136 }
137 } else {
139 // [X,inf]
140 _value = minValue ;
141 } else {
142 // [X,X]
143 _value= 0.5*(minValue + maxValue);
144 }
145 }
146
147 // setPlotRange(minValue,maxValue) ;
150}
151
152
153////////////////////////////////////////////////////////////////////////////////
154/// Create a variable with the given starting value. It is allowed to float
155/// within the defined range. Optionally, a unit can be specified for axis labels.
156RooRealVar::RooRealVar(const char *name, const char *title,
157 double value, double minValue, double maxValue,
158 const char *unit) :
159 RooAbsRealLValue(name, title, unit), _error(-1), _asymErrLo(1), _asymErrHi(-1),
161{
162 _fast = true ;
164
165 double clipValue ;
166 inRange(value,nullptr,&clipValue) ;
167 _value = clipValue ;
168
170}
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Copy Constructor
175
178 _error(other._error),
179 _asymErrLo(other._asymErrLo),
180 _asymErrHi(other._asymErrHi)
181{
182 _sharedProp = other.sharedProp();
183 if (other._binning) {
184 _binning.reset(other._binning->clone());
185 _binning->insertHook(*this) ;
186 }
187 _fast = true ;
188
189 for (const auto& item : other._altNonSharedBinning) {
190 std::unique_ptr<RooAbsBinning> abc( item.second->clone() );
191 abc->insertHook(*this) ;
192 _altNonSharedBinning[item.first] = std::move(abc);
193 }
194
196
197}
198
199
200////////////////////////////////////////////////////////////////////////////////
201/// Destructor
202
204{
205 // We should not forget to explicitly call deleteSharedProperties() in the
206 // destructor, because this is where the expired weak_ptrs in the
207 // _sharedPropList get erased.
209
211}
212
213
214////////////////////////////////////////////////////////////////////////////////
215/// Return value of variable
216
217double RooRealVar::getValV(const RooArgSet*) const
218{
219 return _value ;
220}
221
222
223////////////////////////////////////////////////////////////////////////////////
224/// Enable or disable the silent clipping behavior of `RooRealVar::setVal()`
225/// that was the default in ROOT versions before 6.38. It is not recommended to
226/// enable this, as silently mutating data can be dangerous.
228{
230 if (flag) {
231 oocoutI(static_cast<TObject *>(nullptr), InputArguments)
232 << "Silent clipping of values to range in `RooRealVar::setVal()` enabled." << std::endl;
233 }
234}
235
237{
238 static bool isEnabled = false;
239 return isEnabled;
240}
241
242namespace {
243
244inline void throwOutOfRangeError(RooRealVar const &var, double value, const char *rangeName)
245{
246 std::stringstream ss;
247 ss << "Value " << value;
248 if (rangeName) {
249 ss << " is outside the range \"" << rangeName << "\" ";
250 } else {
251 ss << " is outside the default range ";
252 }
253 ss << "[" << var.getMin() << ", " << var.getMax() << "] of the variable \"";
254 ss << var.GetName() << "\"!";
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());
258}
259
260void printOutOfRangeWarning(RooRealVar const &var, double value, const char *rangeName)
261{
262 std::stringstream ss;
263 ss << "Value " << value;
264 if (rangeName) {
265 ss << " is slightly outside the range \"" << rangeName << "\" ";
266 } else {
267 ss << " is slightly outside the default range ";
268 }
269 ss << "[" << var.getMin() << ", " << var.getMax() << "] of the variable \"";
270 ss << var.GetName() << "\"!";
271 ss << "\nThe value will be clipped. To restore the dangerous old behavior of silently clipping the value to the "
272 "range,"
273 << " call `RooRealVar::enableSilentClipping()`.";
274 oocoutW(&var, InputArguments) << ss.str() << std::endl;
275}
276
277}
278
279
280////////////////////////////////////////////////////////////////////////////////
281/// Set value of variable to 'value'. If 'value' is outside
282/// range of object, clip value into range
283
285{
286 double clipValue ;
287 bool isInRange = inRange(value,0,&clipValue) ;
288
289 if(!isInRange && !isSilentClippingEnabled()) {
290 if (std::abs(clipValue - value) > std::numeric_limits<double>::epsilon()) {
291 throwOutOfRangeError(*this, value, nullptr);
292 } else {
293 printOutOfRangeWarning(*this, value, nullptr);
294 }
295 }
296
297 if (clipValue != _value) {
298 setValueDirty() ;
301 }
302}
303
304
305
306////////////////////////////////////////////////////////////////////////////////
307/// Set value of variable to `value`. If `value` is outside of the
308/// range named `rangeName`, clip value into that range.
309void RooRealVar::setVal(double value, const char* rangeName)
310{
311 double clipValue ;
312 bool isInRange = inRange(value,rangeName,&clipValue) ;
313
314 if(!isInRange && !isSilentClippingEnabled()) {
315 if (std::abs(clipValue - value) > std::numeric_limits<double>::epsilon()) {
317 } else {
319 }
320 }
321
322 if (clipValue != _value) {
323 setValueDirty() ;
326 }
327}
328
329
330
331////////////////////////////////////////////////////////////////////////////////
332/// Return a RooAbsRealLValue representing the error associated
333/// with this variable. The callers takes ownership of the
334/// return object
335
337{
339 TString title(GetTitle());
340 name.Append("err") ;
341 title.Append(" Error") ;
342
343 return new RooErrorVar(name,title,*this) ;
344}
345
346
347
348////////////////////////////////////////////////////////////////////////////////
349/// Returns true if variable has a binning named 'name'.
350
351bool RooRealVar::hasBinning(const char* name) const
352{
353 return sharedProp()->_altBinning.find(name) != sharedProp()->_altBinning.end() || _altNonSharedBinning.find(name) != _altNonSharedBinning.end();
354}
355
356
357
358////////////////////////////////////////////////////////////////////////////////
359/// Return binning definition with name. If binning with 'name' is not found it is created
360/// on the fly as a clone of the default binning if createOnTheFly is true, otherwise
361/// a reference to the default binning is returned. If verbose is true a message
362/// is printed if a binning is created on the fly.
363
364const RooAbsBinning& RooRealVar::getBinning(const char* name, bool verbose, bool createOnTheFly, bool shared) const
365{
366 return const_cast<RooRealVar*>(this)->getBinning(name, verbose, createOnTheFly, shared) ;
367}
368
369
370
371////////////////////////////////////////////////////////////////////////////////
372/// Return binning definition with name. If binning with 'name' is not found it is created
373/// on the fly as a clone of the default binning if createOnTheFly is true, otherwise
374/// a reference to the default binning is returned. If verbose is true a message
375/// is printed if a binning is created on the fly.
376
377RooAbsBinning& RooRealVar::getBinning(const char* name, bool verbose, bool createOnTheFly, bool shared)
378{
379 // Return default (normalization) binning and range if no name is specified
380 if (name==nullptr) {
381 return *_binning ;
382 }
383
384 if (strchr(name, ',')) {
385 coutW(InputArguments) << "Asking variable " << GetName() << "for binning '" << name
386 << "', but comma in binning names is not supported." << std::endl;
387 }
388
389 // Check if non-shared binning with this name has been created already
390 auto item = _altNonSharedBinning.find(name);
391 if (item != _altNonSharedBinning.end()) {
392 return *item->second;
393 }
394
395 // Check if binning with this name has been created already
396 auto item2 = sharedProp()->_altBinning.find(name);
397 if (item2 != sharedProp()->_altBinning.end()) {
398 return *item2->second;
399 }
400
401
402 // Return default binning if requested binning doesn't exist
403 if (!createOnTheFly) {
404 return *_binning ;
405 }
406
407 // Create a new RooRangeBinning with this name with default range
408 auto binning = new RooRangeBinning(getMin(),getMax(),name) ;
409 if (verbose) {
410 coutI(Eval) << "RooRealVar::getBinning(" << GetName() << ") new range named '"
411 << name << "' created with default bounds" << std::endl ;
412 }
413 if(shared) {
414 sharedProp()->_altBinning[name] = binning;
415 } else {
416 _altNonSharedBinning[name].reset(binning);
417 }
418
419 return *binning ;
420}
421
422////////////////////////////////////////////////////////////////////////////////
423/// Get a list of all binning names. An empty name implies the default binning and
424/// a nullptr pointer should be passed to getBinning in this case.
425
426std::list<std::string> RooRealVar::getBinningNames() const
427{
428 std::list<std::string> binningNames;
429 if (_binning) {
430 binningNames.push_back("");
431 }
432
433 for (const auto& item : _altNonSharedBinning) {
434 binningNames.push_back(item.first);
435 }
436 for (const auto& item : sharedProp()->_altBinning) {
437 binningNames.push_back(item.first);
438 }
439
440 return binningNames;
441}
442
443////////////////////////////////////////////////////////////////////////////////
444/// Remove a named binning (or a named range, which are stored internally as binnings)
445
447 // Remove any old binning with this name
448 auto sharedProps = sharedProp();
449 auto item = sharedProps->_altBinning.find(name);
450 if (item != sharedProps->_altBinning.end()) {
451 item->second->removeHook(*this);
452 if (sharedProps->_ownBinnings)
453 delete item->second;
454
455 sharedProps->_altBinning.erase(item);
456 }
457 auto item2 = _altNonSharedBinning.find(name);
458 if (item2 != _altNonSharedBinning.end()) {
459 item2->second->removeHook(*this);
461 }
462}
463
464
465
466void RooRealVar::removeMin(const char* name) {
468}
469void RooRealVar::removeMax(const char* name) {
471}
472
473////////////////////////////////////////////////////////////////////////////////
474/// Create a uniform binning under name 'name' for this variable.
475/// \param[in] nBins Number of bins. The limits are taken from the currently set limits.
476/// \param[in] name Optional name. If name is null, install as default binning.
477void RooRealVar::setBins(Int_t nBins, const char* name, bool shared) {
479}
480
481////////////////////////////////////////////////////////////////////////////////
482/// Add given binning under name 'name' with this variable. If name is null,
483/// the binning is installed as the default binning.
484void RooRealVar::setBinning(const RooAbsBinning& binning, const char* name, bool shared)
485{
486 std::unique_ptr<RooAbsBinning> newBinning( binning.clone() );
487
488 // Process insert hooks required for parameterized binnings
489 if (!name || name[0] == 0) {
490 if (_binning) {
491 _binning->removeHook(*this) ;
492 }
493 newBinning->insertHook(*this) ;
494 _binning = std::move(newBinning);
495 } else {
496 // Remove any old binning with this name
498
499 // Install new
500 newBinning->SetName(name) ;
501 newBinning->SetTitle(name) ;
502 newBinning->insertHook(*this) ;
503 if (newBinning->isShareable() && shared) {
504 sharedProp()->_altBinning[name] = newBinning.release();
505 } else {
507 }
508 }
509}
510
511
512
513////////////////////////////////////////////////////////////////////////////////
514/// Set minimum of name range to given value. If name is null
515/// minimum of default range is set
516
517void RooRealVar::setMin(const char* name, double value, bool shared)
518{
519 // Set new minimum of fit range
520 RooAbsBinning& binning = getBinning(name,true,true,shared) ;
521
522 // Check if new limit is consistent
523 if (value >= getMax()) {
524 coutW(InputArguments) << "RooRealVar::setMin(" << GetName()
525 << "): Proposed new fit min. larger than max., setting min. to max." << std::endl ;
526 binning.setMin(getMax()) ;
527 } else {
528 binning.setMin(value) ;
529 }
530
531 // Clip current value in window if it fell out
532 if (!name) {
533 double clipValue ;
534 if (!inRange(_value,nullptr,&clipValue)) {
536 }
537 }
538
539 setShapeDirty() ;
540}
541
542
543////////////////////////////////////////////////////////////////////////////////
544/// Set maximum of name range to given value. If name is null
545/// maximum of default range is set
546
547void RooRealVar::setMax(const char* name, double value, bool shared)
548{
549 // Set new maximum of fit range
550 RooAbsBinning& binning = getBinning(name,true,true,shared) ;
551
552 // Check if new limit is consistent
553 if (value < getMin()) {
554 coutW(InputArguments) << "RooRealVar::setMax(" << GetName()
555 << "): Proposed new fit max. smaller than min., setting max. to min." << std::endl ;
556 binning.setMax(getMin()) ;
557 } else {
558 binning.setMax(value) ;
559 }
560
561 // Clip current value in window if it fell out
562 if (!name) {
563 double clipValue ;
564 if (!inRange(_value,nullptr,&clipValue)) {
566 }
567 }
568
569 setShapeDirty() ;
570}
571
572
573////////////////////////////////////////////////////////////////////////////////
574/// Set a fit or plotting range.
575/// Ranges can be selected for e.g. fitting, plotting or integration. Note that multiple
576/// variables can have ranges with the same name, so multi-dimensional PDFs can be sliced.
577/// See also the tutorial rf203_ranges.C
578/// \param[in] name Name this range (so it can be selected later for fitting or
579/// plotting). If the name is `nullptr`, the function sets the limits of the default range.
580/// \param[in] min Miniminum of the range.
581/// \param[in] max Maximum of the range.
582void RooRealVar::setRange(const char* name, double min, double max, bool shared)
583{
584 bool exists = name == nullptr || sharedProp()->_altBinning.count(name) > 0 || _altNonSharedBinning.count(name) > 0;
585
586 // Set new fit range
587 RooAbsBinning& binning = getBinning(name,false,true,shared) ;
588
589 // Check if new limit is consistent
590 if (min>max) {
591 coutW(InputArguments) << "RooRealVar::setRange(" << GetName()
592 << "): Proposed new fit max. smaller than min., setting max. to min." << std::endl ;
593 binning.setRange(min,min) ;
594 } else {
595 binning.setRange(min,max) ;
596 }
597
598 if (!exists) {
599 coutI(Eval) << "RooRealVar::setRange(" << GetName()
600 << ") new range named '" << name << "' created with bounds ["
601 << min << "," << max << "]" << std::endl ;
602 }
603
604 setShapeDirty() ;
605}
606
607
608
609////////////////////////////////////////////////////////////////////////////////
610/// Set or modify a parameterised range, i.e., a range the varies in dependence
611/// of parameters.
612/// See setRange() for more details.
613void RooRealVar::setRange(const char* name, RooAbsReal& min, RooAbsReal& max, bool shared)
614{
615 RooParamBinning pb(min,max,100) ;
616 setBinning(pb,name,shared) ;
617}
618
619
620
621////////////////////////////////////////////////////////////////////////////////
622/// Read object contents from given stream
623
624bool RooRealVar::readFromStream(istream& is, bool compact, bool verbose)
625{
626 TString token;
627 TString errorPrefix("RooRealVar::readFromStream(");
628 errorPrefix.Append(GetName()) ;
629 errorPrefix.Append(")") ;
630 RooStreamParser parser(is,errorPrefix) ;
631 double value(0) ;
632
633 if (compact) {
634 // Compact mode: Read single token
635 if (parser.readDouble(value,verbose)) return true ;
636 if (isValidReal(value,verbose)) {
637 setVal(value) ;
638 return false ;
639 } else {
640 return true ;
641 }
642
643 } else {
644 // Extended mode: Read multiple tokens on a single line
645 bool haveValue(false) ;
646 bool haveConstant(false) ;
647 removeError() ;
649
650 bool reprocessToken = false ;
651 while(true) {
652 if (parser.atEOL() || parser.atEOF()) break ;
653
654 if (!reprocessToken) {
655 token=parser.readToken() ;
656 }
658
659 if (!token.CompareTo("+")) {
660
661 // Expect +/- as 3-token sequence
662 if (parser.expectToken("/",true) ||
663 parser.expectToken("-",true)) {
664 break ;
665 }
666
667 // Next token is error or asymmetric error, check if first char of token is a '('
668 TString tmp = parser.readToken() ;
669 if (tmp.CompareTo("(")) {
670 // Symmetric error, convert token do double
671
672 double error ;
673 parser.convertToDouble(tmp,error) ;
674 setError(error) ;
675
676 } else {
677 // Have error
678 double asymErrLo = 0.;
679 double asymErrHi = 0.;
680 if (parser.readDouble(asymErrLo,true) ||
681 parser.expectToken(",",true) ||
682 parser.readDouble(asymErrHi,true) ||
683 parser.expectToken(")",true)) break ;
685 }
686
687 } else if (!token.CompareTo("C")) {
688
689 // Set constant
690 setConstant(true) ;
692
693 } else if (!token.CompareTo("P")) {
694
695 // Next tokens are plot limits
696 double plotMin(0);
697 double plotMax(0);
698 Int_t plotBins(0);
699 if (parser.expectToken("(",true) ||
700 parser.readDouble(plotMin,true) ||
701 parser.expectToken("-",true) ||
702 parser.readDouble(plotMax,true) ||
703 parser.expectToken(":",true) ||
704 parser.readInteger(plotBins,true) ||
705 parser.expectToken(")",true)) break ;
706// setPlotRange(plotMin,plotMax) ;
707 coutW(Eval) << "RooRealVar::readFromStream(" << GetName()
708 << ") WARNING: plot range deprecated, removed P(...) token" << std::endl ;
709
710 } else if (!token.CompareTo("F")) {
711
712 // Next tokens are fit limits
713 double fitMin;
714 double fitMax;
715 Int_t fitBins ;
716 if (parser.expectToken("(",true) ||
717 parser.readDouble(fitMin,true) ||
718 parser.expectToken("-",true) ||
719 parser.readDouble(fitMax,true) ||
720 parser.expectToken(":",true) ||
721 parser.readInteger(fitBins,true) ||
722 parser.expectToken(")",true)) break ;
723 //setBins(fitBins) ;
724 //setRange(fitMin,fitMax) ;
725 coutW(Eval) << "RooRealVar::readFromStream(" << GetName()
726 << ") WARNING: F(lo-hi:bins) token deprecated, use L(lo-hi) B(bins)" << std::endl ;
727 if (!haveConstant) setConstant(false) ;
728
729 } else if (!token.CompareTo("L")) {
730
731 // Next tokens are fit limits
732 double fitMin = 0.0;
733 double fitMax = 0.0;
734 // Int_t fitBins ;
735 if (parser.expectToken("(",true) ||
736 parser.readDouble(fitMin,true) ||
737 parser.expectToken("-",true) ||
738 parser.readDouble(fitMax,true) ||
739 parser.expectToken(")",true)) break ;
741 if (!haveConstant) setConstant(false) ;
742
743 } else if (!token.CompareTo("B")) {
744
745 // Next tokens are fit limits
746 Int_t fitBins = 0;
747 if (parser.expectToken("(",true) ||
748 parser.readInteger(fitBins,true) ||
749 parser.expectToken(")",true)) break ;
751
752 } else {
753 // Token is value
754 if (parser.convertToDouble(token,value)) { parser.zapToEnd() ; break ; }
755 haveValue = true ;
756 // Defer value assignment to end
757 }
758 }
759 if (haveValue) setVal(value) ;
760 return false ;
761 }
762}
763
764
765////////////////////////////////////////////////////////////////////////////////
766/// Write object contents to given stream
767
768void RooRealVar::writeToStream(ostream &os, bool compact) const
769{
770 if (compact) {
771 // Write value only
772 os << getVal();
773 return;
774 }
775
776 // Write value with error (if not zero)
777 if (_printScientific) {
778 std::stringstream text;
779
781 int nDigitsErr = (_printSigDigits + 1) / 2;
782
783 text << std::scientific;
784
785 if (_value >= 0)
786 text << " ";
787 text << std::setprecision(nDigitsVal) << _value;
788
789 text << std::setprecision(nDigitsErr) << " +/- ";
790 if (hasAsymError()) {
791 text << "(" << getAsymErrorLo() << ", " << getAsymErrorHi() << ")";
792 } else if (hasError()) {
793 text << getError();
794 }
795
796 os << text.str() << " ";
797 } else {
798 os << format(_printSigDigits, "EFA") << " ";
799 }
800
801 // Append limits if not constants
802 if (isConstant()) {
803 os << "C ";
804 }
805
806 // Append fit limits
807 if (hasMin()) {
808 os << "L(" << getMin();
809 } else {
810 os << "L(-INF";
811 }
812 if (hasMax()) {
813 os << " - " << getMax() << ") ";
814 } else {
815 os << " - +INF) ";
816 }
817
818 if (getBins() != 100) {
819 os << "B(" << getBins() << ") ";
820 }
821
822 // Add comment with unit, if unit exists
823 if (!_unit.IsNull())
824 os << "// [" << getUnit() << "]";
825}
826
827
828
829////////////////////////////////////////////////////////////////////////////////
830/// Print value of variable
831
832void RooRealVar::printValue(ostream& os) const
833{
834 os << getVal() ;
835
836 if(hasError() && !hasAsymError()) {
837 os << " +/- " << getError() ;
838 } else if (hasAsymError()) {
839 os << " +/- (" << getAsymErrorLo() << "," << getAsymErrorHi() << ")" ;
840 }
841
842}
843
844
845////////////////////////////////////////////////////////////////////////////////
846/// Print extras of variable: (asymmetric) error, constant flag, limits and binning
847
848void RooRealVar::printExtras(ostream& os) const
849{
850 // Append limits if not constants
851 if (isConstant()) {
852 os << "C " ;
853 }
854
855 // Append fit limits
856 os << " L(" ;
857 if(hasMin()) {
858 os << getMin();
859 }
860 else {
861 os << "-INF";
862 }
863 if(hasMax()) {
864 os << " - " << getMax() ;
865 }
866 else {
867 os << " - +INF";
868 }
869 os << ") " ;
870
871 if (getBins()!=100) {
872 os << "B(" << getBins() << ") " ;
873 }
874
875 // Add comment with unit, if unit exists
876 if (!_unit.IsNull())
877 os << "// [" << getUnit() << "]" ;
878
879// std::cout << " _value = " << &_value << " _error = " << &_error ;
880
881
882}
883
884
885////////////////////////////////////////////////////////////////////////////////
886/// Mapping of Print() option string to RooPrintable contents specifications
887
889{
890 if (opt && TString(opt)=="I") {
891 return kName|kClassName|kValue ;
892 }
894}
895
896
897////////////////////////////////////////////////////////////////////////////////
898/// Detailed printing interface
899
900void RooRealVar::printMultiline(ostream& os, Int_t contents, bool verbose, TString indent) const
901{
902 RooAbsRealLValue::printMultiline(os,contents,verbose,indent);
903 os << indent << "--- RooRealVar ---" << std::endl;
904 TString unit(_unit);
905 if(!unit.IsNull()) unit.Prepend(' ');
906 os << indent << " Error = " << getError() << unit << std::endl;
907}
908
909
910
911////////////////////////////////////////////////////////////////////////////////
912/// Format contents of RooRealVar for pretty printing on RooPlot
913/// parameter boxes. This function processes the named arguments
914/// taken by paramOn() and translates them to an option string
915/// parsed by RooRealVar::format(Int_t sigDigits, const char *options)
916
917std::string RooRealVar::format(const RooCmdArg& formatArg) const
918{
920 tmp.setProcessRecArgs(true) ;
921
922 RooCmdConfig pc("RooRealVar::format(" + std::string(GetName()) + ")");
923 pc.defineString("what","FormatArgs",0,"") ;
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") ;
932
933 // Process & check varargs
934 pc.process(tmp) ;
935 if (!pc.ok(true)) {
936 return "";
937 }
938
939 // Extract values from named arguments
940 TString options ;
941 options = pc.getString("what") ;
942
943 if (pc.getInt("tlatex")) {
944 options += "L" ;
945 } else if (pc.getInt("latex")) {
946 options += "X" ;
947 } else if (pc.getInt("latext")) {
948 options += "Y" ;
949 }
950
951 if (pc.getInt("verbn")) options += "V" ;
952 Int_t sigDigits = 2 ;
953 if (pc.hasProcessed("FormatArgs::AutoPrecision")) {
954 options += "P" ;
955 sigDigits = pc.getInt("autop") ;
956 } else if (pc.hasProcessed("FormatArgs::FixedPrecision")) {
957 options += "F" ;
958 sigDigits = pc.getInt("fixedp") ;
959 }
960
961 return format(sigDigits,options) ;
962}
963
964
965
966
967////////////////////////////////////////////////////////////////////////////////
968/// Format numeric value of RooRealVar and its error in a variety of ways
969///
970/// To control what is shown use the following options
971/// N = show name
972/// T = show title (takes precedent over `N`, falls back to `N` if title is empty)
973/// H = hide value
974/// E = show error
975/// A = show asymmetric error instead of parabolic error (if available)
976/// U = show unit
977///
978/// To control how it is shown use these options
979/// L = TLatex mode
980/// X = Latex mode
981/// Y = Latex table mode ( '=' replaced by '&' )
982/// V = Make name \\verbatim in Latex mode
983/// P = use error to control shown precision
984/// F = force fixed precision
985///
986
987std::string RooRealVar::format(Int_t sigDigits, const char *options) const
988{
989 // parse the options string
990 TString opts(options);
991 opts.ToLower();
992
993 bool showName= opts.Contains("n");
994 bool showTitle = opts.Contains("t");
995 bool hideValue= opts.Contains("h");
996 bool showError= opts.Contains("e");
997 bool showUnit= opts.Contains("u");
998 bool tlatexMode= opts.Contains("l");
999 bool latexMode= opts.Contains("x");
1000 bool latexTableMode = opts.Contains("y") ;
1001 bool latexVerbatimName = opts.Contains("v") ;
1002
1003 std::string label = showName ? getPlotLabel() : "";
1004 if(showTitle) {
1005 label = GetTitle();
1006 if(label.empty()) label = getPlotLabel();
1007 }
1008
1010 bool asymError= opts.Contains("a") ;
1011 bool useErrorForPrecision= (((showError && hasError(false) && !isConstant()) || opts.Contains("p")) && !opts.Contains("f")) ;
1012 // calculate the precision to use
1013 if(sigDigits < 1) sigDigits= 1;
1016 leadingDigitVal = (Int_t)floor(log10(std::abs(_error+1e-10)));
1017 if (_value==0&&_error==0) leadingDigitVal=0 ;
1018 } else {
1019 leadingDigitVal = (Int_t)floor(log10(std::abs(_value+1e-10)));
1020 if (_value==0) leadingDigitVal=0 ;
1021 }
1022 Int_t leadingDigitErr= (Int_t)floor(log10(std::abs(_error+1e-10)));
1025
1026 if (_value<0) whereVal -= 1 ;
1027 int nDigitsVal = whereVal < 0 ? -whereVal : 0;
1028 int nDigitsErr = whereErr < 0 ? -whereErr : 0;
1029
1030 std::stringstream text;
1031
1032 if (latexMode)
1033 text << "$";
1034 // begin the string with "<name> = " if requested
1035 if(showName || showTitle) {
1037 text << "\\verb+";
1038 }
1039 text << label;
1041 text << "+";
1042
1043 if (!latexTableMode) {
1044 text << " = ";
1045 } else {
1046 text << " $ & $ ";
1047 }
1048 }
1049
1050 // Add leading space if value is positive
1051 if (_value >= 0)
1052 text << " ";
1053
1054 // append our value if requested
1055 text << std::fixed;
1056 if(!hideValue) {
1057 text << std::setprecision(nDigitsVal) << _value;
1058 }
1059 text << std::setprecision(nDigitsErr); // we only print errors from now on
1060
1061 // append our error if requested and this variable is not constant
1062 if(hasError(false) && showError && !(asymError && hasAsymError(false))) {
1063 if(tlatexMode) {
1064 text << " #pm " << getError();
1065 }
1066 else {
1067 text << (latexMode ? "\\pm " : " +/- ") << getError();
1068 }
1069 }
1070
1071 if (asymError && hasAsymError() && showError) {
1072 if(tlatexMode) {
1073 text << " #pm _{" << getAsymErrorLo() << "}^{+" << getAsymErrorHi() << "}";
1074 }
1075 else if(latexMode) {
1076 text << "\\pm _{" << getAsymErrorLo() << "}^{+" << getAsymErrorHi() << "}";
1077 }
1078 else {
1079 text << " +/- (" << getAsymErrorLo() << ", " << getAsymErrorHi() << ")";
1080 }
1081
1082 }
1083
1084 // append our units if requested
1085 if(!_unit.IsNull() && showUnit) {
1086 text << ' ' << _unit;
1087 }
1088 if (latexMode)
1089 text << "$";
1090 return text.str();
1091}
1092
1093////////////////////////////////////////////////////////////////////////////////
1094/// Overload RooAbsReal::attachToTree to also attach
1095/// branches for errors and/or asymmetric errors
1096/// attribute StoreError and/or StoreAsymError are set
1097
1099{
1100 // Follow usual procedure for value
1101
1102 if (getAttribute("StoreError") || getAttribute("StoreAsymError") || vstore.isFullReal(this) ) {
1103
1104 RooVectorDataStore::RealFullVector* rfv = vstore.addRealFull(this) ;
1105 rfv->setBuffer(this,&_value);
1106
1107 // Attach/create additional branch for error
1108 if (getAttribute("StoreError") || vstore.hasError(this) ) {
1109 rfv->setErrorBuffer(&_error) ;
1110 }
1111
1112 // Attach/create additional branches for asymmetric error
1113 if (getAttribute("StoreAsymError") || vstore.hasAsymError(this)) {
1114 rfv->setAsymErrorBuffer(&_asymErrLo,&_asymErrHi) ;
1115 }
1116
1117 } else {
1118
1120
1121 }
1122}
1123
1124
1125
1126////////////////////////////////////////////////////////////////////////////////
1127/// Overload RooAbsReal::attachToTree to also attach
1128/// branches for errors and/or asymmetric errors
1129/// attribute StoreError and/or StoreAsymError are set
1130
1132{
1133 // Follow usual procedure for value
1135// std::cout << "RooRealVar::attachToTree(" << this << ") name = " << GetName()
1136// << " StoreError = " << (getAttribute("StoreError")?"T":"F") << std::endl ;
1137
1138 // Attach/create additional branch for error
1139 if (getAttribute("StoreError")) {
1141 errName.Append("_err") ;
1143 if (branch) {
1145 } else {
1147 format2.Append("/D");
1148 t.Branch(errName, &_error, (const Text_t*)format2, bufSize);
1149 }
1150 }
1151
1152 // Attach/create additional branches for asymmetric error
1153 if (getAttribute("StoreAsymError")) {
1155 loName.Append("_aerr_lo") ;
1157 if (lobranch) {
1159 } else {
1161 format2.Append("/D");
1163 }
1164
1166 hiName.Append("_aerr_hi") ;
1168 if (hibranch) {
1170 } else {
1172 format2.Append("/D");
1174 }
1175 }
1176}
1177
1178
1179////////////////////////////////////////////////////////////////////////////////
1180/// Overload RooAbsReal::fillTreeBranch to also
1181/// fill tree branches with (asymmetric) errors
1182/// if requested.
1183
1185{
1186 // First determine if branch is taken
1189 if (!valBranch) {
1190 coutE(Eval) << "RooAbsReal::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << std::endl ;
1191 assert(0) ;
1192 }
1193 valBranch->Fill() ;
1194
1195 if (getAttribute("StoreError")) {
1197 errName.Append("_err") ;
1199 if (errBranch) errBranch->Fill() ;
1200 }
1201
1202 if (getAttribute("StoreAsymError")) {
1204 loName.Append("_aerr_lo") ;
1206 if (loBranch) loBranch->Fill() ;
1207
1209 hiName.Append("_aerr_hi") ;
1211 if (hiBranch) hiBranch->Fill() ;
1212 }
1213}
1214
1215
1216
1217////////////////////////////////////////////////////////////////////////////////
1218/// Copy the cached value of another RooAbsArg to our cache
1219/// Warning: This function copies the cached values of source,
1220/// it is the callers responsibility to make sure the cache is clean
1221
1223{
1224 // Follow usual procedure for valueklog
1225 double oldVal = _value;
1227 if(_value != oldVal) {
1229 }
1230
1231 if (valueOnly) return ;
1232
1233 // Copy error too, if source has one
1234 RooRealVar* other = dynamic_cast<RooRealVar*>(const_cast<RooAbsArg*>(source)) ;
1235 if (other) {
1236 // Copy additional error value
1237 _error = other->_error ;
1238 _asymErrLo = other->_asymErrLo ;
1239 _asymErrHi = other->_asymErrHi ;
1240 }
1241}
1242
1243
1244
1245////////////////////////////////////////////////////////////////////////////////
1246/// Stream an object of class RooRealVar.
1247
1249{
1250 UInt_t R__s;
1251 UInt_t R__c;
1252 if (R__b.IsReading()) {
1253
1254 Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
1256 if (R__v==1) {
1257 coutI(Eval) << "RooRealVar::Streamer(" << GetName() << ") converting version 1 data format" << std::endl ;
1258 double fitMin;
1259 double fitMax;
1260 Int_t fitBins ;
1261 R__b >> fitMin;
1262 R__b >> fitMax;
1263 R__b >> fitBins;
1264 _binning = std::make_unique<RooUniformBinning>(fitMin,fitMax,fitBins);
1265 }
1266 R__b >> _error;
1267 R__b >> _asymErrLo;
1268 R__b >> _asymErrHi;
1269 if (R__v>=2) {
1270 RooAbsBinning* binning;
1271 R__b >> binning;
1272 _binning.reset(binning);
1273 }
1274 if (R__v==3) {
1275 // In v3, properties were written as pointers, so read now and install:
1277 R__b >> tmpProp;
1278 installSharedProp(std::shared_ptr<RooRealVarSharedProperties>(tmpProp));
1279 }
1280 if (R__v>=4) {
1281 // In >= v4, properties were written directly, but they might be the "_nullProp"
1282 auto tmpProp = std::make_shared<RooRealVarSharedProperties>();
1283 tmpProp->Streamer(R__b);
1284 installSharedProp(std::move(tmpProp));
1285 }
1286
1287 R__b.CheckByteCount(R__s, R__c, RooRealVar::IsA());
1288
1289 } else {
1290
1291 R__c = R__b.WriteVersion(RooRealVar::IsA(), true);
1293 R__b << _error;
1294 R__b << _asymErrLo;
1295 R__b << _asymErrHi;
1296 R__b << _binning.get();
1297 if (_sharedProp) {
1298 _sharedProp->Streamer(R__b) ;
1299 } else {
1300 _nullProp().Streamer(R__b) ;
1301 }
1302 R__b.SetByteCount(R__c, true);
1303
1304 }
1305}
1306
1307/// Hand out our shared property, create on the fly and register
1308/// in shared map if necessary.
1309std::shared_ptr<RooRealVarSharedProperties> RooRealVar::sharedProp() const {
1310 if (!_sharedProp) {
1311 const_cast<RooRealVar*>(this)->installSharedProp(std::make_shared<RooRealVarSharedProperties>());
1312 }
1313
1314 return _sharedProp;
1315}
1316
1317
1318////////////////////////////////////////////////////////////////////////////////
1319/// Install the shared property into the member _sharedProp.
1320/// If a property with same name already exists, discard the incoming one,
1321/// and share the existing.
1322/// `nullptr` and properties equal to the RooRealVar::_nullProp will not be installed.
1323void RooRealVar::installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop) {
1324 if (prop == nullptr || (*prop == _nullProp())) {
1325 _sharedProp = nullptr;
1326 return;
1327 }
1328
1329
1330 auto& weakPtr = (*sharedPropList())[prop->uuid()];
1331 std::shared_ptr<RooRealVarSharedProperties> existingProp;
1332 if ( (existingProp = weakPtr.lock()) ) {
1333 // Property exists, discard incoming
1334 _sharedProp = std::move(existingProp);
1335 // Incoming is not allowed to delete the binnings now - they are owned by the other instance
1336 prop->disownBinnings();
1337 } else {
1338 // Doesn't exist. Install, register weak pointer for future sharing
1339 _sharedProp = std::move(prop);
1341 }
1342}
1343
1344
1345////////////////////////////////////////////////////////////////////////////////
1346/// Stop sharing properties.
1348{
1349 // Nothing to do if there were no shared properties to begin with.
1350 if(!_sharedProp) return;
1351
1352 // Get the key for the _sharedPropList.
1353 auto key = _sharedProp->uuid(); // we have to make a copy because _sharedPropList gets delete next.
1354
1355 // Actually delete the shared properties object.
1356 _sharedProp.reset();
1357
1358 // If the _sharedPropList was already deleted, we can return now.
1359 if(!sharedPropList()) return;
1360
1361 // Find the std::weak_ptr that the _sharedPropList holds to our
1362 // _sharedProp.
1363 auto iter = sharedPropList()->find(key);
1364
1365 // If no other RooRealVars shared the shared properties with us, the
1366 // weak_ptr in _sharedPropList is expired and we can erase it from the map.
1367 if(iter->second.expired()) {
1368 sharedPropList()->erase(iter);
1369 }
1370}
1371
1372
1373////////////////////////////////////////////////////////////////////////////////
1374/// If true, contents of RooRealVars will be printed in scientific notation
1375
1380
1381
1382////////////////////////////////////////////////////////////////////////////////
1383/// Set number of digits to show when printing RooRealVars
1384
#define e(i)
Definition RSha256.hxx:103
#define coutI(a)
#define oocoutW(o, a)
#define coutW(a)
#define oocoutI(o, a)
#define coutE(a)
static bool staticSharedPropListCleanedUp
#define TRACE_DESTROY
Definition RooTrace.h:24
#define TRACE_CREATE
Definition RooTrace.h:23
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
char Text_t
General string (char)
Definition RtypesCore.h:76
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
Option_t Option_t TPoint TPoint const char text
char name[80]
Definition TGX11.cxx:148
@ kName
const_iterator end() const
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition RooAbsArg.h:431
bool isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:283
bool _fast
Definition RooAbsArg.h:645
friend void RooRefArray::Streamer(TBuffer &)
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:425
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...
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
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
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.
bool hasMin(const char *name=nullptr) const
Check if variable has a lower bound.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:107
TString _unit
Unit for objects value.
Definition RooAbsReal.h:540
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.
Definition RooAbsReal.h:539
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
Definition RooAbsReal.h:149
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
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.
Definition RooErrorVar.h:28
static constexpr double infinity()
Return internal infinity representation.
Definition RooNumber.h:25
static constexpr int isInfinite(double x)
Return true if x is infinite by RooNumber internal specification.
Definition RooNumber.h:27
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...
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:157
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)
Definition RooRealVar.h:61
std::unordered_map< std::string, std::unique_ptr< RooAbsBinning > > _altNonSharedBinning
! Non-shareable alternative binnings
Definition RooRealVar.h:161
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
Definition RooRealVar.h:169
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
Definition RooRealVar.h:160
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:158
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
Definition RooRealVar.h:139
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
! Shared binnings associated with this instance
Definition RooRealVar.h:173
void removeAsymError()
Definition RooRealVar.h:66
void setAsymError(double lo, double hi)
Definition RooRealVar.h:67
double getError() const
Definition RooRealVar.h:59
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
Definition RooRealVar.h:175
~RooRealVar() override
Destructor.
double _asymErrHi
High side of asymmetric error associated with current value.
Definition RooRealVar.h:159
static Int_t _printSigDigits
Definition RooRealVar.h:140
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
Definition RooRealVar.h:60
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.
bool hasAsymError(bool allowZero=true) const
Definition RooRealVar.h:65
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
Definition RooRealVar.h:64
void setMax(const char *name, double value, bool shared=true)
Set maximum of name range to given value.
RooRealVar()
Default constructor.
void removeError()
Definition RooRealVar.h:62
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
Definition RooRealVar.h:179
double getAsymErrorLo() const
Definition RooRealVar.h:63
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.
Implementation of RooAbsBinning that provides a uniform binning in 'n' bins between the range end poi...
Uses std::vector to store data columns.
A TTree is a list of TBranches.
Definition TBranch.h:93
Buffer base class used for serializing objects.
Definition TBuffer.h:43
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
Mother of all ROOT objects.
Definition TObject.h:42
Basic string class.
Definition TString.h:138
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:464
TString & Prepend(const char *cs)
Definition TString.h:682
Bool_t IsNull() const
Definition TString.h:422
TString & Append(const char *cs)
Definition TString.h:581
A TTree represents a columnar dataset.
Definition TTree.h:89
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)
Definition TTree.cxx:8675
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5430
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.
Definition TTree.h:397