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& code) :
58 RooAbsReal(name, title),
59 _paramList("paramList","List of paramficients",this),
60 _nominal(argNominal), _low(lowVec), _high(highVec), _interpCode(code)
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 if (_low.size() != _paramList.size() || _low.size() != _high.size() || _low.size() != _interpCode.size()) {
73 coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") invalid input std::vectors " << std::endl;
74 R__ASSERT(_low.size() == _paramList.size());
75 R__ASSERT(_low.size() == _high.size());
76 R__ASSERT(_low.size() == _interpCode.size());
77 }
78
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Constructor of flat polynomial function
84
85FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title) :
86 RooAbsReal(name, title),
87 _paramList("paramList","List of coefficients",this)
88{
90}
91
92////////////////////////////////////////////////////////////////////////////////
93
95 RooAbsReal(other, name),
96 _paramList("paramList",this,other._paramList),
97 _nominal(other._nominal), _low(other._low), _high(other._high), _interpCode(other._interpCode), _interpBoundary(other._interpBoundary)
98
99{
101}
102
103
104////////////////////////////////////////////////////////////////////////////////
105/// Destructor
106
108{
110}
111
112
113////////////////////////////////////////////////////////////////////////////////
114
116 int index = _paramList.index(&param);
117 if(index<0){
118 coutE(InputArguments) << "FlexibleInterpVar::setInterpCode ERROR: " << param.GetName()
119 << " is not in list" << std::endl;
120 } else if(_interpCode.at(index) != code){
121 coutI(InputArguments) << "FlexibleInterpVar::setInterpCode : " << param.GetName()
122 << " is now " << code << std::endl;
123 _interpCode.at(index) = code;
124 // GHL: Adding suggestion by Swagato:
126 }
127}
128
129////////////////////////////////////////////////////////////////////////////////
130
132 for(unsigned int i=0; i<_interpCode.size(); ++i){
133 _interpCode.at(i) = code;
134 }
135 // GHL: Adding suggestion by Swagato:
137}
138
139////////////////////////////////////////////////////////////////////////////////
140
141void FlexibleInterpVar::setNominal(double newNominal){
142 coutW(InputArguments) << "FlexibleInterpVar::setNominal : nominal is now " << newNominal << std::endl ;
143 _nominal = newNominal;
144
146}
147
148////////////////////////////////////////////////////////////////////////////////
149
150void FlexibleInterpVar::setLow(RooAbsReal& param, double newLow){
151 int index = _paramList.index(&param);
152 if(index<0){
153 coutE(InputArguments) << "FlexibleInterpVar::setLow ERROR: " << param.GetName()
154 << " is not in list" << std::endl ;
155 } else {
156 coutW(InputArguments) << "FlexibleInterpVar::setLow : " << param.GetName()
157 << " is now " << newLow << std::endl ;
158 _low.at(index) = newLow;
159 }
160
162}
163
164////////////////////////////////////////////////////////////////////////////////
165
166void FlexibleInterpVar::setHigh(RooAbsReal& param, double newHigh){
167 int index = _paramList.index(&param);
168 if(index<0){
169 coutE(InputArguments) << "FlexibleInterpVar::setHigh ERROR: " << param.GetName()
170 << " is not in list" << std::endl ;
171 } else {
172 coutW(InputArguments) << "FlexibleInterpVar::setHigh : " << param.GetName()
173 << " is now " << newHigh << std::endl ;
174 _high.at(index) = newHigh;
175 }
176
178}
179
180////////////////////////////////////////////////////////////////////////////////
181
183 for(unsigned int i=0; i<_interpCode.size(); ++i){
184 coutI(InputArguments) <<"interp code for " << _paramList.at(i)->GetName() << " = " << _interpCode.at(i) << std::endl;
185 // GHL: Adding suggestion by Swagato:
186 if( _low.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": low value = " << _low.at(i) << std::endl;
187 if( _high.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": high value = " << _high.at(i) << std::endl;
188 }
189
190}
191
192
193////////////////////////////////////////////////////////////////////////////////
194/// Calculate and return value of polynomial
195
197{
198 double total(_nominal);
199 for (std::size_t i = 0; i < _paramList.size(); ++i) {
200 int code = _interpCode[i];
201 if (code < 0 || code > 4) {
202 coutE(InputArguments) << "FlexibleInterpVar::evaluate ERROR: param " << i
203 << " with unknown interpolation code" << std::endl;
204 }
205 // To get consistent codes with the PiecewiseInterpolation
206 if (code == 4) {
207 code = 5;
208 }
209 double paramVal = static_cast<const RooAbsReal *>(&_paramList[i])->getVal();
211 paramVal, total);
212 }
213
214 if (total <= 0) {
216 }
217
218 return total;
219}
220
222{
223 unsigned int n = _interpCode.size();
224
225 int interpCode = _interpCode[0];
226 if (interpCode < 0 || interpCode > 4) {
227 coutE(InputArguments) << "FlexibleInterpVar::evaluate ERROR: param " << 0
228 << " with unknown interpolation code" << std::endl;
229 }
230 // To get consistent codes with the PiecewiseInterpolation
231 if (interpCode == 4) {
232 interpCode = 5;
233 }
234
235 for (unsigned int i = 1; i < n; i++) {
236 if (_interpCode[i] != _interpCode[0]) {
237 coutE(InputArguments) << "FlexibleInterpVar::evaluate ERROR: Code Squashing AD does not yet support having "
238 "different interpolation codes for the same class object "
239 << std::endl;
240 }
241 }
242
243 std::string const &resName = ctx.buildCall("RooFit::Detail::MathFuncs::flexibleInterp", interpCode,
245 ctx.addResult(this, resName);
246}
247
249{
250 double total(_nominal);
251
252 for (std::size_t i = 0; i < _paramList.size(); ++i) {
253 int code = _interpCode[i];
254 if (code < 0 || code > 4) {
255 coutE(InputArguments) << "FlexibleInterpVar::evaluate ERROR: param " << i
256 << " with unknown interpolation code" << std::endl;
257 }
258 // To get consistent codes with the PiecewiseInterpolation
259 if (code == 4) {
260 code = 5;
261 }
263 ctx.at(&_paramList[i])[0], total);
264 }
265
266 if (total <= 0) {
268 }
269
270 ctx.output()[0] = total;
271}
272
273void FlexibleInterpVar::printMultiline(std::ostream& os, Int_t contents,
274 bool verbose, TString indent) const
275{
276 RooAbsReal::printMultiline(os,contents,verbose,indent);
277 os << indent << "--- FlexibleInterpVar ---" << std::endl;
279}
280
282{
283 for (int i=0;i<(int)_low.size();i++) {
284 auto& param = static_cast<RooAbsReal&>(_paramList[i]);
285 os << std::setw(36) << param.GetName()<<": "<<std::setw(7) << _low[i]<<" "<<std::setw(7) << _high[i]
286 <<std::endl;
287 }
288}
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:377
static void indent(ostringstream &buf, int indent_level)
#define R__ASSERT(e)
Definition TError.h:118
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
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:488
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...
A class to maintain the context for squashing of RooFit models into code.
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
void addResult(RooAbsArg const *key, std::string const &value)
A function to save an expression that includes/depends on the result of the input node.
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 setHigh(RooAbsReal &param, double newHigh)
void translate(RooFit::Detail::CodeSquashContext &ctx) const override
This function defines a translation for each RooAbsReal based object that can be used to express the ...
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
const Int_t n
Definition legend1.C:16
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 Asimov.h:19
static T Min()
Returns maximum representation for type T.
Definition TMath.h:925