All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArVoxelList.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file LArVoxelList.h
3 /// \brief Container of LAr voxel information
4 ///
5 /// \author seligman@nevis.columbia.edu
6 ////////////////////////////////////////////////////////////////////////
7 
8 /// A container for LAr voxel information. Although there's nothing
9 /// in the class below that assumes units, the standard for LArSoft is
10 /// that distances are in cm, and energy is in GeV.
11 ///
12 /// It acts like a map<LArVoxelID,LArVoxelData>, but with additional
13 /// features:
14 ///
15 /// - An Add(LArVoxelList) method allows you to add one LArVoxelList to
16 /// another. Voxels with the same ID are added together; otherwise
17 /// the lists are merged. Usage:
18 /// sim::LArVoxelList a,b;
19 /// a.Add(b);
20 /// There's even an operator+ so you can write "a += b", but be
21 /// careful about wasting memory if you write "a = a+b". Of
22 /// course, you can do:
23 /// sim:LArVoxelList c = a + b;
24 ///
25 /// - An operator* so you can scale all the voxel energies for
26 /// calibration:
27 /// sim::LArVoxelList c;
28 /// double calib = 1.00000012
29 /// c *= calib;
30 /// c = c * calib; // same as above, but wastes memory
31 /// sim::LArVoxelList d = c * calib;
32 /// (Yes, I know we probably won't do calibration in this way,
33 /// but it's here if you need it.)
34 ///
35 /// - A method Cut(double) that will remove all voxels with energy
36 /// less than the argument.
37 ///
38 /// - Methods ID(int) and Energy(int) for those who are unfamiliar with the
39 /// concept of "first" and "second" as used with STL maps:
40 /// sim::LArVoxelList* voxelList = // ...;
41 /// int numberOfVoxels = voxelList->size();
42 /// for (int i=0; i<numberOfVoxels; ++i)
43 /// {
44 /// sim::LArVoxelID = voxelList->ID(i);
45 /// double energy = voxelList->Energy(i);
46 /// }
47 /// The STL equivalent to the above statements (more efficient):
48 /// sim::LArVoxelList* voxelList = // ... ;
49 /// for ( sim::LArVoxelList::const_iterator i = voxelList->begin();
50 /// i != voxelList->end(); ++i )
51 /// {
52 /// sim::LArVoxelID = (*i).first;
53 /// double energy = (*i).second.Energy();
54 /// }
55 ///
56 /// - operator<< method for ROOT display and ease of debugging.
57 
58 #ifndef LARVOXELLIST_H
59 #define LARVOXELLIST_H
60 
63 
64 #include <map>
65 
66 namespace sim {
67 
69  {
70  public:
71  /// Some type definitions to make life easier, and to help "hide"
72  /// the implementation details. (If you're not familiar with STL,
73  /// you can ignore these definitions.)
74  typedef std::map<LArVoxelID, LArVoxelData> list_type;
75  typedef list_type::key_type key_type;
76  typedef list_type::mapped_type mapped_type;
77  typedef list_type::value_type value_type;
78  typedef list_type::iterator iterator;
79  typedef list_type::const_iterator const_iterator;
80  typedef list_type::reverse_iterator reverse_iterator;
81  typedef list_type::const_reverse_iterator const_reverse_iterator;
82  typedef list_type::size_type size_type;
83  typedef list_type::difference_type difference_type;
84  typedef list_type::key_compare key_compare;
85  typedef list_type::allocator_type allocator_type;
86 
87  // Standard constructor and destructor.
88  LArVoxelList();
89  virtual ~LArVoxelList();
90 
91  // Add the energy to the entry with the key; if the key doesn't
92  // exist, create it. Allow the addition both with and without a
93  // particle's track ID for LArVoxelData.
94  void Add( const key_type& key, const double& energy ) { m_voxelList[key].Add(energy); }
95  void Add( const key_type& key, const double& energy, const int& id ) { m_voxelList[key].Add(energy,id); }
96 
97  // The arithmetic methods "advertised" in the class description
98  // above.
99  void Add( const LArVoxelList& );
101  {
102  this->Add(other);
103  return *this;
104  }
105  const LArVoxelList operator+(const LArVoxelList& other) const
106  {
107  return LArVoxelList(*this) += other;
108  }
109 
110  LArVoxelList& operator*=( const double& value );
111  const LArVoxelList operator* (const double& value) const
112  {
113  return LArVoxelList(*this) *= value;
114  }
115  // Just in case: define the result of "scalar * LArVoxelList" to be
116  // the same as "LArVoxelList * scalar".
117  friend const LArVoxelList operator*(const double& value, const LArVoxelList& list);
118 
119  // Apply a threshold cut to the voxels in the list, removing all
120  // those that fall below the cut.
121  void Cut( const double& );
122 
123  const key_type& ID( const size_type ) const;
124  double Energy( const size_type ) const;
125 
126  friend std::ostream& operator<< ( std::ostream& output, const LArVoxelList& );
127 
128  // Standard STL methods, to make this class look like an STL map.
129  // Again, if you don't know STL, you can just ignore these
130  // methods.
131  iterator begin() { return m_voxelList.begin(); }
132  const_iterator begin() const { return m_voxelList.begin(); }
133  iterator end() { return m_voxelList.end(); }
134  const_iterator end() const { return m_voxelList.end(); }
135  reverse_iterator rbegin() { return m_voxelList.rbegin(); }
136  const_reverse_iterator rbegin() const { return m_voxelList.rbegin(); }
137  reverse_iterator rend() { return m_voxelList.rend(); }
138  const_reverse_iterator rend() const { return m_voxelList.rend(); }
139 
140  size_type size() const { return m_voxelList.size(); }
141  bool empty() const { return m_voxelList.empty(); }
142  void swap( LArVoxelList& other ) { m_voxelList.swap( other.m_voxelList ); }
143  void clear() { m_voxelList.clear(); }
144 
145  iterator find(const key_type& key) { return m_voxelList.find(key); }
146  const_iterator find(const key_type& key) const { return m_voxelList.find(key); }
147  iterator upper_bound(const key_type& key) { return m_voxelList.upper_bound(key); }
148  const_iterator upper_bound(const key_type& key) const { return m_voxelList.upper_bound(key); }
149  iterator lower_bound(const key_type& key) { return m_voxelList.lower_bound(key); }
150  const_iterator lower_bound(const key_type& key) const { return m_voxelList.lower_bound(key); }
151 
152  mapped_type& operator[](const key_type& key) { return m_voxelList[key]; }
153  // My own little addition: operator[] in a const context.
154  const mapped_type& operator[]( const key_type& key ) const { return m_voxelList.at(key); }
155  mapped_type& at(const key_type& key) { return m_voxelList.at(key); }
156  const mapped_type& at(const key_type& key) const { return m_voxelList.at(key); }
157 
158  // In addition to operator[], include one insert() method for
159  // anyone who wants to include a LArVoxelID / LArVoxelData pair
160  // directly. Note that, as with operator[], there's no check
161  // against overwriting an existing item.
162  void insert( const key_type& key, const mapped_type& value ) { m_voxelList[key] = value; }
163 
164  size_type erase( const key_type& key ) { return m_voxelList.erase(key); }
165 
166  private:
167  list_type m_voxelList; ///< A sorted list of <LArVoxelID,double> pairs = (voxel ID, energy)
168 
169  };
170 
171 } // namespace sim
172 
173 #endif // LARVOXELLIST_H
174 
const LArVoxelList operator*(const double &value) const
Definition: LArVoxelList.h:111
const mapped_type & at(const key_type &key) const
Definition: LArVoxelList.h:156
list_type::mapped_type mapped_type
Definition: LArVoxelList.h:76
size_type size() const
Definition: LArVoxelList.h:140
void insert(const key_type &key, const mapped_type &value)
Definition: LArVoxelList.h:162
list_type::reverse_iterator reverse_iterator
Definition: LArVoxelList.h:80
reverse_iterator rbegin()
Definition: LArVoxelList.h:135
void swap(LArVoxelList &other)
Definition: LArVoxelList.h:142
list_type::key_compare key_compare
Definition: LArVoxelList.h:84
list_type m_voxelList
A sorted list of &lt;LArVoxelID,double&gt; pairs = (voxel ID, energy)
Definition: LArVoxelList.h:167
const mapped_type & operator[](const key_type &key) const
Definition: LArVoxelList.h:154
std::map< LArVoxelID, LArVoxelData > list_type
Definition: LArVoxelList.h:74
iterator begin()
Definition: LArVoxelList.h:131
LArVoxelList & operator+=(const LArVoxelList &other)
Definition: LArVoxelList.h:100
void Add(const key_type &key, const double &energy, const int &id)
Definition: LArVoxelList.h:95
list_type::const_iterator const_iterator
Definition: LArVoxelList.h:79
friend std::ostream & operator<<(std::ostream &output, const LArVoxelList &)
double Energy(const size_type) const
list_type::value_type value_type
Definition: LArVoxelList.h:77
Encapsulates the information we want store for a voxel.
list_type::const_reverse_iterator const_reverse_iterator
Definition: LArVoxelList.h:81
iterator find(const key_type &key)
Definition: LArVoxelList.h:145
list_type::difference_type difference_type
Definition: LArVoxelList.h:83
reverse_iterator rend()
Definition: LArVoxelList.h:137
bool empty() const
Definition: LArVoxelList.h:141
void Cut(const double &)
Apply an energy cut to the voxels.
list_type::iterator iterator
Definition: LArVoxelList.h:78
iterator upper_bound(const key_type &key)
Definition: LArVoxelList.h:147
const_iterator upper_bound(const key_type &key) const
Definition: LArVoxelList.h:148
const_iterator begin() const
Definition: LArVoxelList.h:132
list_type::size_type size_type
Definition: LArVoxelList.h:82
LArVoxelList & operator*=(const double &value)
const_iterator find(const key_type &key) const
Definition: LArVoxelList.h:146
const_iterator end() const
Definition: LArVoxelList.h:134
list_type::key_type key_type
Definition: LArVoxelList.h:75
const_reverse_iterator rbegin() const
Definition: LArVoxelList.h:136
const_iterator lower_bound(const key_type &key) const
Definition: LArVoxelList.h:150
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output
size_type erase(const key_type &key)
Definition: LArVoxelList.h:164
void Add(const key_type &key, const double &energy)
Definition: LArVoxelList.h:94
temporary value
iterator lower_bound(const key_type &key)
Definition: LArVoxelList.h:149
mapped_type & at(const key_type &key)
Definition: LArVoxelList.h:155
const key_type & ID(const size_type) const
mapped_type & operator[](const key_type &key)
Definition: LArVoxelList.h:152
Unique identifier for a given LAr voxel.
const_reverse_iterator rend() const
Definition: LArVoxelList.h:138
list_type::allocator_type allocator_type
Definition: LArVoxelList.h:85
const LArVoxelList operator+(const LArVoxelList &other) const
Definition: LArVoxelList.h:105
list
Definition: file_to_url.sh:28
virtual ~LArVoxelList()