Public Member Functions | Private Attributes | List of all members
WireCell::SigProc::Microboone::OneChannelNoise Class Reference

#include <Microboone.h>

Inheritance diagram for WireCell::SigProc::Microboone::OneChannelNoise:
WireCell::IChannelFilter WireCell::SigProc::Microboone::ConfigFilterBase WireCell::IComponent< IChannelFilter > WireCell::IConfigurable WireCell::Interface WireCell::IComponent< IConfigurable > WireCell::Interface

Public Member Functions

 OneChannelNoise (const std::string &anode_tn="AnodePlane", const std::string &noisedb="OmniChannelNoiseDB")
 
virtual ~OneChannelNoise ()
 
virtual WireCell::Waveform::ChannelMaskMap apply (int channel, signal_t &sig) const
 
virtual WireCell::Waveform::ChannelMaskMap apply (channel_signals_t &chansig) const
 
- Public Member Functions inherited from WireCell::IChannelFilter
virtual ~IChannelFilter ()
 
- Public Member Functions inherited from WireCell::IComponent< IChannelFilter >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 
- Public Member Functions inherited from WireCell::SigProc::Microboone::ConfigFilterBase
 ConfigFilterBase (const std::string &anode="AnodePlane", const std::string &noisedb="OmniChannelNoiseDB")
 
virtual ~ConfigFilterBase ()
 
virtual void configure (const WireCell::Configuration &config)
 IConfigurable configuration interface. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
void set_channel_noisedb (WireCell::IChannelNoiseDatabase::pointer ndb)
 
- Public Member Functions inherited from WireCell::IConfigurable
virtual ~IConfigurable ()
 
- Public Member Functions inherited from WireCell::IComponent< IConfigurable >
virtual ~IComponent ()
 

Private Attributes

Diagnostics::Chirp m_check_chirp
 
Diagnostics::Partial m_check_partial
 

Additional Inherited Members

- Public Types inherited from WireCell::IChannelFilter
typedef Waveform::realseq_t signal_t
 
typedef std::map< int, signal_tchannel_signals_t
 
- Public Types inherited from WireCell::IComponent< IChannelFilter >
typedef std::shared_ptr< IChannelFilterpointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Public Types inherited from WireCell::Interface
typedef std::shared_ptr< Interfacepointer
 
- Public Types inherited from WireCell::IComponent< IConfigurable >
typedef std::shared_ptr< IConfigurablepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Protected Attributes inherited from WireCell::SigProc::Microboone::ConfigFilterBase
std::string m_anode_tn
 
std::string m_noisedb_tn
 
IAnodePlane::pointer m_anode
 
IChannelNoiseDatabase::pointer m_noisedb
 

Detailed Description

Microboone style single channel noise subtraction.

Fixme: in principle, this class could be general purpose for other detectors. However, it uses the functions above which hard code microboone-isms. If those microboone-specific parameters can be pulled out to a higher layer then this class can become generic and move outside of this file.

Definition at line 97 of file Microboone.h.

Constructor & Destructor Documentation

Microboone::OneChannelNoise::OneChannelNoise ( const std::string anode_tn = "AnodePlane",
const std::string noisedb = "OmniChannelNoiseDB" 
)

Definition at line 956 of file Microboone.cxx.

957  : ConfigFilterBase(anode, noisedb)
958  , m_check_chirp() // fixme, there are magic numbers hidden here
959  , m_check_partial() // fixme, here too.
960 {
961 }
ConfigFilterBase(const std::string &anode="AnodePlane", const std::string &noisedb="OmniChannelNoiseDB")
Definition: Microboone.cxx:849
Microboone::OneChannelNoise::~OneChannelNoise ( )
virtual

Definition at line 962 of file Microboone.cxx.

963 {
964 }

Member Function Documentation

WireCell::Waveform::ChannelMaskMap Microboone::OneChannelNoise::apply ( int  channel,
signal_t sig 
) const
virtual

Filter in place the signal sig from given channel.

Implements WireCell::IChannelFilter.

Definition at line 966 of file Microboone.cxx.

