#include "RooFit.h"
#include "Riostream.h"
#include "Riostream.h"
#include <math.h>
#include "TMath.h"
#include "RooAbsReal.h"
#include "RooRealVar.h"
#include "RooArgList.h"
#include "RooMsgService.h"
#include "TMath.h"
#include "RooStats/HistFactory/FlexibleInterpVar.h"
ClassImp(RooStats::HistFactory::FlexibleInterpVar)
using namespace RooStats;
using namespace HistFactory;
FlexibleInterpVar::FlexibleInterpVar()
{
_paramIter = _paramList.createIterator() ;
_nominal = 0;
}
FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
const RooArgList& paramList,
double nominal, vector<double> low, vector<double> high) :
RooAbsReal(name, title),
_paramList("paramList","List of paramficients",this),
_nominal(nominal), _low(low), _high(high)
{
_paramIter = _paramList.createIterator() ;
TIterator* paramIter = paramList.createIterator() ;
RooAbsArg* param ;
while((param = (RooAbsArg*)paramIter->Next())) {
if (!dynamic_cast<RooAbsReal*>(param)) {
coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") ERROR: paramficient " << param->GetName()
<< " is not of type RooAbsReal" << endl ;
assert(0) ;
}
_paramList.add(*param) ;
_interpCode.push_back(0);
}
delete paramIter ;
}
FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title,
const RooArgList& paramList,
double nominal, vector<double> low, vector<double> high,
vector<int> code) :
RooAbsReal(name, title),
_paramList("paramList","List of paramficients",this),
_nominal(nominal), _low(low), _high(high), _interpCode(code)
{
_paramIter = _paramList.createIterator() ;
TIterator* paramIter = paramList.createIterator() ;
RooAbsArg* param ;
while((param = (RooAbsArg*)paramIter->Next())) {
if (!dynamic_cast<RooAbsReal*>(param)) {
coutE(InputArguments) << "FlexibleInterpVar::ctor(" << GetName() << ") ERROR: paramficient " << param->GetName()
<< " is not of type RooAbsReal" << endl ;
assert(0) ;
}
_paramList.add(*param) ;
}
delete paramIter ;
}
FlexibleInterpVar::FlexibleInterpVar(const char* name, const char* title) :
RooAbsReal(name, title),
_paramList("paramList","List of coefficients",this)
{
_paramIter = _paramList.createIterator() ;
}
FlexibleInterpVar::FlexibleInterpVar(const FlexibleInterpVar& other, const char* name) :
RooAbsReal(other, name),
_paramList("paramList",this,other._paramList),
_nominal(other._nominal), _low(other._low), _high(other._high), _interpCode(other._interpCode)
{
_paramIter = _paramList.createIterator() ;
}
FlexibleInterpVar::~FlexibleInterpVar()
{
delete _paramIter ;
}
void FlexibleInterpVar::setInterpCode(RooAbsReal& param, int code){
int index = _paramList.index(¶m);
if(index<0){
coutE(InputArguments) << "FlexibleInterpVar::setInterpCode ERROR: " << param.GetName()
<< " is not in list" << endl ;
} else {
coutW(InputArguments) << "FlexibleInterpVar::setInterpCode : " << param.GetName()
<< " is now " << code << endl ;
_interpCode.at(index) = code;
}
}
void FlexibleInterpVar::setAllInterpCodes(int code){
for(unsigned int i=0; i<_interpCode.size(); ++i){
_interpCode.at(i) = code;
}
}
void FlexibleInterpVar::printAllInterpCodes(){
for(unsigned int i=0; i<_interpCode.size(); ++i){
coutI(InputArguments) <<"interp code for " << _paramList.at(i)->GetName() << " = " << _interpCode.at(i) <<endl;
}
}
Double_t FlexibleInterpVar::evaluate() const
{
Double_t total(_nominal) ;
_paramIter->Reset() ;
RooAbsReal* param ;
int i=0;
while((param=(RooAbsReal*)_paramIter->Next())) {
if(_interpCode.at(i)==0){
if(param->getVal()>0)
total += param->getVal()*(_high.at(i) - _nominal );
else
total += param->getVal()*(_nominal - _low.at(i));
} else if(_interpCode.at(i)==1){
if(param->getVal()>=0)
total *= pow(_high.at(i)/_nominal, +param->getVal());
else
total *= pow(_low.at(i)/_nominal, -param->getVal());
} else if(_interpCode.at(i)==2){
double a = 0.5*(_high.at(i)+_low.at(i))-_nominal;
double b = 0.5*(_high.at(i)-_low.at(i));
double c = 0;
if(param->getVal()>1 ){
total += (2*a+b)*(param->getVal()-1)+_high.at(i)-_nominal;
} else if(param->getVal()<-1 ) {
total += -1*(2*a-b)*(param->getVal()+1)+_low.at(i)-_nominal;
} else {
total += a*pow(param->getVal(),2) + b*param->getVal()+c;
}
} else if(_interpCode.at(i)==3){
double a = 0.5*(_high.at(i)+_low.at(i))-_nominal;
double b = 0.5*(_high.at(i)-_low.at(i));
double c = 0;
if(param->getVal()>1 ){
total += (2*a+b)*(param->getVal()-1)+_high.at(i)-_nominal;
} else if(param->getVal()<-1 ) {
total += -1*(2*a-b)*(param->getVal()+1)+_low.at(i)-_nominal;
} else {
total += a*pow(param->getVal(),2) + b*param->getVal()+c;
}
} else {
coutE(InputArguments) << "FlexibleInterpVar::evaluate ERROR: " << param->GetName()
<< " with unknown interpolation code" << endl ;
}
++i;
}
if(total<=0) {
total=1E-9;
}
return total;
}
FlexibleInterpVar.cxx:100 FlexibleInterpVar.cxx:101 FlexibleInterpVar.cxx:102 FlexibleInterpVar.cxx:103 FlexibleInterpVar.cxx:104 FlexibleInterpVar.cxx:105 FlexibleInterpVar.cxx:106 FlexibleInterpVar.cxx:107 FlexibleInterpVar.cxx:108 FlexibleInterpVar.cxx:109 FlexibleInterpVar.cxx:110 FlexibleInterpVar.cxx:111 FlexibleInterpVar.cxx:112 FlexibleInterpVar.cxx:113 FlexibleInterpVar.cxx:114 FlexibleInterpVar.cxx:115 FlexibleInterpVar.cxx:116 FlexibleInterpVar.cxx:117 FlexibleInterpVar.cxx:118 FlexibleInterpVar.cxx:119 FlexibleInterpVar.cxx:120 FlexibleInterpVar.cxx:121 FlexibleInterpVar.cxx:122 FlexibleInterpVar.cxx:123 FlexibleInterpVar.cxx:124 FlexibleInterpVar.cxx:125 FlexibleInterpVar.cxx:126 FlexibleInterpVar.cxx:127 FlexibleInterpVar.cxx:128 FlexibleInterpVar.cxx:129 FlexibleInterpVar.cxx:130 FlexibleInterpVar.cxx:131 FlexibleInterpVar.cxx:132 FlexibleInterpVar.cxx:133 FlexibleInterpVar.cxx:134 FlexibleInterpVar.cxx:135 FlexibleInterpVar.cxx:136 FlexibleInterpVar.cxx:137 FlexibleInterpVar.cxx:138 FlexibleInterpVar.cxx:139 FlexibleInterpVar.cxx:140 FlexibleInterpVar.cxx:141 FlexibleInterpVar.cxx:142 FlexibleInterpVar.cxx:143 FlexibleInterpVar.cxx:144 FlexibleInterpVar.cxx:145 FlexibleInterpVar.cxx:146 FlexibleInterpVar.cxx:147 FlexibleInterpVar.cxx:148 FlexibleInterpVar.cxx:149 FlexibleInterpVar.cxx:150 FlexibleInterpVar.cxx:151 FlexibleInterpVar.cxx:152 FlexibleInterpVar.cxx:153 FlexibleInterpVar.cxx:154 FlexibleInterpVar.cxx:155 FlexibleInterpVar.cxx:156 FlexibleInterpVar.cxx:157 FlexibleInterpVar.cxx:158 FlexibleInterpVar.cxx:159 FlexibleInterpVar.cxx:160 FlexibleInterpVar.cxx:161 FlexibleInterpVar.cxx:162 FlexibleInterpVar.cxx:163 FlexibleInterpVar.cxx:164 FlexibleInterpVar.cxx:165 FlexibleInterpVar.cxx:166 FlexibleInterpVar.cxx:167 FlexibleInterpVar.cxx:168 FlexibleInterpVar.cxx:169 FlexibleInterpVar.cxx:170 FlexibleInterpVar.cxx:171 FlexibleInterpVar.cxx:172 FlexibleInterpVar.cxx:173 FlexibleInterpVar.cxx:174 FlexibleInterpVar.cxx:175 FlexibleInterpVar.cxx:176 FlexibleInterpVar.cxx:177 FlexibleInterpVar.cxx:178 FlexibleInterpVar.cxx:179 FlexibleInterpVar.cxx:180 FlexibleInterpVar.cxx:181 FlexibleInterpVar.cxx:182 FlexibleInterpVar.cxx:183 FlexibleInterpVar.cxx:184 FlexibleInterpVar.cxx:185 FlexibleInterpVar.cxx:186 FlexibleInterpVar.cxx:187 FlexibleInterpVar.cxx:188 FlexibleInterpVar.cxx:189 FlexibleInterpVar.cxx:190 FlexibleInterpVar.cxx:191 FlexibleInterpVar.cxx:192 FlexibleInterpVar.cxx:193 FlexibleInterpVar.cxx:194 FlexibleInterpVar.cxx:195 FlexibleInterpVar.cxx:196 FlexibleInterpVar.cxx:197 FlexibleInterpVar.cxx:198 FlexibleInterpVar.cxx:199 FlexibleInterpVar.cxx:200 FlexibleInterpVar.cxx:201 FlexibleInterpVar.cxx:202 FlexibleInterpVar.cxx:203 FlexibleInterpVar.cxx:204 FlexibleInterpVar.cxx:205 FlexibleInterpVar.cxx:206 FlexibleInterpVar.cxx:207 FlexibleInterpVar.cxx:208 FlexibleInterpVar.cxx:209 FlexibleInterpVar.cxx:210 FlexibleInterpVar.cxx:211 FlexibleInterpVar.cxx:212 FlexibleInterpVar.cxx:213 FlexibleInterpVar.cxx:214 FlexibleInterpVar.cxx:215 FlexibleInterpVar.cxx:216 FlexibleInterpVar.cxx:217 FlexibleInterpVar.cxx:218 FlexibleInterpVar.cxx:219 FlexibleInterpVar.cxx:220 FlexibleInterpVar.cxx:221 FlexibleInterpVar.cxx:222 FlexibleInterpVar.cxx:223 FlexibleInterpVar.cxx:224 FlexibleInterpVar.cxx:225 FlexibleInterpVar.cxx:226 FlexibleInterpVar.cxx:227 FlexibleInterpVar.cxx:228 FlexibleInterpVar.cxx:229 FlexibleInterpVar.cxx:230 FlexibleInterpVar.cxx:231 FlexibleInterpVar.cxx:232 FlexibleInterpVar.cxx:233