18 constexpr
int MAX_BOX_ITERATIONS = 10000;
26 const std::string& generator_name)
27 : fVertexType(
vertex_type_t::kSampled), fGeneratorName(generator_name), fTPCDist(nullptr)
38 auto seed =
static_cast<uint_fast64_t
>(lar_seed);
43 std::seed_seq seed_sequence{
seed};
52 uint_fast64_t tpc_cast_seed =
static_cast<uint_fast64_t
>(tpc_seed);
53 std::seed_seq tpc_seed_sequence{tpc_cast_seed};
68 double minX = tpc.
MinX();
69 double maxX = tpc.MaxX();
70 double minY = tpc.MinY();
71 double maxY = tpc.MaxY();
72 double minZ = tpc.MinZ();
73 double maxZ = tpc.MaxZ();
74 std::uniform_real_distribution<double>::param_type x_range(minX, maxX);
75 std::uniform_real_distribution<double>::param_type y_range(minY, maxY);
76 std::uniform_real_distribution<double>::param_type z_range(minZ, maxZ);
79 std::uniform_real_distribution<double> uniform_dist;
84 <<
"Sampled primary vertex in TPC #" << tpc_index <<
", x = " << x <<
", y = " << y
92 int num_iterations = 0;
96 std::uniform_real_distribution<double>::param_type x_range(
fXmin,
fXmax);
97 std::uniform_real_distribution<double>::param_type y_range(
fYmin,
fYmax);
98 std::uniform_real_distribution<double>::param_type z_range(
fZmin,
fZmax);
101 std::uniform_real_distribution<double> uniform_dist;
106 while (!ok && num_iterations < MAX_BOX_ITERATIONS) {
115 size_t num_tpcs = geom.
NTPC();
117 double minX = tpc.MinX();
118 double maxX = tpc.MaxX();
119 double minY = tpc.MinY();
120 double maxY = tpc.MaxY();
121 double minZ = tpc.MinZ();
122 double maxZ = tpc.MaxZ();
123 if (x >= minX && x <= maxX && y >= minY && y <= maxY && z >= minZ && z <= maxZ) {
135 <<
"Failed to sample a vertex within a TPC active volume after " << MAX_BOX_ITERATIONS
139 <<
"Sampled primary vertex at x = " << x <<
", y = " << y <<
", z = " <<
z;
154 auto type = conf().type_();
155 if (
type ==
"sampled") {
161 std::vector<double> tpc_masses;
162 size_t num_tpcs = geom.
NTPC();
165 tpc_masses.push_back(tpc.ActiveMass());
170 fTPCDist.reset(
new std::discrete_distribution<size_t>(tpc_masses.begin(), tpc_masses.end()));
172 else if (
type ==
"fixed") {
176 auto vertex_pos = conf().position_();
177 double Vx = vertex_pos.at(0);
178 double Vy = vertex_pos.at(1);
179 double Vz = vertex_pos.at(2);
183 else if (
type ==
"box") {
186 auto min_pos = conf().min_position_();
187 auto max_pos = conf().max_position_();
189 fXmin = min_pos.at(0);
190 fYmin = min_pos.at(1);
191 fZmin = min_pos.at(2);
193 fXmax = max_pos.at(0);
194 fYmax = max_pos.at(1);
195 fZmax = max_pos.at(2);
205 <<
"Invalid vertex type '" <<
type <<
"' requested. Allowed values are" 206 <<
" 'sampled' and 'fixed'";
details::range_type< T > Iterate() const
Initializes the specified ID with the ID of the first cryostat.
vertex_type_t fVertexType
unsigned int NTPC(CryostatID const &cryoid=cryostat_zero) const
Returns the total number of TPCs in the specified cryostat.
TLorentzVector fVertexPosition
double MinX() const
Returns the world x coordinate of the start of the box.
Geometry information for a single TPC.
ParameterSet const & get_PSet() const
TLorentzVector sample_vertex_pos(const geo::Geometry &geom)
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, std::string const instance="", std::optional< seed_t > const seed=std::nullopt)
Registers an existing engine with rndm::NuRandomService.
ActiveVolumeVertexSampler(const fhicl::Table< Config > &conf, rndm::NuRandomService &rand_service, const geo::Geometry &geom, const std::string &generator_name)
TPCGeo const & TPC(TPCID const &tpcid=tpc_zero) const
Returns the specified TPC.
Algorithm that samples vertex locations uniformly within the active volume of a detector. It is fully experiment-agnostic and multi-TPC aware.
Identifier for a engine, made of module name and optional instance name.
The geometry of one entire detector, as served by art.
The data type to uniquely identify a TPC.
#define MF_LOG_INFO(category)
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
void reconfigure(const fhicl::Table< Config > &conf, const geo::Geometry &geom)
std::unique_ptr< std::discrete_distribution< size_t > > fTPCDist
std::string fGeneratorName
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Encapsulate the construction of a single detector plane.
The data type to uniquely identify a cryostat.
art::detail::EngineCreator::seed_t seed_t
std::mt19937_64 fTPCEngine