-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[df] First integration of RHist filling
#20664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,13 @@ | |
| #include "TProfile2D.h" | ||
| #include "TStatistic.h" | ||
|
|
||
| #include "RConfigure.h" // for R__HAS_ROOT7 | ||
| #ifdef R__HAS_ROOT7 | ||
| #include <ROOT/RBinWithError.hxx> | ||
| #include <ROOT/RHist.hxx> | ||
| #include <ROOT/RHistEngine.hxx> | ||
| #endif | ||
|
|
||
| #include <algorithm> | ||
| #include <cstddef> | ||
| #include <initializer_list> | ||
|
|
@@ -2357,6 +2364,142 @@ public: | |
| columnList, h, h, fProxiedPtr, columnList.size()); | ||
| } | ||
|
|
||
| #ifdef R__HAS_ROOT7 | ||
| //////////////////////////////////////////////////////////////////////////// | ||
| /// \brief Fill and return an RHist (*lazy action*). | ||
| /// \tparam BinContentType The bin content type of the returned RHist. | ||
| /// \param[in] axes The returned histogram will be constructed using these axes. | ||
| /// \param[in] columnList A list containing the names of the columns that will be passed when calling `Fill` | ||
| /// \return the histogram wrapped in a RResultPtr. | ||
| /// | ||
| /// This action is *lazy*: upon invocation of this method the calculation is | ||
| /// booked but not executed. Also see RResultPtr. | ||
| /// | ||
| /// ### Example usage: | ||
| /// ~~~{.cpp} | ||
| /// ROOT::Experimental::RRegularAxis axis(10, {5.0, 15.0}); | ||
| /// auto myHist = myDf.Hist({axis}, {"col0"}); | ||
| /// ~~~ | ||
| template <typename BinContentType = double, typename ColumnType = RDFDetail::RInferredType, typename... ColumnTypes> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One could also argue for |
||
| RResultPtr<ROOT::Experimental::RHist<BinContentType>> | ||
| Hist(std::vector<ROOT::Experimental::RAxisVariant> axes, const ColumnNames_t &columnList) | ||
| { | ||
| std::shared_ptr h = std::make_shared<ROOT::Experimental::RHist<BinContentType>>(std::move(axes)); | ||
| if (h->GetNDimensions() != columnList.size()) { | ||
| throw std::runtime_error("Wrong number of columns for the specified number of histogram axes."); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
| } | ||
|
|
||
| return Hist<ColumnType, ColumnTypes...>(h, columnList); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////// | ||
| /// \brief Fill the provided RHist (*lazy action*). | ||
| /// \param[in] h The histogram that should be filled. | ||
| /// \param[in] columnList A list containing the names of the columns that will be passed when calling `Fill` | ||
| /// \return the histogram wrapped in a RResultPtr. | ||
| /// | ||
| /// This action is *lazy*: upon invocation of this method the calculation is | ||
| /// booked but not executed. Also see RResultPtr. | ||
| /// | ||
| /// During execution of the computation graph, the passed histogram must only be accessed with methods that are | ||
| /// allowed during concurrent filling. | ||
| /// | ||
| /// ### Example usage: | ||
| /// ~~~{.cpp} | ||
| /// auto h = std::make_shared<ROOT::Experimental::RHist<double>>(10, {5.0, 15.0}); | ||
| /// auto myHist = myDf.Hist(h, {"col0"}); | ||
| /// ~~~ | ||
| template <typename ColumnType = RDFDetail::RInferredType, typename... ColumnTypes, typename BinContentType> | ||
| RResultPtr<ROOT::Experimental::RHist<BinContentType>> | ||
| Hist(std::shared_ptr<ROOT::Experimental::RHist<BinContentType>> h, const ColumnNames_t &columnList) | ||
|
Comment on lines
+2407
to
+2414
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we should market this overload as "bring your own histogram" 😅 Jokes aside, this will enable some nice use cases, for example filling a shared histogram from multiple computation graphs, as demonstrated by the |
||
| { | ||
| RDFInternal::WarnHist(); | ||
|
|
||
| if (h->GetNDimensions() != columnList.size()) { | ||
| throw std::runtime_error("Wrong number of columns for the passed histogram."); | ||
| } | ||
|
|
||
| return CreateAction<RDFInternal::ActionTags::Hist, ColumnType, ColumnTypes...>(columnList, h, h, fProxiedPtr, | ||
| columnList.size()); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////// | ||
| /// \brief Fill and return an RHist with weights (*lazy action*). | ||
| /// \tparam BinContentType The bin content type of the returned RHist. | ||
| /// \param[in] axes The returned histogram will be constructed using these axes. | ||
| /// \param[in] columnList A list containing the names of the columns that will be passed when calling `Fill` | ||
| /// \param[in] wName The name of the column that will provide the weights. | ||
| /// \return the histogram wrapped in a RResultPtr. | ||
| /// | ||
| /// This action is *lazy*: upon invocation of this method the calculation is | ||
| /// booked but not executed. Also see RResultPtr. | ||
| /// | ||
| /// This overload is not available for integral bin content types (see \ref RHistEngine::SupportsWeightedFilling). | ||
| /// | ||
| /// ### Example usage: | ||
| /// ~~~{.cpp} | ||
| /// ROOT::Experimental::RRegularAxis axis(10, {5.0, 15.0}); | ||
| /// auto myHist = myDf.Hist({axis}, {"col0"}, "colW"); | ||
| /// ~~~ | ||
| template <typename BinContentType = ROOT::Experimental::RBinWithError, | ||
| typename ColumnType = RDFDetail::RInferredType, typename... ColumnTypes> | ||
| RResultPtr<ROOT::Experimental::RHist<BinContentType>> | ||
| Hist(std::vector<ROOT::Experimental::RAxisVariant> axes, const ColumnNames_t &columnList, std::string_view wName) | ||
| { | ||
| static_assert(ROOT::Experimental::RHistEngine<BinContentType>::SupportsWeightedFilling, | ||
| "weighted filling is not supported for integral bin content types"); | ||
|
|
||
| std::shared_ptr h = std::make_shared<ROOT::Experimental::RHist<BinContentType>>(std::move(axes)); | ||
| if (h->GetNDimensions() != columnList.size()) { | ||
| throw std::runtime_error("Wrong number of columns for the specified number of histogram axes."); | ||
| } | ||
|
|
||
| return Hist<ColumnType, ColumnTypes...>(h, columnList, wName); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////// | ||
| /// \brief Fill the provided RHist with weights (*lazy action*). | ||
| /// \param[in] h The histogram that should be filled. | ||
| /// \param[in] columnList A list containing the names of the columns that will be passed when calling `Fill` | ||
| /// \param[in] wName The name of the column that will provide the weights. | ||
| /// \return the histogram wrapped in a RResultPtr. | ||
| /// | ||
| /// This action is *lazy*: upon invocation of this method the calculation is | ||
| /// booked but not executed. Also see RResultPtr. | ||
| /// | ||
| /// This overload is not available for integral bin content types (see \ref RHistEngine::SupportsWeightedFilling). | ||
| /// | ||
| /// During execution of the computation graph, the passed histogram must only be accessed with methods that are | ||
| /// allowed during concurrent filling. | ||
| /// | ||
| /// ### Example usage: | ||
| /// ~~~{.cpp} | ||
| /// auto h = std::make_shared<ROOT::Experimental::RHist<double>>(10, {5.0, 15.0}); | ||
| /// auto myHist = myDf.Hist(h, {"col0"}, "colW"); | ||
| /// ~~~ | ||
| template <typename ColumnType = RDFDetail::RInferredType, typename... ColumnTypes, typename BinContentType> | ||
| RResultPtr<ROOT::Experimental::RHist<BinContentType>> | ||
| Hist(std::shared_ptr<ROOT::Experimental::RHist<BinContentType>> h, const ColumnNames_t &columnList, | ||
| std::string_view wName) | ||
| { | ||
| static_assert(ROOT::Experimental::RHistEngine<BinContentType>::SupportsWeightedFilling, | ||
| "weighted filling is not supported for integral bin content types"); | ||
|
|
||
| RDFInternal::WarnHist(); | ||
|
|
||
| if (h->GetNDimensions() != columnList.size()) { | ||
| throw std::runtime_error("Wrong number of columns for the passed histogram."); | ||
| } | ||
|
|
||
| // Add the weight column to the list of argument columns to pass it through the infrastructure. | ||
| ColumnNames_t columnListWithWeights(columnList); | ||
| columnListWithWeights.push_back(std::string(wName)); | ||
|
|
||
| return CreateAction<RDFInternal::ActionTags::HistWithWeight, ColumnType, ColumnTypes...>( | ||
| columnListWithWeights, h, h, fProxiedPtr, columnListWithWeights.size()); | ||
| } | ||
| #endif | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////// | ||
| /// \brief Fill and return a TGraph object (*lazy action*). | ||
| /// \tparam X The type of the column used to fill the x axis. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a second tag felt like the easiest solution, together with just a template argument
bool WithWeight = falseforRHistFillHelper. Other approaches are certainly possible...