Skip to content

Commit cfc1b7a

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 c3f7019 commit cfc1b7a

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

roofit/roofitcore/inc/RooNumRunningInt.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class RooNumRunningInt : public RooAbsCachedReal {
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) ;
2626
TObject* clone(const char* newname=nullptr) const override { return new RooNumRunningInt(*this,newname); }
27-
~RooNumRunningInt() override ;
2827

2928
protected:
3029

@@ -39,7 +38,7 @@ class RooNumRunningInt : public RooAbsCachedReal {
3938
RooNumRunningInt* _self ;
4039
std::vector<double> _ax ;
4140
std::vector<double> _ay ;
42-
RooRealVar* _xx ;
41+
RooArgSet _xx ;
4342

4443
} ;
4544

roofit/roofitcore/src/RooNumRunningInt.cxx

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +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-
4238

4339
////////////////////////////////////////////////////////////////////////////////
4440
/// Construct running integral of function '_func' over x_print from
@@ -71,26 +67,17 @@ RooNumRunningInt::RooNumRunningInt(const RooNumRunningInt& other, const char* na
7167
}
7268

7369

74-
75-
////////////////////////////////////////////////////////////////////////////////
76-
/// Destructor
77-
78-
RooNumRunningInt::~RooNumRunningInt()
79-
{
80-
}
81-
82-
8370
////////////////////////////////////////////////////////////////////////////////
8471
/// Return unique name for RooAbsCachedPdf cache components
8572
/// constructed from input function name
8673

8774
const char* RooNumRunningInt::inputBaseName() const
8875
{
89-
static string ret ;
76+
static std::string ret ;
9077
ret = func.arg().GetName() ;
9178
ret += "_NUMRUNINT" ;
9279
return ret.c_str() ;
93-
} ;
80+
}
9481

9582

9683

@@ -100,7 +87,7 @@ const char* RooNumRunningInt::inputBaseName() const
10087
RooNumRunningInt::RICacheElem::RICacheElem(const RooNumRunningInt &self, const RooArgSet *nset)
10188
: FuncCacheElem(self, nset),
10289
_self(&const_cast<RooNumRunningInt &>(self)),
103-
_xx(static_cast<RooRealVar *>(hist()->get()->find(self.x.arg().GetName())))
90+
_xx(*hist()->get()->find(self.x.arg().GetName()))
10491
{
10592
// Instantiate temp arrays
10693
_ax.resize(hist()->numEntries());
@@ -110,7 +97,7 @@ RooNumRunningInt::RICacheElem::RICacheElem(const RooNumRunningInt &self, const R
11097

11198
for (int i=0 ; i<hist()->numEntries() ; i++) {
11299
hist()->get(i) ;
113-
_ax[i] = _xx->getVal() ;
100+
_ax[i] = static_cast<RooRealVar*>(_xx.first())->getVal() ;
114101
_ay[i] = -1 ;
115102
}
116103

@@ -125,7 +112,7 @@ RooArgList RooNumRunningInt::RICacheElem::containedArgs(Action action)
125112
RooArgList ret ;
126113
ret.add(FuncCacheElem::containedArgs(action)) ;
127114
ret.add(*_self) ;
128-
ret.add(*_xx) ;
115+
ret.add(_xx) ;
129116
return ret ;
130117
}
131118

@@ -234,8 +221,8 @@ void RooNumRunningInt::RICacheElem::addRange(Int_t ixlo, Int_t ixhi, Int_t nbins
234221
void RooNumRunningInt::RICacheElem::addPoint(Int_t ix)
235222
{
236223
hist()->get(ix) ;
237-
_self->x = _xx->getVal() ;
238-
_ay[ix] = _self->func.arg().getVal(*_xx) ;
224+
_self->x = static_cast<RooRealVar*>(_xx.first())->getVal() ;
225+
_ay[ix] = _self->func.arg().getVal(_xx) ;
239226

240227
}
241228

@@ -295,5 +282,3 @@ double RooNumRunningInt::evaluate() const
295282
std::cout << "RooNumRunningInt::evaluate(" << GetName() << ")" << std::endl ;
296283
return 0 ;
297284
}
298-
299-

0 commit comments

Comments
 (0)