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

#include <Microboone.h>

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

Public Member Functions

 ADCBitShift (int nbits=12, int exam_nticks=500, double threshold_sigma=7.5, double threshold_fix=0.8)
 
virtual ~ADCBitShift ()
 
virtual WireCell::Waveform::ChannelMaskMap apply (int channel, signal_t &sig) const
 
virtual WireCell::Waveform::ChannelMaskMap apply (channel_signals_t &chansig) const
 
virtual void configure (const WireCell::Configuration &config)
 Accept a configuration. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
- 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::IConfigurable
virtual ~IConfigurable ()
 
- Public Member Functions inherited from WireCell::IComponent< IConfigurable >
virtual ~IComponent ()
 

Private Attributes

int m_nbits
 
int m_exam_nticks
 
double m_threshold_sigma
 
double m_threshold_fix
 

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...
 

Detailed Description

Definition at line 148 of file Microboone.h.

Constructor & Destructor Documentation

Microboone::ADCBitShift::ADCBitShift ( int  nbits = 12,
int  exam_nticks = 500,
double  threshold_sigma = 7.5,
double  threshold_fix = 0.8 
)

Definition at line 1144 of file Microboone.cxx.

1145  : m_nbits(nbits)
1146  , m_exam_nticks(exam_nticks)
1147  , m_threshold_sigma(threshold_sigma)
1148  , m_threshold_fix(threshold_fix)
1149 {
1150 }
Microboone::ADCBitShift::~ADCBitShift ( )
virtual

Definition at line 1151 of file Microboone.cxx.

1152 {
1153 }

Member Function Documentation

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

Filter in place the signal sig from given channel.

Implements WireCell::IChannelFilter.

Definition at line 1183 of file Microboone.cxx.

1184 {
1185  std::vector<int> counter(m_nbits,0);
1186  std::vector<int> s,s1(m_nbits,0);
1187  int nbin = m_exam_nticks;
1188 
1189  for (int i=0;i!=nbin;i++){
1190  int x = signal.at(i);
1191  s.clear();
1192  do
1193  {
1194  s.push_back( (x & 1));
1195  } while (x >>= 1);
1196  s.resize(m_nbits);
1197 
1198  for (int j=0;j!=m_nbits;j++){
1199  counter.at(j) += abs(s.at(j) - s1.at(j));
1200  }
1201  s1=s;
1202  }
1203 
1204  int nshift = 0;
1205  for (int i=0;i!=m_nbits;i++){
1206  if (counter.at(i) < nbin/2. - nbin/2. *sqrt(1./nbin) * m_threshold_sigma){
1207  nshift ++;
1208  }else{
1209  break;
1210  }
1211  }
1212 
1214  if (nshift!=0 && nshift < 11){
1215  WireCell::Waveform::BinRange ADC_bit_shifts;
1216  ADC_bit_shifts.first = nshift;
1217  ADC_bit_shifts.second = nshift;
1218 
1219  ret["ADCBitShift"][ch].push_back(ADC_bit_shifts);
1220 
1221  // do the correction ...
1222  const int nl = signal.size();
1223  std::vector<int> x(nl,0), x_orig(nl,0);
1224  for (int i=0;i!=nl;i++){
1225  x_orig[i] = signal.at(i);
1226  x[i] = signal.at(i);
1227  }
1228 
1229  std::set<int> fillings;
1230  int filling;
1231  int mean = 0;
1232  for (int i=0;i!=nl;i++){
1233  filling = WireCell::Bits::lowest_bits(x_orig[i], nshift);
1234  int y = WireCell::Bits::shift_right(x_orig[i], nshift, filling, 12);
1235  fillings.insert(filling);
1236  // cout << y << " ";
1237  // filling = lowest_bits(x[i], nshift);
1238  // filling = x[i] & int(pow(2, nshift)-1);
1239  x[i] = y;
1240  mean += x[i];
1241  }
1242  mean = mean/nl;
1243 
1244  int exp_diff = pow(2,m_nbits-nshift)*m_threshold_fix;
1245 
1246  // examine the results ...
1247  int prev1_bin_content = mean;
1248  int prev_bin_content = mean;
1249  int next_bin_content = mean;
1250  int next1_bin_content = mean;
1251  int curr_bin_content;
1252 
1253  for (int i=0;i<nl;i=i+1){
1254  curr_bin_content = x[i];
1255  // when to judge if one is likely bad ...
1256  if (abs(curr_bin_content-mean)>exp_diff &&
1257  (abs(curr_bin_content - prev_bin_content) > exp_diff ||
1258  abs(curr_bin_content - next_bin_content) > exp_diff)
1259  ){
1260  int exp_value = ( (2*prev_bin_content - prev1_bin_content) +
1261  (prev_bin_content + next_bin_content)/2. +
1262  (prev_bin_content * 2./3. + next1_bin_content/3.))/3.;
1263  for (auto it = fillings.begin(); it!=fillings.end(); it++){
1264  int y = WireCell::Bits::shift_right(x_orig[i], nshift, (*it), 12);
1265  // when to switch ...
1266  if (fabs(y-exp_value) < fabs(x[i] - exp_value)){
1267  x[i] = y;//hs->SetBinContent(i+1,y);
1268  }
1269  }
1270  }
1271 
1272  prev1_bin_content = prev_bin_content;
1273  prev_bin_content = x[i];
1274  if (i+2 < nl){
1275  next_bin_content = x[i+2];
1276  }else{
1277  next_bin_content = mean;
1278  }
1279  if (i+3 < nl){
1280  next1_bin_content = x[i+3];
1281  }else{
1282  next1_bin_content = mean;
1283  }
1284  }
1285 
1286  // change the histogram ...
1287  for (int i=0;i!=nl;i++){
1288  signal.at(i) = x[i];
1289  }
1290  }
1291  return ret;
1292 }
std::pair< int, int > BinRange
A half-open range of bins (from first bin to one past last bin)
Definition: Waveform.h:38
constexpr T pow(T x)
Definition: pow.h:72
double y
T abs(T value)
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
std::map< std::string, ChannelMasks > ChannelMaskMap
Collect channel masks by some label.
Definition: Waveform.h:59
list x
Definition: train.py:276
int lowest_bits(int value, int n)
Definition: Bits.cxx:9
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:15
std::string nl(std::size_t i=1)
static QCString * s
Definition: config.cpp:1042
int shift_right(int value, int n, int filling, int totalBit)
Definition: Bits.cxx:4
WireCell::Waveform::ChannelMaskMap Microboone::ADCBitShift::apply ( channel_signals_t chansig) const
virtual

