ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4Hitv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4Hitv1.cc
1 #include "PHG4Hitv1.h"
2 #include "PHG4HitDefs.h"
3 
4 #include <phool/phool.h>
5 
6 #include <climits>
7 #include <cmath>
8 #include <cstdlib>
9 #include <string>
10 #include <utility>
11 
12 using namespace std;
13 
15 {
16  CopyFrom(g4hit);
17 }
18 
19 void
21 {
22  hitid = ULONG_LONG_MAX;
23  trackid = INT_MIN;
24  showerid = INT_MIN;
25  edep = NAN;
26  for (int i = 0; i<2;i++)
27  {
28  set_x(i,NAN);
29  set_y(i,NAN);
30  set_z(i,NAN);
31  set_t(i,NAN);
32  }
33  prop_map.clear();
34 }
35 
36 int
38 {
39  // a compile time check if the hit_idbits are within range (1-32)
40  static_assert (PHG4HitDefs::hit_idbits <= sizeof(unsigned int)*8,"hit_idbits < 32, fix in PHG4HitDefs.h");
41  int detid = (hitid>>PHG4HitDefs::hit_idbits);
42  return detid;
43 }
44 
45 void
47  std::cout<<"New Hitv1 0x"<< hex << hitid
48  << dec << " on track "<<trackid<<" EDep "<<edep<<std::endl;
49  std::cout<<"Location: X "<<x[0]<<"/"<<x[1]<<" Y "<<y[0]<<"/"<<y[1]<<" Z "<<z[0]<<"/"<<z[1]<<std::endl;
50  std::cout<<"Time "<<t[0]<<"/"<<t[1]<<std::endl;
51 
52  for (prop_map_t::const_iterator i = prop_map.begin(); i!= prop_map.end(); ++i)
53  {
54  PROPERTY prop_id = static_cast<PROPERTY>(i->first);
55  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
56  cout << "\t" << prop_id << ":\t" << property_info.first << " = \t";
57  switch(property_info.second)
58  {
59  case type_int:
60  cout << get_property_int(prop_id);
61  break;
62  case type_uint:
63  cout << get_property_uint(prop_id);
64  break;
65  case type_float:
66  cout << get_property_float(prop_id);
67  break;
68  default:
69  cout << " unknown type ";
70  }
71  cout <<endl;
72  }
73 }
74 
75 bool
76 PHG4Hitv1::has_property(const PROPERTY prop_id) const
77 {
78  prop_map_t::const_iterator i = prop_map.find(prop_id);
79  return i!=prop_map.end();
80 }
81 
82 float
84 {
85  if (!check_property(prop_id,type_float))
86  {
87  pair<const string,PROPERTY_TYPE> property_info =get_property_info(prop_id);
88  cout << PHWHERE << " Property " << property_info.first << " with id "
89  << prop_id << " is of type " << get_property_type(property_info.second)
90  << " not " << get_property_type(type_float) << endl;
91  exit(1);
92  }
93  prop_map_t::const_iterator i = prop_map.find(prop_id);
94 
95  if (i!=prop_map.end()) return u_property(i->second).fdata;
96 
97  return NAN ;
98 }
99 
100 int
102 {
103  if (!check_property(prop_id,type_int))
104  {
105  pair<const string,PROPERTY_TYPE> property_info =get_property_info(prop_id);
106  cout << PHWHERE << " Property " << property_info.first << " with id "
107  << prop_id << " is of type " << get_property_type(property_info.second)
108  << " not " << get_property_type(type_int) << endl;
109  exit(1);
110  }
111  prop_map_t::const_iterator i = prop_map.find(prop_id);
112 
113  if (i!=prop_map.end()) return u_property(i->second).idata;
114 
115  return INT_MIN;
116 }
117 
118 unsigned int
120 {
121  if (!check_property(prop_id,type_uint))
122  {
123  pair<const string,PROPERTY_TYPE> property_info =get_property_info(prop_id);
124  cout << PHWHERE << " Property " << property_info.first << " with id "
125  << prop_id << " is of type " << get_property_type(property_info.second)
126  << " not " << get_property_type(type_uint) << endl;
127  exit(1);
128  }
129  prop_map_t::const_iterator i = prop_map.find(prop_id);
130 
131  if (i!=prop_map.end()) return u_property(i->second).uidata;
132 
133  return UINT_MAX ;
134 }
135 
136 void
137 PHG4Hitv1::set_property(const PROPERTY prop_id, const float value)
138 {
139  if (!check_property(prop_id,type_float))
140  {
141  pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
142  cout << PHWHERE << " Property " << property_info.first << " with id "
143  << prop_id << " is of type " << get_property_type(property_info.second)
144  << " not " << get_property_type(type_float) << endl;
145  exit(1);
146  }
147  prop_map[prop_id] = u_property(value).get_storage();
148 }
149 
150 void
151 PHG4Hitv1::set_property(const PROPERTY prop_id, const int value)
152 {
153  if (!check_property(prop_id,type_int))
154  {
155  pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
156  cout << PHWHERE << " Property " << property_info.first << " with id "
157  << prop_id << " is of type " << get_property_type(property_info.second)
158  << " not " << get_property_type(type_int) << endl;
159  exit(1);
160  }
161  prop_map[prop_id] = u_property(value).get_storage();
162 }
163 
164 void
165 PHG4Hitv1::set_property(const PROPERTY prop_id, const unsigned int value)
166 {
167  if (!check_property(prop_id,type_uint))
168  {
169  pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
170  cout << PHWHERE << " Property " << property_info.first << " with id "
171  << prop_id << " is of type " << get_property_type(property_info.second)
172  << " not " << get_property_type(type_uint) << endl;
173  exit(1);
174  }
175  prop_map[prop_id] = u_property(value).get_storage();
176 }
177 
178 unsigned int
180 {
181  prop_map_t::const_iterator iter = prop_map.find(prop_id);
182  if (iter != prop_map.end())
183  {
184  return iter->second;
185  }
186  return UINT_MAX;
187 }
188 
189 float
190 PHG4Hitv1::get_px(const int i) const
191 {
192  switch(i)
193  {
194  case 0:
195  return get_property_float(prop_px_0);
196  case 1:
197  return get_property_float(prop_px_1);
198  default:
199  cout << "Invalid index in get_px: " << i << endl;
200  exit(1);
201  }
202 }
203 
204 float
205 PHG4Hitv1::get_py(const int i) const
206 {
207  switch(i)
208  {
209  case 0:
210  return get_property_float(prop_py_0);
211  case 1:
212  return get_property_float(prop_py_1);
213  default:
214  cout << "Invalid index in get_py: " << i << endl;
215  exit(1);
216  }
217 }
218 
219 float
220 PHG4Hitv1::get_pz(const int i) const
221 {
222  switch(i)
223  {
224  case 0:
225  return get_property_float(prop_pz_0);
226  case 1:
227  return get_property_float(prop_pz_1);
228  default:
229  cout << "Invalid index in get_pz: " << i << endl;
230  exit(1);
231  }
232 }
233 
234 void
235 PHG4Hitv1::set_px(const int i, const float f)
236 {
237  switch(i)
238  {
239  case 0:
240  set_property(prop_px_0,f);
241  return;
242  case 1:
243  set_property(prop_px_1,f);
244  return;
245  default:
246  cout << "Invalid index in set_px: " << i << endl;
247  exit(1);
248  }
249 }
250 
251 void
252 PHG4Hitv1::set_py(const int i, const float f)
253 {
254  switch(i)
255  {
256  case 0:
257  set_property(prop_py_0,f);
258  return;
259  case 1:
260  set_property(prop_py_1,f);
261  return;
262  default:
263  cout << "Invalid index in set_py: " << i << endl;
264  exit(1);
265  }
266 }
267 
268 void
269 PHG4Hitv1::set_pz(const int i, const float f)
270 {
271  switch(i)
272  {
273  case 0:
274  set_property(prop_pz_0,f);
275  return;
276  case 1:
277  set_property(prop_pz_1,f);
278  return;
279  default:
280  cout << "Invalid index in set_pz: " << i << endl;
281  exit(1);
282  }
283 }
284 
285 
286 float
287 PHG4Hitv1::get_local_x(const int i) const
288 {
289  switch(i)
290  {
291  case 0:
292  return get_property_float(prop_local_x_0);
293  case 1:
294  return get_property_float(prop_local_x_1);
295  default:
296  cout << "Invalid index in get_local_x: " << i << endl;
297  exit(1);
298  }
299 }
300 
301 float
302 PHG4Hitv1::get_local_y(const int i) const
303 {
304  switch(i)
305  {
306  case 0:
307  return get_property_float(prop_local_y_0);
308  case 1:
309  return get_property_float(prop_local_y_1);
310  default:
311  cout << "Invalid index in get_local_y: " << i << endl;
312  exit(1);
313  }
314 }
315 
316 float
317 PHG4Hitv1::get_local_z(const int i) const
318 {
319  switch(i)
320  {
321  case 0:
322  return get_property_float(prop_local_z_0);
323  case 1:
324  return get_property_float(prop_local_z_1);
325  default:
326  cout << "Invalid index in get_local_z: " << i << endl;
327  exit(1);
328  }
329 }
330 
331 void
332 PHG4Hitv1::set_local_x(const int i, const float f)
333 {
334  switch(i)
335  {
336  case 0:
337  set_property(prop_local_x_0,f);
338  return;
339  case 1:
340  set_property(prop_local_x_1,f);
341  return;
342  default:
343  cout << "Invalid index in set_local_x: " << i << endl;
344  exit(1);
345  }
346 }
347 
348 void
349 PHG4Hitv1::set_local_y(const int i, const float f)
350 {
351  switch(i)
352  {
353  case 0:
354  set_property(prop_local_y_0,f);
355  return;
356  case 1:
357  set_property(prop_local_y_1,f);
358  return;
359  default:
360  cout << "Invalid index in set_local_y: " << i << endl;
361  exit(1);
362  }
363 }
364 
365 void
366 PHG4Hitv1::set_local_z(const int i, const float f)
367 {
368  switch(i)
369  {
370  case 0:
371  set_property(prop_local_z_0,f);
372  return;
373  case 1:
374  set_property(prop_local_z_1,f);
375  return;
376  default:
377  cout << "Invalid index in set_local_z: " << i << endl;
378  exit(1);
379  }
380 }
381 
382 void
383 PHG4Hitv1::identify(ostream& os) const
384 {
385  os << "Class " << this->ClassName() << endl;
386  os << "hitid: 0x" << hex << hitid << dec << endl;
387  os << "x0: " << get_x(0)
388  << ", y0: " << get_y(0)
389  << ", z0: " << get_z(0)
390  << ", t0: " << get_t(0) << endl;
391  os << "x1: " << get_x(1)
392  << ", y1: " << get_y(1)
393  << ", z1: " << get_z(1)
394  << ", t1: " << get_t(1) << endl;
395  os << "trackid: " << trackid << ", showerid: " << showerid
396  << ", edep: " << edep << endl;
397  for (prop_map_t::const_iterator i = prop_map.begin(); i!= prop_map.end(); ++i)
398  {
399  PROPERTY prop_id = static_cast<PROPERTY>(i->first);
400  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
401  os << "\t" << prop_id << ":\t" << property_info.first << " = \t";
402  switch(property_info.second)
403  {
404  case type_int:
405  os << get_property_int(prop_id);
406  break;
407  case type_uint:
408  os << get_property_uint(prop_id);
409  break;
410  case type_float:
411  os << get_property_float(prop_id);
412  break;
413  default:
414  os << " unknown type ";
415  }
416  os <<endl;
417  }
418 }