Logo ROOT   6.08/07
Reference Guide
RooBinningCategory.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 RooBinningCategory.cxx
19 \class RooBinningCategory
20 \ingroup Roofitcore
21 
22 Class RooBinningCategory 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 "RooBinningCategory.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 RooBinningCategory::RooBinningCategory(const char *name, const char *title, RooAbsRealLValue& inputVar,
50  const char* binningName, const char* catTypeName) :
51  RooAbsCategory(name, title), _inputVar("inputVar","Input category",this,inputVar), _bname(binningName)
52 {
53  initialize(catTypeName) ;
54 
55 }
56 
57 
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Copy constructor
61 
63  RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar), _bname(other._bname)
64 {
65 }
66 
67 
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Destructor
71 
73 {
74 }
75 
76 
77 
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// Iterator over all bins in input variable and define corresponding state labels
81 
82 void RooBinningCategory::initialize(const char* catTypeName)
83 {
84  Int_t nbins = ((RooAbsRealLValue&)_inputVar.arg()).getBinning(_bname.Length()>0?_bname.Data():0).numBins() ;
85  for (Int_t i=0 ; i<nbins ; i++) {
86  string name = catTypeName!=0 ? Form("%s%d",catTypeName,i)
87  : (_bname.Length()>0 ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),i)
88  : Form("%s_bin%d",_inputVar.arg().GetName(),i)) ;
89  defineType(name.c_str(),i) ;
90  }
91 }
92 
93 
94 
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// Calculate and return the value of the mapping function
98 
100 {
101  Int_t ibin = ((RooAbsRealLValue&)_inputVar.arg()).getBin(_bname.Length()>0?_bname.Data():0) ;
102  const RooCatType* cat = lookupType(ibin) ;
103  if (!cat) {
104 
105  string name = (_bname.Length()>0) ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),ibin)
106  : Form("%s_bin%d",_inputVar.arg().GetName(),ibin) ;
107  cat = const_cast<RooBinningCategory*>(this)->defineType(name.c_str(),ibin) ;
108  }
109 
110  return *cat ;
111 }
112 
113 
114 
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Print info about this threshold category to the specified stream. In addition to the info
118 /// from RooAbsCategory::printStream() we add:
119 ///
120 /// Standard : input category
121 /// Shape : default value
122 /// Verbose : list of thresholds
123 
124 void RooBinningCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
125 {
126  RooAbsCategory::printMultiline(os,content,verbose,indent);
127 
128  if (verbose) {
129  os << indent << "--- RooBinningCategory ---" << endl
130  << indent << " Maps from " ;
132  }
133 }
134 
135 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
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 printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print info about this threshold category to the specified stream.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
int nbins[3]
STL namespace.
virtual RooCatType evaluate() const
Calculate and return the value of the mapping function.
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
Definition: RooCatType.h:23
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.
bool verbose
char * Form(const char *fmt,...)
Class RooBinningCategory provides a real-to-category mapping defined by a series of thresholds...
static void indent(ostringstream &buf, int indent_level)
void initialize(const char *catTypeName=0)
Iterator over all bins in input variable and define corresponding state labels.
#define ClassImp(name)
Definition: Rtypes.h:279
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.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
const RooAbsReal & arg() const
Definition: RooRealProxy.h:43
void initialize(typename Architecture_t::Matrix_t &A, EInitialization m)
Definition: Functions.h:257
char name[80]
Definition: TGX11.cxx:109
virtual ~RooBinningCategory()
Destructor.