Skip to content

Commit

Permalink
[RF] Move RooFit headers not starting with Roo in RooFit directory
Browse files Browse the repository at this point in the history
In the v6.26 development cycle cycle, some RooFit helper header files
whose names don't start with the `Roo` prefix sneaked into the
RooFitCore library. These headers have the overly generic names
`Floats.h` and `UniqueId.h`, which calls for trouble in environments
where the ROOT headers are directly installed in the main system include
path (most Linux distributions).

To prevent any possible issues, this commit proposes and follows new
conventions for RooFit headers:

  * Installed RooFit headers must start with `Roo*` or must be located
    in a subdirectory starting with `Roo*` (e.g. RooFit or RooStats).
  * Similarly, if the class name doesn't start with Roo, it has to go in
    a `Roo*` namespace (usually `RooFit`)
  * Free functions always need to go in this namespace
  * For implmentation details that we can't avoid installing, we can use
    a `Roo*::Detail` namespace like we have with `ROOT::Detail` (same
    with `Experimental`)

We should also keep in mind what we established in PR #9078:

  * `inc/` is for installed headers
  * `res/` is for headers that are only used at compile time of other
    ROOT components
  * Headers only used within a library go to `src/`

This means that there is no need in specifiying the headers to install
manually in `roofit/rofitcore/CMakeLists.txt`. We can glob for all the
headers fulfilling the criteria above.
  • Loading branch information
guitargeek committed Dec 9, 2021
1 parent 6f74191 commit c9aa695
Show file tree
Hide file tree
Showing 44 changed files with 230 additions and 207 deletions.
4 changes: 2 additions & 2 deletions roofit/roofit/inc/RooLagrangianMorphFunc.h
Expand Up @@ -52,7 +52,7 @@
#ifndef ROO_LAGRANGIAN_MORPH
#define ROO_LAGRANGIAN_MORPH

