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#include <RooTrace.h>
20
23
24#include <Riostream.h>
25#include <TMath.h>
26
28
29using namespace RooStats;
30using namespace HistFactory;
31
32
33////////////////////////////////////////////////////////////////////////////////
34/// Default constructor
35
37{
39}
40
41
42////////////////////////////////////////////////////////////////////////////////
43
44FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
45 const RooArgList& paramList,
46 double argNominal, std::vector<double> const& lowVec, std::vector<double> const& highVec) :
47 FlexibleInterpVar{name, title, paramList, argNominal, lowVec, highVec, std::vector<int>(lowVec.size(), 0)}
48{
49}
50
51
52////////////////////////////////////////////////////////////////////////////////
53
54FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
55 const RooArgList& paramList,
56 double argNominal, std::vector<double> const& lowVec, std::vector<double> const& highVec,
57 std::vector<int> const& codes) :
58 RooAbsReal(name, title),
59 _paramList("paramList","List of paramficients",this),
60 _nominal(argNominal), _low(lowVec), _high(highVec)
61{
62 for (auto param : paramList) {
63 if (!dynamic_cast<RooAbsReal*>(param)) {
64 coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") ERROR: paramficient " << param->GetName()
65 << " is not of type RooAbsReal" << std::endl ;
66 // use R__ASSERT which remains also in release mode
67 R__ASSERT(0) ;
68 }
69 _paramList.add(*param) ;
70 }
71
72 _interpCode.resize(_paramList.size());
73 for (std::size_t i = 0; i < codes.size(); ++i) {
74 setInterpCodeForParam(i, codes[i]);
75 }
76
77 if (_low.size() != _paramList.size() || _low.size() != _high.size() || _low.size() != _interpCode.size()) {
78 coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") invalid input std::vectors " << std::endl;
79 R__ASSERT(_low.size() == _paramList.size());
80 R__ASSERT(_low.size() == _high.size());
81 R__ASSERT(_low.size() == _interpCode.size());
82 }
83
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Constructor of flat polynomial function
89
90FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title) :
91 RooAbsReal(name, title),
92 _paramList("paramList","List of coefficients",this)
93{
95}
96
97////////////////////////////////////////////////////////////////////////////////
98
100 RooAbsReal(other, name),
101 _paramList("paramList",this,other._paramList),
102 _nominal(other._nominal), _low(other._low), _high(other._high), _interpCode(other._interpCode), _interpBoundary(other._interpBoundary)
103
104{
106}
107
108
109////////////////////////////////////////////////////////////////////////////////
110/// Destructor
111
113{
115}
116
118{
119 int index = _paramList.index(&param);
120 if (index < 0) {
121 coutE(InputArguments) << "FlexibleInterpVar::setInterpCode ERROR: " << param.GetName() << " is not in list"
122 << std::endl;
123 return;
124 }
126}
127
129{
130 for (std::size_t i = 0; i < _interpCode.size(); ++i) {
131 setInterpCodeForParam(i, code);
132 }
133}
134
136{
137 RooAbsArg const &param = _paramList[iParam];
138 if (code < 0 || code > 5) {
139 coutE(InputArguments) << "FlexibleInterpVar::setInterpCode ERROR: " << param.GetName()
140 << " with unknown interpolation code " << code << ", keeping current code "
141 << _interpCode[iParam] << std::endl;
142 return;
143 }
144 if (code == 3) {
145 // In the past, code 3 was equivalent to code 2, which confused users.
146 // Now, we just say that code 3 doesn't exist and default to code 2 in
147 // that case for backwards compatible behavior.
148 coutE(InputArguments) << "FlexibleInterpVar::setInterpCode ERROR: " << param.GetName()
149 << " with unknown interpolation code " << code << ", defaulting to code 2" << std::endl;
150 code = 2;
151 }
152 _interpCode.at(iParam) = code;
154}
155
156////////////////////////////////////////////////////////////////////////////////
157
158void FlexibleInterpVar::setNominal(double newNominal){
159 coutW(InputArguments) << "FlexibleInterpVar::setNominal : nominal is now " << newNominal << std::endl ;
160 _nominal = newNominal;
161
163}
164
165////////////////////////////////////////////////////////////////////////////////
166
167void FlexibleInterpVar::setLow(RooAbsReal& param, double newLow){
168 int index = _paramList.index(&param);
169 if(index<0){
170 coutE(InputArguments) << "FlexibleInterpVar::setLow ERROR: " << param.GetName()
171 << " is not in list" << std::endl ;
172 } else {
173 coutW(InputArguments) << "FlexibleInterpVar::setLow : " << param.GetName()
174 << " is now " << newLow << std::endl ;
175 _low.at(index) = newLow;
176 }
177
179}
180
181////////////////////////////////////////////////////////////////////////////////
182
183void FlexibleInterpVar::setHigh(RooAbsReal& param, double newHigh){
184 int index = _paramList.index(&param);
185 if(index<0){
186 coutE(InputArguments) << "FlexibleInterpVar::setHigh ERROR: " << param.GetName()
187 << " is not in list" << std::endl ;
188 } else {
189 coutW(InputArguments) << "FlexibleInterpVar::setHigh : " << param.GetName()
190 << " is now " << newHigh << std::endl ;
191 _high.at(index) = newHigh;
192 }
193
195}
196
197////////////////////////////////////////////////////////////////////////////////
198
200 for(unsigned int i=0; i<_interpCode.size(); ++i){
201 coutI(InputArguments) <<"interp code for " << _paramList.at(i)->GetName() << " = " << _interpCode.at(i) << std::endl;
202 // GHL: Adding suggestion by Swagato:
203 if( _low.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": low value = " << _low.at(i) << std::endl;
204 if( _high.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": high value = " << _high.at(i) << std::endl;
205 }
206
207}
208
209
210////////////////////////////////////////////////////////////////////////////////
211/// Calculate and return value of polynomial
212
214{
215 double total(_nominal);
216 for (std::size_t i = 0; i < _paramList.size(); ++i) {
217 int code = _interpCode[i];
218 // To get consistent codes with the PiecewiseInterpolation
219 if (code == 4) {
220 code = 5;
221 }
222 double paramVal = static_cast<const RooAbsReal *>(&_paramList[i])->getVal();
224 paramVal, total);
225 }
226
227 if (total <= 0) {
229 }
230
231 return total;
232}
233
235{
236 double total(_nominal);
237
238 for (std::size_t i = 0; i < _paramList.size(); ++i) {
239 int code = _interpCode[i];
240 // To get consistent codes with the PiecewiseInterpolation
241 if (code == 4) {
242 code = 5;
243 }
245 ctx.at(&_paramList[i])[0], total);
246 }
247
248 if (total <= 0) {
250 }
251
252 ctx.output()[0] = total;
253}
254
255void FlexibleInterpVar::printMultiline(std::ostream& os, Int_t contents,
256 bool verbose, TString indent) const
257{
258 RooAbsReal::printMultiline(os,contents,verbose,indent);
259 os << indent << "--- FlexibleInterpVar ---" << std::endl;
261}
262
264{
265 for (int i=0;i<(int)_low.size();i++) {
266 auto& param = static_cast<RooAbsReal&>(_paramList[i]);
267 os << std::setw(36) << param.GetName()<<": "<<std::setw(7) << _low[i]<<" "<<std::setw(7) << _high[i]
268 <<std::endl;
269 }
270}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define coutI(a)
#define coutW(a)
#define coutE(a)
#define TRACE_DESTROY
Definition RooTrace.h:24
#define TRACE_CREATE
Definition RooTrace.h:23
#define ClassImp(name)
Definition Rtypes.h:382
static void indent(ostringstream &buf, int indent_level)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
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:110
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:431
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:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
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...
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
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:47
Basic string class.
Definition TString.h:139
double flexibleInterpSingle(unsigned int code, double low, double high, double boundary, double nominal, double paramVal, double res)
Definition MathFuncs.h:213
Namespace for the RooStats classes.
Definition CodegenImpl.h:58
static T Min()
Returns maximum representation for type T.
Definition TMath.h:929