Public Member Functions | Private Attributes | List of all members
WireCell::Gen::Digitizer Class Reference

#include <Digitizer.h>

Inheritance diagram for WireCell::Gen::Digitizer:
WireCell::IFrameFilter WireCell::IConfigurable WireCell::IFunctionNode< IFrame, IFrame > WireCell::IComponent< IConfigurable > WireCell::IFunctionNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 Digitizer (const std::string &anode_tn="AnodePlane", int resolution=12, double gain=-1.0, std::vector< double > fullscale={0.0, 2.0 *units::volt}, std::vector< double > baselines={900 *units::mV, 900 *units::mV, 200 *units::mV})
 
virtual ~Digitizer ()
 
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...
 
virtual bool operator() (const input_pointer &inframe, output_pointer &outframe)
 The calling signature: More...
 
double digitize (double voltage)
 
- Public Member Functions inherited from WireCell::IFrameFilter
virtual ~IFrameFilter ()
 
virtual std::string signature ()
 Set the signature for all subclasses. More...
 
- Public Member Functions inherited from WireCell::IFunctionNode< IFrame, IFrame >
virtual ~IFunctionNode ()
 
virtual bool operator() (const boost::any &anyin, boost::any &anyout)
 The calling signature: More...
 
virtual std::vector< std::stringinput_types ()
 
virtual std::vector< std::stringoutput_types ()
 
- Public Member Functions inherited from WireCell::IFunctionNodeBase
virtual ~IFunctionNodeBase ()
 
virtual NodeCategory category ()
 Return the behavior category type. More...
 
virtual int concurrency ()
 By default assume all subclasses are stateless. More...
 
- Public Member Functions inherited from WireCell::INode
virtual ~INode ()
 
virtual void reset ()
 
- Public Member Functions inherited from WireCell::IComponent< INode >
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

IAnodePlane::pointer m_anode
 
std::string m_anode_tn
 
int m_resolution
 
double m_gain
 
std::vector< double > m_fullscale
 
std::vector< double > m_baselines
 
std::string m_frame_tag
 
Log::logptr_t log
 

Additional Inherited Members

- Public Types inherited from WireCell::IFrameFilter
typedef std::shared_ptr< IFrameFilterpointer
 
- Public Types inherited from WireCell::IFunctionNode< IFrame, IFrame >
typedef IFrame input_type
 
typedef IFrame output_type
 
typedef std::shared_ptr< const IFrameinput_pointer
 
typedef std::shared_ptr< const IFrameoutput_pointer
 
typedef IFunctionNode< IFrame, IFramesignature_type
 
- Public Types inherited from WireCell::IFunctionNodeBase
typedef std::shared_ptr< IFunctionNodeBasepointer
 
- Public Types inherited from WireCell::INode
enum  NodeCategory {
  unknown, sourceNode, sinkNode, functionNode,
  queuedoutNode, joinNode, splitNode, faninNode,
  fanoutNode, multioutNode, hydraNode
}
 
- Public Types inherited from WireCell::IComponent< INode >
typedef std::shared_ptr< INodepointer
 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 22 of file Digitizer.h.

Constructor & Destructor Documentation

Gen::Digitizer::Digitizer ( const std::string anode_tn = "AnodePlane",
int  resolution = 12,
double  gain = -1.0,
std::vector< double >  fullscale = {0.0, 2.0*units::volt},
std::vector< double >  baselines = {900*units::mV,900*units::mV,200*units::mV} 
)

Definition at line 19 of file Digitizer.cxx.

22  : m_anode_tn(anode)
23  , m_resolution(resolution)
24  , m_gain(gain)
25  , m_fullscale(fullscale)
26  , m_baselines(baselines)
27  , m_frame_tag("")
28  , log(Log::logger("sim"))
29 {
30 }
std::string m_anode_tn
Definition: Digitizer.h:45
std::vector< double > m_fullscale
Definition: Digitizer.h:48
std::string m_frame_tag
Definition: Digitizer.h:49
logptr_t logger(std::string name)
Definition: Logging.cxx:71
std::vector< double > m_baselines
Definition: Digitizer.h:48
Log::logptr_t log
Definition: Digitizer.h:50
Gen::Digitizer::~Digitizer ( )
virtual

Definition at line 32 of file Digitizer.cxx.

33 {
34 }

Member Function Documentation

