Logo ROOT   6.10/09
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 <string.h>
36 #include "TTree.h"
37 #include "TString.h"
38 #include "TH1.h"
39 #include "RooAbsCategoryLValue.h"
40 #include "RooArgSet.h"
41 #include "RooStreamParser.h"
42 #include "RooRandom.h"
43 #include "RooMsgService.h"
44 
45 using namespace std;
46 
48 ;
49 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Constructor
53 
54 RooAbsCategoryLValue::RooAbsCategoryLValue(const char *name, const char *title) :
55  RooAbsCategory(name,title)
56 {
57  setValueDirty() ;
58  setShapeDirty() ;
59 }
60 
61 
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Copy constructor
65 
67  RooAbsCategory(other, name), RooAbsLValue(other)
68 {
69 }
70 
71 
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Destructor
75 
77 {
78 }
79 
80 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Assignment operator from integer index number
84 
86 {
87  setIndex(index,kTRUE) ;
88  return *this ;
89 }
90 
91 
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Assignment operator from string pointer
95 
97 {
98  setLabel(label) ;
99  return *this ;
100 }
101 
102 
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Assignment from another RooAbsCategory
106 
108 {
109  if (&other==this) return *this ;
110 
111  const RooCatType* type = lookupType(other.getLabel(),kTRUE) ;
112  if (!type) return *this ;
113 
114  _value = *type ;
115  setValueDirty() ;
116  return *this ;
117 }
118 
119 
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Set our state to our n'th defined type and return kTRUE.
123 /// Return kFALSE if n is out of range.
124 
126 {
127  const RooCatType *newValue= getOrdinal(n,rangeName);
128  if(newValue) {
129  return setIndex(newValue->getVal());
130  }
131  else {
132  return kFALSE;
133  }
134 }
135 
136 
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Copy the cached value from given source and raise dirty flag.
140 /// It is the callers responsability to ensure that the sources
141 /// cache is clean(valid) before this function is called, e.g. by
142 /// calling syncCache() on the source.
143 
144 void RooAbsCategoryLValue::copyCache(const RooAbsArg* source, Bool_t valueOnly, Bool_t setValDirty)
145 {
146  RooAbsCategory::copyCache(source,valueOnly,setValDirty) ;
147  if (isValid(_value)) {
148  setIndex(_value.getVal()) ; // force back-propagation
149  }
150 }
151 
152 
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Read object contents from given stream (dummy implementation)
156 
158 {
159  return kTRUE ;
160 }
161 
162 
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Write object contents to given stream (dummy implementation)
166 
168 {
169 }
170 
171 
172 
173 ////////////////////////////////////////////////////////////////////////////////
174 /// Randomize current value
175 
176 void RooAbsCategoryLValue::randomize(const char* rangeName)
177 {
178  UInt_t ordinal= RooRandom::integer(numTypes(rangeName));
179  setOrdinal(ordinal,rangeName);
180 }
181 
182 
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Set category to i-th fit bin, which is the i-th registered state.
186 
187 void RooAbsCategoryLValue::setBin(Int_t ibin, const char* rangeName)
188 {
189  // Check validity of ibin
190  if (ibin<0 || ibin>=numBins(rangeName)) {
191  coutE(InputArguments) << "RooAbsCategoryLValue::setBin(" << GetName() << ") ERROR: bin index " << ibin
192  << " is out of range (0," << numBins(rangeName)-1 << ")" << endl ;
193  return ;
194  }
195 
196  // Retrieve state corresponding to bin
197  const RooCatType* type = getOrdinal(ibin,rangeName) ;
198 
199  // Set value to requested state
200  setIndex(type->getVal()) ;
201 }
202 
203 
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Get index of plot bin for current value this category.
207 
208 Int_t RooAbsCategoryLValue::getBin(const char* /*rangeName*/) const
209 {
210  //Synchronize _value
211  getLabel() ;
212 
213  // Lookup ordinal index number
215 }
216 
217 
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Returm the number of fit bins ( = number of types )
221 
222 Int_t RooAbsCategoryLValue::numBins(const char* rangeName) const
223 {
224  return numTypes(rangeName) ;
225 }
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:439
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:396
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:92
#define ClassImp(name)
Definition: Rtypes.h:336
int type
Definition: TGX11.cxx:120
Int_t IndexOf(const TObject *obj) const
Definition: TObjArray.cxx:552
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:440
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:91
const Int_t n
Definition: legend1.C:16
virtual Bool_t setIndex(Int_t index, Bool_t printError=kTRUE)=0