Skip to content

Commit

Permalink
Merge pull request #325 from WireCell/feature/wgu_pdhd_apa1
Browse files Browse the repository at this point in the history
Configurable filter names
  • Loading branch information
HaiwangYu authored Aug 16, 2024
2 parents 1a00d64 + 0047230 commit 263396c
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 49 deletions.
21 changes: 17 additions & 4 deletions sigproc/inc/WireCellSigProc/OmnibusSigProc.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,26 @@ namespace WireCell {
double m_r_sigma{2.0};
double m_r_th_percent{0.1};

// Filter names
std::string m_ROI_tight_lf_filter{"ROI_tight_lf"};
std::string m_ROI_tighter_lf_filter{"ROI_tighter_lf"};
std::string m_ROI_loose_lf_filter{"ROI_loose_lf"};

std::string m_Gaus_wide_filter{"Gaus_wide"};

std::vector<std::string> m_Wiener_tight_filters{"Wiener_tight_U", "Wiener_tight_V", "Wiener_tight_W"};
std::vector<std::string> m_Wiener_wide_filters{"Wiener_wide_U", "Wiener_wide_V", "Wiener_wide_W"};
std::vector<std::string> m_Wire_filters{"Wire_ind", "Wire_ind", "Wire_col"};

// specify the planes to process
std::vector<int> m_process_planes{0,1,2};

// Assign different layer indices for U/V/W planes (default 0,1,2)
// Fixme: it's a temporary solution for the collective V plane in PDHD, see:
// https://github.com/WireCell/wire-cell-toolkit/issues/322
std::vector<int> m_plane2layer{0,1,2};


// fixme: this is apparently not used:
// channel offset
int m_charge_ch_offset{10000};
Expand Down Expand Up @@ -233,10 +250,6 @@ namespace WireCell {
// samples.
bool m_sparse{false};

// If true, load plane response with an ident number, see:
// https://github.com/WireCell/wire-cell-toolkit/issues/322
bool m_load_fr_with_plane_ident{false};

size_t m_count{0};
int m_verbose{0};

Expand Down
137 changes: 92 additions & 45 deletions sigproc/src/OmnibusSigProc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ std::string WireCell::SigProc::OmnibusSigProc::OspChan::str() const
void OmnibusSigProc::configure(const WireCell::Configuration& config)
{
m_sparse = get(config, "sparse", false);
m_load_fr_with_plane_ident = get(config, "load_fr_with_plane_ident", false);

m_fine_time_offset = get(config, "ftoffset", m_fine_time_offset);
m_coarse_time_offset = get(config, "ctoffset", m_coarse_time_offset);
Expand Down Expand Up @@ -114,13 +113,43 @@ void OmnibusSigProc::configure(const WireCell::Configuration& config)
m_r_sigma = get(config, "r_sigma", m_r_sigma);
m_r_th_percent = get(config, "r_th_percent", m_r_th_percent);

m_ROI_tight_lf_filter = get(config, "ROI_tight_lf_filter", m_ROI_tight_lf_filter);
m_ROI_tighter_lf_filter = get(config, "ROI_tighter_lf_filter", m_ROI_tighter_lf_filter);
m_ROI_loose_lf_filter = get(config, "ROI_loose_lf_filter", m_ROI_loose_lf_filter);
m_Gaus_wide_filter = get(config, "Gaus_wide_filter", m_Gaus_wide_filter);
if (config.isMember("Wiener_tight_filters")) {
m_Wiener_tight_filters.clear();
for (auto name: config["Wiener_tight_filters"]) {
m_Wiener_tight_filters.push_back(name.asString());
}
}
if (config.isMember("Wiener_wide_filters")) {
m_Wiener_wide_filters.clear();
for (auto name: config["Wiener_wide_filters"]) {
m_Wiener_wide_filters.push_back(name.asString());
}
}
if (config.isMember("Wire_filters")) {
m_Wire_filters.clear();
for (auto name: config["Wire_filters"]) {
m_Wire_filters.push_back(name.asString());
}
}

if (config.isMember("process_planes")) {
m_process_planes.clear();
for (auto jplane : config["process_planes"]) {
m_process_planes.push_back(jplane.asInt());
}
}

if (config.isMember("plane2layer")) {
m_plane2layer.clear();
for (auto jplane : config["plane2layer"]) {
m_plane2layer.push_back(jplane.asInt());
}
}

m_charge_ch_offset = get(config, "charge_ch_offset", m_charge_ch_offset);

m_wiener_tag = get(config, "wiener_tag", m_wiener_tag);
Expand Down Expand Up @@ -181,13 +210,19 @@ void OmnibusSigProc::configure(const WireCell::Configuration& config)
}
for (auto plane : face->planes()) {
int plane_index = plane->planeid().index();
auto& pchans = plane_channels[plane_index];
// Remap plane layer if necessary (default: 0,1,2), see:
// https://github.com/WireCell/wire-cell-toolkit/issues/322
int layer_index = m_plane2layer[plane_index];
auto& pchans = plane_channels[layer_index];
// auto& pchans = plane_channels[plane_index];

// These IChannel vectors are ordered in same order as wire-in-plane.
const auto& ichans = plane->channels();
// Append
pchans.reserve(pchans.size() + ichans.size());
pchans.insert(pchans.end(), ichans.begin(), ichans.end());
ss << "\tpind" << plane_index << " "
<< "lind" << layer_index << " "
<< "aid" << m_anode->ident() << " "
<< "fid" << face->ident() << " "
<< "pid" << plane->ident() << " "
Expand Down Expand Up @@ -265,6 +300,11 @@ WireCell::Configuration OmnibusSigProc::default_configuration() const
cfg["r_sigma"] = m_r_sigma;
cfg["r_th_precent"] = m_r_th_percent;

cfg["ROI_tight_lf_filter"] = m_ROI_tight_lf_filter;
cfg["ROI_tighter_lf_filter"] = m_ROI_tighter_lf_filter;
cfg["ROI_loose_lf_filter"] = m_ROI_loose_lf_filter;
cfg["Gaus_wide_filter"] = m_Gaus_wide_filter;

// cfg["process_planes"] = Json::arrayValue;

// fixme: unused?
Expand Down Expand Up @@ -298,7 +338,6 @@ WireCell::Configuration OmnibusSigProc::default_configuration() const
cfg["isWarped"] = m_isWrapped; // default false

cfg["sparse"] = false;
cfg["load_fr_with_plane_ident"] = false;

return cfg;
}
Expand Down Expand Up @@ -792,16 +831,9 @@ void OmnibusSigProc::init_overall_response(IFrame::pointer frame)

// Convert each average FR to a 2D array
for (int iplane = 0; iplane < 3; ++iplane) {
Array::array_xxf arr;
if (m_load_fr_with_plane_ident) {
// Load correct field response for the swapped V&W planes in PDHD APA1. See:
// https://github.com/WireCell/wire-cell-toolkit/issues/322
arr = Response::as_array(*(fravg.plane(iplane)), fine_nwires, fine_nticks);
}
else {
arr = Response::as_array(fravg.planes[iplane], fine_nwires, fine_nticks);
}

int ilayer = m_plane2layer[iplane]; // Remap plane layer if necessary (default: 0,1,2), see:
// https://github.com/WireCell/wire-cell-toolkit/issues/322
auto arr = Response::as_array(fravg.planes[ilayer], fine_nwires, fine_nticks);

int nrows = 0;
int ncols = 0;
Expand Down Expand Up @@ -1011,9 +1043,9 @@ void OmnibusSigProc::decon_2D_init(int plane)
m_c_data[plane] = m_c_data[plane] / c_resp;

// apply software filter on wire
const std::vector<std::string> filter_names{"Wire_ind", "Wire_ind", "Wire_col"};
// const std::vector<std::string> filter_names{"Wire_ind", "Wire_ind", "Wire_col"};
Waveform::realseq_t wire_filter_wf;
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", filter_names[plane]);
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wire_filters[plane]);
wire_filter_wf = ncr1->filter_waveform(m_c_data[plane].rows());
for (int irow = 0; irow < m_c_data[plane].rows(); ++irow) {
for (int icol = 0; icol < m_c_data[plane].cols(); ++icol) {
Expand Down Expand Up @@ -1064,10 +1096,10 @@ void OmnibusSigProc::decon_2D_ROI_refine(int plane)
{
// apply software filter on time

const std::vector<std::string> filter_names{"Wiener_tight_U", "Wiener_tight_V", "Wiener_tight_W"};
// const std::vector<std::string> filter_names{"Wiener_tight_U", "Wiener_tight_V", "Wiener_tight_W"};
Waveform::realseq_t roi_hf_filter_wf;

auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", filter_names[plane]);
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());

Array::array_xxc c_data_afterfilter(m_c_data[plane].rows(), m_c_data[plane].cols());
Expand All @@ -1090,25 +1122,28 @@ void OmnibusSigProc::decon_2D_tightROI(int plane)

Waveform::realseq_t roi_hf_filter_wf;
if (plane == 0) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_U");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_U");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_tight_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_tight_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf.at(i) *= temp_filter.at(i);
}
}
else if (plane == 1) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_V");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_V");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_tight_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_tight_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf.at(i) *= temp_filter.at(i);
}
}
else {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_W");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_W");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}

