Logo ROOT   6.16/01
Reference Guide
RooThresholdCategory.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 RooThresholdCategory.cxx
19\class RooThresholdCategory
20\ingroup Roofitcore
21
22Class RooThresholdCategory provides a real-to-category mapping defined
23by a series of thresholds.
24**/
25
26
27#include "RooFit.h"
28
29#include "Riostream.h"
30#include "Riostream.h"
31#include <stdlib.h>
32#include "TString.h"
34#include "RooStreamParser.h"
35#include "RooThreshEntry.h"
36#include "RooMsgService.h"
37
38using namespace std;
39
41
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Constructor with input function to be mapped and name and index of default
46/// output state of unmapped values
47
48RooThresholdCategory::RooThresholdCategory(const char *name, const char *title, RooAbsReal& inputVar,
49 const char* defOut, Int_t defIdx) :
50 RooAbsCategory(name, title), _inputVar("inputVar","Input category",this,inputVar)
51{
52 _defCat = (RooCatType*) defineType(defOut,defIdx) ;
54}
55
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Copy constructor
60
62 RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar)
63{
65
66 other._threshIter->Reset() ;
67 RooThreshEntry* te ;
68 while((te=(RooThreshEntry*)other._threshIter->Next())) {
70 }
71
73}
74
75
76
77////////////////////////////////////////////////////////////////////////////////
78/// Destructor
79
81{
83 delete _threshIter ;
84}
85
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// Insert threshold at value upperLimit. All values below upper limit (and above any lower
90/// thresholds, if any) will be mapped to a state name 'catName' with index 'catIdx'
91
92Bool_t RooThresholdCategory::addThreshold(Double_t upperLimit, const char* catName, Int_t catIdx)
93{
94 // Check if identical threshold values is not defined yet
96 RooThreshEntry* te ;
97 while ((te=(RooThreshEntry*)_threshIter->Next())) {
98 if (te->thresh() == upperLimit) {
99 coutW(InputArguments) << "RooThresholdCategory::addThreshold(" << GetName()
100 << ") threshold at " << upperLimit << " already defined" << endl ;
101 return kTRUE ;
102 }
103 }
104
105
106 // Add a threshold entry
107 const RooCatType* type = lookupType(catName,kFALSE) ;
108 if (!type) {
109 if (catIdx==-99999) {
110 type=defineType(catName) ;
111 } else {
112 type=defineType(catName,catIdx) ;
113 }
114 }
115 te = new RooThreshEntry(upperLimit,*type) ;
116 _threshList.Add(te) ;
117
118 return kFALSE ;
119}
120
121
122
123////////////////////////////////////////////////////////////////////////////////
124/// Calculate and return the value of the mapping function
125
127{
128 // Scan the threshold list
129 _threshIter->Reset() ;
130 RooThreshEntry* te ;
131 while((te=(RooThreshEntry*)_threshIter->Next())) {
132 if (_inputVar<te->thresh()) return te->cat() ;
133 }
134
135 // Return default if nothing found
136 return *_defCat ;
137}
138
139
140
141////////////////////////////////////////////////////////////////////////////////
142/// Write object contents to given stream
143
144void RooThresholdCategory::writeToStream(ostream& os, Bool_t compact) const
145{
146 if (compact) {
147 // Write value only
148 os << getLabel() ;
149 } else {
150 // Write mapping expression
151
152 // Scan list of threshold
153 _threshIter->Reset() ;
154 RooThreshEntry* te ;
155 while((te=(RooThreshEntry*)_threshIter->Next())) {
156 os << te->cat().GetName() << ":<" << te->thresh() << " " ;
157 }
158 os << _defCat->GetName() << ":*" ;
159 }
160}
161
162
163
164////////////////////////////////////////////////////////////////////////////////
165/// Print info about this threshold category to the specified stream. In addition to the info
166/// from RooAbsCategory::printStream() we add:
167///
168/// Standard : input category
169/// Shape : default value
170/// Verbose : list of thresholds
171
172void RooThresholdCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
173{
174 RooAbsCategory::printMultiline(os,content,verbose,indent);
175
176 if (verbose) {
177 os << indent << "--- RooThresholdCategory ---" << endl
178 << indent << " Maps from " ;
180
181 os << indent << " Threshold list" << endl ;
182 _threshIter->Reset() ;
183 RooThreshEntry* te ;
184 while((te=(RooThreshEntry*)_threshIter->Next())) {
185 os << indent << " input < " << te->thresh() << " --> " ;
187 }
188 os << indent << " Default value is " ;
190
191
192 }
193}
194
195
#define coutW(a)
Definition: RooMsgService.h:33
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
int type
Definition: TGX11.cxx:120
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 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.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
Definition: RooCatType.h:22
virtual const Text_t * GetName() const
Returns name of object.
Definition: RooCatType.h:44
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,...
const RooAbsReal & arg() const
Definition: RooRealProxy.h:43
Class RooThreshEntry is a utility class for RooThresholdCategory.
Double_t thresh() const
const RooCatType & cat() const
Class RooThresholdCategory provides a real-to-category mapping defined by a series of thresholds.
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print info about this threshold category to the specified stream.
void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
Bool_t addThreshold(Double_t upperLimit, const char *catName, Int_t catIdx=-99999)
Insert threshold at value upperLimit.
virtual ~RooThresholdCategory()
Destructor.
virtual RooCatType evaluate() const
do not persist
virtual void Reset()=0
virtual TObject * Next()=0
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition: TList.cxx:718
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void Add(TObject *obj)
Add object in sorted list.
Definition: TSortedList.cxx:27
@ InputArguments
Definition: RooGlobalFunc.h:58
STL namespace.