ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
22 Class RooThresholdCategory provides a real-to-category mapping defined
23 by 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 <stdio.h>
33 #include "TString.h"
34 #include "RooThresholdCategory.h"
35 #include "RooStreamParser.h"
36 #include "RooThreshEntry.h"
37 #include "RooMsgService.h"
38 
39 using namespace std;
40 
42 
43 
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Constructor with input function to be mapped and name and index of default
47 /// output state of unmapped values
48 
49 RooThresholdCategory::RooThresholdCategory(const char *name, const char *title, RooAbsReal& inputVar,
50  const char* defOut, Int_t defIdx) :
51  RooAbsCategory(name, title), _inputVar("inputVar","Input category",this,inputVar)
52 {
53  _defCat = (RooCatType*) defineType(defOut,defIdx) ;
54  _threshIter = _threshList.MakeIterator() ;
55 }
56 
57 
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Copy constructor
61 
63  RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar)
64 {
66 
67  other._threshIter->Reset() ;
68  RooThreshEntry* te ;
69  while((te=(RooThreshEntry*)other._threshIter->Next())) {
70  _threshList.Add(new RooThreshEntry(*te)) ;
71  }
72 
74 }
75 
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Destructor
80 
82 {
84  delete _threshIter ;
85 }
86 
87 
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Insert threshold at value upperLimit. All values below upper limit (and above any lower
91 /// thresholds, if any) will be mapped to a state name 'catName' with index 'catIdx'
92 
93 Bool_t RooThresholdCategory::addThreshold(Double_t upperLimit, const char* catName, Int_t catIdx)
94 {
95  // Check if identical threshold values is not defined yet
96  _threshIter->Reset() ;
97  RooThreshEntry* te ;
98  while ((te=(RooThreshEntry*)_threshIter->Next())) {
99  if (te->thresh() == upperLimit) {
100  coutW(InputArguments) << "RooThresholdCategory::addThreshold(" << GetName()
101  << ") threshold at " << upperLimit << " already defined" << endl ;
102  return kTRUE ;
103  }
104  }
105 
106 
107  // Add a threshold entry
108  const RooCatType* type = lookupType(catName,kFALSE) ;
109  if (!type) {
110  if (catIdx==-99999) {
111  type=defineType(catName) ;
112  } else {
113  type=defineType(catName,catIdx) ;
114  }
115  }
116  te = new RooThreshEntry(upperLimit,*type) ;
117  _threshList.Add(te) ;
118 
119  return kFALSE ;
120 }
121 
122 
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Calculate and return the value of the mapping function
126 
128 {
129  // Scan the threshold list
130  _threshIter->Reset() ;
131  RooThreshEntry* te ;
132  while((te=(RooThreshEntry*)_threshIter->Next())) {
133  if (_inputVar<te->thresh()) return te->cat() ;
134  }
135 
136  // Return default if nothing found
137  return *_defCat ;
138 }
139 
140 
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Write object contents to given stream
144 
145 void RooThresholdCategory::writeToStream(ostream& os, Bool_t compact) const
146 {
147  if (compact) {
148  // Write value only
149  os << getLabel() ;
150  } else {
151  // Write mapping expression
152 
153  // Scan list of threshold
154  _threshIter->Reset() ;
155  RooThreshEntry* te ;
156  while((te=(RooThreshEntry*)_threshIter->Next())) {
157  os << te->cat().GetName() << ":<" << te->thresh() << " " ;
158  }
159  os << _defCat->GetName() << ":*" ;
160  }
161 }
162 
163 
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Print info about this threshold category to the specified stream. In addition to the info
167 /// from RooAbsCategory::printStream() we add:
168 ///
169 /// Standard : input category
170 /// Shape : default value
171 /// Verbose : list of thresholds
172 
174 {
175  RooAbsCategory::printMultiline(os,content,verbose,indent);
176 
177  if (verbose) {
178  os << indent << "--- RooThresholdCategory ---" << endl
179  << indent << " Maps from " ;
181 
182  os << indent << " Threshold list" << endl ;
183  _threshIter->Reset() ;
184  RooThreshEntry* te ;
185  while((te=(RooThreshEntry*)_threshIter->Next())) {
186  os << indent << " input < " << te->thresh() << " --> " ;
188  }
189  os << indent << " Default value is " ;
191 
192 
193  }
194 }
195 
196 
virtual ~RooThresholdCategory()
Destructor.
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:405
virtual void Reset()=0
ClassImp(RooThresholdCategory) RooThresholdCategory
Constructor with input function to be mapped and name and index of default output state of unmapped v...
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, which is interpreted as an OR of 'enum ContentsOptions' values and in the style given by 'enum StyleOption'.
Double_t thresh() const
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
#define coutW(a)
Definition: RooMsgService.h:34
const RooAbsReal & arg() const
Definition: RooRealProxy.h:43
void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
Class RooThresholdCategory provides a real-to-category mapping defined by a series of thresholds...
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
Definition: RooCatType.h:23
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.
virtual RooCatType evaluate() const
do not persist
Bool_t addThreshold(Double_t upperLimit, const char *catName, Int_t catIdx=-99999)
Insert threshold at value upperLimit.
const RooCatType * defineType(const char *label)
Define a new state with given name.
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
bool verbose
Class RooThreshEntry is a utility class for RooThresholdCategory.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
static void indent(ostringstream &buf, int indent_level)
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
int type
Definition: TGX11.cxx:120
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual TObject * Next()=0
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 TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition: TList.cxx:604
void Add(TObject *obj)
const Bool_t kTRUE
Definition: Rtypes.h:91
const RooCatType & cat() const
virtual const Text_t * GetName() const
Returns name of object.
Definition: RooCatType.h:45
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.
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.