Expand All @@ -1133,25 +1168,28 @@ void OmnibusSigProc::decon_2D_tighterROI(int plane)

Waveform::realseq_t roi_hf_filter_wf;
if (plane == 0) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_U");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_U");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_tighter_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_tighter_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf.at(i) *= temp_filter.at(i);
}
}
else if (plane == 1) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_V");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_V");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_tighter_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_tighter_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf.at(i) *= temp_filter.at(i);
}
}
else {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_W");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_W");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}

Expand Down Expand Up @@ -1181,45 +1219,48 @@ void OmnibusSigProc::decon_2D_looseROI(int plane)
Waveform::realseq_t roi_hf_filter_wf1;
Waveform::realseq_t roi_hf_filter_wf2;
if (plane == 0) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_U");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_U");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
roi_hf_filter_wf1 = roi_hf_filter_wf;
{
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_loose_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_loose_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf.at(i) *= temp_filter.at(i);
}
}
{
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_tight_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_tight_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf1.at(i) *= temp_filter.at(i);
}
}
}
else if (plane == 1) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_V");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_V");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
roi_hf_filter_wf1 = roi_hf_filter_wf;
{
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_loose_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_loose_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf.at(i) *= temp_filter.at(i);
}
}
{
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_tight_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_tight_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf1.at(i) *= temp_filter.at(i);
}
}
}
else {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_W");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_W");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}

