ROOT  6.06/09
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 //
19 // BEGIN_HTML
20 // Class RooBinningCategory provides a real-to-category mapping defined
21 // by a series of thresholds.
22 // END_HTML
23 //
24 
25 
26 #include "RooFit.h"
27 
28 #include "Riostream.h"
29 #include "Riostream.h"
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include "TString.h"
33 #include "RooBinningCategory.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 RooBinningCategory::RooBinningCategory(const char *name, const char *title, RooAbsRealLValue& inputVar,
49  const char* binningName, const char* catTypeName) :
50  RooAbsCategory(name, title), _inputVar("inputVar","Input category",this,inputVar), _bname(binningName)
51 {
52  initialize(catTypeName) ;
53 
54 }
55 
56 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Copy constructor
60 
62  RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar), _bname(other._bname)
63 {
64 }
65 
66 
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Destructor
70 
72 {
73 }
74 
75 
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Iterator over all bins in input variable and define corresponding state labels
80 
81 void RooBinningCategory::initialize(const char* catTypeName)
82 {
83  Int_t nbins = ((RooAbsRealLValue&)_inputVar.arg()).getBinning(_bname.Length()>0?_bname.Data():0).numBins() ;
84  for (Int_t i=0 ; i<nbins ; i++) {
85  string name = catTypeName!=0 ? Form("%s%d",catTypeName,i)
86  : (_bname.Length()>0 ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),i)
87  : Form("%s_bin%d",_inputVar.arg().GetName(),i)) ;
88  defineType(name.c_str(),i) ;
89  }
90 }
91 
92 
93 
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Calculate and return the value of the mapping function
97 
99 {
100  Int_t ibin = ((RooAbsRealLValue&)_inputVar.arg()).getBin(_bname.Length()>0?_bname.Data():0) ;
101  const RooCatType* cat = lookupType(ibin) ;
102  if (!cat) {
103 
104  string name = (_bname.Length()>0) ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),ibin)
105  : Form("%s_bin%d",_inputVar.arg().GetName(),ibin) ;
106  cat = const_cast<RooBinningCategory*>(this)->defineType(name.c_str(),ibin) ;
107  }
108 
109  return *cat ;
110 }
111 
112 
113 
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Print info about this threshold category to the specified stream. In addition to the info
117 /// from RooAbsCategory::printStream() we add:
118 ///
119 /// Standard : input category
120 /// Shape : default value
121 /// Verbose : list of thresholds
122 
124 {
125  RooAbsCategory::printMultiline(os,content,verbose,indent);
126 
127  if (verbose) {
128  os << indent << "--- RooBinningCategory ---" << endl
129  << indent << " Maps from " ;
131  }
132 }
133 
134 
Ssiz_t Length() const
Definition: TString.h:390
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'.
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
int nbins[3]
STL namespace.
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 RooAbsReal & arg() const
Definition: RooRealProxy.h:43
const char * Data() const
Definition: TString.h:349
virtual RooCatType evaluate() const
Calculate and return the value of the mapping function.
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.
bool verbose
char * Form(const char *fmt,...)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
static void indent(ostringstream &buf, int indent_level)
ClassImp(RooBinningCategory) RooBinningCategory
Constructor with input function to be mapped and name and index of default output state of unmapped v...
void initialize(const char *catTypeName=0)
Iterator over all bins in input variable and define corresponding state labels.
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual ~RooBinningCategory()
Destructor.
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.