LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
evgen::LightSource Class Reference

A module for optical MC testing and library building. More...

Inheritance diagram for evgen::LightSource:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Classes

class  MaterialPointFilter
 Filters a point according to the material at that point. More...
 

Public Types

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

Public Member Functions

 LightSource (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt)
 
void beginRun (art::Run &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

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 ()
 

Private Member Functions

simb::MCTruth Sample ()
 
void checkMaterials () const
 Throws an exception if any of the configured materials is not present. More...
 
bool readParametersFromInputFile ()
 

Private Attributes

std::string fVersion
 
std::ifstream fInputFile
 
std::string fFileName
 
char fDummyString [256]
 
TTree * fPhotonsGenerated
 
TLorentzVector fShotPos
 
TLorentzVector fShotMom
 
Int_t fEvID
 
int fSourceMode
 
bool fFillTree
 
int fPosDist
 
int fTDist
 
int fPDist
 
std::set< std::string > const fSelectedMaterials
 Names of materials to consider scintillation from. More...
 
int fXSteps
 
int fYSteps
 
int fZSteps
 
sim::PhotonVoxelDef fThePhotonVoxelDef
 
int fVoxelCount
 
int fCurrentVoxel
 
geo::Vector_t fTPCCenter
 
std::vector< double > fRegionMin
 
std::vector< double > fRegionMax
 
bool fUseCustomRegion
 
geo::Point_t fCenter
 Central position of source [cm]. More...
 
bool fPointSource
 
double fT
 
double fSigmaX
 
double fSigmaY
 
double fSigmaZ
 
double fSigmaT
 
double fP
 
double fSigmaP
 
int fN
 
double const fNMaxF
 Maximum number of attempted samplings (factor on top of fN). More...
 
int fFirstVoxel
 
int fLastVoxel
 
CLHEP::HepRandomEngine & fEngine
 
geo::GeometryCore const & fGeom
 Geometry service provider (cached). More...
 

Static Private Attributes

static const int kUNIF = 0
 
static const int kGAUS = 1
 
static const int kFILE = 0
 
static const int kSCAN = 1
 

Detailed Description

A module for optical MC testing and library building.

Light source event generator which simulate an extended isotropic photon source.

The light source can be run in two modes, file mode or scan mode. Each requires the specification of a different set of parameters.

File mode

Light source position, intensity and shape are supplied on an event by event basis in a text file. See the example provided for the format. Pararmeters required:

int32   SourceMode = 0      - sets light source to file mode
string  FileName            - file of per event light source specifications
int32   PosDist             - how to distribute production points sampled in momentum, position
int32   PDist                   and time ranges specified.  For all of these :
int32   TDist                   0 = uniform and 1 = gauss
bool    FillTree            - whether to write a tree of photon production points to fileservice

Upon reaching the end of the file, the light source will loop back to the first point. hence a one line text file will give a constant light source size, position and intensity.

Scan mode

Divide volume into cuboidal regions and produce an isotropic light source in each, using one region per event. User can specify either to use the full detector volume or some custom specified volume.

This mode is used when building a fast photon sim library, and performing volume scan sensitivity studies.

int32   SourceMode = 1      - sets light source to scan mode
int32   N                   - number of photons to shoot from each point
double  P                   - peak photon momentum (or energy) in eV
double  SigmaP              - momentum distribution width
double  XSteps              - Number of regions to divide volume into in each direction
double  YSteps
double  ZSteps
double  T0                  - Peak time of photon production
double  SigmaT              - time distribution width
int32   PosDist             - how to distribute production points sampled in momentum, position
int32   PDist                 and time ranges specified.  For all of these :
int32   TDist                   0 = uniform and 1 = gaussian
bool    FillTree            - whether to write a tree of photon production points to fileservice
bool    UseCustomRegion     - supply our own volume specification or use the full detector volume?
vdouble[3]  RegionMin       - bounding corners of the custom volume specification
vdouble[3]  RegionMax           (only used if UseCustomRegion=true)

Configuration parameters

This is a partial list of the supported configuration parameters:

  • SelectMaterials (list of strings, default: empty): if specified, generation points are required to be in a volume with any of the materials included in this list; a useful value is SelectMaterials: [ "LAr" ], which generates photons only in liquid argon; the rest of the constraints are also respected (that means that if the configured generation volume has none of the selected materials, generation can go on forever: see NMaxFactor configuration parameter)
  • NMaxFactor (real value, default: 100 times N): as a safety valve, do not attempt more than this times the requested number of photons: for example, in an event where 500 photons are required, with NMax: 20 no more than 10000 generations will be attempted; this is useful if the generation volume efficiency can't be guaranteed to be high (e.g. if only generation in liquid argon is requested in a generation volume that is entirely made of steel).

Definition at line 131 of file LightSource_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::LightSource::LightSource ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 264 of file LightSource_module.cc.

References checkMaterials(), art::detail::EngineCreator::createEngine(), fCurrentVoxel, fDummyString, fEngine, fEvID, fFileName, fFillTree, fFirstVoxel, fGeom, fInputFile, fLastVoxel, fN, fNMaxF, fP, fPDist, fPhotonsGenerated, fPointSource, fPosDist, fRegionMax, fRegionMin, fSelectedMaterials, fShotMom, fShotPos, fSigmaP, fSigmaT, fSigmaX, fSigmaY, fSigmaZ, fSourceMode, fT, fTDist, fThePhotonVoxelDef, fUseCustomRegion, fVoxelCount, fXSteps, fYSteps, fZSteps, sim::PhotonVoxelDef::GetNVoxels(), phot::PhotonVisibilityService::GetVoxelDef(), sim::PhotonVoxelDef::GetVoxelSize(), kFILE, and kSCAN.

265  : art::EDProducer{pset}
266  , fSourceMode{pset.get<int>("SourceMode")}
267  , fFillTree{pset.get<bool>("FillTree")}
268  , fPosDist{pset.get<int>("PosDist")}
269  , fTDist{pset.get<int>("TDist")}
270  , fPDist{pset.get<int>("PDist")}
271  , fSelectedMaterials{makeSet(pset.get<std::vector<std::string>>("SelectMaterials", {}))}
272  , fNMaxF{pset.get<double>("NMaxFactor", 100.0)}
273  // create a default random engine; obtain the random seed from NuRandomService,
274  // unless overridden in configuration with key "Seed"
275  , fEngine(art::ServiceHandle<rndm::NuRandomService>()->registerAndSeedEngine(createEngine(0),
276  pset,
277  "Seed"))
278  , fGeom(*lar::providerFrom<geo::Geometry const>())
279  {
280 
281  checkMaterials();
282 
283  // load optional parameters in function
284  produces<sumdata::RunData, art::InRun>();
285  produces<std::vector<simb::MCTruth>>();
286 
287  if (fSourceMode == kFILE) {
288  fFileName = pset.get<std::string>("SteeringFile");
289  fInputFile.open(fFileName.c_str());
290  fInputFile.getline(fDummyString, 256);
291  }
292  else if (fSourceMode == kSCAN) {
293  fT = pset.get<double>("T0");
294  fSigmaT = pset.get<double>("SigmaT");
295  fN = pset.get<int>("N");
296 
297  fFirstVoxel = pset.get<int>("FirstVoxel");
298  fLastVoxel = pset.get<int>("LastVoxel");
299 
300  fP = pset.get<double>("P");
301  fSigmaP = pset.get<double>("SigmaP");
302 
303  fUseCustomRegion = pset.get<bool>("UseCustomRegion");
304  fPointSource = pset.get<bool>("PointSource", false);
305 
306  if (fUseCustomRegion) {
307  fRegionMin = pset.get<std::vector<double>>("RegionMin");
308  fRegionMax = pset.get<std::vector<double>>("RegionMax");
309  fXSteps = pset.get<int>("XSteps");
310  fYSteps = pset.get<int>("YSteps");
311  fZSteps = pset.get<int>("ZSteps");
312  }
313 
314  // get TPC dimensions removed. -TA
315 
316  fCurrentVoxel = 0;
317 
318  // define voxelization based on parameters read from config.
319  // There are two modes - either read the dimensions of the TPC from
320  // the geometry, or use values specified by the user.
321  if (!fUseCustomRegion) {
324  }
325  else {
327  fRegionMax[0],
328  fXSteps,
329  fRegionMin[1],
330  fRegionMax[1],
331  fYSteps,
332  fRegionMin[2],
333  fRegionMax[2],
334  fZSteps);
335  }
336 
337  // Set distribution widths to voxel size
338 
342 
343  // Get number of voxels we will step through
344 
346 
347  if (fLastVoxel < 0) fLastVoxel = fVoxelCount;
348 
349  mf::LogVerbatim("LightSource") << "Light Source : Determining voxel params : " << fVoxelCount
350  << " " << fSigmaX << " " << fSigmaY << " " << fSigmaZ;
351  }
352  else {
353  throw cet::exception("LightSource")
354  << "EVGEN Light Source : Unrecognised light source mode\n";
355  }
356 
357  if (fFillTree) {
359  fPhotonsGenerated = tfs->make<TTree>("PhotonsGenerated", "PhotonsGenerated");
360  fPhotonsGenerated->Branch("X", &(fShotPos[0]), "X/D");
361  fPhotonsGenerated->Branch("Y", &(fShotPos[1]), "Y/D");
362  fPhotonsGenerated->Branch("Z", &(fShotPos[2]), "Z/D");
363  fPhotonsGenerated->Branch("T", &(fShotPos[3]), "T/D");
364  fPhotonsGenerated->Branch("PX", &(fShotMom[0]), "PX/D");
365  fPhotonsGenerated->Branch("PY", &(fShotMom[1]), "PY/D");
366  fPhotonsGenerated->Branch("PZ", &(fShotMom[2]), "PZ/D");
367  fPhotonsGenerated->Branch("PT", &(fShotMom[3]), "PT/D");
368  fPhotonsGenerated->Branch("EventID", &fEvID, "EventID/I");
369  }
370  }
std::vector< double > fRegionMin
base_engine_t & createEngine(seed_t seed)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
geo::GeometryCore const & fGeom
Geometry service provider (cached).
Vector GetVoxelSize() const
Returns a vector describing the span of a single voxel in x, y an z [cm].
Definition: PhotonVoxels.h:208
static const int kSCAN
Representation of a region of space diced into voxels.
Definition: PhotonVoxels.h:58
std::vector< double > fRegionMax
double const fNMaxF
Maximum number of attempted samplings (factor on top of fN).
void checkMaterials() const
Throws an exception if any of the configured materials is not present.
CLHEP::HepRandomEngine & fEngine
sim::PhotonVoxelDef fThePhotonVoxelDef
const sim::PhotonVoxelDef & GetVoxelDef() const
static const int kFILE
unsigned int GetNVoxels() const
Returns the total number of voxels in the volume.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::set< std::string > const fSelectedMaterials
Names of materials to consider scintillation from.

