From acbeb1170dffc7b09ce4174cc5ef10a4ff0b3b1c Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Wed, 3 Aug 2011 17:27:20 -0400 Subject: ROOT data structure for holding particle, photon, and hit information. --- io/__init__.py | 0 io/root.C | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ io/root.py | 16 ++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 io/__init__.py create mode 100644 io/root.C create mode 100644 io/root.py (limited to 'io') diff --git a/io/__init__.py b/io/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/io/root.C b/io/root.C new file mode 100644 index 0000000..0cfb37f --- /dev/null +++ b/io/root.C @@ -0,0 +1,79 @@ +#include +#include +#include +#include + +struct Photon { + double t; + TVector3 pos; + TVector3 dir; + TVector3 pol; + double wavelength; // nm + int state; + int last_triangle; + int last_solid; +}; + +struct MC { + std::string particle; + TVector3 gen_pos; + TVector3 gen_dir; + double gen_ke; + + std::vector photon; + + void clear() { + particle = "none"; + photon.clear(); + } +}; + +struct Channel { + Channel() : channel_id(-1), t(-9999.0), q(-9999.0) { }; + int channel_id; + double t; + double q; +}; + +struct Event { + int event_id; + MC mc; + int nhit; + std::vector channel; + + void clear() { + mc.clear(); + channel.clear(); + } +}; + +void fill_event(TTree *T, + Event *ev, int event_id, double *gen_pos, int nchannels, + float *channel_times) +{ + ev->event_id = event_id; + MC &mc = ev->mc; + mc.gen_pos.SetXYZ(gen_pos[0], gen_pos[1], gen_pos[2]); + mc.photon.resize(0); + ev->channel.resize(0); + ev->nhit = 0; + Channel ch; + for (int i=0; i < nchannels; i++) { + if (channel_times[i] < 1e8) { + ev->nhit++; + ch.channel_id = i; + ch.t = channel_times[i]; + ch.q = 1.0; + ev->channel.push_back(ch); + } + } + T->Fill(); +} + + +#ifdef __MAKECINT__ +#pragma link C++ class vector; +#pragma link C++ class vector; +#endif + + diff --git a/io/root.py b/io/root.py new file mode 100644 index 0000000..382905a --- /dev/null +++ b/io/root.py @@ -0,0 +1,16 @@ +import ROOT +import os.path + +ROOT.gROOT.ProcessLine('.L '+os.path.join(os.path.dirname(__file__), 'root.C+g')) + +from ROOT import Event + +def make_tree(name, desc=''): + '''Create a ROOT tree for holding event information. + + Returns tuple of Event object for filling and TTree. + ''' + tree = ROOT.TTree(name, desc) + ev = ROOT.Event() + tree.Branch('ev', ev) + return ev, tree -- cgit From 69a78faaf5a11e01893dc0d9b8289f1ea0cbd2fb Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Thu, 4 Aug 2011 11:54:04 -0400 Subject: Use the clear() method on Event to reset for filling. --- io/root.C | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'io') diff --git a/io/root.C b/io/root.C index 0cfb37f..dfcb3c0 100644 --- a/io/root.C +++ b/io/root.C @@ -51,11 +51,10 @@ void fill_event(TTree *T, Event *ev, int event_id, double *gen_pos, int nchannels, float *channel_times) { + ev->clear(); ev->event_id = event_id; MC &mc = ev->mc; mc.gen_pos.SetXYZ(gen_pos[0], gen_pos[1], gen_pos[2]); - mc.photon.resize(0); - ev->channel.resize(0); ev->nhit = 0; Channel ch; for (int i=0; i < nchannels; i++) { -- cgit From 944fa9b2d0dace02180d9fad18ced9c7375fe1a4 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Thu, 4 Aug 2011 11:54:25 -0400 Subject: Import the fill_event() method from ROOT into the root.py namespace. --- io/root.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'io') diff --git a/io/root.py b/io/root.py index 382905a..d970d1d 100644 --- a/io/root.py +++ b/io/root.py @@ -5,6 +5,8 @@ ROOT.gROOT.ProcessLine('.L '+os.path.join(os.path.dirname(__file__), 'root.C+g') from ROOT import Event +fill_event = ROOT.fill_event + def make_tree(name, desc=''): '''Create a ROOT tree for holding event information. -- cgit