Classes | Public Types | Public Member Functions | Private Attributes | List of all members
lar::example::tests::ParticleMaker Class Reference

Creates a collection of simulated particles. More...

Inheritance diagram for lar::example::tests::ParticleMaker:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Classes

struct  Config
 
struct  ParticleConfig
 
struct  ParticleSpecs
 

Public Types

using Parameters = art::EDProducer::Table< Config >
 
- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 

Public Member Functions

 ParticleMaker (Parameters const &config)
 Constructor; see the class documentation for the configuration. More...
 
virtual void produce (art::Event &event) override
 Create and add the particles (the same for all events). More...
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
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)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
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)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

std::vector< ParticleSpecsfParticleSpecs
 Settings for particles. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
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 ()
 

Detailed Description

Creates a collection of simulated particles.

A collection of simb::MCParticle is added to the event. The particles are one starting where the previous one ended (starting from the origin). The configuration specifies the number, type and energy of the particles, and their path length.

Configuration parameters

Definition at line 60 of file ParticleMaker_module.cc.

Member Typedef Documentation

Definition at line 98 of file ParticleMaker_module.cc.

Constructor & Destructor Documentation

lar::example::tests::ParticleMaker::ParticleMaker ( Parameters const &  config)
explicit

Constructor; see the class documentation for the configuration.

Definition at line 138 of file ParticleMaker_module.cc.

139  : EDProducer{config}
140 {
141 
142  auto const& particleSpecs = config().particles();
143  fParticleSpecs.assign(particleSpecs.begin(), particleSpecs.end());
144 
145  // consumes: nothing
146 
147  // produces:
148  produces<std::vector<simb::MCParticle>>();
149 
150 } // lar::example::tests::ParticleMaker::ParticleMaker()
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
static Config * config
Definition: config.cpp:1054
fhicl::Sequence< fhicl::Table< ParticleConfig > > particles
std::vector< ParticleSpecs > fParticleSpecs
Settings for particles.

Member Function Documentation

void lar::example::tests::ParticleMaker::produce ( art::Event event)
overridevirtual

Create and add the particles (the same for all events).

Implements art::EDProducer.

Definition at line 154 of file ParticleMaker_module.cc.

154  {
155 
156  //
157  // set up
158  //
159 
160  // container for the data product
161  auto particles = std::make_unique<std::vector<simb::MCParticle>>();
162 
163  //
164  // creation of the particles
165  //
166  static std::array<TVector3, 6U> const Dirs = {{
167  geo::vect::rounded01( geo::Xaxis<TVector3>(), 1e-8),
168  geo::vect::rounded01( geo::Yaxis<TVector3>(), 1e-8),
169  geo::vect::rounded01( geo::Zaxis<TVector3>(), 1e-8),
170  geo::vect::rounded01(-geo::Xaxis<TVector3>(), 1e-8),
171  geo::vect::rounded01(-geo::Yaxis<TVector3>(), 1e-8),
172  geo::vect::rounded01(-geo::Zaxis<TVector3>(), 1e-8)
173  }}; // Dirs
174 
175  int trackID = 0;
176  TLorentzVector pos;
177  for (auto const& specs: fParticleSpecs) {
178 
179  int const motherID = trackID - 1;
180  if (motherID >= 0) (*particles)[motherID].AddDaughter(trackID);
181 
182  particles->emplace_back(
183  trackID // track ID
184  , specs.type // pdg
185  , "magic" // process
186  , motherID // mother
187  );
188  simb::MCParticle& particle = particles->back();
189 
190  auto const& dir = Dirs[trackID % 6];
191  TLorentzVector const mom{ specs.energy * dir, specs.energy };
192  unsigned int const nSteps = std::ceil(specs.length);
193  particle.AddTrajectoryPoint(pos, mom);
194  for (unsigned int i = 1; i <= nSteps; ++i) {
195  double const stepSize = std::min(specs.length - double(i - 1), 1.0);
196  pos += TLorentzVector{ dir * stepSize, 1.0 };
197  particle.AddTrajectoryPoint(pos, mom);
198  } // for
199 
200  ++trackID;
201 
202  } // for specs
203 
204  //
205  // result storage
206  //
207  mf::LogInfo("ParticleMaker")
208  << "Created " << particles->size() << " space points.";
209 
210  event.put(std::move(particles));
211 
212 } // lar::example::tests::ParticleMaker::produce()
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
Definition: MCParticle.h:257
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
string dir
const double e
def move(depos, offset)
Definition: depos.py:107
Vector rounded01(Vector const &v, Scalar tol)
Returns a vector with all components rounded if close to 0, -1 or +1.
std::vector< ParticleSpecs > fParticleSpecs
Settings for particles.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55

Member Data Documentation

std::vector<ParticleSpecs> lar::example::tests::ParticleMaker::fParticleSpecs
private

Settings for particles.

Definition at line 120 of file ParticleMaker_module.cc.


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