Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:38

0001 #include "GlobalVertexv1.h"
0002 
0003 #include <algorithm>
0004 #include <cmath>
0005 #include <iterator>
0006 
0007 GlobalVertexv1::GlobalVertexv1(const GlobalVertex::VTXTYPE id)
0008   : _id(id)
0009 {
0010   std::fill(std::begin(_pos), std::end(_pos), std::numeric_limits<float>::quiet_NaN());
0011   std::fill(std::begin(_err), std::end(_err), std::numeric_limits<float>::quiet_NaN());
0012 }
0013 
0014 void GlobalVertexv1::identify(std::ostream& os) const
0015 {
0016   os << "---GlobalVertexv1-----------------------" << std::endl;
0017   os << "vertexid: " << get_id();
0018 
0019   os << " t = " << get_t() << std::endl;
0020 
0021   os << " (x,y,z) =  (" << get_position(0);
0022   os << ", " << get_position(1) << ", ";
0023   os << get_position(2) << ") cm" << std::endl;
0024 
0025   os << " chisq = " << get_chisq() << ", ";
0026   os << " ndof = " << get_ndof() << std::endl;
0027 
0028   os << "         ( ";
0029   os << get_error(0, 0) << " , ";
0030   os << get_error(0, 1) << " , ";
0031   os << get_error(0, 2) << " )" << std::endl;
0032   os << "  err  = ( ";
0033   os << get_error(1, 0) << " , ";
0034   os << get_error(1, 1) << " , ";
0035   os << get_error(1, 2) << " )" << std::endl;
0036   os << "         ( ";
0037   os << get_error(2, 0) << " , ";
0038   os << get_error(2, 1) << " , ";
0039   os << get_error(2, 2) << " )" << std::endl;
0040 
0041   os << " list of vtx ids: " << std::endl;
0042   for (ConstVtxIter iter = begin_vtxids(); iter != end_vtxids(); ++iter)
0043   {
0044     os << "  " << iter->first << " => " << iter->second << std::endl;
0045   }
0046   os << "-----------------------------------------------" << std::endl;
0047 
0048   return;
0049 }
0050 
0051 int GlobalVertexv1::isValid() const
0052 {
0053   if (!std::isfinite(_t))
0054   {
0055     return 0;
0056   }
0057   if (!std::isfinite(_t_err))
0058   {
0059     return 0;
0060   }
0061   if (!std::isfinite(_chisq))
0062   {
0063     return 0;
0064   }
0065   if (_ndof == std::numeric_limits<unsigned int>::max())
0066   {
0067     return 0;
0068   }
0069 
0070   for (float _po : _pos)
0071   {
0072     if (!std::isfinite(_po))
0073     {
0074       return 0;
0075     }
0076   }
0077   for (int j = 0; j < 3; ++j)
0078   {
0079     for (int i = j; i < 3; ++i)
0080     {
0081       if (!std::isfinite(get_error(i, j)))
0082       {
0083         return 0;
0084       }
0085     }
0086   }
0087   if (_vtx_ids.empty())
0088   {
0089     return 0;
0090   }
0091   return 1;
0092 }
0093 
0094 void GlobalVertexv1::set_error(unsigned int i, unsigned int j, float value)
0095 {
0096   _err[covar_index(i, j)] = value;
0097   return;
0098 }
0099 
0100 float GlobalVertexv1::get_error(unsigned int i, unsigned int j) const
0101 {
0102   return _err[covar_index(i, j)];
0103 }
0104 
0105 unsigned int GlobalVertexv1::covar_index(unsigned int i, unsigned int j) const
0106 {
0107   if (i > j)
0108   {
0109     std::swap(i, j);
0110   }
0111   return i + 1 + (j + 1) * (j) / 2 - 1;
0112 }