11 #include "art/Framework/Principal/Handle.h"
12 #include "art/Framework/Principal/Event.h"
16 #include "WireCellUtil/Units.h"
17 #include "WireCellUtil/String.h"
18 #include "WireCellUtil/NamedFactory.h"
19 #include "WireCellAux/SimpleDepo.h"
20 #include "WireCellIface/IRecombinationModel.h"
23 WireCell::IDepoSource, WireCell::IConfigurable)
25 using WireCell::Aux::SimpleDepo;
42 class ElectronsAdapter :
public DepoAdapter {
54 class PointAdapter :
public DepoAdapter {
55 WireCell::IRecombinationModel::pointer m_model;
58 PointAdapter(WireCell::IRecombinationModel::pointer model,
double scale=1.0)
59 : m_model(model), m_scale(scale) {}
63 return m_scale * (*m_model)(dE);
68 class StepAdapter :
public DepoAdapter {
69 WireCell::IRecombinationModel::pointer m_model;
72 StepAdapter(WireCell::IRecombinationModel::pointer model,
double scale=1.0)
73 : m_model(model), m_scale(scale) {}
78 return m_scale * (*m_model)(dE, dX);
102 WireCell::Configuration cfg;
114 cfg[
"assn_art_tag"] =
"";
126 std::string model_tn = WireCell::get<std::string>(cfg,
"model",
"");
127 std::string model_type =
"";
128 if (!model_tn.empty()) {
129 WireCell::String::split(model_tn)[0];
132 if (model_type ==
"" or model_type ==
"electrons") {
136 auto model = WireCell::Factory::lookup_tn<WireCell::IRecombinationModel>(model_tn);
138 std::cerr <<
"wcls::SimDepoSource: unknown recombination model: \"" << model_tn <<
"\"\n";
141 if (model_type ==
"MipRecombination") {
144 if (model_type ==
"BirksRecombination" || model_type ==
"BoxRecombination") {
150 m_assnTag = cfg[
"assn_art_tag"].asString();
156 art::Handle< std::vector<sim::SimEnergyDeposit> > sedvh;
158 bool okay =
event.getByLabel(
m_inputTag, sedvh);
160 std::string
msg =
"SimDepoSource failed to get sim::SimEnergyDeposit from art tag: " +
m_inputTag.encode();
162 THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
166 const size_t ndepos = sedvh->size();
168 std::cerr <<
"SimDepoSource got " << ndepos
170 <<
"\" returns: " << (okay ?
"okay" :
"fail") << std::endl;
174 <<
" unused, prior depos\n";
179 std::vector<sim::SimEnergyDeposit> assn_sedv;
181 art::Handle< std::vector<sim::SimEnergyDeposit> > assn_sedvh;
182 okay =
event.getByLabel(
m_assnTag, assn_sedvh);
184 std::string
msg =
"SimDepoSource failed to get sim::SimEnergyDeposit from art tag: " +
m_assnTag.encode();
186 THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
189 std::cout <<
"Larwirecell::SimDepoSource got " << assn_sedvh->size()
190 <<
" associated depos from " <<
m_assnTag << std::endl;
191 assn_sedv.insert(assn_sedv.end(), assn_sedvh->begin(), assn_sedvh->end() );
194 if (ndepos != assn_sedv.size()) {
195 std::string
msg =
"Larwirecell::SimDepoSource Inconsistent size of SimDepoSources";
197 THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
201 for (
size_t ind=0; ind<ndepos; ++ind) {
202 auto const& sed = sedvh->at(ind);
203 auto pt = sed.MidPoint();
204 const WireCell::Point wpt(pt.x()*units::cm, pt.y()*units::cm, pt.z()*units::cm);
205 double wt = sed.Time()*units::ns;
206 double wq = (*m_adapter)(sed);
207 int wid = sed.TrackID();
208 int pdg = sed.PdgCode();
211 if (assn_sedv.size() == 0) {
212 WireCell::IDepo::pointer depo
213 = std::make_shared<SimpleDepo>(wt, wpt, wq,
nullptr, 0.0, 0.0, wid,
pdg, we);
221 auto const& sed1 = assn_sedv.at(ind);
222 auto pt1 = sed1.MidPoint();
223 const WireCell::Point wpt1(pt1.x()*units::cm, pt1.y()*units::cm, pt1.z()*units::cm);
224 double wt1 = sed1.Time()*units::ns;
225 double wq1 = (*m_adapter)(sed1);
226 int wid1 = sed1.TrackID();
227 int pdg1 = sed1.PdgCode();
230 WireCell::IDepo::pointer assn_depo
231 = std::make_shared<SimpleDepo>(wt1, wpt1, wq1,
nullptr, 0.0, 0.0, wid1, pdg1, we1);
233 WireCell::IDepo::pointer depo
234 = std::make_shared<SimpleDepo>(wt, wpt, wq, assn_depo, 0.0, 0.0, wid,
pdg, we);
246 WireCell::IDepo::pointer depo
247 = std::make_shared<SimpleDepo>(0, wpt, 0,
nullptr, 0.0, 0.0);
252 std::sort(
m_depos.begin(),
m_depos.end(), WireCell::ascending_time);
253 std::cerr <<
"SimDepoSource: ready with " <<
m_depos.size() <<
" depos spanning: ["
254 <<
m_depos.front()->time()/units::us <<
", "
255 <<
m_depos.back()->time()/units::us <<
"]us\n";
geo::Length_t StepLength() const
virtual WireCell::Configuration default_configuration() const
IConfigurable.
ElectronsAdapter(double scale=1.0)
BEGIN_PROLOG could also be cerr
virtual double operator()(const sim::SimEnergyDeposit &sed) const
std::deque< WireCell::IDepo::pointer > m_depos
PointAdapter(WireCell::IRecombinationModel::pointer model, double scale=1.0)
util::quantities::megaelectronvolt MeV
virtual void configure(const WireCell::Configuration &config)
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
virtual bool operator()(WireCell::IDepo::pointer &out)
IDepoSource.
virtual double operator()(const sim::SimEnergyDeposit &sed) const
WIRECELL_FACTORY(wclsChannelNoiseDB, wcls::ChannelNoiseDB, wcls::IArtEventVisitor, WireCell::IChannelNoiseDatabase) using namespace WireCell
virtual void visit(art::Event &event)
IArtEventVisitor.
bits::DepoAdapter * m_adapter
StepAdapter(WireCell::IRecombinationModel::pointer model, double scale=1.0)
contains information for a single step in the detector simulation
Energy deposition in the active material.
virtual double operator()(const sim::SimEnergyDeposit &sed) const
virtual ~ElectronsAdapter()
BEGIN_PROLOG could also be cout