Skip to content
Open
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
12 changes: 6 additions & 6 deletions hist/histv7/test/hist_slice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,11 @@ TEST(RHistEngine, SliceSum)
engine.SetBinContent(RBinIndex::Underflow(), 0, 1000);
engine.SetBinContent(RBinIndex::Underflow(), 2, 2000);
for (std::size_t i = 0; i < Bins; i++) {
engine.SetBinContent(i, RBinIndex::Underflow(), 100 * i);
for (std::size_t j = 0; j < Bins; j++) {
engine.SetBinContent(i, RBinIndex::Underflow(), 100 * i);
engine.SetBinContent(i, RBinIndex(j), i * Bins + j);
engine.SetBinContent(i, RBinIndex::Overflow(), 200 * i);
engine.SetBinContent(i, j, i * Bins + j);
}
engine.SetBinContent(i, RBinIndex::Overflow(), 200 * i);
}
engine.SetBinContent(RBinIndex::Overflow(), 3, 3000);
engine.SetBinContent(RBinIndex::Overflow(), 6, 4000);
Expand All @@ -470,11 +470,11 @@ TEST(RHistEngine, SliceRangeSum)
engine.SetBinContent(RBinIndex::Underflow(), 0, 1000);
engine.SetBinContent(RBinIndex::Underflow(), 2, 2000);
for (std::size_t i = 0; i < Bins; i++) {
engine.SetBinContent(i, RBinIndex::Underflow(), 100 * i);
for (std::size_t j = 0; j < Bins; j++) {
engine.SetBinContent(i, RBinIndex::Underflow(), 100 * i);
engine.SetBinContent(i, RBinIndex(j), i * Bins + j);
engine.SetBinContent(i, RBinIndex::Overflow(), 200 * i);
engine.SetBinContent(i, j, i * Bins + j);
}
engine.SetBinContent(i, RBinIndex::Overflow(), 200 * i);
}
engine.SetBinContent(RBinIndex::Overflow(), 3, 3000);
engine.SetBinContent(RBinIndex::Overflow(), 6, 4000);
Expand Down
2 changes: 2 additions & 0 deletions hist/histv7util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ ROOT_STANDARD_LIBRARY_PACKAGE(ROOTHistUtil
HEADERS
ROOT/Hist/ConversionUtils.hxx
ROOT/Hist/ConvertToTH1.hxx
ROOT/Hist/ConvertToTH2.hxx
SOURCES
ConversionUtils.cxx
ConvertToTH1.cxx
ConvertToTH2.cxx
DEPENDENCIES
Core
Hist
Expand Down
120 changes: 120 additions & 0 deletions hist/histv7util/inc/ROOT/Hist/ConvertToTH2.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/// \file
/// \warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes.
/// Feedback is welcome!

#ifndef ROOT_Hist_ConvertToTH2
#define ROOT_Hist_ConvertToTH2

#include <ROOT/RBinWithError.hxx>
#include <ROOT/RHist.hxx>
#include <ROOT/RHistEngine.hxx>

class TH2C;
class TH2S;
class TH2I;
class TH2L;
class TH2F;
class TH2D;

#include <memory>

namespace ROOT {
namespace Experimental {
namespace Hist {

/// Convert a one-dimensional histogram to TH2C.
///
/// \copydetails ConvertToTH2I(const RHistEngine<int> &engine)
std::unique_ptr<TH2C> ConvertToTH2C(const RHistEngine<char> &engine);

/// Convert a one-dimensional histogram to TH2S.
///
/// \copydetails ConvertToTH2I(const RHistEngine<int> &engine)
std::unique_ptr<TH2S> ConvertToTH2S(const RHistEngine<short> &engine);

/// Convert a one-dimensional histogram to TH2I.
///
/// As RHistEngine does not have global statistics, the number of entries and the total sum of weights will be unset.
///
/// Throws an exception if the histogram has more than one dimension.
///
/// \param[in] engine the RHistEngine to convert
/// \return the converted TH2
std::unique_ptr<TH2I> ConvertToTH2I(const RHistEngine<int> &engine);

/// Convert a one-dimensional histogram to TH2L.
///
/// \copydetails ConvertToTH2I(const RHistEngine<int> &engine)
std::unique_ptr<TH2L> ConvertToTH2L(const RHistEngine<long> &engine);

/// Convert a one-dimensional histogram to TH2L.
///
/// \copydetails ConvertToTH2I(const RHistEngine<int> &engine)
std::unique_ptr<TH2L> ConvertToTH2L(const RHistEngine<long long> &engine);

/// Convert a one-dimensional histogram to TH2F.
///
/// \copydetails ConvertToTH2I(const RHistEngine<int> &engine)
std::unique_ptr<TH2F> ConvertToTH2F(const RHistEngine<float> &engine);

/// Convert a one-dimensional histogram to TH2D.
///
/// \copydetails ConvertToTH2I(const RHistEngine<int> &engine)
std::unique_ptr<TH2D> ConvertToTH2D(const RHistEngine<double> &engine);

/// Convert a one-dimensional histogram to TH2D.
///
/// \copydetails ConvertToTH2I(const RHistEngine<int> &engine)
std::unique_ptr<TH2D> ConvertToTH2D(const RHistEngine<RBinWithError> &engine);

/// Convert a one-dimensional histogram to TH2C.
///
/// \copydetails ConvertToTH2I(const RHist<int> &hist)
std::unique_ptr<TH2C> ConvertToTH2C(const RHist<char> &hist);

/// Convert a one-dimensional histogram to TH2S.
///
/// \copydetails ConvertToTH2I(const RHist<int> &hist)
std::unique_ptr<TH2S> ConvertToTH2S(const RHist<short> &hist);

/// Convert a one-dimensional histogram to TH2I.
///
/// If the RHistStats are tainted, for example after setting bin contents, the number of entries and the total sum of
/// weights will be unset.
///
/// Throws an exception if the histogram has more than one dimension.
///
/// \param[in] hist the RHist to convert
/// \return the converted TH2
std::unique_ptr<TH2I> ConvertToTH2I(const RHist<int> &hist);

/// Convert a one-dimensional histogram to TH2L.
///
/// \copydetails ConvertToTH2I(const RHist<int> &hist)
std::unique_ptr<TH2L> ConvertToTH2L(const RHist<long> &hist);

/// Convert a one-dimensional histogram to TH2L.
///
/// \copydetails ConvertToTH2I(const RHist<int> &hist)
std::unique_ptr<TH2L> ConvertToTH2L(const RHist<long long> &hist);

/// Convert a one-dimensional histogram to TH2F.
///
/// \copydetails ConvertToTH2I(const RHist<int> &hist)
std::unique_ptr<TH2F> ConvertToTH2F(const RHist<float> &hist);

/// Convert a one-dimensional histogram to TH2D.
///
/// \copydetails ConvertToTH2I(const RHist<int> &hist)
std::unique_ptr<TH2D> ConvertToTH2D(const RHist<double> &hist);

/// Convert a one-dimensional histogram to TH2D.
///
/// \copydetails ConvertToTH2I(const RHist<int> &hist)
std::unique_ptr<TH2D> ConvertToTH2D(const RHist<RBinWithError> &hist);

} // namespace Hist
} // namespace Experimental
} // namespace ROOT

#endif
12 changes: 8 additions & 4 deletions hist/histv7util/src/ConvertToTH1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ std::unique_ptr<Hist> ConvertToTH1Impl(const RHistEngine<T> &engine)
auto ret = std::make_unique<Hist>();
ret->SetDirectory(nullptr);

ROOT::Experimental::Hist::Internal::ConvertAxis(*ret->GetXaxis(), engine.GetAxes()[0]);
const auto &axis = engine.GetAxes()[0];
ROOT::Experimental::Hist::Internal::ConvertAxis(*ret->GetXaxis(), axis);
ret->SetBinsLength();

Double_t *sumw2 = nullptr;
Expand All @@ -51,7 +52,6 @@ std::unique_ptr<Hist> ConvertToTH1Impl(const RHistEngine<T> &engine)
};

// Copy the bin contents, accounting for TH1 numbering conventions.
const auto &axis = engine.GetAxes()[0];
for (auto index : axis.GetFullRange()) {
if (index.IsUnderflow()) {
copyBinContent(0, index);
Expand All @@ -78,9 +78,13 @@ void ConvertGlobalStatistics(Hist &h, const RHistStats &stats)
Double_t hStats[4] = {
stats.GetSumW(),
stats.GetSumW2(),
stats.GetDimensionStats(0).fSumWX,
stats.GetDimensionStats(0).fSumWX2,
0,
0,
};
if (stats.IsEnabled(0)) {
hStats[2] = stats.GetDimensionStats(0).fSumWX;
hStats[3] = stats.GetDimensionStats(0).fSumWX2;
}
h.PutStats(hStats);
}
} // namespace
Expand Down
Loading
Loading