Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:20:15

0001 /*****************/
0002 /* Cameron Dean  */
0003 /*   LANL 2020   */
0004 /* cdean@bnl.gov */
0005 /*****************/
0006 
0007 // Ideas taken from SvtxTrackMap_v1 & TrkrClusterContainer
0008 
0009 #include "KFParticle_Container.h"
0010 
0011 #include <KFParticle.h>
0012 
0013 #include <cstdlib>
0014 #include <iterator>  // for reverse_iterator
0015 #include <map>       // for _Rb_tree_const_iterator, _Rb_tree_iterator
0016 #include <ostream>   // for operator<<, endl, ostream, basic_ostream, bas...
0017 #include <utility>   // for pair, make_pair
0018 
0019 KFParticle_Container::KFParticle_Container()
0020   : m_kfpmap()
0021 {
0022 }
0023 
0024 // NOLINTNEXTLINE(bugprone-copy-constructor-init)
0025 KFParticle_Container::KFParticle_Container(const KFParticle_Container& kfparticlemap)
0026   : m_kfpmap()
0027 {
0028   for (auto& iter : kfparticlemap)
0029   {
0030     KFParticle* particle = dynamic_cast<KFParticle*>(iter.second->Clone());
0031     m_kfpmap.insert(std::make_pair(iter.first, particle));
0032   }
0033 }
0034 
0035 KFParticle_Container& KFParticle_Container::operator=(const KFParticle_Container& kfparticlemap)
0036 {
0037   Reset();
0038   for (auto& iter : kfparticlemap)
0039   {
0040     KFParticle* particle = dynamic_cast<KFParticle*>(iter.second->Clone());
0041     m_kfpmap.insert(std::make_pair(iter.first, particle));
0042   }
0043   return *this;
0044 }
0045 
0046 KFParticle_Container::~KFParticle_Container()
0047 {
0048   Reset();
0049 }
0050 
0051 void KFParticle_Container::Reset()
0052 {
0053   for (auto& iter : m_kfpmap)
0054   {
0055     KFParticle* particle = iter.second;
0056     delete particle;
0057   }
0058   m_kfpmap.clear();
0059 }
0060 
0061 void KFParticle_Container::identify(std::ostream& os) const
0062 {
0063   os << "KFParticle_Container: size = " << m_kfpmap.size() << std::endl;
0064   return;
0065 }
0066 
0067 const KFParticle* KFParticle_Container::get(unsigned int id) const
0068 {
0069   ConstIter iter = m_kfpmap.find(id);
0070   if (iter == m_kfpmap.end())
0071   {
0072     return nullptr;
0073   }
0074   return iter->second;
0075 }
0076 
0077 KFParticle* KFParticle_Container::get(unsigned int id)
0078 {
0079   Iter iter = m_kfpmap.find(id);
0080   if (iter == m_kfpmap.end())
0081   {
0082     return nullptr;
0083   }
0084   return iter->second;
0085 }
0086 
0087 KFParticle* KFParticle_Container::insert(const KFParticle* particle)
0088 {
0089   unsigned int index = 0;
0090   if (!m_kfpmap.empty())
0091   {
0092     index = m_kfpmap.rbegin()->first + 1;
0093   }
0094   m_kfpmap.insert(std::make_pair(index, dynamic_cast<KFParticle*>(particle->Clone())));
0095   // m_kfpmap[index]->SetId(index);
0096   return m_kfpmap[index];
0097 }
0098 
0099 KFParticle_Container::ConstIter
0100 KFParticle_Container::addParticle(KFParticle* particle)
0101 {
0102   return addParticleSpecifyKey(particle->Id(), particle);
0103 }
0104 
0105 KFParticle_Container::ConstIter
0106 KFParticle_Container::addParticleSpecifyKey(unsigned int id, KFParticle* particle)
0107 {
0108   auto ret = m_kfpmap.insert(std::make_pair(id, particle));
0109   if (!ret.second)
0110   {
0111     std::cout << "KFParticle_Container::AddParticleSpecifyKey: duplicate id: " << id << " exiting now" << std::endl;
0112     exit(1);
0113   }
0114   else
0115   {
0116     return ret.first;
0117   }
0118 }
0119 
0120 KFParticle_Container::Map
0121 KFParticle_Container::returnParticlesByPDGid(int PDGid)
0122 {
0123   Map requiredParticles;
0124 
0125   for (auto& iter : m_kfpmap)
0126   {
0127     if (iter.second->GetPDG() == PDGid)
0128     {
0129       requiredParticles.insert(std::make_pair(iter.first, iter.second));
0130     }
0131   }
0132 
0133   return requiredParticles;
0134 }
0135 
0136 size_t KFParticle_Container::erase(unsigned int key)
0137 {
0138   delete m_kfpmap[key];
0139   return m_kfpmap.erase(key);
0140 }