EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawClusterv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawClusterv1.cc
1 #include "RawClusterv1.h"
2 
3 #include <phool/phool.h>
4 
5 #include <climits>
6 #include <cmath>
7 #include <cstdlib>
8 #include <limits>
9 #include <string>
10 
11 using namespace std;
12 
14  : RawCluster()
15  , clusterid(0)
16  , _energy(numeric_limits<float>::signaling_NaN())
17  , _r(numeric_limits<float>::signaling_NaN())
18  , _phi(numeric_limits<float>::signaling_NaN())
19  , _z(numeric_limits<float>::signaling_NaN())
20 {
21 }
22 
24 {
25  clusterid = 0;
26  _z = (numeric_limits<float>::signaling_NaN());
27  _r = (numeric_limits<float>::signaling_NaN());
28  _phi = (numeric_limits<float>::signaling_NaN());
29  _energy = (numeric_limits<float>::signaling_NaN());
30  prop_map.clear();
31  towermap.clear();
32 }
33 
34 void RawClusterv1::addTower(const RawClusterDefs::keytype twrid, const float etower)
35 {
36  if (towermap.find(twrid) != towermap.end())
37  {
38  cout << "tower 0x" << hex << twrid << ", dec: " << dec
39  << twrid << " already exists, that is bad" << endl;
40  exit(1);
41  }
42  towermap[twrid] = etower;
43 }
44 
45 void RawClusterv1::identify(std::ostream& os) const
46 {
47  os << "RawClusterv1 ID " << get_id() << " consist of " << getNTowers() << " towers with total energy of " << get_energy() << " GeV ";
48  os << "@ (r,phi,z) = (" << get_r() << ", " << get_phi() << ", " << get_z() << "), (x,y,z) = (" << get_x() << ", " << get_y() << ", " << get_z() << ")";
49 
50  for (prop_map_t::const_iterator i = prop_map.begin(); i != prop_map.end(); ++i)
51  {
52  PROPERTY prop_id = static_cast<PROPERTY>(i->first);
53  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
54  os << "\t" << prop_id << ":\t" << property_info.first << " = \t";
55  switch (property_info.second)
56  {
57  case type_int:
58  os << get_property_int(prop_id);
59  break;
60  case type_uint:
61  os << get_property_uint(prop_id);
62  break;
63  case type_float:
64  os << get_property_float(prop_id);
65  break;
66  default:
67  os << " unknown type ";
68  break;
69  }
70  os << endl;
71  }
72 }
73 
75 //float RawClusterv1::get_eta(const float z) const
76 //{
77 // if (get_r() <= 0) return numeric_limits<float>::signaling_NaN();
78 // return asinh((get_z() - z) / get_r());
79 //}
80 //
82 //float RawClusterv1::get_et(const float z) const
83 //{
84 // if (get_r() <= 0) return numeric_limits<float>::signaling_NaN();
85 // return get_energy() * sin(atan2(get_r(), (get_z() - z)));
86 //}
87 
88 bool RawClusterv1::has_property(const PROPERTY prop_id) const
89 {
90  prop_map_t::const_iterator i = prop_map.find(prop_id);
91  return i != prop_map.end();
92 }
93 
94 float RawClusterv1::get_property_float(const PROPERTY prop_id) const
95 {
96  if (!check_property(prop_id, type_float))
97  {
98  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
99  cout << PHWHERE << " Property " << property_info.first << " with id "
100  << prop_id << " is of type " << get_property_type(property_info.second)
101  << " not " << get_property_type(type_float) << endl;
102  exit(1);
103  }
104  prop_map_t::const_iterator i = prop_map.find(prop_id);
105 
106  if (i != prop_map.end()) return u_property(i->second).fdata;
107 
108  return NAN;
109 }
110 
111 int RawClusterv1::get_property_int(const PROPERTY prop_id) const
112 {
113  if (!check_property(prop_id, type_int))
114  {
115  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
116  cout << PHWHERE << " Property " << property_info.first << " with id "
117  << prop_id << " is of type " << get_property_type(property_info.second)
118  << " not " << get_property_type(type_int) << endl;
119  exit(1);
120  }
121  prop_map_t::const_iterator i = prop_map.find(prop_id);
122 
123  if (i != prop_map.end()) return u_property(i->second).idata;
124 
125  return INT_MIN;
126 }
127 
128 unsigned int
130 {
131  if (!check_property(prop_id, type_uint))
132  {
133  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
134  cout << PHWHERE << " Property " << property_info.first << " with id "
135  << prop_id << " is of type " << get_property_type(property_info.second)
136  << " not " << get_property_type(type_uint) << endl;
137  exit(1);
138  }
139  prop_map_t::const_iterator i = prop_map.find(prop_id);
140 
141  if (i != prop_map.end()) return u_property(i->second).uidata;
142 
143  return UINT_MAX;
144 }
145 
146 void RawClusterv1::set_property(const PROPERTY prop_id, const float value)
147 {
148  if (!check_property(prop_id, type_float))
149  {
150  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
151  cout << PHWHERE << " Property " << property_info.first << " with id "
152  << prop_id << " is of type " << get_property_type(property_info.second)
153  << " not " << get_property_type(type_float) << endl;
154  exit(1);
155  }
156  prop_map[prop_id] = u_property(value).get_storage();
157 }
158 
159 void RawClusterv1::set_property(const PROPERTY prop_id, const int value)
160 {
161  if (!check_property(prop_id, type_int))
162  {
163  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
164  cout << PHWHERE << " Property " << property_info.first << " with id "
165  << prop_id << " is of type " << get_property_type(property_info.second)
166  << " not " << get_property_type(type_int) << endl;
167  exit(1);
168  }
169  prop_map[prop_id] = u_property(value).get_storage();
170 }
171 
172 void RawClusterv1::set_property(const PROPERTY prop_id, const unsigned int value)
173 {
174  if (!check_property(prop_id, type_uint))
175  {
176  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
177  cout << PHWHERE << " Property " << property_info.first << " with id "
178  << prop_id << " is of type " << get_property_type(property_info.second)
179  << " not " << get_property_type(type_uint) << endl;
180  exit(1);
181  }
182  prop_map[prop_id] = u_property(value).get_storage();
183 }
184 void RawClusterv1::set_et_iso(const float et_iso, const int radiusx10, bool subtracted, bool clusterTower = 1)
185 {
186  if (clusterTower)
187  {
188  if (subtracted)
189  {
190  switch (radiusx10)
191  {
192  case 1:
194  break;
195  case 2:
197  break;
198  case 3:
200  break;
201  case 4:
203  break;
204  default:
205  std::string warning = "set_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - radius:" + std::to_string(radiusx10) + " has not been defined";
206  PHOOL_VIRTUAL_WARN(warning.c_str());
207  break;
208  }
209  }
210  else
211  {
212  switch (radiusx10)
213  {
214  case 1:
216  break;
217  case 2:
219  break;
220  case 3:
222  break;
223  case 4:
225  break;
226  default:
227  std::string warning = "set_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - radius:" + std::to_string(radiusx10) + " has not been defined";
228  PHOOL_VIRTUAL_WARN(warning.c_str());
229  break;
230  }
231  }
232  }
233  else
234  {
235  PHOOL_VIRTUAL_WARN("set_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - nonclusterTower algorithms have not been defined");
236  }
237 }
238 
239 unsigned int
241 {
242  prop_map_t::const_iterator iter = prop_map.find(prop_id);
243  if (iter != prop_map.end())
244  {
245  return iter->second;
246  }
247  return UINT_MAX;
248 }
249 
250 float RawClusterv1::get_et_iso(const int radiusx10 = 3, bool subtracted = 0, bool clusterTower = 1) const
251 {
252  float r;
253  if (clusterTower)
254  {
255  if (subtracted)
256  {
257  switch (radiusx10)
258  {
259  case 1:
261  break;
262  case 2:
264  break;
265  case 3:
267  break;
268  case 4:
270  break;
271  default:
272  std::string warning = "get_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - radius:" + std::to_string(radiusx10) + " has not been defined";
273  PHOOL_VIRTUAL_WARN(warning.c_str());
274  r = NAN;
275  break;
276  }
277  }
278  else
279  {
280  switch (radiusx10)
281  {
282  case 1:
284  break;
285  case 2:
287  break;
288  case 3:
290  break;
291  case 4:
293  break;
294  default:
295  std::string warning = "get_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - radius:" + std::to_string(radiusx10) + " has not been defined";
296  PHOOL_VIRTUAL_WARN(warning.c_str());
297  r = NAN;
298  break;
299  }
300  }
301  }
302  else
303  {
304  PHOOL_VIRTUAL_WARN("get_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - nonclusterTower algorithms have not been defined");
305  r = NAN;
306  }
307  return r;
308 }