Logo ROOT   6.16/01
Reference Guide
RooMultiCategory.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 RooMultiCategory.cxx
19\class RooMultiCategory
20\ingroup Roofitcore
21
22RooMultiCategory consolidates several RooAbsCategory objects into
23a single category. The states of the multi-category consist of all the permutations
24of the input categories.
25RooMultiCategory state are automatically defined and updated whenever an input
26category modifies its list of states
27**/
28
29#include "RooFit.h"
30
31#include "Riostream.h"
32#include "Riostream.h"
33#include <stdlib.h>
34#include "TString.h"
35#include "RooMultiCategory.h"
36#include "RooStreamParser.h"
37#include "RooArgSet.h"
38#include "RooMultiCatIter.h"
39#include "RooAbsCategory.h"
40#include "RooMsgService.h"
41
42using namespace std;
43
45;
46
47
48////////////////////////////////////////////////////////////////////////////////
49/// Construct a product of the given set of input RooAbsCategories in 'inInputCatList'
50/// The state names of this product category are {S1;S2,S3,...Sn} where Si are the state names
51/// of the input categories. A RooMultiCategory is not an lvalue
52
53RooMultiCategory::RooMultiCategory(const char *name, const char *title, const RooArgSet& inputCatList2) :
54 RooAbsCategory(name, title), _catSet("input","Input category set",this,kTRUE,kTRUE)
55{
56 // Copy category list
57 TIterator* iter = inputCatList2.createIterator() ;
58 RooAbsArg* arg ;
59 while ((arg=(RooAbsArg*)iter->Next())) {
60 if (!dynamic_cast<RooAbsCategory*>(arg)) {
61 coutE(InputArguments) << "RooMultiCategory::RooMultiCategory(" << GetName() << "): input argument " << arg->GetName()
62 << " is not a RooAbsCategory" << endl ;
63 }
64 _catSet.add(*arg) ;
65 }
66 delete iter ;
67
69}
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Copy constructor
75
77 RooAbsCategory(other,name), _catSet("input",this,other._catSet)
78{
80}
81
82
83
84////////////////////////////////////////////////////////////////////////////////
85/// Destructor
86
88{
89}
90
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// Update the list of super-category states
95
97{
98 // WVE broken if used with derived categories!
99 clearTypes() ;
100
102 TObjString* obj ;
103 while((obj=(TObjString*)iter.Next())) {
104 // Register composite label
105 defineType(obj->String()) ;
106 }
107
108 // Renumbering will invalidate cache
109 setValueDirty() ;
110}
111
112
113
114////////////////////////////////////////////////////////////////////////////////
115/// Return the name of the current state,
116/// constructed from the state names of the input categories
117
119{
120 TIterator* lIter = _catSet.createIterator() ;
121
122 // Construct composite label name
123 TString label ;
124 RooAbsCategory* cat ;
126 while((cat=(RooAbsCategory*) lIter->Next())) {
127 label.Append(first?"{":";") ;
128 label.Append(cat->getLabel()) ;
129 first=kFALSE ;
130 }
131 label.Append("}") ;
132 delete lIter ;
133
134 return label ;
135}
136
137
138
139////////////////////////////////////////////////////////////////////////////////
140/// Calculate the current value
141
143{
144 if (isShapeDirty()) const_cast<RooMultiCategory*>(this)->updateIndexList() ;
145
146 // current label is can be looked up by definition
147 // coverity[NULL_RETURNS]
148 return *lookupType(currentLabel()) ;
149}
150
151
152
153////////////////////////////////////////////////////////////////////////////////
154/// Print the state of this object to the specified output stream.
155
156void RooMultiCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
157{
158 RooAbsCategory::printMultiline(os,content,verbose,indent) ;
159
160 if (verbose) {
161 os << indent << "--- RooMultiCategory ---" << endl;
162 os << indent << " Input category list:" << endl ;
163 TString moreIndent(indent) ;
164 moreIndent.Append(" ") ;
165 _catSet.printStream(os,kName|kValue,kStandard,moreIndent.Data()) ;
166 }
167}
168
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Read object contents from given stream
173
174Bool_t RooMultiCategory::readFromStream(istream& /*is*/, Bool_t /*compact*/, Bool_t /*verbose*/)
175{
176 return kTRUE ;
177}
178
179
180
181////////////////////////////////////////////////////////////////////////////////
182/// Write object contents to given stream
183
184void RooMultiCategory::writeToStream(ostream& os, Bool_t compact) const
185{
187}
#define coutE(a)
Definition: RooMsgService.h:34
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
Bool_t isShapeDirty() const
Definition: RooAbsArg.h:331
void setValueDirty() const
Definition: RooAbsArg.h:441
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
virtual const char * getLabel() const
Return label string of current state.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to ostream.
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print info about this object to the specified stream.
const RooCatType * defineType(const char *label)
Define a new state with given name.
const RooCatType * lookupType(Int_t index, Bool_t printError=kFALSE) const
Find our type corresponding to the specified index, or return 0 for no match.
void clearTypes()
Delete all currently defined states.
TIterator * createIterator(Bool_t dir=kIterForward) const
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
Definition: RooCatType.h:22
RooMultiCatIter iterators over all state permutations of a list of categories.
virtual TObject * Next()
Iterator increment operator.
RooMultiCategory consolidates several RooAbsCategory objects into a single category.
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print the state of this object to the specified output stream.
virtual RooCatType evaluate() const
Calculate the current value.
void updateIndexList()
Update the list of super-category states.
TString currentLabel() const
Return the name of the current state, constructed from the state names of the input categories.
virtual ~RooMultiCategory()
Destructor.
RooSetProxy _catSet
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
Iterator abstract base class.
Definition: TIterator.h:30
virtual TObject * Next()=0
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Collectable string class.
Definition: TObjString.h:28
TString & String()
Definition: TObjString.h:49
@ InputArguments
Definition: RooGlobalFunc.h:58
Definition: first.py:1
STL namespace.