Dear ROOT (pyROOT) experts,
I’ve been trying to figure out what the best way for filling a THnSparse from a TTree is.
As far as I could find, there is only one example using a THnSparse which does the filling manually.
What I was hoping for is a feature like chain.Draw(“var1:var2:var3:var4…>>MyTHn”, “cut_string”) in order to create a THnSparse on the fly.
but when I try this with 4 variables, it creates a TH3F. When I try this with more than 4 variables, I get the following error message:
Too many variables. Use the option “para”, “gl5d” or “candle” to display more than 4 variables.
And none of these options seem to help in creating THnSparse as far as I could try.
Is there any feature available like this which would allow for creating ThnSparse directly from the TTree?
Many thanks in advance,
I don’t think
TTree.Draw() can fill
THnSparse, @pcanal please correct me if I’m wrong.
I would have thought that RDataFrame can do it, like this
from array import array
h = ROOT.THnSparseD("", "", dim, array('i', (nbin1, nbin2, ...)), array('d', (min1, min2, ...)), array('d', (max1, max2, ...)))
h = ROOT.RDataFrame(treeName, fileName).Fill(h, ["var1", "var2", ...])
But somehow I get an error
ActionHelpers.hxx:382:21: error: member reference base type 'THnSparseT<TArrayD> *' is not a structure or union
fObjects[slot]->Fill(x0, x1, ...)
@eguiraud Do you have an idea?
I think PyROOT is somehow hiding the actual problem:
THnSparse is not copy-constructible and as such cannot be used with
I see, so is this still the latest recommendation on using THnSparse with RDataFrame?
Yes that’s the Python workaround, thanks for digging that up! It’s fairly ugly – if there is enough request we could add a proper method to RDF to fill a THnSparse.
Thanks a lot for the quick responses! Unfortunately, in our current working environment RDFs are not included. I will try it once our environment is updated.
But on the other hand could the Fill THnSparse feature also be implemented with TTree::Draw or are there technical show stoppers?
After seeing this feature request from '08, I was hoping the feature would already be in place.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.