LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
evgen::ActiveVolumeVertexSampler Class Reference

#include "ActiveVolumeVertexSampler.h"

Classes

struct  Config
 

Public Types

enum  vertex_type_t { vertex_type_t::kSampled, vertex_type_t::kFixed }
 
using Name = fhicl::Name
 
using Comment = fhicl::Comment
 

Public Member Functions

 ActiveVolumeVertexSampler (const fhicl::Table< Config > &conf, rndm::NuRandomService &rand_service, const geo::Geometry &geom, const std::string &generator_name)
 
 ActiveVolumeVertexSampler (const fhicl::ParameterSet &pset, rndm::NuRandomService &rand_service, const geo::Geometry &geom, const std::string &generator_name)
 
void reconfigure (const fhicl::Table< Config > &conf, const geo::Geometry &geom)
 
TLorentzVector sample_vertex_pos (const geo::Geometry &geom)
 

Protected Attributes

TLorentzVector fVertexPosition
 
vertex_type_t fVertexType
 
std::string fGeneratorName
 
std::unique_ptr< std::discrete_distribution< size_t > > fTPCDist
 
std::mt19937_64 fTPCEngine
 

Detailed Description

Definition at line 37 of file ActiveVolumeVertexSampler.h.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
kSampled 
kFixed 

Definition at line 67 of file ActiveVolumeVertexSampler.h.

67 { kSampled, kFixed };
vertex position fixed manually - no fitting done
Definition: DataStructs.h:74

Constructor & Destructor Documentation

evgen::ActiveVolumeVertexSampler::ActiveVolumeVertexSampler ( const fhicl::Table< Config > &  conf,
rndm::NuRandomService rand_service,
const geo::Geometry geom,
const std::string &  generator_name 
)

Definition at line 13 of file ActiveVolumeVertexSampler.cxx.

References fGeneratorName, fTPCEngine, fhicl::Table< T, KeysToIgnore >::get_PSet(), reconfigure(), rndm::NuRandomService::registerEngine(), and seed.

18  fTPCDist(nullptr)
19 {
20  // Configure the algorithm using the FHiCL parameters
21  this->reconfigure(conf, geom);
22 
23  // Register the TPC sampling engine with the seed service. If you need the
24  // seed later, get it from the seed service using the value of the variable
25  // generator_name as the instance name.
26  rndm::NuRandomService::seed_t tpc_seed = rand_service.registerEngine(
27  [this](rndm::NuRandomService::EngineId const& /* unused */,
28  rndm::NuRandomService::seed_t lar_seed) -> void
29  {
30  auto seed = static_cast<uint_fast64_t>(lar_seed);
31  // Use the obtained seed to prepare the random number engine. This is
32  // an attempt to do a decent job, but optimally accomplishing this can
33  // be tricky (see, for example,
34  // http://www.pcg-random.org/posts/cpp-seeding-surprises.html)
35  std::seed_seq seed_sequence{seed};
36  fTPCEngine.seed(seed_sequence);
37  },
38  fGeneratorName, conf.get_PSet(), { "seed" }
39  );
40 
41  // TODO: resolve the other workaround mentioned in the MARLEYHelper
42  // class, then fix this as well
43  uint_fast64_t tpc_cast_seed = static_cast<uint_fast64_t>(tpc_seed);
44  std::seed_seq tpc_seed_sequence{tpc_cast_seed};
45  fTPCEngine.seed(tpc_seed_sequence);
46 }
ParameterSet const & get_PSet() const
Definition: Table.h:69
art::RandomNumberGenerator::seed_t seed_t
long seed
Definition: chem4.cc:68
Identifier for a engine, made of module name and optional instance name.
Definition: EngineId.h:22
void reconfigure(const fhicl::Table< Config > &conf, const geo::Geometry &geom)
std::unique_ptr< std::discrete_distribution< size_t > > fTPCDist
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, std::string instance="")
Registers an existing engine with NuRandomService.
evgen::ActiveVolumeVertexSampler::ActiveVolumeVertexSampler ( const fhicl::ParameterSet pset,
rndm::NuRandomService rand_service,
const geo::Geometry geom,
const std::string &  generator_name 
)
inline

Definition at line 74 of file ActiveVolumeVertexSampler.h.

References reconfigure(), and sample_vertex_pos().

78  rand_service, geom, generator_name) {}
ActiveVolumeVertexSampler(const fhicl::Table< Config > &conf, rndm::NuRandomService &rand_service, const geo::Geometry &geom, const std::string &generator_name)

Member Function Documentation

void evgen::ActiveVolumeVertexSampler::reconfigure ( const fhicl::Table< Config > &  conf,
const geo::Geometry geom 
)

Definition at line 89 of file ActiveVolumeVertexSampler.cxx.

References geo::TPCGeo::ActiveMass(), fGeneratorName, fTPCDist, fVertexPosition, fVertexType, kFixed, kSampled, geo::GeometryCore::NTPC(), and geo::GeometryCore::TPC().

Referenced by ActiveVolumeVertexSampler().

