32 ClassImp(RooParamHistFunc);
37 RooParamHistFunc::RooParamHistFunc(
const char *name,
const char *title, RooDataHist& dh, Bool_t paramRelative) :
38 RooAbsReal(name,title),
42 _relParam(paramRelative)
48 for (Int_t i=0 ; i<_dh.numEntries() ; i++) {
51 const char* vname = Form(
"%s_gamma_bin_%i",GetName(),i) ;
52 RooRealVar* var =
new RooRealVar(vname,vname,0,1000) ;
53 var->setVal(_relParam ? 1 : _dh.weight()) ;
54 var->setError(_relParam ? 1 / sqrt(_dh.weight()) : sqrt(_dh.weight()));
55 var->setConstant(kTRUE) ;
59 addOwnedComponents(allVars) ;
65 RooParamHistFunc::RooParamHistFunc(
const char *name,
const char *title,
const RooAbsArg& , RooDataHist& dh, Bool_t paramRelative) :
66 RooAbsReal(name,title),
70 _relParam(paramRelative)
76 for (Int_t i=0 ; i<_dh.numEntries() ; i++) {
78 const char* vname = Form(
"%s_gamma_bin_%i",GetName(),i) ;
79 RooRealVar* var =
new RooRealVar(vname,vname,0,1000) ;
80 var->setVal(_relParam ? 1 : _dh.weight()) ;
81 var->setError(_relParam ? 1 / sqrt(_dh.weight()) : sqrt(_dh.weight()));
82 var->setConstant(kTRUE) ;
86 addOwnedComponents(allVars) ;
91 RooParamHistFunc::RooParamHistFunc(
const char *name,
const char *title, RooDataHist& dh,
const RooParamHistFunc& paramSource, Bool_t paramRelative) :
92 RooAbsReal(name,title),
96 _relParam(paramRelative)
102 _p.add(paramSource._p) ;
107 RooParamHistFunc::RooParamHistFunc(
const RooParamHistFunc& other,
const char* name) :
108 RooAbsReal(other,name),
109 _x(
"x",this,other._x),
110 _p(
"p",this,other._p),
112 _relParam(other._relParam)
118 Double_t RooParamHistFunc::evaluate()
const
120 Int_t idx = ((RooDataHist&)_dh).getIndex(_x,kTRUE) ;
121 Double_t ret = ((RooAbsReal*)_p.at(idx))->getVal() ;
123 Double_t nom = getNominal(idx) ;
131 Double_t RooParamHistFunc::getActual(Int_t ibin)
133 return ((RooAbsReal&)_p[ibin]).getVal() ;
138 void RooParamHistFunc::setActual(Int_t ibin, Double_t newVal)
140 ((RooRealVar&)_p[ibin]).setVal(newVal) ;
145 Double_t RooParamHistFunc::getNominal(Int_t ibin)
const
148 return _dh.weight() ;
153 Double_t RooParamHistFunc::getNominalError(Int_t ibin)
const
156 return _dh.weightError() ;
164 list<Double_t>* RooParamHistFunc::plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi)
const
167 RooAbsLValue* lvarg =
dynamic_cast<RooAbsLValue*
>(_dh.get()->find(obs.GetName())) ;
173 const RooAbsBinning* binning = lvarg->getBinningPtr(0) ;
174 Double_t* boundaries = binning->array() ;
176 list<Double_t>* hint =
new list<Double_t> ;
179 xlo = xlo - 0.01*(xhi-xlo) ;
180 xhi = xhi + 0.01*(xhi-xlo) ;
182 Double_t delta = (xhi-xlo)*1e-8 ;
186 for (Int_t i=0 ; i<binning->numBoundaries() ; i++) {
187 if (boundaries[i]>=xlo && boundaries[i]<=xhi) {
188 hint->push_back(boundaries[i]-delta) ;
189 hint->push_back(boundaries[i]+delta) ;
201 std::list<Double_t>* RooParamHistFunc::binBoundaries(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi)
const
204 RooAbsLValue* lvarg =
dynamic_cast<RooAbsLValue*
>(_dh.get()->find(obs.GetName())) ;
210 const RooAbsBinning* binning = lvarg->getBinningPtr(0) ;
211 Double_t* boundaries = binning->array() ;
213 list<Double_t>* hint =
new list<Double_t> ;
217 for (Int_t i=0 ; i<binning->numBoundaries() ; i++) {
218 if (boundaries[i]>=xlo && boundaries[i]<=xhi) {
219 hint->push_back(boundaries[i]) ;
229 Int_t RooParamHistFunc::getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars,
230 const RooArgSet* ,
const char* )
const
233 RooAbsCollection *allVarsCommon = allVars.selectCommon(_x) ;
234 Bool_t intAllObs = (allVarsCommon->getSize()==_x.getSize()) ;
235 delete allVarsCommon ;
236 if (intAllObs && matchArgs(allVars,analVars,_x)) {
247 Double_t RooParamHistFunc::analyticalIntegralWN(Int_t code,
const RooArgSet* ,
const char* )
const
253 for (
const auto param : _p) {
254 auto p =
static_cast<const RooAbsReal*
>(param);
255 Double_t bin = p->getVal() ;
256 if (_relParam) bin *= getNominal(i++) ;
262 for (
const auto obs : _x) {
263 auto xx =
static_cast<const RooRealVar*
>(obs);
264 binV *= (xx->getMax()-xx->getMin())/xx->numBins() ;