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
25
26#include <Riostream.h>
27#include <TMath.h>
28
29
30using namespace RooStats;
31using namespace HistFactory;
32
33
34////////////////////////////////////////////////////////////////////////////////
35/// Default constructor
36
41
42
43////////////////////////////////////////////////////////////////////////////////
44
45FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
46 const RooArgList& paramList,
47 double argNominal, std::vector<double> const& lowVec, std::vector<double> const& highVec) :
48 FlexibleInterpVar{name, title, paramList, argNominal, lowVec, highVec, std::vector<int>(lowVec.size(), 0)}
49{
50}
51
52
53////////////////////////////////////////////////////////////////////////////////
54
55FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
56 const RooArgList& paramList,
57 double argNominal, std::vector<double> const& lowVec, std::vector<double> const& highVec,
58 std::vector<int> const& codes) :
59 RooAbsReal(name, title),
60 _paramList("paramList","List of paramficients",this),
61 _nominal(argNominal), _low(lowVec), _high(highVec)
62{
63 for (auto param : paramList) {
64 if (!dynamic_cast<RooAbsReal*>(param)) {
65 coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") ERROR: paramficient " << param->GetName()
66 << " is not of type RooAbsReal" << std::endl ;
67 // use R__ASSERT which remains also in release mode
68 R__ASSERT(0) ;
69 }
70 _paramList.add(*param) ;
71 }
72
73 _interpCode.resize(_paramList.size());
74 for (std::size_t i = 0; i < codes.size(); ++i) {
76 }
77
78 if (_low.size() != _paramList.size() || _low.size() != _high.size() || _low.size() != _interpCode.size()) {
79 coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") invalid input std::vectors " << std::endl;
80 R__ASSERT(_low.size() == _paramList.size());
81 R__ASSERT(_low.size() == _high.size());
82 R__ASSERT(_low.size() == _interpCode.size());
83 }
84
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Constructor of flat polynomial function
90
91FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title) :
92 RooAbsReal(name, title),
93 _paramList("paramList","List of coefficients",this)
94{
96}
97
98////////////////////////////////////////////////////////////////////////////////
99
102 _paramList("paramList",this,other._paramList),
103 _nominal(other._nominal), _low(other._low), _high(other._high), _interpCode(other._interpCode), _interpBoundary(other._interpBoundary)
104
105{
107}
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Destructor
112
117
119{
120 int index = _paramList.index(&param);
121 if (index < 0) {
122 coutE(InputArguments) << "FlexibleInterpVar::setInterpCode ERROR: " << param.GetName() << " is not in list"
123 << std::endl;
124 return;
125 }
127}
128
130{
131 for (std::size_t i = 0; i < _interpCode.size(); ++i) {
132 setInterpCodeForParam(i, code);
133 }
134}
135
137{
138 if (Detail::setInterpolationCode(*this, "FlexibleInterpVar", _paramList[iParam], _interpCode, iParam, code,
139 /*maxCode=*/5)) {
141 }
142}
143
144////////////////////////////////////////////////////////////////////////////////
145
147 coutW(InputArguments) << "FlexibleInterpVar::setNominal : nominal is now " << newNominal << std::endl ;
149
151}
152
153////////////////////////////////////////////////////////////////////////////////
154
156 int index = _paramList.index(&param);
157 if(index<0){
158 coutE(InputArguments) << "FlexibleInterpVar::setLow ERROR: " << param.GetName()
159 << " is not in list" << std::endl ;
160 } else {
161 coutW(InputArguments) << "FlexibleInterpVar::setLow : " << param.GetName()
162 << " is now " << newLow << std::endl ;
163 _low.at(index) = newLow;
164 }
165
167}
168
169////////////////////////////////////////////////////////////////////////////////
170
172 int index = _paramList.index(&param);
173 if(index<0){
174 coutE(InputArguments) << "FlexibleInterpVar::setHigh ERROR: " << param.GetName()
175 << " is not in list" << std::endl ;
176 } else {
177 coutW(InputArguments) << "FlexibleInterpVar::setHigh : " << param.GetName()
178 << " is now " << newHigh << std::endl ;
179 _high.at(index) = newHigh;
180 }
181
183}
184
185////////////////////////////////////////////////////////////////////////////////
186
188 for(unsigned int i=0; i<_interpCode.size(); ++i){
189 coutI(InputArguments) <<"interp code for " << _paramList.at(i)->GetName() << " = " << _interpCode.at(i) << std::endl;
190 // GHL: Adding suggestion by Swagato:
191 if( _low.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": low value = " << _low.at(i) << std::endl;
192 if( _high.at(i) <= 0.001 ) coutE(InputArguments) << GetName() << ", " << _paramList.at(i)->GetName() << ": high value = " << _high.at(i) << std::endl;
193 }
194
195}
196
197
198////////////////////////////////////////////////////////////////////////////////
199/// Calculate and return value of polynomial
200
202{
203 double total(_nominal);
204 for (std::size_t i = 0; i < _paramList.size(); ++i) {
205 int code = _interpCode[i];
206 // To get consistent codes with the PiecewiseInterpolation
207 if (code == 4) {
208 code = 5;
209 }
210 double paramVal = static_cast<const RooAbsReal *>(&_paramList[i])->getVal();
212 paramVal, total);
213 }
214
215 if (total <= 0) {
217 }
218
219 return total;
220}
221
223{
224 double total(_nominal);
225
226 for (std::size_t i = 0; i < _paramList.size(); ++i) {
227 int code = _interpCode[i];
228 // To get consistent codes with the PiecewiseInterpolation
229 if (code == 4) {
230 code = 5;
231 }
233 ctx.at(&_paramList[i])[0], total);
234 }
235
236 if (total <= 0) {
238 }
239
240 ctx.output()[0] = total;
241}
242
243void FlexibleInterpVar::printMultiline(std::ostream& os, Int_t contents,
244 bool verbose, TString indent) const
245{
246 RooAbsReal::printMultiline(os,contents,verbose,indent);
247 os << indent << "--- FlexibleInterpVar ---" << std::endl;
249}
250
252{
253 for (int i=0;i<(int)_low.size();i++) {
254 auto& param = static_cast<RooAbsReal&>(_paramList[i]);
255 os << std::setw(36) << param.GetName()<<": "<<std::setw(7) << _low[i]<<" "<<std::setw(7) << _high[i]
256 <<std::endl;
257 }
258}
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
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:145
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