Logo ROOT   6.14/05
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 
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 "TString.h"
33 #include "RooThresholdCategory.h"
34 #include "RooStreamParser.h"
35 #include "RooThreshEntry.h"
36 #include "RooMsgService.h"
37 
38 using 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 
48 RooThresholdCategory::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())) {
69  _threshList.Add(new RooThreshEntry(*te)) ;
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 
92 Bool_t RooThresholdCategory::addThreshold(Double_t upperLimit, const char* catName, Int_t catIdx)
93 {
94  // Check if identical threshold values is not defined yet
95  _threshIter->Reset() ;
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 
144 void 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 
172 void 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 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual ~RooThresholdCategory()
Destructor.
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 &#39;enum ContentsOptions&#39; values and in the style given by &#39;enum StyleOption&#39;.
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
virtual void Reset()=0
Double_t thresh() const
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
STL namespace.
#define coutW(a)
Definition: RooMsgService.h:33
const RooCatType & cat() const
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.
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:22
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition: TList.cxx:718
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.
virtual const Text_t * GetName() const
Returns name of object.
Definition: RooCatType.h:44
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.
Class RooThreshEntry is a utility class for RooThresholdCategory.
virtual const char * getLabel() const
Return label string of current state.
virtual RooCatType evaluate() const
do not persist
const Bool_t kFALSE
Definition: RtypesCore.h:88
#define ClassImp(name)
Definition: Rtypes.h:359
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.
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
virtual TObject * Next()=0
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
void Add(TObject *obj)
Add object in sorted list.
Definition: TSortedList.cxx:27
const RooAbsReal & arg() const
Definition: RooRealProxy.h:43
const Bool_t kTRUE
Definition: RtypesCore.h:87
char name[80]
Definition: TGX11.cxx:109