LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
LArVoxelList.cxx
Go to the documentation of this file.
1 
9 
10 #include <iterator>
11 #include <vector>
12 #include <iostream>
13 #include <cmath>
14 
15 namespace sim {
16 
17  //----------------------------------------------------------------------------
18  // Nothing special need be done for the constructor or destructor.
20 
21  //----------------------------------------------------------------------------
23 
24  //----------------------------------------------------------------------------
26  {
27  // Go through "other" list, adding its voxels to "this" list.
28  for ( const_iterator i = other.m_voxelList.begin(); i != m_voxelList.end(); ++i ){
29  m_voxelList[ (*i).first ] += (*i).second;
30  }
31  }
32 
33  //----------------------------------------------------------------------------
35  {
36  // Multiply each voxel energy by the value.
37  for ( iterator i = m_voxelList.begin(); i != m_voxelList.end(); ++i ){
38  (*i).second *= value;
39  }
40  return (*this);
41  }
42 
43  //----------------------------------------------------------------------------
46  const LArVoxelList operator*(const double& value, const LArVoxelList& list)
47  {
48  return LArVoxelList(list) *= value;
49  }
50 
51  //----------------------------------------------------------------------------
53  void LArVoxelList::Cut( const double& cut )
54  {
55  // The safest way to do this is to create a list of voxel IDs that
56  // fail the cut, then delete those IDs.
57 
58  // Define a list of IDs.
59  typedef std::vector< key_type > keyList_type;
60  keyList_type keyList;
61 
62  // Add each ID that fails the cut to the list.
63  for ( const_iterator i = m_voxelList.begin(); i != m_voxelList.end(); ++i ){
64  if ( (*i).second.Energy() < cut ) {
65  keyList.push_back( (*i).first );
66  }
67  }
68 
69  // Go through the list, deleting the voxels that are on the list.
70  for ( keyList_type::const_iterator i = keyList.begin(); i != keyList.end(); ++i ){
71  m_voxelList.erase( (*i) );
72  }
73  }
74 
75  //----------------------------------------------------------------------------
77  {
78  const_iterator i = m_voxelList.begin();
79  std::advance(i,index);
80  return (*i).first;
81  }
82 
83  //----------------------------------------------------------------------------
84  double LArVoxelList::Energy( const size_type index ) const
85  {
86  const_iterator i = m_voxelList.begin();
87  std::advance(i,index);
88  return (*i).second.Energy();
89  }
90 
91  //----------------------------------------------------------------------------
92  std::ostream& operator<< ( std::ostream& output, const LArVoxelList& list )
93  {
94  // Determine a field width for the voxel number.
95  LArVoxelList::size_type numberOfVoxels = list.size();
96  int numberOfDigits = (int) std::log10( (double) numberOfVoxels ) + 1;
97 
98  // A simple header.
99  output.width( numberOfDigits );
100  output << "#" << ": < ID, energy >" << std::endl;
101 
102  // Write each voxel on a separate line.
103  LArVoxelList::size_type nVoxel = 0;
104  for ( LArVoxelList::const_iterator voxel = list.begin(); voxel != list.end(); ++voxel, ++nVoxel ){
105  output.width( numberOfDigits );
106  output << nVoxel << ": "
107  << "< " << (*voxel).first
108  << ", " << (*voxel).second
109  << " >\n";
110  }
111 
112  return output;
113  }
114 
115 } // namespace sim
const LArVoxelList operator*(const double &value) const
Definition: LArVoxelList.h:111
size_type size() const
Definition: LArVoxelList.h:140
Container of LAr voxel information.
list_type m_voxelList
A sorted list of <LArVoxelID,double> pairs = (voxel ID, energy)
Definition: LArVoxelList.h:167
iterator begin()
Definition: LArVoxelList.h:131
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
intermediate_table::const_iterator const_iterator
void Cut(const double &)
Apply an energy cut to the voxels.
list_type::iterator iterator
Definition: LArVoxelList.h:78
Monte Carlo Simulation.
list_type::size_type size_type
Definition: LArVoxelList.h:82
LArVoxelList & operator*=(const double &value)
std::string value(boost::any const &)
list_type::key_type key_type
Definition: LArVoxelList.h:75
void Add(const key_type &key, const double &energy)
Definition: LArVoxelList.h:94
const key_type & ID(const size_type) const
virtual ~LArVoxelList()