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