LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
evgen::Decay0Gen Class Reference
Inheritance diagram for evgen::Decay0Gen:
evgen::BaseRadioGen art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 Decay0Gen (fhicl::ParameterSet const &pset)
 
 ~Decay0Gen ()
 
void produce (art::Event &evt)
 
void beginRun (art::Run &run)
 
void beginJob ()
 
void endJob ()
 
virtual void beginRun_radio (art::Run &)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
void fillProductDescriptions ()
 
void registerProducts (ProductDescriptions &productsToRegister)
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
std::unique_ptr< Worker > makeWorker (WorkerParams const &wp)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Protected Member Functions

int GetNDecays ()
 
bool GetGoodPositionTime (TLorentzVector &position)
 
TLorentzVector dirCalc (double p, double m)
 
void FillHistos (simb::MCParticle &part)
 
CLHEP::HepRandomEngine & GetRandomEngine ()
 
int GetNEvents ()
 
void GetTs (double &T0, double &T1)
 
void GetXs (double &X0, double &X1)
 
void GetYs (double &Y0, double &Y1)
 
void GetZs (double &Z0, double &Z1)
 
ConsumesCollector & consumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Protected Attributes

std::vector< std::string > m_isotope
 isotope to simulate. Example: "Ar39" More...
 

Private Member Functions

void produce_radio (art::Event &evt)
 
void beginJob_radio ()
 
void endJob_radio ()
 

Private Attributes

std::shared_ptr< clhep_randomm_random_decay0
 
std::vector< std::unique_ptr< bxdecay0::decay0_generator > > m_decay0_generator
 
TH1D * m_timediff_TH1D
 
bool m_single_isotope_mode
 

Detailed Description

Module to generate particles created by radiological decay, patterend off of SingleGen Currently it generates only in rectangular prisms oriented along the x,y,z axes

Definition at line 25 of file Decay0Gen_module.cc.

Member Typedef Documentation

Definition at line 17 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::detail::Producer::Table = Modifier::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 26 of file Producer.h.

Constructor & Destructor Documentation

evgen::Decay0Gen::Decay0Gen ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 70 of file Decay0Gen_module.cc.

References fhicl::ParameterSet::get(), fhicl::ParameterSet::get_if_present(), evgen::BaseRadioGen::GetRandomEngine(), m_decay0_generator, evgen::BaseRadioGen::m_isotope, m_random_decay0, m_single_isotope_mode, and util::to_string().

70  : BaseRadioGen(pset)
71  {
72  std::string isotope = "";
73  m_single_isotope_mode = pset.get_if_present<std::string>("isotope", isotope);
74 
75  if (not m_single_isotope_mode) {
76  fhicl::ParameterSet decay_chain = pset.get<fhicl::ParameterSet>("decay_chain");
77  int index = 0;
78 
79  while (
80  decay_chain.get_if_present<std::string>("isotope_" + std::to_string(index++), isotope)) {
81  m_isotope.push_back(isotope);
82  }
83  }
84  else {
85  m_isotope.push_back(isotope);
86  }
87 
88  m_random_decay0 = std::make_shared<clhep_random>(GetRandomEngine());
89 
90  for (auto const& isotope : m_isotope) {
91  auto generator = std::make_unique<bxdecay0::decay0_generator>();
92  generator->reset();
93 
94  // Configure the Decay0 generator:
95  generator->set_decay_category(bxdecay0::decay0_generator::DECAY_CATEGORY_BACKGROUND);
96  generator->set_decay_isotope(isotope.c_str());
97  try {
98  generator->initialize(*m_random_decay0);
99  }
100  catch (...) {
101  throw cet::exception("Decay0Gen") << "The inialisation of Decay0 failed. Maybe the isotope "
102  << isotope << " doesn't exists?\n";
103  }
104  m_decay0_generator.push_back(std::move(generator));
105  }
106  }
std::vector< std::unique_ptr< bxdecay0::decay0_generator > > m_decay0_generator
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
T get(std::string const &key) const
Definition: ParameterSet.h:314
CLHEP::HepRandomEngine & GetRandomEngine()
Definition: BaseRadioGen.h:92
BaseRadioGen(fhicl::ParameterSet const &pset)
Definition: BaseRadioGen.h:269
std::vector< std::string > m_isotope
isotope to simulate. Example: "Ar39"
Definition: BaseRadioGen.h:90
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:267
std::shared_ptr< clhep_random > m_random_decay0
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
evgen::Decay0Gen::~Decay0Gen ( )
inline

Definition at line 28 of file Decay0Gen_module.cc.

References beginJob_radio(), endJob_radio(), tca::evt, m_decay0_generator, and produce_radio().

29  {
30  for (auto& i : m_decay0_generator) {
31  i->reset();
32  }
33  }
std::vector< std::unique_ptr< bxdecay0::decay0_generator > > m_decay0_generator

Member Function Documentation

void evgen::BaseRadioGen::beginJob ( )
inlinevirtualinherited

Reimplemented from art::EDProducer.

Definition at line 490 of file BaseRadioGen.h.