#include "Floats.h"
#include "RooFit/Floats.h"
#include "RooAbsArg.h"
#include "RooAbsReal.h"
#include "RooArgList.h"
Expand Down Expand Up @@ -212,7 +212,7 @@ class RooLagrangianMorphFunc : public RooAbsReal {

public:
/// length of floating point digits precision supported by implementation.
static constexpr double implementedPrecision = SuperFloatPrecision::digits10;
static constexpr double implementedPrecision = RooFit::SuperFloatPrecision::digits10;
void importToWorkspace(RooWorkspace *ws, const RooAbsReal *object);
void importToWorkspace(RooWorkspace *ws, RooAbsData *object);

Expand Down
26 changes: 13 additions & 13 deletions roofit/roofit/src/RooLagrangianMorphFunc.cxx
Expand Up @@ -118,7 +118,7 @@ void writeMatrixToStreamT(const MatrixT &matrix, std::ostream &stream) {
for (size_t i = 0; i < size(matrix); ++i) {
for (size_t j = 0; j < size(matrix); ++j) {
#ifdef USE_UBLAS
stream << std::setprecision(SuperFloatPrecision::digits10) << matrix(i, j)
stream << std::setprecision(RooFit::SuperFloatPrecision::digits10) << matrix(i, j)
<< "\t";
#else
stream << matrix(i, j) << "\t";
Expand Down Expand Up @@ -157,15 +157,15 @@ inline void writeMatrixToFileT(const MatrixT &matrix, const char *fname) {

#pragma GCC diagnostic pop

typedef boost::numeric::ublas::matrix<SuperFloat> Matrix;
typedef boost::numeric::ublas::matrix<RooFit::SuperFloat> Matrix;

////////////////////////////////////////////////////////////////////////////////
/// write a matrix

inline void printMatrix(const Matrix &mat) {
for (size_t i = 0; i < mat.size1(); ++i) {
for (size_t j = 0; j < mat.size2(); ++j) {
// std::cout << std::setprecision(SuperFloatPrecision::digits10) <<
// std::cout << std::setprecision(RooFit::SuperFloatPrecision::digits10) <<
// mat(i,j) << " ,\t";
}
std::cout << std::endl;
Expand All @@ -183,7 +183,7 @@ template <> inline size_t size<Matrix>(const Matrix &matrix) {
/// create a new diagonal matrix of size n

inline Matrix diagMatrix(size_t n) {
return boost::numeric::ublas::identity_matrix<SuperFloat>(n);
return boost::numeric::ublas::identity_matrix<RooFit::SuperFloat>(n);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -222,9 +222,9 @@ inline Matrix operator*(const Matrix &m, const Matrix &otherM) {
////////////////////////////////////////////////////////////////////////////////
/// calculate the inverse of a matrix, returning the condition

inline SuperFloat invertMatrix(const Matrix &matrix, Matrix &inverse) {
inline RooFit::SuperFloat invertMatrix(const Matrix &matrix, Matrix &inverse) {
boost::numeric::ublas::permutation_matrix<size_t> pm(size(matrix));
SuperFloat mnorm = norm_inf(matrix);
RooFit::SuperFloat mnorm = norm_inf(matrix);
Matrix lu(matrix);
try {
int res = lu_factorize(lu, pm);
Expand All @@ -239,8 +239,8 @@ inline SuperFloat invertMatrix(const Matrix &matrix, Matrix &inverse) {
// coutE(Eval) << "boost::numberic::ublas error: matrix is not invertible!"
// << std::endl;
}
SuperFloat inorm = norm_inf(inverse);
SuperFloat condition = mnorm * inorm;
RooFit::SuperFloat inorm = norm_inf(inverse);
RooFit::SuperFloat condition = mnorm * inorm;
return condition;
}

Expand Down Expand Up @@ -359,15 +359,15 @@ template <class A, class B> inline void assignElement(A &a, const B &b) {

template <class MatrixT>
inline MatrixT readMatrixFromStreamT(std::istream &stream) {
std::vector<std::vector<SuperFloat>> matrix;
std::vector<SuperFloat> line;
std::vector<std::vector<RooFit::SuperFloat>> matrix;
std::vector<RooFit::SuperFloat> line;
while (!stream.eof()) {
if (stream.peek() == '\n') {
stream.get();
stream.peek();
continue;
}
SuperFloat val;
RooFit::SuperFloat val;
stream >> val;
line.push_back(val);
while (stream.peek() == ' ' || stream.peek() == '\t') {
Expand Down Expand Up @@ -1358,7 +1358,7 @@ buildSampleWeights(T1 &weights, const char *fname,
// build the formula with the correct normalization
RooLinearCombination *sampleformula = new RooLinearCombination(name_full.Data());
for (auto const &formulait : formulas) {
const SuperFloat val(inverse(formulaidx, sampleidx));
const RooFit::SuperFloat val(inverse(formulaidx, sampleidx));
sampleformula->add(val, formulait.second.get());
formulaidx++;
}
Expand Down Expand Up @@ -1854,7 +1854,7 @@ inline void RooLagrangianMorphFunc::updateSampleWeights() {
cxcoutP(ObjectHandling)
<< "updating formula for sample '" << sample << "'" << std::endl;
for (size_t formulaidx = 0; formulaidx < n; ++formulaidx) {
const SuperFloat val(cache->_inverse(formulaidx, sampleidx));
const RooFit::SuperFloat val(cache->_inverse(formulaidx, sampleidx));
#ifdef USE_UBLAS
if (val != val) {
#else
Expand Down
28 changes: 14 additions & 14 deletions roofit/roofitcore/CMakeLists.txt
Expand Up @@ -15,7 +15,7 @@ endif()

ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore
HEADERS
Floats.h
RooFit/Floats.h
Roo1DTable.h
RooAbsAnaConvPdf.h
RooAbsArg.h
Expand Down Expand Up @@ -237,19 +237,19 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore
RooFitLegacy/RooNameSet.h
RooFitLegacy/RooSetPair.h
RooFitLegacy/RooTreeData.h
TestStatistics/ConstantTermsOptimizer.h
TestStatistics/LikelihoodGradientWrapper.h
TestStatistics/LikelihoodWrapper.h
TestStatistics/LikelihoodSerial.h
TestStatistics/MinuitFcnGrad.h
TestStatistics/RooAbsL.h
TestStatistics/RooBinnedL.h
TestStatistics/RooSubsidiaryL.h
TestStatistics/RooSumL.h
TestStatistics/RooRealL.h
TestStatistics/RooUnbinnedL.h
TestStatistics/optional_parameter_types.h
TestStatistics/buildLikelihood.h
RooFit/TestStatistics/ConstantTermsOptimizer.h
RooFit/TestStatistics/LikelihoodGradientWrapper.h
RooFit/TestStatistics/LikelihoodWrapper.h
RooFit/TestStatistics/LikelihoodSerial.h
RooFit/TestStatistics/MinuitFcnGrad.h
RooFit/TestStatistics/RooAbsL.h
RooFit/TestStatistics/RooBinnedL.h
RooFit/TestStatistics/RooSubsidiaryL.h
RooFit/TestStatistics/RooSumL.h
RooFit/TestStatistics/RooRealL.h
RooFit/TestStatistics/RooUnbinnedL.h
RooFit/TestStatistics/optional_parameter_types.h
RooFit/TestStatistics/buildLikelihood.h
SOURCES
src/BidirMMapPipe.cxx
src/BidirMMapPipe.h
Expand Down
26 changes: 0 additions & 26 deletions roofit/roofitcore/inc/Floats.h

This file was deleted.

2 changes: 1 addition & 1 deletion roofit/roofitcore/inc/RooAddPdf.h
Expand Up @@ -145,7 +145,7 @@ class RooAddPdf : public RooAbsPdf {

private:
std::pair<const RooArgSet*, CacheElem*> getNormAndCache(const RooArgSet* defaultNorm = nullptr) const;
mutable UniqueId<RooArgSet>::Value_t _idOfLastUsedNormSet = UniqueId<RooArgSet>::nullval; //!
mutable RooFit::UniqueId<RooArgSet>::Value_t _idOfLastUsedNormSet = RooFit::UniqueId<RooArgSet>::nullval; //!
mutable std::unique_ptr<const RooArgSet> _copyOfLastNormSet = nullptr; //!

void finalizeConstruction();
Expand Down
6 changes: 3 additions & 3 deletions roofit/roofitcore/inc/RooArgSet.h
Expand Up @@ -18,7 +18,7 @@

#include "RooAbsCollection.h"
#include "RooAbsArg.h"
#include "UniqueId.h"
#include "RooFit/UniqueId.h"


class RooArgList ;
Expand Down Expand Up @@ -164,7 +164,7 @@ class RooArgSet : public RooAbsCollection {
/// This ID can be used to check whether two RooAbsData are the same object,
/// which is safer than memory address comparisons that might result in false
/// positives when memory is recycled.
UniqueId<RooArgSet> const& uniqueId() const { return _uniqueId; }
RooFit::UniqueId<RooArgSet> const& uniqueId() const { return _uniqueId; }

protected:
Bool_t checkForDup(const RooAbsArg& arg, Bool_t silent) const ;
Expand Down Expand Up @@ -203,7 +203,7 @@ class RooArgSet : public RooAbsCollection {
//to leak depending if RooArgSets are still alive. This depends on the order of destructions.
static MemPool* memPool();
#endif
const UniqueId<RooArgSet> _uniqueId; //!
const RooFit::UniqueId<RooArgSet> _uniqueId; //!

ClassDefOverride(RooArgSet,1) // Set of RooAbsArg objects
};
Expand Down
35 changes: 35 additions & 0 deletions roofit/roofitcore/inc/RooFit/Floats.h
@@ -0,0 +1,35 @@
/*
* Project: RooFit
* Authors:
* Lydia Brenner (lbrenner@cern.ch), Carsten Burgard (cburgard@cern.ch)
* Katharina Ecker (kecker@cern.ch), Adam Kaluza (akaluza@cern.ch)
*
* Copyright (c) 2021, CERN
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted according to the terms
* listed in LICENSE (http://roofit.sourceforge.net/license.txt)
*/

#ifndef roofit_roofitcore_RooFit_Floats_h
#define roofit_roofitcore_RooFit_Floats_h

#ifdef USE_UBLAS
#include <boost/multiprecision/cpp_dec_float.hpp>
#endif

#include <limits>

namespace RooFit {

#ifdef USE_UBLAS
typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<100>> SuperFloat;
typedef std::numeric_limits<SuperFloat> SuperFloatPrecision;
#else
typedef double SuperFloat;
typedef std::numeric_limits<double> SuperFloatPrecision;
#endif

} // namespace RooFit

#endif
Expand Up @@ -14,7 +14,7 @@
#ifndef ROOT_ROOFIT_LikelihoodSerial
#define ROOT_ROOFIT_LikelihoodSerial

#include <TestStatistics/LikelihoodWrapper.h>
#include <RooFit/TestStatistics/LikelihoodWrapper.h>
#include "RooArgList.h"

#include "Math/MinimizerOptions.h"
Expand Down
Expand Up @@ -15,9 +15,9 @@

#include "RooArgList.h"
#include "RooRealVar.h"
#include "TestStatistics/RooAbsL.h"
#include "TestStatistics/LikelihoodWrapper.h"
#include "TestStatistics/LikelihoodGradientWrapper.h"
#include <RooFit/TestStatistics/RooAbsL.h>
#include <RooFit/TestStatistics/LikelihoodWrapper.h>
#include <RooFit/TestStatistics/LikelihoodGradientWrapper.h>
#include "RooAbsMinimizerFcn.h"

#include <Fit/ParameterSettings.h>
Expand Down
Expand Up @@ -13,7 +13,7 @@
#ifndef ROOT_ROOFIT_TESTSTATISTICS_RooBinnedL
#define ROOT_ROOFIT_TESTSTATISTICS_RooBinnedL

#include <TestStatistics/RooAbsL.h>
#include <RooFit/TestStatistics/RooAbsL.h>
#include "RooAbsReal.h"
#include <vector>

Expand Down
Expand Up @@ -13,7 +13,7 @@
#ifndef ROOT_ROOFIT_TESTSTATISTICS_RooSubsidiaryL
#define ROOT_ROOFIT_TESTSTATISTICS_RooSubsidiaryL

#include "TestStatistics/RooAbsL.h"
#include <RooFit/TestStatistics/RooAbsL.h>
#include "RooArgList.h"
#include "RooArgSet.h"

Expand Down
Expand Up @@ -13,8 +13,8 @@
#ifndef ROOT_ROOFIT_TESTSTATISTICS_RooSumL
#define ROOT_ROOFIT_TESTSTATISTICS_RooSumL

#include "TestStatistics/RooAbsL.h"
#include "TestStatistics/optional_parameter_types.h"
#include <RooFit/TestStatistics/RooAbsL.h>
#include <RooFit/TestStatistics/optional_parameter_types.h>

#include "Math/Util.h" // KahanSum

Expand Down
Expand Up @@ -13,7 +13,7 @@
#ifndef ROOT_ROOFIT_TESTSTATISTICS_RooUnbinnedL
#define ROOT_ROOFIT_TESTSTATISTICS_RooUnbinnedL

#include <TestStatistics/RooAbsL.h>
#include <RooFit/TestStatistics/RooAbsL.h>

// forward declarations
class RooAbsPdf;
Expand Down
Expand Up @@ -13,8 +13,8 @@
#ifndef ROOT_ROOFIT_TESTSTATISTICS_likelihood_builders
#define ROOT_ROOFIT_TESTSTATISTICS_likelihood_builders

#include "TestStatistics/RooAbsL.h"
#include "TestStatistics/optional_parameter_types.h"
#include <RooFit/TestStatistics/RooAbsL.h>
#include <RooFit/TestStatistics/optional_parameter_types.h>

#include <memory>

Expand Down

0 comments on commit c9aa695

Please sign in to comment.