Member Function Documentation

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

Reimplemented from art::EDProducer.

Definition at line 373 of file LightSource_module.cc.

References geo::GeometryCore::DetectorName(), fCurrentVoxel, fFirstVoxel, fGeom, art::fullRun(), and art::Run::put().

374  {
375  run.put(std::make_unique<sumdata::RunData>(fGeom.DetectorName()), art::fullRun());
376 
378  }
constexpr auto fullRun()
geo::GeometryCore const & fGeom
Geometry service provider (cached).
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Run.h:121
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
Definition: GeometryCore.h:203
void evgen::LightSource::checkMaterials ( ) const
private

Throws an exception if any of the configured materials is not present.

Definition at line 541 of file LightSource_module.cc.

References art::errors::Configuration, e, fGeom, fSelectedMaterials, mat, and geo::GeometryCore::ROOTGeoManager().

Referenced by LightSource().

542  {
543 
544  TGeoManager const& manager = *(fGeom.ROOTGeoManager());
545 
546  { // start scope
547  mf::LogDebug log("LightSource");
548  auto const& matList = *(manager.GetListOfMaterials());
549  log << matList.GetSize() << " elements/materials in the geometry:";
550  for (auto const* obj : matList) {
551  auto const mat = dynamic_cast<TGeoMaterial const*>(obj);
552  log << "\n '" << mat->GetName() << "' (Z=" << mat->GetZ() << " A=" << mat->GetA() << ")";
553  } // for
554  } // end scope
555 
556  std::set<std::string> missingMaterials;
557  for (auto const& matName : fSelectedMaterials) {
558  if (!manager.GetMaterial(matName.c_str())) missingMaterials.insert(matName);
559  }
560  if (missingMaterials.empty()) return;
561 
563  e << "Requested filtering on " << missingMaterials.size()
564  << " materials which are not present in the geometry:";
565  for (auto const& matName : missingMaterials)
566  e << "\n '" << matName << "'";
567  throw e << "\n";
568 
569  } // LightSource::checkMaterials()
geo::GeometryCore const & fGeom
Geometry service provider (cached).
TGeoManager * ROOTGeoManager() const
Access to the ROOT geometry description manager.
Float_t mat
Definition: plot.C:38
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Float_t e
Definition: plot.C:35
std::set< std::string > const fSelectedMaterials
Names of materials to consider scintillation from.
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 &)
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 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
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::LightSource::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 381 of file LightSource_module.cc.

