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