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
22Joins 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"
38#include "RooMsgService.h"
39
40#include "TString.h"
41#include "TClass.h"
42
43using std::endl, std::ostream;
44
46
48
49////////////////////////////////////////////////////////////////////////////////
50/// Construct a super category from other categories.
51/// \param[in] name Name of this object
52/// \param[in] title Title (for e.g. printing)
53/// \param[in] inputCategories RooArgSet with category objects. These all need to derive from RooAbsCategoryLValue, *i.e.*
54/// one needs to be able to assign to them.
55RooSuperCategory::RooSuperCategory(const char *name, const char *title, const RooArgSet& inputCategories) :
57 _multiCat("MultiCatProxy", "Stores a RooMultiCategory", this,
58 std::make_unique<RooMultiCategory>((std::string(name) + "_internalMultiCat").c_str(), title, inputCategories), true, true)
59{
60 // Check category list
61 for (const auto arg : inputCategories) {
62 if (!arg->IsA()->InheritsFrom(RooAbsCategoryLValue::Class())) {
63 coutE(InputArguments) << "RooSuperCategory::RooSuperCategory(" << GetName() << "): input category " << arg->GetName()
64 << " is not an lvalue. Use RooMultiCategory instead." << endl ;
65 throw std::invalid_argument("Arguments of RooSuperCategory must be lvalues.");
66 }
67 }
69}
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Copy constructor
75
78 _multiCat("MultiCatProxy", this, other._multiCat)
79{
82}
83
84
85////////////////////////////////////////////////////////////////////////////////
86/// Set the value of the super category to the specified index.
87/// This will propagate to the sub-categories, and set their state accordingly.
89{
90 if (index < 0) {
91 if (printError)
92 coutE(InputArguments) << "RooSuperCategory can only have positive index states. Got " << index << std::endl;
93 return true;
94 }
95
96 bool error = false;
97 for (auto arg : _multiCat->_catSet) {
98 auto cat = static_cast<RooAbsCategoryLValue*>(arg);
99 if (cat->empty()) {
100 if (printError) {
101 coutE(InputArguments) << __func__ << ": Found a category with zero states. Cannot set state for '"
102 << cat->GetName() << "'." << std::endl;
103 }
104 continue;
105 }
106 const value_type thisIndex = index % cat->size();
107 error |= cat->setOrdinal(thisIndex);
108 index = (index - thisIndex) / cat->size();
109 }
110
111 return error;
112}
113
114
115
116////////////////////////////////////////////////////////////////////////////////
117/// Set the value of the super category by specifying the state name.
118/// This looks up the corresponding index number, and calls setIndex().
119bool RooSuperCategory::setLabel(const char* label, bool printError)
120{
121 const value_type index = _multiCat->lookupIndex(label);
122 return setIndex(index, printError);
123}
124
125
126////////////////////////////////////////////////////////////////////////////////
127/// Print the state of this object to the specified output stream.
128
129void RooSuperCategory::printMultiline(ostream& os, Int_t content, bool verbose, TString indent) const
130{
131 RooAbsCategory::printMultiline(os,content,verbose,indent) ;
132
133 if (verbose) {
134 os << indent << "--- RooSuperCategory ---" << '\n';
135 os << indent << " Internal RooMultiCategory:" << '\n';
136 _multiCat->printMultiline(os, content, verbose, indent+" ");
137
138 os << std::endl;
139 }
140}
141
142
143////////////////////////////////////////////////////////////////////////////////
144/// Check that all input category states are in the given range.
145bool RooSuperCategory::inRange(const char* rangeName) const
146{
147 for (const auto c : _multiCat->inputCatList()) {
148 auto cat = static_cast<RooAbsCategoryLValue*>(c);
149 if (!cat->inRange(rangeName)) {
150 return false;
151 }
152 }
153
154 return true;
155}
156
157
158////////////////////////////////////////////////////////////////////////////////
159/// Check that any of the input categories has a range with the given name.
160bool RooSuperCategory::hasRange(const char* rangeName) const
161{
162 for (const auto c : _multiCat->inputCatList()) {
163 auto cat = static_cast<RooAbsCategoryLValue*>(c);
164 if (cat->hasRange(rangeName)) return true;
165 }
166
167 return false;
168}
#define c(i)
Definition RSha256.hxx:101
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:382
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:436
Abstract base class for objects that represent a discrete value that can be set from the outside,...
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:24
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
Joins 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.
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
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:139