Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 "RooBinningCategory.h"
28 
29 #include "RooFit.h"
30 #include "Riostream.h"
31 #include "TString.h"
32 #include "RooStreamParser.h"
33 #include "RooMsgService.h"
34 
35 using namespace std;
36 
37 ClassImp(RooBinningCategory);
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 
58 RooBinningCategory::RooBinningCategory(const RooBinningCategory& other, const char *name) :
59  RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar), _bname(other._bname)
60 {
61 }
62 
63 
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Destructor
67 
68 RooBinningCategory::~RooBinningCategory()
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  Int_t nbins = ((RooAbsRealLValue&)_inputVar.arg()).getBinning(_bname.Length()>0?_bname.Data():0).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  defineType(name.c_str(),i) ;
86  }
87 }
88 
89 
90 
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Calculate and return the value of the mapping function
94 
95 RooCatType RooBinningCategory::evaluate() const
96 {
97  Int_t ibin = ((RooAbsRealLValue&)_inputVar.arg()).getBin(_bname.Length()>0?_bname.Data():0) ;
98  const RooCatType* cat = lookupType(ibin) ;
99  if (!cat) {
100 
101  string name = (_bname.Length()>0) ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),ibin)
102  : Form("%s_bin%d",_inputVar.arg().GetName(),ibin) ;
103  cat = const_cast<RooBinningCategory*>(this)->defineType(name.c_str(),ibin) ;
104  }
105 
106  return *cat ;
107 }
108 
109 
110 
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Print info about this threshold category to the specified stream. In addition to the info
114 /// from RooAbsCategory::printStream() we add:
115 ///
116 /// Standard : input category
117 /// Shape : default value
118 /// Verbose : list of thresholds
119 
120 void RooBinningCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
121 {
122  RooAbsCategory::printMultiline(os,content,verbose,indent);
123 
124  if (verbose) {
125  os << indent << "--- RooBinningCategory ---" << endl
126  << indent << " Maps from " ;
127  _inputVar.arg().printStream(os,kName|kValue,kSingleLine);
128  }
129 }
130 
131