References e, fCenter, fCurrentVoxel, fDummyString, fFileName, fFirstVoxel, fInputFile, fLastVoxel, fSigmaX, fSigmaY, fSigmaZ, fSourceMode, fThePhotonVoxelDef, sim::PhotonVoxel::GetCenter(), sim::PhotonVoxelDef::GetPhotonVoxel(), phot::PhotonVisibilityService::IsBuildJob(), kFILE, kSCAN, art::Event::put(), readParametersFromInputFile(), Sample(), art::errors::ServiceNotFound, and phot::PhotonVisibilityService::StoreLightProd().

382  {
383  if (fSourceMode == kFILE) {
384  // Each event, read coordinates of gun and number of photons to shoot from file
385 
386  // read in one line
388  // Loop file if required
389  mf::LogWarning("LightSource") << "EVGEN Light Source : Warning, reached end of file,"
390  << " looping back to beginning";
391  fInputFile.clear();
392  fInputFile.seekg(0, std::ios::beg);
393  fInputFile.getline(fDummyString, 256);
394 
396  throw cet::exception("LightSource")
397  << "EVGEN Light Source : File error in " << fFileName << "\n";
398  }
399  }
400 
402  fCenter.X() + fSigmaX,
403  1,
404  fCenter.Y() - fSigmaY,
405  fCenter.Y() + fSigmaY,
406  1,
407  fCenter.Z() - fSigmaZ,
408  fCenter.Z() + fSigmaZ,
409  1);
410 
411  fCurrentVoxel = 0;
412  }
413  else if (fSourceMode == kSCAN) {
414  // Step through detector using a number of steps provided in the config file
415  // firing a constant number of photons from each point
417  }
418  else {
419  // Neither file or scan mode, probably a config file error
420  throw cet::exception("LightSource") << "EVGEN : Light Source, unrecognised source mode\n";
421  }
422 
423  auto truthcol = std::make_unique<std::vector<simb::MCTruth>>();
424 
425  truthcol->push_back(Sample());
426  int const nPhotons = truthcol->back().NParticles();
427 
428  evt.put(std::move(truthcol));
429 
430  phot::PhotonVisibilityService* vis = nullptr;
431  try {
433  }
434  catch (art::Exception const& e) {
435  // if the service is not configured, then this is not a build job
436  // (it is a simple generation job instead)
437  if (e.categoryCode() != art::errors::ServiceNotFound) throw;
438  }
439 
440  if (vis && vis->IsBuildJob()) {
441  mf::LogVerbatim("LightSource") << "Light source : Stowing voxel params ";
442  vis->StoreLightProd(fCurrentVoxel, nPhotons);
443  }
444 
445  if (fCurrentVoxel != fLastVoxel) { ++fCurrentVoxel; }
446  else {
447  mf::LogVerbatim("LightSource")
448  << "EVGEN Light Source fully scanned detector. Starting over.";
450  }
451  }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
static const int kSCAN
Representation of a region of space diced into voxels.
Definition: PhotonVoxels.h:58
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
void StoreLightProd(int VoxID, double N)
simb::MCTruth Sample()
sim::PhotonVoxelDef fThePhotonVoxelDef
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
geo::Point_t fCenter
Central position of source [cm].
Point GetCenter() const
Returns the center of the voxel (type Point).
Definition: PhotonVoxels.h:186
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
static const int kFILE
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
PhotonVoxel GetPhotonVoxel(int ID) const
bool evgen::LightSource::readParametersFromInputFile ( )
private

