48 if (binning.isUniform()) {
50 axis[
"min"] << obs.
getMin();
51 axis[
"max"] << obs.
getMax();
53 auto &edges = axis[
"edges"];
55 double val = binning.binLow(0);
56 edges.append_child() << val;
57 for (
int i = 0; i < binning.numBins(); ++i) {
58 val = binning.binHigh(i);
59 edges.append_child() << val;
68 int ndigits = std::floor(std::log10(std::abs(
d))) + 1 -
nSig;
70 if (std::abs(
d /
sf) < 2)
72 return sf * std::round(
d /
sf);
81void erasePrefix(std::string &str, std::string_view prefix)
84 str.erase(0, prefix.size());
91 str.erase(str.size() -
suffix.size());
104 for (
const auto &client :
gamma->clients()) {
105 if (
auto casted =
dynamic_cast<T *
>(client)) {
149 return "gamma_" +
sysname +
"_bin_" + std::to_string(i);
157 for (std::size_t i = 0; i <
paramNames.size(); ++i) {
168 nom.setConstant(
true);
187 const std::vector<std::string> &
parnames,
const std::vector<double> &vals,
194 for (std::size_t i = 0; i < vals.size(); ++i) {
210 gamma->setConstant(
true);
219 if (!
comp.has_child(
"modifiers"))
221 for (
const auto &
mod :
comp[
"modifiers"].children()) {
222 if (
mod[
"type"].val() == ::Literals::staterror)
230 if (
comp.has_child(
"modifiers")) {
231 for (
const auto &
mod :
comp[
"modifiers"].children()) {
232 if (
mod[
"type"].val() == ::Literals::staterror)
237 ::Literals::staterror +
" modifier!");
252 if (!
p.has_child(
"data")) {
268 if (
p.has_child(
"modifiers")) {
278 for (
const auto &
mod :
p[
"modifiers"].children()) {
279 std::string
const &
modtype =
mod[
"type"].val();
281 mod.has_child(
"name")
283 : (
mod.has_child(
"parameter") ?
mod[
"parameter"].val() :
"syst_" + std::to_string(idx));
287 }
else if (
modtype ==
"normfactor") {
292 if (
auto gauss =
dynamic_cast<RooGaussian const *
>(constraint)) {
295 constraints.
add(*constraint);
297 }
else if (
modtype ==
"normsys") {
308 : std::numeric_limits<
double>::epsilon());
310 : std::numeric_limits<
double>::epsilon());
312 }
else if (
modtype ==
"histosys") {
325 }
else if (
modtype ==
"shapesys") {
328 std::vector<double> vals;
329 for (
const auto &
v :
mod[
"data"][
"vals"].children()) {
330 vals.push_back(
v.val_double());
333 for (
const auto &
v :
mod[
"parameters"].children()) {
339 std::string constraint(
mod[
"constraint"].val());
342 }
else if (
modtype ==
"custom") {
367 v.setAllInterpCodes(4);
389 if (!
p.has_child(
"samples")) {
394 if (
p.has_child(::Literals::staterror)) {
395 auto &
staterr =
p[::Literals::staterror];
396 if (
staterr.has_child(
"relThreshold"))
398 if (
staterr.has_child(
"constraint"))
401 std::vector<double>
sumW;
402 std::vector<double>
sumW2;
408 std::vector<std::unique_ptr<RooDataHist>>
data;
409 for (
const auto &
comp :
p[
"samples"].children()) {
412 size_t nbins =
dh->numEntries();
419 for (
size_t i = 0; i < nbins; ++i) {
421 sumW2[i] +=
dh->weightSquared(i);
431 data.emplace_back(std::move(
dh));
440 std::vector<double>
errs(
sumW.size());
441 for (
size_t i = 0; i <
sumW.size(); ++i) {
455 for (
const auto &
comp :
p[
"samples"].children()) {
464 if (constraints.
empty()) {
479 std::string
const &key()
const override
481 static const std::string
keystring =
"interpolation0d";
487 elem[
"type"] << key();
488 elem[
"interpolationCodes"].fill_seq(
fip->interpolationCodes());
491 elem[
"high"].fill_seq(
fip->high(),
fip->variables().size());
492 elem[
"low"].fill_seq(
fip->low(),
fip->variables().size());
499 std::string
const &key()
const override
501 static const std::string
keystring =
"interpolation";
507 elem[
"type"] << key();
508 elem[
"interpolationCodes"].fill_seq(
pip->interpolationCodes());
509 elem[
"positiveDefinite"] <<
pip->positiveDefinite();
511 elem[
"nom"] <<
pip->nominalHist()->GetName();
530 pip.setPositiveDefinite(
p[
"positiveDefinite"].val_bool());
532 if (
p.has_child(
"interpolationCodes")) {
534 for (
auto const &node :
p[
"interpolationCodes"].children()) {
535 pip.setInterpCode(*
static_cast<RooAbsReal *
>(vars.at(i)), node.val_int(),
true);
549 if (!
p.has_child(
"high")) {
552 if (!
p.has_child(
"low")) {
555 if (!
p.has_child(
"nom")) {
559 double nom(
p[
"nom"].val_double());
563 std::vector<double> high;
566 std::vector<double> low;
569 if (vars.size() != low.size() || vars.size() != high.size()) {
571 "' has non-matching lengths of 'vars', 'high' and 'low'!");
576 if (
p.has_child(
"interpolationCodes")) {
578 for (
auto const &node :
p[
"interpolationCodes"].children()) {
579 fip.setInterpCode(*
static_cast<RooAbsReal *
>(vars.at(i)), node.val_int());
590 if (
auto prod =
dynamic_cast<RooProduct *
>(arg)) {
591 for (
const auto &
e : prod->components()) {
616 :
name(
n), param(
p), low(
l), high(
h), constraint(
c)
623 std::vector<double> low;
624 std::vector<double> high;
627 :
name(
n), param(
p), constraint(
c)
629 low.assign(
l->dataHist().weightArray(),
l->dataHist().weightArray() +
l->dataHist().numEntries());
630 high.assign(
h->dataHist().weightArray(),
h->dataHist().weightArray() +
h->dataHist().numEntries());
635 std::vector<double> constraints;
636 std::vector<std::string> parameters;
637 TClass *constraint =
nullptr;
642 std::vector<double> hist;
643 std::vector<double> histError;
644 std::vector<NormFactor> normfactors;
645 std::vector<NormSys> normsys;
646 std::vector<HistoSys> histosys;
647 std::vector<ShapeSys> shapesys;
648 std::vector<RooAbsReal *> otherElements;
649 bool useBarlowBeestonLight =
false;
650 std::vector<std::string> staterrorParameters;
659 for (
RooAbsArg const *pdf : ws->allPdfs()) {
660 if (
auto gauss =
dynamic_cast<RooGaussian const *
>(pdf)) {
661 if (
parname == gauss->getX().GetName()) {
662 sample.normfactors.emplace_back(*par, gauss);
668 sample.normfactors.emplace_back(*par);
685 std::cout <<
pdfname <<
" is not a sumpdf" << std::endl;
697 std::cout <<
"sample " <<
sample->GetName() <<
" is no RooProduct or RooRealSumPdf in " <<
pdfname
707 long unsigned int nBins = 0;
713 std::vector<RooStats::HistFactory::FlexibleInterpVar *>
fips;
714 std::vector<ParamHistFunc *>
phfs;
729 nBins = dataHist.numEntries();
731 if (
sample.hist.empty()) {
732 auto *
w = dataHist.weightArray();
733 sample.hist.assign(
w,
w + dataHist.numEntries());
748 sample.normfactors.emplace_back(*
e);
750 }
else if (
auto par =
dynamic_cast<RooRealVar *
>(
e)) {
778 for (
size_t i = 0; i <
fip->variables().
size(); ++i) {
786 constraint ? constraint->
IsA() : nullptr);
793 for (
size_t i = 0; i <
pip->paramList().
size(); ++i) {
797 if (
auto lo =
dynamic_cast<RooHistFunc *
>(
pip->lowList().at(i))) {
802 sample.histosys.emplace_back(
sysname, var, lo,
hi, constraint ? constraint->
IsA() : nullptr);
812 for (
const auto &
g :
phf->paramList()) {
813 sample.staterrorParameters.push_back(
g->GetName());
823 sample.barlowBeestonLightConstraint = constraint->
IsA();
832 "currently, only RooPoisson and RooGaussian are supported as constraint types");
836 sample.useBarlowBeestonLight =
true;
842 for (
const auto &
g :
phf->paramList()) {
843 sys.parameters.push_back(
g->GetName());
847 if (!constraint && !
g->isConstant()) {
849 }
else if (!constraint) {
850 sys.constraints.push_back(0.0);
852 sys.constraints.push_back(1. / std::sqrt(
constraint_p->getX().getVal()));
853 if (!sys.constraint) {
858 if (!sys.constraint) {
863 sample.shapesys.emplace_back(std::move(sys));
875 if (
sample.hist.empty()) {
878 if (
sample.useBarlowBeestonLight) {
883 const int i = bin.first;
885 const double count =
sample.hist[i - 1];
896 elem[
"type"] <<
"histfactory_dist";
903 for (
const auto &
nf :
sample.normfactors) {
906 mod[
"name"] <<
nf.name;
907 mod[
"parameter"] <<
nf.param->GetName();
908 mod[
"type"] <<
"normfactor";
910 mod[
"constraint_name"] <<
nf.constraint->GetName();
911 tool->queueExport(*
nf.constraint);
915 for (
const auto &sys :
sample.normsys) {
918 mod[
"name"] << sys.name;
919 mod[
"type"] <<
"normsys";
920 mod[
"parameter"] << sys.param->GetName();
921 mod[
"constraint"] << toString(sys.constraint);
922 auto &
data =
mod[
"data"].set_map();
923 data[
"lo"] << sys.low;
924 data[
"hi"] << sys.high;
927 for (
const auto &sys :
sample.histosys) {
930 mod[
"name"] << sys.name;
931 mod[
"type"] <<
"histosys";
932 mod[
"parameter"] << sys.param->GetName();
933 mod[
"constraint"] << toString(sys.constraint);
934 auto &
data =
mod[
"data"].set_map();
935 if (nBins != sys.low.size() || nBins != sys.high.size()) {
936 std::stringstream
ss;
937 ss <<
"inconsistent binning: " << nBins <<
" bins expected, but " << sys.low.size() <<
"/"
938 << sys.high.size() <<
" found in nominal histogram errors!";
945 for (
const auto &sys :
sample.shapesys) {
948 mod[
"name"] << sys.name;
949 mod[
"type"] <<
"shapesys";
951 mod[
"constraint"] << toString(sys.constraint);
952 if (sys.constraint) {
953 auto &vals =
mod[
"data"].set_map()[
"vals"];
954 vals.fill_seq(sys.constraints);
956 auto &vals =
mod[
"data"].set_map()[
"vals"];
958 for (std::size_t i = 0; i < sys.parameters.size(); ++i) {
959 vals.append_child() << 0;
969 mod[
"type"] <<
"custom";
972 if (
sample.useBarlowBeestonLight) {
975 mod[
"name"] << ::Literals::staterror;
976 mod[
"type"] << ::Literals::staterror;
978 mod[
"constraint"] << toString(
sample.barlowBeestonLightConstraint);
984 auto &
out =
output.append_child().set_map();
990 auto &
dataNode = s[
"data"].set_map();
991 if (nBins !=
sample.hist.size()) {
992 std::stringstream
ss;
993 ss <<
"inconsistent binning: " << nBins <<
" bins expected, but " <<
sample.hist.size()
994 <<
" found in nominal histogram!";
998 if (!
sample.histError.empty()) {
999 if (nBins !=
sample.histError.size()) {
1000 std::stringstream
ss;
1001 ss <<
"inconsistent binning: " << nBins <<
" bins expected, but " <<
sample.histError.size()
1002 <<
" found in nominal histogram errors!";
1020 tool->queueExport(*param);
1029 bool autoExportDependants()
const override {
return false; }
1047 std::string
const &key()
const override
1049 static const std::string
keystring =
"histfactory_dist";
1060 bool autoExportDependants()
const override {
return false; }
1065 std::string
const &key()
const override
1067 static const std::string
keystring =
"histfactory_dist";
bool startsWith(std::string_view str, std::string_view prefix)
bool endsWith(std::string_view str, std::string_view suffix)
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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 funcs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t modifier
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
The PiecewiseInterpolation is a class that can morph distributions into each other,...
void setPositiveDefinite(bool flag=true)
const_iterator begin() const
const_iterator end() const
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Abstract interface for all probability density functions.
TClass * IsA() const override
Int_t numBins(const char *rangeName=nullptr) const override
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
Abstract base class for objects that represent a real value and implements functionality common to al...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Returns the bin width (or volume) given a RooHistFunc.
Represents a constant real-valued object.
Container class to hold N-dimensional binned data.
virtual JSONNode & set_seq()=0
A real-valued function sampled from a multidimensional histogram.
Efficient implementation of a product of PDFs of the form.
Represents the product of a given set of RooAbsReal objects.
Implements a PDF constructed from a sum of functions:
Variable that can be changed from the outside.
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const override
Return binning definition with name.
void setAllInterpCodes(int code)
Configuration for a constrained, coherent shape variation of affected samples.
Configuration for an un- constrained overall systematic to scale sample normalisations.
std::string GetName() const
Constrained bin-by-bin variation of affected histogram.
Persistable container for RooFit projects.
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
RooAbsReal * function(RooStringView name) const
Retrieve function (RooAbsReal) with given name. Note that all RooAbsPdfs are also RooAbsReals....
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
RooFactoryWSTool & factory()
Return instance to factory tool.
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
TClass instances represent classes, structs and namespaces in the ROOT type system.
TClass * IsA() const override
const char * GetName() const override
Returns name of object.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
RooCmdArg RecycleConflictNodes(bool flag=true)
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, bool depsAreCond=false)
constexpr double defaultShapeSysGammaMax
constexpr double minShapeUncertainty
constexpr double defaultStatErrorGammaMax
constexpr double defaultGammaMin
CreateGammaConstraintsOutput createGammaConstraints(RooArgList const ¶mList, std::span< const double > relSigmas, double minSigma, Constraint::Type type)
#define STATIC_EXECUTE(MY_FUNC)
static uint64_t sum(uint64_t i)