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