Reads from fInputFile all other parameters in one line.

Returns
whether all reading were successful (ifstream::good()).

Definition at line 609 of file LightSource_module.cc.

References DEFINE_ART_MODULE, fCenter, fInputFile, fN, fP, fSigmaP, fSigmaT, fSigmaX, fSigmaY, fSigmaZ, fT, x, y, and z.

Referenced by produce().

610  {
611  double x, y, z;
612  fInputFile >> x >> y >> z >> fT >> fSigmaX >> fSigmaY >> fSigmaZ >> fSigmaT >> fP >> fSigmaP >>
613  fN;
614  fCenter = {x, y, z};
615  if (!fInputFile.good()) return false;
616 
617  std::string dummy;
618  std::getline(fInputFile, dummy); // this can fail for what I care
619  return true;
620  } // LightSource::readParametersFromInputFile()
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
geo::Point_t fCenter
Central position of source [cm].
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
simb::MCTruth evgen::LightSource::Sample ( )
private

Definition at line 453 of file LightSource_module.cc.

References evgen::LightSource::MaterialPointFilter::accept(), simb::MCTruth::Add(), simb::MCParticle::AddTrajectoryPoint(), e, fCenter, fEngine, fFillTree, fGeom, fN, fNMaxF, fP, fPDist, fPhotonsGenerated, fPointSource, fPosDist, fSelectedMaterials, fShotMom, fShotPos, fSigmaP, fSigmaT, fSigmaX, fSigmaY, fSigmaZ, fT, fTDist, kGAUS, simb::kSingleParticle, simb::MCTruth::NParticles(), part, simb::MCTruth::SetOrigin(), and x.

