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#include "snprintf.h"
48
49using std::endl, std::ostream, std::istream;
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{
281 TString title(GetTitle());
282 name.Append("err") ;
283 title.Append(" Error") ;
284
285 return new RooErrorVar(name,title,*this) ;
286}
287
288
289
290////////////////////////////////////////////////////////////////////////////////
291/// Returns true if variable has a binning named 'name'.
292
293bool RooRealVar::hasBinning(const char* name) const
294{
295 return sharedProp()->_altBinning.find(name) != sharedProp()->_altBinning.end();
296}
297
298
299
300////////////////////////////////////////////////////////////////////////////////
301/// Return binning definition with name. If binning with 'name' is not found it is created
302/// on the fly as a clone of the default binning if createOnTheFly is true, otherwise
303/// a reference to the default binning is returned. If verbose is true a message
304/// is printed if a binning is created on the fly.
305
306const RooAbsBinning& RooRealVar::getBinning(const char* name, bool verbose, bool createOnTheFly) const
307{
308 return const_cast<RooRealVar*>(this)->getBinning(name, verbose, createOnTheFly) ;
309}
310
311
312
313////////////////////////////////////////////////////////////////////////////////
314/// Return binning definition with name. If binning with 'name' is not found it is created
315/// on the fly as a clone of the default binning if createOnTheFly is true, otherwise
316/// a reference to the default binning is returned. If verbose is true a message
317/// is printed if a binning is created on the fly.
318
319RooAbsBinning& RooRealVar::getBinning(const char* name, bool verbose, bool createOnTheFly)
320{
321 // Return default (normalization) binning and range if no name is specified
322 if (name==nullptr) {
323 return *_binning ;
324 }
325
326 if (strchr(name, ',')) {
327 coutW(InputArguments) << "Asking variable " << GetName() << "for binning '" << name
328 << "', but comma in binning names is not supported." << std::endl;
329 }
330
331 // Check if non-shared binning with this name has been created already
332 auto item = _altNonSharedBinning.find(name);
333 if (item != _altNonSharedBinning.end()) {
334 return *item->second;
335 }
336
337 // Check if binning with this name has been created already
338 auto item2 = sharedProp()->_altBinning.find(name);
339 if (item2 != sharedProp()->_altBinning.end()) {
340 return *item2->second;
341 }
342
343
344 // Return default binning if requested binning doesn't exist
345 if (!createOnTheFly) {
346 return *_binning ;
347 }
348
349 // Create a new RooRangeBinning with this name with default range
350 auto binning = new RooRangeBinning(getMin(),getMax(),name) ;
351 if (verbose) {
352 coutI(Eval) << "RooRealVar::getBinning(" << GetName() << ") new range named '"
353 << name << "' created with default bounds" << endl ;
354 }
355 sharedProp()->_altBinning[name] = binning;
356
357 return *binning ;
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// Get a list of all binning names. An empty name implies the default binning and
362/// a nullptr pointer should be passed to getBinning in this case.
363
364std::list<std::string> RooRealVar::getBinningNames() const
365{
366 std::list<std::string> binningNames;
367 if (_binning) {
368 binningNames.push_back("");
369 }
370
371 for (const auto& item : _altNonSharedBinning) {
372 binningNames.push_back(item.first);
373 }
374 for (const auto& item : sharedProp()->_altBinning) {
375 binningNames.push_back(item.first);
376 }
377
378 return binningNames;
379}
380
381void RooRealVar::removeMin(const char* name) {
383}
384void RooRealVar::removeMax(const char* name) {
386}
387void RooRealVar::removeRange(const char* name) {
389}
390
391
392////////////////////////////////////////////////////////////////////////////////
393/// Create a uniform binning under name 'name' for this variable.
394/// \param[in] nBins Number of bins. The limits are taken from the currently set limits.
395/// \param[in] name Optional name. If name is null, install as default binning.
396void RooRealVar::setBins(Int_t nBins, const char* name) {
398}
399
400////////////////////////////////////////////////////////////////////////////////
401/// Add given binning under name 'name' with this variable. If name is null,
402/// the binning is installed as the default binning.
403void RooRealVar::setBinning(const RooAbsBinning& binning, const char* name)
404{
405 std::unique_ptr<RooAbsBinning> newBinning( binning.clone() );
406
407 // Process insert hooks required for parameterized binnings
408 if (!name || name[0] == 0) {
409 if (_binning) {
410 _binning->removeHook(*this) ;
411 }
412 newBinning->insertHook(*this) ;
413 _binning = std::move(newBinning);
414 } else {
415 // Remove any old binning with this name
416 auto sharedProps = sharedProp();
417 auto item = sharedProps->_altBinning.find(name);
418 if (item != sharedProps->_altBinning.end()) {
419 item->second->removeHook(*this);
420 if (sharedProps->_ownBinnings)
421 delete item->second;
422
423 sharedProps->_altBinning.erase(item);
424 }
425 auto item2 = _altNonSharedBinning.find(name);
426 if (item2 != _altNonSharedBinning.end()) {
427 item2->second->removeHook(*this);
428 _altNonSharedBinning.erase(item2);
429 }
430
431 // Install new
432 newBinning->SetName(name) ;
433 newBinning->SetTitle(name) ;
434 newBinning->insertHook(*this) ;
435 if (newBinning->isShareable()) {
436 sharedProp()->_altBinning[name] = newBinning.release();
437 } else {
438 _altNonSharedBinning[name] = std::move(newBinning);
439 }
440 }
441}
442
443
444
445////////////////////////////////////////////////////////////////////////////////
446/// Set minimum of name range to given value. If name is null
447/// minimum of default range is set
448
449void RooRealVar::setMin(const char* name, double value)
450{
451 // Set new minimum of fit range
452 RooAbsBinning& binning = getBinning(name,true,true) ;
453
454 // Check if new limit is consistent
455 if (value >= getMax()) {
456 coutW(InputArguments) << "RooRealVar::setMin(" << GetName()
457 << "): Proposed new fit min. larger than max., setting min. to max." << endl ;
458 binning.setMin(getMax()) ;
459 } else {
460 binning.setMin(value) ;
461 }
462
463 // Clip current value in window if it fell out
464 if (!name) {
465 double clipValue ;
466 if (!inRange(_value,nullptr,&clipValue)) {
467 setVal(clipValue) ;
468 }
469 }
470
471 setShapeDirty() ;
472}
473
474
475////////////////////////////////////////////////////////////////////////////////
476/// Set maximum of name range to given value. If name is null
477/// maximum of default range is set
478
479void RooRealVar::setMax(const char* name, double value)
480{
481 // Set new maximum of fit range
482 RooAbsBinning& binning = getBinning(name,true,true) ;
483
484 // Check if new limit is consistent
485 if (value < getMin()) {
486 coutW(InputArguments) << "RooRealVar::setMax(" << GetName()
487 << "): Proposed new fit max. smaller than min., setting max. to min." << endl ;
488 binning.setMax(getMin()) ;
489 } else {
490 binning.setMax(value) ;
491 }
492
493 // Clip current value in window if it fell out
494 if (!name) {
495 double clipValue ;
496 if (!inRange(_value,nullptr,&clipValue)) {
497 setVal(clipValue) ;
498 }
499 }
500
501 setShapeDirty() ;
502}
503
504
505////////////////////////////////////////////////////////////////////////////////
506/// Set a fit or plotting range.
507/// Ranges can be selected for e.g. fitting, plotting or integration. Note that multiple
508/// variables can have ranges with the same name, so multi-dimensional PDFs can be sliced.
509/// See also the tutorial rf203_ranges.C
510/// \param[in] name Name this range (so it can be selected later for fitting or
511/// plotting). If the name is `nullptr`, the function sets the limits of the default range.
512/// \param[in] min Miniminum of the range.
513/// \param[in] max Maximum of the range.
514void RooRealVar::setRange(const char* name, double min, double max)
515{
516 bool exists = name == nullptr || sharedProp()->_altBinning.count(name) > 0;
517
518 // Set new fit range
519 RooAbsBinning& binning = getBinning(name,false,true) ;
520
521 // Check if new limit is consistent
522 if (min>max) {
523 coutW(InputArguments) << "RooRealVar::setRange(" << GetName()
524 << "): Proposed new fit max. smaller than min., setting max. to min." << endl ;
525 binning.setRange(min,min) ;
526 } else {
527 binning.setRange(min,max) ;
528 }
529
530 if (!exists) {
531 coutI(Eval) << "RooRealVar::setRange(" << GetName()
532 << ") new range named '" << name << "' created with bounds ["
533 << min << "," << max << "]" << endl ;
534 }
535
536 setShapeDirty() ;
537}
538
539
540
541////////////////////////////////////////////////////////////////////////////////
542/// Set or modify a parameterised range, i.e., a range the varies in dependence
543/// of parameters.
544/// See setRange() for more details.
545void RooRealVar::setRange(const char* name, RooAbsReal& min, RooAbsReal& max)
546{
547 RooParamBinning pb(min,max,100) ;
548 setBinning(pb,name) ;
549}
550
551
552
553////////////////////////////////////////////////////////////////////////////////
554/// Read object contents from given stream
555
556bool RooRealVar::readFromStream(istream& is, bool compact, bool verbose)
557{
558 TString token;
559 TString errorPrefix("RooRealVar::readFromStream(");
560 errorPrefix.Append(GetName()) ;
561 errorPrefix.Append(")") ;
562 RooStreamParser parser(is,errorPrefix) ;
563 double value(0) ;
564
565 if (compact) {
566 // Compact mode: Read single token
567 if (parser.readDouble(value,verbose)) return true ;
568 if (isValidReal(value,verbose)) {
569 setVal(value) ;
570 return false ;
571 } else {
572 return true ;
573 }
574
575 } else {
576 // Extended mode: Read multiple tokens on a single line
577 bool haveValue(false) ;
578 bool haveConstant(false) ;
579 removeError() ;
581
582 bool reprocessToken = false ;
583 while(true) {
584 if (parser.atEOL() || parser.atEOF()) break ;
585
586 if (!reprocessToken) {
587 token=parser.readToken() ;
588 }
589 reprocessToken = false ;
590
591 if (!token.CompareTo("+")) {
592
593 // Expect +/- as 3-token sequence
594 if (parser.expectToken("/",true) ||
595 parser.expectToken("-",true)) {
596 break ;
597 }
598
599 // Next token is error or asymmetric error, check if first char of token is a '('
600 TString tmp = parser.readToken() ;
601 if (tmp.CompareTo("(")) {
602 // Symmetric error, convert token do double
603
604 double error ;
605 parser.convertToDouble(tmp,error) ;
606 setError(error) ;
607
608 } else {
609 // Have error
610 double asymErrLo = 0.;
611 double asymErrHi = 0.;
612 if (parser.readDouble(asymErrLo,true) ||
613 parser.expectToken(",",true) ||
614 parser.readDouble(asymErrHi,true) ||
615 parser.expectToken(")",true)) break ;
616 setAsymError(asymErrLo,asymErrHi) ;
617 }
618
619 } else if (!token.CompareTo("C")) {
620
621 // Set constant
622 setConstant(true) ;
623 haveConstant = true ;
624
625 } else if (!token.CompareTo("P")) {
626
627 // Next tokens are plot limits
628 double plotMin(0);
629 double plotMax(0);
630 Int_t plotBins(0);
631 if (parser.expectToken("(",true) ||
632 parser.readDouble(plotMin,true) ||
633 parser.expectToken("-",true) ||
634 parser.readDouble(plotMax,true) ||
635 parser.expectToken(":",true) ||
636 parser.readInteger(plotBins,true) ||
637 parser.expectToken(")",true)) break ;
638// setPlotRange(plotMin,plotMax) ;
639 coutW(Eval) << "RooRealVar::readFromStream(" << GetName()
640 << ") WARNING: plot range deprecated, removed P(...) token" << endl ;
641
642 } else if (!token.CompareTo("F")) {
643
644 // Next tokens are fit limits
645 double fitMin;
646 double fitMax;
647 Int_t fitBins ;
648 if (parser.expectToken("(",true) ||
649 parser.readDouble(fitMin,true) ||
650 parser.expectToken("-",true) ||
651 parser.readDouble(fitMax,true) ||
652 parser.expectToken(":",true) ||
653 parser.readInteger(fitBins,true) ||
654 parser.expectToken(")",true)) break ;
655 //setBins(fitBins) ;
656 //setRange(fitMin,fitMax) ;
657 coutW(Eval) << "RooRealVar::readFromStream(" << GetName()
658 << ") WARNING: F(lo-hi:bins) token deprecated, use L(lo-hi) B(bins)" << endl ;
659 if (!haveConstant) setConstant(false) ;
660
661 } else if (!token.CompareTo("L")) {
662
663 // Next tokens are fit limits
664 double fitMin = 0.0;
665 double fitMax = 0.0;
666 // Int_t fitBins ;
667 if (parser.expectToken("(",true) ||
668 parser.readDouble(fitMin,true) ||
669 parser.expectToken("-",true) ||
670 parser.readDouble(fitMax,true) ||
671 parser.expectToken(")",true)) break ;
672 setRange(fitMin,fitMax) ;
673 if (!haveConstant) setConstant(false) ;
674
675 } else if (!token.CompareTo("B")) {
676
677 // Next tokens are fit limits
678 Int_t fitBins = 0;
679 if (parser.expectToken("(",true) ||
680 parser.readInteger(fitBins,true) ||
681 parser.expectToken(")",true)) break ;
682 setBins(fitBins) ;
683
684 } else {
685 // Token is value
686 if (parser.convertToDouble(token,value)) { parser.zapToEnd() ; break ; }
687 haveValue = true ;
688 // Defer value assignment to end
689 }
690 }
691 if (haveValue) setVal(value) ;
692 return false ;
693 }
694}
695
696
697////////////////////////////////////////////////////////////////////////////////
698/// Write object contents to given stream
699
700void RooRealVar::writeToStream(ostream& os, bool compact) const
701{
702 if (compact) {
703 // Write value only
704 os << getVal() ;
705 } else {
706
707 // Write value with error (if not zero)
708 if (_printScientific) {
709 char fmtVal[16];
710 char fmtErr[16];
711 snprintf(fmtVal,16,"%%.%de",_printSigDigits) ;
712 snprintf(fmtErr,16,"%%.%de",(_printSigDigits+1)/2) ;
713 if (_value>=0) os << " " ;
714 os << Form(fmtVal,_value) ;
715
716 if (hasAsymError()) {
717 os << " +/- (" << Form(fmtErr,getAsymErrorLo())
718 << ", " << Form(fmtErr,getAsymErrorHi()) << ")" ;
719 } else if (hasError()) {
720 os << " +/- " << Form(fmtErr,getError()) ;
721 }
722
723 os << " " ;
724 } else {
725 os << std::unique_ptr<TString>{format(_printSigDigits,"EFA")}->Data() << " " ;
726 }
727
728 // Append limits if not constants
729 if (isConstant()) {
730 os << "C " ;
731 }
732
733 // Append fit limits
734 os << "L(" ;
735 if(hasMin()) {
736 os << getMin();
737 }
738 else {
739 os << "-INF";
740 }
741 if(hasMax()) {
742 os << " - " << getMax() ;
743 }
744 else {
745 os << " - +INF";
746 }
747 os << ") " ;
748
749 if (getBins()!=100) {
750 os << "B(" << getBins() << ") " ;
751 }
752
753 // Add comment with unit, if unit exists
754 if (!_unit.IsNull())
755 os << "// [" << getUnit() << "]" ;
756 }
757}
758
759
760
761////////////////////////////////////////////////////////////////////////////////
762/// Print value of variable
763
764void RooRealVar::printValue(ostream& os) const
765{
766 os << getVal() ;
767
768 if(hasError() && !hasAsymError()) {
769 os << " +/- " << getError() ;
770 } else if (hasAsymError()) {
771 os << " +/- (" << getAsymErrorLo() << "," << getAsymErrorHi() << ")" ;
772 }
773
774}
775
776
777////////////////////////////////////////////////////////////////////////////////
778/// Print extras of variable: (asymmetric) error, constant flag, limits and binning
779
780void RooRealVar::printExtras(ostream& os) const
781{
782 // Append limits if not constants
783 if (isConstant()) {
784 os << "C " ;
785 }
786
787 // Append fit limits
788 os << " L(" ;
789 if(hasMin()) {
790 os << getMin();
791 }
792 else {
793 os << "-INF";
794 }
795 if(hasMax()) {
796 os << " - " << getMax() ;
797 }
798 else {
799 os << " - +INF";
800 }
801 os << ") " ;
802
803 if (getBins()!=100) {
804 os << "B(" << getBins() << ") " ;
805 }
806
807 // Add comment with unit, if unit exists
808 if (!_unit.IsNull())
809 os << "// [" << getUnit() << "]" ;
810
811// cout << " _value = " << &_value << " _error = " << &_error ;
812
813
814}
815
816
817////////////////////////////////////////////////////////////////////////////////
818/// Mapping of Print() option string to RooPrintable contents specifications
819
821{
822 if (opt && TString(opt)=="I") {
823 return kName|kClassName|kValue ;
824 }
826}
827
828
829////////////////////////////////////////////////////////////////////////////////
830/// Detailed printing interface
831
832void RooRealVar::printMultiline(ostream& os, Int_t contents, bool verbose, TString indent) const
833{
834 RooAbsRealLValue::printMultiline(os,contents,verbose,indent);
835 os << indent << "--- RooRealVar ---" << endl;
836 TString unit(_unit);
837 if(!unit.IsNull()) unit.Prepend(' ');
838 os << indent << " Error = " << getError() << unit << endl;
839}
840
841
842
843////////////////////////////////////////////////////////////////////////////////
844/// Format contents of RooRealVar for pretty printing on RooPlot
845/// parameter boxes. This function processes the named arguments
846/// taken by paramOn() and translates them to an option string
847/// parsed by RooRealVar::format(Int_t sigDigits, const char *options)
848
849TString* RooRealVar::format(const RooCmdArg& formatArg) const
850{
851 RooCmdArg tmp(formatArg) ;
852 tmp.setProcessRecArgs(true) ;
853
854 RooCmdConfig pc("RooRealVar::format(" + std::string(GetName()) + ")");
855 pc.defineString("what","FormatArgs",0,"") ;
856 pc.defineInt("autop","FormatArgs::AutoPrecision",0,2) ;
857 pc.defineInt("fixedp","FormatArgs::FixedPrecision",0,2) ;
858 pc.defineInt("tlatex","FormatArgs::TLatexStyle",0,0) ;
859 pc.defineInt("latex","FormatArgs::LatexStyle",0,0) ;
860 pc.defineInt("latext","FormatArgs::LatexTableStyle",0,0) ;
861 pc.defineInt("verbn","FormatArgs::VerbatimName",0,0) ;
862 pc.defineMutex("FormatArgs::TLatexStyle","FormatArgs::LatexStyle","FormatArgs::LatexTableStyle") ;
863 pc.defineMutex("FormatArgs::AutoPrecision","FormatArgs::FixedPrecision") ;
864
865 // Process & check varargs
866 pc.process(tmp) ;
867 if (!pc.ok(true)) {
868 return nullptr ;
869 }
870
871 // Extract values from named arguments
872 TString options ;
873 options = pc.getString("what") ;
874
875 if (pc.getInt("tlatex")) {
876 options += "L" ;
877 } else if (pc.getInt("latex")) {
878 options += "X" ;
879 } else if (pc.getInt("latext")) {
880 options += "Y" ;
881 }
882
883 if (pc.getInt("verbn")) options += "V" ;
884 Int_t sigDigits = 2 ;
885 if (pc.hasProcessed("FormatArgs::AutoPrecision")) {
886 options += "P" ;
887 sigDigits = pc.getInt("autop") ;
888 } else if (pc.hasProcessed("FormatArgs::FixedPrecision")) {
889 options += "F" ;
890 sigDigits = pc.getInt("fixedp") ;
891 }
892
893 return format(sigDigits,options) ;
894}
895
896
897
898
899////////////////////////////////////////////////////////////////////////////////
900/// Format numeric value of RooRealVar and its error in a variety of ways
901///
902/// To control what is shown use the following options
903/// N = show name
904/// T = show title (takes precedent over `N`, falls back to `N` if title is empty)
905/// H = hide value
906/// E = show error
907/// A = show asymmetric error instead of parabolic error (if available)
908/// U = show unit
909///
910/// To control how it is shown use these options
911/// L = TLatex mode
912/// X = Latex mode
913/// Y = Latex table mode ( '=' replaced by '&' )
914/// V = Make name \\verbatim in Latex mode
915/// P = use error to control shown precision
916/// F = force fixed precision
917///
918
919TString *RooRealVar::format(Int_t sigDigits, const char *options) const
920{
921 // parse the options string
922 TString opts(options);
923 opts.ToLower();
924
925 bool showName= opts.Contains("n");
926 bool showTitle = opts.Contains("t");
927 bool hideValue= opts.Contains("h");
928 bool showError= opts.Contains("e");
929 bool showUnit= opts.Contains("u");
930 bool tlatexMode= opts.Contains("l");
931 bool latexMode= opts.Contains("x");
932 bool latexTableMode = opts.Contains("y") ;
933 bool latexVerbatimName = opts.Contains("v") ;
934
935 std::string label = showName ? getPlotLabel() : "";
936 if(showTitle) {
937 label = GetTitle();
938 if(label.empty()) label = getPlotLabel();
939 }
940
941 if (latexTableMode) latexMode = true ;
942 bool asymError= opts.Contains("a") ;
943 bool useErrorForPrecision= (((showError && hasError(false) && !isConstant()) || opts.Contains("p")) && !opts.Contains("f")) ;
944 // calculate the precision to use
945 if(sigDigits < 1) sigDigits= 1;
946 Int_t leadingDigitVal = 0;
947 if (useErrorForPrecision) {
948 leadingDigitVal = (Int_t)floor(log10(std::abs(_error+1e-10)));
949 if (_value==0&&_error==0) leadingDigitVal=0 ;
950 } else {
951 leadingDigitVal = (Int_t)floor(log10(std::abs(_value+1e-10)));
952 if (_value==0) leadingDigitVal=0 ;
953 }
954 Int_t leadingDigitErr= (Int_t)floor(log10(std::abs(_error+1e-10)));
955 Int_t whereVal= leadingDigitVal - sigDigits + 1;
956 Int_t whereErr= leadingDigitErr - sigDigits + 1;
957 char fmtVal[16];
958 char fmtErr[16];
959
960 if (_value<0) whereVal -= 1 ;
961 snprintf(fmtVal,16,"%%.%df", whereVal < 0 ? -whereVal : 0);
962 snprintf(fmtErr,16,"%%.%df", whereErr < 0 ? -whereErr : 0);
963 TString *text= new TString();
964 if(latexMode) text->Append("$");
965 // begin the string with "<name> = " if requested
966 if(showName || showTitle) {
967 if (latexTableMode && latexVerbatimName) {
968 text->Append("\\verb+") ;
969 }
970 text->Append(label);
971 if (latexVerbatimName) text->Append("+") ;
972
973 if (!latexTableMode) {
974 text->Append(" = ");
975 } else {
976 text->Append(" $ & $ ");
977 }
978 }
979
980 // Add leading space if value is positive
981 if (_value>=0) text->Append(" ") ;
982
983 // append our value if requested
984 char buffer[256];
985 if(!hideValue) {
986 chopAt(_value, whereVal);
987 snprintf(buffer, 256,fmtVal, _value);
988 text->Append(buffer);
989 }
990
991 // append our error if requested and this variable is not constant
992 if(hasError(false) && showError && !(asymError && hasAsymError(false))) {
993 if(tlatexMode) {
994 text->Append(" #pm ");
995 }
996 else if(latexMode) {
997 text->Append("\\pm ");
998 }
999 else {
1000 text->Append(" +/- ");
1001 }
1002 snprintf(buffer, 256,fmtErr, getError());
1003 text->Append(buffer);
1004 }
1005
1006 if (asymError && hasAsymError() && showError) {
1007 if(tlatexMode) {
1008 text->Append(" #pm ");
1009 text->Append("_{") ;
1010 snprintf(buffer, 256,fmtErr, getAsymErrorLo());
1011 text->Append(buffer);
1012 text->Append("}^{+") ;
1013 snprintf(buffer, 256,fmtErr, getAsymErrorHi());
1014 text->Append(buffer);
1015 text->Append("}") ;
1016 }
1017 else if(latexMode) {
1018 text->Append("\\pm ");
1019 text->Append("_{") ;
1020 snprintf(buffer, 256,fmtErr, getAsymErrorLo());
1021 text->Append(buffer);
1022 text->Append("}^{+") ;
1023 snprintf(buffer, 256,fmtErr, getAsymErrorHi());
1024 text->Append(buffer);
1025 text->Append("}") ;
1026 }
1027 else {
1028 text->Append(" +/- ");
1029 text->Append(" (") ;
1030 snprintf(buffer, 256, fmtErr, getAsymErrorLo());
1031 text->Append(buffer);
1032 text->Append(", ") ;
1033 snprintf(buffer, 256, fmtErr, getAsymErrorHi());
1034 text->Append(buffer);
1035 text->Append(")") ;
1036 }
1037
1038 }
1039
1040 // append our units if requested
1041 if(!_unit.IsNull() && showUnit) {
1042 text->Append(' ');
1043 text->Append(_unit);
1044 }
1045 if(latexMode) text->Append("$");
1046 return text;
1047}
1048
1049
1050
1051////////////////////////////////////////////////////////////////////////////////
1052/// Utility to calculate number of decimals to show
1053/// based on magnitude of error
1054
1055double RooRealVar::chopAt(double what, Int_t where) const
1056{
1057 double scale= pow(10.0,where);
1058 Int_t trunc= (Int_t)floor(what/scale + 0.5);
1059 return (double)trunc*scale;
1060}
1061
1062
1063
1064////////////////////////////////////////////////////////////////////////////////
1065/// Overload RooAbsReal::attachToTree to also attach
1066/// branches for errors and/or asymmetric errors
1067/// attribute StoreError and/or StoreAsymError are set
1068
1070{
1071 // Follow usual procedure for value
1072
1073 if (getAttribute("StoreError") || getAttribute("StoreAsymError") || vstore.isFullReal(this) ) {
1074
1076 rfv->setBuffer(this,&_value);
1077
1078 // Attach/create additional branch for error
1079 if (getAttribute("StoreError") || vstore.hasError(this) ) {
1080 rfv->setErrorBuffer(&_error) ;
1081 }
1082
1083 // Attach/create additional branches for asymmetric error
1084 if (getAttribute("StoreAsymError") || vstore.hasAsymError(this)) {
1086 }
1087
1088 } else {
1089
1091
1092 }
1093}
1094
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 RooAbsReal::attachToTree(t,bufSize) ;
1106// cout << "RooRealVar::attachToTree(" << this << ") name = " << GetName()
1107// << " StoreError = " << (getAttribute("StoreError")?"T":"F") << endl ;
1108
1109 // Attach/create additional branch for error
1110 if (getAttribute("StoreError")) {
1111 TString errName(GetName()) ;
1112 errName.Append("_err") ;
1113 TBranch* branch = t.GetBranch(errName) ;
1114 if (branch) {
1115 t.SetBranchAddress(errName,&_error) ;
1116 } else {
1117 TString format2(errName);
1118 format2.Append("/D");
1119 t.Branch(errName, &_error, (const Text_t*)format2, bufSize);
1120 }
1121 }
1122
1123 // Attach/create additional branches for asymmetric error
1124 if (getAttribute("StoreAsymError")) {
1125 TString loName(GetName()) ;
1126 loName.Append("_aerr_lo") ;
1127 TBranch* lobranch = t.GetBranch(loName) ;
1128 if (lobranch) {
1129 t.SetBranchAddress(loName,&_asymErrLo) ;
1130 } else {
1131 TString format2(loName);
1132 format2.Append("/D");
1133 t.Branch(loName, &_asymErrLo, (const Text_t*)format2, bufSize);
1134 }
1135
1136 TString hiName(GetName()) ;
1137 hiName.Append("_aerr_hi") ;
1138 TBranch* hibranch = t.GetBranch(hiName) ;
1139 if (hibranch) {
1140 t.SetBranchAddress(hiName,&_asymErrHi) ;
1141 } else {
1142 TString format2(hiName);
1143 format2.Append("/D");
1144 t.Branch(hiName, &_asymErrHi, (const Text_t*)format2, bufSize);
1145 }
1146 }
1147}
1148
1149
1150////////////////////////////////////////////////////////////////////////////////
1151/// Overload RooAbsReal::fillTreeBranch to also
1152/// fill tree branches with (asymmetric) errors
1153/// if requested.
1154
1156{
1157 // First determine if branch is taken
1158 TString cleanName(cleanBranchName()) ;
1159 TBranch* valBranch = t.GetBranch(cleanName) ;
1160 if (!valBranch) {
1161 coutE(Eval) << "RooAbsReal::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << endl ;
1162 assert(0) ;
1163 }
1164 valBranch->Fill() ;
1165
1166 if (getAttribute("StoreError")) {
1167 TString errName(GetName()) ;
1168 errName.Append("_err") ;
1169 TBranch* errBranch = t.GetBranch(errName) ;
1170 if (errBranch) errBranch->Fill() ;
1171 }
1172
1173 if (getAttribute("StoreAsymError")) {
1174 TString loName(GetName()) ;
1175 loName.Append("_aerr_lo") ;
1176 TBranch* loBranch = t.GetBranch(loName) ;
1177 if (loBranch) loBranch->Fill() ;
1178
1179 TString hiName(GetName()) ;
1180 hiName.Append("_aerr_hi") ;
1181 TBranch* hiBranch = t.GetBranch(hiName) ;
1182 if (hiBranch) hiBranch->Fill() ;
1183 }
1184}
1185
1186
1187
1188////////////////////////////////////////////////////////////////////////////////
1189/// Copy the cached value of another RooAbsArg to our cache
1190/// Warning: This function copies the cached values of source,
1191/// it is the callers responsibility to make sure the cache is clean
1192
1193void RooRealVar::copyCache(const RooAbsArg* source, bool valueOnly, bool setValDirty)
1194{
1195 // Follow usual procedure for valueklog
1196 double oldVal = _value;
1197 RooAbsReal::copyCache(source,valueOnly,setValDirty) ;
1198 if(_value != oldVal) {
1200 }
1201
1202 if (valueOnly) return ;
1203
1204 // Copy error too, if source has one
1205 RooRealVar* other = dynamic_cast<RooRealVar*>(const_cast<RooAbsArg*>(source)) ;
1206 if (other) {
1207 // Copy additional error value
1208 _error = other->_error ;
1209 _asymErrLo = other->_asymErrLo ;
1210 _asymErrHi = other->_asymErrHi ;
1211 }
1212}
1213
1214
1215
1216////////////////////////////////////////////////////////////////////////////////
1217/// Stream an object of class RooRealVar.
1218
1220{
1221 UInt_t R__s;
1222 UInt_t R__c;
1223 if (R__b.IsReading()) {
1224
1225 Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
1227 if (R__v==1) {
1228 coutI(Eval) << "RooRealVar::Streamer(" << GetName() << ") converting version 1 data format" << endl ;
1229 double fitMin;
1230 double fitMax;
1231 Int_t fitBins ;
1232 R__b >> fitMin;
1233 R__b >> fitMax;
1234 R__b >> fitBins;
1235 _binning = std::make_unique<RooUniformBinning>(fitMin,fitMax,fitBins);
1236 }
1237 R__b >> _error;
1238 R__b >> _asymErrLo;
1239 R__b >> _asymErrHi;
1240 if (R__v>=2) {
1241 RooAbsBinning* binning;
1242 R__b >> binning;
1243 _binning.reset(binning);
1244 }
1245 if (R__v==3) {
1246 // In v3, properties were written as pointers, so read now and install:
1248 R__b >> tmpProp;
1249 installSharedProp(std::shared_ptr<RooRealVarSharedProperties>(tmpProp));
1250 }
1251 if (R__v>=4) {
1252 // In >= v4, properties were written directly, but they might be the "_nullProp"
1253 auto tmpProp = std::make_shared<RooRealVarSharedProperties>();
1254 tmpProp->Streamer(R__b);
1255 installSharedProp(std::move(tmpProp));
1256 }
1257
1258 R__b.CheckByteCount(R__s, R__c, RooRealVar::IsA());
1259
1260 } else {
1261
1262 R__c = R__b.WriteVersion(RooRealVar::IsA(), true);
1264 R__b << _error;
1265 R__b << _asymErrLo;
1266 R__b << _asymErrHi;
1267 R__b << _binning.get();
1268 if (_sharedProp) {
1269 _sharedProp->Streamer(R__b) ;
1270 } else {
1271 _nullProp().Streamer(R__b) ;
1272 }
1273 R__b.SetByteCount(R__c, true);
1274
1275 }
1276}
1277
1278/// Hand out our shared property, create on the fly and register
1279/// in shared map if necessary.
1280std::shared_ptr<RooRealVarSharedProperties> RooRealVar::sharedProp() const {
1281 if (!_sharedProp) {
1282 const_cast<RooRealVar*>(this)->installSharedProp(std::make_shared<RooRealVarSharedProperties>());
1283 }
1284
1285 return _sharedProp;
1286}
1287
1288
1289////////////////////////////////////////////////////////////////////////////////
1290/// Install the shared property into the member _sharedProp.
1291/// If a property with same name already exists, discard the incoming one,
1292/// and share the existing.
1293/// `nullptr` and properties equal to the RooRealVar::_nullProp will not be installed.
1294void RooRealVar::installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop) {
1295 if (prop == nullptr || (*prop == _nullProp())) {
1296 _sharedProp = nullptr;
1297 return;
1298 }
1299
1300
1301 auto& weakPtr = (*sharedPropList())[prop->uuid()];
1302 std::shared_ptr<RooRealVarSharedProperties> existingProp;
1303 if ( (existingProp = weakPtr.lock()) ) {
1304 // Property exists, discard incoming
1305 _sharedProp = std::move(existingProp);
1306 // Incoming is not allowed to delete the binnings now - they are owned by the other instance
1307 prop->disownBinnings();
1308 } else {
1309 // Doesn't exist. Install, register weak pointer for future sharing
1310 _sharedProp = std::move(prop);
1311 weakPtr = _sharedProp;
1312 }
1313}
1314
1315
1316////////////////////////////////////////////////////////////////////////////////
1317/// Stop sharing properties.
1319{
1320 // Nothing to do if there were no shared properties to begin with.
1321 if(!_sharedProp) return;
1322
1323 // Get the key for the _sharedPropList.
1324 auto key = _sharedProp->uuid(); // we have to make a copy because _sharedPropList gets delete next.
1325
1326 // Actually delete the shared properties object.
1327 _sharedProp.reset();
1328
1329 // If the _sharedPropList was already deleted, we can return now.
1330 if(!sharedPropList()) return;
1331
1332 // Find the std::weak_ptr that the _sharedPropList holds to our
1333 // _sharedProp.
1334 auto iter = sharedPropList()->find(key);
1335
1336 // If no other RooRealVars shared the shared properties with us, the
1337 // weak_ptr in _sharedPropList is expired and we can erase it from the map.
1338 if(iter->second.expired()) {
1339 sharedPropList()->erase(iter);
1340 }
1341}
1342
1343
1344////////////////////////////////////////////////////////////////////////////////
1345/// If true, contents of RooRealVars will be printed in scientific notation
1346
1348{
1349 _printScientific = flag ;
1350}
1351
1352
1353////////////////////////////////////////////////////////////////////////////////
1354/// Set number of digits to show when printing RooRealVars
1355
1357{
1358 _printSigDigits = ndig>1?ndig:1 ;
1359}
#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:382
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:2489
@ 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:467
bool isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:335
bool _fast
Definition RooAbsArg.h:689
friend void RooRefArray::Streamer(TBuffer &)
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:462
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:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
TString _unit
Unit for objects value.
Definition RooAbsReal.h:537
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:536
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: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
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
Implementation of RooAbsBinning that constructs a binning with a range definition that depends on ext...
Binning/range definition that only defines a range but no binning.
Implementation of RooSharedProperties that stores the properties of a RooRealVar that are shared amon...
void Streamer(TBuffer &) override
Stream an object of class TObject.
Variable that can be changed from the outside.
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.
Implementation of RooAbsBinning that provides a uniform binning in 'n' bins between the range end poi...
void setAsymErrorBuffer(double *newBufL, double *newBufH)
void setBuffer(RooAbsReal *real, double *newBuf)
Uses std::vector 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:1182
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:457
TString & Prepend(const char *cs)
Definition TString.h:673
Bool_t IsNull() const
Definition TString.h:414
TString & Append(const char *cs)
Definition TString.h:572
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
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:5294
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=nullptr)
Change branch address, dealing with clone trees properly.
Definition TTree.cxx:8385
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:5