LArVoxelData.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file LArVoxelData.h
3 /// \brief Encapsulates the information we want store for a voxel.
4 ///
5 /// \author seligman@nevis.columbia.edu
6 ////////////////////////////////////////////////////////////////////////
7 
8 /// LArVoxelList associates a voxel ID with voxel data. LArVoxelID
9 /// describes the ID (position); this class describes the data.
10 ///
11 /// In particular, this class stores the association between particle
12 /// tracks and the energy deposited within a voxel.
13 ///
14 /// The key item of information stored for a voxel is the energy.
15 /// Another, less important item is the association of a particular
16 /// particle track to an amount of energy stored in the voxel. If all
17 /// you want is the energy in a voxel, use LArVoxelData::Energy() and
18 /// ignore the rest of this discussion. If you want to understand the
19 /// source of that energy, you have to dig deeper:
20 ///
21 /// LArVoxelData::Energy[trackID] returns the amount of energy
22 /// deposited by the particle with the given track ID (note the use of
23 /// square brackets).
24 ///
25 /// LArVoxelData::NumberParticles() returns the number of individual
26 /// particles whose energy deposits are recorded for this voxel.
27 ///
28 /// LArVoxelData::Energy(i) returns the amount of energy deposited by
29 /// the "i-th" particle (note the use of parenthesis).
30 ///
31 /// LArVoxelData::TrackID(i) returns the track ID of the "i-th"
32 /// particle.
33 ///
34 /// LArVoxelData::UnassignedEnergy() returns the amount of energy in
35 /// the voxel that's not assigned to any particle. There might be
36 /// "unassigned" energy for one of two reasons:
37 ///
38 /// 1) In the Monte Carlo, particles can be cut from the ParticleList
39 /// because they fall below the energy cut. If that happens, the
40 /// particle is also removed from the LArVoxelData lists, and its
41 /// energy placed in "unassigned" energy.
42 ///
43 /// For example, a voxel might contain the sum of many low-energy
44 /// electrons. It may be that none of the individual electron
45 /// tracks would be written to the output, but their sum might be
46 /// enough for the voxel to be written to the output file.
47 ///
48 /// 2) If any form of "voxel arithmetic" is performed (e.g,. adding
49 /// two LArVoxelLists together), it becomes too difficult to
50 /// maintain the particle<->energy relationship because the track
51 /// IDs change. In that case, all the voxel energies are moved to
52 /// "unassigned" energy.
53 ///
54 /// LArVoxelData::AssignedEnergy() returns, in effect,
55 /// Energy() - UnassignedEnergy()
56 ///
57 
58 #ifndef Simulation_LArVoxelData_h_
59 #define Simulation_LArVoxelData_h_
60 
64 
65 #include <iosfwd>
66 #include <numeric>
67 
68 namespace sim {
69 
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  public:
106  // The energy routines described above. (std::accumulate is
107  // defined in <numeric>, and is a standard STL algorithm.)
108  mapped_type AssignedEnergy() const;
109  mapped_type UnassignedEnergy() const;
110  mapped_type Energy() const;
111 
112  size_type NumberParticles() const;
113 
114  const key_type& TrackID( const size_type ) const;
115  const mapped_type& Energy ( const size_type ) const;
116 
117  // Add the energy to the entry with the key; if the key doesn't
118  // exist, create it.
119  void Add( const mapped_type& energy, const key_type& trackID );
120 
121  // If there's no key, it must be "unassigned" energy.
122  void Add( const mapped_type& energy );
123 
124  sim::LArVoxelID VoxelID() const;
125  void SetVoxelID(sim::LArVoxelID voxID);
126 
127  // Arithmetic methods to support the arithmetic that can be
128  // performed by LArVoxelList.
129  void Add( const LArVoxelData& );
131  const LArVoxelData operator+(const LArVoxelData& other) const;
132 
133  LArVoxelData& operator*=( const double& value );
134  const LArVoxelData operator*(const double& value) const;
135 
136  // Just in case: define the result of "scalar * LArVoxelData" to be
137  // the same as "LArVoxelData * scalar".
138  friend const LArVoxelData operator*(const double& value, const LArVoxelData& list);
139 
140  // RemoveTrack any particle with this track ID and move its energy to
141  // the "unassigned" energy; it returns the number of entries
142  // removed. This method is inlined because we need to do this
143  // fast; it's probably being called in a loop over all the
144  // members of a LArVoxelList.
145  size_type RemoveTrack( const int& track );
146 
147  // Remove all particles and move their energies to "unassigned."
148  void RemoveAllTracks();
149 
150  friend std::ostream& operator<< ( std::ostream& output, const LArVoxelData& );
151 
152  // Standard STL methods, to make this class look like an STL map.
153  // Again, if you don't know STL, you can just ignore these
154  // methods. Remember, the "map" portion of this class doesn't
155  // always tell the whole story; you also need to look at the
156  // "unasigned" energy separately.
157  iterator begin();
158  const_iterator begin() const;
159  iterator end();
160  const_iterator end() const;
161  reverse_iterator rbegin();
162  const_reverse_iterator rbegin() const;
163  reverse_iterator rend();
164  const_reverse_iterator rend() const;
165 
166  size_type size() const;
167  bool empty() const;
168  void swap( LArVoxelData& other );
169  void clear();
170 
171  iterator find(const key_type& key);
172  const_iterator find(const key_type& key) const;
173  iterator upper_bound(const key_type& key);
174  const_iterator upper_bound(const key_type& key) const;
175  iterator lower_bound(const key_type& key);
176  const_iterator lower_bound(const key_type& key) const;
177  size_type erase( const key_type& key );
178 
179  mapped_type& operator[](const key_type& key);
180  // My own little addition: operator[] in a const context.
181  const mapped_type& operator[]( const key_type& key) const;
182  mapped_type& at(const key_type& key);
183  const mapped_type& at(const key_type& key) const;
184 
185  // In addition to operator[], include one insert() method. Note
186  // that, as with operator[], there's no check against overwriting
187  // an existing item.
188  void insert( const key_type& key, const mapped_type& value );
189 
190  };
191 
192 } // namespace sim
193 
199 {
200  return std::accumulate( ftrackEnergy.begin(), ftrackEnergy.end(), 0.0,
202 }
204 {
205  return std::accumulate( ftrackEnergy.begin(), ftrackEnergy.end(), fenergy,
207 }
209 {
210  iterator search = ftrackEnergy.find( track );
211  if ( search != ftrackEnergy.end() )
212  {
213  fenergy += (*search).second;
214  ftrackEnergy.erase( search );
215  return 1;
216  }
217  else return 0;
218 }
220 {
221  fenergy = this->Energy();
223 }
225  const sim::LArVoxelData::key_type& trackID )
226 { ftrackEnergy[trackID] += energy; }
228 { fenergy += energy; }
230 {
231  this->Add(other);
232  return *this;
233 }
235 {
236  return LArVoxelData(*this) += other;
237 }
238 inline const sim::LArVoxelData sim::LArVoxelData::operator*(const double& value) const
239 {
240  return LArVoxelData(*this) *= value;
241 }
250 
252 inline bool sim::LArVoxelData::empty() const { return ftrackEnergy.empty(); }
254 {
255  ftrackEnergy.swap( other.ftrackEnergy );
256  double temp = fenergy;
257  fenergy = other.fenergy;
258  other.fenergy = temp;
259 }
262 { return ftrackEnergy.find(key); }
264 { return ftrackEnergy.find(key); }
266 { return ftrackEnergy.upper_bound(key); }
268 { return ftrackEnergy.upper_bound(key); }
270 { return ftrackEnergy.lower_bound(key); }
272 { return ftrackEnergy.lower_bound(key); }
274 { return this->RemoveTrack(key); }
275 
277 { return ftrackEnergy[key]; }
279 { return ftrackEnergy.at(key); }
281 { return ftrackEnergy.at(key); }
283 { return ftrackEnergy.at(key); }
285 { ftrackEnergy[key] = value; }
286 
287 #endif // Simulation_LArVoxelData_h_
void Add(const mapped_type &energy, const key_type &trackID)
Definition: LArVoxelData.h:224
const LArVoxelData operator*(const double &value) const
Definition: LArVoxelData.h:238
size_type erase(const key_type &key)
Definition: LArVoxelData.h:273
list_type::key_compare key_compare
Definition: LArVoxelData.h:86
mapped_type & operator[](const key_type &key)
Definition: LArVoxelData.h:276
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:269
list_type::value_type value_type
Definition: LArVoxelData.h:79
void insert(const key_type &key, const mapped_type &value)
Definition: LArVoxelData.h:284
reverse_iterator rbegin()
Definition: VectorMap.h:208
bool empty() const
Definition: LArVoxelData.h:252
mapped_type & at(const key_type &__k)
Definition: VectorMap.h:272
size_type size() const
Definition: LArVoxelData.h:251
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:242
const LArVoxelData operator+(const LArVoxelData &other) const
Definition: LArVoxelData.h:234
void erase(iterator __position)
Definition: VectorMap.h:332
mapped_type UnassignedEnergy() const
Definition: LArVoxelData.h:197
list_type ftrackEnergy
Definition: LArVoxelData.h:101
iterator begin()
Definition: VectorMap.h:188
LArVoxelData & operator+=(const LArVoxelData &other)
Definition: LArVoxelData.h:229
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
def key(type, name=None)
Definition: graph.py:13
list_type::reverse_iterator reverse_iterator
Definition: LArVoxelData.h:82
vector_type::const_iterator const_iterator
Definition: VectorMap.h:121
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:196
Definition: search.py:1
mapped_type AssignedEnergy() const
Definition: LArVoxelData.h:198
Code to link reconstructed objects back to the MC truth information.
std::reverse_iterator< iterator > reverse_iterator
Definition: VectorMap.h:123
reverse_iterator rend()
Definition: LArVoxelData.h:248
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
virtual ~LArVoxelData()
list_type::difference_type difference_type
Definition: LArVoxelData.h:85
mapped_type Energy() const
Definition: LArVoxelData.h:203
list_type::key_type key_type
Definition: LArVoxelData.h:77
void swap(LArVoxelData &other)
Definition: LArVoxelData.h:253
reverse_iterator rbegin()
Definition: LArVoxelData.h:246
mapped_type & at(const key_type &key)
Definition: LArVoxelData.h:280
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:195
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:208
void SetVoxelID(sim::LArVoxelID voxID)
Definition: LArVoxelData.h:194
iterator find(const key_type &key)
Definition: LArVoxelData.h:261
list_type::size_type size_type
Definition: LArVoxelData.h:84
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:265