Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
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
22Abstract base class for objects that represent a
23discrete value that can be set from the outside, i.e. that may appear on the left
24hand side of an assignment ("*lvalue*").
25
26Each implementation must provide the functions setIndex()/setLabel() to allow direct modification
27of the value. RooAbsCategoryLValue may be derived, but its functional relation
28to other RooAbsArgs must be invertible.
29*/
30
32
33#include <RooRandom.h>
34#include <RooMsgService.h>
35
36
37
38
39
40////////////////////////////////////////////////////////////////////////////////
41/// Constructor
42
43RooAbsCategoryLValue::RooAbsCategoryLValue(const char *name, const char *title) :
44 RooAbsCategory(name,title)
45{
48}
49
50
51
52////////////////////////////////////////////////////////////////////////////////
53/// Copy constructor
54
59
60
61
62////////////////////////////////////////////////////////////////////////////////
63/// Assignment operator from integer index number
64
66{
67 setIndex(index,true) ;
68 return *this ;
69}
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Assignment operator from string pointer
75
77{
78 setLabel(label) ;
79 return *this ;
80}
81
82
83
84////////////////////////////////////////////////////////////////////////////////
85/// Assignment from another RooAbsCategory. This will use the *state name*
86/// of the other object to set the corresponding state. This is less efficient
87/// then directly assigning the state index.
89{
90 if (&other==this) return *this ;
91
92 const auto index = lookupIndex(other.getCurrentLabel());
93 if (index == std::numeric_limits<value_type>::min()) {
94 coutE(ObjectHandling) << "Trying to assign the label '" << other.getCurrentLabel() << "' to category'"
95 << GetName() << "', but such a label is not defined." << std::endl;
96 return *this;
97 }
98
101
102 return *this;
103}
104
105
106////////////////////////////////////////////////////////////////////////////////
107/// Set our state to our `n`th defined type.
108/// \return true in case of an error.
110{
111 return setIndex(getOrdinal(n).second, true);
112}
113
114
115
116////////////////////////////////////////////////////////////////////////////////
117/// Copy the cached value from given source and raise dirty flag.
118/// It is the callers responsibility to ensure that the sources
119/// cache is clean(valid) before this function is called, e.g. by
120/// calling syncCache() on the source.
121
123{
125
126 if (isValid()) {
127 setIndex(_currentIndex); // force back-propagation
128 }
129}
130
131
132////////////////////////////////////////////////////////////////////////////////
133/// Randomize current value.
134/// If the result is not in the range, the randomisation is repeated.
136{
137 const auto& theStateNames = stateNames();
138
139 if (_insertionOrder.size() == theStateNames.size()) {
140 // If users didn't manipulate the state map directly, the order of insertion has to be respected to
141 // ensure backward compatibility.
142 // This heavily uses strings, though.
143 do {
145 const auto item = theStateNames.find(_insertionOrder[ordinal]);
146 setIndex(item->second);
147 } while (!inRange(rangeName));
148 } else {
149 // When not having to respect the insertion order, can just advance the iterator
150 do {
152 const auto it = std::next(theStateNames.begin(), ordinal);
153 setIndex(it->second);
154 } while (!inRange(rangeName));
155 }
156}
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// Set category to i-th fit bin, which is the i-th registered state.
161
163{
164 // Check validity of ibin
166 coutE(InputArguments) << "RooAbsCategoryLValue::setBin(" << GetName() << ") ERROR: bin index " << ibin
167 << " is out of range (0," << numBins(rangeName)-1 << ")" << std::endl;
168 return ;
169 }
170
172 coutF(InputArguments) << "RooAbsCategoryLValue::setBin(" << GetName() << ") ERROR: ranges not implemented"
173 " for setting bins in categories." << std::endl;
174 throw std::logic_error("Ranges not implemented for setting bins in categories.");
175 }
176
177 // Retrieve state corresponding to bin
178 value_type val = getOrdinal(ibin).second;
179 assert(val != std::numeric_limits<value_type>::min());
180
181 // Set value to requested state
182 setIndex(val);
183}
184
185
186////////////////////////////////////////////////////////////////////////////////
187/// Return the number of fit bins ( = number of types )
189{
190 return numTypes(rangeName) ;
191}
#define coutF(a)
#define coutE(a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Definition TGX11.cxx:110
const_iterator begin() const
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition RooAbsArg.h:436
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:431
virtual bool inRange(const char *) const
Definition RooAbsArg.h:319
Abstract base class for objects that represent a discrete value that can be set from the outside,...
void randomize(const char *rangeName=nullptr) override
Randomize current value.
virtual bool setIndex(value_type index, bool printError=true)=0
Change category state by specifying the index code of the desired state.
void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true) override
Copy the cached value from given source and raise dirty flag.
Int_t numBins(const char *rangeName=nullptr) const override
Return the number of fit bins ( = number of types )
bool setOrdinal(unsigned int index)
Set our state to our nth defined type.
RooAbsArg & operator=(int index)
Assignment operator from integer index number.
void setBin(Int_t ibin, const char *rangeName=nullptr) override
Set category to i-th fit bin, which is the i-th registered state.
const RooAbsBinning * getBinningPtr(const char *) const override
virtual bool setLabel(const char *label, bool printError=true)=0
Change category state by specifying a state name.
A space to attach TBranches.
void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValueDirty=true) override
Copy the cached value from given source and raise dirty flag.
value_type _currentIndex
Current category state.
Int_t numTypes(const char *=nullptr) const
Return number of types defined (in range named rangeName if rangeName!=nullptr)
const std::map< std::string, value_type >::value_type & getOrdinal(unsigned int n) const
Return name and index of the nth defined state.
std::vector< std::string > _insertionOrder
Keeps track in which order state numbers have been inserted. Make sure this is updated in recomputeSh...
bool isValid() const override
WVE (08/21/01) Probably obsolete now.
const std::map< std::string, value_type > & stateNames() const
Access the map of state names to index numbers.
value_type lookupIndex(const std::string &stateName) const
Find the index number corresponding to the state name.
Abstract base class for objects that are lvalues, i.e.
static UInt_t integer(UInt_t max, TRandom *generator=randomGenerator())
Return an integer uniformly distributed from [0,n-1].
Definition RooRandom.cxx:95
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const Int_t n
Definition legend1.C:16