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
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"
38#include "RooMsgService.h"
39
40#include "TString.h"
41#include "TClass.h"
42
43using namespace std;
44
46
49 _multiCat("MultiCatProxy", "Stores a RooMultiCategory", this, true, true, true) { }
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 continue;
106 }
107 const value_type thisIndex = index % cat->size();
108 error |= cat->setOrdinal(thisIndex);
109 index = (index - thisIndex) / cat->size();
110 }
111
112 return error;
113}
114
115
116
117////////////////////////////////////////////////////////////////////////////////
118/// Set the value of the super category by specifying the state name.
119/// This looks up the corresponding index number, and calls setIndex().
120bool RooSuperCategory::setLabel(const char* label, bool printError)
121{
122 const value_type index = _multiCat->lookupIndex(label);
123 return setIndex(index, printError);
124}
125
126
127////////////////////////////////////////////////////////////////////////////////
128/// Print the state of this object to the specified output stream.
129
130void RooSuperCategory::printMultiline(ostream& os, Int_t content, bool verbose, TString indent) const
131{
132 RooAbsCategory::printMultiline(os,content,verbose,indent) ;
133
134 if (verbose) {
135 os << indent << "--- RooSuperCategory ---" << '\n';
136 os << indent << " Internal RooMultiCategory:" << '\n';
137 _multiCat->printMultiline(os, content, verbose, indent+" ");
138
139 os << std::endl;
140 }
141}
142
143
144////////////////////////////////////////////////////////////////////////////////
145/// Check that all input category states are in the given range.
146bool RooSuperCategory::inRange(const char* rangeName) const
147{
148 for (const auto c : _multiCat->inputCatList()) {
149 auto cat = static_cast<RooAbsCategoryLValue*>(c);
150 if (!cat->inRange(rangeName)) {
151 return false;
152 }
153 }
154
155 return true;
156}
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// Check that any of the input categories has a range with the given name.
161bool RooSuperCategory::hasRange(const char* rangeName) const
162{
163 for (const auto c : _multiCat->inputCatList()) {
164 auto cat = static_cast<RooAbsCategoryLValue*>(c);
165 if (cat->hasRange(rangeName)) return true;
166 }
167
168 return false;
169}
#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:492
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:55
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.
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