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 croot's TTrees with standard ROOT macros #11

Open
ebusato opened this issue Oct 11, 2016 · 3 comments
Open

Reading croot's TTrees with standard ROOT macros #11

ebusato opened this issue Oct 11, 2016 · 3 comments
Assignees
Labels

Comments

@ebusato
Copy link

ebusato commented Oct 11, 2016

Hi Seb,

I created a TTree with croot using the following struct:

type ROOTDataMult2 struct {
Run uint32
Evt uint32
IChanAbs240 [2]uint16
Ampl [2]float64
Charge [2]float64
T20 [2]float64
T30 [2]float64
T80 [2]float64
NoLocMaxRisingFront [2]uint16
SampleTimes [999]float64
Pulse [2][999]float64
}

The TTree is written properly to the TFile and I can draw all these variables using TTree::Draw. This works great ! But now I'd like to implement the event loop myself using a standard ROOT macro. I could not figure out a way to do so. It always seems to fail because of the missing dictionnary for the ROOTDataMult2 object.

Would you have an example ROOT macro that allows looping over TTree with structs inside ?

Alternatively, is it possible to create TTree with croot with simple variables only (ints, floats, ...) and arrays of simple variables, no structs (in order to avoid the "missing dictionnary" issue) ? I tried creating a branch with

_, err = t.tree.Branch("data", &var, bufsiz, 0)

where var is an int, but it fails saying that it expects a struct.

Thanks !
Emmanuel

@sbinet sbinet self-assigned this Oct 12, 2016
@sbinet
Copy link
Member

sbinet commented Oct 12, 2016

for the second part of the question, see:
https://github.com/go-hep/croot/blob/master/all_test.go#L59

ie:

// in Go

// create a tree
tree := croot.NewTree("tree", "tree", splitlevel)
e := Event{}

// create a branch with energy
_, err = tree.Branch2("evt_i", &e.I, "evt_i/L", bufsiz)
_, err = tree.Branch2("evt_a_e", &e.A.E, "evt_a_e/D", bufsiz)

or:
https://github.com/go-hep/examples/blob/master/croot/go-croot-ex-tree-00/main.go

and then:

## with PyROOT
import ROOT
f = ROOT.TFile.Open("event.root")
t = f.tree
t.Draw("evt_i:evt_a_e")

@sbinet
Copy link
Member

sbinet commented Oct 12, 2016

(and for the first part, yeah... it's either a regression I didn't catch or something I thought was working but really didn't...)

@sbinet sbinet added the bug label Oct 12, 2016
@ebusato
Copy link
Author

ebusato commented Oct 17, 2016

Thanks ! The creation of branches for simple variables (and arrays of simple variables) with Branch2 works fine. I can now implement myself the event loop with the TTreeReader class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants