1 #include "../interface/PdfDiagonalizer.h"
4 #include <TMatrixDSym.h>
5 #include <TMatrixDSymEigen.h>
7 #include <RooAddition.h>
8 #include <RooCustomizer.h>
9 #include <RooFitResult.h>
10 #include <RooRealVar.h>
11 #include <RooWorkspace.h>
15 parameters_(result.floatParsFinal())
19 TMatrixDSym cov(result.covarianceMatrix());
20 TMatrixDSymEigen eigen(cov);
22 const TMatrixD& vectors = eigen.GetEigenVectors();
23 const TVectorD&
values = eigen.GetEigenValues();
28 for (
int i = 0;
i <
n; ++
i) {
29 snprintf(buff,
sizeof(buff),
"%s_eig%d[-5,5]", name,
i);
34 if (w->var(
"_one_") == 0) w->factory(
"_one_[1]");
35 eigvVarsPlusOne.add(*w->var(
"_one_"));
39 for (
int i = 0;
i <
n; ++
i) {
41 for (
int j = 0;
j <
n; ++
j) {
42 snprintf(buff,
sizeof(buff),
"%s_eigCoeff_%d_%d[%g]", name,
i,
j, vectors(
i,
j)*
sqrt(
values(
j)));
43 coeffs.add(*w->factory(buff));
45 snprintf(buff,
sizeof(buff),
"%s_eigBase_%d[%g]", name,
i, (dynamic_cast<RooAbsReal*>(
parameters_.at(
i)))->getVal());
46 coeffs.add(*w->factory(buff));
47 snprintf(buff,
sizeof(buff),
"%s_eigLin_%d", name,
i);
48 RooAddition *
add =
new RooAddition(buff,buff,coeffs,eigvVarsPlusOne);
59 RooCustomizer custom(pdf,
name_.c_str());
66 RooAbsPdf *
ret =
dynamic_cast<RooAbsPdf *
>(custom.build());
67 ret->SetName((std::string(pdf.GetName()) +
"_" +
name_).c_str());
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
RooAbsPdf * diagonalize(RooAbsPdf &pdf)
PdfDiagonalizer(const char *name, RooWorkspace *w, RooFitResult &result)