SumSlice.cxx
Go to the documentation of this file.
1 #include "WireCellImg/SumSlice.h"
2 #include "WireCellImg/ImgData.h"
4 
5 #include "WireCellIface/FrameTools.h" // fixme: *still* need to move this out of iface...
6 
7 
10 
11 WIRECELL_FACTORY(SumSlices, WireCell::Img::SumSlices,
13 
14 using namespace std;
15 using namespace WireCell;
16 
17 
18 Img::SumSliceBase::SumSliceBase() : m_tick_span(4) , m_tag("") { }
19 Img::SumSliceBase::~SumSliceBase() { }
22 
24 {
26 
27  // Name of an IAnodePlane from which we can resolve channel ident to IChannel
28  cfg["anode"] = "";
29 
30  // Number of ticks over which each output slice should sum
31  cfg["tick_span"] = m_tick_span;
32 
33  // If given, use tagged traces. Otherwise use all traces.
34  cfg["tag"] = m_tag;
35 
36  return cfg;
37 }
38 
39 
41 {
42  m_anode = Factory::find_tn<IAnodePlane>(cfg["anode"].asString()); // throws
43  m_tick_span = get(cfg, "tick_span", m_tick_span);
44  m_tag = get<std::string>(cfg, "tag", m_tag);
45 }
46 
47 
49 {
50  const double tick = in->tick();
51  const double span = tick * m_tick_span;
52 
53  for (auto trace : FrameTools::tagged_traces(in, m_tag)) {
54  const int tbin = trace->tbin();
55  const int chid = trace->channel();
56  IChannel::pointer ich = m_anode->channel(chid);
57  const auto& charge = trace->charge();
58  const size_t nq = charge.size();
59  for (size_t qind=0; qind != nq; ++qind) {
60  const auto q = charge[qind];
61  if (q == 0.0) {
62  continue;
63  }
64  size_t slicebin = (tbin+qind)/m_tick_span;
65  auto s = svcmap[slicebin];
66  if (!s) {
67  const double start = slicebin * span; // thus relative to slice frame's time.
68  svcmap[slicebin] = s = new Img::Data::Slice(in, slicebin, start, span);
69  }
70  s->sum(ich, q);
71  }
72  }
73 }
74 
75 
77 {
78  out = nullptr;
79  if (!in) {
80  return true; // eos
81  }
82 
83  // Slices will be sparse in general. Index by a "slice bin" number
84  slice_map_t svcmap;
85  slice(in, svcmap);
86 
87  // intern
88  ISlice::vector islices;
89  for (auto sit : svcmap) {
90  auto s = sit.second;
91  islices.push_back(ISlice::pointer(s));
92  }
93  out = make_shared<Img::Data::SliceFrame>(islices, in->ident(), in->time());
94 
95  return true;
96 }
97 
98 
99 
101 {
102  if (!in) {
103  slices.push_back(nullptr);
104  return true; // eos
105  }
106 
107  // Slices will be sparse in general. Index by a "slice bin" number
108  slice_map_t svcmap;
109  slice(in, svcmap);
110 
111  // intern
112  for (auto sit : svcmap) {
113  auto s = sit.second;
114 
115  /// debug
116  double qtot = 0;
117  for (const auto& a : s->activity()) {
118  qtot += a.second;
119  }
120 
121  slices.push_back(ISlice::pointer(s));
122  }
123 
124  return true;
125 }
126 
ITrace::vector tagged_traces(IFrame::pointer frame, IFrame::tag_t tag)
Definition: FrameTools.cxx:111
span(IterB &&b, IterE &&e, Adaptor &&adaptor) -> span< decltype(adaptor(std::forward< IterB >(b))), decltype(adaptor(std::forward< IterE >(e))) >
std::shared_ptr< const IFrame > pointer
Definition: IData.h:19
SlicingAlgorithm::Slice Slice
std::map< size_t, Data::Slice * > slice_map_t
Definition: SumSlice.h:55
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
Definition: SumSlice.cxx:23
STL namespace.
virtual bool operator()(const input_pointer &depo, output_queue &slices)
The calling signature:
Definition: SumSlice.cxx:100
cfg
Definition: dbjson.py:29
std::vector< pointer > vector
Definition: IData.h:21
const double tick
std::deque< output_pointer > output_queue
std::shared_ptr< const IFrame > input_pointer
Definition: IFunctionNode.h:39
bool operator()(const input_pointer &in, output_pointer &out)
The calling signature:
Definition: SumSlice.cxx:76
std::shared_ptr< const ISliceFrame > output_pointer
Definition: IFunctionNode.h:40
std::vector< TCSlice > slices
Definition: DataStructs.cxx:12
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
Definition: Main.h:22
Json::Value Configuration
Definition: Configuration.h:50
WIRECELL_FACTORY(SumSlicer, WireCell::Img::SumSlicer, WireCell::IFrameSlicer, WireCell::IConfigurable) WIRECELL_FACTORY(SumSlices
std::shared_ptr< const IFrame > input_pointer
void slice(const IFrame::pointer &in, slice_map_t &sm)
Definition: SumSlice.cxx:48
IAnodePlane::pointer m_anode
Definition: SumSlice.h:60
virtual void configure(const WireCell::Configuration &cfg)
Accept a configuration.
Definition: SumSlice.cxx:40
static QCString * s
Definition: config.cpp:1042