92 {
93  auto type = conf().type_();
94  if (type == "sampled") {
95 
97 
98  // Get the active masses of each of the TPCs in the current geometry. Use
99  // them as weights for sampling a TPC to use for the primary vertex.
100  std::vector<double> tpc_masses;
101  size_t num_tpcs = geom.NTPC();
102  for (size_t iTPC = 0; iTPC < num_tpcs; ++iTPC) {
103  // For each TPC, use its active mass (returned in kg) as its sampling
104  // weight
105  tpc_masses.push_back(geom.TPC(iTPC).ActiveMass());
106  }
107 
108  // Load the discrete distribution used to sample TPCs with the up-to-date
109  // set of weights
110  fTPCDist.reset(new std::discrete_distribution<size_t>(tpc_masses.begin(),
111  tpc_masses.end()));
112  }
113  else if (type == "fixed") {
114 
116 
117  auto vertex_pos = conf().position_();
118  double Vx = vertex_pos.at(0);
119  double Vy = vertex_pos.at(0);
120  double Vz = vertex_pos.at(0);
121 
122  fVertexPosition.SetXYZT(Vx, Vy, Vz, 0.); // TODO: add time setting
123  }
124  else throw cet::exception("ActiveVolumeVertexSampler " + fGeneratorName)
125  << "Invalid vertex type '" << type << "' requested. Allowed values are"
126  << " 'sampled' and 'fixed'";
127 }
double ActiveMass() const
Half width (associated with x coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:110
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
std::unique_ptr< std::discrete_distribution< size_t > > fTPCDist
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
TLorentzVector evgen::ActiveVolumeVertexSampler::sample_vertex_pos ( const geo::Geometry geom)

Definition at line 49 of file ActiveVolumeVertexSampler.cxx.

References fGeneratorName, fTPCDist, fTPCEngine, fVertexPosition, fVertexType, kSampled, LOG_INFO, maxY, geo::BoxBoundedGeo::MinX(), minY, geo::GeometryCore::TPC(), x, y, and z.

Referenced by ActiveVolumeVertexSampler().

51 {
52  // sample a new position if needed
54 
55  // Sample a TPC index using the active masses as weights
56  size_t tpc_index = fTPCDist->operator()(fTPCEngine);
57 
58  // Get the dimensions of the chosen TPC's active volume
59  const auto& tpc = geom.TPC(tpc_index);
60  double minX = tpc.MinX();
61  double maxX = tpc.MaxX();
62  double minY = tpc.MinY();
63  double maxY = tpc.MaxY();
64  double minZ = tpc.MinZ();
65  double maxZ = tpc.MaxZ();
66  std::uniform_real_distribution<double>::param_type x_range(minX, maxX);
67  std::uniform_real_distribution<double>::param_type y_range(minY, maxY);
68  std::uniform_real_distribution<double>::param_type z_range(minZ, maxZ);
69 
70  // Sample a location uniformly over this volume
71  static std::uniform_real_distribution<double> uniform_dist;
72  double x = uniform_dist(fTPCEngine, x_range);
73  double y = uniform_dist(fTPCEngine, y_range);
74  double z = uniform_dist(fTPCEngine, z_range);
75  LOG_INFO("ActiveVolumeVertexSampler " + fGeneratorName)
76  << "Sampled primary vertex in TPC #" << tpc_index << ", x = " << x
77  << ", y = " << y << ", z = " << z;
78 
79  // Update the vertex position 4-vector
80  fVertexPosition.SetXYZT(x, y, z, 0.); // TODO: add time sampling
81  }
82 
83  // if we're using a fixed vertex position, we don't need to do any sampling
84 
85  return fVertexPosition;
86 }
Float_t x
Definition: compare.C:6
#define LOG_INFO(category)
double minY
Definition: plot_hist.C:9
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:90
double maxY
Definition: plot_hist.C:10
std::unique_ptr< std::discrete_distribution< size_t > > fTPCDist
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.

Member Data Documentation

std::string evgen::ActiveVolumeVertexSampler::fGeneratorName
protected
std::unique_ptr<std::discrete_distribution<size_t> > evgen::ActiveVolumeVertexSampler::fTPCDist
protected

Definition at line 99 of file ActiveVolumeVertexSampler.h.

Referenced by reconfigure(), and sample_vertex_pos().

std::mt19937_64 evgen::ActiveVolumeVertexSampler::fTPCEngine
protected

Definition at line 102 of file ActiveVolumeVertexSampler.h.

Referenced by ActiveVolumeVertexSampler(), and sample_vertex_pos().

TLorentzVector evgen::ActiveVolumeVertexSampler::fVertexPosition
protected

Definition at line 91 of file ActiveVolumeVertexSampler.h.

Referenced by reconfigure(), and sample_vertex_pos().

vertex_type_t evgen::ActiveVolumeVertexSampler::fVertexType
protected

Definition at line 93 of file ActiveVolumeVertexSampler.h.

Referenced by reconfigure(), and sample_vertex_pos().


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