Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:08

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