PerChannelVariation.cxx
Go to the documentation of this file.
7 
8 #include <string>
9 
12 
13 using namespace WireCell;
14 
16 {
17 }
18 
19 Gen::PerChannelVariation::~PerChannelVariation()
20 {
21 }
22 
23 
24 WireCell::Configuration Gen::PerChannelVariation::default_configuration() const
25 {
27 
28  // nominally correctly configured amplifiers in MB. They should
29  // match what ever was used to create the input waveforms.
30  cfg["gain"] = 14.0*units::mV/units::fC;
31  cfg["shaping"] = 2.2*units::us;
32 
33  // The number of nsamples of the response functions.
34  cfg ["nsamples"] = 310;
35  // The period of sampling the response functions
36  cfg["tick"] = 0.5*units::us;
37 
38  /// If to truncate the waveforms. The convolution
39  /// used to apply the misconfiguring will extend the a trace's
40  /// waveform by nsamples-1. Truncating will clip that much off so
41  /// the waveform will remains the same length but some information
42  /// may be lost. If not truncated, this longer waveform likely
43  /// needs to be handled in some way by the user.
44  cfg["truncate"] = true;
45 
46  /// ch-by-ch electronics responses by calibration
47  cfg["per_chan_resp"] = "";
48 
49  return cfg;
50 }
51 
53 {
54  m_per_chan_resp = get<std::string>(cfg, "per_chan_resp", "");
55 
56  if (! m_per_chan_resp.empty()) {
57  std::cerr<<"SIMULATION: CH-BY-CH ELECTRONICS RESPONSE VARIATION\n";
58  m_cr = Factory::find_tn<IChannelResponse>(m_per_chan_resp);
59  double tick = cfg["tick"].asDouble();
60  auto cr_bins = m_cr->channel_response_binning();
61  if (cr_bins.binsize() != tick) {
62  THROW(ValueError() << errmsg{"PerChannelVariation: channel response tbin size mismatch!"});
63  }
64  m_nsamples = cr_bins.nbins();
65  WireCell::Binning tbins(m_nsamples, cr_bins.min(), cr_bins.min() + m_nsamples*tick);
66  m_from = Response::ColdElec(cfg["gain"].asDouble(),
67  cfg["shaping"].asDouble()).generate(tbins);
68  }
69 
70  m_truncate = cfg["truncate"].asBool();
71 }
72 
73 bool Gen::PerChannelVariation::operator()(const input_pointer& in, output_pointer& out)
74 {
75  if (!in) {
76  out = nullptr;
77  return true;
78  }
79 
80  if (m_per_chan_resp.empty()) {
81  std::cerr << "Gen::PerChannelVariation: warning no ch-by-ch response was found!\n";
82  out = in;
83  return true;
84  }
85 
86  auto traces = in->traces();
87  if (!traces) {
88  std::cerr << "Gen::PerChannelVariation: error no traces in frame for me\n";
89  return false;
90  }
91 
92 
93  size_t ntraces = traces->size();
94  ITrace::vector out_traces(ntraces);
95  for (size_t ind=0; ind<ntraces; ++ind) {
96  auto trace = traces->at(ind);
97  auto chid = trace->channel();
98  Waveform::realseq_t tch_resp = m_cr->channel_response(chid);
99  tch_resp.resize(m_nsamples, 0);
100  auto wave = Waveform::replace_convolve(trace->charge(),
101  tch_resp, m_from, m_truncate);
102  out_traces[ind] = std::make_shared<SimpleTrace>(chid, trace->tbin(), wave);
103  }
104 
105  out = std::make_shared<SimpleFrame>(in->ident(), in->time(), out_traces, in->tick());
106  return true;
107 }
108 
Sequence< real_t > realseq_t
Definition: Waveform.h:31
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
cfg
Definition: dbjson.py:29
std::vector< pointer > vector
Definition: IData.h:21
A functional object caching gain and shape.
Definition: Response.h:165
const double tick
Binning tbins(nticks, t0, t0+readout_time)
realseq_t replace_convolve(Waveform::realseq_t wave, Waveform::realseq_t newres, Waveform::realseq_t oldres, bool truncate=true)
Definition: Waveform.cxx:187
std::shared_ptr< const IFrame > input_pointer
Definition: IFunctionNode.h:39
def configure(cfg)
Definition: cuda.py:34
float fC
Definition: units.py:113
WireCell::Waveform::realseq_t generate(const WireCell::Waveform::Domain &domain, int nsamples)
FIXME: eradicate Domain in favor of Binning.
Definition: Response.cxx:303
#define THROW(e)
Definition: Exceptions.h:25
std::shared_ptr< const IFrame > output_pointer
Definition: IFunctionNode.h:40
Thrown when a wrong value has been encountered.
Definition: Exceptions.h:37
Definition: Main.h:22
static const double us
Definition: Units.h:101
Json::Value Configuration
Definition: Configuration.h:50
WIRECELL_FACTORY(PerChannelVariation, WireCell::Gen::PerChannelVariation, WireCell::IFrameFilter, WireCell::IConfigurable) using namespace WireCell