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

#include <ActiveVolumeVertexSampler.h>

Classes

struct  Config
 

Public Types

enum  vertex_type_t { vertex_type_t::kSampled, vertex_type_t::kFixed, vertex_type_t::kBox }
 
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)
 
TLorentzVector sample_vertex_pos (const geo::Geometry &geom)
 

Public Attributes

 rand_service
 
 geom
 
 generator_name
 

Protected Attributes

TLorentzVector fVertexPosition
 
vertex_type_t fVertexType
 
std::string fGeneratorName
 
std::unique_ptr
< std::discrete_distribution
< size_t > > 
fTPCDist
 
std::mt19937_64 fTPCEngine
 
double fXmin
 
double fYmin
 
double fZmin
 
double fXmax
 
double fYmax
 
double fZmax
 
bool fCheckActive
 

Detailed Description

Definition at line 38 of file ActiveVolumeVertexSampler.h.

Member Typedef Documentation

Definition at line 43 of file ActiveVolumeVertexSampler.h.

Definition at line 42 of file ActiveVolumeVertexSampler.h.

Member Enumeration Documentation

Enumerator
kSampled 
kFixed 
kBox 

Definition at line 87 of file ActiveVolumeVertexSampler.h.

87 { kSampled, kFixed, kBox };
vertex position fixed manually - no fitting done
Definition: DataStructs.h:93

Constructor & Destructor Documentation

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

Definition at line 94 of file ActiveVolumeVertexSampler.h.

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

Member Function Documentation

TLorentzVector evgen::ActiveVolumeVertexSampler::sample_vertex_pos ( const geo::Geometry geom)

Definition at line 58 of file ActiveVolumeVertexSampler.cxx.

60 {
61  // sample a new position if needed
63 
64  // Sample a TPC index using the active masses as weights
65  size_t tpc_index = fTPCDist->operator()(fTPCEngine);
66 
67  // Get the dimensions of the chosen TPC's active volume
68  const auto& tpc = geom.TPC(tpc_index);
69  double minX = tpc.MinX();
70  double maxX = tpc.MaxX();
71  double minY = tpc.MinY();
72  double maxY = tpc.MaxY();
73  double minZ = tpc.MinZ();
74  double maxZ = tpc.MaxZ();
75  std::uniform_real_distribution<double>::param_type x_range(minX, maxX);
76  std::uniform_real_distribution<double>::param_type y_range(minY, maxY);
77  std::uniform_real_distribution<double>::param_type z_range(minZ, maxZ);
78 
79  // Sample a location uniformly over this volume
80  std::uniform_real_distribution<double> uniform_dist;
81  double x = uniform_dist(fTPCEngine, x_range);
82  double y = uniform_dist(fTPCEngine, y_range);
83  double z = uniform_dist(fTPCEngine, z_range);
84  MF_LOG_INFO("ActiveVolumeVertexSampler " + fGeneratorName)
85  << "Sampled primary vertex in TPC #" << tpc_index << ", x = " << x
86  << ", y = " << y << ", z = " << z;
87 
88  // Update the vertex position 4-vector
89  fVertexPosition.SetXYZT(x, y, z, 0.); // TODO: add time sampling
90  }
91  else if (fVertexType == vertex_type_t::kBox) {
92  bool ok = false;
93  int num_iterations = 0;
94 
95  // TODO: reduce code duplication here
96  // Get the range of coordinates covered by the box
97  std::uniform_real_distribution<double>::param_type x_range(fXmin, fXmax);
98  std::uniform_real_distribution<double>::param_type y_range(fYmin, fYmax);
99  std::uniform_real_distribution<double>::param_type z_range(fZmin, fZmax);
100 
101  // Sample a location uniformly over this volume
102  std::uniform_real_distribution<double> uniform_dist;
103 
104  double x = 0.;
105  double y = 0.;
106  double z = 0.;
107  while ( !ok && num_iterations < MAX_BOX_ITERATIONS ) {
108  x = uniform_dist(fTPCEngine, x_range);
109  y = uniform_dist(fTPCEngine, y_range);
110  z = uniform_dist(fTPCEngine, z_range);
111 
112  // If we've been asked to check whether the vertex is within the
113  // active volume of a TPC, verify that. Otherwise just accept the
114  // first vertex position that was sampled unconditionally.
115  if ( fCheckActive ) {
116  size_t num_tpcs = geom.NTPC();
117  for (size_t iTPC = 0; iTPC < num_tpcs; ++iTPC) {
118  const auto& tpc = geom.TPC(iTPC);
119  double minX = tpc.MinX();
120  double maxX = tpc.MaxX();
121  double minY = tpc.MinY();
122  double maxY = tpc.MaxY();
123  double minZ = tpc.MinZ();
124  double maxZ = tpc.MaxZ();
125  if ( x >= minX && x <= maxX && y >= minY && y <= maxY && z >= minZ && z <= maxZ ) {
126  ok = true;
127  break;
128  }
129  }
130  }
131  else ok = true;
132  }
133 
134  if ( !ok ) throw cet::exception("ActiveVolumeVertexSampler " + fGeneratorName)
135  << "Failed to sample a vertex within a TPC active volume after " << MAX_BOX_ITERATIONS
136  << " iterations";
137 
138  MF_LOG_INFO("ActiveVolumeVertexSampler " + fGeneratorName)
139  << "Sampled primary vertex at x = " << x << ", y = " << y
140  << ", z = " << z;
141 
142  // Update the vertex position 4-vector
143  fVertexPosition.SetXYZT(x, y, z, 0.); // TODO: add time sampling
144  }
145 
146  // if we're using a fixed vertex position, we don't need to do any sampling
147  return fVertexPosition;
148 }
process_name opflash particleana ie ie ie z
process_name opflash particleana ie x
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
process_name opflash particleana ie ie y
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.