967 {
969 
970  // sanity check data/config match.
971  const size_t nsiglen = signal.size();
972  int nmismatchlen = 0;
973 
974  // fixme: some channels are just bad can should be skipped.
975 
976  // get signal with nominal baseline correction
977  float baseline = m_noisedb->nominal_baseline(ch);
978 
979  // get signal with nominal gain correction
980  float gc = m_noisedb->gain_correction(ch);
981  WireCell::Waveform::increase(signal, baseline *(-1));
982 
983  auto signal_gc = signal; // copy, need to keep original signal
984 
985  WireCell::Waveform::scale(signal_gc, gc);
986 
987  // std::cerr << "OneChannelNoise: ch="<<ch<<" gain scaled sum=" << Waveform::sum(signal_gc)
988  // << std::endl;;
989 
990 
991  // determine if chirping
992  WireCell::Waveform::BinRange chirped_bins;
993  bool is_chirp = m_check_chirp(signal_gc, chirped_bins.first, chirped_bins.second);
994  if (is_chirp) {
995  ret["chirp"][ch].push_back(chirped_bins);
996 
997  auto wpid = m_anode->resolve(ch);
998  const int iplane = wpid.index();
999 
1000  if (iplane!=2){ // not collection
1001  if (chirped_bins.first>0 || chirped_bins.second<int(signal.size())){
1002  ret["lf_noisy"][ch].push_back(chirped_bins);
1003  //std::cout << "Chirp " << ch << std::endl;
1004  }
1005  }
1006  }
1007 
1008  auto spectrum = WireCell::Waveform::dft(signal);
1009  //std::cerr << "OneChannelNoise: "<<ch<<" dft spectral sum="<<Waveform::sum(spectrum)<<"\n";
1010 
1011  bool is_partial = m_check_partial(spectrum); // Xin's "IS_RC()"
1012 
1013  int nspec=0; // just catch any non-zero
1014  if (!is_partial) {
1015  auto const& spec = m_noisedb->rcrc(ch);
1016  WireCell::Waveform::shrink(spectrum, spec);
1017 
1018  if (nsiglen != spec.size()) {
1019  ++nmismatchlen;
1020  nspec=spec.size();
1021  }
1022  }
1023 
1024  {
1025  auto const& spec = m_noisedb->config(ch);
1026  WireCell::Waveform::scale(spectrum, spec);
1027 
1028  if (nsiglen != spec.size()) {
1029  ++nmismatchlen;
1030  nspec=spec.size();
1031  }
1032  }
1033 
1034  {
1035  auto const& spec = m_noisedb->noise(ch);
1036  WireCell::Waveform::scale(spectrum, spec);
1037 
1038  if (nsiglen != spec.size()) {
1039  ++nmismatchlen;
1040  nspec=spec.size();
1041  }
1042  }
1043 
1044  if (nmismatchlen) {
1045  std::cerr << "OneChannelNoise: WARNING: "<<nmismatchlen << " config/data mismatches. "
1046  << "#spec="<<nspec <<", #wave=" << nsiglen << ".\n"
1047  << "\tResults may be suspect."
1048  << std::endl;
1049  }
1050 
1051  // remove the DC component
1052  spectrum.front() = 0;
1053  signal = WireCell::Waveform::idft(spectrum);
1054 
1055  //std::cerr << "OneChannelNoise: "<<ch<<" after dft: sigsum="<<Waveform::sum(signal)<<"\n";
1056 
1057  //Now calculate the baseline ...
1058  std::pair<double,double> temp = WireCell::Waveform::mean_rms(signal);
1059  auto temp_signal = signal;
1060  for (size_t i=0;i!=temp_signal.size();i++){
1061  if (fabs(temp_signal.at(i)-temp.first)>6*temp.second){
1062  temp_signal.at(i) = temp.first;
1063  }
1064  }
1065  baseline = WireCell::Waveform::median_binned(temp_signal);
1066  //correct baseline
1067  WireCell::Waveform::increase(signal, baseline *(-1));
1068 
1069 
1070  //*** from here down is where things become way too microboone
1071  //*** specific and are basically copy-pasted from the prototype
1072 
1073 
1074  // Now do adaptive baseline for the chirping channels
1075  if (is_chirp) {
1076  Microboone::Chirp_raise_baseline(signal,chirped_bins.first, chirped_bins.second);
1077  Microboone::SignalFilter(signal);
1079  }
1080  // Now do the adaptive baseline for the bad RC channels
1081  if (is_partial) {
1082  // add something
1083  WireCell::Waveform::BinRange temp_chirped_bins;
1084  temp_chirped_bins.first = 0;
1085  temp_chirped_bins.second = signal.size();
1086 
1087  auto wpid = m_anode->resolve(ch);
1088  const int iplane = wpid.index();
1089  if (iplane!=2) { // not collection
1090  ret["lf_noisy"][ch].push_back(temp_chirped_bins);
1091  //std::cout << "Partial " << ch << std::endl;
1092  }
1093  Microboone::SignalFilter(signal);
1095  }
1096 
1097  // std::cerr << "OneChannelNoise: "<<ch<<" before SignalFilter: sigsum="<<Waveform::sum(signal)<<"\n";
1098 
1099  // Identify the Noisy channels ...
1100  Microboone::SignalFilter(signal);
1101 
1102  //
1103  const float min_rms = m_noisedb->min_rms_cut(ch);
1104  const float max_rms = m_noisedb->max_rms_cut(ch);
1105 
1106  //std::cerr << "OneChannelNoise: "<<ch<< " RMS:["<<min_rms<<","<<max_rms<<"] sigsum="<<Waveform::sum(signal)<<"\n";
1107 
1108  bool is_noisy = Microboone::NoisyFilterAlg(signal,min_rms,max_rms);
1110 
1111  if (is_noisy) {
1112  // std::cerr << "OneChannelNoise: "<<ch
1113  // <<" is_noisy="<<is_noisy
1114  // <<", is_chirp="<<is_chirp
1115  // <<", is_partial="<<is_partial
1116  // <<", baseline="<<baseline<<std::endl;
1117 
1118  chirped_bins.first = 0;
1119  chirped_bins.second = signal.size();
1120  ret["noisy"][ch].push_back(chirped_bins);
1121 
1122  if (ret.find("lf_noisy") != ret.end()) {
1123  if(ret["lf_noisy"].find(ch)!=ret["lf_noisy"].end())
1124  ret["lf_noisy"].erase(ch);
1125  }
1126 
1127  }
1128 
1129  return ret;
1130 }
bool SignalFilter(WireCell::Waveform::realseq_t &sig)
Definition: Microboone.cxx:648
std::pair< int, int > BinRange
A half-open range of bins (from first bin to one past last bin)
Definition: Waveform.h:38
bool Chirp_raise_baseline(WireCell::Waveform::realseq_t &sig, int bin1, int bin2)
Definition: Microboone.cxx:615
compseq_t dft(realseq_t seq)
Definition: Waveform.cxx:141
void shrink(Sequence< Val > &seq, const Sequence< Val > &other)
Shrink (divide) seq values by values from the other sequence.
Definition: Waveform.h:162
Configuration find(Configuration &lst, const std::string &dotpath, const T &val)
Return dictionary in given list if it value at dotpath matches.
std::map< std::string, ChannelMasks > ChannelMaskMap
Collect channel masks by some label.
Definition: Waveform.h:59
void increase(Sequence< Val > &seq, Val scalar)
Increase (shift) sequence values by scalar.
Definition: Waveform.h:129
bool NoisyFilterAlg(WireCell::Waveform::realseq_t &spec, float min_rms, float max_rms)
Definition: Microboone.cxx:542
real_t median_binned(realseq_t &wave)
Definition: Waveform.cxx:81
bool RawAdapativeBaselineAlg(WireCell::Waveform::realseq_t &sig)
Definition: Microboone.cxx:693
bool RemoveFilterFlags(WireCell::Waveform::realseq_t &sig)
Definition: Microboone.cxx:821
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition: Waveform.h:146
realseq_t idft(compseq_t spec)
Definition: Waveform.cxx:149
std::pair< double, double > mean_rms(const realseq_t &wave)
Definition: Waveform.cxx:24
IChannelNoiseDatabase::pointer m_noisedb
Definition: Microboone.h:55
QTextStream & endl(QTextStream &s)
WireCell::Waveform::ChannelMaskMap Microboone::OneChannelNoise::apply ( channel_signals_t chansig) const
virtual

Filter in place a group of signals together.

Implements WireCell::IChannelFilter.

Definition at line 1134 of file Microboone.cxx.

1135 {
1137 }
std::map< std::string, ChannelMasks > ChannelMaskMap
Collect channel masks by some label.
Definition: Waveform.h:59

Member Data Documentation

Diagnostics::Chirp WireCell::SigProc::Microboone::OneChannelNoise::m_check_chirp
private

Definition at line 115 of file Microboone.h.

Diagnostics::Partial WireCell::SigProc::Microboone::OneChannelNoise::m_check_partial
private

Definition at line 116 of file Microboone.h.


The documentation for this class was generated from the following files: