1 #include "../interface/VerticalInterpHistPdf.h"
10 #include "RooRealVar.h"
11 #include "RooMsgService.h"
15 #include "../interface/ProfilingTools.h"
16 #define TRACEME() PerfCounter::add( __PRETTY_FUNCTION__ );
31 _funcIter = _funcList.createIterator() ;
32 _coefIter = _coefList.createIterator() ;
38 RooAbsPdf(name,title),
39 _x(
"x",
"Independent variable",this,const_cast<RooRealVar&>(x)),
40 _funcList(
"funcList",
"List of pdfs",this),
41 _coefList(
"coefList",
"List of coefficients",this),
42 _smoothRegion(smoothRegion),
43 _smoothAlgo(smoothAlgo),
49 if (inFuncList.getSize()!=2*inCoefList.getSize()+1) {
50 coutE(InputArguments) <<
"VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName()
51 <<
") number of pdfs and coefficients inconsistent, must have Nfunc=1+2*Ncoef" << endl ;
55 TIterator* funcIter = inFuncList.createIterator() ;
57 while((func = (RooAbsArg*)funcIter->Next())) {
58 RooAbsPdf *pdf =
dynamic_cast<RooAbsPdf*
>(func);
60 coutE(InputArguments) <<
"ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() <<
") function " << func->GetName() <<
" is not of type RooAbsPdf" << endl;
63 RooArgSet *params = pdf->getParameters(RooArgSet(x));
64 if (params->getSize() > 0) {
65 coutE(InputArguments) <<
"ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() <<
") pdf " << func->GetName() <<
" has some parameters." << endl;
73 TIterator* coefIter = inCoefList.createIterator() ;
75 while((coef = (RooAbsArg*)coefIter->Next())) {
76 if (!dynamic_cast<RooAbsReal*>(coef)) {
77 coutE(InputArguments) <<
"ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() <<
") coefficient " << coef->GetName() <<
" is not of type RooAbsReal" << endl;
94 RooAbsPdf(other,name),
95 _x(
"x",this,other._x),
96 _funcList(
"funcList",this,other._funcList),
97 _coefList(
"coefList",this,other._coefList),
98 _smoothRegion(other._smoothRegion),
99 _smoothAlgo(other._smoothAlgo),
131 printf(
"Evaluate called for x %f, cache status %d: ",
_x.arg().getVal(),
_sentry.
good());
133 for (
int i = 0;
i < ndim; ++
i) {
134 RooAbsReal *rar =
dynamic_cast<RooAbsReal *
>(
_coefList.at(
i));
135 printf(
"%s = %+6.4f ", rar->GetName(), rar->getVal());
142 if (ibin < 1) ibin = 1;
143 else if (ibin > nbin) ibin = nbin;
149 RooAbsPdf *pdfi =
dynamic_cast<RooAbsPdf *
>(
_funcList.at(i));
151 _cacheSingle[
i] = pdfi->createHistogram(
"",dynamic_cast<const RooRealVar &>(
_x.arg()));
159 if (y > 0 && y0 > 0) {
160 double logk =
log(y/y0);
177 for (
int i = 0;
i < 2*ndim+1; ++
i) {
183 for (
int i = 0;
i < ndim; ++
i) {
186 double x = (
dynamic_cast<RooAbsReal *
>(
_coefIter->Next()))->getVal();
200 if (val <= 0) val = 1
e-9;
208 void VerticalInterpHistPdf::setupCaches()
const {
210 _cacheTotal = (
dynamic_cast<const RooRealVar &
>(
_x.arg())).createHistogram(
"total");
214 for (
int i = 0;
i < 2*ndim+1; ++
i) {
233 _funcIter = _funcList.createIterator() ;
234 _coefIter = _coefList.createIterator() ;
240 RooAbsPdf(name,title),
241 _funcList(
"funcList",
"List of pdfs",this),
242 _coefList(
"coefList",
"List of coefficients",this),
243 _smoothRegion(smoothRegion),
244 _smoothAlgo(smoothAlgo),
246 _morphs(), _morphParams()
250 if (inFuncList.getSize()!=2*inCoefList.getSize()+1) {
251 coutE(InputArguments) <<
"VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName()
252 <<
") number of pdfs and coefficients inconsistent, must have Nfunc=1+2*Ncoef" << endl ;
256 TIterator* funcIter = inFuncList.createIterator() ;
258 while((func = (RooAbsArg*)funcIter->Next())) {
259 RooAbsPdf *pdf =
dynamic_cast<RooAbsPdf*
>(func);
261 coutE(InputArguments) <<
"ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() <<
") function " << func->GetName() <<
" is not of type RooAbsPdf" << endl;
264 RooArgSet *params = pdf->getParameters(obs);
265 if (params->getSize() > 0) {
266 coutE(InputArguments) <<
"ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() <<
") pdf " << func->GetName() <<
" has some parameters." << endl;
274 TIterator* coefIter = inCoefList.createIterator() ;
276 while((coef = (RooAbsArg*)coefIter->Next())) {
277 if (!dynamic_cast<RooAbsReal*>(coef)) {
278 coutE(InputArguments) <<
"ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() <<
") coefficient " << coef->GetName() <<
" is not of type RooAbsReal" << endl;
292 RooAbsPdf(other,name),
293 _funcList(
"funcList",this,other._funcList),
294 _coefList(
"coefList",this,other._coefList),
295 _smoothRegion(other._smoothRegion),
296 _smoothAlgo(other._smoothAlgo),
299 _morphs(other._morphs), _morphParams(other._morphParams)
301 _morphs(), _morphParams()
307 #ifdef FastVerticalInterpHistPdf_CopyConstructor
348 RooAbsPdf *pdf =
dynamic_cast<RooAbsPdf *
>(
_funcList.at(0));
349 const RooRealVar &
x =
dynamic_cast<const RooRealVar &
>(
_x.arg());
350 std::auto_ptr<TH1>
hist(pdf->createHistogram(
"",x));
351 hist->SetDirectory(0);
362 RooAbsPdf *pdf =
dynamic_cast<RooAbsPdf *
>(
_funcList.at(0));
363 const RooRealVar &
x =
dynamic_cast<const RooRealVar &
>(
_x.arg());
364 const RooRealVar &
y =
dynamic_cast<const RooRealVar &
>(
_y.arg());
366 std::auto_ptr<TH1>
hist(pdf->createHistogram(
"", x, RooFit::YVar(y), cond));
367 hist->SetDirectory(0);
394 RooAbsPdf *pdfHi =
dynamic_cast<RooAbsPdf *
>(
_funcList.at(2*dim+1));
395 RooAbsPdf *pdfLo =
dynamic_cast<RooAbsPdf *
>(
_funcList.at(2*dim+2));
396 const RooRealVar &
x =
dynamic_cast<const RooRealVar &
>(
_x.arg());
397 std::auto_ptr<TH1> histHi(pdfHi->createHistogram(
"",x)); histHi->SetDirectory(0);
398 std::auto_ptr<TH1> histLo(pdfLo->createHistogram(
"",x)); histLo->SetDirectory(0);
407 RooAbsPdf *pdfHi =
dynamic_cast<RooAbsPdf *
>(
_funcList.at(2*dim+1));
408 RooAbsPdf *pdfLo =
dynamic_cast<RooAbsPdf *
>(
_funcList.at(2*dim+2));
409 const RooRealVar &
x =
dynamic_cast<const RooRealVar &
>(
_x.arg());
410 const RooRealVar &
y =
dynamic_cast<const RooRealVar &
>(
_y.arg());
412 std::auto_ptr<TH1> histHi(pdfHi->createHistogram(
"", x, RooFit::YVar(y), cond)); histHi->SetDirectory(0);
413 std::auto_ptr<TH1> histLo(pdfLo->createHistogram(
"", x, RooFit::YVar(y), cond)); histLo->SetDirectory(0);
451 for (
int i = 0, ndim =
_coefList.getSize();
i < ndim; ++
i) {
498 for (
int i = 0;
i < ndim; ++
i) {
519 for (
int i = 0;
i < ndim; ++
i) {
const unsigned int size() const
void Subtract(const FastTemplate &reference)
*this = *this - reference
FastHisto _cache
Cache of the result.
FastHisto2D _cacheNominal
Cache of nominal pdf (additive morphing) and its bin-by-bin logarithm (multiplicative) ...
#define FastVerticalInterpHistPdf_CopyConstructor
virtual ~VerticalInterpHistPdf()
ClassDef(VerticalInterpHistPdf, 1) protected void syncTotal() const
not to be serialized
void setupCaches() const
not to be serialized
void CropUnderflows(T minimum=1e-9)
protect from underflows (*this = max(*this, minimum));
void syncTotal(FastTemplate &cache, const FastTemplate &cacheNominal, const FastTemplate &cacheNominalLog) const
const RooRealProxy & x() const
TIterator * _coefIter
Iterator over FUNC list.
FastVerticalInterpHistPdfBase()
int * _cacheSingleGood
not to be serialized
T GetAt(const T &x) const
void syncComponents(int dimension) const
void Log()
*this = log(*this)
Double_t evaluate() const
bool _init
Iterator over coefficient list.
FastHisto _cacheNominal
Cache of nominal pdf (additive morphing) and its bin-by-bin logarithm (multiplicative) ...
Must be public, for serialization.
TIterator * _coefIter
Iterator over FUNC list.
void setupCaches() const
not to be serialized
double smoothStepFunc(double x) const
void syncComponent(int which) const
SimpleCacheSentry _sentry
Iterator over coefficient list.
T GetAt(const T &x, const T &y) const
Double_t evaluate() const
void NormalizeXSlices()
For each X, normalize along Y.
void CopyValues(const FastTemplate &other)
std::vector< RooAbsReal * > _morphParams
not to be serialized
std::vector< Morph > _morphs
not to be serialized
void Exp()
*this = exp(*this)
void syncComponents(int dimension) const
void addVars(const RooAbsCollection &vars)
virtual ~FastVerticalInterpHistPdfBase()
double smoothStepFunc(double x) const
SimpleCacheSentry _sentry
not to be serialized
TH1 ** _cacheSingle
not to be serialized
FastHisto2D _cacheNominalLog
not to be serialized
Double_t evaluate() const
static void SumDiff(const FastTemplate &h1, const FastTemplate &h2, FastTemplate &sum, FastTemplate &diff)
assigns sum and diff
void LogRatio(const FastTemplate &reference)
*this = log(*this)/(reference)
void syncMorph(Morph &out, const FastTemplate &nominal, FastTemplate &lo, FastTemplate &hi) const
not to be serialized
FastHisto2D _cache
Cache of the result.
void Meld(const FastTemplate &diff, const FastTemplate &sum, T x, T y)
Does this += x * (diff + (sum)*y)
FastHisto _cacheNominalLog
not to be serialized