25 Gen::BlipSource::~BlipSource()
27 delete m_ene; m_ene =
nullptr;
28 delete m_tim; m_tim =
nullptr;
29 delete m_pos; m_pos =
nullptr;
37 cfg[
"rng"] =
"Random";
41 ene[
"value"] = 20000.0;
50 tim[
"type"] =
"decay";
61 extent[
"tail"] = tail; extent[
"head"] = head;
62 pos[
"extent"] = extent;
64 cfg[
"position"] =
pos;
78 struct DecayTime :
public Gen::BlipSource::ScalarMaker {
86 struct Pdf :
public Gen::BlipSource::ScalarMaker {
92 : rng(rng), edges(edges.
begin(), edges.
end()) {
94 cumulative.push_back(0.0);
95 for (
double val : pdf) {
97 cumulative.push_back(total);
101 double cp = rng->uniform(0.0, total);
102 for (
size_t ind=1; ind<cumulative.size(); ++ind) {
103 if (cumulative[ind] >= cp) {
104 double rel = (cp - cumulative[ind-1]) / (cumulative[ind]-cumulative[ind-1]);
105 return edges[ind-1] + rel*(edges[ind] - edges[ind-1]);
120 rng->uniform(extent.first.x(), extent.second.x()),
121 rng->uniform(extent.first.y(), extent.second.y()),
122 rng->uniform(extent.first.z(), extent.second.z()));
130 m_rng_tn =
get(
cfg,
"rng", m_rng_tn);
131 m_rng = Factory::find_tn<IRandom>(m_rng_tn);
133 auto ene = cfg[
"charge"];
134 if (ene[
"type"].asString() ==
"mono") {
137 else if (ene[
"type"].asString() ==
"pdf") {
138 m_ene =
new Pdf(m_rng,
get< std::vector<double> >(ene,
"pdf"),
get< std::vector<double> >(ene,
"edges"));
141 std::cerr <<
"BlipSource: no charge configuration\n";
145 auto tim = cfg[
"time"];
146 m_time = tim[
"start"].asDouble();
147 m_stop = tim[
"stop"].asDouble();
148 if (tim[
"type"].asString() ==
"decay") {
149 m_tim =
new DecayTime(m_rng, tim[
"activity"].asDouble());
152 std::cerr <<
"BlipSource: no time configuration\n";
156 auto pos = cfg[
"position"];
157 if (pos[
"type"].asString() ==
"box") {
158 Ray box = WireCell::convert<Ray>(pos[
"extent"]);
159 std::cerr <<
"Box: \n\t" << box.first/
units::mm <<
"mm\n\t" << box.second/
units::mm <<
"mm\n";
163 std::cerr <<
"BlipSource: no position configuration\n";
174 m_time += (*m_tim)();
175 if (m_time > m_stop) {
176 std::cerr <<
"BlipSource: reached stop time: " 183 depo = std::make_shared<SimpleDepo>(m_time, (*m_pos)(), (*m_ene)(),
184 nullptr, 0, 0, m_blip_count);
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
std::shared_ptr< const IDepo > pointer
boost::error_info< struct tag_errmsg, std::string > errmsg
std::vector< double > cumulative
std::vector< double > edges
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Pdf(IRandom::pointer rng, const std::vector< double > &pdf, const std::vector< double > &edges)
Thrown when a wrong value has been encountered.
DecayTime(IRandom::pointer rng, double rate)
WIRECELL_FACTORY(BlipSource, WireCell::Gen::BlipSource, WireCell::IDepoSource, WireCell::IConfigurable) using namespace WireCell
Json::Value Configuration
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
const GenericPointer< typename T::ValueType > & pointer
QTextStream & endl(QTextStream &s)