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