ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawTowerContainer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawTowerContainer.cc
1 #include "RawTowerContainer.h"
2 
3 #include "RawTower.h"
4 
5 #include <cstdlib>
6 #include <iostream>
7 
8 using namespace std;
9 
11 {
12  if (emin <= 0) // no need to loop through the map if we don't apply a cut
13  {
14  return;
15  }
16  Iterator itr = _towers.begin();
17  Iterator last = _towers.end();
18  for (; itr != last;)
19  {
20  RawTower *tower = (itr->second);
21  if (tower->get_energy() < emin)
22  {
23  delete tower;
24  _towers.erase(itr++);
25  }
26  else
27  {
28  ++itr;
29  }
30  }
31 }
32 
35 {
36  return make_pair(_towers.begin(), _towers.end());
37 }
38 
41 {
42  return make_pair(_towers.begin(), _towers.end());
43 }
44 
46 RawTowerContainer::AddTower(const unsigned int ieta, const int unsigned iphi, RawTower *rawtower)
47 {
48  RawTowerDefs::keytype key = RawTowerDefs::encode_towerid(_caloid, ieta, iphi);
49  _towers[key] = rawtower;
50  rawtower->set_id(key); // force tower key to be synced to container key
51 
52  return _towers.find(key);
53 }
54 
57 {
58  if (RawTowerDefs::decode_caloid(key) != _caloid)
59  {
60  cout << "RawTowerContainer::AddTower - Error - adding tower to wrong container! Container CaloID = "
61  << _caloid << ", requested CaloID = " << RawTowerDefs::decode_caloid(key) << " based on key " << key << endl;
62  exit(2);
63  }
64 
65  _towers[key] = twr;
66  twr->set_id(key); // force tower key to be synced to container key
67 
68  return _towers.find(key);
69 }
70 
71 RawTower *
73 {
74  ConstIterator it = _towers.find(key);
75  if (it != _towers.end())
76  {
77  return it->second;
78  }
79  return NULL;
80 }
81 
82 const RawTower *
84 {
85  ConstIterator it = _towers.find(key);
86  if (it != _towers.end())
87  {
88  return it->second;
89  }
90  return NULL;
91 }
92 
93 RawTower *
94 RawTowerContainer::getTower(const unsigned int ieta, const unsigned int iphi)
95 {
96  RawTowerDefs::keytype key = RawTowerDefs::encode_towerid(_caloid, ieta, iphi);
97  return getTower(key);
98 }
99 
100 const RawTower *
101 RawTowerContainer::getTower(const unsigned int ieta, const unsigned int iphi) const
102 {
103  RawTowerDefs::keytype key = RawTowerDefs::encode_towerid(_caloid, ieta, iphi);
104  return getTower(key);
105 }
106 
107 RawTower *
108 RawTowerContainer::getTower(const unsigned int ieta, const unsigned int iphi , const unsigned int il)
109 {
110  RawTowerDefs::keytype key = RawTowerDefs::encode_towerid(_caloid, ieta, iphi, il);
111  return getTower(key);
112 }
113 
114 const RawTower *
115 RawTowerContainer::getTower(const unsigned int ieta, const unsigned int iphi, const unsigned int il) const
116 {
117  RawTowerDefs::keytype key = RawTowerDefs::encode_towerid(_caloid, ieta, iphi, il);
118  return getTower(key);
119 }
120 
121 
123 {
124  return (!_towers.empty());
125 }
126 
128 {
129  while (_towers.begin() != _towers.end())
130  {
131  delete _towers.begin()->second;
132  _towers.erase(_towers.begin());
133  }
134 }
135 
136 void RawTowerContainer::identify(std::ostream &os) const
137 {
138  os << "RawTowerContainer, number of towers: " << size() << std::endl;
139 }
140 
141 double
143 {
144  double totalenergy = 0;
145  ConstIterator iter;
146  for (iter = _towers.begin(); iter != _towers.end(); ++iter)
147  {
148  totalenergy += iter->second->get_energy();
149  }
150  return totalenergy;
151 }