Analysis Software
Documentation for sPHENIX simulation 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 
14  : cellid(g4cellid)
15 {
16 }
17 
19 {
20  hitedeps.clear();
21  showeredeps.clear();
22  prop_map.clear();
23  return;
24 }
25 
26 void PHG4Cellv1::add_edep(const PHG4HitDefs::keytype g4hitid, const float edep)
27 {
28  hitedeps[g4hitid] = edep;
29  return;
30 }
31 
32 void PHG4Cellv1::add_shower_edep(const int g4showerid, const float edep)
33 {
34  showeredeps[g4showerid] += edep;
35  return;
36 }
37 
39 {
40  return PHG4CellDefs::has_binning(cellid, binning);
41 }
42 
43 short int
45 {
47 }
48 
49 bool PHG4Cellv1::has_property(const PROPERTY prop_id) const
50 {
51  prop_map_t::const_iterator i = prop_map.find(prop_id);
52  return i != prop_map.end();
53 }
54 
55 float PHG4Cellv1::get_property_float(const PROPERTY prop_id) const
56 {
57  if (!check_property(prop_id, type_float))
58  {
59  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
60  std::cout << PHWHERE << " Property " << property_info.first << " with id "
61  << prop_id << " is of type " << get_property_type(property_info.second)
62  << " not " << get_property_type(type_float) << std::endl;
63  exit(1);
64  }
65  prop_map_t::const_iterator i = prop_map.find(prop_id);
66 
67  if (i != prop_map.end()) return u_property(i->second).fdata;
68 
69  return NAN;
70 }
71 
72 int PHG4Cellv1::get_property_int(const PROPERTY prop_id) const
73 {
74  if (!check_property(prop_id, type_int))
75  {
76  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
77  std::cout << PHWHERE << " Property " << property_info.first << " with id "
78  << prop_id << " is of type " << get_property_type(property_info.second)
79  << " not " << get_property_type(type_int) << std::endl;
80  exit(1);
81  }
82  prop_map_t::const_iterator i = prop_map.find(prop_id);
83 
84  if (i != prop_map.end()) return u_property(i->second).idata;
85 
86  return INT_MIN;
87 }
88 
89 unsigned int
91 {
92  if (!check_property(prop_id, type_uint))
93  {
94  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
95  std::cout << PHWHERE << " Property " << property_info.first << " with id "
96  << prop_id << " is of type " << get_property_type(property_info.second)
97  << " not " << get_property_type(type_uint) << std::endl;
98  exit(1);
99  }
100  prop_map_t::const_iterator i = prop_map.find(prop_id);
101 
102  if (i != prop_map.end()) return u_property(i->second).uidata;
103 
104  return UINT_MAX;
105 }
106 
107 void PHG4Cellv1::add_property(const PROPERTY prop_id, const float value)
108 {
109  if (!check_property(prop_id, type_float))
110  {
111  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
112  std::cout << PHWHERE << " Property " << property_info.first << " with id "
113  << prop_id << " is of type " << get_property_type(property_info.second)
114  << " not " << get_property_type(type_float) << std::endl;
115  exit(1);
116  }
117  float val = value;
118  if (prop_map.find(prop_id) != prop_map.end())
119  {
120  val += get_property_float(prop_id);
121  }
122  prop_map[prop_id] = u_property(val).get_storage();
123 }
124 
125 void PHG4Cellv1::add_property(const PROPERTY prop_id, const int value)
126 {
127  if (!check_property(prop_id, type_int))
128  {
129  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
130  std::cout << PHWHERE << " Property " << property_info.first << " with id "
131  << prop_id << " is of type " << get_property_type(property_info.second)
132  << " not " << get_property_type(type_int) << std::endl;
133  exit(1);
134  }
135  int val = value;
136  if (prop_map.find(prop_id) != prop_map.end())
137  {
138  val += get_property_int(prop_id);
139  }
140  prop_map[prop_id] += u_property(val).get_storage();
141 }
142 
143 void PHG4Cellv1::add_property(const PROPERTY prop_id, const unsigned int value)
144 {
145  if (!check_property(prop_id, type_uint))
146  {
147  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
148  std::cout << PHWHERE << " Property " << property_info.first << " with id "
149  << prop_id << " is of type " << get_property_type(property_info.second)
150  << " not " << get_property_type(type_uint) << std::endl;
151  exit(1);
152  }
153  unsigned int val = value;
154  if (prop_map.find(prop_id) != prop_map.end())
155  {
156  val += get_property_uint(prop_id);
157  }
158  prop_map[prop_id] += u_property(val).get_storage();
159 }
160 
161 void PHG4Cellv1::set_property(const PROPERTY prop_id, const float value)
162 {
163  if (!check_property(prop_id, type_float))
164  {
165  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
166  std::cout << PHWHERE << " Property " << property_info.first << " with id "
167  << prop_id << " is of type " << get_property_type(property_info.second)
168  << " not " << get_property_type(type_float) << std::endl;
169  exit(1);
170  }
171  prop_map[prop_id] = u_property(value).get_storage();
172 }
173 
174 void PHG4Cellv1::set_property(const PROPERTY prop_id, const int value)
175 {
176  if (!check_property(prop_id, type_int))
177  {
178  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
179  std::cout << PHWHERE << " Property " << property_info.first << " with id "
180  << prop_id << " is of type " << get_property_type(property_info.second)
181  << " not " << get_property_type(type_int) << std::endl;
182  exit(1);
183  }
184  prop_map[prop_id] += u_property(value).get_storage();
185 }
186 
187 void PHG4Cellv1::set_property(const PROPERTY prop_id, const unsigned int value)
188 {
189  if (!check_property(prop_id, type_uint))
190  {
191  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
192  std::cout << PHWHERE << " Property " << property_info.first << " with id "
193  << prop_id << " is of type " << get_property_type(property_info.second)
194  << " not " << get_property_type(type_uint) << std::endl;
195  exit(1);
196  }
197  prop_map[prop_id] += u_property(value).get_storage();
198 }
199 
200 unsigned int
202 {
203  prop_map_t::const_iterator iter = prop_map.find(prop_id);
204  if (iter != prop_map.end())
205  {
206  return iter->second;
207  }
208  return UINT_MAX;
209 }
210 
211 void PHG4Cellv1::print() const
212 {
213  identify(std::cout);
214 }
215 
217 {
218  hitedeps.clear();
219  showeredeps.clear();
220  prop_map.clear();
221  return;
222 }
223 
224 void PHG4Cellv1::identify(std::ostream& os) const
225 {
226  os << "PHG4Cellv1 0x" << std::hex << cellid << std::dec << std::endl;
227 
228  os << "Associated to " << hitedeps.size() << " hits" << std::endl;
229  for (const auto pair : hitedeps)
230  {
231  os << "\t PHG4hit " << pair.first << " -> " << pair.second << " GeV" << std::endl;
232  }
233 
234  os << "Associated to " << showeredeps.size() << " showers" << std::endl;
235  for (const auto pair : showeredeps)
236  {
237  os << "\t Shower " << pair.first << " -> " << pair.second << " GeV" << std::endl;
238  }
239  os << "Properties:" << std::endl;
240  for (auto i : prop_map)
241  {
242  PROPERTY prop_id = static_cast<PROPERTY>(i.first);
243  std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
244  os << "\t" << prop_id << ":\t" << property_info.first << " = \t";
245  switch (property_info.second)
246  {
247  case type_int:
248  os << get_property_int(prop_id);
249  break;
250  case type_uint:
251  os << get_property_uint(prop_id);
252  break;
253  case type_float:
254  os << get_property_float(prop_id);
255  break;
256  default:
257  os << " unknown type ";
258  }
259  os << std::endl;
260  }
261 }