From 9d61786d403a340d5ceb88b1c565cf0362c00580 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Sun, 14 Aug 2011 21:00:36 -0400 Subject: Add a helper function to the ROOT Channel class that will populate 3 arrays with hit information: hit or not, time and charge. Handy for fetching all the hits in an event into numpy arrays. --- fileio/root.C | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'fileio/root.C') diff --git a/fileio/root.C b/fileio/root.C index 24ed09a..9a959f5 100644 --- a/fileio/root.C +++ b/fileio/root.C @@ -48,6 +48,28 @@ struct Event { int nhit; std::vector channel; + // Populate arrays of length nentries with hit, time, and charge + // information, indexed by channel ID + void get_channels(unsigned int nentries, int *hit, float *time, + float *charge) + { + for (unsigned int i=0; i < nentries; i++) { + hit[i] = 0; + time[i] = -1e9f; + charge[i] = -1e9f; + } + + for (unsigned int i=0; i < channel.size(); i++) { + unsigned int channel_id = channel[i].channel_id; + + if (channel_id < nentries) { + hit[channel_id] = 1; + time[channel_id] = channel[i].t; + charge[channel_id] = channel[i].q; + } + } + } + }; void fill_photons(Event *ev, bool start, -- cgit