Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22Provides a real-to-category mapping defined
23by a series of thresholds. It evaluates the value of `inputVar` passed in the
24constructor, and converts this into a bin number using a binning defined for
25the inputVar. The name of this binning is passed in the constructor.
26**/
27
28
29#include "RooBinningCategory.h"
30
31#include "Riostream.h"
32#include "RooStreamParser.h"
33
34
35////////////////////////////////////////////////////////////////////////////////
36/// Constructor with input function to be mapped and name and index of default
37/// output state of unmapped values
38
40 const char* binningName, const char* catTypeName) :
41 RooAbsCategory(name, title), _inputVar("inputVar","Input category",this,inputVar), _bname(binningName)
42{
44}
45
46
47
48////////////////////////////////////////////////////////////////////////////////
49/// Copy constructor
50
52 RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar), _bname(other._bname)
53{
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Iterator over all bins in input variable and define corresponding state labels
58
60{
61 const int nbins = _inputVar->getBinning(_bname.Length() > 0 ? _bname.Data() : nullptr).numBins();
62 for (Int_t i=0 ; i<nbins ; i++) {
63 std::string name = catTypeName!=nullptr ? Form("%s%d",catTypeName,i)
64 : (_bname.Length()>0 ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),i)
65 : Form("%s_bin%d",_inputVar.arg().GetName(),i)) ;
67 }
68}
69
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Calculate and return the value of the mapping function
75
77{
78 Int_t ibin = _inputVar->getBin(_bname.Length() > 0 ? _bname.Data() : nullptr);
79
80 if (!hasIndex(ibin)) {
81 std::string name = (_bname.Length()>0) ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),ibin)
82 : Form("%s_bin%d",_inputVar.arg().GetName(),ibin) ;
83 const_cast<RooBinningCategory*>(this)->defineState(name,ibin);
84 }
85
86 return ibin;
87}
88
89
90
91
92////////////////////////////////////////////////////////////////////////////////
93/// Print info about this threshold category to the specified stream. In addition to the info
94/// from RooAbsCategory::printStream() we add:
95///
96/// Standard : input category
97/// Shape : default value
98/// Verbose : list of thresholds
99
100void RooBinningCategory::printMultiline(std::ostream& os, Int_t content, bool verbose, TString indent) const
101{
103
104 if (verbose) {
105 os << indent << "--- RooBinningCategory ---" << std::endl
106 << indent << " Maps from " ;
107 _inputVar.arg().printStream(os,kName|kValue,kSingleLine);
108 }
109}
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
A space to attach TBranches.
virtual const std::map< std::string, RooAbsCategory::value_type >::value_type & defineState(const std::string &label)
Define a new state with given label.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print info about this object to the specified stream.
bool hasIndex(value_type index) const
Check if a state with index index exists.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const =0
Retrieve binning configuration with given name or default binning.
Int_t getBin(const char *rangeName=nullptr) const override
Provides a real-to-category mapping defined by a series of thresholds.
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Printing interface (human readable)
value_type evaluate() const override
Calculate and return the value of the mapping function.
TString _bname
Name of the binning specification to be used to perform the mapping.
RooTemplateProxy< RooAbsRealLValue > _inputVar
Input variable that is mapped.
void initialize(const char *catTypeName=nullptr)
Iterator over all bins in input variable and define corresponding state labels.
RooBinningCategory()=default
const T & arg() const
Return reference to object held in proxy.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
const char * Data() const
Definition TString.h:376