All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
evgen::LightSource Class Reference

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

Inheritance diagram for evgen::LightSource:

Classes

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

Public Member Functions

 LightSource (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt)
 
void beginRun (art::Run &run)
 

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:

Definition at line 131 of file LightSource_module.cc.

Constructor & Destructor Documentation

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

Definition at line 270 of file LightSource_module.cc.

271  : art::EDProducer{pset}
272  , fSourceMode{pset.get<int>("SourceMode")}
273  , fFillTree{pset.get<bool>("FillTree")}
274  , fPosDist{pset.get<int>("PosDist")}
275  , fTDist{pset.get<int>("TDist")}
276  , fPDist{pset.get<int>("PDist")}
277  , fSelectedMaterials{makeSet(pset.get<std::vector<std::string>>("SelectMaterials", {}))}
std::set< std::string > const fSelectedMaterials
Names of materials to consider scintillation from.

Member Function Documentation

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

Definition at line 378 of file LightSource_module.cc.

379  {
380  run.put(std::make_unique<sumdata::RunData>(fGeom.DetectorName()));
381 
383  }
geo::GeometryCore const & fGeom
Geometry service provider (cached).
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
void evgen::LightSource::checkMaterials ( ) const
private

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

Definition at line 550 of file LightSource_module.cc.

551  {
552 
553  TGeoManager const& manager = *(fGeom.ROOTGeoManager());
554 
555  { // start scope
556  mf::LogDebug log("LightSource");
557  auto const& matList = *(manager.GetListOfMaterials());
558  log << matList.GetSize() << " elements/materials in the geometry:";
559  for (auto const* obj : matList) {
560  auto const mat = dynamic_cast<TGeoMaterial const*>(obj);
561  log << "\n '" << mat->GetName() << "' (Z=" << mat->GetZ() << " A=" << mat->GetA() << ")";
562  } // for
563  } // end scope
564 
565  std::set<std::string> missingMaterials;
566  for (auto const& matName : fSelectedMaterials) {
567  if (!manager.GetMaterial(matName.c_str())) missingMaterials.insert(matName);
568  }
569  if (missingMaterials.empty()) return;
570 
571  art::Exception e(art::errors::Configuration);
572  e << "Requested filtering on " << missingMaterials.size()
573  << " materials which are not present in the geometry:";
574  for (auto const& matName : missingMaterials)
575  e << "\n '" << matName << "'";
576  throw e << "\n";
577 
578  } // LightSource::checkMaterials()
geo::GeometryCore const & fGeom
Geometry service provider (cached).
TGeoManager * ROOTGeoManager() const
Access to the ROOT geometry description manager.
do i e
std::set< std::string > const fSelectedMaterials
Names of materials to consider scintillation from.
void evgen::LightSource::produce ( art::Event &  evt)

Definition at line 387 of file LightSource_module.cc.

388  {
389  if(fSourceMode==kFILE) {
390  // Each event, read coordinates of gun and number of photons to shoot from file
391 
392  // read in one line
394  // Loop file if required
395  mf::LogWarning("LightSource") << "EVGEN Light Source : Warning, reached end of file,"
396  << " looping back to beginning";
397  fInputFile.clear();
398  fInputFile.seekg(0, std::ios::beg);
399  fInputFile.getline(fDummyString, 256);
400 
402  throw cet::exception("LightSource") << "EVGEN Light Source : File error in "
403  << fFileName << "\n";
404  }
405 
406  }
407 
409  fCenter.X() + fSigmaX,
410  1,
411  fCenter.Y() - fSigmaY,
412  fCenter.Y() + fSigmaY,
413  1,
414  fCenter.Z() - fSigmaZ,
415  fCenter.Z() + fSigmaZ,
416  1);
417 
418  fCurrentVoxel=0;
419  }
420  else if (fSourceMode == kSCAN) {
421  // Step through detector using a number of steps provided in the config file
422  // firing a constant number of photons from each point
424  }
425  else {
426  // Neither file or scan mode, probably a config file error
427  throw cet::exception("LightSource") << "EVGEN : Light Source, unrecognised source mode\n";
428  }
429 
430  auto truthcol = std::make_unique<std::vector<simb::MCTruth>>();
431 
432  truthcol->push_back(Sample());
433  int const nPhotons = truthcol->back().NParticles();
434 
435  evt.put(std::move(truthcol));
436 
437  phot::PhotonVisibilityService* vis = nullptr;
438  try {
439  vis = art::ServiceHandle<phot::PhotonVisibilityService>().get();
440  }
441  catch (art::Exception const& e) {
442  // if the service is not configured, then this is not a build job
443  // (it is a simple generation job instead)
444  if (e.categoryCode() != art::errors::ServiceNotFound) throw;
445  }
446 
447  if (vis && vis->IsBuildJob()) {
448  mf::LogVerbatim("LightSource") << "Light source : Stowing voxel params ";
449  vis->StoreLightProd(fCurrentVoxel, nPhotons);
450  }
451 
452  if (fCurrentVoxel != fLastVoxel) { ++fCurrentVoxel; }
453  else {
454  mf::LogVerbatim("LightSource")
455  << "EVGEN Light Source fully scanned detector. Starting over.";
457  }
458  }
static const int kSCAN
Representation of a region of space diced into voxels.
void StoreLightProd(int VoxID, double N)
simb::MCTruth Sample()
Point GetCenter() const
Returns the center of the voxel (type Point).
sim::PhotonVoxelDef fThePhotonVoxelDef
geo::Point_t fCenter
Central position of source [cm].
static const int kFILE
do i e
TCEvent evt
Definition: DataStructs.cxx:8
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 621 of file LightSource_module.cc.

