Logo ROOT  
Reference Guide
RooErrorVar.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 RooErrorVar.cxx
19\class RooErrorVar
20\ingroup Roofitcore
21
22RooErrorVar is an auxilary class that represents the error
23of a RooRealVar as a seperate object. The main reason of
24existence of this class is to facilitate the reuse of existing
25techniques to perform calculations that involve a RooRealVars
26error, such as calculating the pull value.
27**/
28
29#include "RooErrorVar.h"
30#include "RooAbsBinning.h"
31#include "RooStreamParser.h"
32#include "RooRangeBinning.h"
33#include "RooMsgService.h"
34#include "RooUniformBinning.h"
35
36using namespace std;
37
39;
40
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Construct an lvalue variable representing the error of RooRealVar input
45
46RooErrorVar::RooErrorVar(const char *name, const char *title, const RooRealVar& input) :
48 _realVar("realVar","RooRealVar with error",this,(RooAbsReal&)input)
49{
50 _binning = new RooUniformBinning(-1,1,100) ;
51}
52
53
54
55////////////////////////////////////////////////////////////////////////////////
56
57RooErrorVar::RooErrorVar(const RooErrorVar& other, const char* name) :
59 _realVar("realVar",this,other._realVar)
60{
61 _binning = other._binning->clone() ;
62
63 // Copy constructor
64 for(auto * binning : static_range_cast<RooAbsBinning*>(other._altBinning)) _altBinning.Add(binning->clone());
65}
66
67
68
69////////////////////////////////////////////////////////////////////////////////
70/// Destructor
71
73{
74 delete _binning ;
75}
76
77
78
79////////////////////////////////////////////////////////////////////////////////
80/// Return value, i.e. error on input variable
81
83{
84 return evaluate();
85}
86
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Return true if we have binning with given name
91
93{
95}
96
97
98
99////////////////////////////////////////////////////////////////////////////////
100/// Return binning with given name. If no binning exists with such a name, clone the default
101/// binning on the fly if so requested
102
103const RooAbsBinning& RooErrorVar::getBinning(const char* name, Bool_t verbose, Bool_t createOnTheFly) const
104{
105 return const_cast<RooErrorVar*>(this)->getBinning(name,verbose,createOnTheFly) ;
106}
107
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Return binning with given name. If no binning exists with such a name, clone the default
112/// binning on the fly if so requested
113
114RooAbsBinning& RooErrorVar::getBinning(const char* name, Bool_t /*verbose*/, Bool_t createOnTheFly)
115{
116 // Return default (normalization) binning and range if no name is specified
117 if (name==0) {
118 return *_binning ;
119 }
120
121 // Check if binning with this name has been created already
123 if (binning) {
124 return *binning ;
125 }
126
127 // Return default binning if binning is not found and no creation is requested
128 if (!createOnTheFly) {
129 return *_binning ;
130 }
131
132 // Create a new RooRangeBinning with this name with default range
133 binning = new RooRangeBinning(getMin(),getMax(),name) ;
134 coutI(Contents) << "RooErrorVar::getBinning(" << GetName() << ") new range named '"
135 << name << "' created with default bounds" << endl ;
136
137 _altBinning.Add(binning) ;
138
139 return *binning ;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Get a list of all binning names. An empty name implies the default binning.
144/// A 0 pointer should be passed to getBinning in this case.
145
146std::list<std::string> RooErrorVar::getBinningNames() const
147{
148 std::list<std::string> binningNames(1, "");
149
150 for(auto * binning : static_range_cast<RooAbsArg*>(_altBinning)) {
151 const char* name = binning->GetName();
152 binningNames.push_back(name);
153 }
154 return binningNames;
155}
156
157
158/// Remove lower bound from named binning, or default binning if name is null
159void RooErrorVar::removeMin(const char* name) {
161}
162
163
164/// Remove upper bound from named binning, or default binning if name is null
165void RooErrorVar::removeMax(const char* name) {
167}
168
169
170/// Remove both upper and lower bounds from named binning, or
171/// default binning if name is null
174}
175
176
177////////////////////////////////////////////////////////////////////////////////
178/// Store given binning with this variable under the given name
179
180void RooErrorVar::setBinning(const RooAbsBinning& binning, const char* name)
181{
182 if (!name) {
183 if (_binning) delete _binning ;
184 _binning = binning.clone() ;
185 } else {
186
187 // Remove any old binning with this name
189 if (oldBinning) {
190 _altBinning.Remove(oldBinning) ;
191 delete oldBinning ;
192 }
193
194 // Insert new binning in list of alternative binnings
195 RooAbsBinning* newBinning = binning.clone() ;
196 newBinning->SetName(name) ;
197 newBinning->SetTitle(name) ;
198 _altBinning.Add(newBinning) ;
199
200 }
201
202
203}
204
205
206
207////////////////////////////////////////////////////////////////////////////////
208/// Set the lower bound of the range with the given name to the given value
209/// If name is a null pointer, set the lower bound of the default range
210
211void RooErrorVar::setMin(const char* name, Double_t value)
212{
213 // Set new minimum of fit range
214 RooAbsBinning& binning = getBinning(name) ;
215
216 // Check if new limit is consistent
217 if (value >= getMax()) {
218 coutW(InputArguments) << "RooErrorVar::setMin(" << GetName()
219 << "): Proposed new fit min. larger than max., setting min. to max." << endl ;
220 binning.setMin(getMax()) ;
221 } else {
222 binning.setMin(value) ;
223 }
224
225 // Clip current value in window if it fell out
226 if (!name) {
227 Double_t clipValue ;
228 if (!inRange(_value,0,&clipValue)) {
229 setVal(clipValue) ;
230 }
231 }
232
233 setShapeDirty() ;
234}
235
236
237////////////////////////////////////////////////////////////////////////////////
238/// Set the upper bound of the range with the given name to the given value
239/// If name is a null pointer, set the upper bound of the default range
240
241void RooErrorVar::setMax(const char* name, Double_t value)
242{
243 // Set new maximum of fit range
244 RooAbsBinning& binning = getBinning(name) ;
245
246 // Check if new limit is consistent
247 if (value < getMin()) {
248 coutW(InputArguments) << "RooErrorVar::setMax(" << GetName()
249 << "): Proposed new fit max. smaller than min., setting max. to min." << endl ;
250 binning.setMax(getMin()) ;
251 } else {
252 binning.setMax(value) ;
253 }
254
255 // Clip current value in window if it fell out
256 if (!name) {
257 Double_t clipValue ;
258 if (!inRange(_value,0,&clipValue)) {
259 setVal(clipValue) ;
260 }
261 }
262
263 setShapeDirty() ;
264}
265
266/// Set default binning to nBins uniform bins
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Set the upper and lower lower bound of the range with the given name to the given values
273/// If name is a null pointer, set the upper and lower bounds of the default range
274
275void RooErrorVar::setRange( const char* name, Double_t min, Double_t max)
276{
278
279 // Set new fit range
280 RooAbsBinning& binning = getBinning(name,kFALSE) ;
281
282 // Check if new limit is consistent
283 if (min>max) {
284 coutW(InputArguments) << "RooErrorVar::setRange(" << GetName()
285 << "): Proposed new fit max. smaller than min., setting max. to min." << endl ;
286 binning.setRange(min,min) ;
287 } else {
288 binning.setRange(min,max) ;
289 }
290
291 if (!exists) {
292 coutI(InputArguments) << "RooErrorVar::setRange(" << GetName()
293 << ") new range named '" << name << "' created with bounds ["
294 << min << "," << max << "]" << endl ;
295 }
296
297 setShapeDirty() ;
298}
299
300
301
302////////////////////////////////////////////////////////////////////////////////
303/// Read object contents from given stream
304
306{
307 TString token,errorPrefix("RooErrorVar::readFromStream(") ;
308 errorPrefix.Append(GetName()) ;
309 errorPrefix.Append(")") ;
310 RooStreamParser parser(is,errorPrefix) ;
311 Double_t value(0) ;
312
313 // Compact mode: Read single token
314 if (parser.readDouble(value,verbose)) return kTRUE ;
315 if (isValidReal(value,verbose)) {
316 setVal(value) ;
317 return kFALSE ;
318 } else {
319 return kTRUE ;
320 }
321}
322
323
324
325////////////////////////////////////////////////////////////////////////////////
326/// Write value to stream
327
328void RooErrorVar::writeToStream(ostream& os, Bool_t /*compact*/) const
329{
330 os << getVal() ;
331}
332
333
334////////////////////////////////////////////////////////////////////////////////
335/// Force the internal value cache to be up to date
336
338{
339 _value = evaluate() ;
340}
341
342
343
#define coutI(a)
Definition: RooMsgService.h:30
#define coutW(a)
Definition: RooMsgService.h:32
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
char name[80]
Definition: TGX11.cxx:110
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition: RooAbsArg.h:515
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
Definition: RooAbsBinning.h:26
virtual RooAbsBinning * clone(const char *name=0) const =0
virtual void setMin(Double_t xlo)
Change lower bound to xlo.
Definition: RooAbsBinning.h:52
virtual void setMax(Double_t xhi)
Change upper bound to xhi.
Definition: RooAbsBinning.h:56
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.
virtual Bool_t isValidReal(Double_t value, Bool_t printError=kFALSE) const
Check if given value is valid.
virtual Bool_t inRange(const char *name) const
Check if current value is inside range with given name.
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:63
Double_t _value
Definition: RooAbsReal.h:483
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:93
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:35
RooErrorVar is an auxilary class that represents the error of a RooRealVar as a seperate object.
Definition: RooErrorVar.h:28
void setBinning(const RooAbsBinning &binning, const char *name=0)
Store given binning with this variable under the given name.
void setRange(Double_t min, Double_t max)
Definition: RooErrorVar.h:69
void removeRange(const char *name=0)
Remove both upper and lower bounds from named binning, or default binning if name is null.
void syncCache(const RooArgSet *set=0)
Optional alternative ranges and binnings.
void setMin(Double_t value)
Definition: RooErrorVar.h:61
void setMax(Double_t value)
Definition: RooErrorVar.h:65
virtual Double_t getValV(const RooArgSet *set=0) const
Return value, i.e. error on input variable.
Definition: RooErrorVar.cxx:82
virtual Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooErrorVar.h:41
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
RooLinkedList _altBinning
Definition: RooErrorVar.h:94
Bool_t hasBinning(const char *name) const
Return true if we have binning with given name.
Definition: RooErrorVar.cxx:92
virtual void setVal(Double_t value)
Set the current value of the object. Needs to be overridden by implementations.
Definition: RooErrorVar.h:46
virtual ~RooErrorVar()
Destructor.
Definition: RooErrorVar.cxx:72
RooAbsBinning * _binning
Definition: RooErrorVar.h:99
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write value to stream.
std::list< std::string > getBinningNames() const
Get a list of all binning names.
void removeMin(const char *name=0)
Remove lower bound from named binning, or default binning if name is null.
void removeMax(const char *name=0)
Remove upper bound from named binning, or default binning if name is null.
void setBins(Int_t nBins)
Set default binning to nBins uniform bins.
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning with given name.
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:67
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
static Double_t infinity()
Return internal infinity representation.
Definition: RooNumber.cxx:49
RooRangeBinning is binning/range definition that only defines a range but no binning.
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
Bool_t readDouble(Double_t &value, Bool_t zapOnError=kFALSE)
Read the next token and convert it to a Double_t.
RooUniformBinning is an implementation of RooAbsBinning that provides a uniform binning in 'n' bins b...
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:136
TString & Append(const char *cs)
Definition: TString.h:564
@ InputArguments
Definition: RooGlobalFunc.h:61