Filter in place a group of signals together.

Implements WireCell::IChannelFilter.

Definition at line 1176 of file Microboone.cxx.

1177 {
1178  // No CMM's are produced.
1180 }
std::map< std::string, ChannelMasks > ChannelMaskMap
Collect channel masks by some label.
Definition: Waveform.h:59
void Microboone::ADCBitShift::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 1155 of file Microboone.cxx.

1156 {
1157  m_nbits = get<int>(cfg, "Number_of_ADC_bits", m_nbits);
1158  m_exam_nticks = get<int>(cfg, "Exam_number_of_ticks_test", m_exam_nticks);
1159  m_threshold_sigma = get<double>(cfg, "Threshold_sigma_test", m_threshold_sigma);
1160  m_threshold_fix = get<double>(cfg, "Threshold_fix", m_threshold_fix);
1161  //std::cerr << "ADCBitShift: \n" << cfg << "\n";
1162 }
cfg
Definition: dbjson.py:29
WireCell::Configuration Microboone::ADCBitShift::default_configuration ( ) const
virtual

Optional, override to return a hard-coded default configuration.

Reimplemented from WireCell::IConfigurable.

Definition at line 1163 of file Microboone.cxx.

1164 {
1166  cfg["Number_of_ADC_bits"] = m_nbits;
1167  cfg["Exam_number_of_ticks_test"] = m_exam_nticks;
1168  cfg["Threshold_sigma_test"] = m_threshold_sigma;
1169  cfg["Threshold_fix"] = m_threshold_fix;
1170 
1171  return cfg;
1172 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50

Member Data Documentation

int WireCell::SigProc::Microboone::ADCBitShift::m_exam_nticks
private

Definition at line 167 of file Microboone.h.

int WireCell::SigProc::Microboone::ADCBitShift::m_nbits
private

Definition at line 165 of file Microboone.h.

double WireCell::SigProc::Microboone::ADCBitShift::m_threshold_fix
private

Definition at line 171 of file Microboone.h.

double WireCell::SigProc::Microboone::ADCBitShift::m_threshold_sigma
private

Definition at line 169 of file Microboone.h.


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