[RF] Introduce a first-class `RooBinIndex` for reusable bin-index computation
メンテナーはふだん 1 日以内に返信
@guitargeek がすでに取り組んでいます。
2026年9月8日 から。
評価
この issue はまだ評価されていません。
説明
Explain what you would like to see improved and how.
Related PRs: #23298, #15543, #11171, #12955
Motivation
While working on #23298, the question came up whether the computation of a histogram bin index should be represented by a standalone RooFit object, tentatively called RooBinIndex.
The immediate motivation is RooBinWidthFunction: after #23298 it depends directly on its observables, but consequently needs to determine the current multi-dimensional bin itself in both scalar and batch evaluation. This logic is not specific to bin widths, however. Similar coordinate-to-bin-index computations already exist in several RooFit and HistFactory classes.
A first-class RooBinIndex could provide a single graph node representing
observables -> flattened bin index
and allow multiple histogram-like objects with the same binning to share that result.
This issue is intended to collect the relevant use cases and design questions. It could either serve as the starting point for a refactor now, or remain as follow-up work after merging #23298 independently.
Existing implementations / potential consumers
The following classes currently contain or rely on closely related bin-index logic:
RooBinWidthFunction
The implementation in #23298 computes the current bin directly from its observable list, including multi-dimensional index flattening and separate scalar/batch implementations.
This is the immediate use case that prompted the discussion.
RooHistFunc
RooHistFunc currently has
Int_t getBin() const;
std::vector<Int_t> getBins(RooFit::EvalContext &ctx) const;
which effectively implement a private version of the proposed abstraction.
Its evaluation code additionally has separate scalar, 1D batch, and ND batch paths for mapping function observables onto the underlying histogram bins.
RooHistPdf
RooHistPdf performs essentially the same mapping from PDF observables to the bins of its RooDataHist.
For zero-order histogram evaluation this could naturally become
RooBinIndex -> weight[index]
Interpolation would still require the actual coordinates and neighbouring bin geometry, so RooBinIndex would only represent the central-bin lookup.
RooParamHistFunc
This is perhaps the simplest potential consumer. Its scalar evaluation currently amounts to
idx = dataHist.getIndex(observables);
return parameters[idx];
while code generation independently asks RooDataHist to generate the corresponding tree-index expression.
This could naturally become a parameter lookup driven by a RooBinIndex.
HistFactory ParamHistFunc
The HistFactory implementation contains several versions of the same operation:
- scalar evaluation through
RooDataHist::getIndex(); - vectorized evaluation using
RooAbsBinning::binNumbers()and explicit index multipliers; - code generation through
RooDataHist::calculateTreeIndexForCodeSquash().
This is a strong candidate for consolidation.
PiecewiseInterpolation
#15543 already introduced an optimization based on the fact that the nominal and variation RooHistFuncs in HistFactory use the same bin structure.
The generated code computes the bin index only once and then uses it to address the nominal, low, and high arrays.
A first-class RooBinIndex could make this sharing explicit in the RooFit computation graph instead of rediscovering it in code generation.
Conceptually, a HistFactory channel could then look like
+-> nominal histogram
+-> systematic variations
observables -> BinIndex -+-> MC-stat parameters
+-> bin-width correction
+-> other bin-wise quantities
RooDataHist
RooDataHist::calcTreeIndex() is currently the main general implementation of multi-dimensional bin-index calculation, and calculateTreeIndexForCodeSquash() implements the corresponding generated expression.
It probably should share an implementation with RooBinIndex, but RooDataHist itself should not necessarily depend on a graph node: it also needs to calculate indices for arbitrary coordinate collections outside a computation graph.
A possible layering would therefore be
common bin-index implementation
/ \
RooBinIndex RooDataHist
graph node storage API
Secondary candidates
RooBinSamplingPdf also has duplicated scalar/batch bin lookup: scalar evaluation uses getBin(), while batch evaluation independently determines the bin from the boundaries.
RooBinningCategory is conceptually very close to a one-dimensional RooBinIndex: it maps a real l-value through a named binning onto a category whose index corresponds to the bin number. It probably should not disappear, since the category labels are useful, but the two implementations might eventually share their underlying bin-lookup machinery.
Other uses of binNumber() such as in RooFFTConvPdf, RooPlot, or RooMomentMorphFuncND appear to be local geometry/cache algorithms rather than reusable graph-level bin-index computations, so they probably do not need to participate in this refactor.
Design questions
A reusable RooBinIndex turns out to require a few architectural decisions.
1. Which binning defines the index?
For RooBinWidthFunction after #23298, the live observables and their current default binnings are authoritative.
For RooHistFunc and RooHistPdf, however, the values can come from one set of observables while the relevant bin geometry comes from the corresponding histogram observables / RooDataHist.
Therefore an API that only stores
RooBinIndex(name, observables);
and always uses observables[i].getBinning() may be too restrictive.
The value source and the binning source may need to be representable separately.
2. What is the multi-dimensional flattening convention?
RooDataHist and HistFactory do not universally use the same ordering.
RooDataHist indexing makes the last listed dimension the fastest-running one.
The legacy HistFactory ParamHistFunc, on the other hand, stores parameters in TH1 ordering, where the first/x dimension is fastest, and contains explicit conversion logic between the two conventions.
A standalone RooBinIndex should have a clearly defined canonical ordering. Consumers with legacy storage conventions could then transform their arrays explicitly if necessary.
3. How are categories handled?
For categories, the histogram-bin number is the ordinal state number, which is not necessarily identical to the category's numeric state index.
Scalar evaluation can use RooAbsCategoryLValue::getBin(), but batch evaluation sees the numeric category values and therefore needs a proper value-to-ordinal mapping.
This needs to be handled centrally if RooBinIndex is intended to support mixed real/category histograms.
4. Dynamic and named binnings
The implementation should define how it behaves when
- a binning is replaced;
- the range or number of bins changes;
- a named rather than default binning is used;
- a parameterized/transformed binning changes dynamically.
This is already relevant in #23298 because RooBinWidthFunction needs to detect binning changes that do not necessarily propagate through the usual dirty-state mechanism.
5. Evaluation backends
If introduced as a RooFit graph node, RooBinIndex should ideally have consistent support for
- scalar evaluation;
EvalContextbatch evaluation;- code generation / code squashing.
Otherwise it risks simply moving the current duplication to a different layer.
Possible scope
There seem to be two reasonable levels of implementation.
Minimal extraction
Introduce RooBinIndex primarily for #23298 and the immediately duplicated helpers:
- new
RooBinIndex; - use it in
RooBinWidthFunction; - remove or replace
RooHistFunc::getBin()/getBins()where appropriate.
This would be a relatively small follow-up and would not require restructuring histogram evaluation more generally.
Canonical bin-index node
Make RooBinIndex the common graph-level representation of coordinate-to-bin mapping and adapt at least:
RooBinWidthFunction;RooHistFunc;RooHistPdf;RooParamHistFunc;- HistFactory
ParamHistFunc; PiecewiseInterpolation;- the relevant
RooDataHisthelper implementation.
A more exhaustive cleanup could additionally include RooBinSamplingPdf and share implementation with RooBinningCategory.
This larger version would also make it possible for HistFactory models to explicitly share one bin-index node between several bin-wise functions.
Relation to #23298
I don't think this necessarily needs to block #23298.
The RooBinWidthFunction changes in that PR make the duplicated bin-index computation particularly visible, but a genuinely reusable RooBinIndex requires decisions about binning ownership, index ordering, categories, dynamic binnings and evaluation backends that go beyond the scope of the original PR.
One reasonable path would therefore be to merge #23298 as-is and use this issue as the basis for a later refactor.
Alternatively, if there is agreement on the desired RooBinIndex abstraction, #23298 could serve as the first consumer of it.
ROOT version
latest master
Installation method
built from source
Operating system
linux
Additional context
One of the core motivations for this is to make the computational graph more aligned with the client/server proxy links which form the basis of HS3 export.
- 主要言語
- C++
- スター
- 3.3k
- フォーク
- 1.6k
- 平均マージ
- 2日 15時間
- マージ済み PR(30日)
- 207
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
root-project/root のほかの issue
-
thisroot.sh: wrong ROOTSYS in zsh when the shell's command line has a newline対応中かも @dpiparo が 10 日前に担当しました。 オープンbug in:Build System
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
root-project/root#23746 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Header cleanup campaign対応中かも @hageboeck が今日担当しました。 オープン
root-project/root#23880 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[graph] TScatter / TScatter2D stops drawing remaining points if a non-positive value is encountered in log scale対応中かも @muntasir-396 が 4 日前に担当しました。 オープンgood first issue improvement in:Graphics
root-project/root#23833 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
TDataMember::GetOffset interfers to TDataMember::GetOffsetCint対応中かも @pcanal が 7 日前に担当しました。 オープンbug in:Core Libraries
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
root-project/root#23777 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`TChain::GetEntries` internal caching ineffective?対応中かも @pcanal が 12 日前に担当しました。 オープンimprovement in:TTree
root-project/root#23738 · コメント 6 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
root-project/root の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
espressif/esp-matter#1913 ·
-
bug priority: low
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
chipsalliance/verible#2644 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
grafana/pyroscope-dotnet#470 ·
メンテナーはふだん 1 日以内に返信
-
documentation P5 XS
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
open-astro/AlpacaBridge#1848 ·
メンテナーはふだん 1 日以内に返信