|
40 | 40 | #include "TH2.h" // For Histo actions |
41 | 41 | #include "TH3.h" // For Histo actions |
42 | 42 | #include "THn.h" |
| 43 | +#include "THnSparse.h" |
43 | 44 | #include "TProfile.h" |
44 | 45 | #include "TProfile2D.h" |
45 | 46 | #include "TStatistic.h" |
@@ -2286,6 +2287,82 @@ public: |
2286 | 2287 | columnList.size()); |
2287 | 2288 | } |
2288 | 2289 |
|
| 2290 | + |
| 2291 | + //////////////////////////////////////////////////////////////////////////// |
| 2292 | + /// \brief Fill and return a sparse N-dimensional histogram (*lazy action*). |
| 2293 | + /// \tparam FirstColumn The first type of the column the values of which are used to fill the object. Inferred if not |
| 2294 | + /// present. |
| 2295 | + /// \tparam OtherColumns A list of the other types of the columns the values of which are used to fill the |
| 2296 | + /// object. |
| 2297 | + /// \param[in] model The returned histogram will be constructed using this as a model. |
| 2298 | + /// \param[in] columnList |
| 2299 | + /// A list containing the names of the columns that will be passed when calling `Fill`. |
| 2300 | + /// (N columns for unweighted filling, or N+1 columns for weighted filling) |
| 2301 | + /// \return the N-dimensional histogram wrapped in a RResultPtr. |
| 2302 | + /// |
| 2303 | + /// This action is *lazy*: upon invocation of this method the calculation is |
| 2304 | + /// booked but not executed. See RResultPtr documentation. |
| 2305 | + /// |
| 2306 | + /// ### Example usage: |
| 2307 | + /// ~~~{.cpp} |
| 2308 | + /// auto myFilledObj = myDf.HistoND<float, float, float, float>({"name","title", 4, |
| 2309 | + /// {40,40,40,40}, {20.,20.,20.,20.}, {60.,60.,60.,60.}}, |
| 2310 | + /// {"col0", "col1", "col2", "col3"}); |
| 2311 | + /// ~~~ |
| 2312 | + /// |
| 2313 | + template <typename FirstColumn, typename... OtherColumns> // need FirstColumn to disambiguate overloads |
| 2314 | + RResultPtr<::THnSparseD> HistoNSparseD(const THnSparseDModel &model, const ColumnNames_t &columnList) |
| 2315 | + { |
| 2316 | + std::shared_ptr<::THnSparseD> h(nullptr); |
| 2317 | + { |
| 2318 | + ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(kError); |
| 2319 | + h = model.GetHistogram(); |
| 2320 | + |
| 2321 | + if (int(columnList.size()) == (h->GetNdimensions() + 1)) { |
| 2322 | + h->Sumw2(); |
| 2323 | + } else if (int(columnList.size()) != h->GetNdimensions()) { |
| 2324 | + throw std::runtime_error("Wrong number of columns for the specified number of histogram axes."); |
| 2325 | + } |
| 2326 | + } |
| 2327 | + return CreateAction<RDFInternal::ActionTags::HistoNSparseD, FirstColumn, OtherColumns...>(columnList, h, h, |
| 2328 | + fProxiedPtr); |
| 2329 | + } |
| 2330 | + |
| 2331 | + //////////////////////////////////////////////////////////////////////////// |
| 2332 | + /// \brief Fill and return a sparse N-dimensional histogram (*lazy action*). |
| 2333 | + /// \param[in] model The returned histogram will be constructed using this as a model. |
| 2334 | + /// \param[in] columnList A list containing the names of the columns that will be passed when calling `Fill` |
| 2335 | + /// (N columns for unweighted filling, or N+1 columns for weighted filling) |
| 2336 | + /// \return the N-dimensional histogram wrapped in a RResultPtr. |
| 2337 | + /// |
| 2338 | + /// This action is *lazy*: upon invocation of this method the calculation is |
| 2339 | + /// booked but not executed. Also see RResultPtr. |
| 2340 | + /// |
| 2341 | + /// ### Example usage: |
| 2342 | + /// ~~~{.cpp} |
| 2343 | + /// auto myFilledObj = myDf.HistoNSparseD({"name","title", 4, |
| 2344 | + /// {40,40,40,40}, {20.,20.,20.,20.}, {60.,60.,60.,60.}}, |
| 2345 | + /// {"col0", "col1", "col2", "col3"}); |
| 2346 | + /// ~~~ |
| 2347 | + /// |
| 2348 | + RResultPtr<::THnSparseD> HistoNSparseD(const THnSparseDModel &model, const ColumnNames_t &columnList) |
| 2349 | + { |
| 2350 | + std::shared_ptr<::THnSparseD> h(nullptr); |
| 2351 | + { |
| 2352 | + ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(kError); |
| 2353 | + h = model.GetHistogram(); |
| 2354 | + |
| 2355 | + if (int(columnList.size()) == (h->GetNdimensions() + 1)) { |
| 2356 | + h->Sumw2(); |
| 2357 | + } else if (int(columnList.size()) != h->GetNdimensions()) { |
| 2358 | + throw std::runtime_error("Wrong number of columns for the specified number of histogram axes."); |
| 2359 | + } |
| 2360 | + } |
| 2361 | + return CreateAction<RDFInternal::ActionTags::HistoNSparseD, RDFDetail::RInferredType>(columnList, h, h, fProxiedPtr, |
| 2362 | + columnList.size()); |
| 2363 | + } |
| 2364 | + |
| 2365 | + |
2289 | 2366 | //////////////////////////////////////////////////////////////////////////// |
2290 | 2367 | /// \brief Fill and return a TGraph object (*lazy action*). |
2291 | 2368 | /// \tparam X The type of the column used to fill the x axis. |
|
0 commit comments