Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:22:01

0001 #include "PHG4Showerv1.h"
0002 
0003 #include "PHG4HitDefs.h"
0004 
0005 #include <algorithm>  // for fill
0006 #include <cmath>
0007 #include <iostream>
0008 #include <iterator>  // for begin, end
0009 #include <utility>
0010 
0011 PHG4Showerv1::PHG4Showerv1()
0012 {
0013   // with C++11 begin() and end() exist, you do not need the array size anymore
0014   // to fill an array
0015   std::fill(std::begin(_pos), std::end(_pos), std::numeric_limits<float>::quiet_NaN());
0016   std::fill(std::begin(_covar), std::end(_covar), std::numeric_limits<float>::quiet_NaN());
0017 }
0018 
0019 void PHG4Showerv1::identify(std::ostream &os) const
0020 {
0021   os << "---PHG4Showerv1-------------------------------" << std::endl;
0022   os << "id: " << get_id() << std::endl;
0023   os << "parent_particle_id: " << get_parent_particle_id() << std::endl;
0024   os << "parent_shower_id: " << get_parent_shower_id() << std::endl;
0025   os << "x: " << get_x() << std::endl;
0026   os << "y: " << get_y() << std::endl;
0027   os << "z: " << get_z() << std::endl;
0028 
0029   os << "         ( ";
0030   os << get_covar(0, 0) << " , ";
0031   os << get_covar(0, 1) << " , ";
0032   os << get_covar(0, 2) << " )" << std::endl;
0033   os << " covar = ( ";
0034   os << get_covar(1, 0) << " , ";
0035   os << get_covar(1, 1) << " , ";
0036   os << get_covar(1, 2) << " )" << std::endl;
0037   os << "         ( ";
0038   os << get_covar(2, 0) << " , ";
0039   os << get_covar(2, 1) << " , ";
0040   os << get_covar(2, 2) << " )" << std::endl;
0041 
0042   os << "VOLUME ID : edep eion light_yield" << std::endl;
0043   for (auto iter : _edep)
0044   {
0045     int volid = iter.first;
0046     os << volid << " : " << get_edep(volid) << " " << get_eion(volid) << " "
0047        << get_light_yield(volid) << std::endl;
0048   }
0049 
0050   os << "G4Particle IDs" << std::endl;
0051   for (int _g4particle_id : _g4particle_ids)
0052   {
0053     os << _g4particle_id << " ";
0054   }
0055   os << std::endl;
0056 
0057   os << "G4Hit IDs" << std::endl;
0058   for (const auto &_g4hit_id : _g4hit_ids)
0059   {
0060     for (unsigned long long jter : _g4hit_id.second)
0061     {
0062       os << jter << " ";
0063     }
0064   }
0065   os << std::endl;
0066 
0067   os << "-----------------------------------------------" << std::endl;
0068 
0069   return;
0070 }
0071 
0072 int PHG4Showerv1::isValid() const
0073 {
0074   if (_id == 0)
0075   {
0076     return 0;
0077   }
0078   for (float _po : _pos)
0079   {
0080     if (std::isnan(_po))
0081     {
0082       return 0;
0083     }
0084   }
0085   for (int j = 0; j < 3; ++j)
0086   {
0087     for (int i = j; i < 3; ++i)
0088     {
0089       if (std::isnan(get_covar(i, j)))
0090       {
0091         return 0;
0092       }
0093     }
0094   }
0095   return 1;
0096 }
0097 
0098 void PHG4Showerv1::set_covar(unsigned int i, unsigned int j, float value)
0099 {
0100   _covar[covar_index(i, j)] = value;
0101   return;
0102 }
0103 
0104 float PHG4Showerv1::get_covar(unsigned int i, unsigned int j) const
0105 {
0106   return _covar[covar_index(i, j)];
0107 }
0108 
0109 unsigned int PHG4Showerv1::covar_index(unsigned int i, unsigned int j) const
0110 {
0111   if (i > j)
0112   {
0113     std::swap(i, j);
0114   }
0115   return i + 1 + (j + 1) * (j) / 2 - 1;
0116 }
0117 
0118 unsigned int PHG4Showerv1::get_nhits(int volume) const
0119 {
0120   std::map<int, unsigned int>::const_iterator citer =
0121       _nhits.find(volume);
0122   if (citer == _nhits.end())
0123   {
0124     return 0;
0125   }
0126   return citer->second;
0127 }
0128 
0129 float PHG4Showerv1::get_edep(int volume) const
0130 {
0131   std::map<int, float>::const_iterator citer =
0132       _edep.find(volume);
0133   if (citer == _edep.end())
0134   {
0135     return 0.0;
0136   }
0137   return citer->second;
0138 }
0139 
0140 double PHG4Showerv1::get_edep() const
0141 {
0142   double sum = 0;
0143   for (const auto &iter : _edep)
0144   {
0145     sum += iter.second;
0146   }
0147   return sum;
0148 }
0149 
0150 float PHG4Showerv1::get_eion(int volume) const
0151 {
0152   std::map<int, float>::const_iterator citer =
0153       _eion.find(volume);
0154   if (citer == _eion.end())
0155   {
0156     return 0.0;
0157   }
0158   return citer->second;
0159 }
0160 
0161 double PHG4Showerv1::get_eion() const
0162 {
0163   double sum = 0;
0164   for (const auto &iter : _eion)
0165   {
0166     sum += iter.second;
0167   }
0168   return sum;
0169 }
0170 
0171 float PHG4Showerv1::get_light_yield(int volume) const
0172 {
0173   std::map<int, float>::const_iterator citer =
0174       _light_yield.find(volume);
0175   if (citer == _light_yield.end())
0176   {
0177     return 0.0;
0178   }
0179   return citer->second;
0180 }
0181 
0182 float PHG4Showerv1::get_eh_ratio(int volume) const
0183 {
0184   std::map<int, float>::const_iterator citer =
0185       _eh_ratio.find(volume);
0186   if (citer == _eh_ratio.end())
0187   {
0188     return 0.0;
0189   }
0190   return citer->second;
0191 }