Misconfigure.cxx
Go to the documentation of this file.
7 
10 
11 using namespace WireCell;
12 
14 {
15 }
16 
17 Gen::Misconfigure::~Misconfigure()
18 {
19 }
20 
21 
22 WireCell::Configuration Gen::Misconfigure::default_configuration() const
23 {
25 
26  // nominally correctly configured amplifiers in MB. They should
27  // match what ever was used to create the input waveforms.
28  cfg["from"]["gain"] = 14.0*units::mV/units::fC;
29  cfg["from"]["shaping"] = 2.2*units::us;
30 
31  // Nominally misconfigured amplifiers in MB. They should match
32  // whatever you wished the input waveforms would have been created
33  // with.
34  cfg["to"]["gain"] = 4.7*units::mV/units::fC;
35  cfg["to"]["shaping"] = 1.1*units::us;
36 
37  /// The number of samples of the response functions.
38  cfg["nsamples"] = 50;
39  /// The period of sampling the response functions
40  cfg["tick"] = 0.5*units::us;
41 
42  /// If to truncate the misconfigured waveforms. The convolution
43  /// used to apply the misconfiguring will extend the a trace's
44  /// waveform by nsamples-1. Truncating will clip that much off so
45  /// the waveform will remains the same length but some information
46  /// may be lost. If not truncated, this longer waveform likely
47  /// needs to be handled in some way by the user.
48  cfg["truncate"] = true;
49 
50  return cfg;
51 }
52 
54 {
55  int n = cfg["nsamples"].asInt();
56  double tick = cfg["tick"].asDouble();
57  Binning bins(n, 0, n*tick);
58 
59  m_from = Response::ColdElec(cfg["from"]["gain"].asDouble(),
60  cfg["from"]["shaping"].asDouble()).generate(bins);
61  m_to = Response::ColdElec(cfg["to"]["gain"].asDouble(),
62  cfg["to"]["shaping"].asDouble()).generate(bins);
63 
64  m_truncate = cfg["truncate"].asBool();
65 }
66 
67 bool Gen::Misconfigure::operator()(const input_pointer& in, output_pointer& out)
68 {
69  out = nullptr;
70  if (!in) {
71  return true; // eos, but we don't care here.
72  }
73 
74  auto traces = in->traces();
75  if (!traces) {
76  std::cerr << "Gen::Misconfigure: warning no traces in frame for me\n";
77  return true;
78  }
79 
80  size_t ntraces = traces->size();
81  ITrace::vector out_traces(ntraces);
82  for (size_t ind=0; ind<ntraces; ++ind) {
83  auto trace = traces->at(ind);
84 
85  auto wave = Waveform::replace_convolve(trace->charge(),
86  m_to, m_from, m_truncate);
87  out_traces[ind] = std::make_shared<SimpleTrace>(trace->channel(), trace->tbin(), wave);
88  }
89 
90  out = std::make_shared<SimpleFrame>(in->ident(), in->time(), out_traces, in->tick());
91  return true;
92 }
93 
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
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
std::shared_ptr< const IFrame > output_pointer
Definition: IFunctionNode.h:40
WIRECELL_FACTORY(Misconfigure, WireCell::Gen::Misconfigure, WireCell::IFrameFilter, WireCell::IConfigurable) using namespace WireCell
Definition: Main.h:22
static const double us
Definition: Units.h:101
Json::Value Configuration
Definition: Configuration.h:50
std::size_t n
Definition: format.h:3399