void Gen::Digitizer::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 59 of file Digitizer.cxx.

60 {
61  m_anode_tn = get<string>(cfg, "anode", m_anode_tn);
62  m_anode = Factory::find_tn<IAnodePlane>(m_anode_tn);
63 
64  m_resolution = get(cfg, "resolution", m_resolution);
65  m_gain = get(cfg, "gain", m_gain);
66  m_fullscale = get(cfg, "fullscale", m_fullscale);
67  m_baselines = get(cfg, "baselines", m_baselines);
68  m_frame_tag = get(cfg, "frame_tag", m_frame_tag);
69 
70  std::stringstream ss;
71  ss << "Gen::Digitizer: "
72  << "tag=\""<<m_frame_tag << "\", "
73  << "resolution="<<m_resolution<<" bits, "
74  << "maxvalue=" << (1<<m_resolution) << " counts, "
75  << "gain=" << m_gain << ", "
76  << "fullscale=[" << m_fullscale[0]/units::mV << "," << m_fullscale[1]/units::mV << "] mV, "
77  << "baselines=[" << m_baselines[0]/units::mV << "," << m_baselines[1]/units::mV << "," << m_baselines[2]/units::mV << "] mV";
78  log->debug(ss.str());
79 
80 }
std::string m_anode_tn
Definition: Digitizer.h:45
static const double mV
Definition: Units.h:180
cfg
Definition: dbjson.py:29
std::vector< double > m_fullscale
Definition: Digitizer.h:48
std::string m_frame_tag
Definition: Digitizer.h:49
IAnodePlane::pointer m_anode
Definition: Digitizer.h:44
std::vector< double > m_baselines
Definition: Digitizer.h:48
Log::logptr_t log
Definition: Digitizer.h:50
WireCell::Configuration Gen::Digitizer::default_configuration ( ) const
virtual

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

Reimplemented from WireCell::IConfigurable.

Definition at line 36 of file Digitizer.cxx.

37 {
39  put(cfg, "anode", m_anode_tn);
40 
41  put(cfg, "resolution", m_resolution);
42  put(cfg, "gain", m_gain);
43  Configuration fs(Json::arrayValue); // fixme: sure would be nice if we had some templated sugar for this
44  for (int ind=0; ind<2; ++ind) {
45  fs[ind] = m_fullscale[ind];
46  }
47  cfg["fullscale"] = fs;
48 
49  Configuration bl(Json::arrayValue);
50  for (int ind=0; ind<3; ++ind) {
51  bl[ind] = m_baselines[ind];
52  }
53  cfg["baselines"] = bl;
54 
55  cfg["frame_tag"] = m_frame_tag;
56  return cfg;
57 }
std::string m_anode_tn
Definition: Digitizer.h:45
void put(Configuration &cfg, const std::string &dotpath, const T &val)
Put value in configuration at the dotted path.
cfg
Definition: dbjson.py:29
std::vector< double > m_fullscale
Definition: Digitizer.h:48
std::string m_frame_tag
Definition: Digitizer.h:49
Json::Value Configuration
Definition: Configuration.h:50
std::vector< double > m_baselines
Definition: Digitizer.h:48
double Gen::Digitizer::digitize ( double  voltage)

Definition at line 83 of file Digitizer.cxx.

84 {
85  const int adcmaxval = (1<<m_resolution)-1;
86 
87  if (voltage <= m_fullscale[0]) {
88  return 0;
89  }
90  if (voltage >= m_fullscale[1]) {
91  return adcmaxval;
92  }
93  const double relvoltage = (voltage - m_fullscale[0])/(m_fullscale[1] - m_fullscale[0]);
94  return relvoltage*adcmaxval;
95 }
std::vector< double > m_fullscale
Definition: Digitizer.h:48
bool Gen::Digitizer::operator() ( const input_pointer in,
output_pointer out 
)
virtual

The calling signature:

Implements WireCell::IFunctionNode< IFrame, IFrame >.

Definition at line 97 of file Digitizer.cxx.

