All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArVoxelList.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file LArVoxelList.cxx
3 /// \brief Container of LArVoxelID, energy information.
4 ///
5 /// \author seligman@nevis.columbia.edu
6 ////////////////////////////////////////////////////////////////////////
7 
9 
10 #include <iterator>
11 #include <iostream>
12 #include <cmath>
13 
14 namespace sim {
15 
16  //----------------------------------------------------------------------------
17  // Nothing special need be done for the constructor or destructor.
19 
20  //----------------------------------------------------------------------------
22 
23  //----------------------------------------------------------------------------
24  void LArVoxelList::Add( const LArVoxelList& other )
25  {
26  // Go through "other" list, adding its voxels to "this" list.
27  for ( const_iterator i = other.m_voxelList.begin(); i != m_voxelList.end(); ++i ){
28  m_voxelList[ (*i).first ] += (*i).second;
29  }
30  }
31 
32  //----------------------------------------------------------------------------
34  {
35  // Multiply each voxel energy by the value.
36  for ( iterator i = m_voxelList.begin(); i != m_voxelList.end(); ++i ){
37  (*i).second *= value;
38  }
39  return (*this);
40  }
41 
42  //----------------------------------------------------------------------------
43  /// Just in case: define the result of "scalar * LArVoxelList" to be
44  /// the same as "LArVoxelList * scalar".
45  const LArVoxelList operator*(const double& value, const LArVoxelList& list)
46  {
47  return LArVoxelList(list) *= value;
48  }
49 
50  //----------------------------------------------------------------------------
51  /// Apply an energy cut to the voxels.
52  void LArVoxelList::Cut( const double& cut )
53  {
54  // The safest way to do this is to create a list of voxel IDs that
55  // fail the cut, then delete those IDs.
56 
57  // Define a list of IDs.
58  typedef std::vector< key_type > keyList_type;
59  keyList_type keyList;
60 
61  // Add each ID that fails the cut to the list.
62  for ( const_iterator i = m_voxelList.begin(); i != m_voxelList.end(); ++i ){
63  if ( (*i).second.Energy() < cut ) {
64  keyList.push_back( (*i).first );
65  }
66  }
67 
68  // Go through the list, deleting the voxels that are on the list.
69  for ( keyList_type::const_iterator i = keyList.begin(); i != keyList.end(); ++i ){
70  m_voxelList.erase( (*i) );
71  }
72  }
73 
74  //----------------------------------------------------------------------------
76  {
77  const_iterator i = m_voxelList.begin();
78  std::advance(i,index);
79  return (*i).first;
80  }
81 
82  //----------------------------------------------------------------------------
83  double LArVoxelList::Energy( const size_type index ) const
84  {
85  const_iterator i = m_voxelList.begin();
86  std::advance(i,index);
87  return (*i).second.Energy();
88  }
89 
90  //----------------------------------------------------------------------------
91  std::ostream& operator<< ( std::ostream& output, const LArVoxelList& list )
92  {
93  // Determine a field width for the voxel number.
94  LArVoxelList::size_type numberOfVoxels = list.size();
95  int numberOfDigits = (int) std::log10( (double) numberOfVoxels ) + 1;
96 
97  // A simple header.
98  output.width( numberOfDigits );
99  output << "#" << ": < ID, energy >" << std::endl;
100 
101  // Write each voxel on a separate line.
102  LArVoxelList::size_type nVoxel = 0;
103  for ( LArVoxelList::const_iterator voxel = list.begin(); voxel != list.end(); ++voxel, ++nVoxel ){
104  output.width( numberOfDigits );
105  output << nVoxel << ": "
106  << "< " << (*voxel).first
107  << ", " << (*voxel).second
108  << " >\n";
109  }
110 
111  return output;
112  }
113 
114 } // namespace sim
size_type size() const
Definition: LArVoxelList.h:140
Container of LAr voxel information.
const LArVoxelData operator*(const double &value, const LArVoxelData &data)
list_type m_voxelList
A sorted list of &lt;LArVoxelID,double&gt; pairs = (voxel ID, energy)
Definition: LArVoxelList.h:167
iterator begin()
Definition: LArVoxelList.h:131
list_type::const_iterator const_iterator
Definition: LArVoxelList.h:79
double Energy(const size_type) const
void Cut(const double &)
Apply an energy cut to the voxels.
list_type::iterator iterator
Definition: LArVoxelList.h:78
list_type::size_type size_type
Definition: LArVoxelList.h:82
LArVoxelList & operator*=(const double &value)
list_type::key_type key_type
Definition: LArVoxelList.h:75
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output
void Add(const key_type &key, const double &energy)
Definition: LArVoxelList.h:94
temporary value
const key_type & ID(const size_type) const
std::ostream & operator<<(std::ostream &output, const LArVoxelData &data)
list
Definition: file_to_url.sh:28
virtual ~LArVoxelList()