37#pragma warning(disable : 4996)
39#pragma GCC diagnostic push
40#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
49RooHistConstraint::RooHistConstraint(
const char *
name,
const char *title,
52 _gamma(
"gamma",
"gamma",this),
53 _nominal(
"nominal",
"nominal",this),
63 if (phfSet.
size()==1) {
68 coutE(InputArguments) <<
"RooHistConstraint::ctor(" << GetName()
69 <<
") ERROR: input object must be a RooParamHistFunc" << std::endl ;
70 throw std::string(
"RooHistConstraint::ctor ERROR incongruent input arguments") ;
74 for (
int i=0 ; i<phf->_dh.numEntries() ; i++) {
75 const double wi = phf->_dh.weight(i) ;
76 if (wi<threshold && wi != 0.) {
77 const char* vname =
Form(
"%s_nominal_bin_%i",GetName(),i) ;
78 auto var = std::make_unique<RooRealVar>(vname,vname,0,1.E30);
80 var->setConstant(
true);
82 auto gamma =
static_cast<RooRealVar*
>(phf->_p.at(i));
83 if (var->getVal() > 0.0) {
84 gamma->setConstant(
false);
87 _nominal.addOwned(std::move(var)) ;
98 std::vector<RooParamHistFunc*> phvec ;
100 std::string bin0_name ;
101 for (
const auto arg : phfSet) {
105 phvec.push_back(phfComp) ;
107 nbins = phfComp->_p.size() ;
108 bin0_name = phfComp->_p.at(0)->GetName() ;
109 gammaSet.
add(phfComp->_p) ;
111 if (
int(phfComp->_p.size())!=nbins) {
112 coutE(InputArguments) <<
"RooHistConstraint::ctor(" << GetName()
113 <<
") ERROR: incongruent input arguments: all input RooParamHistFuncs should have same #bins" << std::endl ;
114 throw std::string(
"RooHistConstraint::ctor ERROR incongruent input arguments") ;
116 if (bin0_name != phfComp->_p.at(0)->GetName()) {
117 coutE(InputArguments) <<
"RooHistConstraint::ctor(" << GetName()
118 <<
") ERROR: incongruent input arguments: all input RooParamHistFuncs should have the same bin parameters.\n"
119 <<
"Previously found " << bin0_name <<
", now found " << phfComp->_p.at(0)->GetName() <<
".\n"
120 <<
"Check that the right RooParamHistFuncs have been passed to this RooHistConstraint." << std::endl;
121 throw std::string(
"RooHistConstraint::ctor ERROR incongruent input arguments") ;
126 coutW(InputArguments) <<
"RooHistConstraint::ctor(" << GetName()
127 <<
") WARNING: ignoring input argument " << arg->GetName() <<
" which is not of type RooParamHistFunc" << std::endl;
131 _gamma.add(gammaSet) ;
134 for (
int i=0 ; i<nbins ; i++) {
137 for (
const auto phfunc : phvec) {
138 sumVal += phfunc->getNominal(i);
141 if (sumVal<threshold && sumVal != 0.) {
143 const char* vname =
Form(
"%s_nominal_bin_%i",GetName(),i) ;
144 auto var = std::make_unique<RooRealVar>(vname,vname,0,1000);
147 for(
auto const& elem : phvec) {
148 sumVal2 += elem->getNominal(i) ;
150 var->setVal(sumVal2) ;
151 var->setConstant(
true) ;
153 vname =
Form(
"%s_nominal_error_bin_%i",GetName(),i) ;
163 _nominal.addOwned(std::move(var));
166 (
static_cast<RooRealVar*
>(_gamma.at(i)))->setConstant(
false) ;
176 _gamma(
"gamma",this,other._gamma),
177 _nominal(
"nominal",this,other._nominal),
178 _relParam(other._relParam)
184 double RooHistConstraint::evaluate()
const
188 for (
unsigned int i=0; i < _nominal.size(); ++i) {
190 const auto& nominal =
static_cast<const RooAbsReal&
>(_nominal[i]);
191 double gammaVal =
gamma.getVal();
192 const int nomVal =
static_cast<int>(nominal.getVal());
201 }
else if (nomVal > 0) {
202 coutE(Eval) <<
"ERROR in RooHistConstraint: gamma=0 and nom>0" << std::endl;
211double RooHistConstraint::getLogVal(
const RooArgSet* )
const
214 for (
unsigned int i=0; i < _nominal.size(); ++i) {
216 const auto& nominal =
static_cast<const RooAbsReal&
>(_nominal[i]);
217 double gammaVal =
gamma.getVal();
218 const int nomVal =
static_cast<int>(nominal.getVal());
225 const double logPoisson = nomVal *
log(gammaVal) - gammaVal - std::lgamma(nomVal + 1);
227 }
else if (nomVal > 0) {
228 coutE(Eval) <<
"ERROR in RooHistConstraint: gamma=0 and nom>0" << std::endl;
238#pragma GCC diagnostic pop
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
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value and implements functionality common to al...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Variable that can be changed from the outside.
double poisson_pdf(unsigned int n, double mu)
Probability density function of the Poisson distribution.
RVec< PromoteType< T > > log(const RVec< T > &v)
static uint64_t sum(uint64_t i)