98 {
99  if (!vframe) { // EOS
100  log->debug("Gen::Digitizer: EOS");
101  adcframe = nullptr;
102  return true;
103  }
104 
105 
106  // fixme: maybe make this honor a tag
107  auto vtraces = FrameTools::untagged_traces(vframe);
108  if (vtraces.empty()) {
109  log->error("Gen::Digitizer: no traces in input frame {}", vframe->ident());
110  return false;
111  }
112 
113  // Get extent in channel and tbin
114  auto channels = FrameTools::channels(vtraces);
115  std::sort(channels.begin(), channels.end());
116  auto chbeg = channels.begin();
117  auto chend = std::unique(chbeg, channels.end());
118  auto tbinmm = FrameTools::tbin_range(vtraces);
119 
120  const size_t ncols = tbinmm.second-tbinmm.first;
121  const size_t nrows = std::distance(chbeg, chend);
122 
123  // make a dense array working space. a row is one trace. a
124  // column is one tick.
125  Array::array_xxf arr = Array::array_xxf::Zero(nrows, ncols);
126  FrameTools::fill(arr, vtraces, channels.begin(), chend, tbinmm.first);
127 
128  ITrace::vector adctraces(nrows);
129 
130  for (size_t irow=0; irow < nrows; ++irow) {
131  int ch = channels[irow];
132  WirePlaneId wpid = m_anode->resolve(ch);
133  if (!wpid.valid()) {
134  log->warn("Gen::Digitizer, got invalid WPID for channel {}: {}, skipping", ch, wpid);
135  continue;
136  }
137  const float baseline = m_baselines[wpid.index()];
138 
139  ITrace::ChargeSequence adcwave(ncols);
140  for (size_t icol=0; icol < ncols; ++icol) {
141  double voltage = m_gain*arr(irow, icol) + baseline;
142  const float adcf = digitize(voltage);
143  adcwave[icol] = adcf;
144  }
145  adctraces[irow] = make_shared<SimpleTrace>(ch, tbinmm.first, adcwave);
146  }
147  auto sframe = make_shared<SimpleFrame>(vframe->ident(), vframe->time(), adctraces,
148  vframe->tick(), vframe->masks());
149  if (!m_frame_tag.empty()) {
150  sframe->tag_frame(m_frame_tag);
151  }
152  adcframe = sframe;
153 
154  return true;
155 }
void fill(Array::array_xxf &array, const ITrace::vector &traces, channel_list::iterator ch_begin, channel_list::iterator ch_end, int tbin=0)
Definition: FrameTools.cxx:158
std::vector< pointer > vector
Definition: IData.h:21
double digitize(double voltage)
Definition: Digitizer.cxx:83
ITrace::vector untagged_traces(IFrame::pointer frame)
Definition: FrameTools.cxx:90
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
channel_list channels(const ITrace::vector &traces)
Definition: FrameTools.cxx:132
std::pair< int, int > tbin_range(const ITrace::vector &traces)
Definition: FrameTools.cxx:143
std::string m_frame_tag
Definition: Digitizer.h:49
bool valid() const
return true if valid
Definition: WirePlaneId.cxx:53
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:84
IAnodePlane::pointer m_anode
Definition: Digitizer.h:44
std::vector< double > m_baselines
Definition: Digitizer.h:48
std::vector< float > ChargeSequence
Sequential collection of charge.
Definition: ITrace.h:21
Log::logptr_t log
Definition: Digitizer.h:50
int index() const
Layer as index number (0,1 or 2). -1 if unknown.
Definition: WirePlaneId.cxx:34
Eigen::ArrayXXf array_xxf
A real, 2D array.
Definition: Array.h:54

Member Data Documentation

Log::logptr_t WireCell::Gen::Digitizer::log
private

Definition at line 50 of file Digitizer.h.

IAnodePlane::pointer WireCell::Gen::Digitizer::m_anode
private

Definition at line 44 of file Digitizer.h.

std::string WireCell::Gen::Digitizer::m_anode_tn
private

Definition at line 45 of file Digitizer.h.

std::vector<double> WireCell::Gen::Digitizer::m_baselines
private

Definition at line 48 of file Digitizer.h.

std::string WireCell::Gen::Digitizer::m_frame_tag
private

Definition at line 49 of file Digitizer.h.

std::vector<double> WireCell::Gen::Digitizer::m_fullscale
private

Definition at line 48 of file Digitizer.h.

double WireCell::Gen::Digitizer::m_gain
private

Definition at line 47 of file Digitizer.h.

int WireCell::Gen::Digitizer::m_resolution
private

Definition at line 46 of file Digitizer.h.


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