All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArVoxelCalculator.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file LArVoxelCalculator_service.cc
3 /// \brief Encapsulates calculation of LArVoxelID and LArVoxel parameters
4 ///
5 /// \author brebel@fnal.gov
6 ////////////////////////////////////////////////////////////////////////
7 
8 /// This service encapsulates the calculations associated with
9 /// computing the LArVoxelID, and provides access to the any LArVoxel
10 /// parameters from the input file(s).
11 
12 /// Definition: "Voxels" are three-dimensional "pixels"; basically
13 /// they divide the energy deposition in the LAr into (x,y,z) cubes.
14 /// Well, hyper-cubes actually, since we have to potentially include
15 /// divisions in time as well.
16 
17 // Framework includes
19 
20 #include "fhiclcpp/ParameterSet.h"
21 
22 #include <cmath>
23 
24 namespace sim {
25 
26  //----------------------------------------------------------------------------
27  LArVoxelCalculator::LArVoxelCalculator(fhicl::ParameterSet const& pset)
28  : m_voxelSize{pset.get<double>("VoxelSizeX"),
29  pset.get<double>("VoxelSizeY"),
30  pset.get<double>("VoxelSizeZ"),
31  pset.get<double>("VoxelSizeT")}
32  , m_voxelOffset{pset.get<double>("VoxelOffsetX"),
33  pset.get<double>("VoxelOffsetY"),
34  pset.get<double>("VoxelOffsetZ"),
35  pset.get<double>("VoxelOffsetT")}
36  , m_energyCut{pset.get<double>("VoxelEnergyCut")}
37  {}
38 
39  //----------------------------------------------------------------------------
40  /// Returns a Monte-Carlo step size that's reasonable to use so that
41  /// each segment of a track will be contained within a single voxel.
43  {
44  return std::min( m_voxelSize[0], std::min( m_voxelSize[1], m_voxelSize[2] ) );
45  }
46 
47  //----------------------------------------------------------------------------
48  /// Convert a co-ordinate axis (x, y, z, or t) into a bin number.
49  /// The first argument is the axis (x=0, y=1, z=2, t=3) and the
50  /// second is the value on that axis.
51  int LArVoxelCalculator::AxisToBin( const int axis,
52  const double coord ) const
53  {
54  // We have to be careful of how to handle the case when coord -
55  // offset < 0. The standard floor() function rounds the number in
56  // the correct direction.
57  return static_cast<int>( floor( ( coord - m_voxelOffset[axis] ) / m_voxelSize[axis] ) );
58  }
59 
60  //----------------------------------------------------------------------------
61  /// Get the value of an axis at the center of the given bin. The
62  /// first argument is the axis (x=0, y=1, z=2, t=3) and the second
63  /// is the bin number on that axis.
64  double LArVoxelCalculator::BinToAxis( const int axis,
65  const int bin ) const
66  {
67  return ( static_cast<double>(bin) + 0.5 ) * m_voxelSize[axis] + m_voxelOffset[axis];
68  }
69 
70 } // namespace sim
vector_type const m_voxelOffset
vector_type const m_voxelSize
The sizes of the voxels in (x,y,z,t). Units are (mm,ns).
Encapsulates calculation of LArVoxelID and LArVoxel parameters.
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
double SuggestedStepSize() const
int AxisToBin(const int, const double) const
double BinToAxis(const int, const int) const
LArVoxelCalculator(fhicl::ParameterSet const &pset)