Referenced by produce().

454  {
455  mf::LogVerbatim("LightSource") << "Light source debug : Shooting at " << fCenter;
456 
457  CLHEP::RandFlat flat(fEngine, -1.0, 1.0);
458  CLHEP::RandGaussQ gauss(fEngine);
459 
460  MaterialPointFilter filter(fGeom, fSelectedMaterials);
461 
462  simb::MCTruth mct;
464 
465  unsigned long long int const nMax = static_cast<unsigned long long int>(double(fN) * fNMaxF);
466  unsigned long long int fired = 0ULL;
467  while (mct.NParticles() < fN) {
468  if (fired >= nMax) break;
469 
470  // Choose momentum (supplied in eV, convert to GeV)
471  double const p =
472  1e-9 * ((fPDist == kGAUS) ? gauss.fire(fP, fSigmaP) : fP + fSigmaP * flat.fire());
473 
474  // Choose position
475  ++fired;
476  geo::Point_t x;
477  if (fPointSource) { x = fCenter; }
478  else {
479  if (fPosDist == kGAUS) {
480  x = {gauss.fire(fCenter.X(), fSigmaX),
481  gauss.fire(fCenter.Y(), fSigmaY),
482  gauss.fire(fCenter.Z(), fSigmaZ)};
483  }
484  else {
485  x = {fCenter.X() + fSigmaX * flat.fire(),
486  fCenter.Y() + fSigmaY * flat.fire(),
487  fCenter.Z() + fSigmaZ * flat.fire()};
488  }
489 
490  if (!filter.accept(x)) continue;
491  }
492 
493  // Choose time
494  double t;
495  if (fTDist == kGAUS) { t = gauss.fire(fT, fSigmaT); }
496  else {
497  t = fT + fSigmaT * flat.fire();
498  }
499 
500  //assume the position is relative to the center of the TPC
501  //x += fTPCCenter;
502 
503  fShotPos = TLorentzVector(x.X(), x.Y(), x.Z(), t);
504 
505  // Choose angles
506  double costh = flat.fire();
507  double sinth = std::sqrt(1.0 - cet::square(costh));
508  double phi = 2 * M_PI * flat.fire();
509 
510  // Generate momentum 4-vector
511 
512  fShotMom = TLorentzVector(p * sinth * cos(phi), p * sinth * sin(phi), p * costh, p);
513 
514  int trackid = -(mct.NParticles() +
515  1); // set track id to -i as these are all primary particles and have id <= 0
516  std::string primary("primary");
517  int PDG = 0; //optical photons have PDG 0
518 
519  simb::MCParticle part(trackid, PDG, primary);
520  part.AddTrajectoryPoint(fShotPos, fShotMom);
521 
522  if (fFillTree) fPhotonsGenerated->Fill();
523 
524  mct.Add(part);
525  }
526 
527  mf::LogInfo("LightSource") << "Generated " << mct.NParticles() << " photons after " << fired
528  << " tries.";
529  if (mct.NParticles() < fN) {
530  // this may mean `NMaxFactor` is too small, or the volume is wrong;
531  // or it may be just expected
532  mf::LogWarning("LightSource")
533  << "Warning: " << mct.NParticles() << " photons generated after " << fired << " tries, but "
534  << fN << " were requested.";
535  }
536 
537  return mct;
538  } // LightSource::Sample()
Float_t x
Definition: compare.C:6
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
geo::GeometryCore const & fGeom
Geometry service provider (cached).
void SetOrigin(simb::Origin_t origin)
Definition: MCTruth.h:82
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
static const int kGAUS
int NParticles() const
Definition: MCTruth.h:75
double const fNMaxF
Maximum number of attempted samplings (factor on top of fN).
Framework includes.
CLHEP::HepRandomEngine & fEngine
TString part[npart]
Definition: Style.C:32
single particles thrown at the detector
Definition: MCTruth.h:26
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
void Add(simb::MCParticle const &part)
Definition: MCTruth.h:80
geo::Point_t fCenter
Central position of source [cm].
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Event generator information.
Definition: MCTruth.h:32
Float_t e
Definition: plot.C:35
std::set< std::string > const fSelectedMaterials
Names of materials to consider scintillation from.
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

