Public Member Functions | Private Attributes | List of all members
wcls::SimDepoSource Class Reference

#include <SimDepoSource.h>

Inheritance diagram for wcls::SimDepoSource:
wcls::IArtEventVisitor

Public Member Functions

 SimDepoSource ()
 
virtual ~SimDepoSource ()
 
virtual void visit (art::Event &event)
 IArtEventVisitor. More...
 
virtual bool operator() (WireCell::IDepo::pointer &out)
 IDepoSource. More...
 
virtual WireCell::Configuration default_configuration () const
 IConfigurable. More...
 
virtual void configure (const WireCell::Configuration &config)
 
- Public Member Functions inherited from wcls::IArtEventVisitor
virtual ~IArtEventVisitor ()
 
virtual void produces (art::ProducesCollector &collector)
 

Private Attributes

std::deque< WireCell::IDepo::pointer > m_depos
 
bits::DepoAdapterm_adapter
 
art::InputTag m_inputTag
 
art::InputTag m_assnTag
 

Detailed Description

Definition at line 42 of file SimDepoSource.h.

Constructor & Destructor Documentation

SimDepoSource::SimDepoSource ( )

Definition at line 86 of file SimDepoSource.cxx.

87  : m_adapter(nullptr)
88 {
89 }
bits::DepoAdapter * m_adapter
Definition: SimDepoSource.h:61
SimDepoSource::~SimDepoSource ( )
virtual

Definition at line 91 of file SimDepoSource.cxx.

92 {
93  if (m_adapter) {
94  delete m_adapter;
95  m_adapter = nullptr;
96  }
97 }
bits::DepoAdapter * m_adapter
Definition: SimDepoSource.h:61

Member Function Documentation

void SimDepoSource::configure ( const WireCell::Configuration &  config)
virtual

Definition at line 117 of file SimDepoSource.cxx.

118 {
119  if (m_adapter) {
120  delete m_adapter;
121  m_adapter = nullptr;
122  }
123  double scale = WireCell::get(cfg, "scale", 1.0);
124 
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];
129  }
130 
131  if (model_type == "" or model_type == "electrons") {
133  }
134  else {
135  auto model = WireCell::Factory::lookup_tn<WireCell::IRecombinationModel>(model_tn);
136  if (!model) {
137  std::cerr << "wcls::SimDepoSource: unknown recombination model: \"" << model_tn << "\"\n";
138  return; // I should throw something here!
139  }
140  if (model_type == "MipRecombination") {
142  }
143  if (model_type == "BirksRecombination" || model_type == "BoxRecombination") {
145  }
146  }
147 
148  m_inputTag = cfg["art_tag"].asString();
149  m_assnTag = cfg["assn_art_tag"].asString();
150 }
std::string string
Definition: nybbler.cc:12
Definition: model.py:1
art::InputTag m_assnTag
Definition: SimDepoSource.h:64
art::InputTag m_inputTag
Definition: SimDepoSource.h:63
bits::DepoAdapter * m_adapter
Definition: SimDepoSource.h:61
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
WireCell::Configuration SimDepoSource::default_configuration ( ) const
virtual

IConfigurable.

Definition at line 99 of file SimDepoSource.cxx.

100 {
102 
103  // An empty model or the special model "electrons" means to take
104  // precalcualted input NumElectrons. Anything else means some
105  // recombination model is used.
106  cfg["model"] = "";
107  // Multiply this number to the number of electrons before forming
108  // a WC depo.
109  cfg["scale"] = 1.0;
110 
111  // For locating input in the art::Event
112  cfg["art_tag"] = ""; // eg, "plopper:bogus"
113  cfg["assn_art_tag"] = ""; // eg, "largeant"
114 
115  return cfg;
116 }
bool SimDepoSource::operator() ( WireCell::IDepo::pointer &  out)
virtual

IDepoSource.

Definition at line 258 of file SimDepoSource.cxx.

259 {
260  if (m_depos.empty()) {
261  return false;
262  }
263 
264  out = m_depos.front();
265  m_depos.pop_front();
266 
267  // if (!out) {
268  // std::cerr << "SimDepoSource: reached EOS\n";
269  // }
270  // else {
271  // std::cerr << "SimDepoSource: t=" << out->time()/units::us << "us,"
272  // << " r=" << out->pos()/units::cm << "cm, " << " q=" << out->charge() << "\n";
273  // }
274  return true;
275 }
std::deque< WireCell::IDepo::pointer > m_depos
Definition: SimDepoSource.h:60
void SimDepoSource::visit ( art::Event event)
virtual

IArtEventVisitor.

Implements wcls::IArtEventVisitor.

Definition at line 153 of file SimDepoSource.cxx.

