Analysis Software
Documentation for sPHENIX simulation 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 
10 void RawTowerContainer::compress(const double emin)
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 nullptr;
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 nullptr;
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 
122 {
123  return (!_towers.empty());
124 }
125 
127 {
128  while (_towers.begin() != _towers.end())
129  {
130  delete _towers.begin()->second;
131  _towers.erase(_towers.begin());
132  }
133 }
134 
135 void RawTowerContainer::identify(std::ostream &os) const
136 {
137  os << "RawTowerContainer, number of towers: " << size() << std::endl;
138 }
139 
140 double
142 {
143  double totalenergy = 0;
144  ConstIterator iter;
145  for (iter = _towers.begin(); iter != _towers.end(); ++iter)
146  {
147  totalenergy += iter->second->get_energy();
148  }
149  return totalenergy;
150 }