ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4Cellv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4Cellv1.cc
1 #include "PHG4Cellv1.h"
2 
3 #include <g4main/PHG4HitDefs.h> // for keytype
4 
5 #include <phool/phool.h>
6 
7 #include <climits> // for UINT_MAX, INT_MIN
8 #include <cmath> // for NAN
9 #include <cstdlib> // for exit
10 #include <iostream>
11 #include <string> // for operator<<, string
12 
13 using namespace std;
14 
16  cellid(~0x0)
17 {}
18 
20  cellid(g4cellid)
21 {}
22 
24 {
25  hitedeps.clear();
26  showeredeps.clear();
27  prop_map.clear();
28  return;
29 }
30 
31 void
32 PHG4Cellv1::add_edep(const PHG4HitDefs::keytype g4hitid, const float edep)
33 {
34  hitedeps[g4hitid] = edep;
35  return;
36 }
37 
38 void
39 PHG4Cellv1::add_shower_edep(const int g4showerid, const float edep)
40 {
41  showeredeps[g4showerid] += edep;
42  return;
43 }
44 
45 bool
47 {
48  return PHG4CellDefs::has_binning(cellid, binning);
49 }
50 
51 short int
53 {
55 }
56 
57 bool
58 PHG4Cellv1::has_property(const PROPERTY prop_id) const
59 {
60  prop_map_t::const_iterator i = prop_map.find(prop_id);
61  return i!=prop_map.end();
62 }
63 
64 float
66 {
67  if (!check_property(prop_id,type_float))
68  {
69  pair<const string,PROPERTY_TYPE> property_info =get_property_info(prop_id);
70  cout << PHWHERE << " Property " << property_info.first << " with id "
71  << prop_id << " is of type " << get_property_type(property_info.second)
72  << " not " << get_property_type(type_float) << endl;
73  exit(1);
74  }
75  prop_map_t::const_iterator i = prop_map.find(prop_id);
76 
77  if (i!=prop_map.end()) return u_property(i->second).fdata;
78 
79  return NAN ;
80 }
81 
82 int
84 {
85  if (!check_property(prop_id,type_int))
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_int) << 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).idata;
96 
97  return INT_MIN;
98 }
99 
100 unsigned int
102 {
103  if (!check_property(prop_id,type_uint))
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_uint) << 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).uidata;
114 
115  return UINT_MAX ;
116 }
117 
118 void
119 PHG4Cellv1::add_property(const PROPERTY prop_id, const float value)
120 {
121  if (!check_property(prop_id,type_float))
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_float) << endl;
127  exit(1);
128  }
129  float val = value;
130  if (prop_map.find(prop_id) != prop_map.end())
131  {
132  val += get_property_float(prop_id);
133  }
134  prop_map[prop_id] = u_property(val).get_storage();
135 }
136 
137 void
138 PHG4Cellv1::add_property(const PROPERTY prop_id, const int value)
139 {
140  if (!check_property(prop_id,type_int))
141  {
142  pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
143  cout << PHWHERE << " Property " << property_info.first << " with id "
144  << prop_id << " is of type " << get_property_type(property_info.second)
145  << " not " << get_property_type(type_int) << endl;
146  exit(1);
147  }
148  int val = value;
149  if (prop_map.find(prop_id) != prop_map.end())
150  {
151  val += get_property_int(prop_id);
152  }
153  prop_map[prop_id] += u_property(val).get_storage();
154 }
155 
156 void
157 PHG4Cellv1::add_property(const PROPERTY prop_id, const unsigned int value)
158 {
159  if (!check_property(prop_id,type_uint))
160  {
161  pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
162  cout << PHWHERE << " Property " << property_info.first << " with id "
163  << prop_id << " is of type " << get_property_type(property_info.second)
164  << " not " << get_property_type(type_uint) << endl;
165  exit(1);
166  }
167  unsigned int val = value;
168  if (prop_map.find(prop_id) != prop_map.end())
169  {
170  val += get_property_uint(prop_id);
171  }
172  prop_map[prop_id] += u_property(val).get_storage();
173 }
174 
175 void
176 PHG4Cellv1::set_property(const PROPERTY prop_id, const float value)
177 {
178  if (!check_property(prop_id,type_float))
179  {
180  pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
181  cout << PHWHERE << " Property " << property_info.first << " with id "
182  << prop_id << " is of type " << get_property_type(property_info.second)
183  << " not " << get_property_type(type_float) << endl;
184  exit(1);
185  }
186  prop_map[prop_id] = u_property(value).get_storage();
187 }
188 
189 void
190 PHG4Cellv1::set_property(const PROPERTY prop_id, const int value)
191 {
192  if (!check_property(prop_id,type_int))
193  {
194  pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
195  cout << PHWHERE << " Property " << property_info.first << " with id "
196  << prop_id << " is of type " << get_property_type(property_info.second)
197  << " not " << get_property_type(type_int) << endl;
198  exit(1);
199  }
200  prop_map[prop_id] += u_property(value).get_storage();
201 }
202 
203 void
204 PHG4Cellv1::set_property(const PROPERTY prop_id, const unsigned int value)
205 {
206  if (!check_property(prop_id,type_uint))
207  {
208  pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
209  cout << PHWHERE << " Property " << property_info.first << " with id "
210  << prop_id << " is of type " << get_property_type(property_info.second)
211  << " not " << get_property_type(type_uint) << endl;
212  exit(1);
213  }
214  prop_map[prop_id] += u_property(value).get_storage();
215 }
216 
217 unsigned int
219 {
220  prop_map_t::const_iterator iter = prop_map.find(prop_id);
221  if (iter != prop_map.end())
222  {
223  return iter->second;
224  }
225  return UINT_MAX;
226 }
227 
228 void
230 {
231  identify(cout);
232 }
233 
234 void
236 {
237  hitedeps.clear();
238  showeredeps.clear();
239  prop_map.clear();
240  return;
241 }
242 
243 void PHG4Cellv1::identify(std::ostream& os) const
244 {
245  os << "PHG4Cellv1 0x" << hex << cellid << dec << endl;
246 
247  os <<"Associated to "<<hitedeps.size()<<" hits"<<endl;
248  for (const auto pair :hitedeps)
249  {
250  os <<"\t PHG4hit "<<pair.first<<" -> "<<pair.second<<" GeV"<<endl;
251  }
252 
253  os <<"Associated to "<<showeredeps.size()<<" showers"<<endl;
254  for (const auto pair :showeredeps)
255  {
256  os <<"\t Shower "<<pair.first<<" -> "<<pair.second<<" GeV"<<endl;
257  }
258  os << "Properties:" << endl;
259  for (prop_map_t::const_iterator i = prop_map.begin(); i != prop_map.end(); ++i)
260  {
261  PROPERTY prop_id = static_cast<PROPERTY>(i->first);
262  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
263  os << "\t" << prop_id << ":\t" << property_info.first << " = \t";
264  switch (property_info.second)
265  {
266  case type_int:
267  os << get_property_int(prop_id);
268  break;
269  case type_uint:
270  os << get_property_uint(prop_id);
271  break;
272  case type_float:
273  os << get_property_float(prop_id);
274  break;
275  default:
276  os << " unknown type ";
277  }
278  os << endl;
279  }
280 }