Skip to content
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

Reading TH2I histograms #364

Open
MarcoRiggirello opened this issue Nov 11, 2024 · 5 comments · Fixed by #365
Open

Reading TH2I histograms #364

MarcoRiggirello opened this issue Nov 11, 2024 · 5 comments · Fixed by #365

Comments

@MarcoRiggirello
Copy link

Hi, noob here.
I'm trying to read TH2I histograms. With standard UnROOT, I get this error:

julia> f["OpticalGroup_0/Hybrid_0/SCurve_OpticalGroup0_Hybrid0_MPA0"]
ERROR: UndefVarError: `TH2I` not defined in `UnROOT`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] getindex(d::UnROOT.ROOTDirectory, s::String)
   @ UnROOT ~/.julia/packages/UnROOT/4c5To/src/root.jl:194
 [2] getindex(d::UnROOT.ROOTDirectory, s::String)
   @ UnROOT ~/.julia/packages/UnROOT/4c5To/src/root.jl:191
 [3] _getindex(f::ROOTFile, s::String)
   @ UnROOT ~/.julia/packages/UnROOT/4c5To/src/root.jl:171
 [4] #150
   @ ~/.julia/packages/UnROOT/4c5To/src/root.jl:163 [inlined]
 [5] get!(default::UnROOT.var"#150#151"{ROOTFile, String}, h::Dict{Any, Any}, key::String)
   @ Base ./dict.jl:458
 [6] getindex(f::ROOTFile, s::String)
   @ UnROOT ~/.julia/packages/UnROOT/4c5To/src/root.jl:162
 [7] top-level scope
   @ REPL[3]:1

I tried then to add the TH1I function to bootstrap.jl but this resulted in another kind of error

julia> f["OpticalGroup_0/Hybrid_0/SCurve_OpticalGroup0_Hybrid0_MPA0"]
ERROR: EOFError: read end of file
Stacktrace:
  [1] peek
    @ ./iobuffer.jl:201 [inlined]
  [2] read
    @ ./iobuffer.jl:211 [inlined]
  [3] readtype
    @ ~/.julia/packages/UnROOT/qhPjK/src/io.jl:23 [inlined]
  [4] readtype
    @ ~/.julia/packages/UnROOT/qhPjK/src/streamers.jl:643 [inlined]
  [5] TH(io::UnROOT.MmapStream, tkey::UnROOT.TKey32, refs::Dict{Int32, Any})
    @ UnROOT ~/.julia/packages/UnROOT/qhPjK/src/bootstrap.jl:1030
  [6] TH2I(io::UnROOT.MmapStream, tkey::UnROOT.TKey32, refs::Dict{Int32, Any})
    @ UnROOT ~/.julia/packages/UnROOT/qhPjK/src/bootstrap.jl:954
  [7] getindex(d::UnROOT.ROOTDirectory, s::String)
    @ UnROOT ~/.julia/packages/UnROOT/qhPjK/src/root.jl:195
  [8] getindex(d::UnROOT.ROOTDirectory, s::String)
    @ UnROOT ~/.julia/packages/UnROOT/qhPjK/src/root.jl:191
  [9] _getindex(f::ROOTFile, s::String)
    @ UnROOT ~/.julia/packages/UnROOT/qhPjK/src/root.jl:171
 [10] #150
    @ ~/.julia/packages/UnROOT/qhPjK/src/root.jl:163 [inlined]
 [11] get!(default::UnROOT.var"#150#151"{ROOTFile, String}, h::Dict{Any, Any}, key::String)
    @ Base ./dict.jl:458
 [12] getindex(f::ROOTFile, s::String)
    @ UnROOT ~/.julia/packages/UnROOT/qhPjK/src/root.jl:162
 [13] top-level scope
    @ REPL[3]:1

Am I doing things wrong? What is different with respect to float TArray based TH classes that makes this trivial solution not working?
Thanks for the help
MR

@Moelf
Copy link
Member

Moelf commented Nov 11, 2024

It would be useful to have an sample file.

But in general, this happens when there's a private class evolution on C++ side and we haven't modeled that version in our code.

the bootstrap struct you add for TH1I will have to align with the actual TH1I class in your file.

@MarcoRiggirello
Copy link
Author

Hi Jerry,
the class is the standard TH2I histogram class

I attached a file with one of these objects.
hi.root.gz

Hope that it helps, thanks.

@tamasgal
Copy link
Member

Thanks, I will have a look

@Moelf
Copy link
Member

Moelf commented Nov 12, 2024

the class is the standard TH2I histogram class

what I mean is if you look at https://root.cern.ch/doc/master/TH2_8h_source.html#l00262, it's currently on internal version 4, and we may be compatible to one of the versions but not the one presents in your root file -- this is the part where implementation == specification in .root files, dark times before RNTuple

@tamasgal
Copy link
Member

Can you try with #365 ?

Does this make sense to you? If so, I'd add your sample file to the test samples and write a few tests. I think that it now also deals with TH1I and TH3I but we don't have tests for that. As @Moelf already pointed out, the class version might be different and we need to gather more information about the logic. In my experience, these basic things did not change much, so we might get away with it ;)

julia> using UnROOT

julia> f = ROOTFile("test/samples/issue364_TH1I.root")
ROOTFile with 1 entry and 15 streamers.
test/samples/issue364_TH1I.root
└─ myHisto (TH2I)


julia> counts, edges, sumw2, nentries = UnROOT.parseTH(f["myHisto"])
(Int32[0 0  0 0; 254 254  0 0;  ; 254 251  0 0; 0 0  0 0], (-0.5:1.0:1919.5, 199.5:1.0:230.5), Int32[0 0  0 0; 254 254  0 0;  ; 254 251  0 0; 0 0  0 0], 59520.0)

julia> counts
1920×31 Matrix{Int32}:
   0    0    0    0    0    0  0  0  0  0  0  0  0  0
 254  254  254  251  253     0  0  0  0  0  0  0  0  0
 254  254  254  253  247     0  0  0  0  0  0  0  0  0
 254  254  254  253  254     0  0  0  0  0  0  0  0  0
 254  254  253  254  249     0  0  0  0  0  0  0  0  0
 254  254  254  254  254    0  0  0  0  0  0  0  0  0
 254  254  254  254  252     0  0  0  0  0  0  0  0  0
 254  254  253  254  253     0  0  0  0  0  0  0  0  0
 254  254  254  253  246     0  0  0  0  0  0  0  0  0
 254  254  254  254  254     0  0  0  0  0  0  0  0  0
 254  254  254  253  247    0  0  0  0  0  0  0  0  0
                                                  
 253  254  253  250  247    0  0  0  0  0  0  0  0  0
 254  254  254  254  251     0  0  0  0  0  0  0  0  0
 253  254  252  248  236     0  0  0  0  0  0  0  0  0
 254  254  254  252  252     0  0  0  0  0  0  0  0  0
 254  254  254  252  250     0  0  0  0  0  0  0  0  0
 252  249  244  241  205    0  0  0  0  0  0  0  0  0
 254  252  248  240  230     0  0  0  0  0  0  0  0  0
 254  254  254  252  247     0  0  0  0  0  0  0  0  0
 254  251  247  235  232     0  0  0  0  0  0  0  0  0
   0    0    0    0    0     0  0  0  0  0  0  0  0  0

julia> edges
(-0.5:1.0:1919.5, 199.5:1.0:230.5)

@Moelf Moelf reopened this Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants