Public Member Functions | Private Attributes | List of all members
WireCell::Sio::JsonDepoSource Class Reference

#include <JsonDepoSource.h>

Inheritance diagram for WireCell::Sio::JsonDepoSource:
WireCell::IDepoSource WireCell::IConfigurable WireCell::ISourceNode< IDepo > WireCell::IComponent< IConfigurable > WireCell::ISourceNodeBase WireCell::Interface WireCell::INode WireCell::IComponent< INode > WireCell::Interface

Public Member Functions

 JsonDepoSource ()
 
virtual ~JsonDepoSource ()
 
virtual bool operator() (IDepo::pointer &out)
 IDepoSource. More...
 
virtual WireCell::Configuration default_configuration () const
 IConfigurable. More...
 
virtual void configure (const WireCell::Configuration &config)
 Accept a configuration. More...
 
IDepo::pointer jdepo2idepo (Json::Value jdepo)
 
- Public Member Functions inherited from WireCell::IDepoSource
virtual ~IDepoSource ()
 
virtual std::string signature ()
 Set the signature for all subclasses. More...
 
- Public Member Functions inherited from WireCell::ISourceNode< IDepo >
virtual ~ISourceNode ()
 
virtual NodeCategory category ()
 Return the behavior category type. 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

JsonRecombinationAdaptorm_adapter
 
WireCell::IDepo::vector m_depos
 
bool m_eos
 

Additional Inherited Members

- Public Types inherited from WireCell::IDepoSource
typedef std::shared_ptr< IDepoSourcepointer
 
- Public Types inherited from WireCell::ISourceNode< IDepo >
typedef IDepo output_type
 
typedef ISourceNode< IDeposignature_type
 
typedef std::shared_ptr< signature_typepointer
 
typedef std::shared_ptr< const IDepooutput_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 28 of file JsonDepoSource.h.

Constructor & Destructor Documentation

Sio::JsonDepoSource::JsonDepoSource ( )

Definition at line 67 of file JsonDepoSource.cxx.

68  : m_adapter(nullptr), m_eos(false)
69 {
70 }
JsonRecombinationAdaptor * m_adapter
Sio::JsonDepoSource::~JsonDepoSource ( )
virtual

Definition at line 72 of file JsonDepoSource.cxx.

73 {
74 }

Member Function Documentation

void Sio::JsonDepoSource::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 119 of file JsonDepoSource.cxx.

120 {
121  m_depos.clear();
122  if (m_adapter) {
123  delete m_adapter;
124  m_adapter = nullptr;
125  }
126  std::string model_tn = cfg["model"].asString();
127  std::string model_type = String::split(model_tn)[0];
128 
129  if (model_type == "electrons") { // "n" already gives number of ionization electrons
130  double scale = get(cfg,"scale",1.0);
131  cerr << "Sio::JsonDepoSource: using electrons with scale=" << scale << endl;
132  m_adapter = new ElectronsAdapter(scale);
133  }
134  else {
135  auto model = Factory::lookup_tn<IRecombinationModel>(model_tn);
136  if (!model) {
137  cerr << "Sio::JsonDepoSource::configure: unknown recombination model: \"" << model_tn << "\"\n";
138  return;
139  }
140  if (model_type == "MipRecombination") {
142  }
143  if (model_type == "BirksRecombination" || model_type == "BoxRecombination") {
144  m_adapter = new StepAdapter(model);
145  }
146  }
147 
148  // get and load JSON file.
149  string filename = get<string>(cfg,"filename");
150  string dotpath = get<string>(cfg,"jsonpath","depos");
151  if (filename.empty()) {
152  cerr << "JsonDepoSource::configure: no JSON filename given" << endl;
153  return; // fixme: uh, error handle much?
154  }
155  Json::Value top = WireCell::Persist::load(filename.c_str());
156 
157  double qtot = 0;
158  auto jdepos = branch(top, dotpath);
159  for (auto jdepo : jdepos) {
160  auto idepo = jdepo2idepo(jdepo);
161  m_depos.push_back(idepo);
162  qtot += idepo->charge();
163  }
164  std::sort(m_depos.begin(), m_depos.end(), descending_time);
165  cerr << "Sio::JsonDepoSource::configure: "
166  << "slurped in " << m_depos.size() << " depositions, "
167  << " = " << -1*qtot/units::eplus << " electrons\n";
168 }
JsonRecombinationAdaptor * m_adapter
static const double eplus
Definition: Units.h:110
std::string string
Definition: nybbler.cc:12
IDepo::pointer jdepo2idepo(Json::Value jdepo)
cfg
Definition: dbjson.py:29
string filename
Definition: train.py:213
Configuration branch(Configuration cfg, const std::string &dotpath)
Follow a dot.separated.path and return the branch there.
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2106
Json::Value load(const std::string &filename, const externalvars_t &extvar=externalvars_t(), const externalvars_t &extcode=externalvars_t())
Definition: Persist.cxx:121
WireCell::IDepo::vector m_depos
bool descending_time(const WireCell::IDepo::pointer &lhs, const WireCell::IDepo::pointer &rhs)
Compare two IDepo::pointers for by time, descending. x is used to break tie.
Definition: IDepo.cxx:29
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition: Waveform.h:146
std::vector< std::string > split(const std::string &in, const std::string &delim=":")
Definition: String.cxx:5
QTextStream & endl(QTextStream &s)
WireCell::Configuration Sio::JsonDepoSource::default_configuration ( ) const
virtual

IConfigurable.

Reimplemented from WireCell::IConfigurable.

Definition at line 94 of file JsonDepoSource.cxx.

95 {
97  cfg["filename"] = ""; // json file name
98  cfg["jsonpath"] = "depos"; // path to depo list in json data
99  cfg["model"] = "electrons"; // model for converting "q" and maybe
100  // "s" or "n" to amount of drifting
101  // charge.
102  return cfg;
103 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
IDepo::pointer Sio::JsonDepoSource::jdepo2idepo ( Json::Value  jdepo)

Definition at line 105 of file JsonDepoSource.cxx.

106 {
107  const double q = (*m_adapter)(jdepo);
108  auto idepo = std::make_shared<SimpleDepo>(
109  get(jdepo,"t",0.0),
110  Point(get(jdepo, "x", 0.0),
111  get(jdepo, "y", 0.0),
112  get(jdepo, "z", 0.0)),
113  q);
114  return idepo;
115 }
D3Vector< double > Point
A 3D Cartesian point in double precision.
Definition: Point.h:15
bool Sio::JsonDepoSource::operator() ( IDepo::pointer out)
virtual

IDepoSource.

Implements WireCell::ISourceNode< IDepo >.

Definition at line 77 of file JsonDepoSource.cxx.

78 {
79  if (m_eos) {
80  return false;
81  }
82 
83  if (m_depos.empty()) {
84  m_eos = true;
85  out = nullptr;
86  return true;
87  }
88 
89  out = m_depos.back();
90  m_depos.pop_back();
91  return true;
92 }
WireCell::IDepo::vector m_depos

Member Data Documentation

JsonRecombinationAdaptor* WireCell::Sio::JsonDepoSource::m_adapter
private

Definition at line 45 of file JsonDepoSource.h.

WireCell::IDepo::vector WireCell::Sio::JsonDepoSource::m_depos
private

Definition at line 46 of file JsonDepoSource.h.

bool WireCell::Sio::JsonDepoSource::m_eos
private

Definition at line 47 of file JsonDepoSource.h.


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