Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion roofit/roofitcore/inc/RooBinWidthFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
namespace BatchHelpers { struct RunContext; }

class RooBinWidthFunction : public RooAbsReal {
public:
static bool _enabled;

public:
static void enableClass();
static void disableClass();
static bool isClassEnabled();

/// Create an empty instance.
RooBinWidthFunction() :
_histFunc("HistFuncForBinWidth", "Handle to a RooHistFunc, whose bin volumes should be returned.", this,
Expand Down
31 changes: 27 additions & 4 deletions roofit/roofitcore/src/RooBinWidthFunction.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,28 @@
#include "RooDataHist.h"
#include "RunContext.h"

bool RooBinWidthFunction::_enabled = true;

/// Globally enable bin-width corrections by this class.
void RooBinWidthFunction::enableClass() {
_enabled = true;
}

/// Returns `true` if bin-width corrections by this class are globally enabled, `false` otherwise.
bool RooBinWidthFunction::isClassEnabled() {
return _enabled;
}

/// Globally disable bin-width corrections by this class.
void RooBinWidthFunction::disableClass() {
_enabled = false;
}

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

if (_divideByBinWidth) {
if(!_enabled){
for (std::size_t i=0; i < bins.size(); ++i) {
output[i] = bins[i] >= 0 ? 1./volumes[bins[i]] : 1.;
output[i] = 1.;
}
} else {
for (std::size_t i=0; i < bins.size(); ++i) {
output[i] = bins[i] >= 0 ? volumes[bins[i]] : 1.;
if (_divideByBinWidth) {
for (std::size_t i=0; i < bins.size(); ++i) {
output[i] = bins[i] >= 0 ? 1./volumes[bins[i]] : 1.;
}
} else {
for (std::size_t i=0; i < bins.size(); ++i) {
output[i] = bins[i] >= 0 ? volumes[bins[i]] : 1.;
}
}
}
}