Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooRealVar.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooRealVar.cxx
19\class RooRealVar
20\ingroup Roofitcore
21
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 ;
578 if (isValidReal(value,verbose)) {
579 setVal(value) ;
580 return false ;
581 } else {
582 return true ;
583 }
584
585 } else {
586 // Extended mode: Read multiple tokens on a single line
587 bool haveValue(false) ;
588 bool haveConstant(false) ;
589 removeError() ;
591
592 bool reprocessToken = false ;
593 while(1) {
594 if (parser.atEOL() || parser.atEOF()) break ;
595
596 if (!reprocessToken) {
597 token=parser.readToken() ;
598 }
599 reprocessToken = false ;
600
601 if (!token.CompareTo("+")) {
602
603 // Expect +/- as 3-token sequence
604 if (parser.expectToken("/",true) ||
605 parser.expectToken("-",true)) {
606 break ;
607 }
608
609 // Next token is error or asymmetric error, check if first char of token is a '('
610 TString tmp = parser.readToken() ;
611 if (tmp.CompareTo("(")) {
612 // Symmetric error, convert token do double
613
614 double error ;
615 parser.convertToDouble(tmp,error) ;
616 setError(error) ;
617
618 } else {
619 // Have error
620 double asymErrLo=0., asymErrHi=0.;
621 if (parser.readDouble(asymErrLo,true) ||
622 parser.expectToken(",",true) ||
623 parser.readDouble(asymErrHi,true) ||
624 parser.expectToken(")",true)) break ;
625 setAsymError(asymErrLo,asymErrHi) ;
626 }
627
628 } else if (!token.CompareTo("C")) {
629
630 // Set constant
631 setConstant(true) ;
632 haveConstant = true ;
633
634 } else if (!token.CompareTo("P")) {
635
636 // Next tokens are plot limits
637 double plotMin(0), plotMax(0) ;
638 Int_t plotBins(0) ;
639 if (parser.expectToken("(",true) ||
640 parser.readDouble(plotMin,true) ||
641 parser.expectToken("-",true) ||
642 parser.readDouble(plotMax,true) ||
643 parser.expectToken(":",true) ||
644 parser.readInteger(plotBins,true) ||
645 parser.expectToken(")",true)) break ;
646// setPlotRange(plotMin,plotMax) ;
647 coutW(Eval) << "RooRealVar::readFromStrem(" << GetName()
648 << ") WARNING: plot range deprecated, removed P(...) token" << endl ;
649
650 } else if (!token.CompareTo("F")) {
651
652 // Next tokens are fit limits
653 double fitMin, fitMax ;
654 Int_t fitBins ;
655 if (parser.expectToken("(",true) ||
656 parser.readDouble(fitMin,true) ||
657 parser.expectToken("-",true) ||
658 parser.readDouble(fitMax,true) ||
659 parser.expectToken(":",true) ||
660 parser.readInteger(fitBins,true) ||
661 parser.expectToken(")",true)) break ;
662 //setBins(fitBins) ;
663 //setRange(fitMin,fitMax) ;
664 coutW(Eval) << "RooRealVar::readFromStream(" << GetName()
665 << ") WARNING: F(lo-hi:bins) token deprecated, use L(lo-hi) B(bins)" << endl ;
666 if (!haveConstant) setConstant(false) ;
667
668 } else if (!token.CompareTo("L")) {
669
670 // Next tokens are fit limits
671 double fitMin = 0.0, fitMax = 0.0;
672// Int_t fitBins ;
673 if (parser.expectToken("(",true) ||
674 parser.readDouble(fitMin,true) ||
675 parser.expectToken("-",true) ||
676 parser.readDouble(fitMax,true) ||
677 parser.expectToken(")",true)) break ;
678 setRange(fitMin,fitMax) ;
679 if (!haveConstant) setConstant(false) ;
680
681 } else if (!token.CompareTo("B")) {
682
683 // Next tokens are fit limits
684 Int_t fitBins = 0;
685 if (parser.expectToken("(",true) ||
686 parser.readInteger(fitBins,true) ||
687 parser.expectToken(")",true)) break ;
688 setBins(fitBins) ;
689
690 } else {
691 // Token is value
692 if (parser.convertToDouble(token,value)) { parser.zapToEnd() ; break ; }
693 haveValue = true ;
694 // Defer value assignment to end
695 }
696 }
697 if (haveValue) setVal(value) ;
698 return false ;
699 }
700}
701
702
703////////////////////////////////////////////////////////////////////////////////
704/// Write object contents to given stream
705
706void RooRealVar::writeToStream(ostream& os, bool compact) const
707{
708 if (compact) {
709 // Write value only
710 os << getVal() ;
711 } else {
712
713 // Write value with error (if not zero)
714 if (_printScientific) {
715 char fmtVal[16], fmtErr[16] ;
716 snprintf(fmtVal,16,"%%.%de",_printSigDigits) ;
717 snprintf(fmtErr,16,"%%.%de",(_printSigDigits+1)/2) ;
718 if (_value>=0) os << " " ;
719 os << Form(fmtVal,_value) ;
720
721 if (hasAsymError()) {
722 os << " +/- (" << Form(fmtErr,getAsymErrorLo())
723 << ", " << Form(fmtErr,getAsymErrorHi()) << ")" ;
724 } else if (hasError()) {
725 os << " +/- " << Form(fmtErr,getError()) ;
726 }
727
728 os << " " ;
729 } else {
730 os << std::unique_ptr<TString>{format(_printSigDigits,"EFA")}->Data() << " " ;
731 }
732
733 // Append limits if not constants
734 if (isConstant()) {
735 os << "C " ;
736 }
737
738 // Append fit limits
739 os << "L(" ;
740 if(hasMin()) {
741 os << getMin();
742 }
743 else {
744 os << "-INF";
745 }
746 if(hasMax()) {
747 os << " - " << getMax() ;
748 }
749 else {
750 os << " - +INF";
751 }
752 os << ") " ;
753
754 if (getBins()!=100) {
755 os << "B(" << getBins() << ") " ;
756 }
757
758 // Add comment with unit, if unit exists
759 if (!_unit.IsNull())
760 os << "// [" << getUnit() << "]" ;
761 }
762}
763
764
765
766////////////////////////////////////////////////////////////////////////////////
767/// Print value of variable
768
769void RooRealVar::printValue(ostream& os) const
770{
771 os << getVal() ;
772
773 if(hasError() && !hasAsymError()) {
774 os << " +/- " << getError() ;
775 } else if (hasAsymError()) {
776 os << " +/- (" << getAsymErrorLo() << "," << getAsymErrorHi() << ")" ;
777 }
778
779}
780
781
782////////////////////////////////////////////////////////////////////////////////
783/// Print extras of variable: (asymmetric) error, constant flag, limits and binning
784
785void RooRealVar::printExtras(ostream& os) const
786{
787 // Append limits if not constants
788 if (isConstant()) {
789 os << "C " ;
790 }
791
792 // Append fit limits
793 os << " L(" ;
794 if(hasMin()) {
795 os << getMin();
796 }
797 else {
798 os << "-INF";
799 }
800 if(hasMax()) {
801 os << " - " << getMax() ;
802 }
803 else {
804 os << " - +INF";
805 }
806 os << ") " ;
807
808 if (getBins()!=100) {
809 os << "B(" << getBins() << ") " ;
810 }
811
812 // Add comment with unit, if unit exists
813 if (!_unit.IsNull())
814 os << "// [" << getUnit() << "]" ;
815
816// cout << " _value = " << &_value << " _error = " << &_error ;
817
818
819}
820
821
822////////////////////////////////////////////////////////////////////////////////
823/// Mapping of Print() option string to RooPrintable contents specifications
824
826{
827 if (opt && TString(opt)=="I") {
828 return kName|kClassName|kValue ;
829 }
831}
832
833
834////////////////////////////////////////////////////////////////////////////////
835/// Detailed printing interface
836
837void RooRealVar::printMultiline(ostream& os, Int_t contents, bool verbose, TString indent) const
838{
839 RooAbsRealLValue::printMultiline(os,contents,verbose,indent);
840 os << indent << "--- RooRealVar ---" << endl;
841 TString unit(_unit);
842 if(!unit.IsNull()) unit.Prepend(' ');
843 os << indent << " Error = " << getError() << unit << endl;
844}
845
846
847
848////////////////////////////////////////////////////////////////////////////////
849/// Format contents of RooRealVar for pretty printing on RooPlot
850/// parameter boxes. This function processes the named arguments
851/// taken by paramOn() and translates them to an option string
852/// parsed by RooRealVar::format(Int_t sigDigits, const char *options)
853
854TString* RooRealVar::format(const RooCmdArg& formatArg) const
855{
856 RooCmdArg tmp(formatArg) ;
857 tmp.setProcessRecArgs(true) ;
858
859 RooCmdConfig pc(Form("RooRealVar::format(%s)",GetName())) ;
860 pc.defineString("what","FormatArgs",0,"") ;
861 pc.defineInt("autop","FormatArgs::AutoPrecision",0,2) ;
862 pc.defineInt("fixedp","FormatArgs::FixedPrecision",0,2) ;
863 pc.defineInt("tlatex","FormatArgs::TLatexStyle",0,0) ;
864 pc.defineInt("latex","FormatArgs::LatexStyle",0,0) ;
865 pc.defineInt("latext","FormatArgs::LatexTableStyle",0,0) ;
866 pc.defineInt("verbn","FormatArgs::VerbatimName",0,0) ;
867 pc.defineMutex("FormatArgs::TLatexStyle","FormatArgs::LatexStyle","FormatArgs::LatexTableStyle") ;
868 pc.defineMutex("FormatArgs::AutoPrecision","FormatArgs::FixedPrecision") ;
869
870 // Process & check varargs
871 pc.process(tmp) ;
872 if (!pc.ok(true)) {
873 return 0 ;
874 }
875
876 // Extract values from named arguments
877 TString options ;
878 options = pc.getString("what") ;
879
880 if (pc.getInt("tlatex")) {
881 options += "L" ;
882 } else if (pc.getInt("latex")) {
883 options += "X" ;
884 } else if (pc.getInt("latext")) {
885 options += "Y" ;
886 }
887
888 if (pc.getInt("verbn")) options += "V" ;
889 Int_t sigDigits = 2 ;
890 if (pc.hasProcessed("FormatArgs::AutoPrecision")) {
891 options += "P" ;
892 sigDigits = pc.getInt("autop") ;
893 } else if (pc.hasProcessed("FormatArgs::FixedPrecision")) {
894 options += "F" ;
895 sigDigits = pc.getInt("fixedp") ;
896 }
897
898 return format(sigDigits,options) ;
899}
900
901
902
903
904////////////////////////////////////////////////////////////////////////////////
905/// Format numeric value of RooRealVar and its error in a variety of ways
906///
907/// To control what is shown use the following options
908/// N = show name
909/// T = show title (takes precedent over `N`, falls back to `N` if title is empty)
910/// H = hide value
911/// E = show error
912/// A = show asymmetric error instead of parabolic error (if available)
913/// U = show unit
914///
915/// To control how it is shown use these options
916/// L = TLatex mode
917/// X = Latex mode
918/// Y = Latex table mode ( '=' replaced by '&' )
919/// V = Make name \\verbatim in Latex mode
920/// P = use error to control shown precision
921/// F = force fixed precision
922///
923
924TString *RooRealVar::format(Int_t sigDigits, const char *options) const
925{
926 // parse the options string
927 TString opts(options);
928 opts.ToLower();
929
930 bool showName= opts.Contains("n");
931 bool showTitle = opts.Contains("t");
932 bool hideValue= opts.Contains("h");
933 bool showError= opts.Contains("e");
934 bool showUnit= opts.Contains("u");
935 bool tlatexMode= opts.Contains("l");
936 bool latexMode= opts.Contains("x");
937 bool latexTableMode = opts.Contains("y") ;
938 bool latexVerbatimName = opts.Contains("v") ;
939
940 std::string label = showName ? getPlotLabel() : "";
941 if(showTitle) {
942 label = GetTitle();
943 if(label.empty()) label = getPlotLabel();
944 }
945
946 if (latexTableMode) latexMode = true ;
947 bool asymError= opts.Contains("a") ;
948 bool useErrorForPrecision= (((showError && hasError(false) && !isConstant()) || opts.Contains("p")) && !opts.Contains("f")) ;
949 // calculate the precision to use
950 if(sigDigits < 1) sigDigits= 1;
951 Int_t leadingDigitVal = 0;
952 if (useErrorForPrecision) {
953 leadingDigitVal = (Int_t)floor(log10(std::abs(_error+1e-10)));
954 if (_value==0&&_error==0) leadingDigitVal=0 ;
955 } else {
956 leadingDigitVal = (Int_t)floor(log10(std::abs(_value+1e-10)));
957 if (_value==0) leadingDigitVal=0 ;
958 }
959 Int_t leadingDigitErr= (Int_t)floor(log10(std::abs(_error+1e-10)));
960 Int_t whereVal= leadingDigitVal - sigDigits + 1;
961 Int_t whereErr= leadingDigitErr - sigDigits + 1;
962 char fmtVal[16], fmtErr[16];
963
964 if (_value<0) whereVal -= 1 ;
965 snprintf(fmtVal,16,"%%.%df", whereVal < 0 ? -whereVal : 0);
966 snprintf(fmtErr,16,"%%.%df", whereErr < 0 ? -whereErr : 0);
967 TString *text= new TString();
968 if(latexMode) text->Append("$");
969 // begin the string with "<name> = " if requested
970 if(showName || showTitle) {
971 if (latexTableMode && latexVerbatimName) {
972 text->Append("\\verb+") ;
973 }
974 text->Append(label);
975 if (latexVerbatimName) text->Append("+") ;
976
977 if (!latexTableMode) {
978 text->Append(" = ");
979 } else {
980 text->Append(" $ & $ ");
981 }
982 }
983
984 // Add leading space if value is positive
985 if (_value>=0) text->Append(" ") ;
986
987 // append our value if requested
988 char buffer[256];
989 if(!hideValue) {
990 chopAt(_value, whereVal);
991 snprintf(buffer, 256,fmtVal, _value);
992 text->Append(buffer);
993 }
994
995 // append our error if requested and this variable is not constant
996 if(hasError(false) && showError && !(asymError && hasAsymError(false))) {
997 if(tlatexMode) {
998 text->Append(" #pm ");
999 }
1000 else if(latexMode) {
1001 text->Append("\\pm ");
1002 }
1003 else {
1004 text->Append(" +/- ");
1005 }
1006 snprintf(buffer, 256,fmtErr, getError());
1007 text->Append(buffer);
1008 }
1009
1010 if (asymError && hasAsymError() && showError) {
1011 if(tlatexMode) {
1012 text->Append(" #pm ");
1013 text->Append("_{") ;
1014 snprintf(buffer, 256,fmtErr, getAsymErrorLo());
1015 text->Append(buffer);
1016 text->Append("}^{+") ;
1017 snprintf(buffer, 256,fmtErr, getAsymErrorHi());
1018 text->Append(buffer);
1019 text->Append("}") ;
1020 }
1021 else if(latexMode) {
1022 text->Append("\\pm ");
1023 text->Append("_{") ;
1024 snprintf(buffer, 256,fmtErr, getAsymErrorLo());
1025 text->Append(buffer);
1026 text->Append("}^{+") ;
1027 snprintf(buffer, 256,fmtErr, getAsymErrorHi());
1028 text->Append(buffer);
1029 text->Append("}") ;
1030 }
1031 else {
1032 text->Append(" +/- ");
1033 text->Append(" (") ;
1034 snprintf(buffer, 256, fmtErr, getAsymErrorLo());
1035 text->Append(buffer);
1036 text->Append(", ") ;
1037 snprintf(buffer, 256, fmtErr, getAsymErrorHi());
1038 text->Append(buffer);
1039 text->Append(")") ;
1040 }
1041
1042 }
1043
1044 // append our units if requested
1045 if(!_unit.IsNull() && showUnit) {
1046 text->Append(' ');
1047 text->Append(_unit);
1048 }
1049 if(latexMode) text->Append("$");
1050 return text;
1051}
1052
1053
1054
1055////////////////////////////////////////////////////////////////////////////////
1056/// Utility to calculate number of decimals to show
1057/// based on magnitude of error
1058
1059double RooRealVar::chopAt(double what, Int_t where) const
1060{
1061 double scale= pow(10.0,where);
1062 Int_t trunc= (Int_t)floor(what/scale + 0.5);
1063 return (double)trunc*scale;
1064}
1065
1066
1067
1068////////////////////////////////////////////////////////////////////////////////
1069/// Overload RooAbsReal::attachToTree to also attach
1070/// branches for errors and/or asymmetric errors
1071/// attribute StoreError and/or StoreAsymError are set
1072
1074{
1075 // Follow usual procedure for value
1076
1077 if (getAttribute("StoreError") || getAttribute("StoreAsymError") || vstore.isFullReal(this) ) {
1078
1080 rfv->setBuffer(this,&_value);
1081
1082 // Attach/create additional branch for error
1083 if (getAttribute("StoreError") || vstore.hasError(this) ) {
1084 rfv->setErrorBuffer(&_error) ;
1085 }
1086
1087 // Attach/create additional branches for asymmetric error
1088 if (getAttribute("StoreAsymError") || vstore.hasAsymError(this)) {
1090 }
1091
1092 } else {
1093
1095
1096 }
1097}
1098
1099
1100
1101////////////////////////////////////////////////////////////////////////////////
1102/// Overload RooAbsReal::attachToTree to also attach
1103/// branches for errors and/or asymmetric errors
1104/// attribute StoreError and/or StoreAsymError are set
1105
1107{
1108 // Follow usual procedure for value
1109 RooAbsReal::attachToTree(t,bufSize) ;
1110// cout << "RooRealVar::attachToTree(" << this << ") name = " << GetName()
1111// << " StoreError = " << (getAttribute("StoreError")?"T":"F") << endl ;
1112
1113 // Attach/create additional branch for error
1114 if (getAttribute("StoreError")) {
1115 TString errName(GetName()) ;
1116 errName.Append("_err") ;
1117 TBranch* branch = t.GetBranch(errName) ;
1118 if (branch) {
1119 t.SetBranchAddress(errName,&_error) ;
1120 } else {
1121 TString format2(errName);
1122 format2.Append("/D");
1123 t.Branch(errName, &_error, (const Text_t*)format2, bufSize);
1124 }
1125 }
1126
1127 // Attach/create additional branches for asymmetric error
1128 if (getAttribute("StoreAsymError")) {
1129 TString loName(GetName()) ;
1130 loName.Append("_aerr_lo") ;
1131 TBranch* lobranch = t.GetBranch(loName) ;
1132 if (lobranch) {
1133 t.SetBranchAddress(loName,&_asymErrLo) ;
1134 } else {
1135 TString format2(loName);
1136 format2.Append("/D");
1137 t.Branch(loName, &_asymErrLo, (const Text_t*)format2, bufSize);
1138 }
1139
1140 TString hiName(GetName()) ;
1141 hiName.Append("_aerr_hi") ;
1142 TBranch* hibranch = t.GetBranch(hiName) ;
1143 if (hibranch) {
1144 t.SetBranchAddress(hiName,&_asymErrHi) ;
1145 } else {
1146 TString format2(hiName);
1147 format2.Append("/D");
1148 t.Branch(hiName, &_asymErrHi, (const Text_t*)format2, bufSize);
1149 }
1150 }
1151}
1152
1153
1154////////////////////////////////////////////////////////////////////////////////
1155/// Overload RooAbsReal::fillTreeBranch to also
1156/// fill tree branches with (asymmetric) errors
1157/// if requested.
1158
1160{
1161 // First determine if branch is taken
1162 TString cleanName(cleanBranchName()) ;
1163 TBranch* valBranch = t.GetBranch(cleanName) ;
1164 if (!valBranch) {
1165 coutE(Eval) << "RooAbsReal::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << endl ;
1166 assert(0) ;
1167 }
1168 valBranch->Fill() ;
1169
1170 if (getAttribute("StoreError")) {
1171 TString errName(GetName()) ;
1172 errName.Append("_err") ;
1173 TBranch* errBranch = t.GetBranch(errName) ;
1174 if (errBranch) errBranch->Fill() ;
1175 }
1176
1177 if (getAttribute("StoreAsymError")) {
1178 TString loName(GetName()) ;
1179 loName.Append("_aerr_lo") ;
1180 TBranch* loBranch = t.GetBranch(loName) ;
1181 if (loBranch) loBranch->Fill() ;
1182
1183 TString hiName(GetName()) ;
1184 hiName.Append("_aerr_hi") ;
1185 TBranch* hiBranch = t.GetBranch(hiName) ;
1186 if (hiBranch) hiBranch->Fill() ;
1187 }
1188}
1189
1190
1191
1192////////////////////////////////////////////////////////////////////////////////
1193/// Copy the cached value of another RooAbsArg to our cache
1194/// Warning: This function copies the cached values of source,
1195/// it is the callers responsibility to make sure the cache is clean
1196
1197void RooRealVar::copyCache(const RooAbsArg* source, bool valueOnly, bool setValDirty)
1198{
1199 // Follow usual procedure for valueklog
1200 double oldVal = _value;
1201 RooAbsReal::copyCache(source,valueOnly,setValDirty) ;
1202 if(_value != oldVal) {
1204 }
1205
1206 if (valueOnly) return ;
1207
1208 // Copy error too, if source has one
1209 RooRealVar* other = dynamic_cast<RooRealVar*>(const_cast<RooAbsArg*>(source)) ;
1210 if (other) {
1211 // Copy additional error value
1212 _error = other->_error ;
1213 _asymErrLo = other->_asymErrLo ;
1214 _asymErrHi = other->_asymErrHi ;
1215 }
1216}
1217
1218
1219
1220////////////////////////////////////////////////////////////////////////////////
1221/// Stream an object of class RooRealVar.
1222
1224{
1225 UInt_t R__s, R__c;
1226 if (R__b.IsReading()) {
1227
1228 Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
1230 if (R__v==1) {
1231 coutI(Eval) << "RooRealVar::Streamer(" << GetName() << ") converting version 1 data format" << endl ;
1232 double fitMin, fitMax ;
1233 Int_t fitBins ;
1234 R__b >> fitMin;
1235 R__b >> fitMax;
1236 R__b >> fitBins;
1237 _binning = std::make_unique<RooUniformBinning>(fitMin,fitMax,fitBins);
1238 }
1239 R__b >> _error;
1240 R__b >> _asymErrLo;
1241 R__b >> _asymErrHi;
1242 if (R__v>=2) {
1243 RooAbsBinning* binning;
1244 R__b >> binning;
1245 _binning.reset(binning);
1246 }
1247 if (R__v==3) {
1248 // In v3, properties were written as pointers, so read now and install:
1250 R__b >> tmpProp;
1251 installSharedProp(std::shared_ptr<RooRealVarSharedProperties>(tmpProp));
1252 }
1253 if (R__v>=4) {
1254 // In >= v4, properties were written directly, but they might be the "_nullProp"
1255 auto tmpProp = std::make_shared<RooRealVarSharedProperties>();
1256 tmpProp->Streamer(R__b);
1257 installSharedProp(std::move(tmpProp));
1258 }
1259
1260 R__b.CheckByteCount(R__s, R__c, RooRealVar::IsA());
1261
1262 } else {
1263
1264 R__c = R__b.WriteVersion(RooRealVar::IsA(), true);
1266 R__b << _error;
1267 R__b << _asymErrLo;
1268 R__b << _asymErrHi;
1269 R__b << _binning.get();
1270 if (_sharedProp) {
1271 _sharedProp->Streamer(R__b) ;
1272 } else {
1273 _nullProp().Streamer(R__b) ;
1274 }
1275 R__b.SetByteCount(R__c, true);
1276
1277 }
1278}
1279
1280/// Hand out our shared property, create on the fly and register
1281/// in shared map if necessary.
1282std::shared_ptr<RooRealVarSharedProperties> RooRealVar::sharedProp() const {
1283 if (!_sharedProp) {
1284 const_cast<RooRealVar*>(this)->installSharedProp(std::make_shared<RooRealVarSharedProperties>());
1285 }
1286
1287 return _sharedProp;
1288}
1289
1290
1291////////////////////////////////////////////////////////////////////////////////
1292/// Install the shared property into the member _sharedProp.
1293/// If a property with same name already exists, discard the incoming one,
1294/// and share the existing.
1295/// `nullptr` and properties equal to the RooRealVar::_nullProp will not be installed.
1296void RooRealVar::installSharedProp(std::shared_ptr<RooRealVarSharedProperties>&& prop) {
1297 if (prop == nullptr || (*prop == _nullProp())) {
1298 _sharedProp = nullptr;
1299 return;
1300 }
1301
1302
1303 auto& weakPtr = (*sharedPropList())[prop->uuid()];
1304 std::shared_ptr<RooRealVarSharedProperties> existingProp;
1305 if ( (existingProp = weakPtr.lock()) ) {
1306 // Property exists, discard incoming
1307 _sharedProp = std::move(existingProp);
1308 // Incoming is not allowed to delete the binnings now - they are owned by the other instance
1309 prop->disownBinnings();
1310 } else {
1311 // Doesn't exist. Install, register weak pointer for future sharing
1312 _sharedProp = std::move(prop);
1313 weakPtr = _sharedProp;
1314 }
1315}
1316
1317
1318////////////////////////////////////////////////////////////////////////////////
1319/// Stop sharing properties.
1321{
1322 // Nothing to do if there were no shared properties to begin with.
1323 if(!_sharedProp) return;
1324
1325 // Get the key for the _sharedPropList.
1326 auto key = _sharedProp->uuid(); // we have to make a copy because _sharedPropList gets delete next.
1327
1328 // Actually delete the shared properties object.
1329 _sharedProp.reset();
1330
1331 // If the _sharedPropList was already deleted, we can return now.
1332 if(!sharedPropList()) return;
1333
1334 // Find the std::weak_ptr that the _sharedPropList holds to our
1335 // _sharedProp.
1336 auto iter = sharedPropList()->find(key);
1337
1338 // If no other RooRealVars shared the shared properties with us, the
1339 // weak_ptr in _sharedPropList is expired and we can erase it from the map.
1340 if(iter->second.expired()) {
1341 sharedPropList()->erase(iter);
1342 }
1343}
1344
1345
1346////////////////////////////////////////////////////////////////////////////////
1347/// If true, contents of RooRealVars will be printed in scientific notation
1348
1350{
1351 _printScientific = flag ;
1352}
1353
1354
1355////////////////////////////////////////////////////////////////////////////////
1356/// Set number of digits to show when printing RooRealVars
1357
1359{
1360 _printSigDigits = ndig>1?ndig:1 ;
1361}
#define e(i)
Definition RSha256.hxx:103
#define coutI(a)
#define coutW(a)
#define coutE(a)
static bool staticSharedPropListCleanedUp
#define TRACE_DESTROY
Definition RooTrace.h:24
#define TRACE_CREATE
Definition RooTrace.h:23
int Int_t
Definition RtypesCore.h:45
char Text_t
Definition RtypesCore.h:62
short Version_t
Definition RtypesCore.h:65
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h prop
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t TPoint TPoint const char text
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
@ kName
#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:74
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition RooAbsArg.h:492
bool isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:359
bool _fast
Definition RooAbsArg.h:712
friend void RooRefArray::Streamer(TBuffer &)
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:487
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
TString cleanBranchName() const
Construct a mangled name from the actual name that is free of any math symbols that might be interpre...
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
virtual void setRange(double xlo, double xhi)=0
virtual void setMin(double xlo)
Change lower bound to xlo.
virtual void setMax(double xhi)
Change upper bound to xhi.
virtual RooAbsBinning * clone(const char *name=nullptr) const =0
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.
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:510
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:509
void attachToTree(TTree &t, Int_t bufSize=32000) override
Attach object to a branch of given TTree.
const char * getPlotLabel() const
Get the label associated with the variable.
const Text_t * getUnit() const
Definition RooAbsReal.h:147
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
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.
void defineMutex(const char *head, Args_t &&... tail)
Define arguments where any pair is mutually exclusive.
bool process(const RooCmdArg &arg)
Process given RooCmdArg.
bool hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name 'cmdName' has been processed.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
bool defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
bool defineString(const char *name, const char *argName, Int_t stringNum, const char *defValue="", bool appendMode=false)
Define double property name 'name' mapped to double in slot 'stringNum' in RooCmdArg with name argNam...
bool ok(bool verbose) const
Return true of parsing was successful.
const char * getString(const char *name, const char *defaultValue="", bool convEmptyToNull=false)
Return string property registered with name 'name'.
RooErrorVar is an auxilary class that represents the error of a RooRealVar as a seperate object.
Definition RooErrorVar.h:28
static constexpr double infinity()
Return internal infinity representation.
Definition RooNumber.h:24
static constexpr int isInfinite(double x)
Return true if x is infinite by RooNumber internal specification.
Definition RooNumber.h:34
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.
void setVal(double value) override
Set value of variable to 'value'.
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.
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.
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.
void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true) override
Copy the cached value of another RooAbsArg to our cache Warning: This function copies the cached valu...
std::shared_ptr< RooRealVarSharedProperties > sharedProp() const
Hand out our shared property, create on the fly and register in shared map if necessary.
void attachToTree(TTree &t, Int_t bufSize=32000) override
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
void attachToVStore(RooVectorDataStore &vstore) override
Overload RooAbsReal::attachToTree to also attach branches for errors and/or asymmetric errors attribu...
void printValue(std::ostream &os) const override
Print value of variable.
void printExtras(std::ostream &os) const override
Print extras of variable: (asymmetric) error, constant flag, limits and binning.
std::unique_ptr< RooAbsBinning > _binning
Definition RooRealVar.h:158
void setMin(const char *name, double value)
Set minimum of name range to given value.
bool hasBinning(const char *name) const override
Returns true if variable has a binning named 'name'.
double _asymErrLo
Low side of asymmetric error associated with current value.
Definition RooRealVar.h: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.
std::list< std::string > getBinningNames() const override
Get a list of all binning names.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Detailed printing interface.
std::size_t _valueResetCounter
! How many times the value of this variable was reset
Definition RooRealVar.h:173
~RooRealVar() override
Destructor.
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.
static void cleanup()
Explicitely deletes the shared properties list on exit to avoid problems with the initialization orde...
Int_t defaultPrintContents(Option_t *opt) const override
Mapping of Print() option string to RooPrintable contents specifications.
void setBinning(const RooAbsBinning &binning, const char *name=nullptr)
Add given binning under name 'name' with this variable.
bool hasError(bool allowZero=true) const
Definition RooRealVar.h:63
static SharedPropertiesMap * sharedPropList()
List of properties shared among clones of a variable.
void deleteSharedProperties()
Stop sharing properties.
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to given stream.
std::map< RooSharedProperties::UUID, std::weak_ptr< RooRealVarSharedProperties > > SharedPropertiesMap
Definition RooRealVar.h:167
bool hasAsymError(bool allowZero=true) const
Definition RooRealVar.h:68
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from given stream.
double chopAt(double what, Int_t where) const
Utility to calculate number of decimals to show based on magnitude of error.
TString * format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
double getAsymErrorHi() const
Definition RooRealVar.h:67
void setRange(const char *name, double min, double max)
Set a fit or plotting range.
void setBins(Int_t nBins, const char *name=nullptr)
Create a uniform binning under name 'name' for this variable.
RooRealVar()
Default constructor.
void removeError()
Definition RooRealVar.h:65
void removeMax(const char *name=nullptr)
Remove upper range limit for binning with given name. Empty name means default range.
void setMax(const char *name, double value)
Set maximum of name range to given value.
TClass * IsA() const override
Definition RooRealVar.h:175
double getAsymErrorLo() const
Definition RooRealVar.h:66
static void activate()
Install atexit handler that calls CleanupRooFitAtExit() on program termination.
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
void Streamer(TBuffer &) override
Stream an object of class TObject.
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1170
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:450
TString & Prepend(const char *cs)
Definition TString.h:673
Bool_t IsNull() const
Definition TString.h:418
TString & Append(const char *cs)
Definition TString.h:576
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
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:5285
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=nullptr)
Change branch address, dealing with clone trees properly.
Definition TTree.cxx:8371
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
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.
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()