LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArVoxelList.cxx
Go to the documentation of this file.
1 
9 
10 #include <cmath>
11 #include <iostream>
12 #include <iterator>
13 
14 namespace sim {
15 
16  //----------------------------------------------------------------------------
17  // Nothing special need be done for the constructor or destructor.
19 
20  //----------------------------------------------------------------------------
22 
23  //----------------------------------------------------------------------------
25  {
26  // Go through "other" list, adding its voxels to "this" list.
27  for (const_iterator i = other.m_voxelList.begin(); i != m_voxelList.end(); ++i) {
28  m_voxelList[(*i).first] += (*i).second;
29  }
30  }
31 
32  //----------------------------------------------------------------------------
34  {
35  // Multiply each voxel energy by the value.
36  for (iterator i = m_voxelList.begin(); i != m_voxelList.end(); ++i) {
37  (*i).second *= value;
38  }
39  return (*this);
40  }
41 
42  //----------------------------------------------------------------------------
45  const LArVoxelList operator*(const double& value, const LArVoxelList& list)
46  {
47  return LArVoxelList(list) *= value;
48  }
49 
50  //----------------------------------------------------------------------------
52  void LArVoxelList::Cut(const double& cut)
53  {
54  // The safest way to do this is to create a list of voxel IDs that
55  // fail the cut, then delete those IDs.
56 
57  // Define a list of IDs.
58  typedef std::vector<key_type> keyList_type;
59  keyList_type keyList;
60 
61  // Add each ID that fails the cut to the list.
62  for (const_iterator i = m_voxelList.begin(); i != m_voxelList.end(); ++i) {
63  if ((*i).second.Energy() < cut) { keyList.push_back((*i).first); }
64  }
65 
66  // Go through the list, deleting the voxels that are on the list.
67  for (keyList_type::const_iterator i = keyList.begin(); i != keyList.end(); ++i) {
68  m_voxelList.erase((*i));
69  }
70  }
71 
72  //----------------------------------------------------------------------------
74  {
75  const_iterator i = m_voxelList.begin();
76  std::advance(i, index);
77  return (*i).first;
78  }
79 
80  //----------------------------------------------------------------------------
81  double LArVoxelList::Energy(const size_type index) const
82  {
83  const_iterator i = m_voxelList.begin();
84  std::advance(i, index);
85  return (*i).second.Energy();
86  }
87 
88  //----------------------------------------------------------------------------
89  std::ostream& operator<<(std::ostream& output, const LArVoxelList& list)
90  {
91  // Determine a field width for the voxel number.
92  LArVoxelList::size_type numberOfVoxels = list.size();
93  int numberOfDigits = (int)std::log10((double)numberOfVoxels) + 1;
94 
95  // A simple header.
96  output.width(numberOfDigits);
97  output << "#"
98  << ": < ID, energy >" << std::endl;
99 
100  // Write each voxel on a separate line.
101  LArVoxelList::size_type nVoxel = 0;
102  for (LArVoxelList::const_iterator voxel = list.begin(); voxel != list.end();
103  ++voxel, ++nVoxel) {
104  output.width(numberOfDigits);
105  output << nVoxel << ": "
106  << "< " << (*voxel).first << ", " << (*voxel).second << " >\n";
107  }
108 
109  return output;
110  }
111 
112 } // namespace sim
const LArVoxelList operator*(const double &value) const
Definition: LArVoxelList.h:113
size_type size() const
Definition: LArVoxelList.h:139
Container of LAr voxel information.
intermediate_table::const_iterator const_iterator
list_type m_voxelList
A sorted list of <LArVoxelID,double> pairs = (voxel ID, energy)
Definition: LArVoxelList.h:166
iterator begin()
Definition: LArVoxelList.h:130
list_type::const_iterator const_iterator
Definition: LArVoxelList.h:78
friend std::ostream & operator<<(std::ostream &output, const LArVoxelList &)
double Energy(const size_type) const
void Cut(const double &)
Apply an energy cut to the voxels.
list_type::iterator iterator
Definition: LArVoxelList.h:77
Monte Carlo Simulation.
double value
Definition: spectrum.C:18
list_type::size_type size_type
Definition: LArVoxelList.h:81
LArVoxelList & operator*=(const double &value)
list_type::key_type key_type
Definition: LArVoxelList.h:74
void Add(const key_type &key, const double &energy)
Definition: LArVoxelList.h:93
const key_type & ID(const size_type) const
virtual ~LArVoxelList()