LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
LArVoxelData.h
Go to the documentation of this file.
1 
57 
58 #ifndef Simulation_LArVoxelData_h_
59 #define Simulation_LArVoxelData_h_
60 
64 
65 #include <numeric>
66 #include <iostream>
67 
68 namespace sim {
69 
70  class LArVoxelData
71  {
72  public:
73  // Some type definitions to make life easier, and to help "hide"
74  // the implementation details. (If you're not familiar with STL,
75  // you can ignore these definitions.)
88 
89  // Standard constructor and destructor.
90  LArVoxelData();
91  virtual ~LArVoxelData();
92 
93  private:
94  // This is the sum of all the voxel energy that is not assigned
95  // to a particular particle track.
96  mapped_type fenergy; // Energy not assigned to a particular track in a voxel.
97 
98  // If we're able to maintain a track<->energy relationship for
99  // this voxel, this map contains the amount of energy deposited
100  // in this voxel for the given tracks.
101  list_type ftrackEnergy; // Energy assigned to individual particle tracks in a voxel.
102 
103  sim::LArVoxelID fVoxelID; //id for the voxel represented by these data
104 
105 #ifndef __GCCXML__
106 
107  public:
108  // The energy routines described above. (std::accumulate is
109  // defined in <numeric>, and is a standard STL algorithm.)
110  mapped_type AssignedEnergy() const;
111  mapped_type UnassignedEnergy() const;
112  mapped_type Energy() const;
113 
114  size_type NumberParticles() const;
115 
116  const key_type& TrackID( const size_type ) const;
117  const mapped_type& Energy ( const size_type ) const;
118 
119  // Add the energy to the entry with the key; if the key doesn't
120  // exist, create it.
121  void Add( const mapped_type& energy, const key_type& trackID );
122 
123  // If there's no key, it must be "unassigned" energy.
124  void Add( const mapped_type& energy );
125 
126  sim::LArVoxelID VoxelID() const;
127  void SetVoxelID(sim::LArVoxelID voxID);
128 
129  // Arithmetic methods to support the arithmetic that can be
130  // performed by LArVoxelList.
131  void Add( const LArVoxelData& );
133  const LArVoxelData operator+(const LArVoxelData& other) const;
134 
135  LArVoxelData& operator*=( const double& value );
136  const LArVoxelData operator*(const double& value) const;
137 
138  // Just in case: define the result of "scalar * LArVoxelData" to be
139  // the same as "LArVoxelData * scalar".
140  friend const LArVoxelData operator*(const double& value, const LArVoxelData& list);
141 
142  // RemoveTrack any particle with this track ID and move its energy to
143  // the "unassigned" energy; it returns the number of entries
144  // removed. This method is inlined because we need to do this
145  // fast; it's probably being called in a loop over all the
146  // members of a LArVoxelList.
147  size_type RemoveTrack( const int& track );
148 
149  // Remove all particles and move their energies to "unassigned."
150  void RemoveAllTracks();
151 
152  friend std::ostream& operator<< ( std::ostream& output, const LArVoxelData& );
153 
154  // Standard STL methods, to make this class look like an STL map.
155  // Again, if you don't know STL, you can just ignore these
156  // methods. Remember, the "map" portion of this class doesn't
157  // always tell the whole story; you also need to look at the
158  // "unasigned" energy separately.
159  iterator begin();
160  const_iterator begin() const;
161  iterator end();
162  const_iterator end() const;
163  reverse_iterator rbegin();
164  const_reverse_iterator rbegin() const;
165  reverse_iterator rend();
166  const_reverse_iterator rend() const;
167 
168  size_type size() const;
169  bool empty() const;
170  void swap( LArVoxelData& other );
171  void clear();
172 
173  iterator find(const key_type& key);
174  const_iterator find(const key_type& key) const;
175  iterator upper_bound(const key_type& key);
176  const_iterator upper_bound(const key_type& key) const;
177  iterator lower_bound(const key_type& key);
178  const_iterator lower_bound(const key_type& key) const;
179  size_type erase( const key_type& key );
180 
181  mapped_type& operator[](const key_type& key);
182  // My own little addition: operator[] in a const context.
183  const mapped_type& operator[]( const key_type& key) const;
184  mapped_type& at(const key_type& key);
185  const mapped_type& at(const key_type& key) const;
186 
187  // In addition to operator[], include one insert() method. Note
188  // that, as with operator[], there's no check against overwriting
189  // an existing item.
190  void insert( const key_type& key, const mapped_type& value );
191 
192 #endif
193 
194  };
195 
196 } // namespace sim
197 
198 #ifndef __GCCXML__
199 
205 {
206  return std::accumulate( ftrackEnergy.begin(), ftrackEnergy.end(), 0.0,
208 }
210 {
211  return std::accumulate( ftrackEnergy.begin(), ftrackEnergy.end(), fenergy,
213 }
215 {
216  iterator search = ftrackEnergy.find( track );
217  if ( search != ftrackEnergy.end() )
218  {
219  fenergy += (*search).second;
220  ftrackEnergy.erase( search );
221  return 1;
222  }
223  else return 0;
224 }
226 {
227  fenergy = this->Energy();
229 }
231  const sim::LArVoxelData::key_type& trackID )
232 { ftrackEnergy[trackID] += energy; }
234 { fenergy += energy; }
236 {
237  this->Add(other);
238  return *this;
239 }
241 {
242  return LArVoxelData(*this) += other;
243 }
244 inline const sim::LArVoxelData sim::LArVoxelData::operator*(const double& value) const
245 {
246  return LArVoxelData(*this) *= value;
247 }
256 
258 inline bool sim::LArVoxelData::empty() const { return ftrackEnergy.empty(); }
260 {
261  ftrackEnergy.swap( other.ftrackEnergy );
262  double temp = fenergy;
263  fenergy = other.fenergy;
264  other.fenergy = temp;
265 }
268 { return ftrackEnergy.find(key); }
270 { return ftrackEnergy.find(key); }
272 { return ftrackEnergy.upper_bound(key); }
274 { return ftrackEnergy.upper_bound(key); }
276 { return ftrackEnergy.lower_bound(key); }
278 { return ftrackEnergy.lower_bound(key); }
280 { return this->RemoveTrack(key); }
281 
283 { return ftrackEnergy[key]; }
285 { return ftrackEnergy.at(key); }
287 { return ftrackEnergy.at(key); }
289 { return ftrackEnergy.at(key); }
291 { ftrackEnergy[key] = value; }
292 
293 #endif
294 
295 #endif // Simulation_LArVoxelData_h_
void Add(const mapped_type &energy, const key_type &trackID)
Definition: LArVoxelData.h:230
const LArVoxelData operator*(const double &value) const
Definition: LArVoxelData.h:244
size_type erase(const key_type &key)
Definition: LArVoxelData.h:279
list_type::key_compare key_compare
Definition: LArVoxelData.h:86
mapped_type & operator[](const key_type &key)
Definition: LArVoxelData.h:282
iterator end()
Definition: VectorMap.h:198
std::less< int > key_compare
Definition: VectorMap.h:111
sim::LArVoxelID fVoxelID
Definition: LArVoxelData.h:103
iterator lower_bound(const key_type &key)
Definition: LArVoxelData.h:275
list_type::value_type value_type
Definition: LArVoxelData.h:79
void insert(const key_type &key, const mapped_type &value)
Definition: LArVoxelData.h:290
reverse_iterator rbegin()
Definition: VectorMap.h:208
bool empty() const
Definition: LArVoxelData.h:258
mapped_type & at(const key_type &__k)
Definition: VectorMap.h:272
size_type size() const
Definition: LArVoxelData.h:257
reverse_iterator rend()
Definition: VectorMap.h:218
list_type::mapped_type mapped_type
Definition: LArVoxelData.h:78
list_type::const_reverse_iterator const_reverse_iterator
Definition: LArVoxelData.h:83
vector_type::iterator iterator
Definition: VectorMap.h:120
iterator begin()
Definition: LArVoxelData.h:248
const LArVoxelData operator+(const LArVoxelData &other) const
Definition: LArVoxelData.h:240
void erase(iterator __position)
Definition: VectorMap.h:332
mapped_type UnassignedEnergy() const
Definition: LArVoxelData.h:203
list_type ftrackEnergy
Definition: LArVoxelData.h:101
iterator begin()
Definition: VectorMap.h:188
LArVoxelData & operator+=(const LArVoxelData &other)
Definition: LArVoxelData.h:235
mapped_type fenergy
Definition: LArVoxelData.h:96
size_t size() const
Definition: VectorMap.h:233
std::allocator< std::pair< int, double > > allocator_type
Definition: VectorMap.h:112
list_type::reverse_iterator reverse_iterator
Definition: LArVoxelData.h:82
vector_type::const_iterator const_iterator
Definition: VectorMap.h:121
double energy
Definition: plottest35.C:25
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: VectorMap.h:122
util::VectorMap< int, double > list_type
Definition: LArVoxelData.h:76
bool empty() const
Definition: VectorMap.h:228
size_type NumberParticles() const
Definition: LArVoxelData.h:202
mapped_type AssignedEnergy() const
Definition: LArVoxelData.h:204
Monte Carlo Simulation.
std::reverse_iterator< iterator > reverse_iterator
Definition: VectorMap.h:123
reverse_iterator rend()
Definition: LArVoxelData.h:254
LArVoxelData & operator*=(const double &value)
iterator find(const key_type &key)
Definition: VectorMap.h:383
iterator lower_bound(const key_type &__x)
Definition: VectorMap.h:408
std::string value(boost::any const &)
virtual ~LArVoxelData()
list_type::difference_type difference_type
Definition: LArVoxelData.h:85
mapped_type Energy() const
Definition: LArVoxelData.h:209
list_type::key_type key_type
Definition: LArVoxelData.h:77
void swap(LArVoxelData &other)
Definition: LArVoxelData.h:259
reverse_iterator rbegin()
Definition: LArVoxelData.h:252
mapped_type & at(const key_type &key)
Definition: LArVoxelData.h:286
list_type::const_iterator const_iterator
Definition: LArVoxelData.h:81
void swap(VectorMap &other)
Definition: VectorMap.h:357
sim::LArVoxelID VoxelID() const
Definition: LArVoxelData.h:201
iterator upper_bound(const key_type &__x)
Definition: VectorMap.h:418
friend std::ostream & operator<<(std::ostream &output, const LArVoxelData &)
size_type RemoveTrack(const int &track)
Definition: LArVoxelData.h:214
void SetVoxelID(sim::LArVoxelID voxID)
Definition: LArVoxelData.h:200
iterator find(const key_type &key)
Definition: LArVoxelData.h:267
list_type::size_type size_type
Definition: LArVoxelData.h:84
Float_t track
Definition: plot.C:34
Unique identifier for a given LAr voxel.
std::pair< int, double > value_type
Definition: VectorMap.h:110
list_type::allocator_type allocator_type
Definition: LArVoxelData.h:87
const key_type & TrackID(const size_type) const
list_type::iterator iterator
Definition: LArVoxelData.h:80
iterator upper_bound(const key_type &key)
Definition: LArVoxelData.h:271