154 {
156 
157  bool okay = event.getByLabel(m_inputTag, sedvh);
158  if (!okay) {
159  std::string msg = "SimDepoSource failed to get sim::SimEnergyDeposit from art tag: " + m_inputTag.encode();
160  std::cerr << msg << std::endl;
161  THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
162  }
163  //else if (sedvh->empty()) return;
164 
165  const size_t ndepos = sedvh->size();
166 
167  std::cerr << "SimDepoSource got " << ndepos
168  << " depos from art tag \"" << m_inputTag
169  << "\" returns: " << (okay ? "okay" : "fail") << std::endl;
170 
171  if (!m_depos.empty()) {
172  std::cerr << "SimDepoSource dropping " << m_depos.size()
173  << " unused, prior depos\n";
174  m_depos.clear();
175  }
176 
177  // associate the input SED with the other set of SED (eg, before SCE)
178  std::vector<sim::SimEnergyDeposit> assn_sedv;
179  if (m_assnTag!="") {
181  okay = event.getByLabel(m_assnTag, assn_sedvh);
182  if (!okay) {
183  std::string msg = "SimDepoSource failed to get sim::SimEnergyDeposit from art tag: " + m_assnTag.encode();
184  std::cerr << msg << std::endl;
185  THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
186  }
187  else {
188  std::cout << "Larwirecell::SimDepoSource 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() );
191  }
192  // safty check for the associated SED
193  if (ndepos != assn_sedv.size()) {
194  std::string msg = "Larwirecell::SimDepoSource Inconsistent size of SimDepoSources";
195  std::cerr << msg << std::endl;
196  THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
197  }
198  }
199 
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();
208  double we = sed.Energy()*units::MeV;
209 
210  if (assn_sedv.size() == 0) {
211  WireCell::IDepo::pointer depo
212  = std::make_shared<WireCell::SimpleDepo>(wt, wpt, wq, nullptr, 0.0, 0.0, wid, pdg, we);
213  m_depos.push_back(depo);
214  // std::cerr << ind << ": t=" << wt/units::us << "us,"
215  // << " r=" << wpt/units::cm << "cm, "
216  // << " q=" << wq
217  // << " e=" << we/units::MeV << "\n";
218  }
219  else {
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();
227  double we1 = sed1.Energy()*units::MeV;
228 
229  WireCell::IDepo::pointer assn_depo
230  = std::make_shared<WireCell::SimpleDepo>(wt1, wpt1, wq1, nullptr, 0.0, 0.0, wid1, pdg1, we1);
231 
232  WireCell::IDepo::pointer depo
233  = std::make_shared<WireCell::SimpleDepo>(wt, wpt, wq, assn_depo, 0.0, 0.0, wid, pdg, we);
234  m_depos.push_back(depo);
235  // std::cerr << ind << ": t1=" << wt1/units::us << "us,"
236  // << " r1=" << wpt1/units::cm << "cm, "
237  // << " q1=" << wq1
238  // << " e1=" << we1/units::MeV << "\n";
239  }
240  }
241 
242  // empty "ionization": no TPC activity
243  if (ndepos == 0) {
244  WireCell::Point wpt(0, 0, 0);
245  WireCell::IDepo::pointer depo
246  = std::make_shared<WireCell::SimpleDepo>(0, wpt, 0, nullptr, 0.0, 0.0);
247  m_depos.push_back(depo);
248  }
249 
250  // don't trust user to honor time ordering.
251  std::sort(m_depos.begin(), m_depos.end(), WireCell::ascending_time);
252  std::cerr << "SimDepoSource: ready with " << m_depos.size() << " depos spanning: ["
253  << m_depos.front()->time()/units::us << ", "
254  << m_depos.back()->time()/units::us << "]us\n";
255  m_depos.push_back(nullptr); // EOS marker
256 }
static constexpr double cm
Definition: Units.h:68
static constexpr double us
Definition: Units.h:97
void msg(const char *fmt,...)
Definition: message.cpp:107
std::string string
Definition: nybbler.cc:12
std::deque< WireCell::IDepo::pointer > m_depos
Definition: SimDepoSource.h:60
static constexpr double MeV
Definition: Units.h:129
std::string encode() const
Definition: InputTag.cc:97
art::InputTag m_assnTag
Definition: SimDepoSource.h:64
art::InputTag m_inputTag
Definition: SimDepoSource.h:63
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:44
QAsciiDict< Entry > ns
QTextStream & endl(QTextStream &s)

Member Data Documentation

bits::DepoAdapter* wcls::SimDepoSource::m_adapter
private

Definition at line 61 of file SimDepoSource.h.

art::InputTag wcls::SimDepoSource::m_assnTag
private

Definition at line 64 of file SimDepoSource.h.

std::deque<WireCell::IDepo::pointer> wcls::SimDepoSource::m_depos
private

Definition at line 60 of file SimDepoSource.h.

art::InputTag wcls::SimDepoSource::m_inputTag
private

Definition at line 63 of file SimDepoSource.h.


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