All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 87 of file SimDepoSource.cxx.

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

Definition at line 92 of file SimDepoSource.cxx.

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

Member Function Documentation

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

Definition at line 118 of file SimDepoSource.cxx.

119 {
120  if (m_adapter) {
121  delete m_adapter;
122  m_adapter = nullptr;
123  }
124  double scale = WireCell::get(cfg, "scale", 1.0);
125 
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];
130  }
131 
132  if (model_type == "" or model_type == "electrons") {
134  }
135  else {
136  auto model = WireCell::Factory::lookup_tn<WireCell::IRecombinationModel>(model_tn);
137  if (!model) {
138  std::cerr << "wcls::SimDepoSource: unknown recombination model: \"" << model_tn << "\"\n";
139  return; // I should throw something here!
140  }
141  if (model_type == "MipRecombination") {
142  m_adapter = new wcls::bits::PointAdapter(model, scale);
143  }
144  if (model_type == "BirksRecombination" || model_type == "BoxRecombination") {
145  m_adapter = new wcls::bits::StepAdapter(model, scale);
146  }
147  }
148 
149  m_inputTag = cfg["art_tag"].asString();
150  m_assnTag = cfg["assn_art_tag"].asString();
151 }
BEGIN_PROLOG could also be cerr
art::InputTag m_assnTag
Definition: SimDepoSource.h:64
art::InputTag m_inputTag
Definition: SimDepoSource.h:63
bits::DepoAdapter * m_adapter
Definition: SimDepoSource.h:61
WireCell::Configuration SimDepoSource::default_configuration ( ) const
virtual

IConfigurable.

Definition at line 100 of file SimDepoSource.cxx.

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

IDepoSource.

Definition at line 259 of file SimDepoSource.cxx.

260 {
261  if (m_depos.empty()) {
262  return false;
263  }
264 
265  out = m_depos.front();
266  m_depos.pop_front();
267 
268  // if (!out) {
269  // std::cerr << "SimDepoSource: reached EOS\n";
270  // }
271  // else {
272  // std::cerr << "SimDepoSource: t=" << out->time()/units::us << "us,"
273  // << " r=" << out->pos()/units::cm << "cm, " << " q=" << out->charge() << "\n";
274  // }
275  return true;
276 }
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 154 of file SimDepoSource.cxx.

155 {
156  art::Handle< std::vector<sim::SimEnergyDeposit> > sedvh;
157 
158  bool okay = event.getByLabel(m_inputTag, sedvh);
159  if (!okay) {
160  std::string msg = "SimDepoSource failed to get sim::SimEnergyDeposit from art tag: " + m_inputTag.encode();
161  std::cerr << msg << std::endl;
162  THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
163  }
164  //else if (sedvh->empty()) return;
165 
166  const size_t ndepos = sedvh->size();
167 
168  std::cerr << "SimDepoSource got " << ndepos
169  << " depos from art tag \"" << m_inputTag
170  << "\" returns: " << (okay ? "okay" : "fail") << std::endl;
171 
172  if (!m_depos.empty()) {
173  std::cerr << "SimDepoSource dropping " << m_depos.size()
174  << " unused, prior depos\n";
175  m_depos.clear();
176  }
177 
178  // associate the input SED with the other set of SED (eg, before SCE)
179  std::vector<sim::SimEnergyDeposit> assn_sedv;
180  if (m_assnTag!="") {
181  art::Handle< std::vector<sim::SimEnergyDeposit> > assn_sedvh;
182  okay = event.getByLabel(m_assnTag, assn_sedvh);
183  if (!okay) {
184  std::string msg = "SimDepoSource failed to get sim::SimEnergyDeposit from art tag: " + m_assnTag.encode();
185  std::cerr << msg << std::endl;
186  THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
187  }
188  else {
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() );
192  }
193  // safty check for the associated SED
194  if (ndepos != assn_sedv.size()) {
195  std::string msg = "Larwirecell::SimDepoSource Inconsistent size of SimDepoSources";
196  std::cerr << msg << std::endl;
197  THROW(WireCell::RuntimeError() << WireCell::errmsg{msg});
198  }
199  }
200 
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();
209  double we = sed.Energy()*units::MeV;
210 
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);
214  m_depos.push_back(depo);
215  // std::cerr << ind << ": t=" << wt/units::us << "us,"
216  // << " r=" << wpt/units::cm << "cm, "
217  // << " q=" << wq
218  // << " e=" << we/units::MeV << "\n";
219  }
220  else {
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();
228  double we1 = sed1.Energy()*units::MeV;
229 
230  WireCell::IDepo::pointer assn_depo
231  = std::make_shared<SimpleDepo>(wt1, wpt1, wq1, nullptr, 0.0, 0.0, wid1, pdg1, we1);
232 
233  WireCell::IDepo::pointer depo
234  = std::make_shared<SimpleDepo>(wt, wpt, wq, assn_depo, 0.0, 0.0, wid, pdg, we);
235  m_depos.push_back(depo);
236  // std::cerr << ind << ": t1=" << wt1/units::us << "us,"
237  // << " r1=" << wpt1/units::cm << "cm, "
238  // << " q1=" << wq1
239  // << " e1=" << we1/units::MeV << "\n";
240  }
241  }
242 
243  // empty "ionization": no TPC activity
244  if (ndepos == 0) {
245  WireCell::Point wpt(0, 0, 0);
246  WireCell::IDepo::pointer depo
247  = std::make_shared<SimpleDepo>(0, wpt, 0, nullptr, 0.0, 0.0);
248  m_depos.push_back(depo);
249  }
250 
251  // don't trust user to honor time ordering.
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";
256  m_depos.push_back(nullptr); // EOS marker
257 }
var pdg
Definition: selectors.fcl:14
BEGIN_PROLOG could also be cerr
std::deque< WireCell::IDepo::pointer > m_depos
Definition: SimDepoSource.h:60
util::quantities::megaelectronvolt MeV
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
BEGIN_PROLOG could also be cout

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: