FrameTools.h
Go to the documentation of this file.
1 /** Some tools that operate on frame-related interfaces.
2 
3  fixme: this should probably go into some WireCellItools package.
4  */
5 
6 #ifndef WIRECELL_FRAMETOOLS
7 #define WIRECELL_FRAMETOOLS
8 
9 #include "WireCellIface/IFrame.h"
10 #include "WireCellUtil/Array.h"
11 
12 namespace WireCell {
13  namespace FrameTools {
14 
15  /// Return a vector of traces which have no trace tags. Here,
16  /// any frame tags are ignored. Returned vector of traces has
17  /// undefined order.
19 
20  /// Return a vector of traces for the matching tag. First, if
21  /// there is a matching trace tag, all its traces are
22  /// returned. Else, if the frame as a whole is tagged, the
23  /// entire frame of traces is returned. Else, the returned
24  /// vector is empty. If the tag consisting of the empty
25  /// string then untagged_traces() is called. Returned vector
26  /// of traces has undefined order.
28 
29 
30  /// Return a one-to-one vector of channels from a vector of
31  /// traces.
32  ///
33  /// Note, you probably want to get a sorted/unique version of
34  /// this vector for later use. Do so something like:
35  ///
36  /// auto ch = channels(traces);
37  /// std::sort(ch.begin(), ch.end());
38  /// auto end = std::unique(ch.begin(), ch.end());
39  /// ch.resize(std::distance(ch.begin(), end));
40  ///
41  typedef std::vector<int> channel_list;
42  channel_list channels(const ITrace::vector& traces);
43 
44  /// Return the tbin range of the traces. The first value is
45  /// minimum of all tbins and the second is maximum of all
46  /// tbin+size where size is number of elements in the charge
47  /// array.
48  std::pair<int,int> tbin_range(const ITrace::vector& traces);
49 
50  /// Fill a 2D [nchannels/nrows X nticks/ncolumns] array by
51  /// adding the charge information in the given traces. The
52  /// channel_list range is an ordered sequence of channels used
53  /// to associate traces to rows in the array. Ie, any trace
54  /// with the same channel number as pointed to ch_begin will
55  /// be in row 0 of the array. The "tbin" gives the time bin
56  /// of column 0 of the array and is compared to the tbin value
57  /// of the individual traces. Note, traces which are not
58  /// refered to in the channel list or which are outside the
59  /// array are ignored and not all channels need to have
60  /// associated traces.
62  const ITrace::vector& traces,
63  channel_list::iterator ch_begin,
64  channel_list::iterator ch_end,
65  int tbin = 0);
66 
67 
68  /// Compare the time span of a frame to a time.
69  ///
70  /// Return 0 if the frame time span covers the target time.
71  /// Return -1 if the frame is wholly before the target time.
72  /// Return +1 if the frame is wholly after the target time.
73  ///
74  /// Note, the frame pointer must be valid and the frame must
75  /// have traces.
76  ///
77  /// Note, if the low-edge of the minimum tick or the high-edge
78  /// of the maximum tick is exactly at the target time then the
79  /// frame span is not considered to cover the target time.
80  int frmtcmp(IFrame::pointer frame, double time);
81 
82  /// Split one frame into two. A new .first frame will contain
83  /// traces with all samples taken before the given time and a
84  /// new .second frame with traces containing samples all taken
85  /// on or after the given time. If the original frame time
86  /// span does not cover the target time then the original
87  /// frame is returned in the associated half of the pair and
88  /// the other half will hold the nullptr.
89  ///
90  /// Note, the frame pointer must be valid and the frame must
91  /// have traces.
92  std::pair<IFrame::pointer, IFrame::pointer> split(IFrame::pointer frame, double time);
93 
94  }
95 }
96 
97 #endif
ITrace::vector tagged_traces(IFrame::pointer frame, IFrame::tag_t tag)
Definition: FrameTools.cxx:111
intermediate_table::iterator iterator
std::shared_ptr< const IFrame > pointer
Definition: IData.h:19
void fill(Array::array_xxf &array, const ITrace::vector &traces, channel_list::iterator ch_begin, channel_list::iterator ch_end, int tbin=0)
Definition: FrameTools.cxx:158
std::vector< pointer > vector
Definition: IData.h:21
std::vector< int > channel_list
Definition: FrameTools.h:41
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
ITrace::vector untagged_traces(IFrame::pointer frame)
Definition: FrameTools.cxx:90
channel_list channels(const ITrace::vector &traces)
Definition: FrameTools.cxx:132
int frmtcmp(IFrame::pointer frame, double time)
Definition: FrameTools.cxx:14
std::pair< int, int > tbin_range(const ITrace::vector &traces)
Definition: FrameTools.cxx:143
Definition: Main.h:22
std::pair< IFrame::pointer, IFrame::pointer > split(IFrame::pointer frame, double time)
Definition: FrameTools.cxx:32
std::string tag_t
Definition: IFrame.h:28
Eigen::ArrayXXf array_xxf
A real, 2D array.
Definition: Array.h:54