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