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