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

#include <NoiseSource.h>

Inheritance diagram for WireCell::Gen::NoiseSource:
WireCell::IFrameSource WireCell::IConfigurable WireCell::ISourceNode< IFrame > WireCell::IComponent< IConfigurable > WireCell::ISourceNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 NoiseSource (const std::string &model="", const std::string &anode="AnodePlane", const std::string &rng="Random")
 
virtual ~NoiseSource ()
 
virtual bool operator() (IFrame::pointer &frame)
 IFrameSource. More...
 
virtual void configure (const WireCell::Configuration &config)
 IConfigurable. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
- Public Member Functions inherited from WireCell::IFrameSource
virtual ~IFrameSource ()
 
- Public Member Functions inherited from WireCell::ISourceNode< IFrame >
virtual ~ISourceNode ()
 
virtual NodeCategory category ()
 Return the behavior category type. More...
 
virtual std::string signature ()
 Set the signature for all subclasses. More...
 
virtual bool operator() (boost::any &anyout)
 
virtual std::vector< std::stringoutput_types ()
 
- Public Member Functions inherited from WireCell::ISourceNodeBase
virtual ~ISourceNodeBase ()
 
- Public Member Functions inherited from WireCell::INode
virtual ~INode ()
 
virtual int concurrency ()
 
virtual std::vector< std::stringinput_types ()
 
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

IRandom::pointer m_rng
 
IAnodePlane::pointer m_anode
 
IChannelSpectrum::pointer m_model
 
double m_time
 
double m_stop
 
double m_readout
 
double m_tick
 
int m_frame_count
 
std::string m_anode_tn
 
std::string m_model_tn
 
std::string m_rng_tn
 
int m_nsamples
 
double m_rep_percent
 
bool m_eos
 

Additional Inherited Members

- Public Types inherited from WireCell::IFrameSource
typedef std::shared_ptr< IFrameSourcepointer
 
- Public Types inherited from WireCell::ISourceNode< IFrame >
typedef IFrame output_type
 
typedef ISourceNode< IFramesignature_type
 
typedef std::shared_ptr< signature_typepointer
 
typedef std::shared_ptr< const IFrameoutput_pointer
 
- Public Types inherited from WireCell::ISourceNodeBase
typedef std::shared_ptr< ISourceNodeBasepointer
 
- 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 23 of file NoiseSource.h.

Constructor & Destructor Documentation

Gen::NoiseSource::NoiseSource ( const std::string model = "",
const std::string anode = "AnodePlane",
const std::string rng = "Random" 
)

Definition at line 19 of file NoiseSource.cxx.

20  : m_time(0.0*units::ns)
21  , m_stop(1.0*units::ms)
22  , m_readout(5.0*units::ms)
23  , m_tick(0.5*units::us)
24  , m_frame_count(0)
25  , m_anode_tn(anode)
26  , m_model_tn(model)
27  , m_rng_tn(rng)
28  , m_nsamples(9600)
29  , m_rep_percent(0.02) // replace 2% at a time
30  , m_eos(false)
31 {
32  // initialize the random number ...
33  //auto& spec = (*m_model)(0);
34 
35  // end initialization ..
36 
37 }
static const double ms
Definition: Units.h:104
static const double ns
Definition: Units.h:102
static const double us
Definition: Units.h:105
Gen::NoiseSource::~NoiseSource ( )
virtual

Definition at line 40 of file NoiseSource.cxx.

41 {
42 }

Member Function Documentation

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

IConfigurable.

Implements WireCell::IConfigurable.

Definition at line 61 of file NoiseSource.cxx.

62 {
63  m_rng_tn = get(cfg, "rng", m_rng_tn);
64  m_rng = Factory::find_tn<IRandom>(m_rng_tn);
65  if (!m_rng) {
66  THROW(KeyError() << errmsg{"failed to get IRandom: " + m_rng_tn});
67  }
68 
69  m_anode_tn = get(cfg, "anode", m_anode_tn);
70  m_anode = Factory::find_tn<IAnodePlane>(m_anode_tn);
71  if (!m_anode) {
72  THROW(KeyError() << errmsg{"failed to get IAnodePlane: " + m_anode_tn});
73  }
74 
75  m_model_tn = get(cfg, "model", m_model_tn);
76  m_model = Factory::find_tn<IChannelSpectrum>(m_model_tn);
77  if (!m_model) {
78  THROW(KeyError() << errmsg{"failed to get IChannelSpectrum: " + m_model_tn});
79  }
80 
81  m_readout = get<double>(cfg, "readout_time", m_readout);
82  m_time = get<double>(cfg, "start_time", m_time);
83  m_stop = get<double>(cfg, "stop_time", m_stop);
84  m_tick = get<double>(cfg, "sample_period", m_tick);
85  m_frame_count = get<int>(cfg, "first_frame_number", m_frame_count);
86  m_nsamples = get<int>(cfg,"m_nsamples",m_nsamples);
87  m_rep_percent = get<double>(cfg,"replacement_percentage",m_rep_percent);
88 
89  cerr << "Gen::NoiseSource: using IRandom: \"" << m_rng_tn << "\""
90  << " IAnodePlane: \"" << m_anode_tn << "\""
91  << " IChannelSpectrum: \"" << m_model_tn << "\""
92  << " readout time: " << m_readout/units::us << "us\n";
93 
94 
95 
96 }
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
cfg
Definition: dbjson.py:29
IAnodePlane::pointer m_anode
Definition: NoiseSource.h:40
IChannelSpectrum::pointer m_model
Definition: NoiseSource.h:41
#define THROW(e)
Definition: Exceptions.h:25
IRandom::pointer m_rng
Definition: NoiseSource.h:39
static const double us
Definition: Units.h:105
Thrown when a wrong key or has been encountered.
Definition: Exceptions.h:43
WireCell::Configuration Gen::NoiseSource::default_configuration ( ) const
virtual

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

