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