491  {
492  if (m_isotope.empty()) {
493  throw cet::exception("BaseRadioGen")
494  << "m_isotope is empty, you need to fill it yourself in the constructor of your module\n";
495  }
496 
498  beginJob_radio();
499  m_nevent = 0;
500  }
virtual void beginJob_radio()
Definition: BaseRadioGen.h:81
std::vector< std::string > m_isotope
isotope to simulate. Example: "Ar39"
Definition: BaseRadioGen.h:90
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void evgen::Decay0Gen::beginJob_radio ( )
privatevirtual

Reimplemented from evgen::BaseRadioGen.

Definition at line 108 of file Decay0Gen_module.cc.

References evgen::BaseRadioGen::GetTs(), and m_timediff_TH1D.

Referenced by ~Decay0Gen().

109  {
111  double T0 = 0, T1 = 0;
112  GetTs(T0, T1);
114  tfs->make<TH1D>("TimeDiff", ";Time Diff[ns];n particles", (int)((T1) / 10000), 0, T1);
115  }
void GetTs(double &T0, double &T1)
Definition: BaseRadioGen.h:94
void evgen::BaseRadioGen::beginRun ( art::Run run)
inlinevirtualinherited

Reimplemented from art::EDProducer.

Definition at line 483 of file BaseRadioGen.h.

484  {
486  run.put(std::make_unique<sumdata::RunData>(m_geo_service->DetectorName()), art::fullRun());
487  beginRun_radio(run);
488  }
constexpr auto fullRun()
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Run.h:121
virtual void beginRun_radio(art::Run &)
Definition: BaseRadioGen.h:80
art::ServiceHandle< geo::Geometry const > m_geo_service
Definition: BaseRadioGen.h:157
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
Definition: GeometryCore.h:203
Namespace collecting geometry-related classes utilities.
virtual void evgen::BaseRadioGen::beginRun_radio ( art::Run )
inlinevirtualinherited

Definition at line 80 of file BaseRadioGen.h.

80 {}
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::consumes ( InputTag const &  tag)
protectedinherited

Definition at line 61 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumes().

