Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v626][RF] Backports of RooFit PRs to v6-26-00-patches: Part 3 #9710

Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,13 @@ def is_defined(funcname):
return sorted([attr for attr in dir(klass) if is_defined(attr)])


def is_staticmethod(klass, func_name):
"""Check if the function with name `func_name` of a class is a static method."""
def is_staticmethod_py2(klass, func_name):
"""Check if the function with name `func_name` of a class is a static method in Python 2."""

import sys

if sys.version_info >= (3, 0):
func = getattr(klass(), func_name)
else:
func = getattr(klass, func_name)

return type(func).__name__ == "function"
return type(getattr(klass, func_name)).__name__ == "function"


def rebind_instancemethod(to_class, from_class, func_name):
def rebind_attribute(to_class, from_class, func_name):
"""
Bind the instance method `from_class.func_name` also to class `to_class`.
"""
Expand All @@ -168,7 +161,9 @@ def rebind_instancemethod(to_class, from_class, func_name):

if sys.version_info >= (3, 0):
to_method = from_method
elif is_staticmethod(from_class, func_name):
elif isinstance(from_method, property):
to_method = from_method
elif is_staticmethod_py2(from_class, func_name):
to_method = staticmethod(from_method)
else:
import new
Expand Down Expand Up @@ -231,7 +226,7 @@ def pythonize_roofit_class(klass, name):

setattr(klass, func_name_orig, func_orig)

rebind_instancemethod(klass, python_klass, func_name)
rebind_attribute(klass, python_klass, func_name)

return

