forked from brettviren/wire-cell-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #396 from WireCell/feature/wgu_filt_resp
Add filter on field response
- Loading branch information
Showing
4 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** This component provides per-wire filtering of | ||
* field responses based on a configuration data file. */ | ||
|
||
#ifndef WIRECELLSIGPROC_FILTERRESPONSE | ||
#define WIRECELLSIGPROC_FILTERRESPONSE | ||
|
||
#include "WireCellIface/IChannelResponse.h" | ||
#include "WireCellIface/IConfigurable.h" | ||
#include "WireCellUtil/Units.h" | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace WireCell { | ||
namespace SigProc { | ||
class FilterResponse : public IChannelResponse, public IConfigurable { | ||
public: | ||
FilterResponse(const char* filename = "", const int planeid = 0); | ||
|
||
virtual ~FilterResponse(); | ||
|
||
// IChannelResponse | ||
virtual const Waveform::realseq_t& channel_response(int channel_ident) const; | ||
virtual Binning channel_response_binning() const; | ||
|
||
// IConfigurable | ||
virtual void configure(const WireCell::Configuration& config); | ||
virtual WireCell::Configuration default_configuration() const; | ||
|
||
private: | ||
std::string m_filename; | ||
int m_planeid; | ||
std::unordered_map<int, Waveform::realseq_t> m_cr; | ||
Binning m_bins; | ||
}; | ||
|
||
} // namespace SigProc | ||
|
||
} // namespace WireCell | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "WireCellSigProc/FilterResponse.h" | ||
|
||
#include "WireCellUtil/Persist.h" | ||
#include "WireCellUtil/Exceptions.h" | ||
#include "WireCellUtil/String.h" | ||
#include "WireCellUtil/Response.h" | ||
|
||
#include "WireCellUtil/NamedFactory.h" | ||
|
||
WIRECELL_FACTORY(FilterResponse, WireCell::SigProc::FilterResponse, WireCell::IChannelResponse, | ||
WireCell::IConfigurable) | ||
|
||
using namespace WireCell; | ||
|
||
SigProc::FilterResponse::FilterResponse(const char* filename, const int planeid) | ||
: m_filename(filename), m_planeid(planeid) | ||
{ | ||
} | ||
|
||
SigProc::FilterResponse::~FilterResponse() {} | ||
|
||
WireCell::Configuration SigProc::FilterResponse::default_configuration() const | ||
{ | ||
Configuration cfg; | ||
cfg["filename"] = m_filename; | ||
cfg["planeid"] = m_planeid; | ||
return cfg; | ||
} | ||
|
||
void SigProc::FilterResponse::configure(const WireCell::Configuration& cfg) | ||
{ | ||
|
||
m_filename = get(cfg, "filename", m_filename); | ||
if (m_filename.empty()) { | ||
THROW(ValueError() << errmsg{"must supply a FilterResponse filename"}); | ||
} | ||
m_planeid = get(cfg, "planeid", m_planeid); | ||
|
||
auto top = Persist::load(m_filename); | ||
const int nwires = top["nwires"].asInt(); | ||
const int nticks = top["nticks"].asInt(); | ||
if (!m_bins.nbins()) { // first time | ||
m_bins = Binning(nticks, 0, nticks); // tick range for filter | ||
} | ||
auto jflts = top["filters"]; | ||
if (jflts.isNull()) { | ||
THROW(ValueError() << errmsg{"no filters given in file " + m_filename}); | ||
} | ||
|
||
for (auto jflt : jflts) { | ||
const int plane = jflt["plane"].asInt(); | ||
if (plane != m_planeid) continue; | ||
|
||
const int wire = jflt["wire"].asInt(); | ||
Waveform::realseq_t resp(nticks, 0.0); | ||
std::transform(jflt["values"].begin(), jflt["values"].end(), resp.begin(), | ||
[](const auto& v) { return v.asFloat(); }); | ||
m_cr[wire] = resp; | ||
} | ||
} | ||
|
||
const Waveform::realseq_t& SigProc::FilterResponse::channel_response(int channel_ident) const | ||
{ | ||
const auto& it = m_cr.find(channel_ident); | ||
if (it == m_cr.end()) { | ||
THROW(KeyError() << errmsg{String::format("no response for channel %d", channel_ident)}); | ||
} | ||
return it->second; | ||
} | ||
|
||
Binning SigProc::FilterResponse::channel_response_binning() const { return m_bins; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters