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