Logo ROOT  
Reference Guide
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 "Riostream.h"
35#include "RooStreamParser.h"
36#include "RooArgSet.h"
39#include "RooMsgService.h"
40
41#include "TString.h"
42#include "TClass.h"
43
44using namespace std;
45
47
50 _multiCat("MultiCatProxy", "Stores a RooMultiCategory", this, true, true, true) { }
51
52////////////////////////////////////////////////////////////////////////////////
53/// Construct a super category from other categories.
54/// \param[in] name Name of this object
55/// \param[in] title Title (for e.g. printing)
56/// \param[in] inputCategories RooArgSet with category objects. These all need to derive from RooAbsCategoryLValue, *i.e.*
57/// one needs to be able to assign to them.
58RooSuperCategory::RooSuperCategory(const char *name, const char *title, const RooArgSet& inputCategories) :
60 _multiCat("MultiCatProxy", "Stores a RooMultiCategory", this,
61 *new RooMultiCategory((std::string(name) + "_internalMultiCat").c_str(), title, inputCategories), true, true, true)
62{
63 // Check category list
64 for (const auto arg : inputCategories) {
65 if (!arg->IsA()->InheritsFrom(RooAbsCategoryLValue::Class())) {
66 coutE(InputArguments) << "RooSuperCategory::RooSuperCategory(" << GetName() << "): input category " << arg->GetName()
67 << " is not an lvalue. Use RooMultiCategory instead." << endl ;
68 throw std::invalid_argument("Arguments of RooSuperCategory must be lvalues.");
69 }
70 }
72}
73
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// Copy constructor
78
81 _multiCat("MultiCatProxy", this, other._multiCat)
82{
85}
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// Make an iterator over all state permutations of
90/// the input categories of this supercategory.
91/// The iterator just generates state names, it does not set them.
93{
95}
96
97
98////////////////////////////////////////////////////////////////////////////////
99/// Set the value of the super category to the specified index.
100/// This will propagate to the sub-categories, and set their state accordingly.
102{
103 if (index < 0) {
104 if (printError)
105 coutE(InputArguments) << "RooSuperCategory can only have positive index states. Got " << index << std::endl;
106 return true;
107 }
108
109 bool error = false;
110 for (auto arg : _multiCat->_catSet) {
111 auto cat = static_cast<RooAbsCategoryLValue*>(arg);
112 if (cat->empty()) {
113 if (printError)
114 coutE(InputArguments) << __func__ << ": Found a category with zero states. Cannot set state for '"
115 << cat->GetName() << "'." << std::endl;
116 continue;
117 }
118 const value_type thisIndex = index % cat->size();
119 error |= cat->setOrdinal(thisIndex);
120 index = (index - thisIndex) / cat->size();
121 }
122
123 return error;
124}
125
126
127
128////////////////////////////////////////////////////////////////////////////////
129/// Set the value of the super category by specifying the state name.
130/// This looks up the corresponding index number, and calls setIndex().
131bool RooSuperCategory::setLabel(const char* label, bool printError)
132{
133 const value_type index = _multiCat->lookupIndex(label);
134 return setIndex(index, printError);
135}
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// Print the state of this object to the specified output stream.
140
141void RooSuperCategory::printMultiline(ostream& os, Int_t content, bool verbose, TString indent) const
142{
144
145 if (verbose) {
146 os << indent << "--- RooSuperCategory ---" << '\n';
147 os << indent << " Internal RooMultiCategory:" << '\n';
148 _multiCat->printMultiline(os, content, verbose, indent+" ");
149
150 os << std::endl;
151 }
152}
153
154
155////////////////////////////////////////////////////////////////////////////////
156/// Check that all input category states are in the given range.
157bool RooSuperCategory::inRange(const char* rangeName) const
158{
159 for (const auto c : _multiCat->inputCatList()) {
160 auto cat = static_cast<RooAbsCategoryLValue*>(c);
161 if (!cat->inRange(rangeName)) {
162 return false;
163 }
164 }
165
166 return true;
167}
168
169
170////////////////////////////////////////////////////////////////////////////////
171/// Check that any of the input categories has a range with the given name.
172bool RooSuperCategory::hasRange(const char* rangeName) const
173{
174 for (const auto c : _multiCat->inputCatList()) {
175 auto cat = static_cast<RooAbsCategoryLValue*>(c);
176 if (cat->hasRange(rangeName)) return true;
177 }
178
179 return false;
180}
#define c(i)
Definition: RSha256.hxx:101
#define coutE(a)
Definition: RooMsgService.h:37
#define ClassImp(name)
Definition: Rtypes.h:375
static void indent(ostringstream &buf, int indent_level)
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
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...
static TClass * Class()
virtual value_type getCurrentIndex() const
Return index number of current state.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
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:57
RooMultiCategory connects several RooAbsCategory objects into a single category.
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Print the state of this object to the specified output stream.
RooSetProxy _catSet
Set of input category.
const RooArgSet & inputCatList() const
The RooSuperCategory can join several RooAbsCategoryLValue objects into a single category.
bool setIndex(value_type index, bool printError=true) override
Set the value of the super category to the specified index.
bool hasRange(const char *rangeName) const override
Check that any of the input categories has a range with the given name.
bool inRange(const char *rangeName) const override
Check that all input category states are in the given range.
TIterator * MakeIterator() const
Make an iterator over all state permutations of the input categories of this supercategory.
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Print the state of this object to the specified output stream.
bool setLabel(const char *label, bool printError=true) override
Set the value of the super category by specifying the state name.
RooTemplateProxy< RooMultiCategory > _multiCat
Iterator abstract base class.
Definition: TIterator.h:30
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:136
@ InputArguments
Definition: RooGlobalFunc.h:64