Back to home page

sPhenix code displayed by LXR

 
 

    


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

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