geo::Point_t evgen::LightSource::fCenter
private

Central position of source [cm].

Definition at line 226 of file LightSource_module.cc.

Referenced by produce(), readParametersFromInputFile(), and Sample().

int evgen::LightSource::fCurrentVoxel
private

Definition at line 217 of file LightSource_module.cc.

Referenced by beginRun(), LightSource(), and produce().

char evgen::LightSource::fDummyString[256]
private

Definition at line 191 of file LightSource_module.cc.

Referenced by LightSource(), and produce().

CLHEP::HepRandomEngine& evgen::LightSource::fEngine
private

Definition at line 245 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

Int_t evgen::LightSource::fEvID
private

Definition at line 197 of file LightSource_module.cc.

Referenced by LightSource().

std::string evgen::LightSource::fFileName
private

Definition at line 190 of file LightSource_module.cc.

Referenced by LightSource(), and produce().

bool evgen::LightSource::fFillTree
private

Definition at line 201 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

int evgen::LightSource::fFirstVoxel
private

Definition at line 242 of file LightSource_module.cc.

Referenced by beginRun(), LightSource(), and produce().

geo::GeometryCore const& evgen::LightSource::fGeom
private

Geometry service provider (cached).

Definition at line 246 of file LightSource_module.cc.

Referenced by beginRun(), checkMaterials(), LightSource(), and Sample().

std::ifstream evgen::LightSource::fInputFile
private

Definition at line 189 of file LightSource_module.cc.

Referenced by LightSource(), produce(), and readParametersFromInputFile().

int evgen::LightSource::fLastVoxel
private

Definition at line 243 of file LightSource_module.cc.

Referenced by LightSource(), and produce().

int evgen::LightSource::fN
private

Definition at line 237 of file LightSource_module.cc.

Referenced by LightSource(), readParametersFromInputFile(), and Sample().

double const evgen::LightSource::fNMaxF
private

Maximum number of attempted samplings (factor on top of fN).

Definition at line 240 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

