94 #include "art_root_io/TFileService.h" 96 #include "cetlib/pow.h" 97 #include "cetlib_except/exception.h" 117 #include "TGeoManager.h" 118 #include "TGeoMaterial.h" 119 #include "TGeoNavigator.h" 121 #include "TLorentzVector.h" 123 #include "TVector3.h" 125 #include "CLHEP/Random/RandFlat.h" 126 #include "CLHEP/Random/RandGaussQ.h" 144 std::set<std::string>
const& materialNames);
165 TGeoMaterial
const*
findMaterial(std::string
const& name)
const;
253 template <
typename Coll>
254 std::set<typename Coll::value_type> makeSet(Coll
const& coll)
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)}
278 ,
fGeom(*lar::providerFrom<geo::Geometry const>())
284 produces<sumdata::RunData, art::InRun>();
285 produces<std::vector<simb::MCTruth>>();
288 fFileName = pset.get<std::string>(
"SteeringFile");
293 fT = pset.get<
double>(
"T0");
294 fSigmaT = pset.get<
double>(
"SigmaT");
295 fN = pset.get<
int>(
"N");
300 fP = pset.get<
double>(
"P");
301 fSigmaP = pset.get<
double>(
"SigmaP");
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");
321 if (!fUseCustomRegion) {
354 <<
"EVGEN Light Source : Unrecognised light source mode\n";
389 mf::LogWarning(
"LightSource") <<
"EVGEN Light Source : Warning, reached end of file," 390 <<
" looping back to beginning";
397 <<
"EVGEN Light Source : File error in " <<
fFileName <<
"\n";
420 throw cet::exception(
"LightSource") <<
"EVGEN : Light Source, unrecognised source mode\n";
423 auto truthcol = std::make_unique<std::vector<simb::MCTruth>>();
425 truthcol->push_back(
Sample());
426 int const nPhotons = truthcol->back().NParticles();
428 evt.
put(std::move(truthcol));
441 mf::LogVerbatim(
"LightSource") <<
"Light source : Stowing voxel params ";
448 <<
"EVGEN Light Source fully scanned detector. Starting over.";
457 CLHEP::RandFlat flat(
fEngine, -1.0, 1.0);
458 CLHEP::RandGaussQ gauss(
fEngine);
465 unsigned long long int const nMax =
static_cast<unsigned long long int>(double(
fN) *
fNMaxF);
466 unsigned long long int fired = 0ULL;
468 if (fired >= nMax)
break;
490 if (!filter.
accept(x))
continue;
503 fShotPos = TLorentzVector(x.X(), x.Y(), x.Z(), t);
506 double costh = flat.fire();
507 double sinth = std::sqrt(1.0 - cet::square(costh));
508 double phi = 2 * M_PI * flat.fire();
512 fShotMom = TLorentzVector(p * sinth * cos(phi), p * sinth * sin(phi), p * costh, p);
516 std::string primary(
"primary");
533 <<
"Warning: " << mct.
NParticles() <<
" photons generated after " << fired <<
" tries, but " 534 <<
fN <<
" were requested.";
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() <<
")";
556 std::set<std::string> missingMaterials;
558 if (!manager.GetMaterial(matName.c_str())) missingMaterials.insert(matName);
560 if (missingMaterials.empty())
return;
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 <<
"'";
575 std::set<std::string>
const& materialNames)
576 : fManager(geom.ROOTGeoManager())
577 , fNavigator(fManager->AddNavigator())
578 , fMaterials(materialNames)
594 TGeoNode
const* node =
fNavigator->FindNode(point.X(), point.Y(), point.Z());
595 return node ? node->GetVolume()->GetMaterial() :
nullptr;
602 TGeoMaterial
const* material =
materialAt(point);
603 MF_LOG_TRACE(
"LightSource") <<
"Material at " << point <<
": " 604 << (material ? material->GetName() :
"not found");
605 return material ? (
fMaterials.count(material->GetName()) > 0) :
false;
Definitions of voxel data structures.
std::vector< double > fRegionMin
base_engine_t & createEngine(seed_t seed)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
MaterialPointFilter(geo::GeometryCore const &geom, std::set< std::string > const &materialNames)
Constructor: sets up the filter configuration.
LightSource(fhicl::ParameterSet const &pset)
Utilities related to art service access.
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
geo::GeometryCore const & fGeom
Geometry service provider (cached).
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
void SetOrigin(simb::Origin_t origin)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Vector GetVoxelSize() const
Returns a vector describing the span of a single voxel in x, y an z [cm].
TGeoNavigator * fNavigator
Our own ROOT geometry navigator.
EDProducer(fhicl::ParameterSet const &pset)
Representation of a region of space diced into voxels.
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
std::vector< double > fRegionMax
double const fNMaxF
Maximum number of attempted samplings (factor on top of fN).
TGeoManager * ROOTGeoManager() const
Access to the ROOT geometry description manager.
void checkMaterials() const
Throws an exception if any of the configured materials is not present.
bool operator()(geo::Point_t const &point)
Returns whether the specified point can be accepted.
void produce(art::Event &evt)
CLHEP::HepRandomEngine & fEngine
TTree * fPhotonsGenerated
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
void StoreLightProd(int VoxID, double N)
Access the description of detector geometry.
#define DEFINE_ART_MODULE(klass)
Definitions of geometry vector data types.
std::set< std::string > const & fMaterials
Names of materials to select.
single particles thrown at the detector
Filters a point according to the material at that point.
Description of geometry of one entire detector.
TGeoMaterial const * materialAt(geo::Point_t const &point)
Returns a pointer to the material of the volume at specified point.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
TGeoMaterial const * findMaterial(std::string const &name) const
Returns a pointer to the material with the specified name.
void beginRun(art::Run &run)
sim::PhotonVoxelDef fThePhotonVoxelDef
const sim::PhotonVoxelDef & GetVoxelDef() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
void Add(simb::MCParticle const &part)
geo::Point_t fCenter
Central position of source [cm].
bool readParametersFromInputFile()
TGeoManager * fManager
ROOT geometry manager.
Point GetCenter() const
Returns the center of the voxel (type Point).
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
unsigned int GetNVoxels() const
Returns the total number of voxels in the volume.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
A module for optical MC testing and library building.
bool accept(geo::Point_t const &point)
Returns whether the specified point can be accepted.
Event generator information.
Event Generation using GENIE, cosmics or single particles.
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
std::set< std::string > const fSelectedMaterials
Names of materials to consider scintillation from.
PhotonVoxel GetPhotonVoxel(int ID) const