LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 <iosfwd>
66 #include <numeric>
67 
68 namespace sim {
69 
70  class LArVoxelData {
71  public:
72  // Some type definitions to make life easier, and to help "hide"
73  // the implementation details. (If you're not familiar with STL,
74  // you can ignore these definitions.)
87 
88  // Standard constructor and destructor.
89  LArVoxelData();
90  virtual ~LArVoxelData();
91 
92  private:
93  // This is the sum of all the voxel energy that is not assigned
94  // to a particular particle track.
95  mapped_type fenergy; // Energy not assigned to a particular track in a voxel.
96 
97  // If we're able to maintain a track<->energy relationship for
98  // this voxel, this map contains the amount of energy deposited
99  // in this voxel for the given tracks.
100  list_type ftrackEnergy; // Energy assigned to individual particle tracks in a voxel.
101 
102  sim::LArVoxelID fVoxelID; //id for the voxel represented by these data
103 
104  public:
105  // The energy routines described above. (std::accumulate is
106  // defined in <numeric>, and is a standard STL algorithm.)
107  mapped_type AssignedEnergy() const;
108  mapped_type UnassignedEnergy() const;
109  mapped_type Energy() const;
110 
111  size_type NumberParticles() const;
112 
113  const key_type& TrackID(const size_type) const;
114  const mapped_type& Energy(const size_type) const;
115 
116  // Add the energy to the entry with the key; if the key doesn't
117  // exist, create it.
118  void Add(const mapped_type& energy, const key_type& trackID);
119 
120  // If there's no key, it must be "unassigned" energy.
121  void Add(const mapped_type& energy);
122 
123  sim::LArVoxelID VoxelID() const;
124  void SetVoxelID(sim::LArVoxelID voxID);
125 
126  // Arithmetic methods to support the arithmetic that can be
127  // performed by LArVoxelList.
128  void Add(const LArVoxelData&);
130  const LArVoxelData operator+(const LArVoxelData& other) const;
131 
132  LArVoxelData& operator*=(const double& value);
133  const LArVoxelData operator*(const double& value) const;
134 
135  // Just in case: define the result of "scalar * LArVoxelData" to be
136  // the same as "LArVoxelData * scalar".
137  friend const LArVoxelData operator*(const double& value, const LArVoxelData& list);
138 
139  // RemoveTrack any particle with this track ID and move its energy to
140  // the "unassigned" energy; it returns the number of entries
141  // removed. This method is inlined because we need to do this
142  // fast; it's probably being called in a loop over all the
143  // members of a LArVoxelList.
144  size_type RemoveTrack(const int& track);
145 
146  // Remove all particles and move their energies to "unassigned."
147  void RemoveAllTracks();
148 
149  friend std::ostream& operator<<(std::ostream& output, const LArVoxelData&);
150 
151  // Standard STL methods, to make this class look like an STL map.
152  // Again, if you don't know STL, you can just ignore these
153  // methods. Remember, the "map" portion of this class doesn't
154  // always tell the whole story; you also need to look at the
155  // "unasigned" energy separately.
156  iterator begin();
157  const_iterator begin() const;
158  iterator end();
159  const_iterator end() const;
160  reverse_iterator rbegin();
161  const_reverse_iterator rbegin() const;
162  reverse_iterator rend();
163  const_reverse_iterator rend() const;
164 
165  size_type size() const;
166  bool empty() const;
167  void swap(LArVoxelData& other);
168  void clear();
169 
170  iterator find(const key_type& key);
171  const_iterator find(const key_type& key) const;
172  iterator upper_bound(const key_type& key);
173  const_iterator upper_bound(const key_type& key) const;
174  iterator lower_bound(const key_type& key);
175  const_iterator lower_bound(const key_type& key) const;
176  size_type erase(const key_type& key);
177 
178  mapped_type& operator[](const key_type& key);
179  // My own little addition: operator[] in a const context.
180  const mapped_type& operator[](const key_type& key) const;
181  mapped_type& at(const key_type& key);
182  const mapped_type& at(const key_type& key) const;
183 
184  // In addition to operator[], include one insert() method. Note
185  // that, as with operator[], there's no check against overwriting
186  // an existing item.
187  void insert(const key_type& key, const mapped_type& value);
188  };
189 
190 } // namespace sim
191 
193 {
194  fVoxelID = voxID;
195 }
197 {
198  return fVoxelID;
199 }
201 {
202  return size();
203 }
205 {
206  return fenergy;
207 }
209 {
210  return std::accumulate(ftrackEnergy.begin(),
211  ftrackEnergy.end(),
212  0.0,
214 }
216 {
217  return std::accumulate(ftrackEnergy.begin(),
218  ftrackEnergy.end(),
219  fenergy,
221 }
223 {
224  iterator search = ftrackEnergy.find(track);
225  if (search != ftrackEnergy.end()) {
226  fenergy += (*search).second;
227  ftrackEnergy.erase(search);
228  return 1;
229  }
230  else
231  return 0;
232 }
234 {
235  fenergy = this->Energy();
237 }
239  const sim::LArVoxelData::key_type& trackID)
240 {
241  ftrackEnergy[trackID] += energy;
242 }
244 {
245  fenergy += energy;
246 }
248 {
249  this->Add(other);
250  return *this;
251 }
253 {
254  return LArVoxelData(*this) += other;
255 }
256 inline const sim::LArVoxelData sim::LArVoxelData::operator*(const double& value) const
257 {
258  return LArVoxelData(*this) *= value;
259 }
261 {
262  return ftrackEnergy.begin();
263 }
265 {
266  return ftrackEnergy.begin();
267 }
269 {
270  return ftrackEnergy.end();
271 }
273 {
274  return ftrackEnergy.end();
275 }
277 {
278  return ftrackEnergy.rbegin();
279 }
281 {
282  return ftrackEnergy.rbegin();
283 }
285 {
286  return ftrackEnergy.rend();
287 }
289 {
290  return ftrackEnergy.rend();
291 }
292 
294 {
295  return ftrackEnergy.size();
296 }
297 inline bool sim::LArVoxelData::empty() const
298 {
299  return ftrackEnergy.empty();
300 }
302 {
304  double temp = fenergy;
305  fenergy = other.fenergy;
306  other.fenergy = temp;
307 }
309 {
310  fenergy = 0.;
312 }
314 {
315  return ftrackEnergy.find(key);
316 }
318  const sim::LArVoxelData::key_type& key) const
319 {
320  return ftrackEnergy.find(key);
321 }
323  const sim::LArVoxelData::key_type& key)
324 {
325  return ftrackEnergy.upper_bound(key);
326 }
328  const sim::LArVoxelData::key_type& key) const
329 {
330  return ftrackEnergy.upper_bound(key);
331 }
333  const sim::LArVoxelData::key_type& key)
334 {
335  return ftrackEnergy.lower_bound(key);
336 }
338  const sim::LArVoxelData::key_type& key) const
339 {
340  return ftrackEnergy.lower_bound(key);
341 }
343 {
344  return this->RemoveTrack(key);
345 }
346 
348  const sim::LArVoxelData::key_type& key)
349 {
350  return ftrackEnergy[key];
351 }
353  const sim::LArVoxelData::key_type& key) const
354 {
355  return ftrackEnergy.at(key);
356 }
358 {
359  return ftrackEnergy.at(key);
360 }
362  const sim::LArVoxelData::key_type& key) const
363 {
364  return ftrackEnergy.at(key);
365 }
368 {
369  ftrackEnergy[key] = value;
370 }
371 
372 #endif // Simulation_LArVoxelData_h_
void Add(const mapped_type &energy, const key_type &trackID)
Definition: LArVoxelData.h:238
const LArVoxelData operator*(const double &value) const
Definition: LArVoxelData.h:256
size_type erase(const key_type &key)
Definition: LArVoxelData.h:342
list_type::key_compare key_compare
Definition: LArVoxelData.h:85
std::allocator< std::pair< int, double > > allocator_type
Definition: VectorMap.h:112
mapped_type & operator[](const key_type &key)
Definition: LArVoxelData.h:347
iterator end()
Definition: VectorMap.h:187
std::less< int > key_compare
Definition: VectorMap.h:111
sim::LArVoxelID fVoxelID
Definition: LArVoxelData.h:102
iterator lower_bound(const key_type &key)
Definition: LArVoxelData.h:332
list_type::value_type value_type
Definition: LArVoxelData.h:78
void insert(const key_type &key, const mapped_type &value)
Definition: LArVoxelData.h:366
reverse_iterator rbegin()
Definition: VectorMap.h:191
bool empty() const
Definition: LArVoxelData.h:297
mapped_type & at(const key_type &__k)
Definition: VectorMap.h:234
size_type size() const
Definition: LArVoxelData.h:293
reverse_iterator rend()
Definition: VectorMap.h:195
list_type::mapped_type mapped_type
Definition: LArVoxelData.h:77
list_type::const_reverse_iterator const_reverse_iterator
Definition: LArVoxelData.h:82
vector_type::iterator iterator
Definition: VectorMap.h:120
iterator begin()
Definition: LArVoxelData.h:260
const LArVoxelData operator+(const LArVoxelData &other) const
Definition: LArVoxelData.h:252
void erase(iterator __position)
Definition: VectorMap.h:293
mapped_type UnassignedEnergy() const
Definition: LArVoxelData.h:204
list_type ftrackEnergy
Definition: LArVoxelData.h:100
iterator begin()
Definition: VectorMap.h:183
LArVoxelData & operator+=(const LArVoxelData &other)
Definition: LArVoxelData.h:247
mapped_type fenergy
Definition: LArVoxelData.h:95
size_t size() const
Definition: VectorMap.h:201
list_type::reverse_iterator reverse_iterator
Definition: LArVoxelData.h:81
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:75
bool empty() const
Definition: VectorMap.h:199
size_type NumberParticles() const
Definition: LArVoxelData.h:200
mapped_type AssignedEnergy() const
Definition: LArVoxelData.h:208
Monte Carlo Simulation.
double value
Definition: spectrum.C:18
std::reverse_iterator< iterator > reverse_iterator
Definition: VectorMap.h:123
reverse_iterator rend()
Definition: LArVoxelData.h:284
LArVoxelData & operator*=(const double &value)
iterator find(const key_type &key)
Definition: VectorMap.h:329
iterator lower_bound(const key_type &__x)
Definition: VectorMap.h:349
virtual ~LArVoxelData()
list_type::difference_type difference_type
Definition: LArVoxelData.h:84
mapped_type Energy() const
Definition: LArVoxelData.h:215
list_type::key_type key_type
Definition: LArVoxelData.h:76
void swap(LArVoxelData &other)
Definition: LArVoxelData.h:301
reverse_iterator rbegin()
Definition: LArVoxelData.h:276
mapped_type & at(const key_type &key)
Definition: LArVoxelData.h:357
list_type::const_iterator const_iterator
Definition: LArVoxelData.h:80
void swap(VectorMap &other)
Definition: VectorMap.h:312
sim::LArVoxelID VoxelID() const
Definition: LArVoxelData.h:196
iterator upper_bound(const key_type &__x)
Definition: VectorMap.h:359
friend std::ostream & operator<<(std::ostream &output, const LArVoxelData &)
size_type RemoveTrack(const int &track)
Definition: LArVoxelData.h:222
void SetVoxelID(sim::LArVoxelID voxID)
Definition: LArVoxelData.h:192
iterator find(const key_type &key)
Definition: LArVoxelData.h:313
list_type::size_type size_type
Definition: LArVoxelData.h:83
Float_t track
Definition: plot.C:35
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:86
const key_type & TrackID(const size_type) const
list_type::iterator iterator
Definition: LArVoxelData.h:79
iterator upper_bound(const key_type &key)
Definition: LArVoxelData.h:322