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