Logo ROOT  
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
22RooAbsCategoryLValue is the common abstract base class for objects that represent a
23discrete value that may appear on the left hand side of an equation ('lvalue')
24
25Each implementation must provide setIndex()/setLabel() members to allow direct modification
26of the value. RooAbsCategoryLValue may be derived, but its functional relation
27to 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"
39#include "RooArgSet.h"
40#include "RooStreamParser.h"
41#include "RooRandom.h"
42#include "RooMsgService.h"
43
44using namespace std;
45
47;
48
49
50////////////////////////////////////////////////////////////////////////////////
51/// Constructor
52
53RooAbsCategoryLValue::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
143void 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
175void 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
186void 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
207Int_t RooAbsCategoryLValue::getBin(const char* /*rangeName*/) const
208{
209 //Synchronize _value
210 getLabel() ;
211
212 // Lookup ordinal index number
213 std::string theName = _value.GetName();
214 auto item = std::find_if(_types.begin(), _types.end(), [&theName](const RooCatType* cat){
215 return cat->GetName() == theName;
216 });
217
218 return item - _types.begin();
219}
220
221
222
223////////////////////////////////////////////////////////////////////////////////
224/// Returm the number of fit bins ( = number of types )
225
226Int_t RooAbsCategoryLValue::numBins(const char* rangeName) const
227{
228 return numTypes(rangeName) ;
229}
#define coutE(a)
Definition: RooMsgService.h:34
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
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
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:466
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)=0
virtual Bool_t setIndex(Int_t index, Bool_t printError=kTRUE)=0
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 Int_t getBin(const char *rangeName=0) const
Get index of plot bin for current value this category.
virtual void randomize(const char *rangeName=0)
Randomize current value.
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream (dummy implementation)
virtual void setBin(Int_t ibin, const char *rangeName=0)
Set category to i-th fit bin, which is the i-th registered state.
virtual ~RooAbsCategoryLValue()
Destructor.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream (dummy implementation)
RooAbsArg & operator=(int index)
Assignment operator from integer index number.
virtual Int_t numBins(const char *rangeName) const
Returm the number of fit bins ( = number of types )
Bool_t setOrdinal(UInt_t index, const char *rangeName)
Set our state to our n'th defined type and return kTRUE.
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
std::vector< RooCatType * > _types
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.
const RooCatType * getOrdinal(UInt_t n, const char *rangeName=0) const
Return state definition of ordinal nth defined state, needed by the generator mechanism.
RooCatType _value
Transient cache for byte values from tree branches.
virtual Bool_t isValid() const
Check if current value is a valid state.
virtual const char * getLabel() const
Return label string of current state.
Int_t numTypes(const char *=0) const
Return number of types defined (in range named rangeName if rangeName!=0)
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.
Abstract base class for objects that are lvalues, i.e.
Definition: RooAbsLValue.h:26
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
Definition: RooCatType.h:22
virtual const Text_t * GetName() const
Returns name of object.
Definition: RooCatType.h:44
Int_t getVal() const
Definition: RooCatType.h:79
static UInt_t integer(UInt_t max, TRandom *generator=randomGenerator())
Return an integer uniformly distributed from [0,n-1].
Definition: RooRandom.cxx:102
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
const Int_t n
Definition: legend1.C:16
@ InputArguments
Definition: RooGlobalFunc.h:68