Logo ROOT   6.14/05
Reference Guide
RooAbsCategoryLValue.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 RooAbsCategoryLValue.cxx
19 \class RooAbsCategoryLValue
20 \ingroup Roofitcore
21 
22 RooAbsCategoryLValue is the common abstract base class for objects that represent a
23 discrete value that may appear on the left hand side of an equation ('lvalue')
24 
25 Each implementation must provide setIndex()/setLabel() members to allow direct modification
26 of the value. RooAbsCategoryLValue may be derived, but its functional relation
27 to other RooAbsArgs must be invertible
28 **/
29 
30 #include "RooFit.h"
31 
32 #include "Riostream.h"
33 #include "Riostream.h"
34 #include <stdlib.h>
35 #include "TTree.h"
36 #include "TString.h"
37 #include "TH1.h"
38 #include "RooAbsCategoryLValue.h"
39 #include "RooArgSet.h"
40 #include "RooStreamParser.h"
41 #include "RooRandom.h"
42 #include "RooMsgService.h"
43 
44 using namespace std;
45 
47 ;
48 
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Constructor
52 
53 RooAbsCategoryLValue::RooAbsCategoryLValue(const char *name, const char *title) :
54  RooAbsCategory(name,title)
55 {
56  setValueDirty() ;
57  setShapeDirty() ;
58 }
59 
60 
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Copy constructor
64 
66  RooAbsCategory(other, name), RooAbsLValue(other)
67 {
68 }
69 
70 
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Destructor
74 
76 {
77 }
78 
79 
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Assignment operator from integer index number
83 
85 {
86  setIndex(index,kTRUE) ;
87  return *this ;
88 }
89 
90 
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Assignment operator from string pointer
94 
96 {
97  setLabel(label) ;
98  return *this ;
99 }
100 
101 
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Assignment from another RooAbsCategory
105 
107 {
108  if (&other==this) return *this ;
109 
110  const RooCatType* type = lookupType(other.getLabel(),kTRUE) ;
111  if (!type) return *this ;
112 
113  _value = *type ;
114  setValueDirty() ;
115  return *this ;
116 }
117 
118 
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Set our state to our n'th defined type and return kTRUE.
122 /// Return kFALSE if n is out of range.
123 
125 {
126  const RooCatType *newValue= getOrdinal(n,rangeName);
127  if(newValue) {
128  return setIndex(newValue->getVal());
129  }
130  else {
131  return kFALSE;
132  }
133 }
134 
135 
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Copy the cached value from given source and raise dirty flag.
139 /// It is the callers responsability to ensure that the sources
140 /// cache is clean(valid) before this function is called, e.g. by
141 /// calling syncCache() on the source.
142 
143 void RooAbsCategoryLValue::copyCache(const RooAbsArg* source, Bool_t valueOnly, Bool_t setValDirty)
144 {
145  RooAbsCategory::copyCache(source,valueOnly,setValDirty) ;
146  if (isValid(_value)) {
147  setIndex(_value.getVal()) ; // force back-propagation
148  }
149 }
150 
151 
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Read object contents from given stream (dummy implementation)
155 
157 {
158  return kTRUE ;
159 }
160 
161 
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Write object contents to given stream (dummy implementation)
165 
167 {
168 }
169 
170 
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Randomize current value
174 
175 void RooAbsCategoryLValue::randomize(const char* rangeName)
176 {
177  UInt_t ordinal= RooRandom::integer(numTypes(rangeName));
178  setOrdinal(ordinal,rangeName);
179 }
180 
181 
182 
183 ////////////////////////////////////////////////////////////////////////////////
184 /// Set category to i-th fit bin, which is the i-th registered state.
185 
186 void RooAbsCategoryLValue::setBin(Int_t ibin, const char* rangeName)
187 {
188  // Check validity of ibin
189  if (ibin<0 || ibin>=numBins(rangeName)) {
190  coutE(InputArguments) << "RooAbsCategoryLValue::setBin(" << GetName() << ") ERROR: bin index " << ibin
191  << " is out of range (0," << numBins(rangeName)-1 << ")" << endl ;
192  return ;
193  }
194 
195  // Retrieve state corresponding to bin
196  const RooCatType* type = getOrdinal(ibin,rangeName) ;
197 
198  // Set value to requested state
199  setIndex(type->getVal()) ;
200 }
201 
202 
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Get index of plot bin for current value this category.
206 
207 Int_t RooAbsCategoryLValue::getBin(const char* /*rangeName*/) const
208 {
209  //Synchronize _value
210  getLabel() ;
211 
212  // Lookup ordinal index number
214 }
215 
216 
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Returm the number of fit bins ( = number of types )
220 
221 Int_t RooAbsCategoryLValue::numBins(const char* rangeName) const
222 {
223  return numTypes(rangeName) ;
224 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
#define coutE(a)
Definition: RooMsgService.h:34
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValueDirty=kTRUE)
Copy the cached value from given source and raise dirty flag.
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream (dummy implementation)
RooCatType _value
Transient cache for byte values from tree branches.
const RooCatType * getOrdinal(UInt_t n, const char *rangeName=0) const
Return state definition of ordinal nth defined state, needed by the generator mechanism.
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)=0
static UInt_t integer(UInt_t max, TRandom *generator=randomGenerator())
Return an integer uniformly distributed from [0,n-1].
Definition: RooRandom.cxx:102
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
Bool_t setOrdinal(UInt_t index, const char *rangeName)
Set our state to our n&#39;th defined type and return kTRUE.
void setValueDirty() const
Definition: RooAbsArg.h:441
virtual void randomize(const char *rangeName=0)
Randomize current value.
virtual Int_t getBin(const char *rangeName=0) const
Get index of plot bin for current value this category.
virtual Bool_t isValid() const
Check if current value is a valid state.
virtual Int_t numBins(const char *rangeName) const
Returm the number of fit bins ( = number of types )
Int_t numTypes(const char *=0) const
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Definition: TObjArray.cxx:414
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
Definition: RooCatType.h:22
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream (dummy implementation)
virtual const Text_t * GetName() const
Returns name of object.
Definition: RooCatType.h:44
const RooCatType * lookupType(Int_t index, Bool_t printError=kFALSE) const
Find our type corresponding to the specified index, or return 0 for no match.
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual const char * getLabel() const
Return label string of current state.
const Bool_t kFALSE
Definition: RtypesCore.h:88
#define ClassImp(name)
Definition: Rtypes.h:359
int type
Definition: TGX11.cxx:120
Int_t IndexOf(const TObject *obj) const
Definition: TObjArray.cxx:589
void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)
Copy the cached value from given source and raise dirty flag.
virtual ~RooAbsCategoryLValue()
Destructor.
void setShapeDirty() const
Definition: RooAbsArg.h:442
Int_t getVal() const
Definition: RooCatType.h:79
virtual void setBin(Int_t ibin, const char *rangeName=0)
Set category to i-th fit bin, which is the i-th registered state.
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
TObjArray _types
Abstract base class for objects that are lvalues, i.e.
Definition: RooAbsLValue.h:26
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
RooAbsArg & operator=(int index)
Assignment operator from integer index number.
const Bool_t kTRUE
Definition: RtypesCore.h:87
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109
virtual Bool_t setIndex(Int_t index, Bool_t printError=kTRUE)=0