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}
475
476
477////////////////////////////////////////////////////////////////////////////////
478/// Create a uniform binning under name 'name' for this variable.
479/// \param[in] nBins Number of bins. The limits are taken from the currently set limits.
480/// \param[in] name Optional name. If name is null, install as default binning.
481void RooRealVar::setBins(Int_t nBins, const char* name, bool shared) {
483}
484
485////////////////////////////////////////////////////////////////////////////////
486/// Add given binning under name 'name' with this variable. If name is null,
487/// the binning is installed as the default binning.
488void RooRealVar::setBinning(const RooAbsBinning& binning, const char* name, bool shared)
489{
490 std::unique_ptr<RooAbsBinning> newBinning( binning.clone() );
491
492 // Process insert hooks required for parameterized binnings
493 if (!name || name[0] == 0) {
494 if (_binning) {
495 _binning->removeHook(*this) ;
496 }
497 newBinning->insertHook(*this) ;
498 _binning = std::move(newBinning);
499 } else {
500 // Remove any old binning with this name
502
503 // Install new
504 newBinning->SetName(name) ;
505 newBinning->SetTitle(name) ;
506 newBinning->insertHook(*this) ;
507 if (newBinning->isShareable() && shared) {
508 sharedProp()->_altBinning[name] = newBinning.release();
509 } else {
511 }
512 }
513}
514
515
516
517////////////////////////////////////////////////////////////////////////////////
518/// Set minimum of name range to given value. If name is null
519/// minimum of default range is set
520
521void RooRealVar::setMin(const char* name, double value, bool shared)
522{
523 // Set new minimum of fit range
524 RooAbsBinning& binning = getBinning(name,true,true,shared) ;
525
526 // Check if new limit is consistent
527 if (value >= getMax()) {
528 coutW(InputArguments) << "RooRealVar::setMin(" << GetName()
529 << "): Proposed new fit min. larger than max., setting min. to max." << std::endl ;
530 binning.setMin(getMax()) ;
531 } else {
532 binning.setMin(value) ;
533 }
534
535 // Clip current value in window if it fell out
536 if (!name) {
537 double clipValue ;
538 if (!inRange(_value,nullptr,&clipValue)) {
540 }
541 }
542
543 setShapeDirty() ;
544}
545
546
547////////////////////////////////////////////////////////////////////////////////
548/// Set maximum of name range to given value. If name is null
549/// maximum of default range is set
550
551void RooRealVar::setMax(const char* name, double value, bool shared)
552{
553 // Set new maximum of fit range
554 RooAbsBinning& binning = getBinning(name,true,true,shared) ;
555
556 // Check if new limit is consistent
557 if (value < getMin()) {
558 coutW(InputArguments) << "RooRealVar::setMax(" << GetName()
559 << "): Proposed new fit max. smaller than min., setting max. to min." << std::endl ;
560 binning.setMax(getMin()) ;
561 } else {
562 binning.setMax(value) ;
563 }
564
565 // Clip current value in window if it fell out
566 if (!name) {
567 double clipValue ;
568 if (!inRange(_value,nullptr,&clipValue)) {
570 }
571 }
572
573 setShapeDirty() ;
574}
575
576
577////////////////////////////////////////////////////////////////////////////////
578/// Set a fit or plotting range.
579/// Ranges can be selected for e.g. fitting, plotting or integration. Note that multiple
580/// variables can have ranges with the same name, so multi-dimensional PDFs can be sliced.
581/// See also the tutorial rf203_ranges.C
582/// \param[in] name Name this range (so it can be selected later for fitting or
583/// plotting). If the name is `nullptr`, the function sets the limits of the default range.
584/// \param[in] min Miniminum of the range.
585/// \param[in] max Maximum of the range.
586void RooRealVar::setRange(const char* name, double min, double max, bool shared)
587{
588 bool exists = name == nullptr || sharedProp()->_altBinning.count(name) > 0 || _altNonSharedBinning.count(name) > 0;
589
590 // Set new fit range
591 RooAbsBinning& binning = getBinning(name,false,true,shared) ;
592
593 // Check if new limit is consistent
594 if (min>max) {
595 coutW(InputArguments) << "RooRealVar::setRange(" << GetName()
596 << "): Proposed new fit max. smaller than min., setting max. to min." << std::endl ;
597 binning.setRange(min,min) ;
598 } else {
599 binning.setRange(min,max) ;
600 }
601
602 if (!exists) {
603 coutI(Eval) << "RooRealVar::setRange(" << GetName()
604 << ") new range named '" << name << "' created with bounds ["
605 << min << "," << max << "]" << std::endl ;
606 }
607
608 setShapeDirty() ;
609}
610
611
612
613////////////////////////////////////////////////////////////////////////////////
614/// Set or modify a parameterised range, i.e., a range the varies in dependence
615/// of parameters.
616/// See setRange() for more details.
617void RooRealVar::setRange(const char* name, RooAbsReal& min, RooAbsReal& max, bool shared)
618{
619 RooParamBinning pb(min,max,100) ;
620 setBinning(pb,name,shared) ;
621}
622
623
624
625////////////////////////////////////////////////////////////////////////////////
626/// Read object contents from given stream
627
628bool RooRealVar::readFromStream(istream& is, bool compact, bool verbose)
629{
630 TString token;
631 TString errorPrefix("RooRealVar::readFromStream(");
632 errorPrefix.Append(GetName()) ;
633 errorPrefix.Append(")") ;
634 RooStreamParser parser(is,errorPrefix) ;
635 double value(0) ;
636
637 if (compact) {
638 // Compact mode: Read single token
639 if (parser.readDouble(value,verbose)) return true ;
640 if (isValidReal(value,verbose)) {
641 setVal(value) ;
642 return false ;
643 } else {
644 return true ;
645 }
646
647 } else {
648 // Extended mode: Read multiple tokens on a single line
649 bool haveValue(false) ;
650 bool haveConstant(false) ;
651 removeError() ;
653
654 bool reprocessToken = false ;
655 while(true) {
656 if (parser.atEOL() || parser.atEOF()) break ;
657
658 if (!reprocessToken) {
659 token=parser.readToken() ;
660 }
662
663 if (!token.CompareTo("+")) {
664
665 // Expect +/- as 3-token sequence
666 if (parser.expectToken("/",true) ||
667 parser.expectToken("-",true)) {
668 break ;
669 }
670
671 // Next token is error or asymmetric error, check if first char of token is a '('
672 TString tmp = parser.readToken() ;
673 if (tmp.CompareTo("(")) {
674 // Symmetric error, convert token do double
675
676 double error ;
677 parser.convertToDouble(tmp,error) ;
678 setError(error) ;
679
680 } else {
681 // Have error
682 double asymErrLo = 0.;
683 double asymErrHi = 0.;
684 if (parser.readDouble(asymErrLo,true) ||
685 parser.expectToken(",",true) ||
686 parser.readDouble(asymErrHi,true) ||
687 parser.expectToken(")",true)) break ;
689 }
690
691 } else if (!token.CompareTo("C")) {
692
693 // Set constant
694 setConstant(true) ;
696
697 } else if (!token.CompareTo("P")) {
698
699 // Next tokens are plot limits
700 double plotMin(0);
701 double plotMax(0);
702 Int_t plotBins(0);
703 if (parser.expectToken("(",true) ||
704 parser.readDouble(plotMin,true) ||
705 parser.expectToken("-",true) ||
706 parser.readDouble(plotMax,true) ||
707 parser.expectToken(":",true) ||
708 parser.readInteger(plotBins,true) ||
709 parser.expectToken(")",true)) break ;
710// setPlotRange(plotMin,plotMax) ;
711 coutW(Eval) << "RooRealVar::readFromStream(" << GetName()
712 << ") WARNING: plot range deprecated, removed P(...) token" << std::endl ;
713
714 } else if (!token.CompareTo("F")) {
715
716 // Next tokens are fit limits
717 double fitMin;
718 double fitMax;
719 Int_t fitBins ;
720 if (parser.expectToken("(",true) ||
721 parser.readDouble(fitMin,true) ||
722 parser.expectToken("-",true) ||
723 parser.readDouble(fitMax,true) ||
724 parser.expectToken(":",true) ||
725 parser.readInteger(fitBins,true) ||
726 parser.expectToken(")",true)) break ;
727 //setBins(fitBins) ;
728 //setRange(fitMin,fitMax) ;
729 coutW(Eval) << "RooRealVar::readFromStream(" << GetName()
730 << ") WARNING: F(lo-hi:bins) token deprecated, use L(lo-hi) B(bins)" << std::endl ;
731 if (!haveConstant) setConstant(false) ;
732
733 } else if (!token.CompareTo("L")) {
734
735 // Next tokens are fit limits
736 double fitMin = 0.0;
737 double fitMax = 0.0;
738 // Int_t fitBins ;
739 if (parser.expectToken("(",true) ||
740 parser.readDouble(fitMin,true) ||
741 parser.expectToken("-",true) ||
742 parser.readDouble(fitMax,true) ||
743 parser.expectToken(")",true)) break ;
745 if (!haveConstant) setConstant(false) ;
746
747 } else if (!token.CompareTo("B")) {
748
749 // Next tokens are fit limits
750 Int_t fitBins = 0;
751 if (parser.expectToken("(",true) ||
752 parser.readInteger(fitBins,true) ||
753 parser.expectToken(")",true)) break ;
755
756 } else {
757 // Token is value
758 if (parser.convertToDouble(token,value)) { parser.zapToEnd() ; break ; }
759 haveValue = true ;
760 // Defer value assignment to end
761 }
762 }
763 if (haveValue) setVal(value) ;
764 return false ;
765 }
766}
767
768
769////////////////////////////////////////////////////////////////////////////////
770/// Write object contents to given stream
771
772void RooRealVar::writeToStream(ostream &os, bool compact) const
773{
774 if (compact) {
775 // Write value only
776 os << getVal();
777 return;
778 }
779
780 // Write value with error (if not zero)
781 if (_printScientific) {
782 std::stringstream text;
783
785 int nDigitsErr = (_printSigDigits + 1) / 2;
786
787 text << std::scientific;
788
789 if (_value >= 0)
790 text << " ";
791 text << std::setprecision(nDigitsVal) << _value;
792
793 text << std::setprecision(nDigitsErr) << " +/- ";
794 if (hasAsymError()) {
795 text << "(" << getAsymErrorLo() << ", " << getAsymErrorHi() << ")";
796 } else if (hasError()) {
797 text << getError();
798 }
799
800 os << text.str() << " ";
801 } else {
802 os << format(_printSigDigits, "EFA") << " ";
803 }
804
805 // Append limits if not constants
806 if (isConstant()) {
807 os << "C ";
808 }
809
810 // Append fit limits
811 if (hasMin()) {
812 os << "L(" << getMin();
813 } else {
814 os << "L(-INF";
815 }
816 if (hasMax()) {
817 os << " - " << getMax() << ") ";
818 } else {
819 os << " - +INF) ";
820 }
821
822 if (getBins() != 100) {
823 os << "B(" << getBins() << ") ";
824 }
825
826 // Add comment with unit, if unit exists
827 if (!_unit.IsNull())
828 os << "// [" << getUnit() << "]";
829}
830
831
832
833////////////////////////////////////////////////////////////////////////////////
834/// Print value of variable
835
836void RooRealVar::printValue(ostream& os) const
837{
838 os << getVal() ;
839
840 if(hasError() && !hasAsymError()) {
841 os << " +/- " << getError() ;
842 } else if (hasAsymError()) {
843 os << " +/- (" << getAsymErrorLo() << "," << getAsymErrorHi() << ")" ;
844 }
845
846}
847
848
849////////////////////////////////////////////////////////////////////////////////
850/// Print extras of variable: (asymmetric) error, constant flag, limits and binning
851
852void RooRealVar::printExtras(ostream& os) const
853{
854 // Append limits if not constants
855 if (isConstant()) {
856 os << "C " ;
857 }
858
859 // Append fit limits
860 os << " L(" ;
861 if(hasMin()) {
862 os << getMin();
863 }
864 else {
865 os << "-INF";
866 }
867 if(hasMax()) {
868 os << " - " << getMax() ;
869 }
870 else {
871 os << " - +INF";
872 }
873 os << ") " ;
874
875 if (getBins()!=100) {
876 os << "B(" << getBins() << ") " ;
877 }
878
879 // Add comment with unit, if unit exists
880 if (!_unit.IsNull())
881 os << "// [" << getUnit() << "]" ;
882
883// std::cout << " _value = " << &_value << " _error = " << &_error ;
884
885
886}
887
888
889////////////////////////////////////////////////////////////////////////////////
890/// Mapping of Print() option string to RooPrintable contents specifications
891
893{
894 if (opt && TString(opt)=="I") {
895 return kName|kClassName|kValue ;
896 }
898}
899
900
901////////////////////////////////////////////////////////////////////////////////
902/// Detailed printing interface
903
904void RooRealVar::printMultiline(ostream& os, Int_t contents, bool verbose, TString indent) const
905{
906 RooAbsRealLValue::printMultiline(os,contents,verbose,indent);
907 os << indent << "--- RooRealVar ---" << std::endl;
908 TString unit(_unit);
909 if(!unit.IsNull()) unit.Prepend(' ');
910 os << indent << " Error = " << getError() << unit << std::endl;
911}
912
913
914
915////////////////////////////////////////////////////////////////////////////////
916/// Format contents of RooRealVar for pretty printing on RooPlot
917/// parameter boxes. This function processes the named arguments
918/// taken by paramOn() and translates them to an option string
919/// parsed by RooRealVar::format(Int_t sigDigits, const char *options)
920
921std::string RooRealVar::format(const RooCmdArg& formatArg) const
922{
924 tmp.setProcessRecArgs(true) ;
925
926 RooCmdConfig pc("RooRealVar::format(" + std::string(GetName()) + ")");
927 pc.defineString("what","FormatArgs",0,"") ;
928 pc.defineInt("autop","FormatArgs::AutoPrecision",0,2) ;
929 pc.defineInt("fixedp","FormatArgs::FixedPrecision",0,2) ;
930 pc.defineInt("tlatex","FormatArgs::TLatexStyle",0,0) ;
931 pc.defineInt("latex","FormatArgs::LatexStyle",0,0) ;
932 pc.defineInt("latext","FormatArgs::LatexTableStyle",0,0) ;
933 pc.defineInt("verbn","FormatArgs::VerbatimName",0,0) ;
934 pc.defineMutex("FormatArgs::TLatexStyle","FormatArgs::LatexStyle","FormatArgs::LatexTableStyle") ;
935 pc.defineMutex("FormatArgs::AutoPrecision","FormatArgs::FixedPrecision") ;
936
937 // Process & check varargs
938 pc.process(tmp) ;
939 if (!pc.ok(true)) {
940 return "";
941 }
942
943 // Extract values from named arguments
944 TString options ;
945 options = pc.getString("what") ;
946
947 if (pc.getInt("tlatex")) {
948 options += "L" ;
949 } else if (pc.getInt("latex")) {
950 options += "X" ;
951 } else if (pc.getInt("latext")) {
952 options += "Y" ;
953 }
954
955 if (pc.getInt("verbn")) options += "V" ;
956 Int_t sigDigits = 2 ;
957 if (pc.hasProcessed("FormatArgs::AutoPrecision")) {
958 options += "P" ;
959 sigDigits = pc.getInt("autop") ;
960 } else if (pc.hasProcessed("FormatArgs::FixedPrecision")) {
961 options += "F" ;
962 sigDigits = pc.getInt("fixedp") ;
963 }
964
965 return format(sigDigits,options) ;
966}
967
968
969
970
971////////////////////////////////////////////////////////////////////////////////
972/// Format numeric value of RooRealVar and its error in a variety of ways
973///
974/// To control what is shown use the following options
975/// N = show name
976/// T = show title (takes precedent over `N`, falls back to `N` if title is empty)
977/// H = hide value
978/// E = show error
979/// A = show asymmetric error instead of parabolic error (if available)
980/// U = show unit
981///
982/// To control how it is shown use these options
983/// L = TLatex mode
984/// X = Latex mode
985/// Y = Latex table mode ( '=' replaced by '&' )
986/// V = Make name \\verbatim in Latex mode
987/// P = use error to control shown precision
988/// F = force fixed precision
989///
990
991std::string RooRealVar::format(Int_t sigDigits, const char *options) const
992{
993 // parse the options string
994 TString opts(options);
995 opts.ToLower();
996
997 bool showName= opts.Contains("n");
998 bool showTitle = opts.Contains("t");
999 bool hideValue= opts.Contains("h");
1000 bool showError= opts.Contains("e");
1001 bool showUnit= opts.Contains("u");
1002 bool tlatexMode= opts.Contains("l");
1003 bool latexMode= opts.Contains("x");
1004 bool latexTableMode = opts.Contains("y") ;
1005 bool latexVerbatimName = opts.Contains("v") ;
1006
1007 std::string label = showName ? getPlotLabel() : "";
1008 if(showTitle) {
1009 label = GetTitle();
1010 if(label.empty()) label = getPlotLabel();
1011 }
1012
1014 bool asymError= opts.Contains("a") ;
1015 bool useErrorForPrecision= (((showError && hasError(false) && !isConstant()) || opts.Contains("p")) && !opts.Contains("f")) ;
1016 // calculate the precision to use
1017 if(sigDigits < 1) sigDigits= 1;
1020 leadingDigitVal = (Int_t)floor(log10(std::abs(_error+1e-10)));
1021 if (_value==0&&_error==0) leadingDigitVal=0 ;
1022 } else {
1023 leadingDigitVal = (Int_t)floor(log10(std::abs(_value+1e-10)));
1024 if (_value==0) leadingDigitVal=0 ;
1025 }
1026 Int_t leadingDigitErr= (Int_t)floor(log10(std::abs(_error+1e-10)));
1029
1030 if (_value<0) whereVal -= 1 ;
1031 int nDigitsVal = whereVal < 0 ? -whereVal : 0;
1032 int nDigitsErr = whereErr < 0 ? -whereErr : 0;
1033
1034 std::stringstream text;
1035
1036 if (latexMode)
1037 text << "$";
1038 // begin the string with "<name> = " if requested
1039 if(showName || showTitle) {
1041 text << "\\verb+";
1042 }
1043 text << label;
1045 text << "+";
1046
1047 if (!latexTableMode) {
1048 text << " = ";
1049 } else {
1050 text << " $ & $ ";
1051 }
1052 }
1053
1054 // Add leading space if value is positive
1055 if (_value >= 0)
1056 text << " ";
1057
1058 // append our value if requested
1059 text << std::fixed;
1060 if(!hideValue) {
1061 text << std::setprecision(nDigitsVal) << _value;
1062 }
1063 text << std::setprecision(nDigitsErr); // we only print errors from now on
1064
1065 // append our error if requested and this variable is not constant
1066 if(hasError(false) && showError && !(asymError && hasAsymError(false))) {
1067 if(tlatexMode) {
1068 text << " #pm " << getError();
1069 }
1070 else {
1071 text << (latexMode ? "\\pm " : " +/- ") << getError();
1072 }
1073 }
1074
1075 if (asymError && hasAsymError() && showError) {
1076 if(tlatexMode) {
1077 text << " #pm _{" << getAsymErrorLo() << "}^{+" << getAsymErrorHi() << "}";
1078 }
1079 else if(latexMode) {
1080 text << "\\pm _{" << getAsymErrorLo() << "}^{+" << getAsymErrorHi() << "}";
1081 }
1082 else {
1083 text << " +/- (" << getAsymErrorLo() << ", " << getAsymErrorHi() << ")";
1084 }
1085
1086 }
1087
1088 // append our units if requested
1089 if(!_unit.IsNull() && showUnit) {
1090 text << ' ' << _unit;
1091 }
1092 if (latexMode)
1093 text << "$";
1094 return text.str();
1095}
1096
1097////////////////////////////////////////////////////////////////////////////////
1098/// Overload RooAbsReal::attachToTree to also attach
1099/// branches for errors and/or asymmetric errors
1100/// attribute StoreError and/or StoreAsymError are set
1101
1103{
1104 // Follow usual procedure for value
1105
1106 if (getAttribute("StoreError") || getAttribute("StoreAsymError") || vstore.isFullReal(this) ) {
1107
1108 RooVectorDataStore::RealFullVector* rfv = vstore.addRealFull(this) ;
1109 rfv->setBuffer(this,&_value);
1110
1111 // Attach/create additional branch for error
1112 if (getAttribute("StoreError") || vstore.hasError(this) ) {
1113 rfv->setErrorBuffer(&_error) ;
1114 }
1115
1116 // Attach/create additional branches for asymmetric error
1117 if (getAttribute("StoreAsymError") || vstore.hasAsymError(this)) {
1118 rfv->setAsymErrorBuffer(&_asymErrLo,&_asymErrHi) ;
1119 }
1120
1121 } else {
1122
1124
1125 }
1126}
1127
1128
1129
1130////////////////////////////////////////////////////////////////////////////////
1131/// Overload RooAbsReal::attachToTree to also attach
1132/// branches for errors and/or asymmetric errors
1133/// attribute StoreError and/or StoreAsymError are set
1134
1136{
1137 // Follow usual procedure for value
1139// std::cout << "RooRealVar::attachToTree(" << this << ") name = " << GetName()
1140// << " StoreError = " << (getAttribute("StoreError")?"T":"F") << std::endl ;
1141
1142 // Attach/create additional branch for error
1143 if (getAttribute("StoreError")) {
1145 errName.Append("_err") ;
1147 if (branch) {
1149 } else {
1151 format2.Append("/D");
1152 t.Branch(errName, &_error, (const Text_t*)format2, bufSize);
1153 }
1154 }
1155
1156 // Attach/create additional branches for asymmetric error
1157 if (getAttribute("StoreAsymError")) {
1159 loName.Append("_aerr_lo") ;
1161 if (lobranch) {
1163 } else {
1165 format2.Append("/D");
1167 }
1168
1170 hiName.Append("_aerr_hi") ;
1172 if (hibranch) {
1174 } else {
1176 format2.Append("/D");
1178 }
1179 }
1180}
1181
1182
1183////////////////////////////////////////////////////////////////////////////////
1184/// Overload RooAbsReal::fillTreeBranch to also
1185/// fill tree branches with (asymmetric) errors
1186/// if requested.
1187
1189{
1190 // First determine if branch is taken
1193 if (!valBranch) {
1194 coutE(Eval) << "RooAbsReal::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << std::endl ;
1195 assert(0) ;
1196 }
1197 valBranch->Fill() ;
1198
1199 if (getAttribute("StoreError")) {
1201 errName.Append("_err") ;
1203 if (errBranch) errBranch->Fill() ;
1204 }
1205
1206 if (getAttribute("StoreAsymError")) {
1208 loName.Append("_aerr_lo") ;
1210 if (loBranch) loBranch->Fill() ;
1211
1213 hiName.Append("_aerr_hi") ;
1215 if (hiBranch) hiBranch->Fill() ;
1216 }
1217}
1218
1219
1220
1221////////////////////////////////////////////////////////////////////////////////
1222/// Copy the cached value of another RooAbsArg to our cache
1223/// Warning: This function copies the cached values of source,
1224/// it is the callers responsibility to make sure the cache is clean
1225
1227{
1228 // Follow usual procedure for valueklog
1229 double oldVal = _value;
1231 if(_value != oldVal) {
1233 }
1234
1235 if (valueOnly) return ;
1236
1237 // Copy error too, if source has one
1238 RooRealVar* other = dynamic_cast<RooRealVar*>(const_cast<RooAbsArg*>(source)) ;
1239 if (other) {
1240 // Copy additional error value
1241 _error = other->_error ;
1242 _asymErrLo = other->_asymErrLo ;
1243 _asymErrHi = other->_asymErrHi ;
1244 }
1245}
1246
1247
1248
1249////////////////////////////////////////////////////////////////////////////////
1250/// Stream an object of class RooRealVar.
1251
1253{
1254 UInt_t R__s;
1255 UInt_t R__c;
1256 if (R__b.IsReading()) {
1257
1258 Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
1260 if (R__v==1) {
1261 coutI(Eval) << "RooRealVar::Streamer(" << GetName() << ") converting version 1 data format" << std::endl ;
1262 double fitMin;
1263 double fitMax;
1264 Int_t fitBins ;
1265 R__b >> fitMin;
1266 R__b >> fitMax;
1267 R__b >> fitBins;
1268 _binning = std::make_unique<RooUniformBinning>(fitMin,fitMax,fitBins);
1269 }
1270 R__b >> _error;
1271 R__b >> _asymErrLo;
1272 R__b >> _asymErrHi;
1273 if (R__v>=2) {
1274 RooAbsBinning* binning;
1275 R__b >> binning;
1276 _binning.reset(binning);
1277 }
1278 if (R__v==3) {
1279 // In v3, properties were written as pointers, so read now and install:
1281 R__b >> tmpProp;
1282 installSharedProp(std::shared_ptr<RooRealVarSharedProperties>(tmpProp));
1283 }
1284 if (R__v>=4) {
1285 // In >= v4, properties were written directly, but they might be the "_nullProp"
1286 auto tmpProp = std::make_shared<RooRealVarSharedProperties>();
1287 tmpProp->Streamer(R__b);
1288 installSharedProp(std::move(tmpProp));
1289 }
1290
1291 R__b.CheckByteCount(R__s, R__c, RooRealVar::IsA());
1292
1293 } else {
1294
1295 R__c = R__b.WriteVersion(RooRealVar::IsA(), true);
1297 R__b << _error;
1298 R__b << _asymErrLo;
1299 R__b << _asymErrHi;
1300 R__b << _binning.get();
1301 if (_sharedProp) {
1302 _sharedProp->Streamer(R__b) ;
1303 } else {
1304 _nullProp().Streamer(R__b) ;
1305 }
1306 R__b.SetByteCount(R__c, true);
1307
1308 }
1309}
1310
1311/// Hand out our shared property, create on the fly and register
1312/// in shared map if necessary.
1313std::shared_ptr<RooRealVarSharedProperties> RooRealVar::sharedProp() const {
1314 if (!_sharedProp) {
1315 const_cast<RooRealVar*>(this)->installSharedProp(std::make_shared<RooRealVarSharedProperties>());
1316 }
1317
1318 return _sharedProp;
1319}
1320
1321
1322////////////////////////////////////////////////////////////////////////////////
1323/// Install the shared property into the member _sharedProp.
1324/// If a property with same name already exists, discard the incoming one,
1325/// and share the existing.
1326/// `nullptr` and properties equal to the RooRealVar::_nullProp will not be installed.
1327void RooRealVar::installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop) {
1328 if (prop == nullptr || (*prop == _nullProp())) {
1329 _sharedProp = nullptr;
1330 return;
1331 }
1332
1333
1334 auto& weakPtr = (*sharedPropList())[prop->uuid()];
1335 std::shared_ptr<RooRealVarSharedProperties> existingProp;
1336 if ( (existingProp = weakPtr.lock()) ) {
1337 // Property exists, discard incoming
1338 _sharedProp = std::move(existingProp);
1339 // Incoming is not allowed to delete the binnings now - they are owned by the other instance
1340 prop->disownBinnings();
1341 } else {
1342 // Doesn't exist. Install, register weak pointer for future sharing
1343 _sharedProp = std::move(prop);
1345 }
1346}
1347
1348
1349////////////////////////////////////////////////////////////////////////////////
1350/// Stop sharing properties.
1352{
1353 // Nothing to do if there were no shared properties to begin with.
1354 if(!_sharedProp) return;
1355
1356 // Get the key for the _sharedPropList.
1357 auto key = _sharedProp->uuid(); // we have to make a copy because _sharedPropList gets delete next.
1358
1359 // Actually delete the shared properties object.
1360 _sharedProp.reset();
1361
1362 // If the _sharedPropList was already deleted, we can return now.
1363 if(!sharedPropList()) return;
1364
1365 // Find the std::weak_ptr that the _sharedPropList holds to our
1366 // _sharedProp.
1367 auto iter = sharedPropList()->find(key);
1368
1369 // If no other RooRealVars shared the shared properties with us, the
1370 // weak_ptr in _sharedPropList is expired and we can erase it from the map.
1371 if(iter->second.expired()) {
1372 sharedPropList()->erase(iter);
1373 }
1374}
1375
1376
1377////////////////////////////////////////////////////////////////////////////////
1378/// If true, contents of RooRealVars will be printed in scientific notation
1379
1384
1385
1386////////////////////////////////////////////////////////////////////////////////
1387/// Set number of digits to show when printing RooRealVars
1388
#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:145
@ 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:567
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:566
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 setVal(double value) override
Set value of variable to 'value'.
double _error
Symmetric error associated with current value.
Definition RooRealVar.h:162
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:166
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:174
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:165
void removeRange(const char *name=nullptr) R__DEPRECATED(6
Remove range limits for binning with given name. Empty name means default range.
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:163
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:144
std::shared_ptr< RooRealVarSharedProperties > _sharedProp
! Shared binnings associated with this instance
Definition RooRealVar.h:178
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:180
~RooRealVar() override
Destructor.
double _asymErrHi
High side of asymmetric error associated with current value.
Definition RooRealVar.h:164
static Int_t _printSigDigits
Definition RooRealVar.h:145
static void cleanup()
Explicitly deletes the shared properties list on exit to avoid problems with the initialization order...
void removeRange was a misleading name Please use removeMin()\" and \"removeMax()\" instead
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:184
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