Skip to content

Commit 523c258

Browse files
authored
[RF] Add flag to globally enable or disable all RooBinWidthFunctions
With the (very useful) introduction of the RooBinWidthFunction, the bin width correction moved from the "coefficient" branch of the RooRealSumPdf to the "function" branch of the RooRealSumPdf in HistFactory. This can cause some distress for users who meddle with histfactory models by hand, because bin correction can now appear at places that are different from what they were originally. This commit adds a flag to globally disable all bin width corrections of RooBinWidthFunction, allowing the user to switch an entire model from density-mode to eventcount-mode.
1 parent 9cee6b1 commit 523c258

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

roofit/roofitcore/inc/RooBinWidthFunction.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@
2525
namespace BatchHelpers { struct RunContext; }
2626

2727
class RooBinWidthFunction : public RooAbsReal {
28-
public:
28+
static bool _enabled;
29+
30+
public:
31+
static void enableClass();
32+
static void disableClass();
33+
static bool isClassEnabled();
34+
2935
/// Create an empty instance.
3036
RooBinWidthFunction() :
3137
_histFunc("HistFuncForBinWidth", "Handle to a RooHistFunc, whose bin volumes should be returned.", this,

roofit/roofitcore/src/RooBinWidthFunction.cxx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,28 @@
2929
#include "RooDataHist.h"
3030
#include "RunContext.h"
3131

32+
bool RooBinWidthFunction::_enabled = true;
33+
34+
/// Globally enable bin-width corrections by this class.
35+
void RooBinWidthFunction::enableClass() {
36+
_enabled = true;
37+
}
38+
39+
/// Returns `true` if bin-width corrections by this class are globally enabled, `false` otherwise.
40+
bool RooBinWidthFunction::isClassEnabled() {
41+
return _enabled;
42+
}
43+
44+
/// Globally disable bin-width corrections by this class.
45+
void RooBinWidthFunction::disableClass() {
46+
_enabled = false;
47+
}
3248

3349
/// Compute current bin of observable, and return its volume or inverse volume, depending
3450
/// on configuration chosen in the constructor.
3551
/// If the bin is not valid, return a volume of 1.
3652
double RooBinWidthFunction::evaluate() const {
53+
if(!_enabled) return 1.;
3754
const RooDataHist& dataHist = _histFunc->dataHist();
3855
const auto idx = _histFunc->getBin();
3956
auto volumes = dataHist.binVolumes(0, dataHist.numEntries());
@@ -51,13 +68,19 @@ void RooBinWidthFunction::computeBatch(cudaStream_t*, double* output, size_t, Ro
5168
std::vector<Int_t> bins = _histFunc->getBins(dataMap);
5269
auto volumes = dataHist.binVolumes(0, dataHist.numEntries());
5370

54-
if (_divideByBinWidth) {
71+
if(!_enabled){
5572
for (std::size_t i=0; i < bins.size(); ++i) {
56-
output[i] = bins[i] >= 0 ? 1./volumes[bins[i]] : 1.;
73+
output[i] = 1.;
5774
}
5875
} else {
59-
for (std::size_t i=0; i < bins.size(); ++i) {
60-
output[i] = bins[i] >= 0 ? volumes[bins[i]] : 1.;
76+
if (_divideByBinWidth) {
77+
for (std::size_t i=0; i < bins.size(); ++i) {
78+
output[i] = bins[i] >= 0 ? 1./volumes[bins[i]] : 1.;
79+
}
80+
} else {
81+
for (std::size_t i=0; i < bins.size(); ++i) {
82+
output[i] = bins[i] >= 0 ? volumes[bins[i]] : 1.;
83+
}
6184
}
6285
}
6386
}

0 commit comments

Comments
 (0)