86#define NaN std::numeric_limits<double>::quiet_NaN()
95template <
typename Test,
template <
typename...>
class Ref>
99template <
template <
typename...>
class Ref,
typename... Args>
110template <
class MatrixT>
111inline size_t size(
const MatrixT &matrix);
121template <
class MatrixT>
124 if (!stream.good()) {
127 for (
size_t i = 0; i <
size(matrix); ++i) {
128 for (
size_t j = 0; j <
size(matrix); ++j) {
130 stream << std::setprecision(RooFit::SuperFloatPrecision::digits10) << matrix(i, j) <<
"\t";
132 stream << matrix(i, j) <<
"\t";
142template <
class MatrixT>
145 std::ofstream of(fname);
147 cerr <<
"unable to read file '" << fname <<
"'!" << std::endl;
156#pragma GCC diagnostic push
157#pragma GCC diagnostic ignored "-Wshadow"
158#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
159#include <boost/numeric/ublas/io.hpp>
160#include <boost/numeric/ublas/lu.hpp>
161#include <boost/numeric/ublas/matrix.hpp>
162#include <boost/numeric/ublas/matrix_expression.hpp>
163#include <boost/numeric/ublas/symmetric.hpp>
164#include <boost/numeric/ublas/triangular.hpp>
165#include <boost/operators.hpp>
167#pragma GCC diagnostic pop
169typedef boost::numeric::ublas::matrix<RooFit::SuperFloat>
Matrix;
176 for (
size_t i = 0; i < mat.size1(); ++i) {
177 for (
size_t j = 0; j < mat.size2(); ++j) {
178 std::cout << std::setprecision(RooFit::SuperFloatPrecision::digits10) << mat(i, j) <<
" ,\t";
180 std::cout << std::endl;
188inline size_t size<Matrix>(
const Matrix &matrix)
190 return matrix.size1();
198 return boost::numeric::ublas::identity_matrix<RooFit::SuperFloat>(
n);
208 for (
size_t i = 0; i <
n; ++i) {
209 for (
size_t j = 0; j <
n; ++j) {
210 mat(i, j) =
double(in(i, j));
223 for (
size_t i = 0; i <
n; ++i) {
224 for (
size_t j = 0; j <
n; ++j) {
225 mat(i, j) =
double(in(i, j));
237 return prod(
m, otherM);
245 boost::numeric::ublas::permutation_matrix<size_t> pm(
size(matrix));
249 int res = lu_factorize(lu, pm);
251 std::stringstream ss;
253 cxcoutP(Eval) << ss.str << std::endl;
256 lu_substitute(lu, pm, inverse);
257 }
catch (boost::numeric::ublas::internal_logic &error) {
311 bool status = lu.
Invert(inverse);
314 std::cerr <<
" matrix is not invertible!" << std::endl;
317 const size_t n =
size(inverse);
319 for (
size_t i = 0; i <
n; ++i)
320 for (
size_t j = 0; j <
n; ++j)
321 if (std::abs(inverse(i, j)) < 1
e-9)
338typedef std::vector<std::vector<bool>> FeynmanDiagram;
339typedef std::vector<std::vector<int>> MorphFuncPattern;
340typedef std::map<int, std::unique_ptr<RooAbsReal>> FormulaList;
348 retval.ReplaceAll(
"/",
"_");
349 retval.ReplaceAll(
"^",
"");
350 retval.ReplaceAll(
"*",
"X");
351 retval.ReplaceAll(
"[",
"");
352 retval.ReplaceAll(
"]",
"");
360std::string concatNames(
const List &
c,
const char *sep)
362 std::stringstream ss;
367 ss << itr->GetName();
377template <
class A,
class B>
378inline void assignElement(A &
a,
const B &
b)
380 a =
static_cast<A
>(
b);
385template <
class MatrixT>
386inline MatrixT readMatrixFromStreamT(std::istream &stream)
388 std::vector<std::vector<RooFit::SuperFloat>> matrix;
389 std::vector<RooFit::SuperFloat>
line;
390 while (!stream.eof()) {
391 if (stream.peek() ==
'\n') {
399 while (stream.peek() ==
' ' || stream.peek() ==
'\t') {
402 if (stream.peek() ==
'\n') {
403 matrix.push_back(
line);
407 MatrixT retval(matrix.size(), matrix.size());
408 for (
size_t i = 0; i < matrix.size(); ++i) {
409 if (matrix[i].
size() != matrix.size()) {
410 std::cerr <<
"matrix read from stream doesn't seem to be square!" << std::endl;
412 for (
size_t j = 0; j < matrix[i].size(); ++j) {
413 assignElement(retval(i, j), matrix[i][j]);
422template <
class MatrixT>
423inline MatrixT readMatrixFromFileT(
const char *fname)
425 std::ifstream in(fname);
427 std::cerr <<
"unable to read file '" << fname <<
"'!" << std::endl;
429 MatrixT mat = readMatrixFromStreamT<MatrixT>(in);
438void readValues(std::map<const std::string, T> &myMap,
TH1 *h_pc)
442 for (
int ibx = 1; ibx <= h_pc->
GetNbinsX(); ++ibx) {
447 if (!s_coup.empty()) {
448 myMap[s_coup] =
T(coup_val);
457void setOwnerRecursive(
TFolder *theFolder)
462 for (
auto *subdir : *subdirs) {
463 auto thisfolder =
dynamic_cast<TFolder *
>(subdir);
466 setOwnerRecursive(thisfolder);
479std::unique_ptr<TFolder> readOwningFolderFromFile(
TDirectory *inFile,
const std::string &folderName)
481 std::unique_ptr<TFolder> theFolder(inFile->
Get<
TFolder>(folderName.c_str()));
483 std::cerr <<
"Error: unable to access data from folder '" << folderName <<
"' from file '" << inFile->
GetName()
484 <<
"'!" << std::endl;
487 setOwnerRecursive(theFolder.get());
500template <
class AObjType>
501std::unique_ptr<AObjType> loadFromFileResidentFolder(
TDirectory *inFile,
const std::string &folderName,
502 const std::string &objName,
bool notFoundError =
true)
504 auto folder = readOwningFolderFromFile(inFile, folderName);
508 AObjType *loadedObject =
dynamic_cast<AObjType *
>(folder->FindObject(objName.c_str()));
511 std::stringstream errstr;
512 errstr <<
"Error: unable to retrieve object '" << objName <<
"' from folder '" << folderName
513 <<
"'. contents are:";
514 TIter next(folder->GetListOfFolders()->begin());
519 std::cerr << errstr.str() << std::endl;
525 return std::unique_ptr<AObjType>{
static_cast<AObjType *
>(loadedObject->Clone())};
532void readValues(std::map<const std::string, T> &myMap,
TDirectory *
file,
const std::string &
name,
533 const std::string &key =
"param_card",
bool notFoundError =
true)
535 auto h_pc = loadFromFileResidentFolder<TH1F>(
file,
name, key, notFoundError);
536 readValues(myMap, h_pc.get());
545void readValues(std::map<
const std::string, std::map<const std::string, T>> &inputParameters,
TDirectory *
f,
546 const std::vector<std::string> &names,
const std::string &key =
"param_card",
bool notFoundError =
true)
548 inputParameters.clear();
551 for (
size_t i = 0; i < names.size(); i++) {
552 const std::string
name(names[i]);
554 readValues(inputParameters[
name],
f,
name, key, notFoundError);
572 std::cerr <<
"could not open file '" <<
filename <<
"'!" << std::endl;
594inline void extractServers(
const RooAbsArg &coupling,
T2 &operators)
597 for (
const auto server : coupling.servers()) {
598 extractServers(*server, operators);
602 operators.add(coupling);
609template <class T1, class T2, typename std::enable_if<!is_specialization<T1, std::vector>::value,
T1>
::type * =
nullptr>
610inline void extractOperators(
const T1 &couplings,
T2 &operators)
614 for (
auto itr : couplings) {
615 extractServers(*itr, operators);
622template <class T1, class T2, typename std::enable_if<is_specialization<T1, std::vector>::value,
T1>
::type * =
nullptr>
623inline void extractOperators(
const T1 &
vec,
T2 &operators)
625 for (
const auto &
v :
vec) {
626 extractOperators(
v, operators);
633template <
class T1,
class T2>
634inline void extractCouplings(
const T1 &inCouplings,
T2 &outCouplings)
636 for (
auto itr : inCouplings) {
637 if (!outCouplings.find(itr->GetName())) {
640 outCouplings.add(*itr);
649inline bool setParam(
RooRealVar *
p,
double val,
bool force)
652 if (val >
p->getMax()) {
656 std::cerr <<
": parameter " <<
p->
GetName() <<
" out of bounds: " << val <<
" > " <<
p->getMax() << std::endl;
659 }
else if (val < p->getMin()) {
663 std::cerr <<
": parameter " <<
p->
GetName() <<
" out of bounds: " << val <<
" < " <<
p->getMin() << std::endl;
676template <
class T1,
class T2>
677inline bool setParams(
const T2 &args,
T1 val)
679 for (
auto itr : args) {
683 setParam(param, val,
true);
692template <
class T1,
class T2>
694setParams(
const std::map<const std::string, T1> &point,
const T2 &args,
bool force =
false,
T1 defaultVal = 0)
697 for (
auto itr : args) {
701 ok = setParam(param, defaultVal, force) && ok;
704 for (
auto paramit : point) {
706 const std::string param(paramit.first);
712 ok = setParam(
p, paramit.second, force) && ok;
722inline bool setParams(
TH1 *hist,
const T &args,
bool force =
false)
726 for (
auto itr : args) {
730 ok = setParam(param, 0., force) && ok;
735 for (
int i = 1; i <= ax->
GetNbins(); ++i) {
753 for (
auto itr : parameters) {
770 bool binningOK =
false;
771 for (
auto sampleit : inputParameters) {
772 const std::string sample(sampleit.first);
773 auto hist = loadFromFileResidentFolder<TH1>(
file, sample, varname,
true);
781 auto it = list_hf.find(sample);
782 if (it != list_hf.end()) {
794 std::vector<double> bins;
795 for (
int i = 1; i <
n + 1; ++i) {
803 TString histname = makeValidName(
Form(
"dh_%s_%s", sample.c_str(),
name));
804 TString funcname = makeValidName(
Form(
"phys_%s_%s", sample.c_str(),
name));
808 auto dh = std::make_unique<RooDataHist>(histname, histname, vars, hist.get());
810 auto hf = std::make_unique<RooHistFunc>(funcname, funcname, var, std::move(dh));
812 list_hf[sample] = idx;
823void collectRooAbsReal(
const char * ,
TDirectory *
file, std::map<std::string, int> &list_hf,
824 RooArgList &physics,
const std::string &varname,
827 for (
auto sampleit : inputParameters) {
828 const std::string sample(sampleit.first);
829 auto obj = loadFromFileResidentFolder<RooAbsReal>(
file, sample, varname,
true);
832 auto it = list_hf.find(sample);
833 if (it == list_hf.end()) {
835 list_hf[sample] = idx;
849 for (
auto sampleit : inputParameters) {
850 const std::string sample(sampleit.first);
851 auto obj = loadFromFileResidentFolder<TObject>(
file, sample, varname,
false);
858 TPair *pair =
dynamic_cast<TPair *
>(obj.get());
864 std::stringstream errstr;
865 errstr <<
"Error: unable to retrieve cross section '" << varname <<
"' from folder '" << sample;
869 auto it = list_xs.find(sample.c_str());
871 if (it != list_xs.end()) {
875 std::string objname =
Form(
"phys_%s_%s",
name, sample.c_str());
876 auto xsOwner = std::make_unique<RooRealVar>(objname.c_str(), objname.c_str(), xsection->
GetVal());
880 list_xs[sample] = idx;
881 physics.
addOwned(std::move(xsOwner));
882 assert(physics.
at(idx) == xs);
894void collectCrosssectionsTPair(
const char *
name,
TDirectory *
file, std::map<std::string, int> &list_xs,
895 RooArgList &physics,
const std::string &varname,
const std::string &basefolder,
898 auto pair = loadFromFileResidentFolder<TPair>(
file, basefolder, varname,
false);
902 collectCrosssections<double>(
name,
file, list_xs, physics, varname, inputParameters);
904 collectCrosssections<float>(
name,
file, list_xs, physics, varname, inputParameters);
906 std::cerr <<
"cannot morph objects of class 'TPair' if parameter is not "
920void collectPolynomialsHelper(
const FeynmanDiagram &diagram, MorphFuncPattern &morphfunc, std::vector<int> &term,
921 int vertexid,
bool first)
924 for (
size_t i = 0; i < diagram[vertexid - 1].size(); ++i) {
925 if (!diagram[vertexid - 1][i])
927 std::vector<int> newterm(term);
930 ::collectPolynomialsHelper(diagram, morphfunc, newterm, vertexid,
false);
932 ::collectPolynomialsHelper(diagram, morphfunc, newterm, vertexid - 1,
true);
937 for (
size_t i = 0; i < morphfunc.size(); ++i) {
938 bool thisfound =
true;
939 for (
size_t j = 0; j < morphfunc[i].size(); ++j) {
940 if (morphfunc[i][j] != term[j]) {
951 morphfunc.push_back(term);
959void collectPolynomials(MorphFuncPattern &morphfunc,
const FeynmanDiagram &diagram)
961 int nvtx(diagram.size());
962 std::vector<int> term(diagram[0].
size(), 0);
964 ::collectPolynomialsHelper(diagram, morphfunc, term, nvtx,
true);
971inline void fillFeynmanDiagram(FeynmanDiagram &diagram,
const std::vector<List *> &vertices,
RooArgList &couplings)
973 const int ncouplings = couplings.
getSize();
975 for (
auto const &
vertex : vertices) {
976 std::vector<bool> vertexCouplings(ncouplings,
false);
979 for (
auto citr : couplings) {
983 std::cerr <<
"encountered invalid list of couplings in vertex!" << std::endl;
987 vertexCouplings[idx] =
true;
990 diagram.push_back(vertexCouplings);
997template <
class MatrixT,
class T1,
class T2>
1001 const size_t dim = inputParameters.size();
1002 MatrixT matrix(dim, dim);
1004 for (
auto sampleit : inputParameters) {
1005 const std::string sample(sampleit.first);
1007 if (!setParams<double>(sampleit.second, args,
true, 0)) {
1008 std::cout <<
"unable to set parameters for sample " << sample <<
"!" << std::endl;
1010 auto flagit = flagValues.find(sample);
1011 if (flagit != flagValues.end() && !setParams<int>(flagit->second, flags,
true, 1)) {
1012 std::cout <<
"unable to set parameters for sample " << sample <<
"!" << std::endl;
1016 for (
auto const &formula : formulas) {
1017 if (!formula.second) {
1018 std::cerr <<
"Error: invalid formula encountered!" << std::endl;
1020 matrix(row, col) = formula.second->getVal();
1033 if (inputParameters.size() != formulas.size()) {
1034 std::stringstream ss;
1035 ss <<
"matrix is not square, consistency check failed: " << inputParameters.size() <<
" samples, "
1036 << formulas.size() <<
" expressions:" << std::endl;
1037 ss <<
"formulas: " << std::endl;
1038 for (
auto const &formula : formulas) {
1039 ss << formula.second->GetTitle() << std::endl;
1041 ss <<
"samples: " << std::endl;
1042 for (
auto sample : inputParameters) {
1043 ss << sample.first << std::endl;
1045 std::cerr << ss.str() << std::endl;
1052inline void inverseSanity(
const Matrix &matrix,
const Matrix &inverse,
double &unityDeviation,
double &largestWeight)
1054 Matrix unity(inverse * matrix);
1056 unityDeviation = 0.;
1058 const size_t dim =
size(unity);
1059 for (
size_t i = 0; i < dim; ++i) {
1060 for (
size_t j = 0; j < dim; ++j) {
1061 if (inverse(i, j) > largestWeight) {
1062 largestWeight = (
double)inverse(i, j);
1064 if (std::abs(unity(i, j) -
static_cast<int>(i == j)) > unityDeviation) {
1065 unityDeviation = std::abs((
double)unity(i, j)) -
static_cast<int>(i == j);
1073template <
class List>
1076 for (
auto sampleit : inputParameters) {
1077 const std::string sample(sampleit.first);
1078 RooAbsArg *arg = args.find(sample.c_str());
1080 std::cerr <<
"detected name conflict: cannot use sample '" << sample
1081 <<
"' - a parameter with the same name of type '" << arg->
ClassName() <<
"' is present in set '"
1082 << args.GetName() <<
"'!" << std::endl;
1094 const std::vector<std::vector<std::string>> &nonInterfering)
1103 const int ncouplings = couplings.
getSize();
1104 std::vector<bool> couplingsZero(ncouplings,
true);
1105 std::map<TString, bool> flagsZero;
1108 extractOperators(couplings, operators);
1109 size_t nOps = operators.
getSize();
1111 for (
auto sampleit : inputParameters) {
1112 const std::string sample(sampleit.first);
1113 if (!setParams(sampleit.second, operators,
true)) {
1114 std::cerr <<
"unable to set parameters for sample '" << sample <<
"'!" << std::endl;
1117 if ((
int)nOps != (operators.
getSize())) {
1118 std::cerr <<
"internal error, number of operators inconsistent!" << std::endl;
1124 for (
auto itr1 : couplings) {
1126 if (obj0->
getVal() != 0) {
1127 couplingsZero[idx] =
false;
1133 for (
auto itr2 : flags) {
1134 auto obj1 =
dynamic_cast<RooAbsReal *
>(itr2);
1137 for (
auto sampleit : inputFlags) {
1138 const auto &flag = sampleit.second.find(obj1->GetName());
1139 if (flag != sampleit.second.end()) {
1140 if (flag->second == 0.)
1146 if (nZero > 0 && nNonZero == 0)
1147 flagsZero[obj1->GetName()] =
true;
1149 flagsZero[obj1->GetName()] =
false;
1152 FormulaList formulas;
1153 for (
size_t i = 0; i < morphfunc.size(); ++i) {
1155 bool isZero =
false;
1158 for (
const auto &
group : nonInterfering) {
1159 int nInterferingOperators = 0;
1160 for (
size_t j = 0; j < morphfunc[i].size(); ++j) {
1161 if (morphfunc[i][j] % 2 == 0)
1165 nInterferingOperators++;
1168 if (nInterferingOperators > 1) {
1170 reason =
"blacklisted interference term!";
1176 for (
size_t j = 0; j < morphfunc[i].size(); ++j) {
1177 const int exponent = morphfunc[i][j];
1181 for (
int k = 0; k < exponent; ++k) {
1190 reason =
"coupling " +
cname +
" was listed as leading-order-only";
1193 if (!isZero && couplingsZero[j]) {
1195 reason =
"coupling " +
cname +
" is zero!";
1200 bool removedByFlag =
false;
1202 for (
auto itr : flags) {
1206 TString sval(obj->getStringAttribute(
"NewPhysics"));
1207 int val = atoi(sval);
1209 if (flagsZero.find(obj->GetName()) != flagsZero.end() && flagsZero.at(obj->GetName())) {
1210 removedByFlag =
true;
1211 reason =
Form(
"flag %s is zero", obj->GetName());
1218 if (!isZero && !removedByFlag) {
1220 const auto name = std::string(mfname) +
"_pol" + std::to_string(i);
1221 formulas[i] = std::make_unique<RooProduct>(
name.c_str(), ::concatNames(ss,
" * ").c_str(), ss);
1232 const std::vector<std::vector<RooArgList *>> &diagrams,
RooArgList &couplings,
1233 const RooArgList &flags,
const std::vector<std::vector<std::string>> &nonInterfering)
1235 MorphFuncPattern morphfuncpattern;
1237 for (
const auto &vertices : diagrams) {
1239 ::fillFeynmanDiagram(
d, vertices, couplings);
1240 ::collectPolynomials(morphfuncpattern,
d);
1242 FormulaList retval = buildFormulas(
name, inputs, inputFlags, morphfuncpattern, couplings, flags, nonInterfering);
1243 if (retval.empty()) {
1244 std::stringstream errorMsgStream;
1246 <<
"no formulas are non-zero, check if any if your couplings is floating and missing from your param_cards!"
1248 const auto errorMsg = errorMsgStream.str();
1249 throw std::runtime_error(errorMsg);
1251 checkMatrix(inputs, retval);
1260 FormulaList &formulas,
const Matrix &inverse)
1264 for (
auto sampleit : inputParameters) {
1265 const std::string sample(sampleit.first);
1266 std::stringstream title;
1267 TString name_full(makeValidName(sample.c_str()));
1269 name_full.Append(
"_");
1270 name_full.Append(fname);
1271 name_full.Prepend(
"w_");
1276 auto sampleformula = std::make_unique<RooLinearCombination>(name_full.Data());
1277 for (
auto const &formulait : formulas) {
1279 sampleformula->add(val, formulait.second.get());
1282 weights.addOwned(std::move(sampleformula));
1287inline std::map<std::string, std::string>
1292 std::map<std::string, std::string> weights;
1293 for (
auto sampleit : inputParameters) {
1294 const std::string sample(sampleit.first);
1295 std::stringstream str;
1298 for (
auto const &formulait : formulas) {
1299 double val(inverse(formulaidx, sampleidx));
1301 if (formulaidx > 0 && val > 0)
1303 str << val <<
"*(" << formulait.second->GetTitle() <<
")";
1307 weights[sample] = str.str();
1342 args.
add(*(it.second));
1357 const std::vector<std::vector<RooListProxy *>> &diagramProxyList,
1358 const std::vector<std::vector<std::string>> &nonInterfering,
const RooArgList &flags)
1361 std::vector<std::vector<RooArgList *>> diagrams;
1362 for (
const auto &diagram : diagramProxyList) {
1363 diagrams.emplace_back();
1366 diagrams.back().emplace_back(
vertex);
1370 _formulas = ::createFormulas(funcname, inputParameters, inputFlags, diagrams,
_couplings, flags, nonInterfering);
1375 template <
class List>
1381 Matrix matrix(buildMatrixT<Matrix>(inputParameters,
_formulas, operators, inputFlags, flags));
1382 if (
size(matrix) < 1) {
1383 std::cerr <<
"input matrix is empty, please provide suitable input samples!" << std::endl;
1388 double unityDeviation, largestWeight;
1389 inverseSanity(matrix, inverse, unityDeviation, largestWeight);
1395 oocxcoutW((
TObject *)0, Eval) <<
"Warning: The matrix inversion seems to be unstable. This can "
1396 "be a result to input samples that are not sufficiently "
1397 "different to provide any morphing power."
1399 }
else if (weightwarning) {
1400 oocxcoutW((
TObject *)0, Eval) <<
"Warning: Some weights are excessively large. This can be a "
1401 "result to input samples that are not sufficiently different to "
1402 "provide any morphing power."
1406 "encoded in your samples to cross-check:"
1408 for (
auto sampleit : inputParameters) {
1409 const std::string sample(sampleit.first);
1412 setParams(sampleit.second, operators,
true);
1439 const std::map<std::string, int> &storage,
const RooArgList &physics,
1443 std::cerr <<
"invalid bin width given!" << std::endl;
1447 std::cerr <<
"invalid observable given!" << std::endl;
1461 for (
auto sampleit : inputParameters) {
1463 TString prodname(makeValidName(sampleit.first.c_str()));
1468 std::cerr <<
"unable to access physics object for " << prodname << std::endl;
1475 std::cerr <<
"unable to access weight object for " << prodname << std::endl;
1482 allowNegativeYields =
true;
1483 auto prod = std::make_unique<RooProduct>(prodname, prodname, prodElems);
1484 if (!allowNegativeYields) {
1485 auto maxname = std::string(prodname) +
"_max0";
1488 auto max = std::make_unique<RooFormulaVar>(maxname.c_str(),
"max(0," + prodname +
")", prodset);
1489 max->addOwnedComponents(std::move(prod));
1490 sumElements.
addOwned(std::move(max));
1492 sumElements.
addOwned(std::move(prod));
1494 scaleElements.
add(*(binWidth));
1499 _sumFunc = make_unique<RooRealSumFunc>(
Form(
"%s_morphfunc",
name),
name, sumElements, scaleElements);
1502 std::cerr <<
"unable to access observable" << std::endl;
1503 _sumFunc.get()->addServer(*observable);
1505 std::cerr <<
"unable to access bin width" << std::endl;
1506 _sumFunc.get()->addServer(*binWidth);
1508 std::cerr <<
"no operators listed" << std::endl;
1509 _sumFunc.get()->addServerList(operators);
1511 std::cerr <<
"unable to access weight objects" << std::endl;
1512 _sumFunc.get()->addOwnedComponents(std::move(sumElements));
1513 _sumFunc.get()->addServerList(sumElements);
1514 _sumFunc.get()->addServerList(scaleElements);
1517 std::cout.precision(std::numeric_limits<double>::digits);
1534 if (obsName.empty()) {
1535 std::cerr <<
"Matrix inversion succeeded, but no observable was "
1536 "supplied. quitting..."
1544 setParams(func->
_flags, 1);
1548 setParams(func->
_flags, 1);
1571 setParams(func->
_flags, 1);
1575 setParams(func->
_flags, 1);
1605 return readMatrixFromFileT<TMatrixD>(fname);
1613 return readMatrixFromStreamT<TMatrixD>(stream);
1623 bool obsExists(
false);
1644 TH1 *hist = (
TH1 *)(inputExample);
1647 obs = obsOwner.get();
1651 auto obsOwner = std::make_unique<RooRealVar>(obsname, obsname, 0, 1);
1652 obs = obsOwner.get();
1658 if (strcmp(obsname, obs->
GetName()) != 0) {
1660 <<
" does not match expected name " << obsname << std::endl;
1665 auto binWidth = std::make_unique<RooRealVar>(sbw.
Data(), sbw.
Data(), 1.);
1667 binWidth->setVal(bw);
1668 binWidth->setConstant(
true);
1687 const size_t n(
size(cache->_inverse));
1689 const std::string sample(sampleit.first);
1692 if (!sampleformula) {
1693 coutE(ObjectHandling) <<
Form(
"unable to access formula for sample '%s'!", sample.c_str()) << std::endl;
1696 cxcoutP(ObjectHandling) <<
"updating formula for sample '" << sample <<
"'" << std::endl;
1697 for (
size_t formulaidx = 0; formulaidx <
n; ++formulaidx) {
1702 if (std::isnan(val)) {
1704 coutE(ObjectHandling) <<
"refusing to propagate NaN!" << std::endl;
1706 cxcoutP(ObjectHandling) <<
" " << formulaidx <<
":" << sampleformula->
getCoefficient(formulaidx) <<
" -> "
1707 << val << std::endl;
1736 std::string obsName;
1748 cxcoutP(InputArguments) <<
"initializing physics inputs from file " <<
file->GetName() <<
" with object name(s) '"
1749 << obsName <<
"'" << std::endl;
1751 auto obj = loadFromFileResidentFolder<TObject>(
file, folderNames.front(), obsName,
true);
1753 std::cerr <<
"unable to locate object '" << obsName <<
"' in folder '" << folderNames.front() <<
"'!"
1757 std::string classname = obj->ClassName();
1761 if (classname.find(
"TH1") != std::string::npos) {
1764 }
else if (classname.find(
"RooHistFunc") != std::string::npos ||
1765 classname.find(
"RooParamHistFunc") != std::string::npos ||
1766 classname.find(
"PiecewiseInterpolation") != std::string::npos) {
1768 }
else if (classname.find(
"TParameter<double>") != std::string::npos) {
1770 }
else if (classname.find(
"TParameter<float>") != std::string::npos) {
1772 }
else if (classname.find(
"TPair") != std::string::npos) {
1776 std::cerr <<
"cannot morph objects of class '" <<
mode->GetName() <<
"'!" << std::endl;
1787 std::cout << param.first <<
" = " << param.second;
1789 std::cout <<
" (const)";
1790 std::cout << std::endl;
1802 std::cout << folder << std::endl;
1824 _operators(
"operators",
"set of operators", this),
_observables(
"observables",
"morphing observables", this),
1842 std::vector<RooListProxy *> vertices;
1844 vertices.push_back(
new RooListProxy(
"!couplings",
"set of couplings in the vertex",
this,
true,
false));
1856 std::vector<RooListProxy *> vertices;
1858 cxcoutP(InputArguments) <<
"prod/dec couplings provided" << std::endl;
1862 new RooListProxy(
"!production",
"set of couplings in the production vertex",
this,
true,
false));
1863 vertices.push_back(
new RooListProxy(
"!decay",
"set of couplings in the decay vertex",
this,
true,
false));
1869 cxcoutP(InputArguments) <<
"adding non-own operators" << std::endl;
1884 std::stringstream
name;
1885 name <<
"noInteference";
1886 for (
auto c : nonInterfering) {
1890 for (
auto c : nonInterfering) {
1901 for (
size_t i = 0; i < nonInterfering.size(); ++i) {
1914 coutE(InputArguments) <<
"unable to open file '" <<
filename <<
"'!" << std::endl;
1950 :
RooAbsReal(other,
name), _cacheMgr(other._cacheMgr, this), _scale(other._scale), _sampleMap(other._sampleMap),
1951 _physics(other._physics.GetName(), this, other._physics),
1952 _operators(other._operators.GetName(), this, other._operators),
1953 _observables(other._observables.GetName(), this, other._observables),
1954 _binWidths(other._binWidths.GetName(), this, other._binWidths), _flags{other._flags.GetName(), this, other._flags},
1955 _config(other._config)
1957 for (
size_t j = 0; j < other.
_diagrams.size(); ++j) {
1958 std::vector<RooListProxy *> diagram;
1959 for (
size_t i = 0; i < other.
_diagrams[j].size(); ++i) {
1961 diagram.push_back(list);
1988 : _cacheMgr(this, 10, true, true), _operators(
"operators",
"set of operators", this, true, false),
1989 _observables(
"observable",
"morphing observable", this, true, false),
1990 _binWidths(
"binWidths",
"set of bin width objects", this, true, false)
2014 FeynmanDiagram diagram;
2015 std::vector<bool> prod;
2016 std::vector<bool> dec;
2017 for (
int i = 0; i < nboth; ++i) {
2018 prod.push_back(
true);
2019 dec.push_back(
true);
2021 for (
int i = 0; i < nprod; ++i) {
2022 prod.push_back(
true);
2023 dec.push_back(
false);
2025 for (
int i = 0; i < ndec; ++i) {
2026 prod.push_back(
false);
2027 dec.push_back(
true);
2029 diagram.push_back(prod);
2030 diagram.push_back(dec);
2031 MorphFuncPattern morphfuncpattern;
2032 ::collectPolynomials(morphfuncpattern, diagram);
2033 return morphfuncpattern.size();
2042 for (
auto vertex : vertices) {
2043 extractOperators(*
vertex, operators);
2044 extractCouplings(*
vertex, couplings);
2046 FeynmanDiagram diagram;
2047 ::fillFeynmanDiagram(diagram, vertices, couplings);
2048 MorphFuncPattern morphfuncpattern;
2049 ::collectPolynomials(morphfuncpattern, diagram);
2050 return morphfuncpattern.size();
2056std::map<std::string, std::string>
2058 const std::vector<std::vector<std::string>> &vertices_str)
2060 std::stack<RooArgList> ownedVertices;
2061 std::vector<RooArgList *> vertices;
2063 for (
const auto &vtx : vertices_str) {
2064 ownedVertices.emplace();
2065 auto &
vertex = ownedVertices.top();
2066 for (
const auto &
c : vtx) {
2069 auto couplingOwner = std::make_unique<RooRealVar>(
c.c_str(),
c.c_str(), 1., 0., 10.);
2070 coupling = couplingOwner.get();
2071 couplings.
addOwned(std::move(couplingOwner));
2075 vertices.push_back(&
vertex);
2084std::map<std::string, std::string>
2086 const std::vector<RooArgList *> &vertices,
RooArgList &couplings)
2094std::map<std::string, std::string>
2096 const std::vector<RooArgList *> &vertices,
RooArgList &couplings,
2098 const std::vector<std::vector<std::string>> &nonInterfering)
2100 FormulaList formulas = ::createFormulas(
"", inputs, flagValues, {vertices}, couplings, flags, nonInterfering);
2102 extractOperators(couplings, operators);
2103 Matrix matrix(::buildMatrixT<Matrix>(inputs, formulas, operators, flagValues, flags));
2104 if (
size(matrix) < 1) {
2105 std::cerr <<
"input matrix is empty, please provide suitable input samples!" << std::endl;
2109 auto retval = buildSampleWeightStrings(inputs, formulas, inverse);
2117 const std::vector<RooArgList *> &vertices,
RooArgList &couplings,
2120 const std::vector<std::vector<std::string>> &nonInterfering)
2122 FormulaList formulas = ::createFormulas(
"", inputs, flagValues, {vertices}, couplings, flags, nonInterfering);
2124 extractOperators(couplings, operators);
2125 Matrix matrix(::buildMatrixT<Matrix>(inputs, formulas, operators, flagValues, flags));
2126 if (
size(matrix) < 1) {
2127 std::cerr <<
"input matrix is empty, please provide suitable input samples!" << std::endl;
2132 ::buildSampleWeights(retval, (
const char *)
nullptr , inputs, formulas, inverse);
2140 const std::vector<RooArgList *> &vertices,
RooArgList &couplings)
2155 coutE(Eval) <<
"unable to retrieve morphing function" << std::endl;
2158 std::unique_ptr<RooArgSet> args{mf->getComponents()};
2163 for (
auto itr : *args) {
2188 auto wname = std::string(
"w_") +
name +
"_" + this->
GetName();
2189 return dynamic_cast<RooAbsReal *
>(cache->_weights.find(wname.c_str()));
2207 auto weightName = std::string(
"w_") + sample.first +
"_" + this->
GetName();
2208 auto weight =
static_cast<RooAbsReal *
>(cache->_weights.find(weightName.c_str()));
2225 double val = obj->
getVal();
2228 double variation =
r.Gaus(1, z);
2229 obj->
setVal(val * variation);
2244 coutE(InputArguments) <<
"unable to open file '" <<
filename <<
"'!" << std::endl;
2270 cache->_inverse =
m;
2273 coutE(InputArguments) <<
"unable to open file '" <<
filename <<
"'!" << std::endl;
2288 coutE(Caching) <<
"unable to create cache!" << std::endl;
2306 coutE(Caching) <<
"unable to create cache!" << std::endl;
2330 cxcoutP(Caching) <<
"creating cache from getCache function for " <<
this << std::endl;
2331 cxcoutP(Caching) <<
"current storage has size " <<
_sampleMap.size() << std::endl;
2336 coutE(Caching) <<
"unable to create cache!" << std::endl;
2360 if (value < param->getMin())
2484 auto paramhist = loadFromFileResidentFolder<TH1>(
file, foldername,
"param_card");
2485 setParams(paramhist.get(),
_operators,
false);
2495 const std::string
name(foldername);
2505 for (
auto itr : *list) {
2519 coutE(InputArguments) <<
"observable not available!" << std::endl;
2531 coutE(InputArguments) <<
"bin width not available!" << std::endl;
2550 auto mf = std::make_unique<RooRealSumFunc>(*(this->
getFunc()));
2553 const int nbins = observable->
getBins();
2557 std::unique_ptr<RooArgSet> args{mf->getComponents()};
2558 for (
int i = 0; i < nbins; ++i) {
2563 for (
auto itr : *args) {
2575 double weight = formula->
getVal();
2578 val += dhist.
weight() * weight;
2581 hist->
SetBinError(i + 1, correlateErrors ? unc : sqrt(unc2));
2583 return hist.release();
2592 auto mf = std::make_unique<RooRealSumFunc>(*(this->
getFunc()));
2594 coutE(InputArguments) <<
"unable to retrieve morphing function" << std::endl;
2595 std::unique_ptr<RooArgSet> args{mf->getComponents()};
2596 for (
auto itr : *args) {
2598 if (prod->
getVal() != 0) {
2612 std::string pname(paramname);
2614 bool isUsed =
false;
2616 double thisval = sample.second.at(pname);
2617 if (thisval != val) {
2633 std::string
cname(couplname);
2640 bool isUsed =
false;
2643 double thisval = coupling->
getVal();
2644 if (thisval != val) {
2669 return cache->_formulas.size();
2677 auto mf = std::make_unique<RooRealSumFunc>(*(this->
getFunc()));
2679 std::cerr <<
"Error: unable to retrieve morphing function" << std::endl;
2682 std::unique_ptr<RooArgSet> args{mf->getComponents()};
2683 for (
auto *formula : dynamic_range_cast<RooAbsReal*>(*args)) {
2687 name.Prepend(
"phys_");
2688 if (!args->find(
name.Data())) {
2691 double val = formula->getVal();
2693 std::cout << formula->GetName() <<
": " << val <<
" = " << formula->GetTitle() << std::endl;
2713 return &(cache->_couplings);
2727 double val = var->
getVal();
2728 couplings[
name] = val;
2755 auto func = std::make_unique<RooRealSumFunc>(*(cache->_sumFunc));
2758 return std::make_unique<RooWrapperPdf>(
Form(
"pdf_%s", func->GetName()),
Form(
"pdf of %s", func->GetTitle()), *func);
2767 return cache->_sumFunc.get();
2784 return this->
createPdf()->expectedEvents(nset);
2794 return this->
createPdf()->expectedEvents(set);
2803 return createPdf()->expectedEvents(&nset);
2816 auto weightName = std::string(
"w_") + sample.first +
"_" + this->
GetName();
2817 auto weight =
static_cast<RooAbsReal *
>(cache->_weights.find(weightName.c_str()));
2819 coutE(InputArguments) <<
"unable to find object " + weightName << std::endl;
2834 double w = weight->getVal();
2835 unc2 += newunc2 *
w *
w;
2862 for (
auto flag :
_flags) {
2876 for (
auto c : couplings) {
2877 std::cout <<
c.first <<
": " <<
c.second << std::endl;
2911 std::cerr <<
"unable to acquire in-built function!" << std::endl;
2943 const char *rangeName)
const
2987 coutE(Caching) <<
"unable to retrieve cache!" << std::endl;
2998 coutE(Caching) <<
"unable to retrieve cache!" << std::endl;
3011 coutE(Caching) <<
"unable to retrieve cache!" << std::endl;
3012 return cache->_condition;
3018std::unique_ptr<RooRatio>
3022 for (
auto it : nr) {
3025 for (
auto it : dr) {
3029 return make_unique<RooRatio>(
name, title, num, denom);
3037std::vector<std::string> asStringV(std::string
const &arg)
3039 std::vector<std::string> out;
3041 for (std::string &tok :
ROOT::
Split(arg,
",{}", true)) {
3042 if (tok[0] ==
'\'') {
3043 out.emplace_back(tok.substr(1, tok.size() - 2));
3045 throw std::runtime_error(
"Strings in factory expressions need to be in single quotes!");
3055 create(
RooFactoryWSTool &,
const char *typeName,
const char *instName, std::vector<std::string> args)
override;
3058std::string LMIFace::create(
RooFactoryWSTool &ft,
const char * ,
const char *instanceName,
3059 std::vector<std::string> args)
3062 const std::array<std::string, 4> funcArgs{{
"fileName",
"observableName",
"couplings",
"folders"}};
3063 std::map<string, string> mappedInputs;
3065 for (
unsigned int i = 1; i < args.size(); i++) {
3066 if (args[i].find(
"$fileName(") != 0 && args[i].find(
"$observableName(") != 0 &&
3067 args[i].find(
"$couplings(") != 0 && args[i].find(
"$folders(") != 0 && args[i].find(
"$NewPhysics(") != 0) {
3068 throw std::string(
Form(
"%s::create() ERROR: unknown token %s encountered", instanceName, args[i].c_str()));
3072 for (
unsigned int i = 0; i < args.size(); i++) {
3073 if (args[i].find(
"$NewPhysics(") == 0) {
3075 for (
const auto &subarg : subargs) {
3076 std::vector<std::string> parts =
ROOT::Split(subarg,
"=");
3077 if (parts.size() == 2) {
3078 ft.
ws().
arg(parts[0].c_str())->
setAttribute(
"NewPhysics", atoi(parts[1].c_str()));
3080 throw std::string(
Form(
"%s::create() ERROR: unknown token %s encountered, check input provided for %s",
3081 instanceName, subarg.c_str(), args[i].c_str()));
3085 if (subargs.size() == 1) {
3087 for (
auto const ¶m : funcArgs) {
3088 if (args[i].find(param) != string::npos)
3089 mappedInputs[param] = subargs[0];
3093 Form(
"Incorrect number of arguments in %s, have %d, expect 1", args[i].c_str(), (
Int_t)subargs.size()));
3098 config.
fileName = asStringV(mappedInputs[
"fileName"])[0];
3099 config.
observableName = asStringV(mappedInputs[
"observableName"])[0];
3100 config.
folderNames = asStringV(mappedInputs[
"folders"]);
3105 return instanceName;
RooCollectionProxy< RooArgList > RooListProxy
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
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
TMatrixT< Double_t > TMatrixD
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
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 Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
bool isConstant() const
Check if the "Constant" attribute is set.
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
virtual double * array() const =0
RooAbsCacheElement is the abstract base class for objects to be stored in RooAbsCache cache manager o...
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
RooAbsArg * first() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
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...
Int_t numBins(const char *rangeName=nullptr) const override
virtual Int_t getBins(const char *name=nullptr) const
Get number of bins of currently defined range.
void setConstant(bool value=true)
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
void setBin(Int_t ibin, const char *rangeName=nullptr) override
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
double 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,...
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=nullptr)
Setter function without integration set.
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=nullptr, const TNamed *isetRangeName=nullptr)
Getter function without integration set.
bool addOwned(RooAbsArg &var, bool silent=false) override
Overloaded RooCollection_t::addOwned() method insert object into owning set and registers object as s...
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...
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< std::vector< std::string > > &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
RooArgSet createWeights(const ParamMap &inputs, const std::vector< RooArgList * > &vertices, RooArgList &couplings, const FlagMap &inputFlags, const RooArgList &flags, const std::vector< std::vector< std::string > > &nonInterfering)
create only the weight formulas. static function for external usage.
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::vector< std::string > > _nonInterfering
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
void writeMatrixToStream(const TMatrixD &matrix, std::ostream &stream)
write a matrix to a stream
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
double getCondition() const
Retrieve the condition of the coefficient matrix.
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.
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Retrieve the matrix of coefficients.
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.
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Retrieve the mat.
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
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
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)
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.
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Retrieve bin boundaries if this distribution is binned in obs.
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooRealSumFunc to more intuitively reflect the contents of the ...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Variant of getAnalyticalIntegral that is also passed the normalization set that should be applied to ...
CacheMode canNodeBeCached() const override
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
bool isBinnedDistribution(const RooArgSet &obs) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
bool checkObservables(const RooArgSet *nset) const override
Overloadable function in which derived classes can implement consistency checks of the variables.
void setCacheAndTrackHints(RooArgSet &) override
std::list< double > * plotSamplingHint(RooAbsRealLValue &, double, double) const override
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
bool forceAnalyticalInt(const RooAbsArg &arg) const override
RooRealVar represents a variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
void setError(double value)
void setMin(const char *name, double value)
Set minimum of name range to given value.
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const override
Return binning definition with name.
void setBinning(const RooAbsBinning &binning, const char *name=nullptr)
Add given binning under name 'name' with this variable.
void setBins(Int_t nBins, const char *name=nullptr)
Create a uniform binning under name 'name' for this variable.
void setMax(const char *name, double value)
Set maximum of name range to given value.
bool import(const RooAbsArg &arg, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Import a RooAbsArg object, e.g.
RooAbsArg * arg(RooStringView name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
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.
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.
<div class="legacybox"><h2>Legacy Code</h2> TFolder is a legacy interface: there will be no bug fixes...
TCollection * GetListOfFolders() const
virtual void SetOwner(Bool_t owner=kTRUE)
Set ownership.
TH1 is the base class of all histogram classes in ROOT.
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 Double_t Integral(Option_t *option="") const
Return integral of bin contents.
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 void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
virtual TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
const char * GetName() const override
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
TString & Append(const char *cs)
RooCmdArg Silence(bool flag=true)
void(off) SmallVectorTemplateBase< T
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
void init()
Inspect hardware capabilities, and load the optimal library for RooFit computations.
std::string observableName
std::vector< std::string > folderNames
std::vector< std::vector< const char * > > nonInterfering
#define Split(a, ahi, alo)