Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "PHG4Hit.h"
0002 
0003 #include <TSystem.h>  // for gSystem
0004 
0005 #include <cassert>
0006 #include <cstdlib>
0007 #include <type_traits>
0008 
0009 void PHG4Hit::CopyFrom(const PHObject* phobj)
0010 {
0011   const PHG4Hit* g4hit = dynamic_cast<const PHG4Hit*>(phobj);
0012   assert(g4hit);
0013   for (int i = 0; i < 2; i++)
0014   {
0015     set_x(i, g4hit->get_x(i));
0016     set_y(i, g4hit->get_y(i));
0017     set_z(i, g4hit->get_z(i));
0018     set_t(i, g4hit->get_t(i));
0019   }
0020   set_edep(g4hit->get_edep());
0021   set_hit_id(g4hit->get_hit_id());
0022   set_shower_id(g4hit->get_shower_id());
0023   set_trkid(g4hit->get_trkid());
0024   // This is a generic copy of ALL properties a hit has
0025   // do not add explicit copies, they will be added to
0026   // the new hits with their default value increasing memory use
0027   for (unsigned char ic = 0; ic < std::numeric_limits<unsigned char>::max(); ic++)
0028   {
0029     PROPERTY prop_id = static_cast<PHG4Hit::PROPERTY>(ic);
0030     if (g4hit->has_property(prop_id))
0031     {
0032       set_property_nocheck(prop_id, g4hit->get_property_nocheck(prop_id));
0033     }
0034   }
0035 }
0036 
0037 void PHG4Hit::identify(std::ostream& os) const
0038 {
0039   os << "Class " << this->ClassName() << std::endl;
0040   os << "x0: " << get_x(0)
0041      << ", y0: " << get_y(0)
0042      << ", z0: " << get_z(0)
0043      << ", t0: " << get_t(0) << std::endl;
0044   os << "x1: " << get_x(1)
0045      << ", y1: " << get_y(1)
0046      << ", z1: " << get_z(1)
0047      << ", t1: " << get_t(1) << std::endl;
0048   os << "trackid: " << get_trkid() << ", edep: " << get_edep() << std::endl;
0049   os << "strip_z_index: " << get_strip_z_index() << ", strip_y_index: " << get_strip_y_index() << std::endl;
0050   os << "ladder_z_index: " << get_ladder_z_index() << ", ladder_phi_index: " << get_ladder_phi_index() << std::endl;
0051   os << "stave_index: " << get_property_int(prop_stave_index) << " half_stave_index " << get_property_int(prop_half_stave_index) << std::endl;
0052   os << "module_index: " << get_property_int(prop_module_index) << " chip_index " << get_property_int(prop_chip_index) << std::endl;
0053   os << "layer id: " << get_layer() << ", scint_id: " << get_scint_id() << std::endl;
0054   os << "hit type: " << get_hit_type() << std::endl;
0055   return;
0056 }
0057 
0058 std::ostream& operator<<(std::ostream& stream, const PHG4Hit* hit)
0059 {
0060   stream << std::endl
0061          << "(x,y,z) = "
0062          << "(" << hit->get_avg_x() << ", " << hit->get_avg_y() << ", " << hit->get_avg_z() << ")" << std::endl;
0063   stream << "trackid: " << hit->get_trkid() << " hitid: " << hit->get_hit_id() << " layer: " << hit->get_layer() << std::endl;
0064   return stream;
0065 }
0066 
0067 void PHG4Hit::Reset()
0068 {
0069   std::cout << "Reset not implemented by daughter class" << std::endl;
0070   return;
0071 }
0072 
0073 std::pair<const std::string, PHG4Hit::PROPERTY_TYPE>
0074 PHG4Hit::get_property_info(const PROPERTY prop_id)
0075 {
0076   switch (prop_id)
0077   {
0078   case prop_eion:
0079     return std::make_pair("ionizing energy loss", PHG4Hit::type_float);
0080   case prop_light_yield:
0081     return std::make_pair("light yield", PHG4Hit::type_float);
0082   case prop_raw_light_yield:
0083     return std::make_pair("raw light yield", PHG4Hit::type_float);
0084   case scint_gammas:
0085     return std::make_pair("scintillation photons", PHG4Hit::type_float);
0086   case cerenkov_gammas:
0087     return std::make_pair("cerenkov photons", PHG4Hit::type_float);
0088   case prop_px_0:
0089     return std::make_pair("px in", PHG4Hit::type_float);
0090   case prop_px_1:
0091     return std::make_pair("px out", PHG4Hit::type_float);
0092   case prop_py_0:
0093     return std::make_pair("py in", PHG4Hit::type_float);
0094   case prop_py_1:
0095     return std::make_pair("py out", PHG4Hit::type_float);
0096   case prop_pz_0:
0097     return std::make_pair("pz in", PHG4Hit::type_float);
0098   case prop_pz_1:
0099     return std::make_pair("pz out", PHG4Hit::type_float);
0100   case prop_local_x_0:
0101     return std::make_pair("local x in", PHG4Hit::type_float);
0102   case prop_local_x_1:
0103     return std::make_pair("local x out", PHG4Hit::type_float);
0104   case prop_local_y_0:
0105     return std::make_pair("local y in", PHG4Hit::type_float);
0106   case prop_local_y_1:
0107     return std::make_pair("local y out", PHG4Hit::type_float);
0108   case prop_local_z_0:
0109     return std::make_pair("local z in", PHG4Hit::type_float);
0110   case prop_local_z_1:
0111     return std::make_pair("local z out", PHG4Hit::type_float);
0112   case prop_path_length:
0113     return std::make_pair("pathlength", PHG4Hit::type_float);
0114   case prop_layer:
0115     return std::make_pair("layer ID", PHG4Hit::type_uint);
0116   case prop_scint_id:
0117     return std::make_pair("scintillator ID", PHG4Hit::type_int);
0118   case prop_row:
0119     return std::make_pair("row", PHG4Hit::type_int);
0120   case prop_sector:
0121     return std::make_pair("sector", PHG4Hit::type_int);
0122   case prop_strip_z_index:
0123     return std::make_pair("strip z index", PHG4Hit::type_int);
0124   case prop_strip_y_index:
0125     return std::make_pair("strip y index", PHG4Hit::type_int);
0126   case prop_ladder_z_index:
0127     return std::make_pair("ladder z index", PHG4Hit::type_int);
0128   case prop_ladder_phi_index:
0129     return std::make_pair("ladder phi index", PHG4Hit::type_int);
0130   case prop_index_i:
0131     return std::make_pair("generic index i", PHG4Hit::type_int);
0132   case prop_index_j:
0133     return std::make_pair("generic index j", PHG4Hit::type_int);
0134   case prop_index_k:
0135     return std::make_pair("generic index k", PHG4Hit::type_int);
0136   case prop_index_l:
0137     return std::make_pair("generic index l", PHG4Hit::type_int);
0138   case prop_stave_index:
0139     return std::make_pair("stave index", PHG4Hit::type_int);
0140   case prop_half_stave_index:
0141     return std::make_pair("half stave index", PHG4Hit::type_int);
0142   case prop_module_index:
0143     return std::make_pair("module index", PHG4Hit::type_int);
0144   case prop_chip_index:
0145     return std::make_pair("chip index", PHG4Hit::type_int);
0146   case prop_local_pos_x_0:
0147     return std::make_pair("local x pos in", PHG4Hit::type_float);
0148   case prop_local_pos_y_0:
0149     return std::make_pair("local y pos in", PHG4Hit::type_float);
0150   case prop_local_pos_z_0:
0151     return std::make_pair("local z pos in", PHG4Hit::type_float);
0152   case prop_hit_type:
0153     return std::make_pair("hit type", PHG4Hit::type_int);
0154   case prop_local_pos_x_1:
0155     return std::make_pair("local x pos out", PHG4Hit::type_float);
0156   case prop_local_pos_y_1:
0157     return std::make_pair("local y pos out", PHG4Hit::type_float);
0158   case prop_local_pos_z_1:
0159     return std::make_pair("local z pos out", PHG4Hit::type_float);
0160 
0161   default:
0162     std::cout << "PHG4Hit::get_property_info - Fatal Error - unknown index " << prop_id << std::endl;
0163     gSystem->Exit(1);
0164     exit(1);
0165   }
0166 }
0167 
0168 bool PHG4Hit::check_property(const PROPERTY prop_id, const PROPERTY_TYPE prop_type)
0169 {
0170   std::pair<const std::string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0171   if (property_info.second != prop_type)
0172   {
0173     return false;
0174   }
0175   return true;
0176 }
0177 
0178 std::string
0179 PHG4Hit::get_property_type(const PROPERTY_TYPE prop_type)
0180 {
0181   switch (prop_type)
0182   {
0183   case type_int:
0184     return "int";
0185   case type_uint:
0186     return "unsigned int";
0187   case type_float:
0188     return "float";
0189   default:
0190     return "unkown";
0191   }
0192 }