LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ParticleList.h
Go to the documentation of this file.
1 
77 
106 
107 #ifndef SIM_PARTICLELIST_H
108 #define SIM_PARTICLELIST_H
109 
111 
112 #include <set>
113 #include <ostream>
114 #include <map>
115 #include <cstdlib> // std::abs()
116 
117 namespace sim {
118 
119  // Forward declarations.
120  class EveIdCalculator;
121 
122  class ParticleList {
123  public:
124  // Some type definitions to make life easier, and to help "hide"
125  // the implementation details. (If you're not familiar with STL,
126  // you can ignore these definitions.)
127  typedef std::map<int,simb::MCParticle*> list_type;
128  typedef list_type::key_type key_type;
129  typedef list_type::mapped_type mapped_type;
130  typedef list_type::value_type value_type;
133  typedef list_type::reverse_iterator reverse_iterator;
134  typedef list_type::const_reverse_iterator const_reverse_iterator;
135  typedef list_type::size_type size_type;
136  typedef list_type::difference_type difference_type;
137  typedef list_type::key_compare key_compare;
138  typedef list_type::allocator_type allocator_type;
139 
140  // Standard constructor, let compiler default the detector
141  ParticleList();
142  virtual ~ParticleList();
143 
144  private:
146  int parentID = 0;
147 
148  archived_info_type() = default;
149 
150  archived_info_type(int pid): parentID(pid) {}
152  : parentID(part.Mother())
153  {}
155  : parentID(part->Mother())
156  {}
157 
158  int Mother() const { return parentID; }
159 
160  friend std::ostream& operator<<
161  ( std::ostream& output, const ParticleList::archived_info_type& );
162  }; // archived_info_type
163 
164 
165  typedef std::set< int > primaries_type;
166  typedef std::map<int, archived_info_type> archive_type;
169 
170  list_type m_particleList;
171  primaries_type m_primaries;
172  archive_type m_archive;
174 
175 #ifndef __GCCXML__
176 
177  public:
178 
179  // Because this list contains pointers, we have to provide the
180  // copy and assignment constructors.
181  // ParticleList( const ParticleList& rhs );
182  // ParticleList& operator=( const ParticleList& rhs );
183 
184  // you know what? let's make it UNCOPIABLE instead!
185  // The cost of copying this buauty is such that we don't want it
186  // to happen unless really requested (copy())
187  ParticleList( const ParticleList& rhs ) = delete;
188  ParticleList& operator=( const ParticleList& rhs ) = delete;
189  ParticleList( ParticleList&& rhs ) = default;
190  ParticleList& operator=( ParticleList&& rhs ) = default;
191 
193  ParticleList MakeCopy() const;
194 
195  // The methods advertised above:
196 
197  // Apply an energy threshold cut to the particles in the list,
198  // removing all those that fall below the cut. (Be careful if
199  // you're playing with voxels; this method does not change the
200  // contents of a LArVoxelList.)
201  void Cut( const double& );
202 
203  const key_type& TrackId( const size_type ) const;
204  mapped_type const& Particle( const size_type ) const;
205  mapped_type Particle( const size_type );
206 
208  bool HasParticle( int trackID ) const
209  {
210  auto iParticle = find(trackID);
211  return (iParticle != end()) && (iParticle->second != nullptr);
212  }
213 
215  bool KnownParticle( int trackID ) const
216  { return find(trackID) != end(); }
217 
218 
219  bool IsPrimary( int trackID ) const;
220  int NumberOfPrimaries() const;
221 
222  std::vector<const simb::MCParticle*> GetPrimaries() const;
223 
224  const simb::MCParticle* Primary( const int ) const;
225  simb::MCParticle* Primary( const int );
226 
227  // Standard STL methods, to make this class look like an STL map.
228  // Again, if you don't know STL, you can just ignore these
229  // methods.
230  iterator begin();
231  const_iterator begin() const;
232  iterator end();
233  const_iterator end() const;
234  reverse_iterator rbegin();
235  const_reverse_iterator rbegin() const;
236  reverse_iterator rend();
237  const_reverse_iterator rend() const;
238 
239  size_type size() const;
240  bool empty() const;
241  void swap( ParticleList& other );
242 
243  iterator find(const key_type& key);
244  const_iterator find(const key_type& key) const;
245  iterator upper_bound(const key_type& key);
246  const_iterator upper_bound(const key_type& key) const;
247  iterator lower_bound(const key_type& key);
248  const_iterator lower_bound(const key_type& key) const;
249 
250  // Be careful when using operator[] here! It takes the track ID as the argument:
251  // sim::ParticleList partList;
252  // const sim::Particle* = partList[3];
253  // The above line means the particle with trackID==3, NOT the third
254  // particle in the list! Use partList.Particle(3) if you want to
255  // get the particles by index number instead of track ID.
256  // Note that this only works in a const context. Use the insert()
257  // or Add() methods to add a new particle to the list.
258  mapped_type const& operator[]( const key_type& key ) const;
259  // This non-const version of operator[] does NOT permit you to insert
260  // Particles into the list. Use Add() or insert() for that.
261  mapped_type operator[]( const key_type& key );
262  mapped_type at(const key_type& key);
263  mapped_type const& at(const key_type& key) const;
264 
266  key_type key(mapped_type const& part) const;
267 
268  // These two methods do the same thing:
269  // - Add the Particle to the list, using the track ID as the key.
270  // - Update the list of primary particles as needed.
271  // Note that when you insert a Particle* into a ParticleList, it
272  // takes over management of the pointer. Don't delete it yourself!
273  void insert( simb::MCParticle* value );
274  void Add( simb::MCParticle* value );
275 
277  void Archive( const key_type& key );
278  void Archive( const mapped_type& key );
279 
281  int GetMotherOf( const key_type& key ) const;
282 
283  void clear();
284  size_type erase( const key_type& key );
285  iterator erase( iterator key );
286 
287  friend std::ostream& operator<< ( std::ostream& output, const ParticleList& );
288  friend std::ostream& operator<<
289  ( std::ostream& output, const ParticleList::archived_info_type& );
290 
291  // Methods associated with the eve ID calculation.
292  // Calculate the eve ID.
293  int EveId ( const int trackID ) const;
294  // Set a pointer to a different eve ID calculation. The name
295  // begins with "Adopt" because it accepts control of the ponters;
296  // do NOT delete the pointer yourself if you use this method.
297  static void AdoptEveIdCalculator( EveIdCalculator* );
298 
299 #endif
300  };
301 }
302 
303 #ifndef __GCCXML__
304 
314 inline bool sim::ParticleList::empty() const { return m_particleList.empty(); }
317 { m_particleList.swap( other.m_particleList ); m_archive.swap( other.m_archive ); m_primaries.swap( other.m_primaries); }
319 { return m_particleList.find(abs(key)); }
321 { return m_particleList.find(abs(key)); }
323 { return m_particleList.upper_bound(abs(key)); }
325 { return m_particleList.upper_bound(abs(key)); }
327 { return m_particleList.lower_bound(abs(key)); }
329 { return m_particleList.lower_bound(abs(key)); }
331 { return m_particleList.at(std::abs(key)); }
333 { return m_particleList.at(std::abs(key)); }
335 { return at(key); }
337 { return at(key); }
338 inline sim::ParticleList::key_type sim::ParticleList::key(mapped_type const& part) const { return part->TrackId(); }
339 
340 
341 #endif
342 
343 
344 #endif // SIM_PARTICLELIST_H
intermediate_table::iterator iterator
mapped_type const & operator[](const key_type &key) const
Definition: ParticleList.h:336
ParticleList & operator=(const ParticleList &rhs)=delete
bool empty() const
Definition: ParticleList.h:314
void insert(simb::MCParticle *value)
friend std::ostream & operator<<(std::ostream &output, const ParticleList::archived_info_type &)
ParticleList MakeCopy() const
Returns a copy of this object.
key_type key(mapped_type const &part) const
Extracts the key from the specified value.
Definition: ParticleList.h:338
const key_type & TrackId(const size_type) const
primaries_type m_primaries
Definition: ParticleList.h:171
list_type::value_type value_type
Definition: ParticleList.h:130
virtual ~ParticleList()
list_type::const_iterator const_iterator
Definition: ParticleList.h:132
mapped_type at(const key_type &key)
Definition: ParticleList.h:330
list_type::iterator iterator
Definition: ParticleList.h:131
constexpr auto abs(T v)
Returns the absolute value of the argument.
void Add(simb::MCParticle *value)
Definition: ParticleList.h:315
list_type::reverse_iterator reverse_iterator
Definition: ParticleList.h:133
primaries_type::const_iterator primaries_const_iterator
Definition: ParticleList.h:168
intermediate_table::const_iterator const_iterator
primaries_type::iterator primaries_iterator
Definition: ParticleList.h:167
int EveId(const int trackID) const
Particle class.
std::map< int, simb::MCParticle * > list_type
Definition: ParticleList.h:127
list_type::difference_type difference_type
Definition: ParticleList.h:136
iterator upper_bound(const key_type &key)
Definition: ParticleList.h:322
std::set< int > primaries_type
Definition: ParticleList.h:165
iterator find(const key_type &key)
Definition: ParticleList.h:318
TString part[npart]
Definition: Style.C:32
iterator lower_bound(const key_type &key)
Definition: ParticleList.h:326
mapped_type const & Particle(const size_type) const
std::map< int, archived_info_type > archive_type
Definition: ParticleList.h:166
bool IsPrimary(int trackID) const
reverse_iterator rbegin()
Definition: ParticleList.h:309
archived_info_type(simb::MCParticle const *part)
Definition: ParticleList.h:154
iterator begin()
Definition: ParticleList.h:305
list_type::const_reverse_iterator const_reverse_iterator
Definition: ParticleList.h:134
list_type::size_type size_type
Definition: ParticleList.h:135
Monte Carlo Simulation.
void Cut(const double &)
int GetMotherOf(const key_type &key) const
This function seeks for the exact key, not its absolute value.
list_type::key_type key_type
Definition: ParticleList.h:128
double value
Definition: spectrum.C:18
reverse_iterator rend()
Definition: ParticleList.h:311
archived_info_type(simb::MCParticle const &part)
Definition: ParticleList.h:151
list_type::allocator_type allocator_type
Definition: ParticleList.h:138
std::vector< const simb::MCParticle * > GetPrimaries() const
list_type::key_compare key_compare
Definition: ParticleList.h:137
const simb::MCParticle * Primary(const int) const
size_type erase(const key_type &key)
bool KnownParticle(int trackID) const
Returns whether we have had this particle, archived or live.
Definition: ParticleList.h:215
void swap(ParticleList &other)
Definition: ParticleList.h:316
list_type m_particleList
Sorted list of particles in the event.
Definition: ParticleList.h:170
static void AdoptEveIdCalculator(EveIdCalculator *)
archive_type m_archive
archive of the particles no longer among us
Definition: ParticleList.h:173
size_type size() const
Definition: ParticleList.h:313
int NumberOfPrimaries() const
list_type::mapped_type mapped_type
Definition: ParticleList.h:129
bool HasParticle(int trackID) const
Returns whether we have this particle, live (with full information)
Definition: ParticleList.h:208
void Archive(const key_type &key)
Removes the particle from the list, keeping minimal info of it.