Reimplemented from WireCell::IConfigurable.

Definition at line 44 of file NoiseSource.cxx.

45 {
47  cfg["start_time"] = m_time;
48  cfg["stop_time"] = m_stop;
49  cfg["readout_time"] = m_readout;
50  cfg["sample_period"] = m_tick;
51  cfg["first_frame_number"] = m_frame_count;
52 
53  cfg["anode"] = m_anode_tn;
54  cfg["model"] = m_model_tn;
55  cfg["rng"] = m_rng_tn;
56  cfg["nsamples"] = m_nsamples;
57  cfg["replacement_percentage"] = m_rep_percent;
58  return cfg;
59 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool Gen::NoiseSource::operator() ( IFrame::pointer frame)
virtual

IFrameSource.

Implements WireCell::ISourceNode< IFrame >.

Definition at line 100 of file NoiseSource.cxx.

101 {
102  if (m_eos) { // This source does not restart.
103  return false;
104  }
105 
106  if (m_time >= m_stop) {
107  frame = nullptr;
108  m_eos = true;
109  return true;
110  }
111  ITrace::vector traces;
112  const int tbin = 0;
113  int nsamples = 0;
114  for (auto chid : m_anode->channels()) {
115  const auto& spec = (*m_model)(chid);
116 
118  // std::cout << noise.size() << " " << nsamples << std::endl;
119  noise.resize(m_nsamples,0);
120  auto trace = make_shared<SimpleTrace>(chid, tbin, noise);
121  traces.push_back(trace);
122  nsamples += noise.size();
123  }
124  cerr << "Gen::NoiseSource: made " << traces.size() << " traces, "
125  << nsamples << " samples\n";
126  frame = make_shared<SimpleFrame>(m_frame_count, m_time, traces, m_tick);
127  m_time += m_readout;
128  ++m_frame_count;
129  return true;
130 }
Sequence< real_t > realseq_t
Definition: Waveform.h:31
std::vector< pointer > vector
Definition: IData.h:21
IAnodePlane::pointer m_anode
Definition: NoiseSource.h:40
WireCell::Waveform::realseq_t generate_waveform(const std::vector< float > &spec, IRandom::pointer rng, double replace=0.02)
Definition: Noise.cxx:7
IRandom::pointer m_rng
Definition: NoiseSource.h:39

Member Data Documentation

IAnodePlane::pointer WireCell::Gen::NoiseSource::m_anode
private

Definition at line 40 of file NoiseSource.h.

std::string WireCell::Gen::NoiseSource::m_anode_tn
private

Definition at line 44 of file NoiseSource.h.

bool WireCell::Gen::NoiseSource::m_eos
private

Definition at line 47 of file NoiseSource.h.

int WireCell::Gen::NoiseSource::m_frame_count
private

Definition at line 43 of file NoiseSource.h.

IChannelSpectrum::pointer WireCell::Gen::NoiseSource::m_model
private

Definition at line 41 of file NoiseSource.h.

std::string WireCell::Gen::NoiseSource::m_model_tn
private

Definition at line 44 of file NoiseSource.h.

int WireCell::Gen::NoiseSource::m_nsamples
private

Definition at line 45 of file NoiseSource.h.

double WireCell::Gen::NoiseSource::m_readout
private

Definition at line 42 of file NoiseSource.h.

double WireCell::Gen::NoiseSource::m_rep_percent
private

Definition at line 46 of file NoiseSource.h.

IRandom::pointer WireCell::Gen::NoiseSource::m_rng
private

Definition at line 39 of file NoiseSource.h.

std::string WireCell::Gen::NoiseSource::m_rng_tn
private

Definition at line 44 of file NoiseSource.h.

double WireCell::Gen::NoiseSource::m_stop
private

Definition at line 42 of file NoiseSource.h.

double WireCell::Gen::NoiseSource::m_tick
private

Definition at line 42 of file NoiseSource.h.

double WireCell::Gen::NoiseSource::m_time
private

Definition at line 42 of file NoiseSource.h.


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