PerChannelResponse.cxx
Go to the documentation of this file.
2 
3 #include "WireCellUtil/Persist.h"
5 #include "WireCellUtil/String.h"
6 
8 
9 WIRECELL_FACTORY(PerChannelResponse,
12 
13 using namespace WireCell;
14 
16  : m_filename(filename)
17 {
18 }
19 
20 SigProc::PerChannelResponse::~PerChannelResponse()
21 {
22 }
23 
24 WireCell::Configuration SigProc::PerChannelResponse::default_configuration() const
25 {
27  cfg["filename"] = m_filename;
28  return cfg;
29 }
30 
32 {
33  m_filename = get(cfg, "filename", m_filename);
34  if (m_filename.empty()) {
35  THROW(ValueError() << errmsg{"must supply a PerChannelResponse filename"});
36  }
37 
38  auto top = Persist::load(m_filename);
39  const double tick = top["tick"].asFloat();
40  const double t0 = top["t0"].asFloat();
41  auto jchannels = top["channels"];
42  if (jchannels.isNull()) {
43  THROW(ValueError() << errmsg{"no channels given in file " + m_filename});
44  }
45 
46  for (auto jchresp : jchannels) {
47  const int ch = jchresp[0].asInt();
48  auto jresp = jchresp[1];
49  const int nsamp = jresp.size();
50  if (nsamp == 0) {
51  THROW(ValueError() << errmsg{"zero length response in file " + m_filename});
52  }
53  Waveform::realseq_t resp(nsamp, 0);
54  for (int ind=0; ind<nsamp; ++ind) {
55  resp[ind] = jresp[ind].asFloat();
56  }
57  m_cr[ch] = resp;
58  if (!m_bins.nbins()) { // first time
59  m_bins = Binning(nsamp, t0, t0+nsamp*tick);
60  }
61  }
62 
63 }
64 
65 
66 const Waveform::realseq_t& SigProc::PerChannelResponse::channel_response(int channel_ident) const
67 {
68  const auto& it = m_cr.find(channel_ident);
69  if (it == m_cr.end()) {
70  THROW(KeyError() << errmsg{String::format("no response for channel %d", channel_ident)});
71  }
72  return it->second;
73 }
74 
75 Binning SigProc::PerChannelResponse::channel_response_binning() const
76 {
77  return m_bins;
78 }
code to link reconstructed objects back to the MC truth information
Sequence< real_t > realseq_t
Definition: Waveform.h:31
WIRECELL_FACTORY(PerChannelResponse, WireCell::SigProc::PerChannelResponse, WireCell::IChannelResponse, WireCell::IConfigurable) using namespace WireCell
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
cfg
Definition: dbjson.py:29
string filename
Definition: train.py:213
const double tick
def configure(cfg)
Definition: cuda.py:34
#define THROW(e)
Definition: Exceptions.h:25
Thrown when a wrong value has been encountered.
Definition: Exceptions.h:37
Definition: Main.h:22
Json::Value Configuration
Definition: Configuration.h:50
def channel_ident(G, wire)
Definition: apa.py:445
Thrown when a wrong key or has been encountered.
Definition: Exceptions.h:43
def load(filename, jpath="depos")
Definition: depos.py:34