Member Data Documentation

bool evgen::ActiveVolumeVertexSampler::fCheckActive
protected

Definition at line 133 of file ActiveVolumeVertexSampler.h.

std::string evgen::ActiveVolumeVertexSampler::fGeneratorName
protected

Definition at line 115 of file ActiveVolumeVertexSampler.h.

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

Definition at line 119 of file ActiveVolumeVertexSampler.h.

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

Definition at line 122 of file ActiveVolumeVertexSampler.h.

TLorentzVector evgen::ActiveVolumeVertexSampler::fVertexPosition
protected

Definition at line 111 of file ActiveVolumeVertexSampler.h.

vertex_type_t evgen::ActiveVolumeVertexSampler::fVertexType
protected

Definition at line 113 of file ActiveVolumeVertexSampler.h.

double evgen::ActiveVolumeVertexSampler::fXmax
protected

Definition at line 129 of file ActiveVolumeVertexSampler.h.

double evgen::ActiveVolumeVertexSampler::fXmin
protected

Definition at line 125 of file ActiveVolumeVertexSampler.h.

double evgen::ActiveVolumeVertexSampler::fYmax
protected

Definition at line 130 of file ActiveVolumeVertexSampler.h.

double evgen::ActiveVolumeVertexSampler::fYmin
protected

Definition at line 126 of file ActiveVolumeVertexSampler.h.

double evgen::ActiveVolumeVertexSampler::fZmax
protected

Definition at line 131 of file ActiveVolumeVertexSampler.h.

double evgen::ActiveVolumeVertexSampler::fZmin
protected

Definition at line 127 of file ActiveVolumeVertexSampler.h.

evgen::ActiveVolumeVertexSampler::generator_name
Initial value:
{}
void reconfigure(const fhicl::Table<Config>& conf,

Definition at line 98 of file ActiveVolumeVertexSampler.h.

evgen::ActiveVolumeVertexSampler::geom

Definition at line 97 of file ActiveVolumeVertexSampler.h.

evgen::ActiveVolumeVertexSampler::rand_service

Definition at line 97 of file ActiveVolumeVertexSampler.h.


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