7 #include "art/Framework/Principal/Handle.h"
8 #include "art/Framework/Principal/Event.h"
12 #include "WireCellUtil/Units.h"
13 #include "WireCellUtil/String.h"
14 #include "WireCellUtil/NamedFactory.h"
15 #include "WireCellAux/SimpleDepo.h"
16 #include "WireCellAux/SimpleDepoSet.h"
17 #include "WireCellIface/IRecombinationModel.h"
20 WireCell::IDepoSetSource, WireCell::IConfigurable)
22 using WireCell::Aux::SimpleDepo;
23 using WireCell::Aux::SimpleDepoSet;
54 WireCell::IRecombinationModel::pointer
m_model;
57 PointAdapter(WireCell::IRecombinationModel::pointer model,
double scale=1.0)
58 : m_model(model), m_scale(scale) {}
62 return m_scale * (*m_model)(dE);
68 WireCell::IRecombinationModel::pointer
m_model;
71 StepAdapter(WireCell::IRecombinationModel::pointer model,
double scale=1.0)
72 : m_model(model), m_scale(scale) {}
77 return m_scale * (*m_model)(dE, dX);
87 : m_count(0), m_adapter(nullptr)
101 WireCell::Configuration cfg;
113 cfg[
"assn_art_tag"] =
"";
125 std::string model_tn = WireCell::get<std::string>(cfg,
"model",
"");
126 std::string model_type =
"";
127 if (!model_tn.empty()) {
128 WireCell::String::split(model_tn)[0];
131 if (model_type ==
"" or model_type ==
"electrons") {
135 auto model = WireCell::Factory::lookup_tn<WireCell::IRecombinationModel>(model_tn);
137 std::cerr <<
"wcls::SimDepoSetSource: unknown recombination model: \"" << model_tn <<
"\"\n";
140 if (model_type ==
"MipRecombination") {
143 if (model_type ==
"BirksRecombination" || model_type ==
"BoxRecombination") {
149 m_assnTag = cfg[
"assn_art_tag"].asString();
155 art::Handle< std::vector<sim::SimEnergyDeposit> > sedvh;
157 bool okay =
event.getByLabel(
m_inputTag, sedvh);
159 std::string
msg =
"SimDepoSetSource failed to get sim::SimEnergyDeposit from art tag: " +
m_inputTag.encode();
161 THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
165 const size_t ndepos = sedvh->size();
167 std::cerr <<
"SimDepoSetSource got " << ndepos
169 <<
"\" returns: " << (okay ?
"okay" :
"fail") << std::endl;
173 <<
" unused, prior depos\n";
178 std::vector<sim::SimEnergyDeposit> assn_sedv;
180 art::Handle< std::vector<sim::SimEnergyDeposit> > assn_sedvh;
181 okay =
event.getByLabel(
m_assnTag, assn_sedvh);
183 std::string
msg =
"SimDepoSetSource failed to get sim::SimEnergyDeposit from art tag: " +
m_assnTag.encode();
185 THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
188 std::cout <<
"Larwirecell::SimDepoSetSource got " << assn_sedvh->size()
189 <<
" associated depos from " <<
m_assnTag << std::endl;
190 assn_sedv.insert(assn_sedv.end(), assn_sedvh->begin(), assn_sedvh->end() );
193 if (ndepos != assn_sedv.size()) {
194 std::string
msg =
"Larwirecell::SimDepoSetSource Inconsistent size of SimDepoSetSources";
196 THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
200 for (
size_t ind=0; ind<ndepos; ++ind) {
201 auto const& sed = sedvh->at(ind);
202 auto pt = sed.MidPoint();
203 const WireCell::Point wpt(pt.x()*units::cm, pt.y()*units::cm, pt.z()*units::cm);
204 double wt = sed.Time()*units::ns;
205 double wq = (*m_adapter)(sed);
206 int wid = sed.TrackID();
207 int pdg = sed.PdgCode();
210 if (assn_sedv.size() == 0) {
211 WireCell::IDepo::pointer depo
212 = std::make_shared<SimpleDepo>(wt, wpt, wq,
nullptr, 0.0, 0.0, wid,
pdg, we);
220 auto const& sed1 = assn_sedv.at(ind);
221 auto pt1 = sed1.MidPoint();
222 const WireCell::Point wpt1(pt1.x()*units::cm, pt1.y()*units::cm, pt1.z()*units::cm);
223 double wt1 = sed1.Time()*units::ns;
224 double wq1 = (*m_adapter)(sed1);
225 int wid1 = sed1.TrackID();
226 int pdg1 = sed1.PdgCode();
229 WireCell::IDepo::pointer assn_depo
230 = std::make_shared<SimpleDepo>(wt1, wpt1, wq1,
nullptr, 0.0, 0.0, wid1, pdg1, we1);
232 WireCell::IDepo::pointer depo
233 = std::make_shared<SimpleDepo>(wt, wpt, wq, assn_depo, 0.0, 0.0, wid,
pdg, we);
245 WireCell::IDepo::pointer depo
246 = std::make_shared<SimpleDepo>(0, wpt, 0,
nullptr, 0.0, 0.0);
251 std::sort(
m_depos.begin(),
m_depos.end(), WireCell::ascending_time);
252 std::cerr <<
"SimDepoSetSource: ready with " <<
m_depos.size() <<
" depos spanning: ["
253 <<
m_depos.front()->time()/units::us <<
", "
254 <<
m_depos.back()->time()/units::us <<
"]us\n";
virtual ~SimDepoSetSource()
geo::Length_t StepLength() const
WireCell::IDepo::vector m_depos
ElectronsAdapter(double scale=1.0)
BEGIN_PROLOG could also be cerr
virtual double operator()(const sim::SimEnergyDeposit &sed) const
PointAdapter(WireCell::IRecombinationModel::pointer model, double scale=1.0)
util::quantities::megaelectronvolt MeV
WireCell::IRecombinationModel::pointer m_model
virtual void configure(const WireCell::Configuration &config)
virtual bool operator()(WireCell::IDepoSet::pointer &out)
IDepoSetSource.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
virtual double operator()(const sim::SimEnergyDeposit &sed) const
WIRECELL_FACTORY(wclsChannelNoiseDB, wcls::ChannelNoiseDB, wcls::IArtEventVisitor, WireCell::IChannelNoiseDatabase) using namespace WireCell
StepAdapter(WireCell::IRecombinationModel::pointer model, double scale=1.0)
virtual WireCell::Configuration default_configuration() const
IConfigurable.
contains information for a single step in the detector simulation
Energy deposition in the active material.
virtual void visit(art::Event &event)
IArtEventVisitor.
virtual double operator()(const sim::SimEnergyDeposit &sed) const
virtual ~ElectronsAdapter()
WireCell::IRecombinationModel::pointer m_model
BEGIN_PROLOG could also be cout