File indexing completed on 2025-12-16 09:21:58
0001 #include "PHG4Hitv1.h"
0002 #include "PHG4HitDefs.h"
0003
0004 #include <phool/phool.h>
0005
0006 #include <cstdlib>
0007 #include <limits>
0008 #include <string>
0009 #include <utility>
0010
0011 PHG4Hitv1::PHG4Hitv1(const PHG4Hit* g4hit)
0012 {
0013 CopyFrom(g4hit);
0014 }
0015
0016 void PHG4Hitv1::Reset()
0017 {
0018 hitid = std::numeric_limits<PHG4HitDefs::keytype>::max();
0019 trackid = std::numeric_limits<int>::min();
0020 showerid = std::numeric_limits<int>::min();
0021 edep = std::numeric_limits<float>::quiet_NaN();
0022 for (int i = 0; i < 2; i++)
0023 {
0024 set_x(i, std::numeric_limits<float>::quiet_NaN());
0025 set_y(i, std::numeric_limits<float>::quiet_NaN());
0026 set_z(i, std::numeric_limits<float>::quiet_NaN());
0027 set_t(i, std::numeric_limits<float>::quiet_NaN());
0028 }
0029 prop_map.clear();
0030 }
0031
0032 int PHG4Hitv1::get_detid() const
0033 {
0034
0035 static_assert(PHG4HitDefs::hit_idbits <= sizeof(unsigned int) * 8, "hit_idbits < 32, fix in PHG4HitDefs.h");
0036 int detid = (hitid >> PHG4HitDefs::hit_idbits);
0037 return detid;
0038 }
0039
0040 void PHG4Hitv1::print() const
0041 {
0042 std::cout << "New Hitv1 0x" << std::hex << hitid
0043 << std::dec << " on track " << trackid << " EDep " << edep << std::endl;
0044 std::cout << "Location: X " << x[0] << "/" << x[1] << " Y " << y[0] << "/" << y[1] << " Z " << z[0] << "/" << z[1] << std::endl;
0045 std::cout << "Time " << t[0] << "/" << t[1] << std::endl;
0046
0047 for (auto i : prop_map)
0048 {
0049 PROPERTY prop_id = static_cast<PROPERTY>(i.first);
0050 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0051 std::cout << "\t" << prop_id << ":\t" << property_info.first << " = \t";
0052 switch (property_info.second)
0053 {
0054 case type_int:
0055 std::cout << get_property_int(prop_id);
0056 break;
0057 case type_uint:
0058 std::cout << get_property_uint(prop_id);
0059 break;
0060 case type_float:
0061 std::cout << get_property_float(prop_id);
0062 break;
0063 default:
0064 std::cout << " unknown type ";
0065 }
0066 std::cout << std::endl;
0067 }
0068 }
0069
0070 bool PHG4Hitv1::has_property(const PROPERTY prop_id) const
0071 {
0072 prop_map_t::const_iterator i = prop_map.find(prop_id);
0073 return i != prop_map.end();
0074 }
0075
0076 float PHG4Hitv1::get_property_float(const PROPERTY prop_id) const
0077 {
0078 if (!check_property(prop_id, type_float))
0079 {
0080 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0081 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0082 << prop_id << " is of type " << get_property_type(property_info.second)
0083 << " not " << get_property_type(type_float) << std::endl;
0084 exit(1);
0085 }
0086 prop_map_t::const_iterator i = prop_map.find(prop_id);
0087
0088 if (i != prop_map.end())
0089 {
0090 return u_property(i->second).fdata;
0091 }
0092
0093 return std::numeric_limits<float>::quiet_NaN();
0094 }
0095
0096 int PHG4Hitv1::get_property_int(const PROPERTY prop_id) const
0097 {
0098 if (!check_property(prop_id, type_int))
0099 {
0100 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0101 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0102 << prop_id << " is of type " << get_property_type(property_info.second)
0103 << " not " << get_property_type(type_int) << std::endl;
0104 exit(1);
0105 }
0106 prop_map_t::const_iterator i = prop_map.find(prop_id);
0107
0108 if (i != prop_map.end())
0109 {
0110 return u_property(i->second).idata;
0111 }
0112
0113 return std::numeric_limits<int>::min();
0114 }
0115
0116 unsigned int
0117 PHG4Hitv1::get_property_uint(const PROPERTY prop_id) const
0118 {
0119 if (!check_property(prop_id, type_uint))
0120 {
0121 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0122 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0123 << prop_id << " is of type " << get_property_type(property_info.second)
0124 << " not " << get_property_type(type_uint) << std::endl;
0125 exit(1);
0126 }
0127 prop_map_t::const_iterator i = prop_map.find(prop_id);
0128
0129 if (i != prop_map.end())
0130 {
0131 return u_property(i->second).uidata;
0132 }
0133
0134 return std::numeric_limits<unsigned int>::max();
0135 }
0136
0137 void PHG4Hitv1::set_property(const PROPERTY prop_id, const float value)
0138 {
0139 if (!check_property(prop_id, type_float))
0140 {
0141 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0142 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0143 << prop_id << " is of type " << get_property_type(property_info.second)
0144 << " not " << get_property_type(type_float) << std::endl;
0145 exit(1);
0146 }
0147 prop_map[prop_id] = u_property(value).get_storage();
0148 }
0149
0150 void PHG4Hitv1::set_property(const PROPERTY prop_id, const int value)
0151 {
0152 if (!check_property(prop_id, type_int))
0153 {
0154 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0155 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0156 << prop_id << " is of type " << get_property_type(property_info.second)
0157 << " not " << get_property_type(type_int) << std::endl;
0158 exit(1);
0159 }
0160 prop_map[prop_id] = u_property(value).get_storage();
0161 }
0162
0163 void PHG4Hitv1::set_property(const PROPERTY prop_id, const unsigned int value)
0164 {
0165 if (!check_property(prop_id, type_uint))
0166 {
0167 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0168 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0169 << prop_id << " is of type " << get_property_type(property_info.second)
0170 << " not " << get_property_type(type_uint) << std::endl;
0171 exit(1);
0172 }
0173 prop_map[prop_id] = u_property(value).get_storage();
0174 }
0175
0176 unsigned int
0177 PHG4Hitv1::get_property_nocheck(const PROPERTY prop_id) const
0178 {
0179 prop_map_t::const_iterator iter = prop_map.find(prop_id);
0180 if (iter != prop_map.end())
0181 {
0182 return iter->second;
0183 }
0184 return std::numeric_limits<unsigned int>::max();
0185 }
0186
0187 float PHG4Hitv1::get_px(const int i) const
0188 {
0189 switch (i)
0190 {
0191 case 0:
0192 return get_property_float(prop_px_0);
0193 case 1:
0194 return get_property_float(prop_px_1);
0195 default:
0196 std::cout << "Invalid index in get_px: " << i << std::endl;
0197 exit(1);
0198 }
0199 }
0200
0201 float PHG4Hitv1::get_py(const int i) const
0202 {
0203 switch (i)
0204 {
0205 case 0:
0206 return get_property_float(prop_py_0);
0207 case 1:
0208 return get_property_float(prop_py_1);
0209 default:
0210 std::cout << "Invalid index in get_py: " << i << std::endl;
0211 exit(1);
0212 }
0213 }
0214
0215 float PHG4Hitv1::get_pz(const int i) const
0216 {
0217 switch (i)
0218 {
0219 case 0:
0220 return get_property_float(prop_pz_0);
0221 case 1:
0222 return get_property_float(prop_pz_1);
0223 default:
0224 std::cout << "Invalid index in get_pz: " << i << std::endl;
0225 exit(1);
0226 }
0227 }
0228
0229 void PHG4Hitv1::set_px(const int i, const float f)
0230 {
0231 switch (i)
0232 {
0233 case 0:
0234 set_property(prop_px_0, f);
0235 return;
0236 case 1:
0237 set_property(prop_px_1, f);
0238 return;
0239 default:
0240 std::cout << "Invalid index in set_px: " << i << std::endl;
0241 exit(1);
0242 }
0243 }
0244
0245 void PHG4Hitv1::set_py(const int i, const float f)
0246 {
0247 switch (i)
0248 {
0249 case 0:
0250 set_property(prop_py_0, f);
0251 return;
0252 case 1:
0253 set_property(prop_py_1, f);
0254 return;
0255 default:
0256 std::cout << "Invalid index in set_py: " << i << std::endl;
0257 exit(1);
0258 }
0259 }
0260
0261 void PHG4Hitv1::set_pz(const int i, const float f)
0262 {
0263 switch (i)
0264 {
0265 case 0:
0266 set_property(prop_pz_0, f);
0267 return;
0268 case 1:
0269 set_property(prop_pz_1, f);
0270 return;
0271 default:
0272 std::cout << "Invalid index in set_pz: " << i << std::endl;
0273 exit(1);
0274 }
0275 }
0276
0277 float PHG4Hitv1::get_local_x(const int i) const
0278 {
0279 switch (i)
0280 {
0281 case 0:
0282 return get_property_float(prop_local_x_0);
0283 case 1:
0284 return get_property_float(prop_local_x_1);
0285 default:
0286 std::cout << "Invalid index in get_local_x: " << i << std::endl;
0287 exit(1);
0288 }
0289 }
0290
0291 float PHG4Hitv1::get_local_y(const int i) const
0292 {
0293 switch (i)
0294 {
0295 case 0:
0296 return get_property_float(prop_local_y_0);
0297 case 1:
0298 return get_property_float(prop_local_y_1);
0299 default:
0300 std::cout << "Invalid index in get_local_y: " << i << std::endl;
0301 exit(1);
0302 }
0303 }
0304
0305 float PHG4Hitv1::get_local_z(const int i) const
0306 {
0307 switch (i)
0308 {
0309 case 0:
0310 return get_property_float(prop_local_z_0);
0311 case 1:
0312 return get_property_float(prop_local_z_1);
0313 default:
0314 std::cout << "Invalid index in get_local_z: " << i << std::endl;
0315 exit(1);
0316 }
0317 }
0318
0319 void PHG4Hitv1::set_local_x(const int i, const float f)
0320 {
0321 switch (i)
0322 {
0323 case 0:
0324 set_property(prop_local_x_0, f);
0325 return;
0326 case 1:
0327 set_property(prop_local_x_1, f);
0328 return;
0329 default:
0330 std::cout << "Invalid index in set_local_x: " << i << std::endl;
0331 exit(1);
0332 }
0333 }
0334
0335 void PHG4Hitv1::set_local_y(const int i, const float f)
0336 {
0337 switch (i)
0338 {
0339 case 0:
0340 set_property(prop_local_y_0, f);
0341 return;
0342 case 1:
0343 set_property(prop_local_y_1, f);
0344 return;
0345 default:
0346 std::cout << "Invalid index in set_local_y: " << i << std::endl;
0347 exit(1);
0348 }
0349 }
0350
0351 void PHG4Hitv1::set_local_z(const int i, const float f)
0352 {
0353 switch (i)
0354 {
0355 case 0:
0356 set_property(prop_local_z_0, f);
0357 return;
0358 case 1:
0359 set_property(prop_local_z_1, f);
0360 return;
0361 default:
0362 std::cout << "Invalid index in set_local_z: " << i << std::endl;
0363 exit(1);
0364 }
0365 }
0366
0367 void PHG4Hitv1::identify(std::ostream& os) const
0368 {
0369 os << "Class " << this->ClassName() << std::endl;
0370 os << "hitid: 0x" << std::hex << hitid << std::dec << std::endl;
0371 os << "x0: " << get_x(0)
0372 << ", y0: " << get_y(0)
0373 << ", z0: " << get_z(0)
0374 << ", t0: " << get_t(0) << std::endl;
0375 os << "x1: " << get_x(1)
0376 << ", y1: " << get_y(1)
0377 << ", z1: " << get_z(1)
0378 << ", t1: " << get_t(1) << std::endl;
0379 os << "trackid: " << trackid << ", showerid: " << showerid
0380 << ", edep: " << edep << std::endl;
0381 for (auto i : prop_map)
0382 {
0383 PROPERTY prop_id = static_cast<PROPERTY>(i.first);
0384 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0385 os << "\t" << prop_id << ":\t" << property_info.first << " = \t";
0386 switch (property_info.second)
0387 {
0388 case type_int:
0389 os << get_property_int(prop_id);
0390 break;
0391 case type_uint:
0392 os << get_property_uint(prop_id);
0393 break;
0394 case type_float:
0395 os << get_property_float(prop_id);
0396 break;
0397 default:
0398 os << " unknown type ";
0399 }
0400 os << std::endl;
0401 }
0402 }