Analysis Software
Documentation for sPHENIX simulation 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 (auto i : prop_map)
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())
107  {
108  return u_property(i->second).fdata;
109  }
110 
111  return NAN;
112 }
113 
114 int RawClusterv1::get_property_int(const PROPERTY prop_id) const
115 {
116  if (!check_property(prop_id, type_int))
117  {
118  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
119  cout << PHWHERE << " Property " << property_info.first << " with id "
120  << prop_id << " is of type " << get_property_type(property_info.second)
121  << " not " << get_property_type(type_int) << endl;
122  exit(1);
123  }
124  prop_map_t::const_iterator i = prop_map.find(prop_id);
125 
126  if (i != prop_map.end())
127  {
128  return u_property(i->second).idata;
129  }
130 
131  return INT_MIN;
132 }
133 
134 unsigned int
136 {
137  if (!check_property(prop_id, type_uint))
138  {
139  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
140  cout << PHWHERE << " Property " << property_info.first << " with id "
141  << prop_id << " is of type " << get_property_type(property_info.second)
142  << " not " << get_property_type(type_uint) << endl;
143  exit(1);
144  }
145  prop_map_t::const_iterator i = prop_map.find(prop_id);
146 
147  if (i != prop_map.end())
148  {
149  return u_property(i->second).uidata;
150  }
151 
152  return UINT_MAX;
153 }
154 
155 void RawClusterv1::set_property(const PROPERTY prop_id, const float value)
156 {
157  if (!check_property(prop_id, type_float))
158  {
159  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
160  cout << PHWHERE << " Property " << property_info.first << " with id "
161  << prop_id << " is of type " << get_property_type(property_info.second)
162  << " not " << get_property_type(type_float) << endl;
163  exit(1);
164  }
165  prop_map[prop_id] = u_property(value).get_storage();
166 }
167 
168 void RawClusterv1::set_property(const PROPERTY prop_id, const int value)
169 {
170  if (!check_property(prop_id, type_int))
171  {
172  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
173  cout << PHWHERE << " Property " << property_info.first << " with id "
174  << prop_id << " is of type " << get_property_type(property_info.second)
175  << " not " << get_property_type(type_int) << endl;
176  exit(1);
177  }
178  prop_map[prop_id] = u_property(value).get_storage();
179 }
180 
181 void RawClusterv1::set_property(const PROPERTY prop_id, const unsigned int value)
182 {
183  if (!check_property(prop_id, type_uint))
184  {
185  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
186  cout << PHWHERE << " Property " << property_info.first << " with id "
187  << prop_id << " is of type " << get_property_type(property_info.second)
188  << " not " << get_property_type(type_uint) << endl;
189  exit(1);
190  }
191  prop_map[prop_id] = u_property(value).get_storage();
192 }
193 void RawClusterv1::set_et_iso(const float et_iso, const int radiusx10, bool subtracted, bool clusterTower = true)
194 {
195  if (clusterTower)
196  {
197  if (subtracted)
198  {
199  switch (radiusx10)
200  {
201  case 1:
203  break;
204  case 2:
206  break;
207  case 3:
209  break;
210  case 4:
212  break;
213  default:
214  std::string warning = "set_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - radius:" + std::to_string(radiusx10) + " has not been defined";
215  PHOOL_VIRTUAL_WARN(warning.c_str());
216  break;
217  }
218  }
219  else
220  {
221  switch (radiusx10)
222  {
223  case 1:
225  break;
226  case 2:
228  break;
229  case 3:
231  break;
232  case 4:
234  break;
235  default:
236  std::string warning = "set_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - radius:" + std::to_string(radiusx10) + " has not been defined";
237  PHOOL_VIRTUAL_WARN(warning.c_str());
238  break;
239  }
240  }
241  }
242  else
243  {
244  PHOOL_VIRTUAL_WARN("set_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - nonclusterTower algorithms have not been defined");
245  }
246 }
247 
248 unsigned int
250 {
251  prop_map_t::const_iterator iter = prop_map.find(prop_id);
252  if (iter != prop_map.end())
253  {
254  return iter->second;
255  }
256  return UINT_MAX;
257 }
258 
259 float RawClusterv1::get_et_iso(const int radiusx10 = 3, bool subtracted = false, bool clusterTower = true) const
260 {
261  float r;
262  if (clusterTower)
263  {
264  if (subtracted)
265  {
266  switch (radiusx10)
267  {
268  case 1:
270  break;
271  case 2:
273  break;
274  case 3:
276  break;
277  case 4:
279  break;
280  default:
281  std::string warning = "get_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - radius:" + std::to_string(radiusx10) + " has not been defined";
282  PHOOL_VIRTUAL_WARN(warning.c_str());
283  r = NAN;
284  break;
285  }
286  }
287  else
288  {
289  switch (radiusx10)
290  {
291  case 1:
293  break;
294  case 2:
296  break;
297  case 3:
299  break;
300  case 4:
302  break;
303  default:
304  std::string warning = "get_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - radius:" + std::to_string(radiusx10) + " has not been defined";
305  PHOOL_VIRTUAL_WARN(warning.c_str());
306  r = NAN;
307  break;
308  }
309  }
310  }
311  else
312  {
313  PHOOL_VIRTUAL_WARN("get_et_iso(const int radiusx10, bool subtracted, bool clusterTower) - nonclusterTower algorithms have not been defined");
314  r = NAN;
315  }
316  return r;
317 }