LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
evgen::SingleGen Class Reference

module to produce single or multiple specified particles in the detector More...

Inheritance diagram for evgen::SingleGen:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Classes

struct  Config
 

Public Types

using Parameters = art::EDProducer::Table< Config >
 
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 SingleGen (Parameters const &config)
 
void produce (art::Event &evt)
 
void beginRun (art::Run &run)
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > consumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > consumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > mayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > mayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Member Functions

void SampleOne (unsigned int i, simb::MCTruth &mct)
 
void SampleMany (simb::MCTruth &mct)
 
void Sample (simb::MCTruth &mct)
 
void printVecs (std::vector< std::string > const &list)
 
bool PadVector (std::vector< double > &vec)
 
double SelectFromHist (const TH1 &h)
 
void SelectFromHist (const TH2 &h, double &x, double &y)
 
void setup ()
 Performs checks and initialization based on the current configuration. More...
 

Static Private Member Functions

static std::map< int, std::string > makeParticleSelectionModeNames ()
 actual TH2 for angle distributions - Xz on x axis . More...
 
static std::map< int, std::string > makeDistributionNames ()
 Returns a vector with the name of distribution keywords. More...
 
template<typename OptionList >
static auto selectOption (std::string Option, OptionList const &allowedOptions) -> decltype(auto)
 Parses an option string and returns the corresponding option number. More...
 
template<typename OptionList >
static std::string presentOptions (OptionList const &allowedOptions, bool printKey, std::initializer_list< typename OptionList::value_type::first_type > exclude)
 Returns a string describing all options in the list. More...
 
template<typename OptionList >
static std::string presentOptions (OptionList const &allowedOptions, bool printKey=true)
 
template<typename OptionList >
static std::string optionName (typename OptionList::value_type::first_type optionKey, OptionList const &allowedOptions, std::string defName="<unknown>")
 Returns the name of the specified option key, or defName if not known. More...
 

Private Attributes

int fMode
 
bool fPadOutVectors
 
std::vector< int > fPDG
 PDG code of particles to generate. More...
 
std::vector< double > fP0
 Central momentum (GeV/c) to generate. More...
 
std::vector< double > fSigmaP
 Variation in momenta (GeV/c) More...
 
int fPDist
 How to distribute momenta (gaus or uniform) More...
 
std::vector< double > fX0
 Central x position (cm) in world coordinates. More...
 
std::vector< double > fY0
 Central y position (cm) in world coordinates. More...
 
std::vector< double > fZ0
 Central z position (cm) in world coordinates. More...
 
std::vector< double > fT0
 Central t position (s) in world coordinates. More...
 
std::vector< double > fSigmaX
 Variation in x position (cm) More...
 
std::vector< double > fSigmaY
 Variation in y position (cm) More...
 
std::vector< double > fSigmaZ
 Variation in z position (cm) More...
 
std::vector< double > fSigmaT
 Variation in t position (s) More...
 
int fPosDist
 How to distribute xyz (gaus, or uniform) More...
 
int fTDist
 How to distribute t (gaus, or uniform) More...
 
bool fSingleVertex
 if true - all particles produced at the same location More...
 
std::vector< double > fTheta0XZ
 Angle in XZ plane (degrees) More...
 
std::vector< double > fTheta0YZ
 Angle in YZ plane (degrees) More...
 
std::vector< double > fSigmaThetaXZ
 Variation in angle in XZ plane. More...
 
std::vector< double > fSigmaThetaYZ
 Variation in angle in YZ plane. More...
 
int fAngleDist
 How to distribute angles (gaus, uniform) More...
 
std::string fHistFileName
 Filename containing histogram of momenta. More...
 
std::vector< std::string > fPHist
 name of histogram of momenta More...
 
std::vector< std::string > fThetaXzYzHist
 name of histogram for thetaxz/thetayz distribution More...
 
std::vector< std::unique_ptr< TH1 > > hPHist
 
std::vector< std::unique_ptr< TH2 > > hThetaXzYzHist
 actual TH1 for momentum distributions More...
 

Static Private Attributes

static const std::map< int, std::string > ParticleSelectionModeNames = SingleGen::makeParticleSelectionModeNames()
 Names of all particle selection modes. More...
 
static const std::map< int, std::string > DistributionNames = SingleGen::makeDistributionNames()
 Names of all distribution modes. More...
 
Constants for particle type extraction mode (`ParticleSelectionMode` parameter).
static constexpr int kSelectAllParts = 0
 One particle per entry is generated. More...
 
static constexpr int kSelectOneRandPart = 1
 
Constants for kinematic distribution options.
static constexpr int kUNIF = 0
 Uniform distribution. More...
 
static constexpr int kGAUS = 1
 Gaussian distribution. More...
 
static constexpr int kHIST = 2
 

Detailed Description

module to produce single or multiple specified particles in the detector

Definition at line 72 of file SingleGen_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

evgen::SingleGen::SingleGen ( Parameters const &  config)
explicit

Definition at line 475 of file SingleGen_module.cc.

References art::EngineCreator::createEngine(), seed, and setup().

476  : fMode (selectOption(config().ParticleSelectionMode(), ParticleSelectionModeNames))
477  , fPadOutVectors(config().PadOutVectors())
478  , fPDG (config().PDG())
479  , fP0 (config().P0())
480  , fSigmaP (config().SigmaP())
481  , fPDist (selectOption(config().PDist(), DistributionNames))
482  , fX0 (config().X0())
483  , fY0 (config().Y0())
484  , fZ0 (config().Z0())
485  , fT0 (config().T0())
486  , fSigmaX (config().SigmaX())
487  , fSigmaY (config().SigmaY())
488  , fSigmaZ (config().SigmaZ())
489  , fSigmaT (config().SigmaT())
490  , fPosDist (selectOption(config().PosDist(), DistributionNames))
491  , fTDist (selectOption(config().TDist(), DistributionNames))
492  , fTheta0XZ (config().Theta0XZ())
493  , fTheta0YZ (config().Theta0YZ())
494  , fSigmaThetaXZ (config().SigmaThetaXZ())
495  , fSigmaThetaYZ (config().SigmaThetaYZ())
496  , fAngleDist (selectOption(config().AngleDist(), DistributionNames))
497  , fHistFileName (config().HistogramFile())
498  , fPHist (config().PHist())
499 // , fThetaPhiHist (config().ThetaPhiHist())
500  , fThetaXzYzHist(config().ThetaXzYzHist())
501  {
502  setup();
503 
504  // create a default random engine; obtain the random seed from NuRandomService,
505  // unless overridden in configuration with key "Seed"
508  if (config().Seed(seed)) {
510  (seed, 0 /* dummy? */);
511  }
512 
513  produces< std::vector<simb::MCTruth> >();
514  produces< sumdata::RunData, art::InRun >();
515 
516  }
int fPDist
How to distribute momenta (gaus or uniform)
static const std::map< int, std::string > DistributionNames
Names of all distribution modes.
int fTDist
How to distribute t (gaus, or uniform)
std::vector< double > fSigmaT
Variation in t position (s)
std::vector< std::string > fThetaXzYzHist
name of histogram for thetaxz/thetayz distribution
art::RandomNumberGenerator::seed_t seed_t
int fPosDist
How to distribute xyz (gaus, or uniform)
std::vector< double > fSigmaZ
Variation in z position (cm)
std::vector< double > fT0
Central t position (s) in world coordinates.
base_engine_t & createEngine(seed_t seed)
long seed
Definition: chem4.cc:68
std::vector< double > fP0
Central momentum (GeV/c) to generate.
std::vector< double > fTheta0YZ
Angle in YZ plane (degrees)
static auto selectOption(std::string Option, OptionList const &allowedOptions) -> decltype(auto)
Parses an option string and returns the corresponding option number.
std::vector< double > fY0
Central y position (cm) in world coordinates.
std::vector< int > fPDG
PDG code of particles to generate.
std::vector< double > fSigmaThetaYZ
Variation in angle in YZ plane.
std::vector< double > fSigmaP
Variation in momenta (GeV/c)
std::vector< double > fZ0
Central z position (cm) in world coordinates.
std::vector< std::string > fPHist
name of histogram of momenta
std::vector< double > fSigmaX
Variation in x position (cm)
std::vector< double > fX0
Central x position (cm) in world coordinates.
static const std::map< int, std::string > ParticleSelectionModeNames
Names of all particle selection modes.
std::string fHistFileName
Filename containing histogram of momenta.
int fAngleDist
How to distribute angles (gaus, uniform)
std::vector< double > fTheta0XZ
Angle in XZ plane (degrees)
void setup()
Performs checks and initialization based on the current configuration.
std::vector< double > fSigmaThetaXZ
Variation in angle in XZ plane.
std::vector< double > fSigmaY
Variation in y position (cm)