62  {
63  return collector_.consumes<T, BT>(tag);
64  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ProductToken< T > consumes(InputTag const &)
ConsumesCollector & art::ModuleBase::consumesCollector ( )
protectedinherited

Definition at line 57 of file ModuleBase.cc.

References art::ModuleBase::collector_.

58  {
59  return collector_;
60  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::consumesMany ( )
protectedinherited

Definition at line 75 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesMany().

76  {
77  collector_.consumesMany<T, BT>();
78  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::consumesView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::consumesView ( InputTag const &  tag)
inherited

Definition at line 68 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesView().

69  {
70  return collector_.consumesView<T, BT>(tag);
71  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > consumesView(InputTag const &)
TLorentzVector evgen::BaseRadioGen::dirCalc ( double  p,
double  m 
)
inlineprotectedinherited

Definition at line 810 of file BaseRadioGen.h.

Referenced by evgen::BaseRadioGen::endJob_radio(), and evgen::SpectrumVolumeGen::produce_radio().

811  {
812  // isotropic production angle for the decay product
813  double costheta = (2.0 * m_random_flat.fire() - 1.0);
814 
815  if (costheta < -1.0) costheta = -1.0;
816  if (costheta > 1.0) costheta = 1.0;
817 
818  double const sintheta = sqrt(1.0 - costheta * costheta);
819  double const phi = 2.0 * M_PI * m_random_flat.fire();
820 
821  return TLorentzVector{p * sintheta * std::cos(phi),
822  p * sintheta * std::sin(phi),
823  p * costheta,
824  std::sqrt(p * p + m * m)};
825  }
CLHEP::RandFlat m_random_flat
Definition: BaseRadioGen.h:161
void art::detail::Producer::doBeginJob ( SharedResources const &  resources)
inherited

Definition at line 22 of file Producer.cc.

References art::detail::Producer::beginJobWithFrame(), and art::detail::Producer::setupQueues().

23  {
24  setupQueues(resources);
25  ProcessingFrame const frame{ScheduleID{}};
26  beginJobWithFrame(frame);
27  }
virtual void setupQueues(SharedResources const &)=0
virtual void beginJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doBeginRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 65 of file Producer.cc.

References art::detail::Producer::beginRunWithFrame(), art::RangeSet::forRun(), art::RunPrincipal::makeRun(), r, art::RunPrincipal::runID(), and art::ModuleContext::scheduleID().

66  {
67  auto r = rp.makeRun(mc, RangeSet::forRun(rp.runID()));
68  ProcessingFrame const frame{mc.scheduleID()};
69  beginRunWithFrame(r, frame);
70  r.commitProducts();
71  return true;
72  }
TRandom r
Definition: spectrum.C:23
virtual void beginRunWithFrame(Run &, ProcessingFrame const &)=0
static RangeSet forRun(RunID)
Definition: RangeSet.cc:51
bool art::detail::Producer::doBeginSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 85 of file Producer.cc.

References art::detail::Producer::beginSubRunWithFrame(), art::RangeSet::forSubRun(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::SubRunPrincipal::subRunID().

86  {
87  auto sr = srp.makeSubRun(mc, RangeSet::forSubRun(srp.subRunID()));
88  ProcessingFrame const frame{mc.scheduleID()};
89  beginSubRunWithFrame(sr, frame);
90  sr.commitProducts();
91  return true;
92  }
virtual void beginSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:57
void art::detail::Producer::doEndJob ( )
inherited

Definition at line 30 of file Producer.cc.

References art::detail::Producer::endJobWithFrame().

31  {
32  ProcessingFrame const frame{ScheduleID{}};
33  endJobWithFrame(frame);
34  }
virtual void endJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doEndRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 75 of file Producer.cc.

References art::detail::Producer::endRunWithFrame(), art::RunPrincipal::makeRun(), r, art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

76  {
77  auto r = rp.makeRun(mc, rp.seenRanges());
78  ProcessingFrame const frame{mc.scheduleID()};
79  endRunWithFrame(r, frame);
80  r.commitProducts();
81  return true;
82  }
TRandom r
Definition: spectrum.C:23
virtual void endRunWithFrame(Run &, ProcessingFrame const &)=0
bool art::detail::Producer::doEndSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 95 of file Producer.cc.

References art::detail::Producer::endSubRunWithFrame(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

96  {
97  auto sr = srp.makeSubRun(mc, srp.seenRanges());
98  ProcessingFrame const frame{mc.scheduleID()};
99  endSubRunWithFrame(sr, frame);
100  sr.commitProducts();
101  return true;
102  }
virtual void endSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
bool art::detail::Producer::doEvent ( EventPrincipal ep,
ModuleContext const &  mc,
std::atomic< std::size_t > &  counts_run,
std::atomic< std::size_t > &  counts_passed,
std::atomic< std::size_t > &  counts_failed 
)
inherited

Definition at line 105 of file Producer.cc.

References art::detail::Producer::checkPutProducts_, e, art::EventPrincipal::makeEvent(), art::detail::Producer::produceWithFrame(), and art::ModuleContext::scheduleID().

110  {
111  auto e = ep.makeEvent(mc);
112  ++counts_run;
113  ProcessingFrame const frame{mc.scheduleID()};
114  produceWithFrame(e, frame);
115  e.commitProducts(checkPutProducts_, &expectedProducts<InEvent>());
116  ++counts_passed;
117  return true;
118  }
bool const checkPutProducts_
Definition: Producer.h:70
Float_t e
Definition: plot.C:35
virtual void produceWithFrame(Event &, ProcessingFrame const &)=0
void art::detail::Producer::doRespondToCloseInputFile ( FileBlock const &  fb)
inherited

Definition at line 44 of file Producer.cc.

References art::detail::Producer::respondToCloseInputFileWithFrame().

45  {
46  ProcessingFrame const frame{ScheduleID{}};
48  }
virtual void respondToCloseInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToCloseOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 58 of file Producer.cc.

References art::detail::Producer::respondToCloseOutputFilesWithFrame().

59  {
60  ProcessingFrame const frame{ScheduleID{}};
62  }
virtual void respondToCloseOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenInputFile ( FileBlock const &  fb)
inherited

Definition at line 37 of file Producer.cc.

References art::detail::Producer::respondToOpenInputFileWithFrame().

38  {
39  ProcessingFrame const frame{ScheduleID{}};
41  }
virtual void respondToOpenInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 51 of file Producer.cc.

References art::detail::Producer::respondToOpenOutputFilesWithFrame().

52  {
53  ProcessingFrame const frame{ScheduleID{}};
55  }
virtual void respondToOpenOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void evgen::BaseRadioGen::endJob ( )
inlinevirtualinherited

Reimplemented from art::EDProducer.

Definition at line 502 of file BaseRadioGen.h.

503  {
504  if (m_nevent) {
505  m_pdg_TH1D->Scale(1. / m_nevent);
506 
507  for (auto histo : m_pos_xy_TH2D) {
508  m_pos_xy_TH2D[histo.first]->Scale(1. / m_nevent);
509  m_pos_xz_TH2D[histo.first]->Scale(1. / m_nevent);
510  m_dir_x_TH1D[histo.first]->Scale(1. / m_nevent);
511  m_dir_y_TH1D[histo.first]->Scale(1. / m_nevent);
512  m_dir_z_TH1D[histo.first]->Scale(1. / m_nevent);
513  m_mom_TH1D[histo.first]->Scale(1. / m_nevent);
514  m_ke_TH1D[histo.first]->Scale(1. / m_nevent);
515  m_time_TH1D[histo.first]->Scale(1. / m_nevent);
516  }
517  }
518  endJob_radio();
519  }
std::map< int, TH1D * > m_dir_y_TH1D
Definition: BaseRadioGen.h:184
std::map< int, TH1D * > m_dir_x_TH1D
Definition: BaseRadioGen.h:183
virtual void endJob_radio()
Definition: BaseRadioGen.h:82
std::map< int, TH1D * > m_mom_TH1D
Definition: BaseRadioGen.h:186
std::map< int, TH1D * > m_ke_TH1D
Definition: BaseRadioGen.h:187
std::map< int, TH1D * > m_dir_z_TH1D
Definition: BaseRadioGen.h:185
std::map< int, TH2D * > m_pos_xz_TH2D
Definition: BaseRadioGen.h:182
std::map< int, TH1D * > m_time_TH1D
Definition: BaseRadioGen.h:188
std::map< int, TH2D * > m_pos_xy_TH2D
Definition: BaseRadioGen.h:181
void evgen::Decay0Gen::endJob_radio ( )
privatevirtual

Reimplemented from evgen::BaseRadioGen.

Definition at line 117 of file Decay0Gen_module.cc.

References evgen::BaseRadioGen::GetNEvents(), and m_timediff_TH1D.

Referenced by ~Decay0Gen().

118  {
119  if (GetNEvents()) m_timediff_TH1D->Scale(1. / GetNEvents());
120  }
void evgen::BaseRadioGen::FillHistos ( simb::MCParticle part)
inlineprotectedinherited

Definition at line 788 of file BaseRadioGen.h.

Referenced by evgen::BaseRadioGen::endJob_radio(), evgen::SpectrumVolumeGen::produce_radio(), and produce_radio().

789  {
790  int pdg = part.PdgCode();
791  int simple_pdg = 0;
792  std::string dummy = "";
793  SimplePDG(pdg, simple_pdg, dummy);
794 
795  TLorentzVector position = part.Position();
796  TLorentzVector mom = part.Momentum();
797  double mass = mom.M();
798  m_pos_xy_TH2D[simple_pdg]->Fill(position.X(), position.Y());
799  m_pos_xz_TH2D[simple_pdg]->Fill(position.X(), position.Z());
800  m_dir_x_TH1D[simple_pdg]->Fill(mom.Px() / mom.P());
801  m_dir_y_TH1D[simple_pdg]->Fill(mom.Py() / mom.P());
802  m_dir_z_TH1D[simple_pdg]->Fill(mom.Pz() / mom.P());
803  double ke = (sqrt(mom.P() * mom.P() + mass * mass) - mass) * 1000.;
804  m_ke_TH1D[simple_pdg]->Fill(ke);
805  m_mom_TH1D[simple_pdg]->Fill(mom.P() * 1000.);
806  m_time_TH1D[simple_pdg]->Fill(position.T());
807  m_pdg_TH1D->Fill(simple_pdg);
808  }
void SimplePDG(int pdg, int &simple, std::string &name)
Definition: BaseRadioGen.h:754
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:220
int PdgCode() const
Definition: MCParticle.h:213
std::map< int, TH1D * > m_dir_y_TH1D
Definition: BaseRadioGen.h:184
std::map< int, TH1D * > m_dir_x_TH1D
Definition: BaseRadioGen.h:183
std::map< int, TH1D * > m_mom_TH1D
Definition: BaseRadioGen.h:186
std::map< int, TH1D * > m_ke_TH1D
Definition: BaseRadioGen.h:187
std::map< int, TH1D * > m_dir_z_TH1D
Definition: BaseRadioGen.h:185
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:221
std::map< int, TH2D * > m_pos_xz_TH2D
Definition: BaseRadioGen.h:182
std::map< int, TH1D * > m_time_TH1D
Definition: BaseRadioGen.h:188
std::map< int, TH2D * > m_pos_xy_TH2D
Definition: BaseRadioGen.h:181
void art::Modifier::fillProductDescriptions ( )
inherited

Definition at line 10 of file Modifier.cc.

References art::ProductRegistryHelper::fillDescriptions(), and art::ModuleBase::moduleDescription().

11  {
13  }
void fillDescriptions(ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
std::array< std::vector< ProductInfo >, NumBranchTypes > const & art::ModuleBase::getConsumables ( ) const
inherited

Definition at line 43 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::getConsumables().

44  {
45  return collector_.getConsumables();
46  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables() const
bool evgen::BaseRadioGen::GetGoodPositionTime ( TLorentzVector &  position)
inlineprotectedinherited

Deal with the time first

We use all the XYZ that have been set earlier, until we find the correct volume and material

We use the list of nodes

Definition at line 521 of file BaseRadioGen.h.

Referenced by evgen::BaseRadioGen::endJob_radio(), evgen::SpectrumVolumeGen::produce_radio(), and produce_radio().

522  {
523 
525  double time = m_T0 + m_random_flat.fire() * (m_T1 - m_T0);
526 
527  if (not m_geo_volume_mode) {
529 
530  size_t n_tries = 0;
531 
532  double xpos = std::numeric_limits<double>::signaling_NaN();
533  double ypos = std::numeric_limits<double>::signaling_NaN();
534  double zpos = std::numeric_limits<double>::signaling_NaN();
535 
536  while (n_tries++ < m_max_tries_event) {
537 
538  if (m_distrib_xpos)
539  xpos = m_distrib_xpos->GetRandom(m_X0, m_X1);
540  else
541  xpos = m_X0 + m_random_flat.fire() * (m_X1 - m_X0);
542 
543  if (m_distrib_ypos)
544  ypos = m_distrib_ypos->GetRandom(m_Y0, m_Y1);
545  else
546  ypos = m_Y0 + m_random_flat.fire() * (m_Y1 - m_Y0);
547 
548  if (m_distrib_zpos)
549  zpos = m_distrib_zpos->GetRandom(m_Z0, m_Z1);
550  else
551  zpos = m_Z0 + m_random_flat.fire() * (m_Z1 - m_Z0);
552 
553  auto node = gGeoManager->FindNode(xpos, ypos, zpos);
554 
555  if (NodeSupported(node)) break;
556  }
557 
558  if (std::isnan(xpos) or std::isnan(ypos) or std::isnan(zpos)) {
559  MF_LOG_ERROR("BaseRadioGen") << "Error in generation of random position!";
560  }
561 
562  position.SetXYZT(xpos, ypos, zpos, time);
563  return true;
564  }
565  else {
567 
568  if (m_good_nodes.empty() or m_volume_cc == 0)
569  MF_LOG_ERROR("BaseRadioGen") << "There is no node to throw events in!";
570 
571  double which_vol = m_random_flat.fire() * m_volume_cc;
572 
573  const TGeoNode* node = nullptr;
574  size_t i = 0;
575 
576  for (auto const& nd : m_good_nodes) {
577  if (which_vol < nd.second) {
578  node = nd.first;
579  break;
580  }
581  i++;
582  }
583 
584  const TGeoNode* world = gGeoManager->GetNode(0);
585  double x_min, x_max;
586  double y_min, y_max;
587  double z_min, z_max;
588  GetNodeXYZMinMax(node, world, x_min, x_max, y_min, y_max, z_min, z_max);
589 
590  size_t n_tries = 0;
591 
592  while (n_tries++ < m_max_tries_event) {
593  double xpos = std::numeric_limits<double>::signaling_NaN();
594  double ypos = std::numeric_limits<double>::signaling_NaN();
595  double zpos = std::numeric_limits<double>::signaling_NaN();
596 
597  if (m_distrib_xpos)
598  xpos = m_distrib_xpos->GetRandom(x_min, x_max);
599  else
600  xpos = x_min + m_random_flat.fire() * (x_max - x_min);
601 
602  if (m_distrib_ypos)
603  ypos = m_distrib_ypos->GetRandom(y_min, y_max);
604  else
605  ypos = y_min + m_random_flat.fire() * (y_max - y_min);
606 
607  if (m_distrib_zpos)
608  zpos = m_distrib_zpos->GetRandom(z_min, z_max);
609  else
610  zpos = z_min + m_random_flat.fire() * (z_max - z_min);
611 
612  if (std::isnan(xpos) or std::isnan(ypos) or std::isnan(zpos)) {
613  MF_LOG_ERROR("BaseRadioGen") << "Error in generation of random position!";
614  }
615  position.SetXYZT(xpos, ypos, zpos, time);
616 
617  const TGeoNode* node_generated = gGeoManager->FindNode(xpos, ypos, zpos);
618  if (node_generated == node) return true;
619 
620  if (node->GetNdaughters() and IsDaughterNode(node_generated, node)) return true;
621  }
622  }
623 
624  return false;
625  }
double m_X1
Top corner x position (cm) in world coordinates.
Definition: BaseRadioGen.h:152
std::map< const TGeoNode *, double > m_good_nodes
Definition: BaseRadioGen.h:172
bool NodeSupported(TGeoNode const *node) const
Definition: BaseRadioGen.h:192
#define MF_LOG_ERROR(category)
STL namespace.
double x_min
Definition: berger.C:15
double m_Y1
Top corner y position (cm) in world coordinates.
Definition: BaseRadioGen.h:153
double m_Z1
Top corner z position (cm) in world coordinates.
Definition: BaseRadioGen.h:154
double m_T0
Beginning of time window to simulate in ns.
Definition: BaseRadioGen.h:147
double x_max
Definition: berger.C:16
double m_Z0
Bottom corner z position (cm) in world coordinates.
Definition: BaseRadioGen.h:151
bool IsDaughterNode(const TGeoNode *daughter_node, const TGeoNode *mother_node)
Definition: BaseRadioGen.h:639
CLHEP::RandFlat m_random_flat
Definition: BaseRadioGen.h:161
double m_Y0
Bottom corner y position (cm) in world coordinates.
Definition: BaseRadioGen.h:150
double m_X0
Bottom corner x position (cm) in world coordinates.
Definition: BaseRadioGen.h:149
double m_T1
End of time window to simulate in ns.
Definition: BaseRadioGen.h:148
void GetNodeXYZMinMax(const TGeoNode *from, const TGeoNode *to, double &x_min, double &x_max, double &y_min, double &y_max, double &z_min, double &z_max)
Definition: BaseRadioGen.h:199
int evgen::BaseRadioGen::GetNDecays ( )
inlineprotectedinherited

Definition at line 629 of file BaseRadioGen.h.

Referenced by evgen::BaseRadioGen::endJob_radio(), evgen::SpectrumVolumeGen::produce_radio(), and produce_radio().

630  {
631 
632  if (m_rate_mode) { return m_random_poisson.fire(m_rate); }
633  else {
634  double rate = abs(m_Bq * (m_T1 - m_T0) * m_volume_cc / 1.0E9);
635  return m_random_poisson.fire(rate);
636  }
637  }
CLHEP::RandPoisson m_random_poisson
Definition: BaseRadioGen.h:162
constexpr auto abs(T v)
Returns the absolute value of the argument.
double m_rate
Radioactivity in Becquerels (decay per sec) use either of this of Bq.
Definition: BaseRadioGen.h:145
double m_T0
Beginning of time window to simulate in ns.
Definition: BaseRadioGen.h:147
double m_Bq
Radioactivity in Becquerels (decay per sec) per cubic cm.
Definition: BaseRadioGen.h:144
double m_T1
End of time window to simulate in ns.
Definition: BaseRadioGen.h:148
int evgen::BaseRadioGen::GetNEvents ( )
inlineprotectedinherited

Definition at line 93 of file BaseRadioGen.h.

References evgen::BaseRadioGen::m_nevent.

Referenced by endJob_radio().

93 { return m_nevent; }
CLHEP::HepRandomEngine& evgen::BaseRadioGen::GetRandomEngine ( )
inlineprotectedinherited

Definition at line 92 of file BaseRadioGen.h.

References evgen::BaseRadioGen::m_engine.

Referenced by Decay0Gen().

92 { return m_engine; }
CLHEP::HepRandomEngine & m_engine
Definition: BaseRadioGen.h:160
void evgen::BaseRadioGen::GetTs ( double &  T0,
double &  T1 
)
inlineprotectedinherited

Definition at line 94 of file BaseRadioGen.h.

References evgen::BaseRadioGen::m_T0, and evgen::BaseRadioGen::m_T1.

Referenced by beginJob_radio().

95  {
96  T0 = m_T0;
97  T1 = m_T1;
98  }
double m_T0
Beginning of time window to simulate in ns.
Definition: BaseRadioGen.h:147
double m_T1
End of time window to simulate in ns.
Definition: BaseRadioGen.h:148
void evgen::BaseRadioGen::GetXs ( double &  X0,
double &  X1 
)
inlineprotectedinherited

Definition at line 99 of file BaseRadioGen.h.

References evgen::BaseRadioGen::m_X0, and evgen::BaseRadioGen::m_X1.

100  {
101  X0 = m_X0;
102  X1 = m_X1;
103  }
double m_X1
Top corner x position (cm) in world coordinates.
Definition: BaseRadioGen.h:152
Double_t X1
Definition: plot.C:263
double m_X0
Bottom corner x position (cm) in world coordinates.
Definition: BaseRadioGen.h:149
void evgen::BaseRadioGen::GetYs ( double &  Y0,
double &  Y1 
)
inlineprotectedinherited

Definition at line 104 of file BaseRadioGen.h.

References evgen::BaseRadioGen::m_Y0, and evgen::BaseRadioGen::m_Y1.

105  {
106  Y0 = m_Y0;
107  Y1 = m_Y1;
108  }
double m_Y1
Top corner y position (cm) in world coordinates.
Definition: BaseRadioGen.h:153
Double_t Y1
Definition: plot.C:263
double m_Y0
Bottom corner y position (cm) in world coordinates.
Definition: BaseRadioGen.h:150
void evgen::BaseRadioGen::GetZs ( double &  Z0,
double &  Z1 
)
inlineprotectedinherited

Definition at line 109 of file BaseRadioGen.h.

References evgen::BaseRadioGen::CalculateActiveVolumeFromAllNodes(), evgen::BaseRadioGen::CalculateActiveVolumeFromXYZ(), evgen::BaseRadioGen::DeclareOutputHistos(), evgen::BaseRadioGen::m_Z0, evgen::BaseRadioGen::m_Z1, and evgen::BaseRadioGen::SimplePDG().

110  {
111  Z0 = m_Z0;
112  Z1 = m_Z1;
113  }
double m_Z1
Top corner z position (cm) in world coordinates.
Definition: BaseRadioGen.h:154
Double_t Z1
Definition: plot.C:263
double m_Z0
Bottom corner z position (cm) in world coordinates.
Definition: BaseRadioGen.h:151
std::unique_ptr< Worker > art::ModuleBase::makeWorker ( WorkerParams const &  wp)
inherited

Definition at line 37 of file ModuleBase.cc.

References art::ModuleBase::doMakeWorker(), and art::NumBranchTypes.

38  {
39  return doMakeWorker(wp);
40  }
virtual std::unique_ptr< Worker > doMakeWorker(WorkerParams const &wp)=0
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::mayConsume ( InputTag const &  tag)
protectedinherited

Definition at line 82 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsume().

83  {
84  return collector_.mayConsume<T, BT>(tag);
85  }
ProductToken< T > mayConsume(InputTag const &)
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::mayConsumeMany ( )
protectedinherited

Definition at line 96 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeMany().

97  {
98  collector_.mayConsumeMany<T, BT>();
99  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::mayConsumeView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::mayConsumeView ( InputTag const &  tag)
inherited

Definition at line 89 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeView().

90  {
91  return collector_.mayConsumeView<T, BT>(tag);
92  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > mayConsumeView(InputTag const &)
ModuleDescription const & art::ModuleBase::moduleDescription ( ) const
inherited

Definition at line 13 of file ModuleBase.cc.

References art::errors::LogicError.

Referenced by art::OutputModule::doRespondToOpenInputFile(), art::OutputModule::doWriteEvent(), art::Modifier::fillProductDescriptions(), art::OutputModule::makePlugins_(), art::OutputWorker::OutputWorker(), reco::shower::LArPandoraModularShowerCreation::produce(), art::Modifier::registerProducts(), and art::OutputModule::registerProducts().

14  {
15  if (md_.has_value()) {
16  return *md_;
17  }
18 
20  "There was an error while calling moduleDescription().\n"}
21  << "The moduleDescription() base-class member function cannot be called\n"
22  "during module construction. To determine which module is "
23  "responsible\n"
24  "for calling it, find the '<module type>:<module "
25  "label>@Construction'\n"
26  "tag in the message prefix above. Please contact artists@fnal.gov\n"
27  "for guidance.\n";
28  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
void evgen::BaseRadioGen::produce ( art::Event evt)
inlinevirtualinherited

Implements art::EDProducer.

Definition at line 477 of file BaseRadioGen.h.

478  {
479  m_nevent++;
480  produce_radio(evt);
481  }
virtual void produce_radio(art::Event &evt)=0
void evgen::Decay0Gen::produce_radio ( art::Event evt)
privatevirtual

Implements evgen::BaseRadioGen.

Definition at line 123 of file Decay0Gen_module.cc.

References util::abs(), simb::MCTruth::Add(), simb::MCParticle::AddTrajectoryPoint(), DEFINE_ART_MODULE, e, evgen::BaseRadioGen::FillHistos(), evgen::BaseRadioGen::GetGoodPositionTime(), evgen::BaseRadioGen::GetNDecays(), simb::kSingleParticle, m_decay0_generator, m_random_decay0, m_timediff_TH1D, MF_LOG_DEBUG, MF_LOG_ERROR, part, art::Event::put(), and simb::MCTruth::SetOrigin().

Referenced by ~Decay0Gen().

124  {
125  //unique_ptr allows ownership to be transferred to the art::Event after the put statement
126  std::unique_ptr<std::vector<simb::MCTruth>> truthcol(new std::vector<simb::MCTruth>);
127 
128  simb::MCTruth truth;
130  int track_id = -1;
131  const std::string primary_str("primary");
132  int bad_position = 0;
133  int tentative_decay = 0;
134  for (auto const& decay0_gen : m_decay0_generator) {
135  int n_decay = GetNDecays();
136 
137  tentative_decay += n_decay;
138  for (int iDecay = 0; iDecay < n_decay; ++iDecay) {
139  TLorentzVector position;
140  if (GetGoodPositionTime(position)) {
141 
142  bxdecay0::event gendecay; // Declare an empty decay event
143  decay0_gen->shoot(*m_random_decay0, gendecay); // Randomize the decay event
144  std::vector<bxdecay0::particle> part = gendecay.get_particles();
145 
146  double t_alpha = 0;
147  double t_electron = 0;
148  for (auto const& p : part) {
149  // alpha particles need a little help since they're not in the TDatabasePDG table
150  // so don't rely so heavily on default arguments to the MCParticle constructor
152  if (not p.is_valid()) {
153  p.print(std::cout);
154  throw cet::exception("Decay0Gen") << "Invalid part generated by Decay0, printed "
155  "above (no clue what that means so throw)";
156  }
157 
158  double mass = bxdecay0::particle_mass_MeV(p.get_code());
159  int pdg = 0;
160  //int simple_pdg=0; // simple_pdg is unused here
161 
162  if (p.is_alpha()) {
163  pdg = 1000020040;
164  part = simb::MCParticle(track_id, pdg, primary_str, -1, mass / 1000, 1);
165  }
166  else if (p.is_gamma()) {
167  pdg = 22;
168  part = simb::MCParticle(track_id, pdg, primary_str);
169  }
170  else if (p.is_positron()) {
171  pdg = -11;
172  part = simb::MCParticle(track_id, pdg, primary_str);
173  }
174  else if (p.is_electron()) {
175  pdg = 11;
176  part = simb::MCParticle(track_id, pdg, primary_str);
177  }
178  else if (p.is_neutron()) {
179  pdg = 2112;
180  part = simb::MCParticle(track_id, pdg, primary_str);
181  }
182  else if (p.is_proton()) {
183  pdg = 2212;
184  part = simb::MCParticle(track_id, pdg, primary_str);
185  }
186  else {
187  p.print(std::cout);
188  throw cet::exception("Decay0Gen") << "Particle above is weird, cannot recognise it.";
189  }
190 
191  if ((p.is_positron() or p.is_electron()) and t_electron == 0) {
192  t_electron = p.get_time();
193  }
194  if (p.is_alpha() and t_alpha == 0) { t_alpha = p.get_time(); }
195  track_id--;
196  TLorentzVector mom(p.get_px() / 1000.,
197  p.get_py() / 1000.,
198  p.get_pz() / 1000.,
199  sqrt(p.get_p() * p.get_p() + mass * mass) / 1000.);
200 
201  TLorentzVector this_part_position = position;
202  double t = position.T();
203  this_part_position.SetT(t + p.get_time() * 1e9);
204 
205  part.AddTrajectoryPoint(this_part_position, mom);
206 
207  truth.Add(part);
208 
209  FillHistos(part);
210  }
211  if (abs(t_alpha - t_electron) > 1.e-15) {
212  m_timediff_TH1D->Fill(1e9 * abs(t_alpha - t_electron));
213  }
214  gendecay.reset();
215  }
216  else { // !GetGoodPosition
217  ++bad_position;
218  }
219  } // idecay
220  } // m_decay_generators
221 
222  MF_LOG_DEBUG("Decay0Gen") << truth;
223  if (bad_position > 0) {
224  MF_LOG_ERROR("Decay0Gen")
225  << "There were " << bad_position
226  << " failed attempts to get a good position to generate a decay out of the target "
227  << tentative_decay << " decays.\n"
228  << "If these 2 numbers are close together, it means that the rate of your background is "
229  "wrong (underestimated).\n"
230  << "You can fix this by increasing the parameter \"max_tries_event\" to a bigger number "
231  "(default is 1M) in your fhicl.\n"
232  << "Another way is to change the \"volume_rand\" to a smaller one.\n";
233  }
234  truthcol->push_back(truth);
235  evt.put(std::move(truthcol));
236  }
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
Definition: MCParticle.h:258
void SetOrigin(simb::Origin_t origin)
Definition: MCTruth.h:82
constexpr auto abs(T v)
Returns the absolute value of the argument.
#define MF_LOG_ERROR(category)
void FillHistos(simb::MCParticle &part)
Definition: BaseRadioGen.h:788
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
TString part[npart]
Definition: Style.C:32
std::vector< std::unique_ptr< bxdecay0::decay0_generator > > m_decay0_generator
single particles thrown at the detector
Definition: MCTruth.h:26
bool GetGoodPositionTime(TLorentzVector &position)
Definition: BaseRadioGen.h:521
void Add(simb::MCParticle const &part)
Definition: MCTruth.h:80
#define MF_LOG_DEBUG(id)
Event generator information.
Definition: MCTruth.h:32
Float_t e
Definition: plot.C:35
std::shared_ptr< clhep_random > m_random_decay0
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void art::Modifier::registerProducts ( ProductDescriptions productsToRegister)
inherited

Definition at line 16 of file Modifier.cc.

References art::ModuleBase::moduleDescription(), and art::ProductRegistryHelper::registerProducts().

17  {
18  ProductRegistryHelper::registerProducts(productsToRegister,
20  }
void registerProducts(ProductDescriptions &productsToRegister, ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
void art::ModuleBase::setModuleDescription ( ModuleDescription const &  md)
inherited

Definition at line 31 of file ModuleBase.cc.

References art::ModuleBase::md_.

32  {
33  md_ = md;
34  }
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
void art::ModuleBase::sortConsumables ( std::string const &  current_process_name)
inherited

Definition at line 49 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::sortConsumables().

50  {
51  // Now that we know we have seen all the consumes declarations,
52  // sort the results for fast lookup later.
53  collector_.sortConsumables(current_process_name);
54  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
void sortConsumables(std::string const &current_process_name)

Member Data Documentation

std::vector<std::unique_ptr<bxdecay0::decay0_generator> > evgen::Decay0Gen::m_decay0_generator
private

Definition at line 44 of file Decay0Gen_module.cc.

Referenced by Decay0Gen(), produce_radio(), and ~Decay0Gen().

std::vector<std::string> evgen::BaseRadioGen::m_isotope
protectedinherited

isotope to simulate. Example: "Ar39"

Definition at line 90 of file BaseRadioGen.h.

Referenced by Decay0Gen(), and evgen::SpectrumVolumeGen::SpectrumVolumeGen().

std::shared_ptr<clhep_random> evgen::Decay0Gen::m_random_decay0
private

Definition at line 41 of file Decay0Gen_module.cc.

Referenced by Decay0Gen(), and produce_radio().

bool evgen::Decay0Gen::m_single_isotope_mode
private

Definition at line 46 of file Decay0Gen_module.cc.

Referenced by Decay0Gen().

TH1D* evgen::Decay0Gen::m_timediff_TH1D
private

Definition at line 45 of file Decay0Gen_module.cc.

Referenced by beginJob_radio(), endJob_radio(), and produce_radio().


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