621  {
622  double x, y, z;
623  fInputFile >> x >> y >> z >> fT
624  >> fSigmaX >> fSigmaY >> fSigmaZ >> fSigmaT
625  >> fP >> fSigmaP >> fN;
626  fCenter = { x, y, z };
627  if (!fInputFile.good()) return false;
628 
629  std::string dummy;
630  std::getline(fInputFile, dummy); // this can fail for what I care
631  return true;
632  } // LightSource::readParametersFromInputFile()
process_name opflash particleana ie ie ie z
process_name opflash particleana ie x
process_name opflash particleana ie ie y
geo::Point_t fCenter
Central position of source [cm].
simb::MCTruth evgen::LightSource::Sample ( )
private

Definition at line 461 of file LightSource_module.cc.

462  {
463  mf::LogVerbatim("LightSource") << "Light source debug : Shooting at " << fCenter;
464 
465  CLHEP::RandFlat flat(fEngine, -1.0, 1.0);
466  CLHEP::RandGaussQ gauss(fEngine);
467 
468  MaterialPointFilter filter(fGeom, fSelectedMaterials);
469 
470  simb::MCTruth mct;
471  mct.SetOrigin(simb::kSingleParticle);
472 
473  unsigned long long int const nMax = static_cast<unsigned long long int>(double(fN) * fNMaxF);
474  unsigned long long int fired = 0ULL;
475  while (mct.NParticles() < fN) {
476  if (fired >= nMax) break;
477 
478  // Choose momentum (supplied in eV, convert to GeV)
479  double const p =
480  1e-9 * ((fPDist == kGAUS) ? gauss.fire(fP, fSigmaP) : fP + fSigmaP * flat.fire());
481 
482  // Choose position
483  ++fired;
484  geo::Point_t x;
485  if (fPointSource) { x = fCenter; }
486  else {
487  if (fPosDist == kGAUS) {
488  x = {gauss.fire(fCenter.X(), fSigmaX),
489  gauss.fire(fCenter.Y(), fSigmaY),
490  gauss.fire(fCenter.Z(), fSigmaZ)};
491  }
492  else {
493  x = {fCenter.X() + fSigmaX * flat.fire(),
494  fCenter.Y() + fSigmaY * flat.fire(),
495  fCenter.Z() + fSigmaZ * flat.fire()};
496  }
497 
498  if (!filter.accept(x)) continue;
499  }
500 
501  // Choose time
502  double t;
503  if (fTDist == kGAUS) { t = gauss.fire(fT, fSigmaT); }
504  else {
505  t = fT + fSigmaT * flat.fire();
506  }
507 
508  //assume the position is relative to the center of the TPC
509  //x += fTPCCenter;
510 
511  fShotPos = TLorentzVector(x.X(), x.Y(), x.Z(), t);
512 
513  // Choose angles
514  double costh = flat.fire();
515  double sinth = std::sqrt(1.0 - cet::square(costh));
516  double phi = 2 * M_PI * flat.fire();
517 
518  // Generate momentum 4-vector
519 
520  fShotMom = TLorentzVector(p * sinth * cos(phi), p * sinth * sin(phi), p * costh, p);
521 
522  int trackid = -(mct.NParticles() +
523  1); // set track id to -i as these are all primary particles and have id <= 0
524  std::string primary("primary");
525  int PDG = 0; //optical photons have PDG 0
526 
527  simb::MCParticle part(trackid, PDG, primary);
528  part.AddTrajectoryPoint(fShotPos, fShotMom);
529 
530  if (fFillTree) fPhotonsGenerated->Fill();
531 
532  mct.Add(part);
533  }
534 
535  mf::LogInfo("LightSource") << "Generated " << mct.NParticles() << " photons after " << fired
536  << " tries.";
537  if (mct.NParticles() < fN) {
538  // this may mean `NMaxFactor` is too small, or the volume is wrong;
539  // or it may be just expected
540  mf::LogWarning("LightSource")
541  << "Warning: " << mct.NParticles() << " photons generated after " << fired << " tries, but "
542  << fN << " were requested.";
543  }
544 
545  return mct;
546  } // LightSource::Sample()
process_name stream1 can override from command line with o or output services DetectorPropertiesService services DetectorPropertiesService services DetectorPropertiesService services DetectorPropertiesService physics analyzers pmtresponse NeutronTrackingCut services LArG4Parameters gaussian physics producers generator PDG
process_name opflash particleana ie x
geo::GeometryCore const & fGeom
Geometry service provider (cached).
pdgs p
Definition: selectors.fcl:22
static const int kGAUS
double const fNMaxF
Maximum number of attempted samplings (factor on top of fN).
CLHEP::HepRandomEngine & fEngine
physics filters filter
geo::Point_t fCenter
Central position of source [cm].
do i e
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:184
std::set< std::string > const fSelectedMaterials
Names of materials to consider scintillation from.

