93 #include "art_root_io/TFileService.h" 96 #include "cetlib_except/exception.h" 101 #include "nurandom/RandomUtils/NuRandomService.h" 115 #include "TGeoManager.h" 116 #include "TGeoMaterial.h" 117 #include "TGeoNavigator.h" 119 #include "TLorentzVector.h" 121 #include "TVector3.h" 123 #include "CLHEP/Random/RandFlat.h" 124 #include "CLHEP/Random/RandGaussQ.h" 142 std::set<std::string>
const& materialNames);
256 template <
typename Coll>
257 std::set<typename Coll::value_type>
258 makeSet(Coll
const& coll)
272 ,
fPosDist{pset.get<
int>(
"PosDist")}
273 ,
fTDist{pset.get<
int>(
"TDist")}
274 ,
fPDist{pset.get<
int>(
"PDist")}
275 ,
fSelectedMaterials{makeSet(pset.get<std::vector<std::string>>(
"SelectMaterials", {}))}
276 ,
fNMaxF{pset.get<
double>(
"NMaxFactor", 100.0)}
280 ,
fGeom(*lar::providerFrom<geo::Geometry const>())
286 produces<sumdata::RunData, art::InRun>();
287 produces<std::vector<simb::MCTruth>>();
295 fT = pset.get<
double>(
"T0");
296 fSigmaT = pset.get<
double>(
"SigmaT");
297 fN = pset.get<
int>(
"N");
302 fP = pset.get<
double>(
"P");
303 fSigmaP = pset.get<
double>(
"SigmaP");
308 if (fUseCustomRegion) {
309 fRegionMin = pset.get<std::vector<double>>(
"RegionMin");
310 fRegionMax = pset.get<std::vector<double>>(
"RegionMax");
311 fXSteps = pset.get<
int>(
"XSteps");
312 fYSteps = pset.get<
int>(
"YSteps");
313 fZSteps = pset.get<
int>(
"ZSteps");
323 if (!fUseCustomRegion) {
356 <<
"EVGEN Light Source : Unrecognised light source mode\n";
393 mf::LogWarning(
"LightSource") <<
"EVGEN Light Source : Warning, reached end of file," 394 <<
" looping back to beginning";
400 throw cet::exception(
"LightSource") <<
"EVGEN Light Source : File error in " 425 throw cet::exception(
"LightSource") <<
"EVGEN : Light Source, unrecognised source mode\n";
428 auto truthcol = std::make_unique<std::vector<simb::MCTruth>>();
430 truthcol->push_back(
Sample());
431 int const nPhotons = truthcol->back().NParticles();
446 mf::LogVerbatim(
"LightSource") <<
"Light source : Stowing voxel params ";
453 <<
"EVGEN Light Source fully scanned detector. Starting over.";
471 unsigned long long int const nMax =
static_cast<unsigned long long int>(double(
fN) *
fNMaxF);
472 unsigned long long int fired = 0ULL;
474 if (fired >= nMax)
break;
496 if (!filter.
accept(x))
continue;
509 fShotPos = TLorentzVector(x.X(), x.Y(), x.Z(),
t);
512 double costh = flat.fire();
513 double sinth = std::sqrt(1.0 -
cet::square(costh));
514 double phi = 2 *
M_PI * flat.fire();
518 fShotMom = TLorentzVector(p * sinth * cos(phi), p * sinth * sin(phi), p * costh, p);
539 <<
"Warning: " << mct.
NParticles() <<
" photons generated after " << fired <<
" tries, but " 540 <<
fN <<
" were requested.";
555 auto const& matList = *(manager.GetListOfMaterials());
556 log << matList.GetSize() <<
" elements/materials in the geometry:";
557 for (
auto const* obj : matList) {
558 auto const mat =
dynamic_cast<TGeoMaterial
const*
>(obj);
559 log <<
"\n '" << mat->GetName() <<
"' (Z=" << mat->GetZ() <<
" A=" << mat->GetA() <<
")";
563 std::set<std::string> missingMaterials;
565 if (!manager.GetMaterial(matName.c_str())) missingMaterials.insert(matName);
567 if (missingMaterials.empty())
return;
570 e <<
"Requested filtering on " << missingMaterials.size()
571 <<
" materials which are not present in the geometry:";
572 for (
auto const& matName : missingMaterials)
573 e <<
"\n '" << matName <<
"'";
582 std::set<std::string>
const& materialNames)
583 : fManager(geom.ROOTGeoManager())
584 , fNavigator(fManager->AddNavigator())
585 , fMaterials(materialNames)
602 TGeoNode
const* node =
fNavigator->FindNode(point.X(), point.Y(), point.Z());
603 return node ? node->GetVolume()->GetMaterial() :
nullptr;
612 MF_LOG_TRACE(
"LightSource") <<
"Material at " << point <<
": " 613 << (material ? material->GetName() :
"not found");
614 return material ? (
fMaterials.count(material->GetName()) > 0) :
false;
Definitions of voxel data structures.
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< double > fRegionMin
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)
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
geo::GeometryCore const & fGeom
Geometry service provider (cached).
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.
std::vector< double > fRegionMax
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
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.
art framework interface to geometry description
bool operator()(geo::Point_t const &point)
void produce(art::Event &evt)
CLHEP::HepRandomEngine & fEngine
TTree * fPhotonsGenerated
void StoreLightProd(int VoxID, double N)
#define DEFINE_ART_MODULE(klass)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
std::set< std::string > const & fMaterials
Names of materials to select.
single particles thrown at the detector
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
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.
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
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
const sim::PhotonVoxelDef & GetVoxelDef() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
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.
cet::LibraryManager dummy("noplugin")
Definitions of geometry vector data types.
Access the description of detector geometry.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
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.
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