Member Function Documentation

void evgen::SingleGen::beginRun ( art::Run run)
virtual

Reimplemented from art::EDProducer.

Definition at line 722 of file SingleGen_module.cc.

References geo::GeometryCore::DetectorName(), and art::Run::put().

723  {
724 
725  // grab the geometry object to see what geometry we are using
727  std::unique_ptr<sumdata::RunData> runcol(new sumdata::RunData(geo->DetectorName()));
728 
729  run.put(std::move(runcol));
730 
731  return;
732  }
art::ProductID put(std::unique_ptr< PROD > &&)
Definition: Run.h:148
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
Namespace collecting geometry-related classes utilities.
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 147 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

148 {
149  if (!moduleContext_)
150  return ProductToken<T>::invalid();
151 
152  consumables_[BT].emplace_back(ConsumableType::Product,
153  TypeID{typeid(T)},
154  it.label(),
155  it.instance(),
156  it.process());
157  return ProductToken<T>{it};
158 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 162 of file Consumer.h.

163 {
164  if (!moduleContext_)
165  return;
166 
167  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
168 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 172 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

173 {
174  if (!moduleContext_)
175  return ViewToken<T>::invalid();
176 
177  consumables_[BT].emplace_back(ConsumableType::ViewElement,
178  TypeID{typeid(T)},
179  it.label(),
180  it.instance(),
181  it.process());
182  return ViewToken<T>{it};
183 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited

Definition at line 32 of file EngineCreator.cc.

References art::EngineCreator::rng().

34 {
35  return rng()->createEngine(
36  placeholder_schedule_id(), seed, kind_of_engine_to_make);
37 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited

Definition at line 40 of file EngineCreator.cc.

References art::EngineCreator::rng().

43 {
44  return rng()->createEngine(
45  placeholder_schedule_id(), seed, kind_of_engine_to_make, engine_label);
46 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
CurrentProcessingContext const * art::EDProducer::currentContext ( ) const
protectedinherited

Definition at line 120 of file EDProducer.cc.

References art::EDProducer::current_context_.

121  {
122  return current_context_.get();
123  }
CPC_exempt_ptr current_context_
Definition: EDProducer.h:116
EngineCreator::seed_t EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited

Definition at line 49 of file EngineCreator.cc.

References fhicl::ParameterSet::get().

Referenced by art::MixFilter< T >::initEngine_().

52 {
53  auto const& explicit_seeds = pset.get<std::vector<int>>(key, {});
54  return explicit_seeds.empty() ? implicit_seed : explicit_seeds.front();
55 }
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References B, and art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
Int_t B
Definition: plot.C:25
std::map< int, std::string > evgen::SingleGen::makeDistributionNames ( )
staticprivate

Returns a vector with the name of distribution keywords.

Definition at line 395 of file SingleGen_module.cc.

395  {
396  std::map<int, std::string> names;
397  names[int(kUNIF)] = "uniform";
398  names[int(kGAUS)] = "Gaussian";
399  names[int(kHIST)] = "histograms";
400  return names;
401  } // SingleGen::makeDistributionNames()
static constexpr int kGAUS
Gaussian distribution.
static constexpr int kUNIF
Uniform distribution.
static constexpr int kHIST
std::map< int, std::string > evgen::SingleGen::makeParticleSelectionModeNames ( )
staticprivate

actual TH2 for angle distributions - Xz on x axis .

Returns a vector with the name of particle selection mode keywords.

Definition at line 388 of file SingleGen_module.cc.

388  {
389  std::map<int, std::string> names;
390  names[int(kSelectAllParts )] = "all";
391  names[int(kSelectOneRandPart)] = "singleRandom";
392  return names;
393  } // SingleGen::makeParticleSelectionModeNames()
static constexpr int kSelectOneRandPart
static constexpr int kSelectAllParts
One particle per entry is generated.
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 190 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

191 {
192  if (!moduleContext_)
193  return ProductToken<T>::invalid();
194 
195  consumables_[BT].emplace_back(ConsumableType::Product,
196  TypeID{typeid(T)},
197  it.label(),
198  it.instance(),
199  it.process());
200  return ProductToken<T>{it};
201 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 205 of file Consumer.h.

206 {
207  if (!moduleContext_)
208  return;
209 
210  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
211 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 215 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

216 {
217  if (!moduleContext_)
218  return ViewToken<T>::invalid();
219 
220  consumables_[BT].emplace_back(ConsumableType::ViewElement,
221  TypeID{typeid(T)},
222  it.label(),
223  it.instance(),
224  it.process());
225  return ViewToken<T>{it};
226 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID().

41  {
42  return true;
43  }
template<typename OptionList >
std::string evgen::SingleGen::optionName ( typename OptionList::value_type::first_type  optionKey,
OptionList const &  allowedOptions,
std::string  defName = "<unknown>" 
)
staticprivate

Returns the name of the specified option key, or defName if not known.

Definition at line 459 of file SingleGen_module.cc.

Referenced by setup().

463  {
464  auto iOption = allowedOptions.find(optionKey);
465  return (iOption != allowedOptions.end())? iOption->second: defName;
466  } // SingleGen::optionName()
bool evgen::SingleGen::PadVector ( std::vector< double > &  vec)
private

Definition at line 695 of file SingleGen_module.cc.

References fPadOutVectors, and fPDG.

Referenced by setup().

696  {
697  // check if the vec has the same size as fPDG
698  if( vec.size() != fPDG.size() ){
699  // if not padding out the vectors always cause an
700  // exception to be thrown if the vector in question
701  // is not the same size as the fPDG vector
702  // the exception is thrown in the reconfigure method
703  // that calls this one
704  if (!fPadOutVectors) return false;
705  else if( fPadOutVectors){
706  // if padding of vectors is desired but the vector in
707  // question has more than one entry it isn't clear
708  // what the padded values should be so cause
709  // an exception
710  if(vec.size() != 1) return false;
711 
712  // pad it out
713  vec.resize(fPDG.size(), vec[0]);
714 
715  }// end if padding out vectors
716  }// end if the vector size is not the same as fPDG
717 
718  return true;
719  }
std::vector< int > fPDG
PDG code of particles to generate.
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited

Definition at line 89 of file Consumer.cc.

References fhicl::ParameterSet::get_if_present().

Referenced by art::EDProducer::doBeginJob(), art::EDFilter::doBeginJob(), and art::EDAnalyzer::doBeginJob().

90 {
91  if (!moduleContext_)
92  return;
93 
94  pset.get_if_present("errorOnMissingConsumes", requireConsumes_);
95  for (auto& consumablesPerBranch : consumables_) {
96  cet::sort_all(consumablesPerBranch);
97  }
98 }
bool requireConsumes_
Definition: Consumer.h:137
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename OptionList >
std::string evgen::SingleGen::presentOptions ( OptionList const &  allowedOptions,
bool  printKey,
std::initializer_list< typename OptionList::value_type::first_type >  exclude 
)
staticprivate

Returns a string describing all options in the list.

Template Parameters
OptionListtype of list of options (e.g. std::map<int, std::string>)
Parameters
allowedOptionsthe list of allowed options
printKeywhether to print the key of the option beside its name
excludeKeyslist of keys to be ignored (none by default)
Returns
a string with all options in a line

The result string is a list of option names, separated by commas, like in `"'apple', 'orange', 'banana'". IfprintKeyistrue`, the key of each option is also written in parentheses, like in `"'apple' (1), 'orange' (7), 'banana' (2)"`.

Definition at line 438 of file SingleGen_module.cc.

References n, and util::flags::to_string().

441  {
442  std::string msg;
443 
444  unsigned int n = 0;
445  for (auto const& option: allowedOptions) {
446  auto const& key = option.first;
447  if (std::find(exclude.begin(), exclude.end(), key) != exclude.end())
448  continue;
449  if (n++ > 0) msg += ", ";
450  msg += '\"' + std::string(option.second) + '\"';
451  if (printKey)
452  msg += " (" + std::to_string(key) + ")";
453  } // for
454  return msg;
455  } // SingleGen::presentOptions()
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
Char_t n[5]
template<typename OptionList >
static std::string evgen::SingleGen::presentOptions ( OptionList const &  allowedOptions,
bool  printKey = true 
)
inlinestaticprivate

Definition at line 371 of file SingleGen_module.cc.

372  { return presentOptions(allowedOptions, printKey, {}); }
static std::string presentOptions(OptionList const &allowedOptions, bool printKey, std::initializer_list< typename OptionList::value_type::first_type > exclude)
Returns a string describing all options in the list.
void evgen::SingleGen::printVecs ( std::vector< std::string > const &  list)
private

Definition at line 1021 of file SingleGen_module.cc.

References e, fP0, fPDG, fSigmaP, fSigmaT, fSigmaThetaXZ, fSigmaThetaYZ, fSigmaX, fSigmaY, fSigmaZ, fT0, fTheta0XZ, fTheta0YZ, fX0, fY0, and fZ0.

Referenced by setup().

1022  {
1023 
1024  mf::LogInfo("SingleGen") << " You are using vector values for SingleGen configuration.\n "
1025  << " Some of the configuration vectors may have been padded out ,"
1026  << " because they (weren't) as long as the pdg vector"
1027  << " in your configuration. \n"
1028  << " The new input particle configuration is:\n" ;
1029 
1030  std::string values;
1031  for(size_t i = 0; i <=1; ++i){// list.size(); ++i){
1032 
1033  values.append(list[i]);
1034  values.append(": [ ");
1035 
1036  for(size_t e = 0; e < fPDG.size(); ++e){
1037  std::stringstream buf;
1038  buf.width(10);
1039  if(i == 0 ) buf << fPDG[e] << ", ";
1040  buf.precision(5);
1041  if(i == 1 ) buf << fP0[e] << ", ";
1042  if(i == 2 ) buf << fSigmaP[e] << ", ";
1043  if(i == 3 ) buf << fX0[e] << ", ";
1044  if(i == 4 ) buf << fY0[e] << ", ";
1045  if(i == 5 ) buf << fZ0[e] << ", ";
1046  if(i == 6 ) buf << fSigmaX[e] << ", ";
1047  if(i == 7 ) buf << fSigmaY[e] << ", ";
1048  if(i == 8 ) buf << fSigmaZ[e] << ", ";
1049  if(i == 9 ) buf << fTheta0XZ[e] << ", ";
1050  if(i == 10) buf << fTheta0YZ[e] << ", ";
1051  if(i == 11) buf << fSigmaThetaXZ[e] << ", ";
1052  if(i == 12) buf << fSigmaThetaYZ[e] << ", ";
1053  if(i == 13) buf << fT0[e] << ", ";
1054  if(i == 14) buf << fSigmaT[e] << ", ";
1055  values.append(buf.str());
1056  }
1057 
1058  values.erase(values.find_last_of(","));
1059  values.append(" ] \n");
1060 
1061  }// end loop over vector names in list
1062 
1063  mf::LogInfo("SingleGen") << values;
1064 
1065  return;
1066  }
std::vector< double > fSigmaT
Variation in t position (s)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< double > fSigmaZ
Variation in z position (cm)
std::vector< double > fT0
Central t position (s) in world coordinates.
std::vector< double > fP0
Central momentum (GeV/c) to generate.
std::vector< double > fTheta0YZ
Angle in YZ plane (degrees)
std::vector< double > fY0
Central y position (cm) in world coordinates.
std::vector< int > fPDG
PDG code of particles to generate.
std::vector< double > fSigmaThetaYZ
Variation in angle in YZ plane.
std::vector< double > fSigmaP
Variation in momenta (GeV/c)
std::vector< double > fZ0
Central z position (cm) in world coordinates.
std::vector< double > fSigmaX
Variation in x position (cm)
std::vector< double > fX0
Central x position (cm) in world coordinates.
std::vector< double > fTheta0XZ
Angle in XZ plane (degrees)
Float_t e
Definition: plot.C:34
std::vector< double > fSigmaThetaXZ
Variation in angle in XZ plane.
std::vector< double > fSigmaY
Variation in y position (cm)
void evgen::SingleGen::produce ( art::Event evt)
virtual

unique_ptr allows ownership to be transferred to the art::Event after the put statement

Implements art::EDProducer.

Definition at line 735 of file SingleGen_module.cc.

References simb::kSingleParticle, LOG_DEBUG, art::Event::put(), Sample(), and simb::MCTruth::SetOrigin().

736  {
737 
739  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
740 
741  simb::MCTruth truth;
743  Sample(truth);
744 
745  LOG_DEBUG("SingleGen") << truth;
746 
747  truthcol->push_back(truth);
748 
749  evt.put(std::move(truthcol));
750 
751  return;
752  }
void SetOrigin(simb::Origin_t origin)
Definition: MCTruth.h:78
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
single particles thrown at the detector
Definition: MCTruth.h:24
void Sample(simb::MCTruth &mct)
#define LOG_DEBUG(id)
Event generator information.
Definition: MCTruth.h:30
void evgen::SingleGen::Sample ( simb::MCTruth mct)
private

Definition at line 985 of file SingleGen_module.cc.

References fMode, fPDG, fSingleVertex, art::RandomNumberGenerator::getEngine(), art::EngineCreator::rng(), SampleMany(), and SampleOne().

Referenced by produce().

986  {
987 
988  switch (fMode) {
989  case 0: // List generation mode: every event will have one of each
990  // particle species in the fPDG array
991  if (fSingleVertex){
992  SampleMany(mct);
993  }
994  else{
995  for (unsigned int i=0; i<fPDG.size(); ++i) {
996  SampleOne(i,mct);
997  }//end loop over particles
998  }
999  break;
1000  case 1: // Random selection mode: every event will exactly one particle
1001  // selected randomly from the fPDG array
1002  {
1004  CLHEP::HepRandomEngine &engine = rng->getEngine();
1005  CLHEP::RandFlat flat(engine);
1006 
1007  unsigned int i=flat.fireInt(fPDG.size());
1008  SampleOne(i,mct);
1009  }
1010  break;
1011  default:
1012  mf::LogWarning("UnrecognizeOption") << "SingleGen does not recognize ParticleSelectionMode "
1013  << fMode;
1014  break;
1015  } // switch on fMode
1016 
1017  return;
1018  }
void SampleOne(unsigned int i, simb::MCTruth &mct)
bool fSingleVertex
if true - all particles produced at the same location
base_engine_t & getEngine() const
std::vector< int > fPDG
PDG code of particles to generate.
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void SampleMany(simb::MCTruth &mct)
void evgen::SingleGen::SampleMany ( simb::MCTruth mct)
private

Definition at line 871 of file SingleGen_module.cc.

References simb::MCTruth::Add(), simb::MCParticle::AddTrajectoryPoint(), fAngleDist, fP0, fPDG, fPDist, fPosDist, fSigmaP, fSigmaT, fSigmaThetaXZ, fSigmaThetaYZ, fSigmaX, fSigmaY, fSigmaZ, fT0, fTDist, fTheta0XZ, fTheta0YZ, fX0, fY0, fZ0, art::RandomNumberGenerator::getEngine(), hPHist, hThetaXzYzHist, kGAUS, kHIST, part, art::EngineCreator::rng(), SelectFromHist(), and x.

Referenced by Sample().

871  {
872 
873  // get the random number generator service and make some CLHEP generators
875  CLHEP::HepRandomEngine &engine = rng->getEngine();
876  CLHEP::RandFlat flat(engine);
877  CLHEP::RandGaussQ gauss(engine);
878 
879  // Choose position
880  TVector3 x;
881  if (fPosDist == kGAUS) {
882  x[0] = gauss.fire(fX0[0], fSigmaX[0]);;
883  x[1] = gauss.fire(fY0[0], fSigmaY[0]);
884  x[2] = gauss.fire(fZ0[0], fSigmaZ[0]);
885  }
886  else {
887  x[0] = fX0[0] + fSigmaX[0]*(2.0*flat.fire()-1.0);
888  x[1] = fY0[0] + fSigmaY[0]*(2.0*flat.fire()-1.0);
889  x[2] = fZ0[0] + fSigmaZ[0]*(2.0*flat.fire()-1.0);
890  }
891 
892  double t = 0.;
893  if(fTDist==kGAUS){
894  t = gauss.fire(fT0[0], fSigmaT[0]);
895  }
896  else{
897  t = fT0[0] + fSigmaT[0]*(2.0*flat.fire()-1.0);
898  }
899 
900  TLorentzVector pos(x[0], x[1], x[2], t);
901 
902  // loop through particles and select momenta and angles
903  for (unsigned int i(0); i<fPDG.size(); ++i){
904  // Choose momentum
905  double p = 0.0;
906  double m = 0.0;
907  if (fPDist == kGAUS) {
908  p = gauss.fire(fP0[i], fSigmaP[i]);
909  }
910  else if (fPDist == kHIST){
911  p = SelectFromHist(*(hPHist[i]));
912  }
913  else {
914  p = fP0[i] + fSigmaP[i]*(2.0*flat.fire()-1.0);
915  }
916 
917  static TDatabasePDG pdgt;
918  TParticlePDG* pdgp = pdgt.GetParticle(fPDG[i]);
919  if (pdgp) m = pdgp->Mass();
920 
921 
922  // Choose angles
923  double thxz = 0;
924  double thyz = 0;
925 
926  double thyzrads = 0;
927  double thyzradsplussigma = 0;
928  double thyzradsminussigma = 0;
929 
930  if (fAngleDist == kGAUS) {
931  thxz = gauss.fire(fTheta0XZ[i], fSigmaThetaXZ[i]);
932  thyz = gauss.fire(fTheta0YZ[i], fSigmaThetaYZ[i]);
933  }
934  else if (fAngleDist == kHIST){
935  double thetaxz = 0;
936  double thetayz = 0;
937  SelectFromHist(*(hThetaXzYzHist[i]), thetaxz, thetayz);
938  thxz = (180./M_PI)*thetaxz;
939  thyz = (180./M_PI)*thetayz;
940  }
941  else {
942 
943  // Choose angles flat in phase space, which is flat in theta_xz
944  // and flat in sin(theta_yz).
945 
946  thxz = fTheta0XZ[i] + fSigmaThetaXZ[i]*(2.0*flat.fire()-1.0);
947 
948  thyzrads = std::asin(std::sin((M_PI/180.)*(fTheta0YZ[i]))); //Taking asin of sin gives value between -Pi/2 and Pi/2 regardless of user input
949  thyzradsplussigma = TMath::Min((thyzrads + ((M_PI/180.)*fabs(fSigmaThetaYZ[i]))), M_PI/2.);
950  thyzradsminussigma = TMath::Max((thyzrads - ((M_PI/180.)*fabs(fSigmaThetaYZ[i]))), -M_PI/2.);
951 
952  //uncomment line to print angular variation info
953  //std::cout << "Central angle: " << (180./M_PI)*thyzrads << " Max angle: " << (180./M_PI)*thyzradsplussigma << " Min angle: " << (180./M_PI)*thyzradsminussigma << std::endl;
954 
955  double sinthyzmin = std::sin(thyzradsminussigma);
956  double sinthyzmax = std::sin(thyzradsplussigma);
957  double sinthyz = sinthyzmin + flat.fire() * (sinthyzmax - sinthyzmin);
958  thyz = (180. / M_PI) * std::asin(sinthyz);
959  }
960 
961  double thxzrad=thxz*M_PI/180.0;
962  double thyzrad=thyz*M_PI/180.0;
963 
964  TLorentzVector pvec(p*std::cos(thyzrad)*std::sin(thxzrad),
965  p*std::sin(thyzrad),
966  p*std::cos(thxzrad)*std::cos(thyzrad),
967  std::sqrt(p*p+m*m));
968 
969  // set track id to -i as these are all primary particles and have id <= 0
970  int trackid = -1*(i+1);
971  std::string primary("primary");
972 
973  simb::MCParticle part(trackid, fPDG[i], primary);
974  part.AddTrajectoryPoint(pos, pvec);
975 
976  //std::cout << "Px: " << pvec.Px() << " Py: " << pvec.Py() << " Pz: " << pvec.Pz() << std::endl;
977  //std::cout << "x: " << pos.X() << " y: " << pos.Y() << " z: " << pos.Z() << " time: " << pos.T() << std::endl;
978  //std::cout << "YZ Angle: " << (thyzrad * (180./M_PI)) << " XZ Angle: " << (thxzrad * (180./M_PI)) << std::endl;
979  mct.Add(part);
980  }
981  }
Float_t x
Definition: compare.C:6
int fPDist
How to distribute momenta (gaus or uniform)
int fTDist
How to distribute t (gaus, or uniform)
std::vector< std::unique_ptr< TH2 > > hThetaXzYzHist
actual TH1 for momentum distributions
std::vector< double > fSigmaT
Variation in t position (s)
std::vector< std::unique_ptr< TH1 > > hPHist
void Add(simb::MCParticle &part)
Definition: MCTruth.h:77
int fPosDist
How to distribute xyz (gaus, or uniform)
std::vector< double > fSigmaZ
Variation in z position (cm)
std::vector< double > fT0
Central t position (s) in world coordinates.
base_engine_t & getEngine() const
std::vector< double > fP0
Central momentum (GeV/c) to generate.
std::vector< double > fTheta0YZ
Angle in YZ plane (degrees)
TString part[npart]
Definition: Style.C:32
double SelectFromHist(const TH1 &h)
std::vector< double > fY0
Central y position (cm) in world coordinates.
std::vector< int > fPDG
PDG code of particles to generate.
std::vector< double > fSigmaThetaYZ
Variation in angle in YZ plane.
std::vector< double > fSigmaP
Variation in momenta (GeV/c)
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
std::vector< double > fZ0
Central z position (cm) in world coordinates.
std::vector< double > fSigmaX
Variation in x position (cm)
static constexpr int kGAUS
Gaussian distribution.
std::vector< double > fX0
Central x position (cm) in world coordinates.
int fAngleDist
How to distribute angles (gaus, uniform)
std::vector< double > fTheta0XZ
Angle in XZ plane (degrees)
static constexpr int kHIST
std::vector< double > fSigmaThetaXZ
Variation in angle in XZ plane.
std::vector< double > fSigmaY
Variation in y position (cm)
void evgen::SingleGen::SampleOne ( unsigned int  i,
simb::MCTruth mct 
)
private

Definition at line 757 of file SingleGen_module.cc.

References simb::MCTruth::Add(), simb::MCParticle::AddTrajectoryPoint(), fAngleDist, fP0, fPDG, fPDist, fPosDist, fSigmaP, fSigmaT, fSigmaThetaXZ, fSigmaThetaYZ, fSigmaX, fSigmaY, fSigmaZ, fT0, fTDist, fTheta0XZ, fTheta0YZ, fX0, fY0, fZ0, art::RandomNumberGenerator::getEngine(), hPHist, hThetaXzYzHist, kGAUS, kHIST, part, art::EngineCreator::rng(), SelectFromHist(), and x.

Referenced by Sample().

757  {
758 
759  // get the random number generator service and make some CLHEP generators
761  CLHEP::HepRandomEngine &engine = rng->getEngine();
762  CLHEP::RandFlat flat(engine);
763  CLHEP::RandGaussQ gauss(engine);
764 
765  // Choose momentum
766  double p = 0.0;
767  double m = 0.0;
768  if (fPDist == kGAUS) {
769  p = gauss.fire(fP0[i], fSigmaP[i]);
770  }
771  else if (fPDist == kHIST){
772  p = SelectFromHist(*(hPHist[i]));
773  }
774  else{// if (fPDist == kUNIF) {
775  p = fP0[i] + fSigmaP[i]*(2.0*flat.fire()-1.0);
776  }
777 // else {std::cout << "do not understand the value of PDist!";}
778 
779  static TDatabasePDG pdgt;
780  TParticlePDG* pdgp = pdgt.GetParticle(fPDG[i]);
781  if (pdgp) m = pdgp->Mass();
782 
783  // Choose position
784  TVector3 x;
785  if (fPosDist == kGAUS) {
786  x[0] = gauss.fire(fX0[i], fSigmaX[i]);;
787  x[1] = gauss.fire(fY0[i], fSigmaY[i]);
788  x[2] = gauss.fire(fZ0[i], fSigmaZ[i]);
789  }
790  else {
791  x[0] = fX0[i] + fSigmaX[i]*(2.0*flat.fire()-1.0);
792  x[1] = fY0[i] + fSigmaY[i]*(2.0*flat.fire()-1.0);
793  x[2] = fZ0[i] + fSigmaZ[i]*(2.0*flat.fire()-1.0);
794  }
795 
796  double t = 0.;
797  if(fTDist==kGAUS){
798  t = gauss.fire(fT0[i], fSigmaT[i]);
799  }
800  else{
801  t = fT0[i] + fSigmaT[i]*(2.0*flat.fire()-1.0);
802  }
803 
804  TLorentzVector pos(x[0], x[1], x[2], t);
805 
806  // Choose angles
807  double thxz = 0;
808  double thyz = 0;
809 
810  double thyzrads = 0;
811  double thyzradsplussigma = 0;
812  double thyzradsminussigma = 0;
813 
814  if (fAngleDist == kGAUS) {
815  thxz = gauss.fire(fTheta0XZ[i], fSigmaThetaXZ[i]);
816  thyz = gauss.fire(fTheta0YZ[i], fSigmaThetaYZ[i]);
817  }
818  else if (fAngleDist == kHIST){ // Select thetaxz and thetayz from histogram
819  double thetaxz = 0;
820  double thetayz = 0;
821  SelectFromHist(*(hThetaXzYzHist[i]), thetaxz, thetayz);
822  thxz = (180./M_PI)*thetaxz;
823  thyz = (180./M_PI)*thetayz;
824  }
825  else {
826 
827  // Choose angles flat in phase space, which is flat in theta_xz
828  // and flat in sin(theta_yz).
829 
830  thxz = fTheta0XZ[i] + fSigmaThetaXZ[i]*(2.0*flat.fire()-1.0);
831 
832  thyzrads = std::asin(std::sin((M_PI/180.)*(fTheta0YZ[i]))); //Taking asin of sin gives value between -Pi/2 and Pi/2 regardless of user input
833  thyzradsplussigma = TMath::Min((thyzrads + ((M_PI/180.)*fabs(fSigmaThetaYZ[i]))), M_PI/2.);
834  thyzradsminussigma = TMath::Max((thyzrads - ((M_PI/180.)*fabs(fSigmaThetaYZ[i]))), -M_PI/2.);
835 
836  //uncomment line to print angular variation info
837  //std::cout << "Central angle: " << (180./M_PI)*thyzrads << " Max angle: " << (180./M_PI)*thyzradsplussigma << " Min angle: " << (180./M_PI)*thyzradsminussigma << std::endl;
838 
839  double sinthyzmin = std::sin(thyzradsminussigma);
840  double sinthyzmax = std::sin(thyzradsplussigma);
841  double sinthyz = sinthyzmin + flat.fire() * (sinthyzmax - sinthyzmin);
842  thyz = (180. / M_PI) * std::asin(sinthyz);
843  }
844 
845  double thxzrad=thxz*M_PI/180.0;
846  double thyzrad=thyz*M_PI/180.0;
847 
848  TLorentzVector pvec(p*std::cos(thyzrad)*std::sin(thxzrad),
849  p*std::sin(thyzrad),
850  p*std::cos(thxzrad)*std::cos(thyzrad),
851  std::sqrt(p*p+m*m));
852 
853  // set track id to -i as these are all primary particles and have id <= 0
854  int trackid = -1*(i+1);
855  std::string primary("primary");
856 
857  simb::MCParticle part(trackid, fPDG[i], primary);
858  part.AddTrajectoryPoint(pos, pvec);
859 
860  //std::cout << "Px: " << pvec.Px() << " Py: " << pvec.Py() << " Pz: " << pvec.Pz() << std::endl;
861  //std::cout << "x: " << pos.X() << " y: " << pos.Y() << " z: " << pos.Z() << " time: " << pos.T() << std::endl;
862  //std::cout << "YZ Angle: " << (thyzrad * (180./M_PI)) << " XZ Angle: " << (thxzrad * (180./M_PI)) << std::endl;
863 
864  mct.Add(part);
865  }
Float_t x
Definition: compare.C:6
int fPDist
How to distribute momenta (gaus or uniform)
int fTDist
How to distribute t (gaus, or uniform)
std::vector< std::unique_ptr< TH2 > > hThetaXzYzHist
actual TH1 for momentum distributions
std::vector< double > fSigmaT
Variation in t position (s)
std::vector< std::unique_ptr< TH1 > > hPHist
void Add(simb::MCParticle &part)
Definition: MCTruth.h:77
int fPosDist
How to distribute xyz (gaus, or uniform)
std::vector< double > fSigmaZ
Variation in z position (cm)
std::vector< double > fT0
Central t position (s) in world coordinates.
base_engine_t & getEngine() const
std::vector< double > fP0
Central momentum (GeV/c) to generate.
std::vector< double > fTheta0YZ
Angle in YZ plane (degrees)
TString part[npart]
Definition: Style.C:32
double SelectFromHist(const TH1 &h)
std::vector< double > fY0
Central y position (cm) in world coordinates.
std::vector< int > fPDG
PDG code of particles to generate.
std::vector< double > fSigmaThetaYZ
Variation in angle in YZ plane.
std::vector< double > fSigmaP
Variation in momenta (GeV/c)
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
std::vector< double > fZ0
Central z position (cm) in world coordinates.
std::vector< double > fSigmaX
Variation in x position (cm)
static constexpr int kGAUS
Gaussian distribution.
std::vector< double > fX0
Central x position (cm) in world coordinates.
int fAngleDist
How to distribute angles (gaus, uniform)
std::vector< double > fTheta0XZ
Angle in XZ plane (degrees)
static constexpr int kHIST
std::vector< double > fSigmaThetaXZ
Variation in angle in XZ plane.
std::vector< double > fSigmaY
Variation in y position (cm)
double evgen::SingleGen::SelectFromHist ( const TH1 &  h)
private

Definition at line 1070 of file SingleGen_module.cc.

References art::RandomNumberGenerator::getEngine(), and art::EngineCreator::rng().

Referenced by SampleMany(), and SampleOne().

1071  {
1073  CLHEP::HepRandomEngine &engine = rng->getEngine();
1074  CLHEP::RandFlat flat(engine);
1075 
1076  double throw_value = h.Integral() * flat.fire();
1077  double cum_value(0);
1078  for (int i(0); i < h.GetNbinsX()+1; ++i){
1079  cum_value += h.GetBinContent(i);
1080  if (throw_value < cum_value){
1081  return flat.fire()*h.GetBinWidth(i) + h.GetBinLowEdge(i);
1082  }
1083  }
1084  return throw_value; // for some reason we've gone through all bins and failed?
1085  }
base_engine_t & getEngine() const
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
void evgen::SingleGen::SelectFromHist ( const TH2 &  h,
double &  x,
double &  y 
)
private

Definition at line 1087 of file SingleGen_module.cc.

References DEFINE_ART_MODULE, art::RandomNumberGenerator::getEngine(), and art::EngineCreator::rng().

1088  {
1090  CLHEP::HepRandomEngine &engine = rng->getEngine();
1091  CLHEP::RandFlat flat(engine);
1092 
1093  double throw_value = h.Integral() * flat.fire();
1094  double cum_value(0);
1095  for (int i(0); i < h.GetNbinsX()+1; ++i){
1096  for (int j(0); j < h.GetNbinsY()+1; ++j){
1097  cum_value += h.GetBinContent(i, j);
1098  if (throw_value < cum_value){
1099  x = flat.fire()*h.GetXaxis()->GetBinWidth(i) + h.GetXaxis()->GetBinLowEdge(i);
1100  y = flat.fire()*h.GetYaxis()->GetBinWidth(j) + h.GetYaxis()->GetBinLowEdge(j);
1101  return;
1102  }
1103  }
1104  }
1105  return; // for some reason we've gone through all bins and failed?
1106  }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
base_engine_t & getEngine() const
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
template<typename OptionList >
auto evgen::SingleGen::selectOption ( std::string  Option,
OptionList const &  allowedOptions 
) -> decltype(auto)
staticprivate

Parses an option string and returns the corresponding option number.

Template Parameters
OptionListtype of list of options (e.g. std::map<int, std::string>)
Parameters
Optionthe string of the option to be parsed
allowedOptionslist of valid options, as key/name pairs
Returns
the key of the Option string from allowedOptions
Exceptions
std::runtime_errorif Option is not in the option list

The option string Option represent a single one among the supported options as defined in allowedOptions. The option string can be either one of the option names (the matching is not case-sensitive) or the number of the option itself.

OptionList requirements

OptionList must behave like a sequence with forward iterators. Each element must behave as a pair, whose first element is the option key and the second element is the option name, equivalent to a string in that it must be forward-iterable and its elements can be converted by std::tolower(). The key type has no requirements beside being copiable.

Definition at line 411 of file SingleGen_module.cc.

References evd::details::end(), and s.

412  {
413  using key_type = typename OptionList::value_type::first_type;
414  using tolower_type = int(*)(int);
415  auto toLower = [](auto const& S)
416  {
417  std::string s;
418  s.reserve(S.size());
419  std::transform(S.cbegin(), S.cend(), std::back_inserter(s),
420  (tolower_type) &std::tolower);
421  return s;
422  };
423  auto option = toLower(Option);
424  for (auto const& candidate: allowedOptions) {
425  if (toLower(candidate.second) == option) return candidate.first;
426  }
427  try {
428  std::size_t end;
429  key_type num = std::stoi(Option, &end);
430  if (allowedOptions.count(num) && (end == Option.length())) return num;
431  }
432  catch (std::invalid_argument const&) {}
433  throw std::runtime_error("Option '" + Option + "' not supported.");
434  } // SingleGen::selectOption()
Float_t s
Definition: plot.C:23
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
void evgen::SingleGen::setup ( )
private

Performs checks and initialization based on the current configuration.

Definition at line 520 of file SingleGen_module.cc.

References art::errors::Configuration, DistributionNames, fAngleDist, fHistFileName, fP0, fPadOutVectors, fPDG, fPDist, fPHist, fPosDist, fSigmaP, fSigmaT, fSigmaThetaXZ, fSigmaThetaYZ, fSigmaX, fSigmaY, fSigmaZ, fT0, fTDist, fTheta0XZ, fTheta0YZ, fThetaXzYzHist, fX0, fY0, fZ0, hPHist, hThetaXzYzHist, kGAUS, kHIST, kUNIF, art::errors::NotFound, optionName(), PadVector(), printVecs(), and util::flags::to_string().

Referenced by SingleGen().

521  {
522  // do not put seed in reconfigure because we don't want to reset
523  // the seed midstream
524  std::vector<std::string> vlist(15);
525  vlist[0] = "PDG";
526  vlist[1] = "P0";
527  vlist[2] = "SigmaP";
528  vlist[3] = "X0";
529  vlist[4] = "Y0";
530  vlist[5] = "Z0";
531  vlist[6] = "SigmaX";
532  vlist[7] = "SigmaY";
533  vlist[8] = "SigmaZ";
534  vlist[9] = "Theta0XZ";
535  vlist[10] = "Theta0YZ";
536  vlist[11] = "SigmaThetaXZ";
537  vlist[12] = "SigmaThetaYZ";
538  vlist[13] = "T0";
539  vlist[14] = "SigmaT";
540 
541 // vlist[15] = "PHist";
542 // vlist[16] = "ThetaHist";
543 // vlist[17] = "PhiHist";
544 
545  // begin tests for multiple particle error possibilities
546  std::string list;
547  if (fPDist != kHIST) {
548  if( !this->PadVector(fP0 ) ){ list.append(vlist[1].append(", \n")); }
549  if( !this->PadVector(fSigmaP ) ){ list.append(vlist[2].append(", \n")); }
550  }
551  if( !this->PadVector(fX0 ) ){ list.append(vlist[3].append(", \n")); }
552  if( !this->PadVector(fY0 ) ){ list.append(vlist[4].append(", \n")); }
553  if( !this->PadVector(fZ0 ) ){ list.append(vlist[5].append(", \n")); }
554  if( !this->PadVector(fSigmaX ) ){ list.append(vlist[6].append(", \n")); }
555  if( !this->PadVector(fSigmaY ) ){ list.append(vlist[7].append(", \n")); }
556  if( !this->PadVector(fSigmaZ ) ){ list.append(vlist[8].append(", \n")); }
557  if( !this->PadVector(fTheta0XZ ) ){ list.append(vlist[9].append(", \n")); }
558  if( !this->PadVector(fTheta0YZ ) ){ list.append(vlist[10].append(", \n")); }
559  if( !this->PadVector(fSigmaThetaXZ) ){ list.append(vlist[11].append(", \n")); }
560  if( !this->PadVector(fSigmaThetaYZ) ){ list.append(vlist[12].append(" \n")); }
561  if( !this->PadVector(fT0 ) ){ list.append(vlist[13].append(", \n")); }
562  if( !this->PadVector(fSigmaT ) ){ list.append(vlist[14].append(", \n")); }
563 
564 
565 
566  if(list.size() > 0)
567  throw cet::exception("SingleGen") << "The "<< list
568  << "\n vector(s) defined in the fhicl files has/have "
569  << "a different size than the PDG vector "
570  << "\n and it has (they have) more than one value, "
571  << "\n disallowing sensible padding "
572  << " and/or you have set fPadOutVectors to false. \n";
573 
574  if(fPDG.size() > 1 && fPadOutVectors) this->printVecs(vlist);
575 
576  // If needed, get histograms for momentum and angle distributions
577  TFile* histFile = nullptr;
578  if (!fHistFileName.empty()) {
579  if (fHistFileName[0] == '/') {
580  // We have an absolute path, use given name exactly.
581  if (cet::file_exists(fHistFileName)) {
582  histFile = new TFile(fHistFileName.c_str());
583  if (!histFile || histFile->IsZombie() || !histFile->IsOpen()) {
584  delete histFile;
585  histFile = nullptr;
586  throw art::Exception(art::errors::NotFound) << "Cannot open ROOT file specified in parameter HistogramFile: \"" << fHistFileName << "\"";
587  }
588  }
589  else {
590  throw art::Exception(art::errors::NotFound) << "ROOT file specified in parameter HistogramFile: \"" << fHistFileName << "\" does not exist!";
591  }
592  }
593  else {
594  // We have a relative path, search starting from current directory.
595  std::string relative_filename{"./"};
596  relative_filename += fHistFileName;
597  if (cet::file_exists(relative_filename)) {
598  histFile = new TFile(relative_filename.c_str());
599  if (!histFile || histFile->IsZombie() || !histFile->IsOpen()) {
600  delete histFile;
601  histFile = nullptr;
602  throw art::Exception(art::errors::NotFound) << "Cannot open ROOT file found using relative path and originally specified in parameter HistogramFile: \"" << relative_filename << '"';
603  }
604  }
605  else {
606  cet::search_path sp{"FW_SEARCH_PATH"};
607  std::string found_filename;
608  auto found = sp.find_file(fHistFileName, found_filename);
609  if (!found) {
610  throw art::Exception(art::errors::NotFound) << "Cannot find ROOT file in current directory nor on FW_SEARCH_PATH specified in parameter HistogramFile: \"" << fHistFileName << '"';
611  }
612  histFile = new TFile(found_filename.c_str());
613  if (!histFile || histFile->IsZombie() || !histFile->IsOpen()) {
614  delete histFile;
615  histFile = nullptr;
616  throw art::Exception(art::errors::NotFound) << "Cannot open ROOT file found on FW_SEARCH_PATH and originally specified in parameter HistogramFile: \"" << found_filename << '"';
617  }
618  }
619  }
620  }
621 
622  //
623  // deal with position distribution
624  //
625  switch (fPosDist) {
626  case kGAUS: case kUNIF: break; // supported, no further action needed
627  default:
629  << "Position distribution of type '"
631  << "' (" << std::to_string(fPosDist) << ") is not supported.";
632  } // switch(fPosDist)
633 
634  //
635  // deal with time distribution
636  //
637  switch (fTDist) {
638  case kGAUS: case kUNIF: break; // supported, no further action needed
639  default:
641  << "Time distribution of type '"
643  << "' (" << std::to_string(fTDist) << ") is not supported.";
644  } // switch(fTDist)
645 
646  //
647  // deal with momentum distribution
648  //
649  switch (fPDist) {
650  case kHIST:
651  if (fPHist.size() != fPDG.size()) {
653  << fPHist.size() << " momentum histograms to describe " << fPDG.size() << " particle types...";
654  }
655  hPHist.reserve(fPHist.size());
656  for (auto const& histName: fPHist) {
657  TH1* pHist = dynamic_cast<TH1*>(histFile->Get(histName.c_str()));
658  if (!pHist) {
660  << "Failed to read momentum histogram '" << histName << "' from '" << histFile->GetPath() << "\'";
661  }
662  pHist->SetDirectory(nullptr); // make it independent of the input file
663  hPHist.emplace_back(pHist);
664  } // for
665  break;
666  default: // supported, no further action needed
667  break;
668  } // switch(fPDist)
669 
670  switch (fAngleDist) {
671  case kHIST:
672  if (fThetaXzYzHist.size() != fPDG.size()) {
674  << fThetaXzYzHist.size() << " direction histograms to describe " << fPDG.size() << " particle types...";
675  }
676  hThetaXzYzHist.reserve(fThetaXzYzHist.size());
677  for (auto const& histName: fThetaXzYzHist) {
678  TH2* pHist = dynamic_cast<TH2*>(histFile->Get(histName.c_str()));
679  if (!pHist) {
681  << "Failed to read direction histogram '" << histName << "' from '" << histFile->GetPath() << "\'";
682  }
683  pHist->SetDirectory(nullptr); // make it independent of the input file
684  hThetaXzYzHist.emplace_back(pHist);
685  } // for
686  default: // supported, no further action needed
687  break;
688  } // switch(fAngleDist)
689 
690  delete histFile;
691 
692  }
int fPDist
How to distribute momenta (gaus or uniform)
static const std::map< int, std::string > DistributionNames
Names of all distribution modes.
int fTDist
How to distribute t (gaus, or uniform)
bool PadVector(std::vector< double > &vec)
std::vector< std::unique_ptr< TH2 > > hThetaXzYzHist
actual TH1 for momentum distributions
std::vector< double > fSigmaT
Variation in t position (s)
std::vector< std::unique_ptr< TH1 > > hPHist
std::vector< std::string > fThetaXzYzHist
name of histogram for thetaxz/thetayz distribution
int fPosDist
How to distribute xyz (gaus, or uniform)
void printVecs(std::vector< std::string > const &list)
std::vector< double > fSigmaZ
Variation in z position (cm)
std::vector< double > fT0
Central t position (s) in world coordinates.
std::vector< double > fP0
Central momentum (GeV/c) to generate.
std::vector< double > fTheta0YZ
Angle in YZ plane (degrees)
std::vector< double > fY0
Central y position (cm) in world coordinates.
std::vector< int > fPDG
PDG code of particles to generate.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< double > fSigmaThetaYZ
Variation in angle in YZ plane.
std::vector< double > fSigmaP
Variation in momenta (GeV/c)
std::vector< double > fZ0
Central z position (cm) in world coordinates.
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
std::vector< std::string > fPHist
name of histogram of momenta
std::vector< double > fSigmaX
Variation in x position (cm)
static constexpr int kGAUS
Gaussian distribution.
std::vector< double > fX0
Central x position (cm) in world coordinates.
static std::string optionName(typename OptionList::value_type::first_type optionKey, OptionList const &allowedOptions, std::string defName="<unknown>")
Returns the name of the specified option key, or defName if not known.
std::string fHistFileName
Filename containing histogram of momenta.
int fAngleDist
How to distribute angles (gaus, uniform)
static constexpr int kUNIF
Uniform distribution.
std::vector< double > fTheta0XZ
Angle in XZ plane (degrees)
static constexpr int kHIST
std::vector< double > fSigmaThetaXZ
Variation in angle in XZ plane.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< double > fSigmaY
Variation in y position (cm)
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Definition at line 125 of file Consumer.cc.

Referenced by art::EDProducer::doEndJob(), art::EDFilter::doEndJob(), art::EDAnalyzer::doEndJob(), and art::RootOutput::endJob().

126 {
127  if (!moduleContext_)
128  return;
129 
130  // If none of the branches have missing consumes statements, exit early.
131  if (std::all_of(cbegin(missingConsumes_),
132  cend(missingConsumes_),
133  [](auto const& perBranch) { return perBranch.empty(); }))
134  return;
135 
136  constexpr cet::HorizontalRule rule{60};
137  mf::LogPrint log{"MTdiagnostics"};
138  log << '\n'
139  << rule('=') << '\n'
140  << "The following consumes (or mayConsume) statements are missing from\n"
141  << module_context(moduleDescription_) << '\n'
142  << rule('-') << '\n';
143 
144  cet::for_all_with_index(
145  missingConsumes_, [&log](std::size_t const i, auto const& perBranch) {
146  for (auto const& pi : perBranch) {
147  log << " "
148  << assemble_consumes_statement(static_cast<BranchType>(i), pi)
149  << '\n';
150  }
151  });
152  log << rule('=');
153 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139
void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Definition at line 101 of file Consumer.cc.

References art::errors::ProductRegistrationFailure.

103 {
104  // Early exits if consumes tracking has been disabled or if the
105  // consumed product is an allowed consumable.
106  if (!moduleContext_)
107  return;
108 
109  if (cet::binary_search_all(consumables_[bt], pi))
110  return;
111 
112  if (requireConsumes_) {
114  "Consumer: an error occurred during validation of a "
115  "retrieved product\n\n")
116  << "The following consumes (or mayConsume) statement is missing from\n"
117  << module_context(moduleDescription_) << ":\n\n"
118  << " " << assemble_consumes_statement(bt, pi) << "\n\n";
119  }
120 
121  missingConsumes_[bt].insert(pi);
122 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
bool requireConsumes_
Definition: Consumer.h:137
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139

Member Data Documentation

const std::map< int, std::string > evgen::SingleGen::DistributionNames = SingleGen::makeDistributionNames()
staticprivate

Names of all distribution modes.

Definition at line 248 of file SingleGen_module.cc.

Referenced by setup().

int evgen::SingleGen::fAngleDist
private

How to distribute angles (gaus, uniform)

Definition at line 300 of file SingleGen_module.cc.

Referenced by SampleMany(), SampleOne(), and setup().

std::string evgen::SingleGen::fHistFileName
private

Filename containing histogram of momenta.

Definition at line 301 of file SingleGen_module.cc.

Referenced by setup().

int evgen::SingleGen::fMode
private

Particle Selection Mode 0–generate a list of all particles, 1–generate a single particle selected randomly from the list

Definition at line 274 of file SingleGen_module.cc.

Referenced by Sample().

std::vector<double> evgen::SingleGen::fP0
private

Central momentum (GeV/c) to generate.

Definition at line 282 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

bool evgen::SingleGen::fPadOutVectors
private

Select to pad out configuration vectors if they are not of of the same length as PDG false: don't pad out - all values need to specified true: pad out - default values assumed and printed out

Definition at line 277 of file SingleGen_module.cc.

Referenced by PadVector(), and setup().

std::vector<int> evgen::SingleGen::fPDG
private

PDG code of particles to generate.

Definition at line 281 of file SingleGen_module.cc.

Referenced by PadVector(), printVecs(), Sample(), SampleMany(), SampleOne(), and setup().

int evgen::SingleGen::fPDist
private

How to distribute momenta (gaus or uniform)

Definition at line 284 of file SingleGen_module.cc.

Referenced by SampleMany(), SampleOne(), and setup().

std::vector<std::string> evgen::SingleGen::fPHist
private

name of histogram of momenta

Definition at line 302 of file SingleGen_module.cc.

Referenced by setup().

int evgen::SingleGen::fPosDist
private

How to distribute xyz (gaus, or uniform)

Definition at line 293 of file SingleGen_module.cc.

Referenced by SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fSigmaP
private

Variation in momenta (GeV/c)

Definition at line 283 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fSigmaT
private

Variation in t position (s)

Definition at line 292 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fSigmaThetaXZ
private

Variation in angle in XZ plane.

Definition at line 298 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fSigmaThetaYZ
private

Variation in angle in YZ plane.

Definition at line 299 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fSigmaX
private

Variation in x position (cm)

Definition at line 289 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fSigmaY
private

Variation in y position (cm)

Definition at line 290 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fSigmaZ
private

Variation in z position (cm)

Definition at line 291 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

bool evgen::SingleGen::fSingleVertex
private

if true - all particles produced at the same location

Definition at line 295 of file SingleGen_module.cc.

Referenced by Sample().

std::vector<double> evgen::SingleGen::fT0
private

Central t position (s) in world coordinates.

Definition at line 288 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

int evgen::SingleGen::fTDist
private

How to distribute t (gaus, or uniform)

Definition at line 294 of file SingleGen_module.cc.

Referenced by SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fTheta0XZ
private

Angle in XZ plane (degrees)

Definition at line 296 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fTheta0YZ
private

Angle in YZ plane (degrees)

Definition at line 297 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<std::string> evgen::SingleGen::fThetaXzYzHist
private

name of histogram for thetaxz/thetayz distribution

Definition at line 304 of file SingleGen_module.cc.

Referenced by setup().

std::vector<double> evgen::SingleGen::fX0
private

Central x position (cm) in world coordinates.

Definition at line 285 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fY0
private

Central y position (cm) in world coordinates.

Definition at line 286 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<double> evgen::SingleGen::fZ0
private

Central z position (cm) in world coordinates.

Definition at line 287 of file SingleGen_module.cc.

Referenced by printVecs(), SampleMany(), SampleOne(), and setup().

std::vector<std::unique_ptr<TH1> > evgen::SingleGen::hPHist
private

Definition at line 306 of file SingleGen_module.cc.

Referenced by SampleMany(), SampleOne(), and setup().

std::vector<std::unique_ptr<TH2> > evgen::SingleGen::hThetaXzYzHist
private

actual TH1 for momentum distributions

Definition at line 308 of file SingleGen_module.cc.

Referenced by SampleMany(), SampleOne(), and setup().

constexpr int evgen::SingleGen::kGAUS = 1
staticprivate

Gaussian distribution.

Definition at line 270 of file SingleGen_module.cc.

Referenced by SampleMany(), SampleOne(), and setup().

constexpr int evgen::SingleGen::kHIST = 2
staticprivate

Distribution from histograms.

Definition at line 271 of file SingleGen_module.cc.

Referenced by SampleMany(), SampleOne(), and setup().

constexpr int evgen::SingleGen::kSelectAllParts = 0
staticprivate

One particle per entry is generated.

Definition at line 262 of file SingleGen_module.cc.

constexpr int evgen::SingleGen::kSelectOneRandPart = 1
staticprivate

One particle is generated, extracted from the provided options.

Definition at line 263 of file SingleGen_module.cc.

constexpr int evgen::SingleGen::kUNIF = 0
staticprivate

Uniform distribution.

Definition at line 269 of file SingleGen_module.cc.

Referenced by setup().

const std::map< int, std::string > evgen::SingleGen::ParticleSelectionModeNames = SingleGen::makeParticleSelectionModeNames()
staticprivate

Names of all particle selection modes.

Definition at line 246 of file SingleGen_module.cc.


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