LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArVoxelList.h
Go to the documentation of this file.
1 
57 
58 #ifndef LARVOXELLIST_H
59 #define LARVOXELLIST_H
60 
63 
64 #include <map>
65 
66 namespace sim {
67 
68  class LArVoxelList {
69  public:
73  typedef std::map<LArVoxelID, LArVoxelData> list_type;
74  typedef list_type::key_type key_type;
75  typedef list_type::mapped_type mapped_type;
76  typedef list_type::value_type value_type;
79  typedef list_type::reverse_iterator reverse_iterator;
80  typedef list_type::const_reverse_iterator const_reverse_iterator;
81  typedef list_type::size_type size_type;
82  typedef list_type::difference_type difference_type;
83  typedef list_type::key_compare key_compare;
84  typedef list_type::allocator_type allocator_type;
85 
86  // Standard constructor and destructor.
87  LArVoxelList();
88  virtual ~LArVoxelList();
89 
90  // Add the energy to the entry with the key; if the key doesn't
91  // exist, create it. Allow the addition both with and without a
92  // particle's track ID for LArVoxelData.
93  void Add(const key_type& key, const double& energy) { m_voxelList[key].Add(energy); }
94  void Add(const key_type& key, const double& energy, const int& id)
95  {
96  m_voxelList[key].Add(energy, id);
97  }
98 
99  // The arithmetic methods "advertised" in the class description
100  // above.
101  void Add(const LArVoxelList&);
103  {
104  this->Add(other);
105  return *this;
106  }
108  {
109  return LArVoxelList(*this) += other;
110  }
111 
112  LArVoxelList& operator*=(const double& value);
113  const LArVoxelList operator*(const double& value) const { return LArVoxelList(*this) *= value; }
114  // Just in case: define the result of "scalar * LArVoxelList" to be
115  // the same as "LArVoxelList * scalar".
116  friend const LArVoxelList operator*(const double& value, const LArVoxelList& list);
117 
118  // Apply a threshold cut to the voxels in the list, removing all
119  // those that fall below the cut.
120  void Cut(const double&);
121 
122  const key_type& ID(const size_type) const;
123  double Energy(const size_type) const;
124 
125  friend std::ostream& operator<<(std::ostream& output, const LArVoxelList&);
126 
127  // Standard STL methods, to make this class look like an STL map.
128  // Again, if you don't know STL, you can just ignore these
129  // methods.
130  iterator begin() { return m_voxelList.begin(); }
131  const_iterator begin() const { return m_voxelList.begin(); }
132  iterator end() { return m_voxelList.end(); }
133  const_iterator end() const { return m_voxelList.end(); }
134  reverse_iterator rbegin() { return m_voxelList.rbegin(); }
135  const_reverse_iterator rbegin() const { return m_voxelList.rbegin(); }
136  reverse_iterator rend() { return m_voxelList.rend(); }
137  const_reverse_iterator rend() const { return m_voxelList.rend(); }
138 
139  size_type size() const { return m_voxelList.size(); }
140  bool empty() const { return m_voxelList.empty(); }
142  void clear() { m_voxelList.clear(); }
143 
144  iterator find(const key_type& key) { return m_voxelList.find(key); }
145  const_iterator find(const key_type& key) const { return m_voxelList.find(key); }
146  iterator upper_bound(const key_type& key) { return m_voxelList.upper_bound(key); }
147  const_iterator upper_bound(const key_type& key) const { return m_voxelList.upper_bound(key); }
148  iterator lower_bound(const key_type& key) { return m_voxelList.lower_bound(key); }
149  const_iterator lower_bound(const key_type& key) const { return m_voxelList.lower_bound(key); }
150 
151  mapped_type& operator[](const key_type& key) { return m_voxelList[key]; }
152  // My own little addition: operator[] in a const context.
153  const mapped_type& operator[](const key_type& key) const { return m_voxelList.at(key); }
154  mapped_type& at(const key_type& key) { return m_voxelList.at(key); }
155  const mapped_type& at(const key_type& key) const { return m_voxelList.at(key); }
156 
157  // In addition to operator[], include one insert() method for
158  // anyone who wants to include a LArVoxelID / LArVoxelData pair
159  // directly. Note that, as with operator[], there's no check
160  // against overwriting an existing item.
161  void insert(const key_type& key, const mapped_type& value) { m_voxelList[key] = value; }
162 
163  size_type erase(const key_type& key) { return m_voxelList.erase(key); }
164 
165  private:
166  list_type m_voxelList;
167  };
168 
169 } // namespace sim
170 
171 #endif // LARVOXELLIST_H
intermediate_table::iterator iterator
const LArVoxelList operator*(const double &value) const
Definition: LArVoxelList.h:113
const mapped_type & at(const key_type &key) const
Definition: LArVoxelList.h:155
list_type::mapped_type mapped_type
Definition: LArVoxelList.h:75
size_type size() const
Definition: LArVoxelList.h:139
void insert(const key_type &key, const mapped_type &value)
Definition: LArVoxelList.h:161
list_type::reverse_iterator reverse_iterator
Definition: LArVoxelList.h:79
intermediate_table::const_iterator const_iterator
reverse_iterator rbegin()
Definition: LArVoxelList.h:134
void swap(LArVoxelList &other)
Definition: LArVoxelList.h:141
list_type::key_compare key_compare
Definition: LArVoxelList.h:83
list_type m_voxelList
A sorted list of <LArVoxelID,double> pairs = (voxel ID, energy)
Definition: LArVoxelList.h:166
const mapped_type & operator[](const key_type &key) const
Definition: LArVoxelList.h:153
std::map< LArVoxelID, LArVoxelData > list_type
Definition: LArVoxelList.h:73
iterator begin()
Definition: LArVoxelList.h:130
LArVoxelList & operator+=(const LArVoxelList &other)
Definition: LArVoxelList.h:102
void Add(const key_type &key, const double &energy, const int &id)
Definition: LArVoxelList.h:94
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
list_type::value_type value_type
Definition: LArVoxelList.h:76
Encapsulates the information we want store for a voxel.
list_type::const_reverse_iterator const_reverse_iterator
Definition: LArVoxelList.h:80
iterator find(const key_type &key)
Definition: LArVoxelList.h:144
double energy
Definition: plottest35.C:25
list_type::difference_type difference_type
Definition: LArVoxelList.h:82
reverse_iterator rend()
Definition: LArVoxelList.h:136
bool empty() const
Definition: LArVoxelList.h:140
void Cut(const double &)
Apply an energy cut to the voxels.
list_type::iterator iterator
Definition: LArVoxelList.h:77
Monte Carlo Simulation.
iterator upper_bound(const key_type &key)
Definition: LArVoxelList.h:146
const_iterator upper_bound(const key_type &key) const
Definition: LArVoxelList.h:147
const_iterator begin() const
Definition: LArVoxelList.h:131
double value
Definition: spectrum.C:18
list_type::size_type size_type
Definition: LArVoxelList.h:81
LArVoxelList & operator*=(const double &value)
const_iterator find(const key_type &key) const
Definition: LArVoxelList.h:145
const_iterator end() const
Definition: LArVoxelList.h:133
list_type::key_type key_type
Definition: LArVoxelList.h:74
const_reverse_iterator rbegin() const
Definition: LArVoxelList.h:135
const_iterator lower_bound(const key_type &key) const
Definition: LArVoxelList.h:149
size_type erase(const key_type &key)
Definition: LArVoxelList.h:163
void Add(const key_type &key, const double &energy)
Definition: LArVoxelList.h:93
iterator lower_bound(const key_type &key)
Definition: LArVoxelList.h:148
mapped_type & at(const key_type &key)
Definition: LArVoxelList.h:154
const key_type & ID(const size_type) const
mapped_type & operator[](const key_type &key)
Definition: LArVoxelList.h:151
Unique identifier for a given LAr voxel.
const_reverse_iterator rend() const
Definition: LArVoxelList.h:137
list_type::allocator_type allocator_type
Definition: LArVoxelList.h:84
const LArVoxelList operator+(const LArVoxelList &other) const
Definition: LArVoxelList.h:107
virtual ~LArVoxelList()