37 _gamma(
"gamma",
"gamma",this),
38 _nominal(
"nominal",
"nominal",this),
48 if (phfSet.
size()==1) {
53 coutE(InputArguments) <<
"RooHistConstraint::ctor(" <<
GetName()
54 <<
") ERROR: input object must be a RooParamHistFunc" << std::endl ;
55 throw std::string(
"RooHistConstraint::ctor ERROR incongruent input arguments") ;
59 for (
int i=0 ; i<phf->_dh.numEntries() ; i++) {
61 if (phf->_dh.weight()<threshold && phf->_dh.weight() != 0.) {
62 const char* vname =
Form(
"%s_nominal_bin_%i",
GetName(),i) ;
63 auto var = std::make_unique<RooRealVar>(vname,vname,0,1.E30);
64 var->setVal(phf->_dh.weight()) ;
65 var->setConstant(
true);
67 auto gam =
static_cast<RooRealVar*
>(phf->_p.at(i));
68 if (var->getVal() > 0.0) {
83 std::vector<RooParamHistFunc*> phvec ;
85 std::string bin0_name ;
86 for (
const auto arg : phfSet) {
90 phvec.push_back(phfComp) ;
92 nbins = phfComp->_p.getSize() ;
93 bin0_name = phfComp->_p.at(0)->GetName() ;
94 gammaSet.
add(phfComp->_p) ;
96 if (phfComp->_p.getSize()!=nbins) {
97 coutE(InputArguments) <<
"RooHistConstraint::ctor(" <<
GetName()
98 <<
") ERROR: incongruent input arguments: all input RooParamHistFuncs should have same #bins" << std::endl ;
99 throw std::string(
"RooHistConstraint::ctor ERROR incongruent input arguments") ;
101 if (bin0_name != phfComp->_p.at(0)->GetName()) {
102 coutE(InputArguments) <<
"RooHistConstraint::ctor(" <<
GetName()
103 <<
") ERROR: incongruent input arguments: all input RooParamHistFuncs should have the same bin parameters.\n"
104 <<
"Previously found " << bin0_name <<
", now found " << phfComp->_p.at(0)->GetName() <<
".\n"
105 <<
"Check that the right RooParamHistFuncs have been passed to this RooHistConstraint." << std::endl;
106 throw std::string(
"RooHistConstraint::ctor ERROR incongruent input arguments") ;
111 coutW(InputArguments) <<
"RooHistConstraint::ctor(" <<
GetName()
112 <<
") WARNING: ignoring input argument " << arg->GetName() <<
" which is not of type RooParamHistFunc" << std::endl;
119 for (
int i=0 ; i<nbins ; i++) {
122 for (
const auto phfunc : phvec) {
123 sumVal += phfunc->getNominal(i);
126 if (sumVal<threshold && sumVal != 0.) {
128 const char* vname =
Form(
"%s_nominal_bin_%i",
GetName(),i) ;
129 auto var = std::make_unique<RooRealVar>(vname,vname,0,1000);
132 for(
auto const& elem : phvec) {
133 sumVal2 += elem->getNominal(i) ;
135 var->setVal(sumVal2) ;
136 var->setConstant(
true) ;
138 vname =
Form(
"%s_nominal_error_bin_%i",
GetName(),i) ;
161 _gamma(
"gamma",this,other._gamma),
162 _nominal(
"nominal",this,other._nominal),
163 _relParam(other._relParam)
176 double gamVal = gamma.getVal();
177 const int nomVal =
static_cast<int>(nominal.getVal());
186 }
else if (nomVal > 0) {
187 coutE(Eval) <<
"ERROR in RooHistConstraint: gam=0 and nom>0" << std::endl;
202 double gamVal = gamma.getVal();
203 const int nomVal =
static_cast<int>(nominal.getVal());
210 const double logPoisson = nomVal * log(gamVal) - gamVal - std::lgamma(nomVal + 1);
212 }
else if (nomVal > 0) {
213 coutE(Eval) <<
"ERROR in RooHistConstraint: gam=0 and nom>0" << std::endl;
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
RooAbsArg * first() const
void setConstant(bool value=true)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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.
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 RooHistConstraint implements constraint terms for a binned PDF with statistical uncertainties.
double getLogVal(const RooArgSet *set=nullptr) const override
Return the log of the current value with given normalization An error message is printed if the argum...
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
A histogram function that assigns scale parameters to every bin.
RooRealVar represents a variable that can be changed from the outside.
const char * GetName() const override
Returns name of object.
double poisson_pdf(unsigned int n, double mu)
Probability density function of the Poisson distribution.
static uint64_t sum(uint64_t i)