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 <Riostream.h>
26#include <TMath.h>
27
28
29using namespace RooStats;
30using namespace HistFactory;
31
32
33////////////////////////////////////////////////////////////////////////////////
34/// Default constructor
35
39
40
41////////////////////////////////////////////////////////////////////////////////
42
43FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
44 const RooArgList& paramList,
45 double argNominal, std::vector<double> const& lowVec, std::vector<double> const& highVec) :
46 FlexibleInterpVar{name, title, paramList, argNominal, lowVec, highVec, std::vector<int>(lowVec.size(), 0)}
47{
48}
49
50
51////////////////////////////////////////////////////////////////////////////////
52
53FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
54 const RooArgList& paramList,
55 double argNominal, std::vector<double> const& lowVec, std::vector<double> const& highVec,
56 std::vector<int> const& codes) :
57 RooAbsReal(name, title),
58 _paramList("paramList","List of paramficients",this),
59 _nominal(argNominal), _low(lowVec), _high(highVec)
60{
61 for (auto param : paramList) {
62 if (!dynamic_cast<RooAbsReal*>(param)) {
63 coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") ERROR: paramficient " << param->GetName()
64 << " is not of type RooAbsReal" << std::endl ;
65 // use R__ASSERT which remains also in release mode
66 R__ASSERT(0) ;
67 }
68 _paramList.add(*param) ;
69 }
70
71 _interpCode.resize(_paramList.size());
72 for (std::size_t i = 0; i < codes.size(); ++i) {
74 }
75
76 if (_low.size() != _paramList.size() || _low.size() != _high.size() || _low.size() != _interpCode.size()) {
77 coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") invalid input std::vectors " << std::endl;
78 R__ASSERT(_low.size() == _paramList.size());
79 R__ASSERT(_low.size() == _high.size());
80 R__ASSERT(_low.size() == _interpCode.size());
81 }
82
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Constructor of flat polynomial function
87
88FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title) :
89 RooAbsReal(name, title),
90 _paramList("paramList","List of coefficients",this)
91{
92}
93
94////////////////////////////////////////////////////////////////////////////////
95
98 _paramList("paramList",this,other._paramList),
99 _nominal(other._nominal), _low(other._low), _high(other._high), _interpCode(other._interpCode), _interpBoundary(other._interpBoundary)
100
101{
102}
103
104
105////////////////////////////////////////////////////////////////////////////////
106/// Destructor
107
111
113{
114 int index = _paramList.index(&param);
115 if (index < 0) {
116 coutE(InputArguments) << "FlexibleInterpVar::setInterpCode ERROR: " << param.GetName() << " is not in list"
117 << std::endl;
118 return;
119 }
121}
122
124{
125 for (std::size_t i = 0; i < _interpCode.size(); ++i) {
126 setInterpCodeForParam(i, code);
127 }
128}
129
131{
132 if (Detail::setInterpolationCode(*this, "FlexibleInterpVar", _paramList[iParam], _interpCode, iParam, code,
133 /*maxCode=*/5)) {
135 }
136}
137
138////////////////////////////////////////////////////////////////////////////////
139
141 coutW(InputArguments) << "FlexibleInterpVar::setNominal : nominal is now " << newNominal << std::endl ;
143
145}
146
147////////////////////////////////////////////////////////////////////////////////
148
150 int index = _paramList.index(&param);
151 if(index<0){
152 coutE(InputArguments) << "FlexibleInterpVar::setLow ERROR: " << param.GetName()
153 << " is not in list" << std::endl ;
154 } else {
155 coutW(InputArguments) << "FlexibleInterpVar::setLow : " << param.GetName()
156 << " is now " << newLow << std::endl ;
157 _low.at(index) = newLow;
158 }
159
161}
162
163////////////////////////////////////////////////////////////////////////////////
164
166 int index = _paramList.index(&param);
167 if(index<0){
168 coutE(InputArguments) << "FlexibleInterpVar::setHigh ERROR: " << param.GetName()
169 << " is not in list" << std::endl ;
170 } else {
171 coutW(InputArguments) << "FlexibleInterpVar::setHigh : " << param.GetName()
172 << " is now " << newHigh << std::endl ;
173 _high.at(index) = newHigh;
174 }
175
177}
178
179////////////////////////////////////////////////////////////////////////////////
180
182 for(unsigned int i=0; i<_interpCode.size(); ++i){
183 coutI(InputArguments) <<"interp code for " << _paramList.at(i)->GetName() << " = " << _interpCode.at(i) << std::endl;
184 // GHL: Adding suggestion by Swagato:
185 if( _low.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": low value = " << _low.at(i) << std::endl;
186 if( _high.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": high value = " << _high.at(i) << std::endl;
187 }
188
189}
190
191
192////////////////////////////////////////////////////////////////////////////////
193/// Calculate and return value of polynomial
194
196{
197 double total(_nominal);
198 for (std::size_t i = 0; i < _paramList.size(); ++i) {
199 int code = _interpCode[i];
200 // To get consistent codes with the PiecewiseInterpolation
201 if (code == 4) {
202 code = 5;
203 }
204 double paramVal = static_cast<const RooAbsReal *>(&_paramList[i])->getVal();
206 paramVal, total);
207 }
208
209 if (total <= 0) {
211 }
212
213 return total;
214}
215
217{
218 double total(_nominal);
219
220 for (std::size_t i = 0; i < _paramList.size(); ++i) {
221 int code = _interpCode[i];
222 // To get consistent codes with the PiecewiseInterpolation
223 if (code == 4) {
224 code = 5;
225 }
227 ctx.at(&_paramList[i])[0], total);
228 }
229
230 if (total <= 0) {
232 }
233
234 ctx.output()[0] = total;
235}
236
237void FlexibleInterpVar::printMultiline(std::ostream& os, Int_t contents,
238 bool verbose, TString indent) const
239{
240 RooAbsReal::printMultiline(os,contents,verbose,indent);
241 os << indent << "--- FlexibleInterpVar ---" << std::endl;
243}
244
246{
247 for (int i=0;i<(int)_low.size();i++) {
248 auto& param = static_cast<RooAbsReal&>(_paramList[i]);
249 os << std::setw(36) << param.GetName()<<": "<<std::setw(7) << _low[i]<<" "<<std::setw(7) << _high[i]
250 <<std::endl;
251 }
252}
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: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:148
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:425
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...
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:49
Basic string class.
Definition TString.h:138
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:66
static T Min()
Returns maximum representation for type T.
Definition TMath.h:938