Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooSuperCategory.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 RooSuperCategory.cxx
19\class RooSuperCategory
20\ingroup Roofitcore
21
22The RooSuperCategory can join several RooAbsCategoryLValue objects into
23a single category. For this, it uses a RooMultiCategory, which takes care
24of enumerating all the permutations of possible states.
25In addition, the super category derives from RooAbsCategoryLValue, *i.e.*, it allows for
26setting its state (opposed to the RooMultiCategory, which just reacts
27to the states of its subcategories). This requires that all input categories
28are lvalues as well. This is because a modification of the state of the
29supercategory will propagate to its input categories.
30**/
31
32#include "RooSuperCategory.h"
33
34#include "RooFit.h"
35#include "Riostream.h"
36#include "RooStreamParser.h"
37#include "RooArgSet.h"
40#include "RooMsgService.h"
41
42#include "TString.h"
43#include "TClass.h"
44
45using namespace std;
46
48
51 _multiCat("MultiCatProxy", "Stores a RooMultiCategory", this, true, true, true) { }
52
53////////////////////////////////////////////////////////////////////////////////
54/// Construct a super category from other categories.
55/// \param[in] name Name of this object
56/// \param[in] title Title (for e.g. printing)
57/// \param[in] inputCategories RooArgSet with category objects. These all need to derive from RooAbsCategoryLValue, *i.e.*
58/// one needs to be able to assign to them.
59RooSuperCategory::RooSuperCategory(const char *name, const char *title, const RooArgSet& inputCategories) :
61 _multiCat("MultiCatProxy", "Stores a RooMultiCategory", this,
62 *new RooMultiCategory((std::string(name) + "_internalMultiCat").c_str(), title, inputCategories), true, true, true)
63{
64 // Check category list
65 for (const auto arg : inputCategories) {
66 if (!arg->IsA()->InheritsFrom(RooAbsCategoryLValue::Class())) {
67 coutE(InputArguments) << "RooSuperCategory::RooSuperCategory(" << GetName() << "): input category " << arg->GetName()
68 << " is not an lvalue. Use RooMultiCategory instead." << endl ;
69 throw std::invalid_argument("Arguments of RooSuperCategory must be lvalues.");
70 }
71 }
73}
74
75
76
77////////////////////////////////////////////////////////////////////////////////
78/// Copy constructor
79
82 _multiCat("MultiCatProxy", this, other._multiCat)
83{
86}
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Make an iterator over all state permutations of
91/// the input categories of this supercategory.
92/// The iterator just generates state names, it does not set them.
94{
96}
97
98
99////////////////////////////////////////////////////////////////////////////////
100/// Set the value of the super category to the specified index.
101/// This will propagate to the sub-categories, and set their state accordingly.
103{
104 if (index < 0) {
105 if (printError)
106 coutE(InputArguments) << "RooSuperCategory can only have positive index states. Got " << index << std::endl;
107 return true;
108 }
109
110 bool error = false;
111 for (auto arg : _multiCat->_catSet) {
112 auto cat = static_cast<RooAbsCategoryLValue*>(arg);
113 if (cat->size() == 0) {
114 if (printError)
115 coutE(InputArguments) << __func__ << ": Found a category with zero states. Cannot set state for '"
116 << cat->GetName() << "'." << std::endl;
117 continue;
118 }
119 const value_type thisIndex = index % cat->size();
120 error |= cat->setOrdinal(thisIndex);
121 index = (index - thisIndex) / cat->size();
122 }
123
124 return error;
125}
126
127
128
129////////////////////////////////////////////////////////////////////////////////
130/// Set the value of the super category by specifying the state name.
131/// This looks up the corresponding index number, and calls setIndex().
132Bool_t RooSuperCategory::setLabel(const char* label, Bool_t printError)
133{
134 const value_type index = _multiCat->lookupIndex(label);
135 return setIndex(index, printError);
136}
137
138
139////////////////////////////////////////////////////////////////////////////////
140/// Print the state of this object to the specified output stream.
141
142void RooSuperCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
143{
144 RooAbsCategory::printMultiline(os,content,verbose,indent) ;
145
146 if (verbose) {
147 os << indent << "--- RooSuperCategory ---" << '\n';
148 os << indent << " Internal RooMultiCategory:" << '\n';
149 _multiCat->printMultiline(os, content, verbose, indent+" ");
150
151 os << std::endl;
152 }
153}
154
155
156////////////////////////////////////////////////////////////////////////////////
157/// Check that all input category states are in the given range.
158Bool_t RooSuperCategory::inRange(const char* rangeName) const
159{
160 for (const auto c : _multiCat->inputCatList()) {
161 auto cat = static_cast<RooAbsCategoryLValue*>(c);
162 if (!cat->inRange(rangeName)) {
163 return false;
164 }
165 }
166
167 return true;
168}
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Check that any of the input categories has a range with the given name.
173Bool_t RooSuperCategory::hasRange(const char* rangeName) const
174{
175 for (const auto c : _multiCat->inputCatList()) {
176 auto cat = static_cast<RooAbsCategoryLValue*>(c);
177 if (cat->hasRange(rangeName)) return true;
178 }
179
180 return false;
181}
#define c(i)
Definition RSha256.hxx:101
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:364
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:110
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition RooAbsArg.h:513
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual value_type getCurrentIndex() const
Return index number of current state.
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print info about this object to the specified stream.
value_type lookupIndex(const std::string &stateName) const
Find the index number corresponding to the state name.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
RooMultiCategory connects several RooAbsCategory objects into a single category.
const RooArgSet & inputCatList() const
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const override
Print the state of this object to the specified output stream.
The RooSuperCategory can join several RooAbsCategoryLValue objects into a single category.
virtual bool setIndex(value_type index, bool printError=true) override
Set the value of the super category to the specified index.
virtual Bool_t hasRange(const char *rangeName) const override
Check that any of the input categories has a range with the given name.
virtual Bool_t inRange(const char *rangeName) const override
Check that all input category states are in the given range.
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const override
Print the state of this object to the specified output stream.
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE) override
Set the value of the super category by specifying the state name.
TIterator * MakeIterator() const
Make an iterator over all state permutations of the input categories of this supercategory.
RooTemplateProxy< RooMultiCategory > _multiCat
Iterator abstract base class.
Definition TIterator.h:30
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:136