Sum a vector of frames, returning a new one with the given ident. The start time of the new one will be the minimum time of all frames. The sample period (tick) of all frames must be identical. Traces on a common channel are summed producing a single trace which covers a time domain spanning the minimum and maximum tbin of all the traces in the channel. Zeros are padded for any intervening samples outside of any individual trace.
18 const int nframes = frames.size();
19 std::vector<double> times(nframes),
ticks(nframes);
20 for (
int ind=0; ind<nframes; ++ind) {
21 times[ind] = frames[ind]->time();
22 ticks[ind] = frames[ind]->tick();
24 auto tick_mm = std::minmax_element(
ticks.begin(),
ticks.end());
25 if (*tick_mm.first != *tick_mm.second) {
29 auto times_mm = std::minmax_element(times.begin(), times.end());
30 const double start_time = *times_mm.first;
35 for (
int ind=0; ind<nframes; ++ind) {
37 const double dt = frame->time() - start_time;
38 const int tbinoff = dt/
tick;
39 for (
auto trace : *frame->traces()) {
40 const int ch =
trace->channel();
41 const int new_tbin = tbinoff +
trace->tbin();
42 index[ch].push_back(make_pair(new_tbin, &(
trace->charge())));
48 for (
auto ctc : index) {
50 auto tcv = ctc.second;
53 const int tbin = tc.first;
54 tbins.push_back(tbin);
55 tbins.push_back(tbin+tc.second->size());
57 auto tbin_mm = std::minmax_element(tbins.begin(), tbins.end());
58 const int trace_tbin = *tbin_mm.first;
59 const int trace_nbins = *tbin_mm.second-trace_tbin;
60 vector<float> charge(trace_nbins, 0.0);
62 int ind = tc.first - trace_tbin;
63 for (
auto q : *tc.second) {
69 out_traces.push_back(trace);
72 return make_shared<SimpleFrame>(ident, start_time, out_traces,
tick);
std::map< int, std::vector< tbin_charge_t > > channel_index_t
tick ticks
Alias for common language habits.
Binning tbins(nticks, t0, t0+readout_time)
const GenericPointer< typename T::ValueType > & pointer