Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RooRealVar.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooRealVar.h,v 1.54 2007/05/11 09:11:30 verkerke Exp $
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 #ifndef ROO_REAL_VAR
17 #define ROO_REAL_VAR
18 
19 #include <list>
20 #include <string>
21 #include <cmath>
22 #include <float.h>
23 #include "TString.h"
24 
25 #include "RooAbsRealLValue.h"
26 #include "RooUniformBinning.h"
27 #include "RooNumber.h"
30 
31 class RooArgSet ;
32 class RooErrorVar ;
33 class RooVectorDataStore ;
34 class RooExpensiveObjectCache ;
35 
36 class RooRealVar : public RooAbsRealLValue {
37 public:
38  // Constructors, assignment etc.
39  RooRealVar() ;
40  RooRealVar(const char *name, const char *title,
41  Double_t value, const char *unit= "") ;
42  RooRealVar(const char *name, const char *title, Double_t minValue,
43  Double_t maxValue, const char *unit= "");
44  RooRealVar(const char *name, const char *title, Double_t value,
45  Double_t minValue, Double_t maxValue, const char *unit= "") ;
46  RooRealVar(const RooRealVar& other, const char* name=0);
47  RooRealVar& operator=(const RooRealVar& other);
48  virtual TObject* clone(const char* newname) const { return new RooRealVar(*this,newname); }
49  virtual ~RooRealVar();
50 
51  // Parameter value and error accessors
52  virtual Double_t getValV(const RooArgSet* nset=0) const ;
53  RooSpan<const double> getValBatch(std::size_t begin, std::size_t batchSize,
54  const RooArgSet* = nullptr) const;
55 
56  virtual void setVal(Double_t value);
57  inline Double_t getError() const { return _error>=0?_error:0. ; }
58  inline Bool_t hasError(Bool_t allowZero=kTRUE) const { return allowZero ? (_error>=0) : (_error>0) ; }
59  inline void setError(Double_t value) { _error= value ; }
60  inline void removeError() { _error = -1 ; }
61  inline Double_t getAsymErrorLo() const { return _asymErrLo<=0?_asymErrLo:0. ; }
62  inline Double_t getAsymErrorHi() const { return _asymErrHi>=0?_asymErrHi:0. ; }
63  inline Bool_t hasAsymError(Bool_t allowZero=kTRUE) const { return allowZero ? ((_asymErrHi>=0 && _asymErrLo<=0)) : ((_asymErrHi>0 && _asymErrLo<0)) ; }
64  inline void removeAsymError() { _asymErrLo = 1 ; _asymErrHi = -1 ; }
65  inline void setAsymError(Double_t lo, Double_t hi) { _asymErrLo = lo ; _asymErrHi = hi ; }
66  inline Double_t getErrorLo() const { return _asymErrLo<=0?_asymErrLo:-1*_error ; }
67  inline Double_t getErrorHi() const { return _asymErrHi>=0?_asymErrHi:_error ; }
68 
69  RooErrorVar* errorVar() const ;
70 
71  // Set/get finite fit range limits
72  void setMin(const char* name, Double_t value) ;
73  void setMax(const char* name, Double_t value) ;
74  void setRange(const char* name, Double_t min, Double_t max) ;
75  void setRange(const char* name, RooAbsReal& min, RooAbsReal& max) ;
76  inline void setMin(Double_t value) { setMin(0,value) ; }
77  inline void setMax(Double_t value) { setMax(0,value) ; }
78  inline void setRange(Double_t min, Double_t max) { setRange(0,min,max) ; }
79  inline void setRange(RooAbsReal& min, RooAbsReal& max) { setRange(0,min,max) ; }
80 
81  void setBins(Int_t nBins, const char* name=0) { setBinning(RooUniformBinning(getMin(name),getMax(name),nBins),name) ; }
82  void setBinning(const RooAbsBinning& binning, const char* name=0) ;
83 
84  // RooAbsRealLValue implementation
85  Bool_t hasBinning(const char* name) const ;
86  const RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const ;
87  RooAbsBinning& getBinning(const char* name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) ;
88  std::list<std::string> getBinningNames() const ;
89 
90  // Set infinite fit range limits
91  inline void removeMin(const char* name=0) { getBinning(name).setMin(-RooNumber::infinity()) ; }
92  inline void removeMax(const char* name=0) { getBinning(name).setMax(RooNumber::infinity()) ; }
93  inline void removeRange(const char* name=0) { getBinning(name).setRange(-RooNumber::infinity(),RooNumber::infinity()) ; }
94 
95  // I/O streaming interface (machine readable)
96  virtual Bool_t readFromStream(std::istream& is, Bool_t compact, Bool_t verbose=kFALSE) ;
97  virtual void writeToStream(std::ostream& os, Bool_t compact) const ;
98 
99  // We implement a fundamental type of AbsArg that can be stored in a dataset
100  inline virtual Bool_t isFundamental() const { return kTRUE; }
101 
102  // Force to be a leaf-node of any expression tree, even if we have (shape) servers
103  virtual Bool_t isDerived() const {
104  // Does value or shape of this arg depend on any other arg?
105  return !_serverList.empty() || _proxyList.GetEntries()>0;
106  }
107 
108  // Printing interface (human readable)
109  virtual void printValue(std::ostream& os) const ;
110  virtual void printExtras(std::ostream& os) const ;
111  virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
112  virtual Int_t defaultPrintContents(Option_t* opt) const ;
113 
114 
115  TString* format(const RooCmdArg& formatArg) const ;
116  TString* format(Int_t sigDigits, const char *options) const ;
117 
118  static void printScientific(Bool_t flag=kFALSE) ;
119  static void printSigDigits(Int_t ndig=5) ;
120 
121  using RooAbsRealLValue::operator= ;
122 
123  void deleteSharedProperties() ;
124 
125  void copyCacheFast(const RooRealVar& other, Bool_t setValDirty=kTRUE) { _value = other._value ; if (setValDirty) setValueDirty() ; }
126 
127  protected:
128 
129  static Bool_t _printScientific ;
130  static Int_t _printSigDigits ;
131 
132  virtual void setVal(Double_t value, const char* rangeName) ;
133 
134  friend class RooAbsRealLValue ;
135  virtual void setValFast(Double_t value) { _value = value ; setValueDirty() ; }
136 
137 
138  virtual Double_t evaluate() const { return _value ; } // dummy because we overloaded getVal()
139  virtual void copyCache(const RooAbsArg* source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE) ;
140  virtual void attachToTree(TTree& t, Int_t bufSize=32000) ;
141  virtual void attachToVStore(RooVectorDataStore& vstore) ;
142  virtual void fillTreeBranch(TTree& t) ;
143 
144  Double_t chopAt(Double_t what, Int_t where) const ;
145 
146  Double_t _error; // Symmetric error associated with current value
147  Double_t _asymErrLo ; // Low side of asymmetric error associated with current value
148  Double_t _asymErrHi ; // High side of asymmetric error associated with current value
149  RooAbsBinning* _binning ;
150  RooLinkedList _altNonSharedBinning ; // Non-shareable alternative binnings
151 
152  inline RooRealVarSharedProperties* sharedProp() const {
153  if (!_sharedProp) {
154  _sharedProp = (RooRealVarSharedProperties*) _sharedPropList.registerProperties(new RooRealVarSharedProperties()) ;
155  }
156  return _sharedProp ;
157  }
158 
159  virtual void setExpensiveObjectCache(RooExpensiveObjectCache&) { ; } // variables don't need caches
160 
161  static RooSharedPropertiesList _sharedPropList; // List of properties shared among clone sets
162  static RooRealVarSharedProperties _nullProp ; // Null property
163  mutable RooRealVarSharedProperties* _sharedProp ; //! Shared properties associated with this instance
164 
165  ClassDef(RooRealVar,5) // Real-valued variable
166 };
167 
168 
169 
170 
171 #endif