83#define NaN std::numeric_limits<double>::quiet_NaN() 
   92template <
typename Test, 
template <
typename...> 
class Ref>
 
   96template <
template <
typename...> 
class Ref, 
typename... Args>
 
  107template <
class MatrixT>
 
  108inline size_t size(
const MatrixT &matrix);
 
  118template <
class MatrixT>
 
  121   if (!stream.good()) {
 
  124   for (
size_t i = 0; i < 
size(matrix); ++i) {
 
  125      for (
size_t j = 0; j < 
size(matrix); ++j) {
 
  127         stream << std::setprecision(RooFit::SuperFloatPrecision::digits10) << matrix(i, j) << 
"\t";
 
  129         stream << matrix(i, j) << 
"\t";
 
  139template <
class MatrixT>
 
  142   std::ofstream of(fname);
 
  144      cerr << 
"unable to read file '" << fname << 
"'!" << std::endl;
 
  153#pragma GCC diagnostic push 
  154#pragma GCC diagnostic ignored "-Wshadow" 
  155#pragma GCC diagnostic ignored "-Wunused-local-typedefs" 
  156#include <boost/numeric/ublas/io.hpp> 
  157#include <boost/numeric/ublas/lu.hpp> 
  158#include <boost/numeric/ublas/matrix.hpp> 
  159#include <boost/numeric/ublas/matrix_expression.hpp> 
  160#include <boost/numeric/ublas/symmetric.hpp>  
  161#include <boost/numeric/ublas/triangular.hpp> 
  162#include <boost/operators.hpp> 
  164#pragma GCC diagnostic pop 
  166typedef boost::numeric::ublas::matrix<RooFit::SuperFloat> 
Matrix;
 
  173   for (
size_t i = 0; i < mat.size1(); ++i) {
 
  174      for (
size_t j = 0; j < mat.size2(); ++j) {
 
  175         std::cout << std::setprecision(RooFit::SuperFloatPrecision::digits10) << mat(i, j) << 
" ,\t";
 
  177      std::cout << std::endl;
 
  185inline size_t size<Matrix>(
const Matrix &matrix)
 
  187   return matrix.size1();
 
  195   return boost::numeric::ublas::identity_matrix<RooFit::SuperFloat>(
n);
 
  205   for (
size_t i = 0; i < 
n; ++i) {
 
  206      for (
size_t j = 0; j < 
n; ++j) {
 
  207         mat(i, j) = 
double(in(i, j));
 
  220   for (
size_t i = 0; i < 
n; ++i) {
 
  221      for (
size_t j = 0; j < 
n; ++j) {
 
  222         mat(i, j) = 
double(in(i, j));
 
  234   return prod(
m, otherM);
 
  242   boost::numeric::ublas::permutation_matrix<size_t> pm(
size(matrix));
 
  246      int res = lu_factorize(lu, pm);
 
  248         std::stringstream ss;
 
  250         cxcoutP(Eval) << ss.str << std::endl;
 
  253      lu_substitute(lu, pm, inverse);
 
  254   } 
catch (boost::numeric::ublas::internal_logic &error) {
 
  308   bool status = lu.
Invert(inverse);
 
  311      std::cerr << 
" matrix is not invertible!" << std::endl;
 
  314   const size_t n = 
size(inverse);
 
  316   for (
size_t i = 0; i < 
n; ++i)
 
  317      for (
size_t j = 0; j < 
n; ++j)
 
  318         if (fabs(inverse(i, j)) < 1
e-9)
 
  335typedef std::vector<std::vector<bool>> FeynmanDiagram;
 
  336typedef std::vector<std::vector<int>> MorphFuncPattern;
 
  337typedef std::map<int, std::unique_ptr<RooAbsReal>> FormulaList;
 
  342inline TString makeValidName(
const char *input)
 
  345   retval.ReplaceAll(
"/", 
"_");
 
  346   retval.ReplaceAll(
"^", 
"");
 
  347   retval.ReplaceAll(
"*", 
"X");
 
  348   retval.ReplaceAll(
"[", 
"");
 
  349   retval.ReplaceAll(
"]", 
"");
 
  357std::string concatNames(
const List &
c, 
const char *sep)
 
  359   std::stringstream ss;
 
  364      ss << itr->GetName();
 
  374template <
class A, 
class B>
 
  375inline void assignElement(A &
a, 
const B &
b)
 
  377   a = 
static_cast<A
>(
b);
 
  382template <
class MatrixT>
 
  383inline MatrixT readMatrixFromStreamT(std::istream &stream)
 
  385   std::vector<std::vector<RooFit::SuperFloat>> matrix;
 
  386   std::vector<RooFit::SuperFloat> 
line;
 
  387   while (!stream.eof()) {
 
  388      if (stream.peek() == 
'\n') {
 
  396      while (stream.peek() == 
' ' || stream.peek() == 
'\t') {
 
  399      if (stream.peek() == 
'\n') {
 
  400         matrix.push_back(
line);
 
  404   MatrixT retval(matrix.size(), matrix.size());
 
  405   for (
size_t i = 0; i < matrix.size(); ++i) {
 
  406      if (matrix[i].
size() != matrix.size()) {
 
  407         std::cerr << 
"matrix read from stream doesn't seem to be square!" << std::endl;
 
  409      for (
size_t j = 0; j < matrix[i].size(); ++j) {
 
  410         assignElement(retval(i, j), matrix[i][j]);
 
  419template <
class MatrixT>
 
  420inline MatrixT readMatrixFromFileT(
const char *fname)
 
  422   std::ifstream in(fname);
 
  424      std::cerr << 
"unable to read file '" << fname << 
"'!" << std::endl;
 
  426   MatrixT mat = readMatrixFromStreamT<MatrixT>(in);
 
  435void readValues(std::map<const std::string, T> &myMap, 
TH1 *h_pc)
 
  439      for (
int ibx = 1; ibx <= h_pc->
GetNbinsX(); ++ibx) {
 
  444         if (!s_coup.empty()) {
 
  445            myMap[s_coup] = 
T(coup_val);
 
  454void setOwnerRecursive(
TFolder *theFolder)
 
  459   for (
auto *subdir : *subdirs) {
 
  460      auto thisfolder = 
dynamic_cast<TFolder *
>(subdir);
 
  463         setOwnerRecursive(thisfolder);
 
  476std::unique_ptr<TFolder> readOwningFolderFromFile(
TDirectory *inFile, 
const std::string &folderName)
 
  478   std::unique_ptr<TFolder> theFolder(inFile->
Get<
TFolder>(folderName.c_str()));
 
  480      std::cerr << 
"Error: unable to access data from folder '" << folderName << 
"' from file '" << inFile->
GetName()
 
  481                << 
"'!" << std::endl;
 
  484   setOwnerRecursive(theFolder.get());
 
  497template <
class AObjType>
 
  498std::unique_ptr<AObjType> loadFromFileResidentFolder(
TDirectory *inFile, 
const std::string &folderName,
 
  499                                                     const std::string &objName, 
bool notFoundError = 
true)
 
  501   auto folder = readOwningFolderFromFile(inFile, folderName);
 
  505   AObjType *loadedObject = 
dynamic_cast<AObjType *
>(folder->FindObject(objName.c_str()));
 
  508         std::stringstream errstr;
 
  509         errstr << 
"Error: unable to retrieve object '" << objName << 
"' from folder '" << folderName
 
  510                << 
"'. contents are:";
 
  511         TIter next(folder->GetListOfFolders()->begin());
 
  516         std::cerr << errstr.str() << std::endl;
 
  522   return std::unique_ptr<AObjType>{
static_cast<AObjType *
>(loadedObject->Clone())};
 
  529void readValues(std::map<const std::string, T> &myMap, 
TDirectory *
file, 
const std::string &
name,
 
  530                const std::string &key = 
"param_card", 
bool notFoundError = 
true)
 
  532   auto h_pc = loadFromFileResidentFolder<TH1F>(
file, 
name, key, notFoundError);
 
  533   readValues(myMap, h_pc.get());
 
  542void readValues(std::map<
const std::string, std::map<const std::string, T>> &inputParameters, 
TDirectory *
f,
 
  543                const std::vector<std::string> &names, 
const std::string &key = 
"param_card", 
bool notFoundError = 
true)
 
  545   inputParameters.clear();
 
  548   for (
size_t i = 0; i < names.size(); i++) {
 
  549      const std::string 
name(names[i]);
 
  551      readValues(inputParameters[
name], 
f, 
name, key, notFoundError);
 
  560inline TDirectory *openFile(
const std::string &filename)
 
  562   if (filename.empty()) {
 
  569         std::cerr << 
"could not open file '" << filename << 
"'!" << std::endl;
 
  591inline void extractServers(
const RooAbsArg &coupling, 
T2 &operators)
 
  594   for (
const auto server : coupling.servers()) {
 
  595      extractServers(*server, operators);
 
  599      operators.add(coupling);
 
  606template <class T1, class T2, typename std::enable_if<!is_specialization<T1, std::vector>::value, 
T1>
::type * = 
nullptr>
 
  607inline void extractOperators(
const T1 &couplings, 
T2 &operators)
 
  611   for (
auto itr : couplings) {
 
  612      extractServers(*itr, operators);
 
  619template <class T1, class T2, typename std::enable_if<is_specialization<T1, std::vector>::value, 
T1>
::type * = 
nullptr>
 
  620inline void extractOperators(
const T1 &
vec, 
T2 &operators)
 
  622   for (
const auto &
v : 
vec) {
 
  623      extractOperators(
v, operators);
 
  630template <
class T1, 
class T2>
 
  631inline void extractCouplings(
const T1 &inCouplings, 
T2 &outCouplings)
 
  633   for (
auto itr : inCouplings) {
 
  634      if (!outCouplings.find(itr->GetName())) {
 
  637         outCouplings.add(*itr);
 
  646inline bool setParam(
RooRealVar *p, 
double val, 
bool force)
 
  653         std::cerr << 
": parameter " << p->
GetName() << 
" out of bounds: " << val << 
" > " << p->
getMax() << std::endl;
 
  656   } 
else if (val < p->getMin()) {
 
  660         std::cerr << 
": parameter " << p->
GetName() << 
" out of bounds: " << val << 
" < " << p->
getMin() << std::endl;
 
  673template <
class T1, 
class T2>
 
  674inline bool setParams(
const T2 &args, 
T1 val)
 
  676   for (
auto itr : args) {
 
  680      setParam(param, val, 
true);
 
  689template <
class T1, 
class T2>
 
  691setParams(
const std::map<const std::string, T1> &point, 
const T2 &args, 
bool force = 
false, 
T1 defaultVal = 0)
 
  694   for (
auto itr : args) {
 
  698      ok = setParam(param, defaultVal, force) && ok;
 
  701   for (
auto paramit : point) {
 
  703      const std::string param(paramit.first);
 
  709      ok = setParam(p, paramit.second, force) && ok;
 
  719inline bool setParams(
TH1 *hist, 
const T &args, 
bool force = 
false)
 
  723   for (
auto itr : args) {
 
  727      ok = setParam(param, 0., force) && ok;
 
  732   for (
int i = 1; i <= ax->
GetNbins(); ++i) {
 
  750   for (
auto itr : parameters) {
 
  767   bool binningOK = 
false;
 
  768   for (
auto sampleit : inputParameters) {
 
  769      const std::string sample(sampleit.first);
 
  770      auto hist = loadFromFileResidentFolder<TH1>(
file, sample, varname, 
true);
 
  774      auto it = list_hf.find(sample);
 
  775      if (it != list_hf.end()) {
 
  787            std::vector<double> bins;
 
  788            for (
int i = 1; i < 
n + 1; ++i) {
 
  796         TString histname = makeValidName(
Form(
"dh_%s_%s", sample.c_str(), 
name));
 
  797         TString funcname = makeValidName(
Form(
"phys_%s_%s", sample.c_str(), 
name));
 
  806         auto hf = std::make_unique<RooHistFunc>(funcname, funcname, var, *dh);
 
  808         list_hf[sample] = idx;
 
  819void collectRooAbsReal(
const char * , 
TDirectory *
file, std::map<std::string, int> &list_hf,
 
  820                       RooArgList &physics, 
const std::string &varname,
 
  823   for (
auto sampleit : inputParameters) {
 
  824      const std::string sample(sampleit.first);
 
  825      auto obj = loadFromFileResidentFolder<RooAbsReal>(
file, sample, varname, 
true);
 
  828      auto it = list_hf.find(sample);
 
  829      if (it == list_hf.end()) {
 
  831         list_hf[sample] = idx;
 
  845   for (
auto sampleit : inputParameters) {
 
  846      const std::string sample(sampleit.first);
 
  847      auto obj = loadFromFileResidentFolder<TObject>(
file, sample, varname, 
false);
 
  854      TPair *pair = 
dynamic_cast<TPair *
>(obj.get());
 
  860         std::stringstream errstr;
 
  861         errstr << 
"Error: unable to retrieve cross section '" << varname << 
"' from folder '" << sample;
 
  865      auto it = list_xs.find(sample.c_str());
 
  867      if (it != list_xs.end()) {
 
  871         std::string objname = 
Form(
"phys_%s_%s", 
name, sample.c_str());
 
  872         auto xsOwner = std::make_unique<RooRealVar>(objname.c_str(), objname.c_str(), xsection->
GetVal());
 
  876         list_xs[sample] = idx;
 
  877         physics.
addOwned(std::move(xsOwner));
 
  878         assert(physics.
at(idx) == xs);
 
  890void collectCrosssectionsTPair(
const char *
name, 
TDirectory *
file, std::map<std::string, int> &list_xs,
 
  891                               RooArgList &physics, 
const std::string &varname, 
const std::string &basefolder,
 
  894   auto pair = loadFromFileResidentFolder<TPair>(
file, basefolder, varname, 
false);
 
  898      collectCrosssections<double>(
name, 
file, list_xs, physics, varname, inputParameters);
 
  900      collectCrosssections<float>(
name, 
file, list_xs, physics, varname, inputParameters);
 
  902      std::cerr << 
"cannot morph objects of class 'TPair' if parameter is not " 
  916void collectPolynomialsHelper(
const FeynmanDiagram &diagram, MorphFuncPattern &morphfunc, std::vector<int> &term,
 
  917                              int vertexid, 
bool first)
 
  920      for (
size_t i = 0; i < diagram[vertexid - 1].size(); ++i) {
 
  921         if (!diagram[vertexid - 1][i])
 
  923         std::vector<int> newterm(term);
 
  926            ::collectPolynomialsHelper(diagram, morphfunc, newterm, vertexid, 
false);
 
  928            ::collectPolynomialsHelper(diagram, morphfunc, newterm, vertexid - 1, 
true);
 
  933      for (
size_t i = 0; i < morphfunc.size(); ++i) {
 
  934         bool thisfound = 
true;
 
  935         for (
size_t j = 0; j < morphfunc[i].size(); ++j) {
 
  936            if (morphfunc[i][j] != term[j]) {
 
  947         morphfunc.push_back(term);
 
  955void collectPolynomials(MorphFuncPattern &morphfunc, 
const FeynmanDiagram &diagram)
 
  957   int nvtx(diagram.size());
 
  958   std::vector<int> term(diagram[0].
size(), 0);
 
  960   ::collectPolynomialsHelper(diagram, morphfunc, term, nvtx, 
true);
 
  967inline void fillFeynmanDiagram(FeynmanDiagram &diagram, 
const std::vector<List *> &vertices, 
RooArgList &couplings)
 
  969   const int ncouplings = couplings.
getSize();
 
  971   for (
auto const &
vertex : vertices) {
 
  972      std::vector<bool> vertexCouplings(ncouplings, 
false);
 
  975      for (
auto citr : couplings) {
 
  979            std::cerr << 
"encountered invalid list of couplings in vertex!" << std::endl;
 
  983            vertexCouplings[idx] = 
true;
 
  986      diagram.push_back(vertexCouplings);
 
  993template <
class MatrixT, 
class T1, 
class T2>
 
  997   const size_t dim = inputParameters.size();
 
  998   MatrixT matrix(dim, dim);
 
 1000   for (
auto sampleit : inputParameters) {
 
 1001      const std::string sample(sampleit.first);
 
 1003      if (!setParams<double>(sampleit.second, args, 
true, 0)) {
 
 1004         std::cout << 
"unable to set parameters for sample " << sample << 
"!" << std::endl;
 
 1006      auto flagit = flagValues.find(sample);
 
 1007      if (flagit != flagValues.end() && !setParams<int>(flagit->second, flags, 
true, 1)) {
 
 1008         std::cout << 
"unable to set parameters for sample " << sample << 
"!" << std::endl;
 
 1012      for (
auto const &formula : formulas) {
 
 1013         if (!formula.second) {
 
 1014            std::cerr << 
"Error: invalid formula encountered!" << std::endl;
 
 1016         matrix(row, col) = formula.second->getVal();
 
 1029   if (inputParameters.size() != formulas.size()) {
 
 1030      std::stringstream ss;
 
 1031      ss << 
"matrix is not square, consistency check failed: " << inputParameters.size() << 
" samples, " 
 1032         << formulas.size() << 
" expressions:" << std::endl;
 
 1033      ss << 
"formulas: " << std::endl;
 
 1034      for (
auto const &formula : formulas) {
 
 1035         ss << formula.second->GetTitle() << std::endl;
 
 1037      ss << 
"samples: " << std::endl;
 
 1038      for (
auto sample : inputParameters) {
 
 1039         ss << sample.first << std::endl;
 
 1041      std::cerr << ss.str() << std::endl;
 
 1048inline void inverseSanity(
const Matrix &matrix, 
const Matrix &inverse, 
double &unityDeviation, 
double &largestWeight)
 
 1050   Matrix unity(inverse * matrix);
 
 1052   unityDeviation = 0.;
 
 1054   const size_t dim = 
size(unity);
 
 1055   for (
size_t i = 0; i < dim; ++i) {
 
 1056      for (
size_t j = 0; j < dim; ++j) {
 
 1057         if (inverse(i, j) > largestWeight) {
 
 1058            largestWeight = (
double)inverse(i, j);
 
 1060         if (
fabs(unity(i, j) - 
static_cast<int>(i == j)) > unityDeviation) {
 
 1061            unityDeviation = 
fabs((
double)unity(i, j)) - 
static_cast<int>(i == j);
 
 1069template <
class List>
 
 1072   for (
auto sampleit : inputParameters) {
 
 1073      const std::string sample(sampleit.first);
 
 1074      RooAbsArg *arg = args.find(sample.c_str());
 
 1076         std::cerr << 
"detected name conflict: cannot use sample '" << sample
 
 1077                   << 
"' - a parameter with the same name of type '" << arg->
ClassName() << 
"' is present in set '" 
 1078                   << args.GetName() << 
"'!" << std::endl;
 
 1090                          const std::vector<RooArgList *> &nonInterfering)
 
 1099   const int ncouplings = couplings.
getSize();
 
 1100   std::vector<bool> couplingsZero(ncouplings, 
true);
 
 1101   std::map<TString, bool> flagsZero;
 
 1104   extractOperators(couplings, operators);
 
 1105   size_t nOps = operators.
getSize();
 
 1107   for (
auto sampleit : inputParameters) {
 
 1108      const std::string sample(sampleit.first);
 
 1109      if (!setParams(sampleit.second, operators, 
true)) {
 
 1110         std::cerr << 
"unable to set parameters for sample '" << sample << 
"'!" << std::endl;
 
 1113      if ((
int)nOps != (operators.
getSize())) {
 
 1114         std::cerr << 
"internal error, number of operators inconsistent!" << std::endl;
 
 1120      for (
auto itr1 : couplings) {
 
 1122         if (obj0->
getVal() != 0) {
 
 1123            couplingsZero[idx] = 
false;
 
 1129   for (
auto itr2 : flags) {
 
 1130      auto obj1 = 
dynamic_cast<RooAbsReal *
>(itr2);
 
 1133      for (
auto sampleit : inputFlags) {
 
 1134         const auto &flag = sampleit.second.find(obj1->GetName());
 
 1135         if (flag != sampleit.second.end()) {
 
 1136            if (flag->second == 0.)
 
 1142      if (nZero > 0 && nNonZero == 0)
 
 1143         flagsZero[obj1->GetName()] = 
true;
 
 1145         flagsZero[obj1->GetName()] = 
false;
 
 1148   FormulaList formulas;
 
 1149   for (
size_t i = 0; i < morphfunc.size(); ++i) {
 
 1151      bool isZero = 
false;
 
 1154      for (
const auto &
group : nonInterfering) {
 
 1155         int nInterferingOperators = 0;
 
 1156         for (
size_t j = 0; j < morphfunc[i].size(); ++j) {
 
 1157            if (morphfunc[i][j] % 2 == 0)
 
 1161               nInterferingOperators++;
 
 1164         if (nInterferingOperators > 1) {
 
 1166            reason = 
"blacklisted interference term!";
 
 1172         for (
size_t j = 0; j < morphfunc[i].size(); ++j) {
 
 1173            const int exponent = morphfunc[i][j];
 
 1177            for (
int k = 0; k < exponent; ++k) {
 
 1183            std::string cname(coupling->
GetName());
 
 1186               reason = 
"coupling " + cname + 
" was listed as leading-order-only";
 
 1189            if (!isZero && couplingsZero[j]) {
 
 1191               reason = 
"coupling " + cname + 
" is zero!";
 
 1196      bool removedByFlag = 
false;
 
 1198      for (
auto itr : flags) {
 
 1202         TString sval(obj->getStringAttribute(
"NewPhysics"));
 
 1203         int val = atoi(sval);
 
 1205            if (flagsZero.find(obj->GetName()) != flagsZero.end() && flagsZero.at(obj->GetName())) {
 
 1206               removedByFlag = 
true;
 
 1207               reason = 
Form(
"flag %s is zero", obj->GetName());
 
 1214      if (!isZero && !removedByFlag) {
 
 1216         const auto name = std::string(mfname) + 
"_pol" + std::to_string(i);
 
 1217         formulas[i] = std::make_unique<RooProduct>(
name.c_str(), ::concatNames(ss, 
" * ").c_str(), ss);
 
 1228                           const std::vector<std::vector<RooArgList *>> &diagrams, 
RooArgList &couplings,
 
 1229                           const RooArgList &flags, 
const std::vector<RooArgList *> &nonInterfering)
 
 1231   MorphFuncPattern morphfuncpattern;
 
 1233   for (
const auto &vertices : diagrams) {
 
 1235      ::fillFeynmanDiagram(
d, vertices, couplings);
 
 1236      ::collectPolynomials(morphfuncpattern, 
d);
 
 1238   FormulaList retval = buildFormulas(
name, inputs, inputFlags, morphfuncpattern, couplings, flags, nonInterfering);
 
 1239   if (retval.empty()) {
 
 1240      std::stringstream errorMsgStream;
 
 1242         << 
"no formulas are non-zero, check if any if your couplings is floating and missing from your param_cards!" 
 1244      const auto errorMsg = errorMsgStream.str();
 
 1245      throw std::runtime_error(errorMsg);
 
 1247   checkMatrix(inputs, retval);
 
 1256                               FormulaList &formulas, 
const Matrix &inverse)
 
 1260   for (
auto sampleit : inputParameters) {
 
 1261      const std::string sample(sampleit.first);
 
 1262      std::stringstream title;
 
 1263      TString name_full(makeValidName(sample.c_str()));
 
 1265         name_full.Append(
"_");
 
 1266         name_full.Append(fname);
 
 1267         name_full.Prepend(
"w_");
 
 1272      auto sampleformula = std::make_unique<RooLinearCombination>(name_full.Data());
 
 1273      for (
auto const &formulait : formulas) {
 
 1275         sampleformula->add(val, formulait.second.get());
 
 1278      weights.addOwned(std::move(sampleformula));
 
 1283inline std::map<std::string, std::string>
 
 1288   std::map<std::string, std::string> weights;
 
 1289   for (
auto sampleit : inputParameters) {
 
 1290      const std::string sample(sampleit.first);
 
 1291      std::stringstream str;
 
 1294      for (
auto const &formulait : formulas) {
 
 1295         double val(inverse(formulaidx, sampleidx));
 
 1297            if (formulaidx > 0 && val > 0)
 
 1299            str << val << 
"*(" << formulait.second->GetTitle() << 
")";
 
 1303      weights[sample] = str.str();
 
 1338         args.
add(*(it.second));
 
 1353                                const std::vector<std::vector<RooListProxy *>> &diagramProxyList,
 
 1354                                const std::vector<RooArgList *> &nonInterfering, 
const RooArgList &flags)
 
 1357      std::vector<std::vector<RooArgList *>> diagrams;
 
 1358      for (
const auto &diagram : diagramProxyList) {
 
 1359         diagrams.emplace_back();
 
 1362            diagrams.back().emplace_back(
vertex);
 
 1366      _formulas = ::createFormulas(funcname, inputParameters, inputFlags, diagrams, 
_couplings, flags, nonInterfering);
 
 1371   template <
class List>
 
 1377      Matrix matrix(buildMatrixT<Matrix>(inputParameters, 
_formulas, operators, inputFlags, flags));
 
 1378      if (
size(matrix) < 1) {
 
 1379         std::cerr << 
"input matrix is empty, please provide suitable input samples!" << std::endl;
 
 1384      double unityDeviation, largestWeight;
 
 1385      inverseSanity(matrix, inverse, unityDeviation, largestWeight);
 
 1391            oocxcoutW((
TObject *)0, Eval) << 
"Warning: The matrix inversion seems to be unstable. This can " 
 1392                                             "be a result to input samples that are not sufficiently " 
 1393                                             "different to provide any morphing power." 
 1395         } 
else if (weightwarning) {
 
 1396            oocxcoutW((
TObject *)0, Eval) << 
"Warning: Some weights are excessively large. This can be a " 
 1397                                             "result to input samples that are not sufficiently different to " 
 1398                                             "provide any morphing power." 
 1402                                          "encoded in your samples to cross-check:" 
 1404         for (
auto sampleit : inputParameters) {
 
 1405            const std::string sample(sampleit.first);
 
 1408            setParams(sampleit.second, operators, 
true);
 
 1435                                     const std::map<std::string, int> &storage, 
const RooArgList &physics,
 
 1439         std::cerr << 
"invalid bin width given!" << std::endl;
 
 1443         std::cerr << 
"invalid observable given!" << std::endl;
 
 1457      for (
auto sampleit : inputParameters) {
 
 1459         TString prodname(makeValidName(sampleit.first.c_str()));
 
 1464            std::cerr << 
"unable to access physics object for " << prodname << std::endl;
 
 1471            std::cerr << 
"unable to access weight object for " << prodname << std::endl;
 
 1478         allowNegativeYields = 
true;
 
 1479         auto prod = std::make_unique<RooProduct>(prodname, prodname, prodElems);
 
 1480         if (!allowNegativeYields) {
 
 1481            auto maxname = std::string(prodname) + 
"_max0";
 
 1484            auto max = std::make_unique<RooFormulaVar>(maxname.c_str(), 
"max(0," + prodname + 
")", prodset);
 
 1485            max->addOwnedComponents(std::move(prod));
 
 1486            sumElements.
addOwned(std::move(max));
 
 1488            sumElements.
addOwned(std::move(prod));
 
 1490         scaleElements.
add(*(binWidth));
 
 1495      _sumFunc = make_unique<RooRealSumFunc>(
Form(
"%s_morphfunc", 
name), 
name, sumElements, scaleElements);
 
 1498         std::cerr << 
"unable to access observable" << std::endl;
 
 1499      _sumFunc.get()->addServer(*observable);
 
 1501         std::cerr << 
"unable to access bin width" << std::endl;
 
 1502      _sumFunc.get()->addServer(*binWidth);
 
 1504         std::cerr << 
"no operators listed" << std::endl;
 
 1505      _sumFunc.get()->addServerList(operators);
 
 1507         std::cerr << 
"unable to access weight objects" << std::endl;
 
 1508      _sumFunc.get()->addOwnedComponents(std::move(sumElements));
 
 1509      _sumFunc.get()->addServerList(sumElements);
 
 1510      _sumFunc.get()->addServerList(scaleElements);
 
 1513      std::cout.precision(std::numeric_limits<double>::digits);
 
 1527                              {func->_nonInterfering.begin(), func->_nonInterfering.end()}, func->
_flags);
 
 1530      if (obsName.empty()) {
 
 1531         std::cerr << 
"Matrix inversion succeeded, but no observable was " 
 1532                      "supplied. quitting..." 
 1540      setParams(func->
_flags, 1);
 
 1544      setParams(func->
_flags, 1);
 
 1559                              {func->_nonInterfering.begin(), func->_nonInterfering.end()}, func->
_flags);
 
 1567      setParams(func->
_flags, 1);
 
 1571      setParams(func->
_flags, 1);
 
 1601   return readMatrixFromFileT<TMatrixD>(fname);
 
 1609   return readMatrixFromStreamT<TMatrixD>(stream);
 
 1619   bool obsExists(
false);
 
 1625   if (mode && mode->
InheritsFrom(RooHistFunc::Class())) {
 
 1629   } 
else if (mode && mode->
InheritsFrom(RooParamHistFunc::Class())) {
 
 1640         TH1 *hist = (
TH1 *)(inputExample);
 
 1643         obs = obsOwner.get();
 
 1647         auto obsOwner = std::make_unique<RooRealVar>(obsname, obsname, 0, 1);
 
 1648         obs = obsOwner.get();
 
 1654      if (strcmp(obsname, obs->
GetName()) != 0) {
 
 1656                               << 
" does not match expected name " << obsname << std::endl;
 
 1661   auto binWidth = std::make_unique<RooRealVar>(sbw.
Data(), sbw.
Data(), 1.);
 
 1663   binWidth->setVal(bw);
 
 1664   binWidth->setConstant(
true);
 
 1683   const size_t n(
size(cache->_inverse));
 
 1685      const std::string sample(sampleit.first);
 
 1688      if (!sampleformula) {
 
 1689         coutE(ObjectHandling) << 
Form(
"unable to access formula for sample '%s'!", sample.c_str()) << std::endl;
 
 1692      cxcoutP(ObjectHandling) << 
"updating formula for sample '" << sample << 
"'" << std::endl;
 
 1693      for (
size_t formulaidx = 0; formulaidx < 
n; ++formulaidx) {
 
 1698         if (std::isnan(val)) {
 
 1700            coutE(ObjectHandling) << 
"refusing to propagate NaN!" << std::endl;
 
 1702         cxcoutP(ObjectHandling) << 
"   " << formulaidx << 
":" << sampleformula->
getCoefficient(formulaidx) << 
" -> " 
 1703                                 << val << std::endl;
 
 1733   cxcoutP(InputArguments) << 
"initializing physics inputs from file " << 
file->GetName() << 
" with object name(s) '" 
 1734                           << obsName << 
"'" << std::endl;
 
 1736   auto obj = loadFromFileResidentFolder<TObject>(
file, folderNames.front(), obsName, 
true);
 
 1738      std::cerr << 
"unable to locate object '" << obsName << 
"' in folder '" << folderNames.front() << 
"'!" 
 1742   std::string classname = obj->ClassName();
 
 1746   if (classname.find(
"TH1") != std::string::npos) {
 
 1748   } 
else if (classname.find(
"RooHistFunc") != std::string::npos ||
 
 1749              classname.find(
"RooParamHistFunc") != std::string::npos ||
 
 1750              classname.find(
"PiecewiseInterpolation") != std::string::npos) {
 
 1752   } 
else if (classname.find(
"TParameter<double>") != std::string::npos) {
 
 1754   } 
else if (classname.find(
"TParameter<float>") != std::string::npos) {
 
 1756   } 
else if (classname.find(
"TPair") != std::string::npos) {
 
 1760      std::cerr << 
"cannot morph objects of class '" << mode->
GetName() << 
"'!" << std::endl;
 
 1769   for (
auto const &folder : folders) {
 
 1771      const std::string sample(var ? var->
getVal() : folder->GetName());
 
 1780   while ((obj = (
TObject *)next())) {
 
 1781      auto f = readOwningFolderFromFile(
file, obj->
GetName());
 
 1784      std::string 
name(
f->GetName());
 
 1799         std::cout << param.first << 
" = " << param.second;
 
 1801            std::cout << 
" (const)";
 
 1802         std::cout << std::endl;
 
 1814      std::cout << folder << std::endl;
 
 1836     _operators(
"operators", 
"set of operators", this), 
_observables(
"observables", 
"morphing observables", this),
 
 1849                                               const char *observableName, 
const RooArgSet &couplings,
 
 1851   : 
RooAbsReal(
name, title), _cacheMgr(this, 10, true, true), _physics(
"physics", 
"physics", this),
 
 1852     _operators(
"operators", 
"set of operators", this), _observables(
"observables", 
"morphing observables", this),
 
 1853     _binWidths(
"binWidths", 
"set of binWidth objects", this), _flags(
"flags", 
"flags", this)
 
 1873      std::vector<RooListProxy *> vertices;
 
 1875      vertices.push_back(
new RooListProxy(
"!couplings", 
"set of couplings in the vertex", 
this, 
true, 
false));
 
 1887      std::vector<RooListProxy *> vertices;
 
 1889      cxcoutP(InputArguments) << 
"prod/dec couplings provided" << std::endl;
 
 1893         new RooListProxy(
"!production", 
"set of couplings in the production vertex", 
this, 
true, 
false));
 
 1894      vertices.push_back(
new RooListProxy(
"!decay", 
"set of couplings in the decay vertex", 
this, 
true, 
false));
 
 1900         cxcoutP(InputArguments) << 
"adding non-own operators" << std::endl;
 
 1915   std::stringstream 
name;
 
 1916   name << 
"noInteference";
 
 1917   for (
auto c : nonInterfering) {
 
 1922   for (
auto c : nonInterfering) {
 
 1923      p->addOwned(std::make_unique<RooStringVar>(
c, 
c, 
c));
 
 1933   for (
size_t i = 0; i < nonInterfering.size(); ++i) {
 
 1946      coutE(InputArguments) << 
"unable to open file '" << filename << 
"'!" << std::endl;
 
 1982   : 
RooAbsReal(other, 
name), _cacheMgr(other._cacheMgr, this), _scale(other._scale), _sampleMap(other._sampleMap),
 
 1983     _physics(other._physics.GetName(), this, other._physics),
 
 1984     _operators(other._operators.GetName(), this, other._operators),
 
 1985     _observables(other._observables.GetName(), this, other._observables),
 
 1986     _binWidths(other._binWidths.GetName(), this, other._binWidths), _flags{other._flags.GetName(), this, other._flags},
 
 1987     _config(other._config)
 
 1989   for (
size_t j = 0; j < other.
_diagrams.size(); ++j) {
 
 1990      std::vector<RooListProxy *> diagram;
 
 1991      for (
size_t i = 0; i < other.
_diagrams[j].size(); ++i) {
 
 1993         diagram.push_back(list);
 
 2020   : _cacheMgr(this, 10, true, true), _operators(
"operators", 
"set of operators", this, true, false),
 
 2021     _observables(
"observable", 
"morphing observable", this, true, false),
 
 2022     _binWidths(
"binWidths", 
"set of bin width objects", this, true, false)
 
 2024   static int counter(0);
 
 2059   FeynmanDiagram diagram;
 
 2060   std::vector<bool> prod;
 
 2061   std::vector<bool> dec;
 
 2062   for (
int i = 0; i < nboth; ++i) {
 
 2063      prod.push_back(
true);
 
 2064      dec.push_back(
true);
 
 2066   for (
int i = 0; i < nprod; ++i) {
 
 2067      prod.push_back(
true);
 
 2068      dec.push_back(
false);
 
 2070   for (
int i = 0; i < ndec; ++i) {
 
 2071      prod.push_back(
false);
 
 2072      dec.push_back(
true);
 
 2074   diagram.push_back(prod);
 
 2075   diagram.push_back(dec);
 
 2076   MorphFuncPattern morphfuncpattern;
 
 2077   ::collectPolynomials(morphfuncpattern, diagram);
 
 2078   return morphfuncpattern.size();
 
 2087   for (
auto vertex : vertices) {
 
 2088      extractOperators(*
vertex, operators);
 
 2089      extractCouplings(*
vertex, couplings);
 
 2091   FeynmanDiagram diagram;
 
 2092   ::fillFeynmanDiagram(diagram, vertices, couplings);
 
 2093   MorphFuncPattern morphfuncpattern;
 
 2094   ::collectPolynomials(morphfuncpattern, diagram);
 
 2095   return morphfuncpattern.size();
 
 2101std::map<std::string, std::string>
 
 2103                                            const std::vector<std::vector<std::string>> &vertices_str)
 
 2105   std::stack<RooArgList> ownedVertices;
 
 2106   std::vector<RooArgList *> vertices;
 
 2108   for (
const auto &vtx : vertices_str) {
 
 2109      ownedVertices.emplace();
 
 2110      auto &
vertex = ownedVertices.top();
 
 2111      for (
const auto &
c : vtx) {
 
 2114            auto couplingOwner = std::make_unique<RooRealVar>(
c.c_str(), 
c.c_str(), 1., 0., 10.);
 
 2115            coupling = couplingOwner.get();
 
 2116            couplings.
addOwned(std::move(couplingOwner));
 
 2120      vertices.push_back(&
vertex);
 
 2129std::map<std::string, std::string>
 
 2131                                            const std::vector<RooArgList *> &vertices, 
RooArgList &couplings)
 
 2139std::map<std::string, std::string>
 
 2141                                            const std::vector<RooArgList *> &vertices, 
RooArgList &couplings,
 
 2143                                            const std::vector<RooArgList *> &nonInterfering)
 
 2145   FormulaList formulas = ::createFormulas(
"", inputs, flagValues, {vertices}, couplings, flags, nonInterfering);
 
 2147   extractOperators(couplings, operators);
 
 2148   Matrix matrix(::buildMatrixT<Matrix>(inputs, formulas, operators, flagValues, flags));
 
 2149   if (
size(matrix) < 1) {
 
 2150      std::cerr << 
"input matrix is empty, please provide suitable input samples!" << std::endl;
 
 2154   auto retval = buildSampleWeightStrings(inputs, formulas, inverse);
 
 2162                                                const std::vector<RooArgList *> &vertices, 
RooArgList &couplings,
 
 2165                                                const std::vector<RooArgList *> &nonInterfering)
 
 2167   FormulaList formulas = ::createFormulas(
"", inputs, flagValues, {vertices}, couplings, flags, nonInterfering);
 
 2169   extractOperators(couplings, operators);
 
 2170   Matrix matrix(::buildMatrixT<Matrix>(inputs, formulas, operators, flagValues, flags));
 
 2171   if (
size(matrix) < 1) {
 
 2172      std::cerr << 
"input matrix is empty, please provide suitable input samples!" << std::endl;
 
 2177   ::buildSampleWeights(retval, (
const char *)
nullptr , inputs, formulas, inverse);
 
 2185                                                const std::vector<RooArgList *> &vertices, 
RooArgList &couplings)
 
 2187   std::vector<RooArgList *> nonInterfering;
 
 2201      coutE(Eval) << 
"unable to retrieve morphing function" << std::endl;
 
 2209   for (
auto itr : *args) {
 
 2234   auto wname = std::string(
"w_") + 
name + 
"_" + this->
GetName();
 
 2235   return dynamic_cast<RooAbsReal *
>(cache->_weights.find(wname.c_str()));
 
 2253      auto weightName = std::string(
"w_") + sample.first + 
"_" + this->
GetName();
 
 2254      auto weight = 
static_cast<RooAbsReal *
>(cache->_weights.find(weightName.c_str()));
 
 2271      double val = obj->
getVal();
 
 2274      double variation = 
r.Gaus(1, z);
 
 2275      obj->
setVal(val * variation);
 
 2290      coutE(InputArguments) << 
"unable to open file '" << filename << 
"'!" << std::endl;
 
 2316      cache->_inverse = 
m;
 
 2319         coutE(InputArguments) << 
"unable to open file '" << filename << 
"'!" << std::endl;
 
 2334         coutE(Caching) << 
"unable to create cache!" << std::endl;
 
 2352      coutE(Caching) << 
"unable to create cache!" << std::endl;
 
 2376      cxcoutP(Caching) << 
"creating cache from getCache function for " << 
this << std::endl;
 
 2377      cxcoutP(Caching) << 
"current storage has size " << 
_sampleMap.size() << std::endl;
 
 2382         coutE(Caching) << 
"unable to create cache!" << std::endl;
 
 2404   if (value > param->
getMax())
 
 2406   if (value < param->getMin())
 
 2530   auto paramhist = loadFromFileResidentFolder<TH1>(
file, foldername, 
"param_card");
 
 2531   setParams(paramhist.get(), 
_operators, 
false);
 
 2541   const std::string 
name(foldername);
 
 2551   for (
auto itr : *list) {
 
 2565      coutE(InputArguments) << 
"observable not available!" << std::endl;
 
 2577      coutE(InputArguments) << 
"bin width not available!" << std::endl;
 
 2596   auto mf = std::make_unique<RooRealSumFunc>(*(this->
getFunc()));
 
 2599   const int nbins = observable->
getBins();
 
 2604   for (
int i = 0; i < nbins; ++i) {
 
 2609      for (
auto itr : *args) {
 
 2621         double weight = formula->
getVal();
 
 2624         val += dhist.
weight() * weight;
 
 2627      hist->
SetBinError(i + 1, correlateErrors ? unc : sqrt(unc2));
 
 2629   return hist.release();
 
 2638   auto mf = std::make_unique<RooRealSumFunc>(*(this->
getFunc()));
 
 2640      coutE(InputArguments) << 
"unable to retrieve morphing function" << std::endl;
 
 2642   for (
auto itr : *args) {
 
 2644      if (prod->
getVal() != 0) {
 
 2658   std::string pname(paramname);
 
 2660   bool isUsed = 
false;
 
 2662      double thisval = sample.second.at(pname);
 
 2663      if (thisval != val) {
 
 2679   std::string cname(couplname);
 
 2686   bool isUsed = 
false;
 
 2689      double thisval = coupling->
getVal();
 
 2690      if (thisval != val) {
 
 2715   return cache->_formulas.size();
 
 2723   auto mf = std::make_unique<RooRealSumFunc>(*(this->
getFunc()));
 
 2725      std::cerr << 
"Error: unable to retrieve morphing function" << std::endl;
 
 2729   for (
auto itr : *args) {
 
 2734         name.Prepend(
"phys_");
 
 2738         double val = formula->
getVal();
 
 2740            std::cout << formula->
GetName() << 
": " << val << 
" = " << formula->
GetTitle() << std::endl;
 
 2760   return &(cache->_couplings);
 
 2774      double val = var->
getVal();
 
 2775      couplings[
name] = val;
 
 2802   auto func = std::make_unique<RooRealSumFunc>(*(cache->_sumFunc));
 
 2805   return std::make_unique<RooWrapperPdf>(
Form(
"pdf_%s", func->GetName()), 
Form(
"pdf of %s", func->GetTitle()), *func);
 
 2814   return cache->_sumFunc.get();
 
 2831   return this->
createPdf()->expectedEvents(nset);
 
 2841   return this->
createPdf()->expectedEvents(set);
 
 2850   return createPdf()->expectedEvents(&nset);
 
 2863      auto weightName = std::string(
"w_") + sample.first + 
"_" + this->
GetName();
 
 2864      auto weight = 
static_cast<RooAbsReal *
>(cache->_weights.find(weightName.c_str()));
 
 2866         coutE(InputArguments) << 
"unable to find object " + weightName << std::endl;
 
 2881      double w = weight->getVal();
 
 2882      unc2 += newunc2 * w * w;
 
 2909   for (
auto flag : 
_flags) {
 
 2923   for (
auto c : couplings) {
 
 2924      std::cout << 
c.first << 
": " << 
c.second << std::endl;
 
 2954      std::cerr << 
"unable to acquire in-built function!" << std::endl;
 
 2986                                                      const char *rangeName)
 const 
 3030      coutE(Caching) << 
"unable to retrieve cache!" << std::endl;
 
 3041      coutE(Caching) << 
"unable to retrieve cache!" << std::endl;
 
 3054      coutE(Caching) << 
"unable to retrieve cache!" << std::endl;
 
 3055   return cache->_condition;
 
 3061std::unique_ptr<RooRatio>
 
 3065   for (
auto it : nr) {
 
 3068   for (
auto it : dr) {
 
 3072   return make_unique<RooRatio>(
name, title, num, denom);
 
size_t size< TMatrixD >(const TMatrixD &mat)
 
void writeMatrixToStreamT(const MatrixT &matrix, std::ostream &stream)
write a matrix to a stream
 
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
 
static constexpr double morphUnityDeviation
 
Matrix makeSuperMatrix(const TMatrixD &in)
convert a TMatrixD into a Matrix
 
static constexpr double morphLargestWeight
 
void writeMatrixToFileT(const MatrixT &matrix, const char *fname)
write a matrix to a text file
 
double invertMatrix(const Matrix &matrix, Matrix &inverse)
 
TMatrixD makeRootMatrix(const Matrix &in)
convert a matrix into a TMatrixD
 
Matrix diagMatrix(size_t n)
create a new diagonal matrix of size n
 
void printMatrix(const TMatrixD &mat)
write a matrix
 
TMatrixT< Double_t > TMatrixD
 
char * Form(const char *fmt,...)
 
std::string & operator+=(std::string &left, const TString &right)
 
TTime operator*(const TTime &t1, const TTime &t2)
 
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
 
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
 
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
 
virtual void Print(Option_t *options=0) const
Print the object to the defaultPrintStream().
 
friend class RooListProxy
 
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
 
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
 
Bool_t isConstant() const
Check if the "Constant" attribute is set.
 
virtual Double_t * array() const =0
 
RooAbsCacheElement is the abstract base class for objects to be stored in RooAbsCache cache manager o...
 
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
 
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add an argument and transfer the ownership to the collection.
 
Storage_t::size_type size() const
 
RooAbsArg * first() const
 
RooAbsArg * find(const char *name) const
Find object with given name in list.
 
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
 
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
 
virtual void setBin(Int_t ibin, const char *rangeName=0)
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
 
virtual Int_t numBins(const char *rangeName=0) const
 
virtual Int_t getBins(const char *name=0) const
Get number of bins of currently defined range.
 
void setConstant(Bool_t value=kTRUE)
 
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
 
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
 
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
 
RooArgList is a container object that can hold multiple RooAbsArg objects.
 
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
 
RooArgSet is a container object that can hold multiple RooAbsArg objects.
 
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
 
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=0, const TNamed *isetRangeName=0)
 
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=0)
 
The RooDataHist is a container class to hold N-dimensional binned data.
 
double weight(std::size_t i) const
Return weight of i-th bin.
 
double weightSquared(std::size_t i) const
Return squared weight sum of i-th bin.
 
const RooArgSet * get() const override
Get bin centre of current bin.
 
RooHistFunc implements a real-valued function sampled from a multidimensional histogram.
 
RooArgSet const & getHistObsList() const
 
RooDataHist & dataHist()
Return RooDataHist that is represented.
 
static RooLagrangianMorphFunc::CacheElem * createCache(const RooLagrangianMorphFunc *func)
create all the temporary objects required by the class
 
void buildMatrix(const RooLagrangianMorphFunc::ParamMap &inputParameters, const RooLagrangianMorphFunc::FlagMap &inputFlags, const List &flags)
build and invert the morphing matrix
 
static RooLagrangianMorphFunc::CacheElem * createCache(const RooLagrangianMorphFunc *func, const Matrix &inverse)
create all the temporary objects required by the class function variant with precomputed inverse matr...
 
std::unique_ptr< RooRealSumFunc > _sumFunc
 
RooArgList containedArgs(Action) override
retrieve the list of contained args
 
void operModeHook(RooAbsArg::OperMode) override
Interface for changes of operation mode.
 
void createComponents(const RooLagrangianMorphFunc::ParamMap &inputParameters, const RooLagrangianMorphFunc::FlagMap &inputFlags, const char *funcname, const std::vector< std::vector< RooListProxy * > > &diagramProxyList, const std::vector< RooArgList * > &nonInterfering, const RooArgList &flags)
create the basic objects required for the morphing
 
void buildMorphingFunction(const char *name, const RooLagrangianMorphFunc::ParamMap &inputParameters, const std::map< std::string, int > &storage, const RooArgList &physics, bool allowNegativeYields, RooRealVar *observable, RooRealVar *binWidth)
build the final morphing function
 
Class RooLagrangianMorphing is a implementation of the method of Effective Lagrangian Morphing,...
 
bool isParameterConstant(const char *paramname) const
return true if the parameter with the given name is set constant, false otherwise
 
bool isBinnedDistribution(const RooArgSet &obs) const override
check if this PDF is a binned distribution in the given observable
 
int nPolynomials() const
return the number of samples in this morphing function
 
void setParameter(const char *name, double value)
set one parameter to a specific value
 
ParamSet getMorphParameters() const
retrieve the parameter set
 
double evaluate() const override
call getVal on the internal function
 
void disableInterference(const std::vector< const char * > &nonInterfering)
disable interference between terms
 
RooProduct * getSumElement(const char *name) const
return the RooProduct that is the element of the RooRealSumPdfi corresponding to the given sample nam...
 
RooRealVar * getBinWidth() const
retrieve the histogram observable
 
void writeMatrixToFile(const TMatrixD &matrix, const char *fname)
write a matrix to a file
 
RooRealVar * getParameter(const char *name) const
retrieve the RooRealVar object incorporating the parameter with the given name
 
bool useCoefficients(const TMatrixD &inverse)
setup the morphing function with a predefined inverse matrix call this function before any other afte...
 
const RooArgSet * getParameterSet() const
get the set of parameters
 
TMatrixD readMatrixFromStream(std::istream &stream)
read a matrix from a stream
 
std::vector< std::string > getSamples() const
return the vector of sample names, used to build the morph func
 
int countSamples(std::vector< RooArgList * > &vertices)
calculate the number of samples needed to morph a certain physics process
 
void setCacheAndTrackHints(RooArgSet &) override
Retrieve the matrix of coefficients.
 
ParamSet getCouplings() const
retrieve a set of couplings (-?-)
 
void printSampleWeights() const
print the current sample weights
 
std::map< const std::string, double > ParamSet
 
RooArgSet createWeights(const ParamMap &inputs, const std::vector< RooArgList * > &vertices, RooArgList &couplings, const FlagMap &inputFlags, const RooArgList &flags, const std::vector< RooArgList * > &nonInterfering)
create only the weight formulas. static function for external usage.
 
void writeMatrixToStream(const TMatrixD &matrix, std::ostream &stream)
write a matrix to a stream
 
void addFolders(const RooArgList &folders)
convert the RooArgList folders into a simple vector of std::string
 
std::map< const std::string, ParamSet > ParamMap
 
bool updateCoefficients()
retrive the new physics objects and update the weights in the morphing function
 
double _scale
The cache manager.
 
RooRealVar * getObservable() const
retrieve the histogram observable
 
int countContributingFormulas() const
count the number of formulas that correspond to the current parameter set
 
std::list< double > * plotSamplingHint(RooAbsRealLValue &, double, double) const override
retrieve the sample Hint
 
RooRealVar * getFlag(const char *name) const
retrieve the RooRealVar object incorporating the flag with the given name
 
void randomizeParameters(double z)
randomize the parameters a bit useful to test and debug fitting
 
bool isCouplingUsed(const char *couplname)
check if there is any morphing power provided for the given coupling morphing power is provided as so...
 
void readParameters(TDirectory *f)
read the parameters from the input file
 
double getScale()
get energy scale of the EFT expansion
 
std::vector< RooListProxy * > _nonInterfering
 
double getCondition() const
Retrieve the condition of the coefficient matrix.
 
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=0) const override
Retrieve the matrix of coefficients.
 
TMatrixD getMatrix() const
Retrieve the matrix of coefficients.
 
void printWeights() const
print the current sample weights
 
void printCouplings() const
print a set of couplings
 
TMatrixD readMatrixFromFile(const char *fname)
read a matrix from a text file
 
~RooLagrangianMorphFunc() override
default destructor
 
void printParameters() const
print the parameters and their current values
 
void printPhysics() const
print the current physics values
 
static std::unique_ptr< RooRatio > makeRatio(const char *name, const char *title, RooArgList &nr, RooArgList &dr)
Return the RooRatio form of products and denominators of morphing functions.
 
void setFlag(const char *name, double value)
set one flag to a specific value
 
TH1 * createTH1(const std::string &name)
retrieve a histogram output of the current morphing settings
 
double expectedUncertainty() const
return the expected uncertainty for the current parameter set
 
int nParameters() const
return the number of parameters in this morphing function
 
bool hasParameter(const char *paramname) const
check if a parameter of the given name is contained in the list of known parameters
 
bool checkObservables(const RooArgSet *nset) const override
check if observable exists in the RooArgSet (-?-)
 
bool hasCache() const
return true if a cache object is present, false otherwise
 
void printFlags() const
print the flags and their current values
 
void setScale(double val)
set energy scale of the EFT expansion
 
TMatrixD getInvertedMatrix() const
Retrieve the matrix of coefficients after inversion.
 
RooAbsArg::CacheMode canNodeBeCached() const override
Retrieve the matrix of coefficients.
 
void updateSampleWeights()
update sample weight (-?-)
 
void setParameters(const char *foldername)
set the morphing parameters to those supplied in the sample with the given name
 
RooObjCacheManager _cacheMgr
 
bool isParameterUsed(const char *paramname) const
check if there is any morphing power provided for the given parameter morphing power is provided as s...
 
RooListProxy _observables
 
RooAbsPdf::ExtendMode extendMode() const
return extended mored capabilities
 
std::map< const std::string, FlagSet > FlagMap
 
bool forceAnalyticalInt(const RooAbsArg &arg) const override
Force analytical integration for the given observable.
 
void setParameterConstant(const char *paramname, bool constant) const
call setConstant with the boolean argument provided on the parameter with the given name
 
void disableInterferences(const std::vector< std::vector< const char * > > &nonInterfering)
disable interference between terms
 
void printSamples() const
print all the known samples to the console
 
double getParameterValue(const char *name) const
set one parameter to a specific value
 
void setup(bool ownParams=true)
setup this instance with the given set of operators and vertices if own=true, the class will own the ...
 
void printMetaArgs(std::ostream &os) const override
Retrieve the matrix of coefficients.
 
std::unique_ptr< RooWrapperPdf > createPdf() const
(currently similar to cloning the Pdf
 
RooAbsReal * getSampleWeight(const char *name)
retrieve the weight (prefactor) of a sample with the given name
 
std::map< std::string, std::string > createWeightStrings(const ParamMap &inputs, const std::vector< std::vector< std::string > > &vertices)
create only the weight formulas. static function for external usage.
 
std::vector< std::vector< RooListProxy * > > _diagrams
 
double expectedEvents() const
return the number of expected events for the current parameter set
 
std::map< std::string, int > _sampleMap
 
TObject * clone(const char *newname) const override
cloning method
 
RooLagrangianMorphFunc::CacheElem * getCache() const
retrieve the cache object
 
RooRealVar * setupObservable(const char *obsname, TClass *mode, TObject *inputExample)
setup observable, recycle existing observable if defined
 
const RooArgList * getCouplingSet() const
get the set of couplings
 
RooRealSumFunc * getFunc() const
get the func
 
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
retrieve the list of bin boundaries
 
void printEvaluation() const
print the contributing samples and their respective weights
 
bool writeCoefficients(const char *filename)
write the inverse matrix to a file
 
void collectInputs(TDirectory *f)
retrieve the physics inputs
 
void init()
initialise inputs required for the morphing function
 
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=0) const override
Retrieve the mat.
 
RooLinearCombination is a class that helps perform linear combination of floating point numbers and p...
 
void setCoefficient(size_t idx, RooFit::SuperFloat c)
 
RooFit::SuperFloat getCoefficient(size_t idx)
 
RooListProxy is the concrete proxy for RooArgList objects.
 
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE) override
Reimplementation of standard RooArgList::addOwned()
 
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Reimplementation of standard RooArgList::add()
 
A histogram function that assigns scale parameters to every bin.
 
const RooArgList & paramList() const
 
A RooProduct represents the product of a given set of RooAbsReal objects.
 
virtual Bool_t forceAnalyticalInt(const RooAbsArg &arg) const
 
Bool_t isBinnedDistribution(const RooArgSet &obs) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
 
virtual std::list< Double_t > * binBoundaries(RooAbsRealLValue &, Double_t, Double_t) const
Retrieve bin boundaries if this distribution is binned in obs.
 
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=0) const
Variant of getAnalyticalIntegral that is also passed the normalization set that should be applied to ...
 
virtual std::list< Double_t > * plotSamplingHint(RooAbsRealLValue &, Double_t, Double_t) const
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
 
virtual CacheMode canNodeBeCached() const
 
virtual Bool_t checkObservables(const RooArgSet *nset) const
Overloadable function in which derived classes can implement consistency checks of the variables.
 
Double_t analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
 
virtual void setCacheAndTrackHints(RooArgSet &)
 
void printMetaArgs(std::ostream &os) const
 
RooRealVar represents a variable that can be changed from the outside.
 
void setMin(const char *name, Double_t value)
Set minimum of name range to given value.
 
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
 
void setError(Double_t value)
 
void setMax(const char *name, Double_t value)
Set maximum of name range to given value.
 
Double_t getError() const
 
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
 
void setBinning(const RooAbsBinning &binning, const char *name=0)
Add given binning under name 'name' with this variable.
 
virtual void setVal(Double_t value)
Set value of variable to 'value'.
 
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
 
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::addOwned() method insert object into owning set and registers object as server ...
 
RooStringVar is a RooAbsArg implementing string values.
 
const char * getVal() const
 
Class to manage histogram axis.
 
const char * GetBinLabel(Int_t bin) const
Return label for bin.
 
TClass instances represent classes, structs and namespaces in the ROOT type system.
 
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
 
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
 
Double_t GetCondition() const
 
Bool_t Invert(TMatrixD &inv)
For a matrix A(m,m), its inverse A_inv is defined as A * A_inv = A_inv * A = unit (m x m) Ainv is ret...
 
Describe directory structure in memory.
 
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
 
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
 
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
 
void Close(Option_t *option="") override
Close a file.
 
A TFolder object is a collection of objects and folders.
 
TCollection * GetListOfFolders() const
 
virtual void SetOwner(Bool_t owner=kTRUE)
Set ownership.
 
TH1 is the base class of all histogram classes in ROOT.
 
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
 
virtual Int_t GetNbinsX() const
 
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
 
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
 
virtual Double_t GetBinLowEdge(Int_t bin) const
Return bin lower edge for 1D histogram.
 
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
 
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width for 1D histogram.
 
virtual TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
 
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
 
virtual const char * GetTitle() const
Returns title of object.
 
virtual const char * GetName() const
Returns name of object.
 
Mother of all ROOT objects.
 
virtual const char * GetName() const
Returns name of object.
 
virtual const char * ClassName() const
Returns name of class to which the object belongs.
 
Class used by TMap to store (key,value) pairs.
 
Named parameter, streamable and storable.
 
const AParamType & GetVal() const
 
Random number generator class based on M.
 
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
 
const char * Data() const
 
std::string_view View() const
 
TString & Append(const char *cs)
 
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
 
std::string observableName
 
std::vector< std::string > folderNames
 
std::vector< std::vector< const char * > > nonInterfering