double evgen::LightSource::fP
private

Definition at line 233 of file LightSource_module.cc.

Referenced by LightSource(), readParametersFromInputFile(), and Sample().

int evgen::LightSource::fPDist
private

Definition at line 204 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

TTree* evgen::LightSource::fPhotonsGenerated
private

Definition at line 194 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

bool evgen::LightSource::fPointSource
private

Definition at line 227 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

int evgen::LightSource::fPosDist
private

Definition at line 202 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

std::vector<double> evgen::LightSource::fRegionMax
private

Definition at line 222 of file LightSource_module.cc.

Referenced by LightSource().

std::vector<double> evgen::LightSource::fRegionMin
private

Definition at line 221 of file LightSource_module.cc.

Referenced by LightSource().

std::set<std::string> const evgen::LightSource::fSelectedMaterials
private

Names of materials to consider scintillation from.

Definition at line 207 of file LightSource_module.cc.

Referenced by checkMaterials(), LightSource(), and Sample().

TLorentzVector evgen::LightSource::fShotMom
private

Definition at line 196 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

TLorentzVector evgen::LightSource::fShotPos
private

Definition at line 195 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

double evgen::LightSource::fSigmaP
private

Definition at line 234 of file LightSource_module.cc.

Referenced by LightSource(), readParametersFromInputFile(), and Sample().

double evgen::LightSource::fSigmaT
private

Definition at line 232 of file LightSource_module.cc.

Referenced by LightSource(), readParametersFromInputFile(), and Sample().

double evgen::LightSource::fSigmaX
private

Definition at line 229 of file LightSource_module.cc.

Referenced by LightSource(), produce(), readParametersFromInputFile(), and Sample().

double evgen::LightSource::fSigmaY
private

Definition at line 230 of file LightSource_module.cc.

Referenced by LightSource(), produce(), readParametersFromInputFile(), and Sample().

double evgen::LightSource::fSigmaZ
private

Definition at line 231 of file LightSource_module.cc.

Referenced by LightSource(), produce(), readParametersFromInputFile(), and Sample().

int evgen::LightSource::fSourceMode
private

Definition at line 200 of file LightSource_module.cc.

Referenced by LightSource(), and produce().

double evgen::LightSource::fT
private

Definition at line 228 of file LightSource_module.cc.

Referenced by LightSource(), readParametersFromInputFile(), and Sample().

int evgen::LightSource::fTDist
private

Definition at line 203 of file LightSource_module.cc.

Referenced by LightSource(), and Sample().

sim::PhotonVoxelDef evgen::LightSource::fThePhotonVoxelDef
private

Definition at line 214 of file LightSource_module.cc.

Referenced by LightSource(), and produce().

geo::Vector_t evgen::LightSource::fTPCCenter
private

Definition at line 220 of file LightSource_module.cc.

bool evgen::LightSource::fUseCustomRegion
private

Definition at line 223 of file LightSource_module.cc.

Referenced by LightSource().

std::string evgen::LightSource::fVersion
private

Definition at line 180 of file LightSource_module.cc.

int evgen::LightSource::fVoxelCount
private

Definition at line 216 of file LightSource_module.cc.

Referenced by LightSource().

int evgen::LightSource::fXSteps
private

Definition at line 210 of file LightSource_module.cc.

Referenced by LightSource().

int evgen::LightSource::fYSteps
private

Definition at line 211 of file LightSource_module.cc.

Referenced by LightSource().

int evgen::LightSource::fZSteps
private

Definition at line 212 of file LightSource_module.cc.

Referenced by LightSource().

const int evgen::LightSource::kFILE = 0
staticprivate

Definition at line 185 of file LightSource_module.cc.

Referenced by LightSource(), and produce().

const int evgen::LightSource::kGAUS = 1
staticprivate

Definition at line 184 of file LightSource_module.cc.

Referenced by Sample().

const int evgen::LightSource::kSCAN = 1
staticprivate

Definition at line 186 of file LightSource_module.cc.

Referenced by LightSource(), and produce().

const int evgen::LightSource::kUNIF = 0
staticprivate

Definition at line 183 of file LightSource_module.cc.


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