85 _paramSet(
"!paramSet",
"bin parameters", this),
129 _dataVars(
"!dataVars",
"data Vars", this),
130 _paramSet(
"!paramSet",
"bin parameters", this),
149 if( vars.
empty() )
return 0;
153 for (
auto comp : vars) {
155 auto errorMsg = std::string(
"ParamHistFunc::GetNumBins") + vars.
GetName() +
") ERROR: component "
156 + comp->GetName() +
" in vars list is not of type RooRealVar";
157 oocoutE(
nullptr, InputArguments) << errorMsg << std::endl;
158 throw std::runtime_error(errorMsg);
162 Int_t varNumBins = var->numBins();
205 const int i = index /
n.yz;
206 const int tmp = index %
n.yz;
207 const int j = tmp /
n.z;
208 const int k = tmp %
n.z;
210 const int idx = i + j *
n.x + k *
n.xy;
212 throw std::runtime_error(
"invalid index");
233 for(
int i=0; i <
numBins(); ++i) {
244 if( num_hist_bins !=
numBins() ) {
245 std::cout <<
"Error - ParamHistFunc: cannot set Shape of ParamHistFunc: " <<
GetName()
246 <<
" using histogram: " << shape->
GetName()
247 <<
". Bins don't match" << std::endl;
248 throw std::runtime_error(
"setShape");
252 Int_t TH1BinNumber = 0;
263 std::cout <<
"Error - ParamHisFunc: cannot set Shape of ParamHistFunc: " <<
GetName()
264 <<
" - param is not RooRealVar" << std::endl;
265 throw std::runtime_error(
"setShape");
299 std::cout <<
"Warning - ParamHistFunc::createParamSet() :"
300 <<
" No Variables provided. Not making constraint terms."
305 else if( numVars == 1 ) {
310 std::stringstream VarNameStream;
311 VarNameStream << Prefix <<
"_bin_" << i;
312 std::string VarName = VarNameStream.str();
314 RooRealVar gamma( VarName.c_str(), VarName.c_str(), 1.0 );
317 gamma.setConstant(
false );
321 paramSet.
add(*w.arg(VarName));
325 else if( numVars == 2 ) {
329 std::vector< Int_t > Indices(numVars, 0);
342 std::stringstream VarNameStream;
343 VarNameStream << Prefix <<
"_bin_" << i <<
"_" << j;
344 std::string VarName = VarNameStream.str();
346 RooRealVar gamma( VarName.c_str(), VarName.c_str(), 1.0 );
349 gamma.setConstant(
false );
353 paramSet.
add(*w.arg(VarName));
358 else if( numVars == 3 ) {
362 std::vector< Int_t > Indices(numVars, 0);
377 std::stringstream VarNameStream;
378 VarNameStream << Prefix <<
"_bin_" << i <<
"_" << j <<
"_" << k;
379 std::string VarName = VarNameStream.str();
381 RooRealVar gamma( VarName.c_str(), VarName.c_str(), 1.0 );
384 gamma.setConstant(
false );
388 paramSet.
add(*w.arg(VarName));
395 std::cout <<
" Error: ParamHistFunc doesn't support dimensions > 3D " << std::endl;
421 double gamma_min,
double gamma_max) {
427 for (
auto comp : params) {
430 if(
auto var =
dynamic_cast<RooRealVar*
>(comp)) {
431 var->setMin( gamma_min );
432 var->setMax( gamma_max );
447 double gamma_min,
double gamma_max) {
454 if( gamma_max <= gamma_min ) {
456 std::cout <<
"Warning: gamma_min <= gamma_max: Using default values (0, 10)" << std::endl;
463 double gamma_nominal = 1.0;
465 if( gamma_nominal < gamma_min ) {
466 gamma_nominal = gamma_min;
469 if( gamma_nominal > gamma_max ) {
470 gamma_nominal = gamma_max;
476 std::stringstream VarNameStream;
477 VarNameStream << Prefix <<
"_bin_" << i;
478 std::string VarName = VarNameStream.str();
480 auto gamma = std::make_unique<RooRealVar>(VarName.c_str(), VarName.c_str(),
481 gamma_nominal, gamma_min, gamma_max);
482 gamma->setConstant(
false );
483 paramSet.
addOwned(std::move(gamma));
493 int numVars = vars.
size();
495 if (numVars > 3 || numVars < 1) {
496 std::cout <<
"ParamHistFunc() - Only works for 1-3 variables (1d-3d)" << std::endl;
500 int numBinsX = numVars >= 1 ?
static_cast<RooRealVar const&
>(*vars[0]).
numBins() : 1;
501 int numBinsY = numVars >= 2 ?
static_cast<RooRealVar const&
>(*vars[1]).
numBins() : 1;
502 int numBinsZ = numVars >= 3 ?
static_cast<RooRealVar const&
>(*vars[2]).
numBins() : 1;
504 return {numBinsX, numBinsY, numBinsZ};
529 if( numVarBins != numElements ) {
530 std::cout <<
"ParamHistFunc::addParamSet - ERROR - "
531 <<
"Supplied list of parameters " << params.
GetName()
532 <<
" has " << numElements <<
" elements but the ParamHistFunc"
533 <<
GetName() <<
" has " << numVarBins <<
" bins."
564 std::span<double> output = ctx.
output();
565 std::size_t
size = output.size();
576 std::array<int, 3> idxMult{{1,
n.x,
n.xy}};
581 auto indexBuffer =
reinterpret_cast<int*
>(output.data() +
size) -
size;
582 std::fill(indexBuffer, indexBuffer +
size, 0);
587 for (std::size_t iVar = 0; iVar <
_dataVars.size(); ++iVar) {
592 for (std::size_t i = 0; i <
size; ++i) {
605 if (allVars.
empty())
return 0 ;
610 analVars.
add(allVars) ;
613 Int_t sterileIdx(-1) ;
644 for (
unsigned int i=0; i <
_paramSet.size(); ++i) {
648 const double paramVal = param.getVal();
651 value += paramVal * binVolumes[i];
673 double* boundaries = binning->
array() ;
675 std::list<double>* hint =
new std::list<double> ;
678 xlo = xlo - 0.01*(xhi-xlo) ;
679 xhi = xhi + 0.01*(xhi-xlo) ;
681 double delta = (xhi-xlo)*1
e-8 ;
686 if (boundaries[i]>=xlo && boundaries[i]<=xhi) {
687 hint->push_back(boundaries[i]-delta) ;
688 hint->push_back(boundaries[i]+delta) ;
708 auto &binnings =
_dataSet.getBinnings();
709 for (
size_t i = 0; i < vars.
size(); i++) {
710 if (varName == vars[i]->
GetName()) {
712 double *boundaries = binnings.at(i)->array();
713 std::list<double> *hint =
new std::list<double>;
714 for (
int j = 0; j < binnings.at(i)->numBoundaries(); j++) {
715 if (boundaries[j] >= xlo && boundaries[j] <= xhi) {
716 hint->push_back(boundaries[j]);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
static NumBins getNumBinsPerDim(RooArgSet const &vars)
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Return sampling hint for making curves of (projections) of this function as the recursive division st...
static Int_t GetNumBins(const RooArgSet &vars)
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Implement analytical integrations by doing appropriate weighting from component integrals functions t...
void setConstant(bool constant)
Int_t getCurrentBin() const
Get the index of the gamma parameter associated with the current bin.
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Advertise that all integrals can be handled internally.
RooObjCacheManager _normIntMgr
! The integration cache manager
double evaluate() const override
Find the bin corresponding to the current value of the observable, and evaluate the associated parame...
void doEval(RooFit::EvalContext &) const override
Find all bins corresponding to the values of the observables in ctx,.
RooAbsReal & getParameter() const
Int_t addParamSet(const RooArgList ¶ms)
static RooArgList createParamSet(RooWorkspace &w, const std::string &, const RooArgList &Vars)
Create the list of RooRealVar parameters which represent the height of the histogram bins.
void setParamConst(Int_t, bool=true)
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Return sampling hint for making curves of (projections) of this function as the recursive division st...
RooListProxy _paramSet
interpolation parameters
void setShape(TH1 *shape)
RooListProxy _dataVars
The RooRealVars.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
friend class RooWorkspace
Abstract base class for RooRealVar binning definitions.
virtual Int_t numBoundaries() const =0
virtual double * array() const =0
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
Abstract base class for objects that are lvalues, i.e.
virtual const RooAbsBinning * getBinningPtr(const char *rangeName) const =0
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Int_t numBins(const char *rangeName=nullptr) const override
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooAbsReal()
coverity[UNINIT_CTOR] Default constructor
bool _forceNumInt
Force numerical integration if flag set.
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.
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
TH1 is the base class of all histogram classes in ROOT.
virtual Int_t GetNbinsY() const
virtual Int_t GetNbinsZ() const
virtual Int_t GetNbinsX() const
Bool_t IsBinUnderflow(Int_t bin, Int_t axis=0) const
Return true if the bin is underflow.
Bool_t IsBinOverflow(Int_t bin, Int_t axis=0) const
Return true if the bin is overflow.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
const char * GetName() const override
Returns name of object.
Mother of all ROOT objects.
RooCmdArg RecycleConflictNodes(bool flag=true)