Member Data Documentation

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

Central position of source [cm].

Definition at line 231 of file LightSource_module.cc.

int evgen::LightSource::fCurrentVoxel
private

Definition at line 222 of file LightSource_module.cc.

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

Definition at line 196 of file LightSource_module.cc.

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

Definition at line 250 of file LightSource_module.cc.

Int_t evgen::LightSource::fEvID
private

Definition at line 202 of file LightSource_module.cc.

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

Definition at line 195 of file LightSource_module.cc.

bool evgen::LightSource::fFillTree
private

Definition at line 206 of file LightSource_module.cc.

int evgen::LightSource::fFirstVoxel
private

Definition at line 247 of file LightSource_module.cc.

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

Geometry service provider (cached).

Definition at line 251 of file LightSource_module.cc.

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

Definition at line 194 of file LightSource_module.cc.

int evgen::LightSource::fLastVoxel
private

Definition at line 248 of file LightSource_module.cc.

int evgen::LightSource::fN
private

Definition at line 242 of file LightSource_module.cc.

double const evgen::LightSource::fNMaxF
private

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

Definition at line 245 of file LightSource_module.cc.

double evgen::LightSource::fP
private

Definition at line 238 of file LightSource_module.cc.

int evgen::LightSource::fPDist
private

Definition at line 209 of file LightSource_module.cc.

TTree* evgen::LightSource::fPhotonsGenerated
private

Definition at line 199 of file LightSource_module.cc.

bool evgen::LightSource::fPointSource
private

Definition at line 232 of file LightSource_module.cc.

int evgen::LightSource::fPosDist
private

Definition at line 207 of file LightSource_module.cc.

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

Definition at line 227 of file LightSource_module.cc.

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

Definition at line 226 of file LightSource_module.cc.

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

Names of materials to consider scintillation from.

Definition at line 212 of file LightSource_module.cc.

TLorentzVector evgen::LightSource::fShotMom
private

Definition at line 201 of file LightSource_module.cc.

TLorentzVector evgen::LightSource::fShotPos
private

Definition at line 200 of file LightSource_module.cc.

double evgen::LightSource::fSigmaP
private

Definition at line 239 of file LightSource_module.cc.

double evgen::LightSource::fSigmaT
private

Definition at line 237 of file LightSource_module.cc.

double evgen::LightSource::fSigmaX
private

Definition at line 234 of file LightSource_module.cc.

double evgen::LightSource::fSigmaY
private

Definition at line 235 of file LightSource_module.cc.

double evgen::LightSource::fSigmaZ
private

Definition at line 236 of file LightSource_module.cc.

int evgen::LightSource::fSourceMode
private

Definition at line 205 of file LightSource_module.cc.

double evgen::LightSource::fT
private

Definition at line 233 of file LightSource_module.cc.

int evgen::LightSource::fTDist
private

Definition at line 208 of file LightSource_module.cc.

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

Definition at line 219 of file LightSource_module.cc.

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

Definition at line 225 of file LightSource_module.cc.

bool evgen::LightSource::fUseCustomRegion
private

Definition at line 228 of file LightSource_module.cc.

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

Definition at line 185 of file LightSource_module.cc.

int evgen::LightSource::fVoxelCount
private

Definition at line 221 of file LightSource_module.cc.

int evgen::LightSource::fXSteps
private

Definition at line 215 of file LightSource_module.cc.

int evgen::LightSource::fYSteps
private

Definition at line 216 of file LightSource_module.cc.

int evgen::LightSource::fZSteps
private

Definition at line 217 of file LightSource_module.cc.

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

Definition at line 190 of file LightSource_module.cc.

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

Definition at line 189 of file LightSource_module.cc.

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

Definition at line 191 of file LightSource_module.cc.

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

Definition at line 188 of file LightSource_module.cc.


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