summaryrefslogtreecommitdiff
path: root/fileio
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2011-08-10 11:25:39 -0400
committerStan Seibert <stan@mtrr.org>2011-08-10 11:25:39 -0400
commit01d5527db39520ca548518ed1194f8b863a4f077 (patch)
treeac75370a5677bac0f64e0b7529af40b94cfef4f8 /fileio
parent23b4bedf43f2ff120c1178c3445e39b8735030f3 (diff)
downloadchroma-01d5527db39520ca548518ed1194f8b863a4f077.tar.gz
chroma-01d5527db39520ca548518ed1194f8b863a4f077.tar.bz2
chroma-01d5527db39520ca548518ed1194f8b863a4f077.zip
Rename chroma.io to chroma.fileio to avoid collision with Python package named io
Diffstat (limited to 'fileio')
-rw-r--r--fileio/__init__.py0
-rw-r--r--fileio/root.C95
-rw-r--r--fileio/root.py19
3 files changed, 114 insertions, 0 deletions
diff --git a/fileio/__init__.py b/fileio/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/fileio/__init__.py
diff --git a/fileio/root.C b/fileio/root.C
new file mode 100644
index 0000000..096811a
--- /dev/null
+++ b/fileio/root.C
@@ -0,0 +1,95 @@
+#include <TVector3.h>
+#include <vector>
+#include <TTree.h>
+#include <string>
+
+struct Photon {
+ double t;
+ TVector3 pos;
+ TVector3 dir;
+ TVector3 pol;
+ double wavelength; // nm
+ unsigned int history;
+ int last_hit_triangle;
+};
+
+struct MC {
+ std::string particle;
+ TVector3 gen_pos;
+ TVector3 gen_dir;
+ double gen_total_e;
+
+ std::vector<Photon> photon_start;
+ std::vector<Photon> photon_stop;
+
+};
+
+struct Channel {
+ Channel() : channel_id(-1), t(-9999.0), q(-9999.0) { };
+ int channel_id;
+ double t;
+ double q;
+ unsigned int mc_history;
+};
+
+struct Event {
+ int event_id;
+ MC mc;
+ int nhit;
+ std::vector<Channel> channel;
+
+};
+
+void fill_photons(Event *ev, bool start,
+ unsigned int nphotons, float *pos, float *dir,
+ float *pol, float *wavelength, float *t0,
+ int *histories=0, int *last_hit_triangle=0)
+{
+ std::vector<Photon> &photons = start ? ev->mc.photon_start : ev->mc.photon_stop;
+ photons.resize(nphotons);
+
+ for (unsigned int i=0; i < nphotons; i++) {
+ Photon &photon = photons[i];
+ photon.t = t0[i];
+ photon.pos.SetXYZ(pos[3*i], pos[3*i + 1], pos[3*i + 2]);
+ photon.dir.SetXYZ(dir[3*i], dir[3*i + 1], dir[3*i + 2]);
+ photon.pol.SetXYZ(pol[3*i], pol[3*i + 1], pol[3*i + 2]);
+ photon.wavelength = wavelength[i];
+ if (histories)
+ photon.history = histories[i];
+ else
+ photon.history = 0;
+
+ if (last_hit_triangle)
+ photon.last_hit_triangle = last_hit_triangle[i];
+ else
+ photon.last_hit_triangle = -1;
+ }
+}
+
+
+void fill_hits(Event *ev, unsigned int nchannels, float *t,
+ float *q, unsigned int *history)
+{
+ ev->channel.resize(0);
+ ev->nhit = 0;
+ Channel ch;
+ for (unsigned int i=0; i < nchannels; i++) {
+ if (t[i] < 1e8) {
+ ev->nhit++;
+ ch.channel_id = i;
+ ch.t = t[i];
+ ch.q = q[i];
+ ch.mc_history = history[i];
+ ev->channel.push_back(ch);
+ }
+ }
+}
+
+
+#ifdef __MAKECINT__
+#pragma link C++ class vector<Photon>;
+#pragma link C++ class vector<Channel>;
+#endif
+
+
diff --git a/fileio/root.py b/fileio/root.py
new file mode 100644
index 0000000..e43f5d4
--- /dev/null
+++ b/fileio/root.py
@@ -0,0 +1,19 @@
+import ROOT
+import os.path
+
+ROOT.gROOT.ProcessLine('.L '+os.path.join(os.path.dirname(__file__), 'root.C+g'))
+
+from ROOT import Event
+
+fill_photons = ROOT.fill_photons
+fill_hits = ROOT.fill_hits
+
+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