File indexing completed on 2025-08-06 08:18:55
0001 #include "PHG4Cellv1.h"
0002
0003 #include <g4main/PHG4HitDefs.h> // for keytype
0004
0005 #include <phool/phool.h>
0006
0007 #include <cmath> // for NAN
0008 #include <cstdlib> // for exit
0009 #include <iostream>
0010 #include <limits>
0011 #include <string> // for operator<<, string
0012
0013 PHG4Cellv1::PHG4Cellv1(const PHG4CellDefs::keytype g4cellid)
0014 : cellid(g4cellid)
0015 {
0016 }
0017
0018 PHG4Cellv1::~PHG4Cellv1()
0019 {
0020 hitedeps.clear();
0021 showeredeps.clear();
0022 prop_map.clear();
0023 return;
0024 }
0025
0026 void PHG4Cellv1::add_edep(const PHG4HitDefs::keytype g4hitid, const float edep)
0027 {
0028 hitedeps[g4hitid] = edep;
0029 return;
0030 }
0031
0032 void PHG4Cellv1::add_shower_edep(const int g4showerid, const float edep)
0033 {
0034 showeredeps[g4showerid] += edep;
0035 return;
0036 }
0037
0038 bool PHG4Cellv1::has_binning(const PHG4CellDefs::CellBinning binning) const
0039 {
0040 return PHG4CellDefs::has_binning(cellid, binning);
0041 }
0042
0043 short int
0044 PHG4Cellv1::get_detid() const
0045 {
0046 return PHG4CellDefs::get_detid(cellid);
0047 }
0048
0049 bool PHG4Cellv1::has_property(const PROPERTY prop_id) const
0050 {
0051 prop_map_t::const_iterator i = prop_map.find(prop_id);
0052 return i != prop_map.end();
0053 }
0054
0055 float PHG4Cellv1::get_property_float(const PROPERTY prop_id) const
0056 {
0057 if (!check_property(prop_id, type_float))
0058 {
0059 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0060 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0061 << prop_id << " is of type " << get_property_type(property_info.second)
0062 << " not " << get_property_type(type_float) << std::endl;
0063 exit(1);
0064 }
0065 prop_map_t::const_iterator i = prop_map.find(prop_id);
0066
0067 if (i != prop_map.end())
0068 {
0069 return u_property(i->second).fdata;
0070 }
0071
0072 return NAN;
0073 }
0074
0075 int PHG4Cellv1::get_property_int(const PROPERTY prop_id) const
0076 {
0077 if (!check_property(prop_id, type_int))
0078 {
0079 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0080 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0081 << prop_id << " is of type " << get_property_type(property_info.second)
0082 << " not " << get_property_type(type_int) << std::endl;
0083 exit(1);
0084 }
0085 prop_map_t::const_iterator i = prop_map.find(prop_id);
0086
0087 if (i != prop_map.end())
0088 {
0089 return u_property(i->second).idata;
0090 }
0091
0092 return INT_MIN;
0093 }
0094
0095 unsigned int
0096 PHG4Cellv1::get_property_uint(const PROPERTY prop_id) const
0097 {
0098 if (!check_property(prop_id, type_uint))
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_uint) << 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).uidata;
0111 }
0112
0113 return std::numeric_limits<unsigned int>::max();
0114 }
0115
0116 void PHG4Cellv1::add_property(const PROPERTY prop_id, const float value)
0117 {
0118 if (!check_property(prop_id, type_float))
0119 {
0120 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0121 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0122 << prop_id << " is of type " << get_property_type(property_info.second)
0123 << " not " << get_property_type(type_float) << std::endl;
0124 exit(1);
0125 }
0126 float val = value;
0127 if (prop_map.find(prop_id) != prop_map.end())
0128 {
0129 val += get_property_float(prop_id);
0130 }
0131 prop_map[prop_id] = u_property(val).get_storage();
0132 }
0133
0134 void PHG4Cellv1::add_property(const PROPERTY prop_id, const int value)
0135 {
0136 if (!check_property(prop_id, type_int))
0137 {
0138 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0139 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0140 << prop_id << " is of type " << get_property_type(property_info.second)
0141 << " not " << get_property_type(type_int) << std::endl;
0142 exit(1);
0143 }
0144 int val = value;
0145 if (prop_map.find(prop_id) != prop_map.end())
0146 {
0147 val += get_property_int(prop_id);
0148 }
0149 prop_map[prop_id] += u_property(val).get_storage();
0150 }
0151
0152 void PHG4Cellv1::add_property(const PROPERTY prop_id, const unsigned int value)
0153 {
0154 if (!check_property(prop_id, type_uint))
0155 {
0156 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0157 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0158 << prop_id << " is of type " << get_property_type(property_info.second)
0159 << " not " << get_property_type(type_uint) << std::endl;
0160 exit(1);
0161 }
0162 unsigned int val = value;
0163 if (prop_map.find(prop_id) != prop_map.end())
0164 {
0165 val += get_property_uint(prop_id);
0166 }
0167 prop_map[prop_id] += u_property(val).get_storage();
0168 }
0169
0170 void PHG4Cellv1::set_property(const PROPERTY prop_id, const float value)
0171 {
0172 if (!check_property(prop_id, type_float))
0173 {
0174 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0175 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0176 << prop_id << " is of type " << get_property_type(property_info.second)
0177 << " not " << get_property_type(type_float) << std::endl;
0178 exit(1);
0179 }
0180 prop_map[prop_id] = u_property(value).get_storage();
0181 }
0182
0183 void PHG4Cellv1::set_property(const PROPERTY prop_id, const int value)
0184 {
0185 if (!check_property(prop_id, type_int))
0186 {
0187 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0188 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0189 << prop_id << " is of type " << get_property_type(property_info.second)
0190 << " not " << get_property_type(type_int) << std::endl;
0191 exit(1);
0192 }
0193 prop_map[prop_id] += u_property(value).get_storage();
0194 }
0195
0196 void PHG4Cellv1::set_property(const PROPERTY prop_id, const unsigned int value)
0197 {
0198 if (!check_property(prop_id, type_uint))
0199 {
0200 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0201 std::cout << PHWHERE << " Property " << property_info.first << " with id "
0202 << prop_id << " is of type " << get_property_type(property_info.second)
0203 << " not " << get_property_type(type_uint) << std::endl;
0204 exit(1);
0205 }
0206 prop_map[prop_id] += u_property(value).get_storage();
0207 }
0208
0209 unsigned int
0210 PHG4Cellv1::get_property_nocheck(const PROPERTY prop_id) const
0211 {
0212 prop_map_t::const_iterator iter = prop_map.find(prop_id);
0213 if (iter != prop_map.end())
0214 {
0215 return iter->second;
0216 }
0217 return std::numeric_limits<unsigned int>::max();
0218 }
0219
0220 void PHG4Cellv1::print() const
0221 {
0222 identify(std::cout);
0223 }
0224
0225 void PHG4Cellv1::Reset()
0226 {
0227 hitedeps.clear();
0228 showeredeps.clear();
0229 prop_map.clear();
0230 return;
0231 }
0232
0233 void PHG4Cellv1::identify(std::ostream& os) const
0234 {
0235 os << "PHG4Cellv1 0x" << std::hex << cellid << std::dec << std::endl;
0236
0237 os << "Associated to " << hitedeps.size() << " hits" << std::endl;
0238 for (const auto pair : hitedeps)
0239 {
0240 os << "\t PHG4hit " << pair.first << " -> " << pair.second << " GeV" << std::endl;
0241 }
0242
0243 os << "Associated to " << showeredeps.size() << " showers" << std::endl;
0244 for (const auto pair : showeredeps)
0245 {
0246 os << "\t Shower " << pair.first << " -> " << pair.second << " GeV" << std::endl;
0247 }
0248 os << "Properties:" << std::endl;
0249 for (auto i : prop_map)
0250 {
0251 PROPERTY prop_id = static_cast<PROPERTY>(i.first);
0252 std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0253 os << "\t" << prop_id << ":\t" << property_info.first << " = \t";
0254 switch (property_info.second)
0255 {
0256 case type_int:
0257 os << get_property_int(prop_id);
0258 break;
0259 case type_uint:
0260 os << get_property_uint(prop_id);
0261 break;
0262 case type_float:
0263 os << get_property_float(prop_id);
0264 break;
0265 default:
0266 os << " unknown type ";
0267 }
0268 os << std::endl;
0269 }
0270 }