Logo ROOT  
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. It evaluates the value of `inputVar` passed in the
24 constructor, and converts this into a bin number using a binning defined for
25 the inputVar. The name of this binning is passed in the constructor.
26 **/
27 
28 
29 #include "RooBinningCategory.h"
30 
31 #include "RooFit.h"
32 #include "Riostream.h"
33 #include "RooStreamParser.h"
34 
35 using namespace std;
36 
38 
39 
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Constructor with input function to be mapped and name and index of default
43 /// output state of unmapped values
44 
45 RooBinningCategory::RooBinningCategory(const char *name, const char *title, RooAbsRealLValue& inputVar,
46  const char* binningName, const char* catTypeName) :
47  RooAbsCategory(name, title), _inputVar("inputVar","Input category",this,inputVar), _bname(binningName)
48 {
49  initialize(catTypeName) ;
50 
51 }
52 
53 
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Copy constructor
57 
59  RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar), _bname(other._bname)
60 {
61 }
62 
63 
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Destructor
67 
69 {
70 }
71 
72 
73 
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// Iterator over all bins in input variable and define corresponding state labels
77 
78 void RooBinningCategory::initialize(const char* catTypeName)
79 {
80  const int nbins = _inputVar->getBinning(_bname.Length() > 0 ? _bname.Data() : nullptr).numBins();
81  for (Int_t i=0 ; i<nbins ; i++) {
82  string name = catTypeName!=0 ? Form("%s%d",catTypeName,i)
83  : (_bname.Length()>0 ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),i)
84  : Form("%s_bin%d",_inputVar.arg().GetName(),i)) ;
85  defineState(name,i);
86  }
87 }
88 
89 
90 
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Calculate and return the value of the mapping function
94 
96 {
97  Int_t ibin = _inputVar->getBin(_bname.Length() > 0 ? _bname.Data() : nullptr);
98 
99  if (!hasIndex(ibin)) {
100  string name = (_bname.Length()>0) ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),ibin)
101  : Form("%s_bin%d",_inputVar.arg().GetName(),ibin) ;
102  const_cast<RooBinningCategory*>(this)->defineState(name,ibin);
103  }
104 
105  return ibin;
106 }
107 
108 
109 
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Print info about this threshold category to the specified stream. In addition to the info
113 /// from RooAbsCategory::printStream() we add:
114 ///
115 /// Standard : input category
116 /// Shape : default value
117 /// Verbose : list of thresholds
118 
120 {
122 
123  if (verbose) {
124  os << indent << "--- RooBinningCategory ---" << endl
125  << indent << " Maps from " ;
127  }
128 }
129 
130 
RooStreamParser.h
RooAbsBinning::numBins
Int_t numBins() const
Return number of bins.
Definition: RooAbsBinning.h:38
RooBinningCategory.h
RooFit.h
RooTemplateProxy::arg
const T & arg() const
Return reference to object held in proxy.
Definition: RooTemplateProxy.h:290
TString::Data
const char * Data() const
Definition: TString.h:369
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
RooAbsCategory::defineState
virtual const std::map< std::string, RooAbsCategory::value_type >::value_type & defineState(const std::string &label)
Define a new state with given label.
Definition: RooAbsCategory.cxx:213
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
TString
Basic string class.
Definition: TString.h:136
bool
RooAbsCategory
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
Definition: RooAbsCategory.h:37
RooAbsCategory::hasIndex
bool hasIndex(value_type index) const
Check if a state with index index exists.
Definition: RooAbsCategory.cxx:188
RooPrintable::kName
@ kName
Definition: RooPrintable.h:33
RooBinningCategory::RooBinningCategory
RooBinningCategory()
Definition: RooBinningCategory.h:27
RooPrintable::kValue
@ kValue
Definition: RooPrintable.h:33
RooBinningCategory
Class RooBinningCategory provides a real-to-category mapping defined by a series of thresholds.
Definition: RooBinningCategory.h:23
RooAbsCategory::printMultiline
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.
Definition: RooAbsCategory.cxx:406
RooAbsRealLValue::getBin
virtual Int_t getBin(const char *rangeName=0) const
Definition: RooAbsRealLValue.h:53
RooBinningCategory::evaluate
virtual value_type evaluate() const
Calculate and return the value of the mapping function.
Definition: RooBinningCategory.cxx:95
RooBinningCategory::initialize
void initialize(const char *catTypeName=0)
Iterator over all bins in input variable and define corresponding state labels.
Definition: RooBinningCategory.cxx:78
RooBinningCategory::_inputVar
RooTemplateProxy< RooAbsRealLValue > _inputVar
Definition: RooBinningCategory.h:40
RooBinningCategory::~RooBinningCategory
virtual ~RooBinningCategory()
Destructor.
Definition: RooBinningCategory.cxx:68
name
char name[80]
Definition: TGX11.cxx:110
RooPrintable::printStream
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,...
Definition: RooPrintable.cxx:75
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooBinningCategory::printMultiline
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.
Definition: RooBinningCategory.cxx:119
RooPrintable::kSingleLine
@ kSingleLine
Definition: RooPrintable.h:34
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
RooBinningCategory::_bname
TString _bname
Definition: RooBinningCategory.h:41
Riostream.h
RooAbsRealLValue
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
Definition: RooAbsRealLValue.h:31
RooAbsRealLValue::getBinning
virtual const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const =0
Retrive binning configuration with given name or default binning.
int