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