Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FlexibleInterpVar.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id: cranmer $
2// Author: Kyle Cranmer, Akira Shibata
3// Author: Giovanni Petrucciani (UCSD) (log-interpolation)
4/*************************************************************************
5 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12////////////////////////////////////////////////////////////////////////////////
13
14/** \class RooStats::HistFactory::FlexibleInterpVar
15 * \ingroup HistFactory
16 */
17
18#include <RooMsgService.h>
19
22
24
25#include <TMath.h>
26
27
28using namespace RooStats;
29using namespace HistFactory;
30
31
32////////////////////////////////////////////////////////////////////////////////
33/// Default constructor
34
38
39
40////////////////////////////////////////////////////////////////////////////////
41
42FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
43 const RooArgList& paramList,
44 double argNominal, std::vector<double> const& lowVec, std::vector<double> const& highVec) :
45 FlexibleInterpVar{name, title, paramList, argNominal, lowVec, highVec, std::vector<int>(lowVec.size(), 0)}
46{
47}
48
49
50////////////////////////////////////////////////////////////////////////////////
51
52FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
53 const RooArgList& paramList,
54 double argNominal, std::vector<double> const& lowVec, std::vector<double> const& highVec,
55 std::vector<int> const& codes) :
56 RooAbsReal(name, title),
57 _paramList("paramList","List of paramficients",this),
58 _nominal(argNominal), _low(lowVec), _high(highVec)
59{
60 for (auto param : paramList) {
61 if (!dynamic_cast<RooAbsReal*>(param)) {
62 coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") ERROR: paramficient " << param->GetName()
63 << " is not of type RooAbsReal" << std::endl ;
64 // use R__ASSERT which remains also in release mode
65 R__ASSERT(0) ;
66 }
67 _paramList.add(*param) ;
68 }
69
70 _interpCode.resize(_paramList.size());
71 for (std::size_t i = 0; i < codes.size(); ++i) {
72 setInterpCodeForParam(i, codes[i]);
73 }
74
75 if (_low.size() != _paramList.size() || _low.size() != _high.size() || _low.size() != _interpCode.size()) {
76 coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") invalid input std::vectors " << std::endl;
77 R__ASSERT(_low.size() == _paramList.size());
78 R__ASSERT(_low.size() == _high.size());
79 R__ASSERT(_low.size() == _interpCode.size());
80 }
81
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Constructor of flat polynomial function
86
87FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title) :
88 RooAbsReal(name, title),
89 _paramList("paramList","List of coefficients",this)
90{
91}
92
93////////////////////////////////////////////////////////////////////////////////
94
97 _paramList("paramList",this,other._paramList),
98 _nominal(other._nominal), _low(other._low), _high(other._high), _interpCode(other._interpCode), _interpBoundary(other._interpBoundary)
99
100{
101}
102
103
104////////////////////////////////////////////////////////////////////////////////
105/// Destructor
106
110
112{
113 int index = _paramList.index(&param);
114 if (index < 0) {
115 coutE(InputArguments) << "FlexibleInterpVar::setInterpCode ERROR: " << param.GetName() << " is not in list"
116 << std::endl;
117 return;
118 }
120}
121
123{
124 for (std::size_t i = 0; i < _interpCode.size(); ++i) {
125 setInterpCodeForParam(i, code);
126 }
127}
128
130{
131 if (Detail::setInterpolationCode(*this, "FlexibleInterpVar", _paramList[iParam], _interpCode, iParam, code,
132 /*maxCode=*/5)) {
134 }
135}
136
137////////////////////////////////////////////////////////////////////////////////
138
140 coutW(InputArguments) << "FlexibleInterpVar::setNominal : nominal is now " << newNominal << std::endl ;
142
144}
145
146////////////////////////////////////////////////////////////////////////////////
147
149 int index = _paramList.index(&param);
150 if(index<0){
151 coutE(InputArguments) << "FlexibleInterpVar::setLow ERROR: " << param.GetName()
152 << " is not in list" << std::endl ;
153 } else {
154 coutW(InputArguments) << "FlexibleInterpVar::setLow : " << param.GetName()
155 << " is now " << newLow << std::endl ;
156 _low.at(index) = newLow;
157 }
158
160}
161
162////////////////////////////////////////////////////////////////////////////////
163
165 int index = _paramList.index(&param);
166 if(index<0){
167 coutE(InputArguments) << "FlexibleInterpVar::setHigh ERROR: " << param.GetName()
168 << " is not in list" << std::endl ;
169 } else {
170 coutW(InputArguments) << "FlexibleInterpVar::setHigh : " << param.GetName()
171 << " is now " << newHigh << std::endl ;
172 _high.at(index) = newHigh;
173 }
174
176}
177
178////////////////////////////////////////////////////////////////////////////////
179
181 for(unsigned int i=0; i<_interpCode.size(); ++i){
182 coutI(InputArguments) <<"interp code for " << _paramList.at(i)->GetName() << " = " << _interpCode.at(i) << std::endl;
183 // GHL: Adding suggestion by Swagato:
184 if( _low.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": low value = " << _low.at(i) << std::endl;
185 if( _high.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": high value = " << _high.at(i) << std::endl;
186 }
187
188}
189
190
191////////////////////////////////////////////////////////////////////////////////
192/// Calculate and return value of polynomial
193
195{
196 double total(_nominal);
197 for (std::size_t i = 0; i < _paramList.size(); ++i) {
198 int code = _interpCode[i];
199 // To get consistent codes with the PiecewiseInterpolation
200 if (code == 4) {
201 code = 5;
202 }
203 double paramVal = static_cast<const RooAbsReal *>(&_paramList[i])->getVal();
205 paramVal, total);
206 }
207
208 if (total <= 0) {
210 }
211
212 return total;
213}
214
216{
217 double total(_nominal);
218
219 for (std::size_t i = 0; i < _paramList.size(); ++i) {
220 int code = _interpCode[i];
221 // To get consistent codes with the PiecewiseInterpolation
222 if (code == 4) {
223 code = 5;
224 }
226 ctx.at(&_paramList[i])[0], total);
227 }
228
229 if (total <= 0) {
231 }
232
233 ctx.output()[0] = total;
234}
235
236void FlexibleInterpVar::printMultiline(std::ostream& os, Int_t contents,
237 bool verbose, TString indent) const
238{
239 RooAbsReal::printMultiline(os,contents,verbose,indent);
240 os << indent << "--- FlexibleInterpVar ---" << std::endl;
242}
243
245{
246 for (int i=0;i<(int)_low.size();i++) {
247 auto& param = static_cast<RooAbsReal&>(_paramList[i]);
248 os << std::setw(36) << param.GetName()<<": "<<std::setw(7) << _low[i]<<" "<<std::setw(7) << _high[i]
249 <<std::endl;
250 }
251}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define coutI(a)
#define coutW(a)
#define coutE(a)
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.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:130
static unsigned int total
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Definition TGX11.cxx:142
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:404
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
Storage_t::size_type size() const
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:107
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Structure printing.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Interface for detailed printing of object.
void setInterpCode(RooAbsReal &param, int code)
void setLow(RooAbsReal &param, double newLow)
void setInterpCodeForParam(int iParam, int code)
void setHigh(RooAbsReal &param, double newHigh)
double evaluate() const override
Calculate and return value of polynomial.
virtual void printFlexibleInterpVars(std::ostream &os) const
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Basic string class.
Definition TString.h:137
double flexibleInterpSingle(unsigned int code, double low, double high, double boundary, double nominal, double paramVal, double res)
Definition MathFuncs.h:254
Namespace for the RooStats classes.
Definition CodegenImpl.h:67
static T Min()
Returns maximum representation for type T.
Definition TMath.h:938