Expand Down
22 changes: 14 additions & 8 deletions etc/RooFitHS3_wsexportkeys.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
"mean": "mean"
}
},
"RooExponential": {
"type": "Exponential",
"proxies": {
"x": "x",
"c": "c"
}
},
"RooProduct": {
"type": "prod",
"proxies": {
Expand All @@ -34,13 +41,6 @@
"paramSet": "parameters"
}
},
"RooRealSumPdf": {
"type": "sumpdf",
"proxies": {
"funcList": "samples",
"coefList": "coefficients"
}
},
"RooAddPdf": {
"type": "pdfsum",
"proxies": {
Expand All @@ -49,6 +49,12 @@
"coefficients": "coefficients"
}
},
"RooAddition": {
"type": "sum",
"proxies": {
"set": "summands"
}
},
"RooArgusBG": {
"type": "ARGUS",
"proxies": {
Expand All @@ -58,4 +64,4 @@
"p": "power"
}
}
}
}
18 changes: 12 additions & 6 deletions etc/RooFitHS3_wsfactoryexpressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"sigma"
]
},
"Exponential": {
"class": "RooExponential",
"arguments": [
"x",
"c"
]
},
"Poisson": {
"class": "RooPoisson",
"arguments": [
Expand All @@ -29,13 +36,12 @@
"high"
]
},
"sumpdf": {
"class": "RooRealSumPdf",
"sum": {
"class": "RooAddition",
"arguments": [
"samples",
"coefficients"
"summands"
]
},
},
"paramhist": {
"class": "ParamHistFunc",
"arguments": [
Expand All @@ -52,4 +58,4 @@
"power"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class PiecewiseInterpolation : public RooAbsReal {
const RooArgList& lowList() const { return _lowSet ; }
const RooArgList& highList() const { return _highSet ; }
const RooArgList& paramList() const { return _paramSet ; }

const std::vector<int>& interpolationCodes() const { return _interpCode; }

//virtual Bool_t forceAnalyticalInt(const RooAbsArg&) const { return kTRUE ; }
Bool_t setBinIntegrator(RooArgSet& allVars) ;

Expand All @@ -58,7 +59,7 @@ class PiecewiseInterpolation : public RooAbsReal {

void setPositiveDefinite(bool flag=true){_positiveDefinite=flag;}

void setInterpCode(RooAbsReal& param, int code);
void setInterpCode(RooAbsReal& param, int code, bool silent=false);
void setAllInterpCodes(int code);
void printAllInterpCodes();

Expand Down
8 changes: 5 additions & 3 deletions roofit/histfactory/src/PiecewiseInterpolation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -742,14 +742,16 @@ Double_t PiecewiseInterpolation::analyticalIntegralWN(Int_t code, const RooArgSe

////////////////////////////////////////////////////////////////////////////////

void PiecewiseInterpolation::setInterpCode(RooAbsReal& param, int code){
void PiecewiseInterpolation::setInterpCode(RooAbsReal& param, int code, bool silent){
int index = _paramSet.index(&param);
if(index<0){
coutE(InputArguments) << "PiecewiseInterpolation::setInterpCode ERROR: " << param.GetName()
<< " is not in list" << endl ;
} else {
coutW(InputArguments) << "PiecewiseInterpolation::setInterpCode : " << param.GetName()
<< " is now " << code << endl ;
if(!silent){
coutW(InputArguments) << "PiecewiseInterpolation::setInterpCode : " << param.GetName()
<< " is now " << code << endl ;
}
_interpCode.at(index) = code;
}
}
Expand Down
2 changes: 1 addition & 1 deletion roofit/histfactory/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
# @author Stephan Hageboeck CERN, 2019

ROOT_ADD_GTEST(testHistFactory testHistFactory.cxx
LIBRARIES RooFitCore RooFit RooStats HistFactory RooBatchCompute
LIBRARIES RooFitCommon RooFitCore RooFit RooStats HistFactory RooBatchCompute
COPY_TO_BUILDDIR ${CMAKE_CURRENT_SOURCE_DIR}/ref_6.16_example_UsingC_channel1_meas_model.root ${CMAKE_CURRENT_SOURCE_DIR}/ref_6.16_example_UsingC_combined_meas_model.root)
1 change: 1 addition & 0 deletions roofit/hs3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitHS3
HEADERS
RooFitHS3/RooJSONFactoryWSTool.h
RooFitHS3/HistFactoryJSONTool.h
RooFitHS3/JSONInterface.h
SOURCES
src/RooJSONFactoryWSTool.cxx
src/HistFactoryJSONTool.cxx
Expand Down
8 changes: 4 additions & 4 deletions roofit/hs3/inc/RooFitHS3/HistFactoryJSONTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>

namespace RooFit {
namespace Detail {
namespace Experimental {
class JSONNode;
}
} // namespace RooFit
Expand All @@ -21,8 +21,8 @@ class JSONTool {
protected:
RooStats::HistFactory::Measurement *_measurement;

void Export(const RooStats::HistFactory::Channel &c, RooFit::Detail::JSONNode &t) const;
void Export(const RooStats::HistFactory::Sample &s, RooFit::Detail::JSONNode &t) const;
void Export(const RooStats::HistFactory::Channel &c, RooFit::Experimental::JSONNode &t) const;
void Export(const RooStats::HistFactory::Sample &s, RooFit::Experimental::JSONNode &t) const;

public:
JSONTool(RooStats::HistFactory::Measurement *);
Expand All @@ -31,7 +31,7 @@ class JSONTool {
void PrintJSON(std::string const &filename);
void PrintYAML(std::ostream &os = std::cout);
void PrintYAML(std::string const &filename);
void Export(RooFit::Detail::JSONNode &t) const;
void Export(RooFit::Experimental::JSONNode &t) const;
};

} // namespace HistFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <vector>

namespace RooFit {
namespace Detail {
namespace Experimental {

class JSONNode {
protected:
Expand Down Expand Up @@ -80,6 +80,8 @@ class JSONNode {
virtual int val_int() const { return atoi(this->val().c_str()); }
virtual float val_float() const { return atof(this->val().c_str()); }
virtual bool val_bool() const { return atoi(this->val().c_str()); }
template <class T>
T val_t() const;
virtual bool has_key() const = 0;
virtual bool has_val() const = 0;
virtual bool has_child(std::string const &) const = 0;
Expand All @@ -103,13 +105,24 @@ class JSONNode {
virtual const JSONNode &child(size_t pos) const = 0;
};

} // namespace Detail
} // namespace Experimental
} // namespace RooFit

class JSONTree {
virtual RooFit::Detail::JSONNode &rootnode() = 0;
virtual RooFit::Experimental::JSONNode &rootnode() = 0;
};

std::ostream &operator<<(std::ostream &os, RooFit::Detail::JSONNode const &s);
std::ostream &operator<<(std::ostream &os, RooFit::Experimental::JSONNode const &s);
template <class T>
std::vector<T> &operator<<(std::vector<T> &v, RooFit::Experimental::JSONNode const &n)
{
if (!n.is_seq()) {
throw std::runtime_error("node " + n.key() + " is not of sequence type!");
}
for (const auto &e : n.children()) {
v.push_back(e.val_t<T>());
}
return v;
}

#endif
Loading