20 #include "PMTNoiseROI.h" 30 : m_intag(
"quiet"), m_outtag(
"raw"), m_anode_tn(anode_tn)
31 , m_pad_window(pad_window)
32 , m_min_window_length(min_window_length)
33 , m_threshold(threshold)
34 , m_rms_threshold(rms_threshold)
35 , m_sort_wires(sort_wires)
38 , m_nwire_pmt_col_th(nwire_pmt_col_th)
88 std::map<int, Waveform::realseq_t> bychan_coll;
89 std::map<int, Waveform::realseq_t> bychan_indu;
90 std::map<int, Waveform::realseq_t> bychan_indv;
91 std::map<int,double> by_chan_rms;
94 for (
auto trace : traces) {
95 int ch =
trace->channel();
97 auto wpid =
m_anode->resolve(ch);
98 const int iplane = wpid.index();
102 by_chan_rms[ch] = results.second;
107 bychan_indu[ch] =
trace->charge();
108 }
else if (iplane == 1){
109 bychan_indv[ch] =
trace->charge();
111 bychan_coll[ch] =
trace->charge();
117 for (
auto cs : bychan_coll) {
125 for (
auto cs : bychan_indu) {
130 for (
auto cs : bychan_indv) {
138 for (
int i=0;i!=
int(PMT_ROIs.size());i++){
141 if (PMT_ROIs.at(i)->get_sorted_uwires().size() > 0 && PMT_ROIs.at(i)->get_sorted_vwires().size() > 0){
142 for (
int j=0;j!=
int(PMT_ROIs.at(i)->get_sorted_uwires().size());j++){
143 if (PMT_ROIs.at(i)->get_average_uwires_peak_height(j) <
m_ind_th1* PMT_ROIs.at(i)->get_average_wwires_peak_height() &&
144 PMT_ROIs.at(i)->get_max_uwires_peak_height(j) <
m_ind_th2 * PMT_ROIs.at(i)->get_max_wwires_peak_height() &&
145 PMT_ROIs.at(i)->get_sorted_uwires().at(j).size() <= PMT_ROIs.at(i)->get_sorted_wwires().size()
148 for (
int k=0;
k!=
int(PMT_ROIs.at(i)->get_sorted_uwires().at(j).size());
k++){
149 RemovePMTSignal(bychan_indu[PMT_ROIs.at(i)->get_sorted_uwires().at(j).at(
k)],PMT_ROIs.at(i)->get_start_bin(),PMT_ROIs.at(i)->get_end_bin());
157 for (
int j=0;j!=
int(PMT_ROIs.at(i)->get_sorted_vwires().size());j++){
158 if (PMT_ROIs.at(i)->get_average_vwires_peak_height(j) <
m_ind_th1 * PMT_ROIs.at(i)->get_average_wwires_peak_height() &&
159 PMT_ROIs.at(i)->get_max_vwires_peak_height(j) <
m_ind_th2 * PMT_ROIs.at(i)->get_max_wwires_peak_height() &&
160 PMT_ROIs.at(i)->get_sorted_vwires().at(j).size() <= PMT_ROIs.at(i)->get_sorted_wwires().size()
163 for (
int k=0;
k!=
int(PMT_ROIs.at(i)->get_sorted_vwires().at(j).size());
k++){
164 RemovePMTSignal(bychan_indv[PMT_ROIs.at(i)->get_sorted_vwires().at(j).at(
k)],PMT_ROIs.at(i)->get_start_bin(),PMT_ROIs.at(i)->get_end_bin());
172 for (
int j=0;j!=
int(PMT_ROIs.at(i)->get_sorted_wwires().size());j++){
173 RemovePMTSignal(bychan_coll[PMT_ROIs.at(i)->get_sorted_wwires().at(j)],PMT_ROIs.at(i)->get_start_bin(),PMT_ROIs.at(i)->get_end_bin(),1);
180 delete PMT_ROIs.at(i);
188 for (
auto cs : bychan_indu) {
193 for (
auto cs : bychan_indv) {
198 for (
auto cs : bychan_coll) {
205 for (
size_t ind=0; ind<itraces.size(); ++ind) {
226 for (
int i=0;i!=
int(signal.size());i++){
227 float content = signal.at(i);
238 float min = signal.at(start_bin);
239 peak_bin = start_bin;
240 for (
int j=start_bin+1;j!=end_bin;j++){
241 if (signal.at(j) <
min)
248 if (PMT_ROIs.size()==0){
249 PMT_ROIs.push_back(ROI);
251 bool flag_merge =
false;
252 for (
int i=0;i!=
int(PMT_ROIs.size());i++){
253 flag_merge = PMT_ROIs.at(i)->merge_ROI(*ROI);
260 PMT_ROIs.push_back(ROI);
303 for (
int i=0;i!=
int(PMT_ROIs.size());i++){
307 int peak_m1 = peak - 1;
if (peak_m1 <0) peak_m1 = 0;
308 int peak_m2 = peak - 2;
if (peak_m2 <0) peak_m2 = 0;
309 int peak_m3 = peak - 3;
if (peak_m3 <0) peak_m3 = 0;
310 int peak_p1 = peak + 1;
if (peak_p1 >=
int(signal.size())) peak_p1 =
int(signal.size())-1;
311 int peak_p2 = peak + 2;
if (peak_p2 >=
int(signal.size())) peak_p2 =
int(signal.size())-1;
312 int peak_p3 = peak + 3;
if (peak_p3 >=
int(signal.size())) peak_p3 =
int(signal.size())-1;
315 fabs(signal.at(peak)) + fabs(signal.at(peak_m1)) + fabs(signal.at(peak_p1)) > fabs(signal.at(peak_m1)) + fabs(signal.at(peak_m2)) + fabs(signal.at(peak)) &&
316 fabs(signal.at(peak)) + fabs(signal.at(peak_m1)) + fabs(signal.at(peak_p1)) > fabs(signal.at(peak_p1)) + fabs(signal.at(peak_p2)) + fabs(signal.at(peak)) &&
317 fabs(signal.at(peak)) + fabs(signal.at(peak_m1)) + fabs(signal.at(peak_p1)) > fabs(signal.at(peak_m2)) + fabs(signal.at(peak_m3)) + fabs(signal.at(peak_m1)) &&
318 fabs(signal.at(peak)) + fabs(signal.at(peak_m1)) + fabs(signal.at(peak_p1)) > fabs(signal.at(peak_p2)) + fabs(signal.at(peak_p3)) + fabs(signal.at(peak_p1)) ){
343 float start_content = signal.at(start_bin);
346 if (fabs(signal.at(j)) < fabs(start_content)){
348 start_content = signal.at(start_bin);
351 float end_content = signal.at(end_bin);
353 if (j>=
int(signal.size()))
continue;
354 if (fabs(signal.at(j)) < fabs(end_content)){
356 end_content = signal.at(end_bin);
360 for (
int j=start_bin;j<=end_bin;j++){
361 float content = start_content + (end_content - start_content) * (j - start_bin) / (end_bin - start_bin*1.0);
364 signal.at(j) = content;
366 signal.at(j)=content;
std::shared_ptr< const ITrace > pointer
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
void tag_traces(const tag_t &tag, const IFrame::trace_list_t &indices, const IFrame::trace_summary_t &summary=IFrame::trace_summary_t(0))
boost::error_info< struct tag_errmsg, std::string > errmsg
WIRECELL_FACTORY(OmnibusPMTNoiseFilter, WireCell::SigProc::OmnibusPMTNoiseFilter, WireCell::IFrameFilter, WireCell::IConfigurable) using namespace WireCell
void IDPMTSignalInduction(Waveform::realseq_t &signal, double rms, int ch, int plane)
void insert_uwires(int wire_no, float peak_height)
std::pair< double, double > CalcRMS(const WireCell::Waveform::realseq_t &signal)
std::vector< pointer > vector
virtual void configure(const WireCell::Configuration &config)
IConfigurable interface.
void IDPMTSignalCollection(Waveform::realseq_t &signal, double rms, int ch)
Explicitly inject required services.
std::shared_ptr< const IFrame > input_pointer
virtual bool operator()(const input_pointer &in, output_pointer &out)
IFrameFilter interface.
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
void RemovePMTSignal(Waveform::realseq_t &signal, int start_bin, int end_bin, int flag=0)
OmnibusPMTNoiseFilter(const std::string anode_tn="AnodePlane", int pad_window=5, int min_window_length=4, int threshold=4, float rms_threshold=0.5, int sort_wires=4, float ind_th1=2.0, float ind_th2=0.5, int nwire_pmt_col_th=6)
Create an OmnibusPMTNoiseFilter.
std::shared_ptr< const IFrame > output_pointer
IAnodePlane::pointer m_anode
std::vector< PMTNoiseROI * > PMT_ROIs
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
WireCell::ITrace::vector tagged_traces(WireCell::IFrame::pointer frame, WireCell::IFrame::tag_t tag)
Json::Value Configuration
std::vector< int > & get_peaks()
virtual ~OmnibusPMTNoiseFilter()
void insert_vwires(int wire_no, float peak_height)
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
std::vector< size_t > trace_list_t
Thrown when a wrong key or has been encountered.