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 TString* tmp = format(_printSigDigits,"EFA") ;
731 os << tmp->Data() << " " ;
732 delete tmp ;
733 }
734
735 // Append limits if not constants
736 if (isConstant()) {
737 os << "C " ;
738 }
739
740 // Append fit limits
741 os << "L(" ;
742 if(hasMin()) {
743 os << getMin();
744 }
745 else {
746 os << "-INF";
747 }
748 if(hasMax()) {
749 os << " - " << getMax() ;
750 }
751 else {
752 os << " - +INF";
753 }
754 os << ") " ;
755
756 if (getBins()!=100) {
757 os << "B(" << getBins() << ") " ;
758 }
759
760 // Add comment with unit, if unit exists
761 if (!_unit.IsNull())
762 os << "// [" << getUnit() << "]" ;
763 }
764}
765
766
767
768////////////////////////////////////////////////////////////////////////////////
769/// Print value of variable
770
771void RooRealVar::printValue(ostream& os) const
772{
773 os << getVal() ;
774
775 if(hasError() && !hasAsymError()) {
776 os << " +/- " << getError() ;
777 } else if (hasAsymError()) {
778 os << " +/- (" << getAsymErrorLo() << "," << getAsymErrorHi() << ")" ;
779 }
780
781}
782
783
784////////////////////////////////////////////////////////////////////////////////
785/// Print extras of variable: (asymmetric) error, constant flag, limits and binning
786
787void RooRealVar::printExtras(ostream& os) const
788{
789 // Append limits if not constants
790 if (isConstant()) {
791 os << "C " ;
792 }
793
794 // Append fit limits
795 os << " L(" ;
796 if(hasMin()) {
797 os << getMin();
798 }
799 else {
800 os << "-INF";
801 }
802 if(hasMax()) {
803 os << " - " << getMax() ;
804 }
805 else {
806 os << " - +INF";
807 }
808 os << ") " ;
809
810 if (getBins()!=100) {
811 os << "B(" << getBins() << ") " ;
812 }
813
814 // Add comment with unit, if unit exists
815 if (!_unit.IsNull())
816 os << "// [" << getUnit() << "]" ;
817
818// cout << " _value = " << &_value << " _error = " << &_error ;
819
820
821}
822
823
824////////////////////////////////////////////////////////////////////////////////
825/// Mapping of Print() option string to RooPrintable contents specifications
826
828{
829 if (opt && TString(opt)=="I") {
830 return kName|kClassName|kValue ;
831 }
833}
834
835
836////////////////////////////////////////////////////////////////////////////////
837/// Detailed printing interface
838
839void RooRealVar::printMultiline(ostream& os, Int_t contents, bool verbose, TString indent) const
840{
842 os << indent << "--- RooRealVar ---" << endl;
843 TString unit(_unit);
844 if(!unit.IsNull()) unit.Prepend(' ');
845 os << indent << " Error = " << getError() << unit << endl;
846}
847
848
849
850////////////////////////////////////////////////////////////////////////////////
851/// Format contents of RooRealVar for pretty printing on RooPlot
852/// parameter boxes. This function processes the named arguments
853/// taken by paramOn() and translates them to an option string
854/// parsed by RooRealVar::format(Int_t sigDigits, const char *options)
855
856TString* RooRealVar::format(const RooCmdArg& formatArg) const
857{
858 RooCmdArg tmp(formatArg) ;
859 tmp.setProcessRecArgs(true) ;
860
861 RooCmdConfig pc(Form("RooRealVar::format(%s)",GetName())) ;
862 pc.defineString("what","FormatArgs",0,"") ;
863 pc.defineInt("autop","FormatArgs::AutoPrecision",0,2) ;
864 pc.defineInt("fixedp","FormatArgs::FixedPrecision",0,2) ;
865 pc.defineInt("tlatex","FormatArgs::TLatexStyle",0,0) ;
866 pc.defineInt("latex","FormatArgs::LatexStyle",0,0) ;
867 pc.defineInt("latext","FormatArgs::LatexTableStyle",0,0) ;
868 pc.defineInt("verbn","FormatArgs::VerbatimName",0,0) ;
869 pc.defineMutex("FormatArgs::TLatexStyle","FormatArgs::LatexStyle","FormatArgs::LatexTableStyle") ;
870 pc.defineMutex("FormatArgs::AutoPrecision","FormatArgs::FixedPrecision") ;
871
872 // Process & check varargs
873 pc.process(tmp) ;
874 if (!pc.ok(true)) {
875 return 0 ;
876 }
877
878 // Extract values from named arguments
879 TString options ;
880 options = pc.getString("what") ;
881
882 if (pc.getInt("tlatex")) {
883 options += "L" ;
884 } else if (pc.getInt("latex")) {
885 options += "X" ;
886 } else if (pc.getInt("latext")) {
887 options += "Y" ;
888 }
889
890 if (pc.getInt("verbn")) options += "V" ;
891 Int_t sigDigits = 2 ;
892 if (pc.hasProcessed("FormatArgs::AutoPrecision")) {
893 options += "P" ;
894 sigDigits = pc.getInt("autop") ;
895 } else if (pc.hasProcessed("FormatArgs::FixedPrecision")) {
896 options += "F" ;
897 sigDigits = pc.getInt("fixedp") ;
898 }
899
900 return format(sigDigits,options) ;
901}
902
903
904
905
906////////////////////////////////////////////////////////////////////////////////
907/// Format numeric value of RooRealVar and its error in a variety of ways
908///
909/// To control what is shown use the following options
910/// N = show name
911/// H = hide value
912/// E = show error
913/// A = show asymmetric error instead of parabolic error (if available)
914/// U = show unit
915///
916/// To control how it is shown use these options
917/// L = TLatex mode
918/// X = Latex mode
919/// Y = Latex table mode ( '=' replaced by '&' )
920/// V = Make name \\verbatim in Latex mode
921/// P = use error to control shown precision
922/// F = force fixed precision
923///
924
925TString *RooRealVar::format(Int_t sigDigits, const char *options) const
926{
927 //cout << "format = " << options << endl ;
928
929 // parse the options string
930 TString opts(options);
931 opts.ToLower();
932 bool showName= opts.Contains("n");
933 bool hideValue= opts.Contains("h");
934 bool showError= opts.Contains("e");
935 bool showUnit= opts.Contains("u");
936 bool tlatexMode= opts.Contains("l");
937 bool latexMode= opts.Contains("x");
938 bool latexTableMode = opts.Contains("y") ;
939 bool latexVerbatimName = opts.Contains("v") ;
940
941 if (latexTableMode) latexMode = true ;
942 bool asymError= opts.Contains("a") ;
943 bool useErrorForPrecision= (((showError && hasError(false) && !isConstant()) || opts.Contains("p")) && !opts.Contains("f")) ;
944 // calculate the precision to use
945 if(sigDigits < 1) sigDigits= 1;
946 Int_t leadingDigitVal = 0;
947 if (useErrorForPrecision) {
948 leadingDigitVal = (Int_t)floor(log10(fabs(_error+1e-10)));
949 if (_value==0&&_error==0) leadingDigitVal=0 ;
950 } else {
951 leadingDigitVal = (Int_t)floor(log10(fabs(_value+1e-10)));
952 if (_value==0) leadingDigitVal=0 ;
953 }
954 Int_t leadingDigitErr= (Int_t)floor(log10(fabs(_error+1e-10)));
955 Int_t whereVal= leadingDigitVal - sigDigits + 1;
956 Int_t whereErr= leadingDigitErr - sigDigits + 1;
957 char fmtVal[16], fmtErr[16];
958
959 if (_value<0) whereVal -= 1 ;
960 snprintf(fmtVal,16,"%%.%df", whereVal < 0 ? -whereVal : 0);
961 snprintf(fmtErr,16,"%%.%df", whereErr < 0 ? -whereErr : 0);
962 TString *text= new TString();
963 if(latexMode) text->Append("$");
964 // begin the string with "<name> = " if requested
965 if(showName) {
966 if (latexTableMode && latexVerbatimName) {
967 text->Append("\\verb+") ;
968 }
969 text->Append(getPlotLabel());
970 if (latexVerbatimName) text->Append("+") ;
971
972 if (!latexTableMode) {
973 text->Append(" = ");
974 } else {
975 text->Append(" $ & $ ");
976 }
977 }
978
979 // Add leading space if value is positive
980 if (_value>=0) text->Append(" ") ;
981
982 // append our value if requested
983 char buffer[256];
984 if(!hideValue) {
985 chopAt(_value, whereVal);
986 snprintf(buffer, 256,fmtVal, _value);
987 text->Append(buffer);
988 }
989
990 // append our error if requested and this variable is not constant
991 if(hasError(false) && showError && !(asymError && hasAsymError(false))) {
992 if(tlatexMode) {
993 text->Append(" #pm ");
994 }
995 else if(latexMode) {
996 text->Append("\\pm ");
997 }
998 else {
999 text->Append(" +/- ");
1000 }
1001 snprintf(buffer, 256,fmtErr, getError());
1002 text->Append(buffer);
1003 }
1004
1005 if (asymError && hasAsymError() && showError) {
1006 if(tlatexMode) {
1007 text->Append(" #pm ");
1008 text->Append("_{") ;
1009 snprintf(buffer, 256,fmtErr, getAsymErrorLo());
1010 text->Append(buffer);
1011 text->Append("}^{+") ;
1012 snprintf(buffer, 256,fmtErr, getAsymErrorHi());
1013 text->Append(buffer);
1014 text->Append("}") ;
1015 }
1016 else if(latexMode) {
1017 text->Append("\\pm ");
1018 text->Append("_{") ;
1019 snprintf(buffer, 256,fmtErr, getAsymErrorLo());
1020 text->Append(buffer);
1021 text->Append("}^{+") ;
1022 snprintf(buffer, 256,fmtErr, getAsymErrorHi());
1023 text->Append(buffer);
1024 text->Append("}") ;
1025 }
1026 else {
1027 text->Append(" +/- ");
1028 text->Append(" (") ;
1029 snprintf(buffer, 256, fmtErr, getAsymErrorLo());
1030 text->Append(buffer);
1031 text->Append(", ") ;
1032 snprintf(buffer, 256, fmtErr, getAsymErrorHi());
1033 text->Append(buffer);
1034 text->Append(")") ;
1035 }
1036
1037 }
1038
1039 // append our units if requested
1040 if(!_unit.IsNull() && showUnit) {
1041 text->Append(' ');
1042 text->Append(_unit);
1043 }
1044 if(latexMode) text->Append("$");
1045 return text;
1046}
1047
1048
1049
1050////////////////////////////////////////////////////////////////////////////////
1051/// Utility to calculate number of decimals to show
1052/// based on magnitude of error
1053
1054double RooRealVar::chopAt(double what, Int_t where) const
1055{
1056 double scale= pow(10.0,where);
1057 Int_t trunc= (Int_t)floor(what/scale + 0.5);
1058 return (double)trunc*scale;
1059}
1060
1061
1062
1063////////////////////////////////////////////////////////////////////////////////
1064/// Overload RooAbsReal::attachToTree to also attach
1065/// branches for errors and/or asymmetric errors
1066/// attribute StoreError and/or StoreAsymError are set
1067
1069{
1070 // Follow usual procedure for value
1071
1072 if (getAttribute("StoreError") || getAttribute("StoreAsymError") || vstore.isFullReal(this) ) {
1073
1075 rfv->setBuffer(this,&_value);
1076
1077 // Attach/create additional branch for error
1078 if (getAttribute("StoreError") || vstore.hasError(this) ) {
1079 rfv->setErrorBuffer(&_error) ;
1080 }
1081
1082 // Attach/create additional branches for asymmetric error
1083 if (getAttribute("StoreAsymError") || vstore.hasAsymError(this)) {
1085 }
1086
1087 } else {
1088
1090
1091 }
1092}
1093
1094
1095
1096////////////////////////////////////////////////////////////////////////////////
1097/// Overload RooAbsReal::attachToTree to also attach
1098/// branches for errors and/or asymmetric errors
1099/// attribute StoreError and/or StoreAsymError are set
1100
1102{
1103 // Follow usual procedure for value
1104 RooAbsReal::attachToTree(t,bufSize) ;
1105// cout << "RooRealVar::attachToTree(" << this << ") name = " << GetName()
1106// << " StoreError = " << (getAttribute("StoreError")?"T":"F") << endl ;
1107
1108 // Attach/create additional branch for error
1109 if (getAttribute("StoreError")) {
1110 TString errName(GetName()) ;
1111 errName.Append("_err") ;
1112 TBranch* branch = t.GetBranch(errName) ;
1113 if (branch) {
1114 t.SetBranchAddress(errName,&_error) ;
1115 } else {
1116 TString format2(errName);
1117 format2.Append("/D");
1118 t.Branch(errName, &_error, (const Text_t*)format2, bufSize);
1119 }
1120 }
1121
1122 // Attach/create additional branches for asymmetric error
1123 if (getAttribute("StoreAsymError")) {
1124 TString loName(GetName()) ;
1125 loName.Append("_aerr_lo") ;
1126 TBranch* lobranch = t.GetBranch(loName) ;
1127 if (lobranch) {
1128 t.SetBranchAddress(loName,&_asymErrLo) ;
1129 } else {
1130 TString format2(loName);
1131 format2.Append("/D");
1132 t.Branch(loName, &_asymErrLo, (const Text_t*)format2, bufSize);
1133 }
1134
1135 TString hiName(GetName()) ;
1136 hiName.Append("_aerr_hi") ;
1137 TBranch* hibranch = t.GetBranch(hiName) ;
1138 if (hibranch) {
1139 t.SetBranchAddress(hiName,&_asymErrHi) ;
1140 } else {
1141 TString format2(hiName);
1142 format2.Append("/D");
1143 t.Branch(hiName, &_asymErrHi, (const Text_t*)format2, bufSize);
1144 }
1145 }
1146}
1147
1148
1149////////////////////////////////////////////////////////////////////////////////
1150/// Overload RooAbsReal::fillTreeBranch to also
1151/// fill tree branches with (asymmetric) errors
1152/// if requested.
1153
1155{
1156 // First determine if branch is taken
1157 TString cleanName(cleanBranchName()) ;
1158 TBranch* valBranch = t.GetBranch(cleanName) ;
1159 if (!valBranch) {
1160 coutE(Eval) << "RooAbsReal::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << endl ;
1161 assert(0) ;
1162 }
1163 valBranch->Fill() ;
1164
1165 if (getAttribute("StoreError")) {
1166 TString errName(GetName()) ;
1167 errName.Append("_err") ;
1168 TBranch* errBranch = t.GetBranch(errName) ;
1169 if (errBranch) errBranch->Fill() ;
1170 }
1171
1172 if (getAttribute("StoreAsymError")) {
1173 TString loName(GetName()) ;
1174 loName.Append("_aerr_lo") ;
1175 TBranch* loBranch = t.GetBranch(loName) ;
1176 if (loBranch) loBranch->Fill() ;
1177
1178 TString hiName(GetName()) ;
1179 hiName.Append("_aerr_hi") ;
1180 TBranch* hiBranch = t.GetBranch(hiName) ;
1181 if (hiBranch) hiBranch->Fill() ;
1182 }
1183}
1184
1185
1186
1187////////////////////////////////////////////////////////////////////////////////
1188/// Copy the cached value of another RooAbsArg to our cache
1189/// Warning: This function copies the cached values of source,
1190/// it is the callers responsibility to make sure the cache is clean
1191
1192void RooRealVar::copyCache(const RooAbsArg* source, bool valueOnly, bool setValDirty)
1193{
1194 // Follow usual procedure for valueklog
1195 double oldVal = _value;
1196 RooAbsReal::copyCache(source,valueOnly,setValDirty) ;
1197 if(_value != oldVal) {
1199 }
1200
1201 if (valueOnly) return ;
1202
1203 // Copy error too, if source has one
1204 RooRealVar* other = dynamic_cast<RooRealVar*>(const_cast<RooAbsArg*>(source)) ;
1205 if (other) {
1206 // Copy additional error value
1207 _error = other->_error ;
1208 _asymErrLo = other->_asymErrLo ;
1209 _asymErrHi = other->_asymErrHi ;
1210 }
1211}
1212
1213
1214
1215////////////////////////////////////////////////////////////////////////////////
1216/// Stream an object of class RooRealVar.
1217
1219{
1220 UInt_t R__s, R__c;
1221 if (R__b.IsReading()) {
1222
1223 Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
1225 if (R__v==1) {
1226 coutI(Eval) << "RooRealVar::Streamer(" << GetName() << ") converting version 1 data format" << endl ;
1227 double fitMin, fitMax ;
1228 Int_t fitBins ;
1229 R__b >> fitMin;
1230 R__b >> fitMax;
1231 R__b >> fitBins;
1232 _binning.reset(new RooUniformBinning(fitMin,fitMax,fitBins));
1233 }
1234 R__b >> _error;
1235 R__b >> _asymErrLo;
1236 R__b >> _asymErrHi;
1237 if (R__v>=2) {
1238 RooAbsBinning* binning;
1239 R__b >> binning;
1240 _binning.reset(binning);
1241 }
1242 if (R__v==3) {
1243 // In v3, properties were written as pointers, so read now and install:
1245 R__b >> tmpProp;
1246 installSharedProp(std::shared_ptr<RooRealVarSharedProperties>(tmpProp));
1247 }
1248 if (R__v>=4) {
1249 // In >= v4, properties were written directly, but they might be the "_nullProp"
1250 auto tmpProp = std::make_shared<RooRealVarSharedProperties>();
1251 tmpProp->Streamer(R__b);
1252 installSharedProp(std::move(tmpProp));
1253 }
1254
1255 R__b.CheckByteCount(R__s, R__c, RooRealVar::IsA());
1256
1257 } else {
1258
1259 R__c = R__b.WriteVersion(RooRealVar::IsA(), true);
1261 R__b << _error;
1262 R__b << _asymErrLo;
1263 R__b << _asymErrHi;
1264 R__b << _binning.get();
1265 if (_sharedProp) {
1266 _sharedProp->Streamer(R__b) ;
1267 } else {
1268 _nullProp().Streamer(R__b) ;
1269 }
1270 R__b.SetByteCount(R__c, true);
1271
1272 }
1273}
1274
1275/// Hand out our shared property, create on the fly and register
1276/// in shared map if necessary.
1277std::shared_ptr<RooRealVarSharedProperties> RooRealVar::sharedProp() const {
1278 if (!_sharedProp) {
1279 const_cast<RooRealVar*>(this)->installSharedProp(std::make_shared<RooRealVarSharedProperties>());
1280 }
1281
1282 return _sharedProp;
1283}
1284
1285
1286////////////////////////////////////////////////////////////////////////////////
1287/// Install the shared property into the member _sharedProp.
1288/// If a property with same name already exists, discard the incoming one,
1289/// and share the existing.
1290/// `nullptr` and properties equal to the RooRealVar::_nullProp will not be installed.
1291void RooRealVar::installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop) {
1292 if (prop == nullptr || (*prop == _nullProp())) {
1293 _sharedProp = nullptr;
1294 return;
1295 }
1296
1297
1298 auto& weakPtr = (*sharedPropList())[prop->uuid()];
1299 std::shared_ptr<RooRealVarSharedProperties> existingProp;
1300 if ( (existingProp = weakPtr.lock()) ) {
1301 // Property exists, discard incoming
1302 _sharedProp = std::move(existingProp);
1303 // Incoming is not allowed to delete the binnings now - they are owned by the other instance
1304 prop->disownBinnings();
1305 } else {
1306 // Doesn't exist. Install, register weak pointer for future sharing
1307 _sharedProp = std::move(prop);
1308 weakPtr = _sharedProp;
1309 }
1310}
1311
1312
1313////////////////////////////////////////////////////////////////////////////////
1314/// Stop sharing properties.
1316{
1317 // Nothing to do if there were no shared properties to begin with.
1318 if(!_sharedProp) return;
1319
1320 // Get the key for the _sharedPropList.
1321 auto key = _sharedProp->uuid(); // we have to make a copy because _sharedPropList gets delete next.
1322
1323 // Actually delete the shared properties object.
1324 _sharedProp.reset();
1325
1326 // If the _sharedPropList was already deleted, we can return now.
1327 if(!sharedPropList()) return;
1328
1329 // Find the std::weak_ptr that the _sharedPropList holds to our
1330 // _sharedProp.
1331 auto iter = sharedPropList()->find(key);
1332
1333 // If no other RooRealVars shared the shared properties with us, the
1334 // weak_ptr in _sharedPropList is expired and we can erase it from the map.
1335 if(iter->second.expired()) {
1336 sharedPropList()->erase(iter);
1337 }
1338}
1339
1340
1341////////////////////////////////////////////////////////////////////////////////
1342/// If true, contents of RooRealVars will be printed in scientific notation
1343
1345{
1346 _printScientific = flag ;
1347}
1348
1349
1350////////////////////////////////////////////////////////////////////////////////
1351/// Set number of digits to show when printing RooRealVars
1352
1354{
1355 _printSigDigits = ndig>1?ndig:1 ;
1356}
#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:2452
#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:71
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition: RooAbsArg.h:495
bool isConstant() const
Check if the "Constant" attribute is set.
Definition: RooAbsArg.h:362
bool _fast
Definition: RooAbsArg.h:713
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:490
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
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:1978
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:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
TString _unit
Unit for objects value.
Definition: RooAbsReal.h:481
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:480
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:419
const Text_t * getUnit() const
Definition: RooAbsReal.h:147
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: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
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:771
void printExtras(std::ostream &os) const override
Print extras of variable: (asymmetric) error, constant flag, limits and binning.
Definition: RooRealVar.cxx:787
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:839
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:827
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:856
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:1155
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:447
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: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 > > floor(const RVec< T > &v)
Definition: RVec.hxx:1790
RVec< PromoteTypes< T0, T1 > > pow(const T0 &x, const RVec< T1 > &v)
Definition: RVec.hxx:1770
RVec< PromoteType< T > > trunc(const RVec< T > &v)
Definition: RVec.hxx:1792
RVec< PromoteType< T > > log10(const RVec< T > &v)
Definition: RVec.hxx:1766
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
@ InputArguments
Definition: RooGlobalFunc.h:62
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()