Expand Down Expand Up @@ -1257,25 +1298,28 @@ void OmnibusSigProc::decon_2D_looseROI_debug_mode(int plane)

Waveform::realseq_t roi_hf_filter_wf;
if (plane == 0) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_U");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_U");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_loose_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_loose_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf.at(i) *= temp_filter.at(i);
}
}
else if (plane == 1) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_V");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_V");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", "ROI_loose_lf");
auto ncr2 = Factory::find<IFilterWaveform>("LfFilter", m_ROI_loose_lf_filter);
auto temp_filter = ncr2->filter_waveform(m_c_data[plane].cols());
for (size_t i = 0; i != roi_hf_filter_wf.size(); i++) {
roi_hf_filter_wf.at(i) *= temp_filter.at(i);
}
}
else {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_W");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_tight_W");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_tight_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}

Expand Down Expand Up @@ -1329,15 +1373,18 @@ void OmnibusSigProc::decon_2D_hits(int plane)

Waveform::realseq_t roi_hf_filter_wf;
if (plane == 0) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_wide_U");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_wide_U");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_wide_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}
else if (plane == 1) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_wide_V");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_wide_V");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_wide_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}
else {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_wide_W");
// auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Wiener_wide_W");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Wiener_wide_filters[plane]);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}

Expand All @@ -1362,15 +1409,15 @@ void OmnibusSigProc::decon_2D_charge(int plane)

Waveform::realseq_t roi_hf_filter_wf;
if (plane == 0) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Gaus_wide");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Gaus_wide_filter);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}
else if (plane == 1) {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Gaus_wide");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Gaus_wide_filter);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}
else {
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", "Gaus_wide");
auto ncr1 = Factory::find<IFilterWaveform>("HfFilter", m_Gaus_wide_filter);
roi_hf_filter_wf = ncr1->filter_waveform(m_c_data[plane].cols());
}

Expand Down

0 comments on commit 263396c

Please sign in to comment.