Skip to content

Commit 8f58ae3

Browse files
committed
[RF] Avoid implicit creation of normalization set in RooNumRunningInt
Fixes this error when using the RooNumRunningInt class: ``` what(): calling RooAbsReal::getVal() with r-value references to the normalization set is not allowed, because it breaks RooFits caching logic and potentially introduces significant overhead. Please explicitly create the RooArgSet outside the call to getVal(). ```
1 parent 4731fd5 commit 8f58ae3

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

roofit/roofitcore/inc/RooNumRunningInt.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ class RooNumRunningInt : public RooAbsCachedReal {
2323
public:
2424
RooNumRunningInt(const char *name, const char *title, RooAbsReal& _func, RooRealVar& _x, const char* binningName="cache");
2525
RooNumRunningInt(const RooNumRunningInt& other, const char* name=nullptr) ;
26-
TObject* clone(const char* newname=nullptr) const override { return new RooNumRunningInt(*this,newname); }
27-
~RooNumRunningInt() override ;
26+
TObject *clone(const char *newname = nullptr) const override { return new RooNumRunningInt(*this, newname); }
2827

29-
protected:
28+
protected:
3029

3130
class RICacheElem: public FuncCacheElem {
3231
public:
@@ -39,8 +38,7 @@ class RooNumRunningInt : public RooAbsCachedReal {
3938
RooNumRunningInt* _self ;
4039
std::vector<double> _ax ;
4140
std::vector<double> _ay ;
42-
RooRealVar* _xx ;
43-
41+
RooArgSet _xx;
4442
} ;
4543

4644
friend class RICacheElem ;

roofit/roofitcore/src/RooNumRunningInt.cxx

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ when any of the parameters of the input p.d.f. has changed.
3535
#include "RooHistPdf.h"
3636
#include "RooRealVar.h"
3737

38-
using std::string;
39-
40-
41-
42-
4338
////////////////////////////////////////////////////////////////////////////////
4439
/// Construct running integral of function '_func' over x_print from
4540
/// the lower bound on _x to the present value of _x using a numeric
@@ -70,37 +65,25 @@ RooNumRunningInt::RooNumRunningInt(const RooNumRunningInt& other, const char* na
7065
{
7166
}
7267

73-
74-
75-
////////////////////////////////////////////////////////////////////////////////
76-
/// Destructor
77-
78-
RooNumRunningInt::~RooNumRunningInt()
79-
{
80-
}
81-
82-
8368
////////////////////////////////////////////////////////////////////////////////
8469
/// Return unique name for RooAbsCachedPdf cache components
8570
/// constructed from input function name
8671

8772
const char* RooNumRunningInt::inputBaseName() const
8873
{
89-
static string ret ;
90-
ret = func.arg().GetName() ;
91-
ret += "_NUMRUNINT" ;
92-
return ret.c_str() ;
93-
} ;
94-
95-
74+
static std::string ret;
75+
ret = func.arg().GetName();
76+
ret += "_NUMRUNINT";
77+
return ret.c_str();
78+
}
9679

9780
////////////////////////////////////////////////////////////////////////////////
9881
/// Construct RunningIntegral CacheElement
9982

10083
RooNumRunningInt::RICacheElem::RICacheElem(const RooNumRunningInt &self, const RooArgSet *nset)
10184
: FuncCacheElem(self, nset),
10285
_self(&const_cast<RooNumRunningInt &>(self)),
103-
_xx(static_cast<RooRealVar *>(hist()->get()->find(self.x.arg().GetName())))
86+
_xx(*hist()->get()->find(self.x.arg().GetName()))
10487
{
10588
// Instantiate temp arrays
10689
_ax.resize(hist()->numEntries());
@@ -110,7 +93,7 @@ RooNumRunningInt::RICacheElem::RICacheElem(const RooNumRunningInt &self, const R
11093

11194
for (int i=0 ; i<hist()->numEntries() ; i++) {
11295
hist()->get(i) ;
113-
_ax[i] = _xx->getVal() ;
96+
_ax[i] = static_cast<RooRealVar *>(_xx.first())->getVal();
11497
_ay[i] = -1 ;
11598
}
11699

@@ -125,7 +108,7 @@ RooArgList RooNumRunningInt::RICacheElem::containedArgs(Action action)
125108
RooArgList ret ;
126109
ret.add(FuncCacheElem::containedArgs(action)) ;
127110
ret.add(*_self) ;
128-
ret.add(*_xx) ;
111+
ret.add(_xx);
129112
return ret ;
130113
}
131114

@@ -234,9 +217,8 @@ void RooNumRunningInt::RICacheElem::addRange(Int_t ixlo, Int_t ixhi, Int_t nbins
234217
void RooNumRunningInt::RICacheElem::addPoint(Int_t ix)
235218
{
236219
hist()->get(ix) ;
237-
_self->x = _xx->getVal() ;
238-
_ay[ix] = _self->func.arg().getVal(*_xx) ;
239-
220+
_self->x = static_cast<RooRealVar *>(_xx.first())->getVal();
221+
_ay[ix] = _self->func.arg().getVal(_xx);
240222
}
241223

242224

@@ -295,5 +277,3 @@ double RooNumRunningInt::evaluate() const
295277
std::cout << "RooNumRunningInt::evaluate(" << GetName() << ")" << std::endl ;
296278
return 0 ;
297279
}
298-
299-

0 commit comments

Comments
 (0)